1 #ifndef BL_DISTRIBUTIONMAPPING_H
2 #define BL_DISTRIBUTIONMAPPING_H
3 #include <AMReX_Config.H>
22 template <
typename T>
class FabArray;
23 template <
typename T>
class LayoutData;
95 int nprocs = ParallelDescriptor::
NProcs());
127 [[nodiscard]] Long
size () const noexcept {
return Long(
m_ref->m_pmap.size()); }
128 [[nodiscard]] Long
capacity () const noexcept {
return Long(
m_ref->m_pmap.capacity()); }
129 [[nodiscard]]
bool empty () const noexcept {
return m_ref->m_pmap.empty(); }
135 [[nodiscard]]
int operator[] (
int index)
const noexcept {
return m_ref->m_pmap[index]; }
137 std::istream&
readFrom (std::istream& is);
139 std::ostream&
writeOn (std::ostream& os)
const;
160 Real& efficiency,
bool sort=
true);
162 Real* efficiency=
nullptr,
163 bool do_full_knapsack=
true,
167 const std::vector<Long>& wgts, Real keep_ratio,
168 Real& old_efficiency, Real& new_efficiency,
226 Real& currentEfficiency, Real& proposedEfficiency,
228 bool broadcastToAll=
true,
230 Real keep_ratio = Real(0.0));
236 const BoxArray& ba,
bool sort=
true);
238 const BoxArray& ba, Real& eff,
bool sort=
true);
261 Real& currentEfficiency, Real& proposedEfficiency,
262 bool broadcastToAll=
true,
270 bool use_box_vol=
true,
280 template <
typename T>
282 const std::vector<T>& cost,
285 [[nodiscard]] std::weak_ptr<Ref>
getWeakRef ()
const;
303 const LIpair& rhs)
const noexcept
305 return lhs.first < rhs.first;
312 const LIpair& rhs)
const noexcept
314 return lhs.first > rhs.first;
318 static void Sort (std::vector<LIpair>& vec,
bool reverse);
322 std::vector<LIpair>* LIpairV =
nullptr,
328 bool do_full_knapsack,
333 const std::vector<Long>& wgts,
336 Real* efficiency=
nullptr);
421 template <
typename T>
428 const auto nboxes =
int(dm.
size());
429 for (
int ibox = 0; ibox < nboxes; ++ibox) {
430 wgts[dm[ibox]] += cost[ibox];
435 for (
auto const& w : wgts) {
436 max_weight =
std::max(w, max_weight);
440 *efficiency =
static_cast<Real
>(sum_weight) /
441 (
static_cast<Real
>(nprocs) *
static_cast<Real
>(max_weight));
A collection of Boxes stored in an Array.
Definition: AMReX_BoxArray.H:550
Calculates the distribution of FABs to MPI processes.
Definition: AMReX_DistributionMapping.H:41
static void Initialize()
Initializes distribution strategy from ParmParse.
Definition: AMReX_DistributionMapping.cpp:107
int operator[](int index) const noexcept
Equivalent to ProcessorMap()[index].
Definition: AMReX_DistributionMapping.H:135
static DistributionMapping makeKnapSack(const MultiFab &weight, int nmax=std::numeric_limits< int >::max())
Definition: AMReX_DistributionMapping.cpp:1728
Long linkCount() const noexcept
Number of references to this DistributionMapping.
Definition: AMReX_DistributionMapping.H:132
void RRSFCProcessorMap(const BoxArray &boxes, int nprocs)
Definition: AMReX_DistributionMapping.cpp:1571
Long size() const noexcept
Length of the underlying processor map.
Definition: AMReX_DistributionMapping.H:127
void SFCProcessorMapDoIt(const BoxArray &boxes, const std::vector< Long > &wgts, int nprocs, bool sort=true, Real *efficiency=nullptr)
Definition: AMReX_DistributionMapping.cpp:1267
void define(const BoxArray &boxes, int nprocs=ParallelDescriptor::NProcs())
Build mapping out of BoxArray over nprocs processors. You need to call this if you built your Distrib...
Definition: AMReX_DistributionMapping.cpp:345
static bool SameRefs(const DistributionMapping &lhs, const DistributionMapping &rhs)
Definition: AMReX_DistributionMapping.H:187
void KnapSackDoIt(const std::vector< Long > &wgts, int nprocs, Real &efficiency, bool do_full_knapsack, int nmax=std::numeric_limits< int >::max(), bool sort=true)
Definition: AMReX_DistributionMapping.cpp:724
void RRSFCDoIt(const BoxArray &boxes, int nprocs)
Definition: AMReX_DistributionMapping.cpp:1538
static int SFC_Threshold()
Definition: AMReX_DistributionMapping.cpp:89
bool empty() const noexcept
Definition: AMReX_DistributionMapping.H:129
bool operator!=(const DistributionMapping &rhs) const noexcept
Are the distributions different?
Definition: AMReX_DistributionMapping.cpp:101
std::ostream & writeOn(std::ostream &os) const
Definition: AMReX_DistributionMapping.cpp:2021
static void LeastUsedTeams(Vector< int > &rteam, Vector< Vector< int > > &rworker, int nteams, int nworkers)
rteam: Least used ordering of Teams rworker[i]: Least used ordering of team workers for Team i
Definition: AMReX_DistributionMapping.cpp:239
static Strategy m_Strategy
Everyone uses the same Strategy – defaults to SFC.
Definition: AMReX_DistributionMapping.H:353
DistributionMapping() noexcept
The default constructor.
Definition: AMReX_DistributionMapping.cpp:303
static void Sort(std::vector< LIpair > &vec, bool reverse)
Definition: AMReX_DistributionMapping.cpp:177
std::shared_ptr< Ref > m_ref
The data – a reference-counted pointer to a Ref.
Definition: AMReX_DistributionMapping.H:362
static DistributionMapping makeRoundRobin(const MultiFab &weight)
Definition: AMReX_DistributionMapping.cpp:1751
void KnapSackProcessorMap(const std::vector< Long > &wgts, int nprocs, Real *efficiency=nullptr, bool do_full_knapsack=true, int nmax=std::numeric_limits< int >::max(), bool sort=true)
Definition: AMReX_DistributionMapping.cpp:850
std::pair< Long, int > LIpair
Definition: AMReX_DistributionMapping.H:298
const std::vector< bool > & getOwnerShip()
Definition: AMReX_DistributionMapping.cpp:1948
bool operator==(const DistributionMapping &rhs) const noexcept
Are the distributions equal?
Definition: AMReX_DistributionMapping.cpp:95
static DistributionMapping makeSFC(const MultiFab &weight, bool sort=true)
Definition: AMReX_DistributionMapping.cpp:1762
void RoundRobinProcessorMap(int nboxes, int nprocs, bool sort=true)
Definition: AMReX_DistributionMapping.cpp:455
const Vector< int > & getIndexArray()
Definition: AMReX_DistributionMapping.cpp:1929
void SFCProcessorMap(const BoxArray &boxes, const std::vector< Long > &wgts, int nprocs, bool sort=true)
Definition: AMReX_DistributionMapping.cpp:1493
const Vector< int > & ProcessorMap() const noexcept
Returns a constant reference to the mapping of boxes in the underlying BoxArray to the CPU that holds...
Definition: AMReX_DistributionMapping.cpp:47
RefID getRefID() const noexcept
This gives a unique ID of the reference, which is different from dmID above.
Definition: AMReX_DistributionMapping.H:379
static Strategy strategy()
Definition: AMReX_DistributionMapping.cpp:53
void RoundRobinDoIt(int nboxes, int nprocs, std::vector< LIpair > *LIpairV=nullptr, bool sort=true)
Definition: AMReX_DistributionMapping.cpp:371
static void Finalize()
Definition: AMReX_DistributionMapping.cpp:167
static void LeastUsedCPUs(int nprocs, Vector< int > &result)
Least used ordering of CPUs (by # of bytes of FAB data).
Definition: AMReX_DistributionMapping.cpp:192
std::weak_ptr< Ref > getWeakRef() const
Definition: AMReX_DistributionMapping.cpp:1967
Strategy
The distribution strategies.
Definition: AMReX_DistributionMapping.H:48
@ UNDEFINED
Definition: AMReX_DistributionMapping.H:48
@ KNAPSACK
Definition: AMReX_DistributionMapping.H:48
@ RRSFC
Definition: AMReX_DistributionMapping.H:48
@ ROUNDROBIN
Definition: AMReX_DistributionMapping.H:48
@ SFC
Definition: AMReX_DistributionMapping.H:48
void(DistributionMapping::*)(const BoxArray &, int) PVMF
A useful typedef.
Definition: AMReX_DistributionMapping.H:350
Long capacity() const noexcept
Definition: AMReX_DistributionMapping.H:128
static PVMF m_BuildMap
Pointer to one of the CreateProcessorMap() functions. Corresponds to the one specified by m_Strategy.
Definition: AMReX_DistributionMapping.H:358
std::istream & readFrom(std::istream &is)
Definition: AMReX_DistributionMapping.cpp:2000
static void ComputeDistributionMappingEfficiency(const DistributionMapping &dm, const std::vector< T > &cost, Real *efficiency)
Computes the average cost per MPI rank given a distribution mapping global cost vector.
Definition: AMReX_DistributionMapping.H:422
Base class for FabArray.
Definition: AMReX_FabArrayBase.H:41
An Array of FortranArrayBox(FAB)-like Objects.
Definition: AMReX_FabArray.H:344
a one-thingy-per-box distributed object
Definition: AMReX_LayoutData.H:13
A collection (stored as an array) of FArrayBox objects.
Definition: AMReX_MultiFab.H:38
int NProcs()
Process ID in MPI_COMM_WORLD.
Definition: AMReX_MPMD.cpp:122
int NProcsSub() noexcept
number of ranks in current frame
Definition: AMReX_ParallelContext.H:74
int NProcs() noexcept
return the number of MPI ranks local to the current Parallel Context
Definition: AMReX_ParallelDescriptor.H:243
int IOProcessorNumber() noexcept
Definition: AMReX_ParallelDescriptor.H:266
@ max
Definition: AMReX_ParallelReduce.H:17
Definition: AMReX_Amr.cpp:49
DistributionMapping MakeSimilarDM(const BoxArray &ba, const MultiFab &mf, const IntVect &ng)
Function that creates a DistributionMapping "similar" to that of a MultiFab.
Definition: AMReX_DistributionMapping.cpp:2034
const int[]
Definition: AMReX_BLProfiler.cpp:1664
std::ostream & operator<<(std::ostream &os, AmrMesh const &amr_mesh)
Definition: AMReX_AmrMesh.cpp:1236
Definition: AMReX_DistributionMapping.H:310
bool operator()(const LIpair &lhs, const LIpair &rhs) const noexcept
Definition: AMReX_DistributionMapping.H:311
Definition: AMReX_DistributionMapping.H:301
bool operator()(const LIpair &lhs, const LIpair &rhs) const noexcept
Definition: AMReX_DistributionMapping.H:302
Definition: AMReX_DistributionMapping.H:365
constexpr RefID() noexcept
Definition: AMReX_DistributionMapping.H:366
friend std::ostream & operator<<(std::ostream &os, const RefID &id)
Definition: AMReX_DistributionMapping.cpp:1993
bool operator==(const RefID &rhs) const noexcept
Definition: AMReX_DistributionMapping.H:369
void PrintPtr(std::ostream &os) const
Definition: AMReX_DistributionMapping.H:372
Ref * data
Definition: AMReX_DistributionMapping.H:375
const Ref * dataPtr() const noexcept
Definition: AMReX_DistributionMapping.H:371
bool operator!=(const RefID &rhs) const noexcept
Definition: AMReX_DistributionMapping.H:370
bool operator<(const RefID &rhs) const noexcept
Definition: AMReX_DistributionMapping.H:368
RefID(Ref *data_) noexcept
Definition: AMReX_DistributionMapping.H:367
Definition: AMReX_DistributionMapping.H:51
Ref()=default
Constructors to match those in DistributionMapping ....
std::vector< bool > m_ownership
true ownership
Definition: AMReX_DistributionMapping.H:67
Ref(const Vector< int > &pmap)
Definition: AMReX_DistributionMapping.H:57
Vector< int > m_pmap
index array for all boxes
Definition: AMReX_DistributionMapping.H:65
Vector< int > m_index_array
index array for local boxes owned by the team
Definition: AMReX_DistributionMapping.H:66
Ref(int len)
Definition: AMReX_DistributionMapping.H:55
void clear()
dtor, copy-ctor, copy-op=, move-ctor, and move-op= are compiler generated.
Definition: AMReX_DistributionMapping.H:63
Ref(Vector< int > &&pmap) noexcept
Definition: AMReX_DistributionMapping.H:59