DASH  0.3.0
dash::Distribution Class Reference

Specifies how a Pattern distributes elements to units in a specific dimension. More...

#include <Distribution.h>

Public Member Functions

 Distribution ()=default
 Constructor, initializes Distribution with distribution type NONE. More...
 
 Distribution (dash::internal::DistributionType distType, int blockSize)
 Constructor, initializes Distribution with a distribution type and a block size. More...
 
 Distribution (const self_t &other)=default
 
self_toperator= (const self_t &other)=default
 
template<typename IndexType , typename SizeType >
IndexType local_index_to_block_coord (IndexType unit_teamspec_coord, IndexType local_index, SizeType num_units_in_dim) const
 Resolve the block coordinate for a given local index in the distribution's dimension. More...
 
template<typename IndexType , typename SizeType >
IndexType max_blocksize_in_range (IndexType range, SizeType num_units) const
 The maximum size of a single block within an extent for a given total number of units. More...
 
bool operator== (const Distribution &other) const
 Equality comparison operator. More...
 
bool operator!= (const Distribution &other) const
 Inequality comparison operator. More...
 

Public Attributes

dash::internal::DistributionType type {dash::internal::DIST_NONE}
 
dash::default_size_t blocksz {0}
 

Friends

std::ostream & operator<< (std::ostream &os, const self_t &distribution)
 

Related Functions

(Note that these are not member functions.)

const Distribution BLOCKED
 Distribution specifying that elements in a Pattern's dimension shall be distributed to units in even-sized blocks. More...
 
const Distribution CYCLIC
 Distribution specifying that elements in a Pattern's dimension shall be distributed by cycling among units. More...
 
const Distribution NONE
 Distribution specifying that elements in a Pattern's dimension shall not be distributed. More...
 
Distribution TILE (int blockSize)
 Distribution specifying that elements in a Pattern's dimension shall be distributed to units in a tiled blocks of the given size. More...
 
Distribution BLOCKCYCLIC (int blockSize)
 Distribution specifying that elements in a Pattern's dimension shall be distributed to units in blocks of the given size. More...
 

Detailed Description

Specifies how a Pattern distributes elements to units in a specific dimension.

Predefined configurations are

  • dash::BLOCKED
  • dash::BLOCKCYCLIC
  • dash::CYCLIC
  • dash::TILE
  • dash::NONE
See also
Pattern

Definition at line 24 of file Distribution.h.

Constructor & Destructor Documentation

◆ Distribution() [1/2]

dash::Distribution::Distribution ( )
default

Constructor, initializes Distribution with distribution type NONE.

Referenced by Distribution().

◆ Distribution() [2/2]

dash::Distribution::Distribution ( dash::internal::DistributionType  distType,
int  blockSize 
)
inline

Constructor, initializes Distribution with a distribution type and a block size.

Definition at line 47 of file Distribution.h.

References Distribution().

50  : type(distType),
51  blocksz(blockSize) {
52  }

Member Function Documentation

◆ local_index_to_block_coord()

template<typename IndexType , typename SizeType >
IndexType dash::Distribution::local_index_to_block_coord ( IndexType  unit_teamspec_coord,
IndexType  local_index,
SizeType  num_units_in_dim 
) const
inline

Resolve the block coordinate for a given local index in the distribution's dimension.

Definition at line 63 of file Distribution.h.

70  {
71  // NOTE: blocksize should be this->blocksz
72  SizeType local_block_offset = 0;
73  switch (type) {
74  case dash::internal::DIST_NONE:
75  // There is only one block in this dimension, so
76  // block coordinate is 0:
77  return 0;
78  case dash::internal::DIST_BLOCKED:
79  // Same as blockcyclic, but local block offset is
80  // always 0:
81  return unit_teamspec_coord;
82  case dash::internal::DIST_TILE:
83  // Same as blockcyclic
84  case dash::internal::DIST_BLOCKCYCLIC:
85  // Number of blocks local to the unit that are
86  // in front of the given local index:
87  local_block_offset = local_index / blocksz;
88  // Number of blocks of any unit that are in front
89  // of the given local index. Unit's coordinate in team
90  // spec is equivalent to the number of units in front of
91  // the unit.
92  return (local_block_offset * num_units_in_dim) +
93  unit_teamspec_coord;
94  case dash::internal::DIST_CYCLIC:
95  // Like blockcyclic, but with blocksize 1:
96  DASH_LOG_TRACE("Distribution.local_index_to_block_coord",
97  "unit_teamspec_coord", unit_teamspec_coord,
98  "local_index", local_index,
99  "num_units_in_dim", num_units_in_dim);
100  return unit_teamspec_coord + local_index * num_units_in_dim;
101  default:
102  DASH_THROW(
104  "Distribution type undefined in " <<
105  "local_index_to_block_coord");
106  }
107  }

◆ max_blocksize_in_range()

template<typename IndexType , typename SizeType >
IndexType dash::Distribution::max_blocksize_in_range ( IndexType  range,
SizeType  num_units 
) const
inline

The maximum size of a single block within an extent for a given total number of units.

Parameters
rangeNumber of elements to distribute
num_unitsNumber of units to which elements are distributed

Definition at line 114 of file Distribution.h.

Referenced by dash::ShiftTilePattern< NumDimensions, Arrangement, IndexType >::ndim(), dash::SeqTilePattern< NumDimensions, Arrangement, IndexType >::ndim(), dash::BlockPattern< 1, Arrangement, IndexType >::underfilled_blocksize(), dash::BlockPattern< 1, ROW_MAJOR, dash::default_index_t >::underfilled_blocksize(), and dash::TilePattern< NumDimensions, Arrangement, IndexType >::underfilled_blocksize().

119  {
120  DASH_LOG_TRACE("Distribution.max_blocksize_in_range()",
121  "range:", range, "nunits:", num_units);
122  switch (type) {
123  case dash::internal::DIST_NONE:
124  return range;
125  case dash::internal::DIST_BLOCKED:
126  return num_units == 0 ? 0 : dash::math::div_ceil(range, num_units);
127  case dash::internal::DIST_CYCLIC:
128  return 1;
129  case dash::internal::DIST_BLOCKCYCLIC:
130  case dash::internal::DIST_TILE:
131  DASH_LOG_TRACE("Distribution.max_blocksize_in_range",
132  "TILE", "blocksz:", blocksz);
133  // Shrink block size in dimension if it exceeds the number
134  // of elements in dimension:
135  return std::min<SizeType>(range, blocksz);
136  default:
137  DASH_THROW(
139  "Distribution type undefined in max_blocksize_in_range");
140  }
141  }

◆ operator!=()

bool dash::Distribution::operator!= ( const Distribution other) const
inline

Inequality comparison operator.

Definition at line 153 of file Distribution.h.

153  {
154  return !(*this == other);
155  }

◆ operator==()

bool dash::Distribution::operator== ( const Distribution other) const
inline

Equality comparison operator.

Definition at line 146 of file Distribution.h.

146  {
147  return (this->type == other.type &&
148  this->blocksz == other.blocksz);
149  }

Friends And Related Function Documentation

◆ BLOCKCYCLIC()

Distribution BLOCKCYCLIC ( int  blockSize)
related

Distribution specifying that elements in a Pattern's dimension shall be distributed to units in blocks of the given size.

◆ BLOCKED

const Distribution BLOCKED
related

Distribution specifying that elements in a Pattern's dimension shall be distributed to units in even-sized blocks.

Definition at line 165 of file Distribution.h.

◆ CYCLIC

const Distribution CYCLIC
related

Distribution specifying that elements in a Pattern's dimension shall be distributed by cycling among units.

Semantically equivalent to BLOCKCYCLIC(1) but with slight performance improvement.

Definition at line 174 of file Distribution.h.

◆ NONE

const Distribution NONE
related

Distribution specifying that elements in a Pattern's dimension shall not be distributed.

Definition at line 181 of file Distribution.h.

◆ TILE()

Distribution TILE ( int  blockSize)
related

Distribution specifying that elements in a Pattern's dimension shall be distributed to units in a tiled blocks of the given size.


The documentation for this class was generated from the following file: