diff options
-rw-r--r-- | Docs/source/usage/parameters.rst | 18 | ||||
-rw-r--r-- | Source/Particles/MultiParticleContainer.cpp | 6 | ||||
-rw-r--r-- | Source/WarpX.H | 5 | ||||
-rw-r--r-- | Source/WarpX.cpp | 20 |
4 files changed, 46 insertions, 3 deletions
diff --git a/Docs/source/usage/parameters.rst b/Docs/source/usage/parameters.rst index 6aada000e..87e8d0299 100644 --- a/Docs/source/usage/parameters.rst +++ b/Docs/source/usage/parameters.rst @@ -2049,12 +2049,26 @@ Additional parameters * ``warpx.sort_intervals`` (`string`) optional (defaults: ``-1`` on CPU; ``4`` on GPU) Using the `Intervals parser`_ syntax, this string defines the timesteps at which particles are - sorted by bin. + sorted. If ``<=0``, do not sort particles. It is turned on on GPUs for performance reasons (to improve memory locality). +* ``warpx.sort_particles_for_deposition`` (`bool`) optional (default: ``true`` for the CUDA backend, otherwise ``false``) + This option controls the type of sorting used if particle sorting is turned on, i.e. if ``sort_intervals`` is not ``<=0``. + If ``true``, particles will be sorted by cell to optimize deposition with many particles per cell, in the order x -> y -> z -> ppc. + If ``false``, particles will be sorted by bin, using the ``sort_bin_size`` parameter below, in the order ppc -> x -> y -> z. + ``true`` is recommend for best performance on NVIDIA GPUs, especially if there are many particles per cell. + +* ``warpx.sort_idx_type`` (list of `int`) optional (default: ``0 0 0``) + This controls the type of grid used to sort the particles when ``sort_particles_for_deposition`` is ``true``. Possible values are: + ``idx_type = {0, 0, 0}``: Sort particles to a cell centered grid + ``idx_type = {1, 1, 1}``: Sort particles to a node centered grid + ``idx_type = {2, 2, 2}``: Compromise between a cell and node centered grid. + In 2D (XZ and RZ), only the first two elements are read. + In 1D, only the first element is read. + * ``warpx.sort_bin_size`` (list of `int`) optional (default ``1 1 1``) - If ``sort_intervals`` is activated particles are sorted in bins of ``sort_bin_size`` cells. + If ``sort_intervals`` is activated and ``sort_particles_for_deposition`` is ``false``, particles are sorted in bins of ``sort_bin_size`` cells. In 2D, only the first two elements are read. .. _running-cpp-parameters-diagnostics: diff --git a/Source/Particles/MultiParticleContainer.cpp b/Source/Particles/MultiParticleContainer.cpp index 359b1ecde..6107bb9c1 100644 --- a/Source/Particles/MultiParticleContainer.cpp +++ b/Source/Particles/MultiParticleContainer.cpp @@ -621,7 +621,11 @@ void MultiParticleContainer::SortParticlesByBin (amrex::IntVect bin_size) { for (auto& pc : allcontainers) { - pc->SortParticlesByBin(bin_size); + if (WarpX::sort_particles_for_deposition) { + pc->SortParticlesForDeposition(WarpX::sort_idx_type); + } else { + pc->SortParticlesByBin(bin_size); + } } } diff --git a/Source/WarpX.H b/Source/WarpX.H index bfc2e0562..1358630b3 100644 --- a/Source/WarpX.H +++ b/Source/WarpX.H @@ -307,6 +307,11 @@ public: static utils::parser::IntervalsParser sort_intervals; static amrex::IntVect sort_bin_size; + //! If true, particles will be sorted in the order x -> y -> z -> ppc for faster deposition + static bool sort_particles_for_deposition; + //! Specifies the type of grid used for the above sorting, i.e. cell-centered, nodal, or mixed + static amrex::IntVect sort_idx_type; + static bool do_subcycling; static bool do_multi_J; static int do_multi_J_n_depositions; diff --git a/Source/WarpX.cpp b/Source/WarpX.cpp index 1e48d659d..ec9f3ee05 100644 --- a/Source/WarpX.cpp +++ b/Source/WarpX.cpp @@ -172,6 +172,14 @@ int WarpX::num_mirrors = 0; utils::parser::IntervalsParser WarpX::sort_intervals; amrex::IntVect WarpX::sort_bin_size(AMREX_D_DECL(1,1,1)); +#if defined(AMREX_USE_CUDA) +bool WarpX::sort_particles_for_deposition = true; +#else +bool WarpX::sort_particles_for_deposition = false; +#endif + +amrex::IntVect WarpX::sort_idx_type(AMREX_D_DECL(0,0,0)); + bool WarpX::do_dynamic_scheduling = true; int WarpX::electrostatic_solver_id; @@ -1165,6 +1173,18 @@ WarpX::ReadParameters () for (int i=0; i<AMREX_SPACEDIM; i++) sort_bin_size[i] = vect_sort_bin_size[i]; } + + pp_warpx.query("sort_particles_for_deposition",sort_particles_for_deposition); + Vector<int> vect_sort_idx_type(AMREX_SPACEDIM,0); + bool sort_idx_type_is_specified = + utils::parser::queryArrWithParser( + pp_warpx, "sort_idx_type", + vect_sort_idx_type, 0, AMREX_SPACEDIM); + if (sort_idx_type_is_specified){ + for (int i=0; i<AMREX_SPACEDIM; i++) + sort_idx_type[i] = vect_sort_idx_type[i]; + } + } { |