13 #ifndef THRILL_COMMON_MATH_HEADER 14 #define THRILL_COMMON_MATH_HEADER 29 template <
typename IntegerType,
unsigned bits = (8 * sizeof(IntegerType))>
32 size_t s =
static_cast<size_t>(a) + static_cast<size_t>(b);
33 if (s >= (
size_t(1) << bits))
34 s = (
size_t(1) << bits) - 1;
35 return static_cast<IntegerType
>(s);
75 return Range(begin + shift, end + shift);
80 return x >= begin && x <
end;
93 return (i *
size() + parts - 1) / parts +
begin;
99 return ((index - begin) * parts) /
size();
104 return os <<
'[' << r.
begin <<
',' << r.
end <<
')';
111 size_t global_size,
size_t p,
size_t i) {
112 return Range(0, global_size).Partition(i, p);
116 size_t partition = k * p / global_size;
128 return n % 2 == 0 ? n - 1 : n;
146 size_t idle = (r * n / 2) % (n - 1);
152 return (r - p + n - 1) % (n - 1);
156 return (r - p + n) % n;
165 #endif // !THRILL_COMMON_MATH_HEADER static uint_pair max()
return an uint_pair instance containing the largest value possible
size_t size() const
size of range
size_t CalculateBeginOfPart(size_t i, size_t parts) const
Range(size_t begin, size_t end)
friend std::ostream & operator<<(std::ostream &os, const Range &r)
ostream-able
represents a 1 dimensional range (interval) [begin,end)
Range Partition(size_t i, size_t parts) const
bool IsValid() const
valid non-empty range (begin < end)
static size_t CalcOneFactorPeer(size_t r, size_t p, size_t n)
Calculate a Perfect Matching (1-Factor) on a Complete Graph.
bool Contains(size_t x) const
true if the Range contains x
static Range CalculateLocalRange(size_t global_size, size_t p, size_t i)
void swap(CountingPtr< A, D > &a1, CountingPtr< A, D > &a2) noexcept
static IntegerType AddTruncToType(const IntegerType &a, const IntegerType &b)
static size_t CalculatePartition(size_t global_size, size_t p, size_t k)
static uint_pair min()
return an uint_pair instance containing the smallest value possible
static size_t CalcOneFactorSize(size_t n)
Number of rounds in Perfect Matching (1-Factor).
size_t FindPartition(size_t index, size_t parts) const
Range operator+(const size_t &shift) const
return shifted Range
void Swap()
swap boundaries, making a valid range invalid.
bool IsEmpty() const
range is empty (begin == end)