34 template<
typename IType>
37 IType bat = ntot / npart;
38 IType residue = ntot % npart;
40 return std::make_tuple(
me * (bat + 1), (
me + 1) * (bat + 1));
42 return std::make_tuple(
me * bat + residue, (
me + 1) * bat + residue);
59 if (adist.size() != npart + 1)
60 adist.resize(npart + 1);
61 int bat = ntot / npart;
62 int residue = ntot % npart;
64 for (
int i = 1; i < npart; i++)
67 adist[i] = adist[i - 1] + bat + 1;
69 adist[i] = adist[i - 1] + bat;
79 IV bat = ntot / npart;
80 IV residue = ntot % npart;
81 std::vector<IV> partitions(npart, 0);
83 std::fill_n(partitions.begin() + residue, npart - residue, bat);
96 inline void FairDivideAligned(
const int ntot,
const int base,
const int npart,
const int me,
int& first,
int& last)
98 const int blocksize = (((ntot + npart - 1) / npart + base - 1) / base) * base;
99 first =
me * blocksize;
116 if (adist.size() != npart + 1)
117 adist.resize(npart + 1);
118 int bat = ntot / npart;
119 int residue = npart - ntot % npart;
121 for (
int i = 0; i < npart; i++)
124 adist[i + 1] = adist[i] + bat;
126 adist[i + 1] = adist[i] + bat + 1;
142 if (adist.size() != npart + 1)
143 adist.resize(npart + 1);
144 int bat = ntot / npart;
145 int residue = ntot % npart;
148 for (
int i = 1; i < npart; i++)
151 adist[i] = adist[i - 1] + bat + 1;
153 adist[i] = adist[i - 1] + bat;
154 if (
me >= adist[i] &&
me < adist[i + 1])
173 if (adist.size() != npart + 1)
174 adist.resize(npart + 1);
175 int bat = ntot / npart;
176 int residue = npart - ntot % npart;
179 for (
int i = 0; i < npart; i++)
182 adist[i + 1] = adist[i] + bat;
184 adist[i + 1] = adist[i] + bat + 1;
185 if (
me >= adist[i] &&
me < adist[i + 1])
int FairDivideHigh(int me, int ntot, int npart, IV &adist)
partition ntot elements among npart
void fill_n(T *x, size_t count, const T &value)
void FairDivideLow(int ntot, int npart, IV &adist)
partition ntot elements among npart
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.
void FairDivide(int ntot, int npart, IV &adist)
Partition ntot over npart.
std::tuple< IType, IType > FairDivideBoundary(IType me, IType ntot, IType npart)
Partition ntot over npart.
std::vector< IV > fairDivide(IV ntot, IV npart)
return the occupation vector for ntot entities partitioned npart ways.