Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Compiling for 32bit Linux #4371

Closed
ax3l opened this issue Mar 12, 2025 · 8 comments · Fixed by #4375
Closed

Compiling for 32bit Linux #4371

ax3l opened this issue Mar 12, 2025 · 8 comments · Fixed by #4375

Comments

@ax3l
Copy link
Member

ax3l commented Mar 12, 2025

Compiling AMReX 25.02 for 32bit Linux raises this static assert:

src/Particle/ParticleContainer.cpp:52:8:   required from here
2025-03-12T17:03:32.0388802Z   /usr/local/include/AMReX_ParticleContainerI.H:65:61: error: static assertion failed: sizeof ParticleType is not a multiple of sizeof RealType
2025-03-12T17:03:32.0390003Z      65 |         static_assert(sizeof(ParticleType)%sizeof(RealType) == 0,
2025-03-12T17:03:32.0390575Z         |                       ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~

https://github.com/AMReX-Codes/amrex/blob/25.02/Src/Particle/AMReX_ParticleContainerI.H#L65-L66

Seen in

@ax3l
Copy link
Member Author

ax3l commented Mar 12, 2025

@atmyers @WeiqunZhang is this potentially an easy fix?

@WeiqunZhang
Copy link
Member

What's the data type of ParticleType? We can probably use alignas on it to work around the issue. Or maybe the function containing the static_assert can be relaxed.

@ax3l
Copy link
Member Author

ax3l commented Mar 14, 2025

The data type should be a double for ParticleReal for pure SoA particles, I am seeing this with a default build of ImpactX using Python bindings on 32bit Linux.

The problem is likely from some integer types that we also store in ParticleType?

@ax3l
Copy link
Member Author

ax3l commented Mar 14, 2025

Type seems to be this: amrex::SoAParticle<3, 0>

ParticleContainer.cpp:52:8:   required from here
2025-03-13T08:33:47.7341772Z   /usr/local/include/AMReX_ParticleContainerI.H:65:61: error: static assertion failed: sizeof ParticleType is not a multiple of sizeof RealType
2025-03-13T08:33:47.7342864Z      65 |         static_assert(sizeof(ParticleType)%sizeof(RealType) == 0,
2025-03-13T08:33:47.7343420Z         |                       ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~
2025-03-13T08:33:47.9897603Z   /usr/local/include/AMReX_ParticleContainerI.H: In instantiation of ‘void amrex::ParticleContainer_impl<ParticleType, NArrayReal, NArrayInt, Allocator, CellAssignor>::Initialize() [with T_ParticleType = amrex::SoAParticle<3, 0>; int T_NArrayReal = 3; int T_NArrayInt = 0; Allocator = std::allocator; T_CellAssignor = amrex::DefaultAssignor]’:

Accidentally cropped the one line that counts in the initial report, haha.

@WeiqunZhang
Copy link
Member

I don't understand. It looks like that the first non-static member of SoAParticle<3, 0> is long long. That should make the size of the class a multiple of 8, assuming long long needs to be aligned with 8.

@WeiqunZhang
Copy link
Member

Oh I see. ChatGPT says,

On an i686 (32-bit x86) system, the alignment of long long depends on the ABI (Application Binary Interface) used.
Alignment of long long on i686 (x86, 32-bit):

    System V i386 ABI (Used by Linux, including Alpine Linux with musl)
        Alignment of long long: 4 bytes
        Size of long long: 8 bytes
        This means that long long can be stored at 4-byte aligned addresses instead of 8-byte aligned addresses.

Why is long long only 4-byte aligned on i686?

    On x86 (32-bit), most data types do not require strict alignment.
    The i386 System V ABI specifies that long long should be aligned to 4 bytes, not 8.
    This differs from architectures like x86_64, where long long is 8-byte aligned.

@WeiqunZhang WeiqunZhang linked a pull request Mar 14, 2025 that will close this issue
@WeiqunZhang
Copy link
Member

@ax3l Could you test #4375?

@WeiqunZhang
Copy link
Member

https://en.wikipedia.org/wiki/Data_structure_alignment

A long long (eight bytes) will be 8-byte aligned on Windows and 4-byte aligned on Linux (8-byte with -malign-double compile time option).

atmyers pushed a commit that referenced this issue Mar 26, 2025

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
This fixes build issues on 32-bit Linux. This should not affect 64 bits
machines.

Fix #4371
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants