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

warpx.roundrobin_sfc: A runtime parameter to control distribution mapping #4909

Merged
merged 8 commits into from
Aug 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions Docs/source/usage/parameters.rst
Original file line number Diff line number Diff line change
Expand Up @@ -733,6 +733,14 @@ Distribution across MPI ranks and parallelization
* ``warpx.do_dynamic_scheduling`` (`0` or `1`) optional (default `1`)
Whether to activate OpenMP dynamic scheduling.

* ``warpx.roundrobin_sfc`` (`0` or `1`) optional (default `0`)
Whether to use AMReX's RRSFS strategy for making DistributionMapping to
override the default space filling curve (SFC) strategy. If this is
enabled, the round robin method is used to distribute Boxes ordered by
SFC. This could potentially mitigate the load imbalance issue during
initialization by avoiding putting neighboring boxes on the same
process.

.. _running-cpp-parameters-parser:

Math parser and user-defined constants
Expand Down
6 changes: 6 additions & 0 deletions Python/pywarpx/picmi.py
Original file line number Diff line number Diff line change
Expand Up @@ -2593,6 +2593,9 @@ class Simulation(picmistandard.PICMI_Simulation):
warpx_do_dynamic_scheduling: bool, default=True
Whether to do dynamic scheduling with OpenMP

warpx_roundrobin_sfc: bool, default=False
Whether to use the RRSFC strategy for making DistributionMapping

warpx_load_balance_intervals: string, default='0'
The intervals for doing load balancing

Expand Down Expand Up @@ -2709,6 +2712,7 @@ def init(self, kw):
)
self.random_seed = kw.pop("warpx_random_seed", None)
self.do_dynamic_scheduling = kw.pop("warpx_do_dynamic_scheduling", None)
self.roundrobin_sfc = kw.pop("warpx_roundrobin_sfc", None)
self.load_balance_intervals = kw.pop("warpx_load_balance_intervals", None)
self.load_balance_efficiency_ratio_threshold = kw.pop(
"warpx_load_balance_efficiency_ratio_threshold", None
Expand Down Expand Up @@ -2804,6 +2808,8 @@ def initialize_inputs(self):

pywarpx.warpx.do_dynamic_scheduling = self.do_dynamic_scheduling

pywarpx.warpx.roundrobin_sfc = self.roundrobin_sfc

pywarpx.particles.use_fdtd_nci_corr = self.use_fdtd_nci_corr

pywarpx.amr.check_input = self.amr_check_input
Expand Down
4 changes: 4 additions & 0 deletions Source/WarpX.H
Original file line number Diff line number Diff line change
Expand Up @@ -1242,6 +1242,10 @@ protected:
//! This function is called in amrex::AmrCore::InitFromScratch.
void PostProcessBaseGrids (amrex::BoxArray& ba0) const final;

//! Use this function to override how DistributionMapping is made.
[[nodiscard]] amrex::DistributionMapping
MakeDistributionMap (int lev, amrex::BoxArray const& ba) final;

//! Make a new level from scratch using provided BoxArray and
//! DistributionMapping. Only used during initialization. Called
//! by AmrCoreInitFromScratch.
Expand Down
26 changes: 26 additions & 0 deletions Source/WarpX.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3587,6 +3587,32 @@ WarpX::getField(FieldType field_type, const int lev, const int direction) const
return *getFieldPointer(field_type, lev, direction);
}

amrex::DistributionMapping
WarpX::MakeDistributionMap (int lev, amrex::BoxArray const& ba)
{
bool roundrobin_sfc = false;
const ParmParse pp("warpx");
pp.query("roundrobin_sfc", roundrobin_sfc);

// If this is true, AMReX's RRSFC strategy is used to make
// DistributionMapping. Note that the DistributionMapping made by the
// here could still be overridden by load balancing. In the RRSFC
// strategy, the Round robin method is used to distribute Boxes orderd
// by the space filling curve. This might help avoid some processes
// running out of memory due to having too many particles during
// initialization.

if (roundrobin_sfc) {
WeiqunZhang marked this conversation as resolved.
Show resolved Hide resolved
auto old_strategy = amrex::DistributionMapping::strategy();
amrex::DistributionMapping::strategy(amrex::DistributionMapping::RRSFC);
amrex::DistributionMapping dm(ba);
amrex::DistributionMapping::strategy(old_strategy);
return dm;
} else {
return amrex::AmrCore::MakeDistributionMap(lev, ba);
}
}

const amrex::Vector<std::array< std::unique_ptr<amrex::MultiFab>,3>>&
WarpX::getMultiLevelField(warpx::fields::FieldType field_type) const
{
Expand Down
Loading