QMCPACK
FairDivide.h File Reference

A collection of functions for dividing fairly. More...

+ Include dependency graph for FairDivide.h:
+ This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Functions

template<typename IType >
std::tuple< IType, IType > FairDivideBoundary (IType me, IType ntot, IType npart)
 Partition ntot over npart. More...
 
template<class IV >
void FairDivide (int ntot, int npart, IV &adist)
 Partition ntot over npart. More...
 
template<class IV >
std::vector< IV > fairDivide (IV ntot, IV npart)
 return the occupation vector for ntot entities partitioned npart ways. More...
 
void FairDivideAligned (const int ntot, const int base, const int npart, const int me, int &first, int &last)
 Partition ntot over npart and the size of each partition is a multiple of base size. More...
 
template<class IV >
void FairDivideLow (int ntot, int npart, IV &adist)
 partition ntot elements among npart More...
 
template<class IV >
int FairDivideHigh (int me, int ntot, int npart, IV &adist)
 partition ntot elements among npart More...
 
template<class IV >
int FairDivideLow (int me, int ntot, int npart, IV &adist)
 partition ntot elements among npart More...
 

Detailed Description

A collection of functions for dividing fairly.

Definition in file FairDivide.h.

Function Documentation

◆ FairDivide()

void FairDivide ( int  ntot,
int  npart,
IV &  adist 
)
inline

Partition ntot over npart.

Parameters
ntotthe total size
npartthe number of partitions
adistan index array

Simply divide ntot data among npart partitions so that the size of each group cannot differ by more than 1.

The array adist contains the offset for the i-th group, i.e., adist[i+1]-adist[i] is the number of elements for the i-th group.

Definition at line 57 of file FairDivide.h.

Referenced by QMCCostFunctionBatched::checkConfigurations(), QMCCostFunctionBatched::correlatedSampling(), and QMCCostFunctionBatched::fillOverlapHamiltonianMatrices().

58 {
59  if (adist.size() != npart + 1)
60  adist.resize(npart + 1);
61  int bat = ntot / npart;
62  int residue = ntot % npart;
63  adist[0] = 0;
64  for (int i = 1; i < npart; i++)
65  {
66  if (i < residue)
67  adist[i] = adist[i - 1] + bat + 1;
68  else
69  adist[i] = adist[i - 1] + bat;
70  }
71  adist[npart] = ntot;
72 }

◆ fairDivide()

std::vector<IV> fairDivide ( IV  ntot,
IV  npart 
)

return the occupation vector for ntot entities partitioned npart ways.

Definition at line 77 of file FairDivide.h.

References OMPstd::fill_n().

Referenced by QMCDriverNew::adjustGlobalWalkerCount(), MCPopulation::redistributeWalkers(), and qmcplusplus::TEST_CASE().

78 {
79  IV bat = ntot / npart;
80  IV residue = ntot % npart;
81  std::vector<IV> partitions(npart, 0);
82  std::fill_n(partitions.begin(), residue, bat + 1);
83  std::fill_n(partitions.begin() + residue, npart - residue, bat);
84  return partitions;
85 }
void fill_n(T *x, size_t count, const T &value)
Definition: OMPstd.hpp:21

◆ FairDivideAligned()

void FairDivideAligned ( const int  ntot,
const int  base,
const int  npart,
const int  me,
int &  first,
int &  last 
)
inline

Partition ntot over npart and the size of each partition is a multiple of base size.

Parameters
ntotthe total size
basethe base size
npartthe number of partitions
memy partition id [0,ntot)
firstthe beginning of my partition, can be equal and larger than ntot
lastthe end of my partition, must be smaller than ntot

Definition at line 96 of file FairDivide.h.

References qmcplusplus::Units::mass::me, and omptarget::min().

Referenced by SoaDistanceTableAB< T, D, SC >::evaluate(), SplineC2R< ST >::evaluateDetRatios(), SplineC2C< ST >::evaluateDetRatios(), SplineR2R< ST >::evaluateDetRatios(), SplineC2R< ST >::evaluateValue(), SplineC2C< ST >::evaluateValue(), SplineR2R< ST >::evaluateValue(), SplineC2COMPTarget< ST >::evaluateValue(), SplineC2ROMPTarget< ST >::evaluateValue(), SplineC2R< ST >::evaluateVGH(), SplineR2R< ST >::evaluateVGH(), SplineC2C< ST >::evaluateVGH(), SplineC2COMPTarget< ST >::evaluateVGH(), SplineC2ROMPTarget< ST >::evaluateVGH(), SplineC2R< ST >::evaluateVGHGH(), SplineR2R< ST >::evaluateVGHGH(), SplineC2C< ST >::evaluateVGHGH(), SplineC2COMPTarget< ST >::evaluateVGHGH(), SplineC2ROMPTarget< ST >::evaluateVGHGH(), SplineC2R< ST >::evaluateVGL(), SplineR2R< ST >::evaluateVGL(), SplineC2C< ST >::evaluateVGL(), and qmcplusplus::TEST_CASE().

97 {
98  const int blocksize = (((ntot + npart - 1) / npart + base - 1) / base) * base;
99  first = me * blocksize;
100  last = std::min((me + 1) * blocksize, ntot);
101  if (first > last)
102  first = last;
103 }
T min(T a, T b)

◆ FairDivideBoundary()

std::tuple<IType, IType> FairDivideBoundary ( IType  me,
IType  ntot,
IType  npart 
)
inline

Partition ntot over npart.

Parameters
meindex of boundaries being returned
ntotthe total size
npartthe number of partitions

Simply divide ntot data among npart partitions so that the size of each group cannot differ by more than 1. Return the boundaries of the partition associated with partition 'me'

Definition at line 35 of file FairDivide.h.

References qmcplusplus::Units::mass::me.

36 {
37  IType bat = ntot / npart;
38  IType residue = ntot % npart;
39  if (me < residue)
40  return std::make_tuple(me * (bat + 1), (me + 1) * (bat + 1));
41  else
42  return std::make_tuple(me * bat + residue, (me + 1) * bat + residue);
43 }

◆ FairDivideHigh()

int FairDivideHigh ( int  me,
int  ntot,
int  npart,
IV &  adist 
)
inline

partition ntot elements among npart

Parameters
merank [0,ntot)
ntottotal number of elements
npartnumber of partitions
adistdistribution offset
Returns
partition id to which me belongs

mypart satisfies adist[mypart] <= me < adist[mypart+1]

Definition at line 140 of file FairDivide.h.

References qmcplusplus::Units::mass::me.

141 {
142  if (adist.size() != npart + 1)
143  adist.resize(npart + 1);
144  int bat = ntot / npart;
145  int residue = ntot % npart;
146  int mypart = 0;
147  adist[0] = 0;
148  for (int i = 1; i < npart; i++)
149  {
150  if (i < residue)
151  adist[i] = adist[i - 1] + bat + 1;
152  else
153  adist[i] = adist[i - 1] + bat;
154  if (me >= adist[i] && me < adist[i + 1])
155  mypart = i;
156  }
157  adist[npart] = ntot;
158  return mypart;
159 }

◆ FairDivideLow() [1/2]

void FairDivideLow ( int  ntot,
int  npart,
IV &  adist 
)
inline

partition ntot elements among npart

Parameters
ntottotal number of elements
npartnumber of partitions
adistdistribution offset

adist[ip-1]-adist[ip] is the number of elements of ip partition This method makes the zero-th node equal to or less than 1.

Definition at line 114 of file FairDivide.h.

Referenced by HybridRepSetReader< SA >::create_atomic_centers_Gspace(), WalkerControlMPI::determineNewWalkerPopulation(), WalkerControl::determineNewWalkerPopulation(), SplineC2R< ST >::gather_tables(), SplineR2R< ST >::gather_tables(), SplineC2C< ST >::gather_tables(), SplineC2COMPTarget< ST >::gather_tables(), SplineC2ROMPTarget< ST >::gather_tables(), qmcplusplus::generateCuspInfo(), HybridRepSetReader< SA >::initialize_hybrid_pio_gather(), SplineSetReader< typename SA::SplineBase >::initialize_spline_pio_gather(), HDFWalkerInput_0_4::read_hdf5(), HDFWalkerInput_0_4::read_hdf5_scatter(), HDFWalkerInput_0_4::read_phdf5(), RMC::resetReptiles(), VMC::resetRun(), CSVMC::resetRun(), DMC::resetUpdateEngines(), DMC::run(), and qmcplusplus::TEST_CASE().

115 {
116  if (adist.size() != npart + 1)
117  adist.resize(npart + 1);
118  int bat = ntot / npart;
119  int residue = npart - ntot % npart;
120  adist[0] = 0;
121  for (int i = 0; i < npart; i++)
122  {
123  if (i < residue)
124  adist[i + 1] = adist[i] + bat;
125  else
126  adist[i + 1] = adist[i] + bat + 1;
127  }
128 }

◆ FairDivideLow() [2/2]

int FairDivideLow ( int  me,
int  ntot,
int  npart,
IV &  adist 
)
inline

partition ntot elements among npart

Parameters
merank [0,ntot)
ntottotal number of elements
npartnumber of partitions
adistdistribution offset
Returns
partition id to which me belongs

mypart satisfies adist[mypart] <= me < adist[mypart+1]

Definition at line 171 of file FairDivide.h.

References qmcplusplus::Units::mass::me.

172 {
173  if (adist.size() != npart + 1)
174  adist.resize(npart + 1);
175  int bat = ntot / npart;
176  int residue = npart - ntot % npart;
177  int mypart = 0;
178  adist[0] = 0;
179  for (int i = 0; i < npart; i++)
180  {
181  if (i < residue)
182  adist[i + 1] = adist[i] + bat;
183  else
184  adist[i + 1] = adist[i] + bat + 1;
185  if (me >= adist[i] && me < adist[i + 1])
186  mypart = i;
187  }
188  return mypart;
189 }