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

Add leapfrog pusher for plasma #847

Merged

Conversation

AlexanderSinn
Copy link
Member

@AlexanderSinn AlexanderSinn commented Jan 12, 2023

To use the new leapfrog pusher, compile with

-DHiPACE_PUSHER=LEAPFROG

Leapfrog: 40% faster plasma push

--------------------------------------------------------------------------------------------------
Name                                               NCalls  Excl. Min  Excl. Avg  Excl. Max   Max %
--------------------------------------------------------------------------------------------------
AnyDST::Execute()                                   18000      33.76      33.76      33.76  23.54%
DepositCurrent_PlasmaParticleContainer()             6000      26.52      26.52      26.52  18.49%
AdvancePlasmaParticles()                             6000      22.52      22.52      22.52  15.70%
ExplicitDeposition()                                 6000      22.36      22.36      22.36  15.59%
hpmg::MultiGrid::solve1()                            3000      21.49      21.49      21.49  14.98%

AB5:

--------------------------------------------------------------------------------------------------
Name                                               NCalls  Excl. Min  Excl. Avg  Excl. Max   Max %
--------------------------------------------------------------------------------------------------
AnyDST::Execute()                                   18000      33.68      33.68      33.68  21.85%
AdvancePlasmaParticles()                             6000      32.24      32.24      32.24  20.92%
DepositCurrent_PlasmaParticleContainer()             6000      26.65      26.65      26.65  17.29%
ExplicitDeposition()                                 6000      22.33      22.33      22.33  14.49%
hpmg::MultiGrid::solve1()                            3000      21.49      21.49      21.49  13.94%

Leapfrog: 2.5x less memory for plasma

-------------------------------------------------------------------
Name                                      Nalloc  Nfree  Max Memory
-------------------------------------------------------------------
Unprofiled                                     1      1      29 GiB
sortBeamParticlesByBox()                      44     44      11 GiB
BeamParticleContainer::InitParticles          10     10    7390 MiB
PlasmaParticleContainer::InitParticles        34     34    4737 MiB
DenseBins<T>::buildGPU                        36     36    1210 MiB

AB5:

-------------------------------------------------------------------
Name                                      Nalloc  Nfree  Max Memory
-------------------------------------------------------------------
Unprofiled                                     1      1      29 GiB
PlasmaParticleContainer::InitParticles        84     84      11 GiB
sortBeamParticlesByBox()                      44     44      11 GiB
BeamParticleContainer::InitParticles          10     10    7390 MiB
DenseBins<T>::buildGPU                        36     36    1210 MiB

Leapfrog: within ~10^-5 field results

image

AB5:

image

Delta:

image

  • Small enough (< few 100s of lines), otherwise it should probably be split into smaller PRs
  • Tested (describe the tests in the PR description)
  • Runs on GPU (basic: the code compiles and run well with the new module)
  • Contains an automated test (checksum and/or comparison with theory)
  • Documented: all elements (classes and their members, functions, namespaces, etc.) are documented
  • Constified (All that can be const is const)
  • Code is clean (no unwanted comments, )
  • Style and code conventions are respected at the bottom of https://github.com/Hi-PACE/hipace
  • Proper label and GitHub project, if applicable

@AlexanderSinn AlexanderSinn added the component: plasma About the plasma species label Jan 12, 2023
@AlexanderSinn AlexanderSinn changed the title Replace Adams-Bashforth pusher with Leapfrog method, keep AB5 option [WIP] Replace Adams-Bashforth pusher with Leapfrog method, keep AB5 option Jan 13, 2023
@AlexanderSinn
Copy link
Member Author

The differences between the new and old AB5 pusher in CI can be explained by:

Ionization: for new electrons the old pusher would immediately push them with force terms equal to zero, while the new pusher would gather force terms first.

Collisions: Because it is more convenient with how temp slices work, with the new pusher collisions are done after the push while the old pusher pushed after collisions.

production.SI: This is a very tiny change in the checksum of fields like Bx, ExmBy, Bz etc. that don’t have a strong structure in on the xz slice, possibly caused by reordering some multiplications and divisions in the pusher.

So they are effectively equivalent. I will now change the default to leapfrog.

@AlexanderSinn AlexanderSinn changed the title [WIP] Replace Adams-Bashforth pusher with Leapfrog method, keep AB5 option Replace Adams-Bashforth pusher with Leapfrog method, keep AB5 option as default Jan 26, 2023
@AlexanderSinn AlexanderSinn changed the title Replace Adams-Bashforth pusher with Leapfrog method, keep AB5 option as default Add leapfrog pusher for plasma Jan 26, 2023
@SeverinDiederichs
Copy link
Member

SeverinDiederichs commented Jan 29, 2023

Suggestion I'd like: Since it is a compile time option, it would be great if it was printed in the output, similar to other compile time options like the precision. i.e.,

HiPACE++ (v22.12-33-gab7921595939) running in double precision
using CUDA version 11.7.64
using the leapfrog / Adams-Bashforth plasma particle pusher

Copy link
Member

@MaxThevenet MaxThevenet left a comment

Choose a reason for hiding this comment

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

Looks great, thanks for this PR! Indeed quite a bit of cleaning. See small comments below.

CMakeLists.txt Outdated Show resolved Hide resolved
src/particles/plasma/MultiPlasma.H Show resolved Hide resolved
src/particles/pusher/PlasmaParticleAdvance.cpp Outdated Show resolved Hide resolved
src/salame/Salame.cpp Outdated Show resolved Hide resolved
Copy link
Member

@MaxThevenet MaxThevenet left a comment

Choose a reason for hiding this comment

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

Nice, thanks for the comments!

@MaxThevenet MaxThevenet merged commit 5f8a7f5 into Hi-PACE:development Jan 31, 2023
@MaxThevenet
Copy link
Member

For the record, could you update the description of your PR to reflect the new name of the compile-time option?

@@ -165,7 +165,8 @@ or by providing arguments to the CMake call
``HiPACE_amrex_branch`` ``development`` Repository branch for ``HiPACE_amrex_repo``
``HiPACE_amrex_internal`` **ON**/OFF Needs a pre-installed AMReX library if set to ``OFF``
``HiPACE_OPENPMD`` **ON**/OFF openPMD I/O (HDF5, ADIOS2)
============================= ======================================== =====================================================
``HiPACE_PUSHER`` **AB5**/LEAPFROG Use fifth-order Adams-Bashforth or leapfrog Plasma Pusher
Copy link
Member

Choose a reason for hiding this comment

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

@AlexanderSinn is it work making this a compile-time option?

I think pre-compiling both options and doing a runtime switch before the two specialized kernels would be more user friendly.

Copy link
Member

Choose a reason for hiding this comment

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

Discussed: needs additional (25) force terms on the particle, so that's a bit of a heavy lift.

Copy link
Member Author

Choose a reason for hiding this comment

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

As mentioned, it is a compile-time option not for performance of the push kernel, but rather to save on memory of the 25 Adams-Bashforth force terms (per plasma particle) if the leapfrog pusher is used. One would need to change these to runtime components to make this a runtime option.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
component: plasma About the plasma species
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants