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

Split up particles over multiple tiles for OpenMP #862

Open
wants to merge 15 commits into
base: development
Choose a base branch
from

Conversation

atmyers
Copy link
Contributor

@atmyers atmyers commented Feb 25, 2025

I now get, on this example, the following timings for track_particles on 1, 2, and 4 threads:

1.893
1.017
0.5939

Fix #847

@atmyers atmyers requested a review from ax3l February 25, 2025 22:50
@ax3l ax3l self-assigned this Feb 25, 2025
@ax3l ax3l added bug Something isn't working backend: openmp Specific to OpenMP execution (CPUs) bug: affects latest release Bug also exists in latest release version tracking: particles labels Feb 25, 2025
Copy link
Member

@ax3l ax3l left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yay, thank you for the fix! 🎉

@ax3l
Copy link
Member

ax3l commented Feb 25, 2025

Oh, CI indicates we did not initialize the right number of total particles yet (or forgot them in output)?

@atmyers
Copy link
Contributor Author

atmyers commented Feb 27, 2025

Only the run_fodo_programmable fails now. Are we sure that example is thread-safe?

@ax3l
Copy link
Member

ax3l commented Feb 27, 2025

Yay! 🚀 ✨

Yes, I think it is actually not thread safe... Let's set those two controls to False:

pge1.threadsafe = True # allow OpenMP threading for speed

pge2.threadsafe = True # allow OpenMP threading for speed

Needs some further work, e.g., on testing GIL-free Python,
to support threading of Python part.
@ax3l ax3l force-pushed the fix_omp_drift branch 2 times, most recently from 8112176 to be2027f Compare February 27, 2025 19:12
}

if (n_logical < nthreads) {
amrex::Abort("ImpactParticleContainer::prepare() "
Copy link
Member

@ax3l ax3l Feb 27, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@atmyers I added more more concrete guidance to users here, can you please double check it?

In which situations would we not be able to find enough tiles? Is there other guidance we should give or can we make it a high warning and "just" be less parallel (i.e., less parallely efficient)?

Copy link
Contributor Author

@atmyers atmyers Feb 27, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Currently, the code will not just be efficient, it will give incorrect results if the number of tiles according to the tile_size is fewer than the number of threads. The issue is that the copyParticles routine in AMReX does not copy the ones that aren't on a valid tile. This resulted in some of the particles not getting written out some examples (since we us copyParticles to a pinned_pc in IO).

This can be changed in AMReX, I'd suggest changing this to a warning rather than an Abort at that point.

Copy link
Member

@ax3l ax3l left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you, I understand the logic way better now 🙏

@ax3l ax3l enabled auto-merge (squash) February 27, 2025 22:32
@ax3l
Copy link
Member

ax3l commented Feb 28, 2025

@atmyers I see segfaults on Windows right now, which is one of the few runners compiling with -DImpactX_COMPUTE=NOACC.

Can you compile in the same mode please and run valgrind on the failing example(s)? I suspect there is an actual bug somewhere.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backend: openmp Specific to OpenMP execution (CPUs) bug: affects latest release Bug also exists in latest release version bug Something isn't working tracking: particles
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Particle Push: OpenMP Not Working if no Collective Effects
2 participants