DASH  0.3.0
dash::TeamSpec< MaxDimensions, IndexType > Class Template Reference

Specifies the arrangement of team units in a specified number of dimensions. More...

#include <TeamSpec.h>

Public Types

typedef IndexType index_type
 
typedef SizeType size_type
 
typedef std::array< SizeType, NumDimensions > extents_type
 
typedef std::integral_constant< dim_t, NumDimensions > ndim
 The number of dimension in the cartesian space. More...
 

Public Member Functions

 TeamSpec (Team &team=dash::Team::All())
 Constructor, creates an instance of TeamSpec from a team (set of units) with all team units organized linearly in the first dimension. More...
 
 TeamSpec (const self_t &other, const DistributionSpec< MaxDimensions > &distribution, Team &team=dash::Team::All())
 Constructor, creates an instance of TeamSpec with given extents from a team (set of units) and a distribution spec. More...
 
 TeamSpec (const DistributionSpec< MaxDimensions > &distribution, Team &team=dash::Team::All())
 Constructor, creates an instance of TeamSpec from a team (set of units) and a distribution spec. More...
 
template<typename ... Types>
 TeamSpec (SizeType value, Types ... values)
 Constructor, initializes new instance of TeamSpec with extents specified in argument list. More...
 
 TeamSpec (const std::array< SizeType, MaxDimensions > &extents)
 Constructor, initializes new instance of TeamSpec with extents specified in array by dimension. More...
 
void balance_extents ()
 Tries to equally distribute the units across the dimensions. More...
 
team_unit_t neighbor (std::initializer_list< int > offsets) const
 Resolve unit id at given offset in Cartesian team grid relative to the active unit's position in the team. More...
 
team_unit_t neighbor (const std::array< int, MaxDimensions > &offsets) const
 
team_unit_t periodic_neighbor (std::initializer_list< int > offsets) const
 Resolve unit id at given offset in Cartesian team grid relative to the active unit's position in the team. More...
 
team_unit_t periodic_neighbor (const std::array< int, MaxDimensions > &offsets) const
 
bool includes_index (IndexType index, dim_t dimension, IndexType dim_offset) const
 Whether the given index lies in the cartesian sub-space specified by a dimension and offset in the dimension. More...
 
SizeType num_units (dim_t dimension) const
 The number of units (extent) available in the given dimension. More...
 
template<typename... Args>
void resize (SizeType arg, Args... args)
 Change the extent of the cartesian space in every dimension. More...
 
template<typename SizeType_ >
void resize (const std::array< SizeType_, MaxDimensions > &extents)
 Change the extent of the cartesian space in every dimension. More...
 
void resize_dim (dim_t dim, SizeType extent)
 Change the extent of the cartesian space in the given dimension. More...
 
dim_t rank () const
 The actual number of dimensions with extent greater than 1 in this team arragement, that is the dimension of the vector space spanned by the team arrangement's extents. More...
 
bool operator== (const self_t &other) const
 Equality comparison operator. More...
 
constexpr bool operator!= (const self_t &other) const
 Inequality comparison operator. More...
 
void resize (const std::array< SizeType_, NumDimensions > &extents)
 Change the extent of the cartesian space in every dimension. More...
 
void resize (dim_t dim, SizeType extent)
 Change the extent of the cartesian space in the given dimension. More...
 
constexpr SizeType size () const noexcept
 The number of discrete elements within the space spanned by the coordinate. More...
 
constexpr const extents_type & extents () const noexcept
 Extents of the cartesian space, by dimension. More...
 
SizeType extent (dim_t dim) const
 The extent of the cartesian space in the given dimension. More...
 
constexpr IndexType at (IndexType arg, Args... args) const
 Convert the given coordinates to their respective linear index. More...
 
IndexType at (const std::array< OffsetType, NumDimensions > &point) const
 Convert the given cartesian point to its respective linear index. More...
 
IndexType at (const std::array< OffsetType, NumDimensions > &point, const ViewSpec_t &viewspec) const
 Convert the given cartesian point to a linear index, respective to the offsets specified in the given ViewSpec. More...
 
std::array< IndexType, NumDimensions > coords (IndexType index) const
 Convert given linear offset (index) to cartesian coordinates. More...
 
std::array< IndexType, NumDimensions > coords (IndexType index, const ViewSpec_t &viewspec) const
 Convert given linear offset (index) to cartesian coordinates with respect to a given viewspec. More...
 
constexpr std::enable_if<(U > 0), SizeType >::type x (SizeType offs) const
 Accessor for dimension 1 (x), enabled for dimensionality > 0. More...
 
constexpr std::enable_if<(U > 1), SizeType >::type y (SizeType offs) const
 Accessor for dimension 2 (y), enabled for dimensionality > 1. More...
 
constexpr std::enable_if<(U > 2), SizeType >::type z (SizeType offs) const
 Accessor for dimension 3 (z), enabled for dimensionality > 2. More...
 

Detailed Description

template<dim_t MaxDimensions, typename IndexType = dash::default_index_t>
class dash::TeamSpec< MaxDimensions, IndexType >

Specifies the arrangement of team units in a specified number of dimensions.

Size of TeamSpec implies the number of units in the team.

Reoccurring units are currently not supported.

Template Parameters
NumDimensionsNumber of dimensions
Examples:
ex.06.pattern-block-visualizer/main.cpp, ex.11.halo-stencil/main.cpp, and ex.11.simple-stencil/main.cpp.

Definition at line 33 of file TeamSpec.h.

Member Typedef Documentation

◆ ndim

typedef std::integral_constant<dim_t, NumDimensions> dash::CartesianIndexSpace< NumDimensions, Arrangement, IndexType >::ndim
inherited

The number of dimension in the cartesian space.

Definition at line 279 of file Cartesian.h.

Constructor & Destructor Documentation

◆ TeamSpec() [1/5]

template<dim_t MaxDimensions, typename IndexType = dash::default_index_t>
dash::TeamSpec< MaxDimensions, IndexType >::TeamSpec ( Team team = dash::Team::All())
inline

Constructor, creates an instance of TeamSpec from a team (set of units) with all team units organized linearly in the first dimension.

Definition at line 50 of file TeamSpec.h.

52  : _is_linear(true),
53  _myid(team.myid())
54  {
55  DASH_LOG_TRACE_VAR("TeamSpec(t)", team.is_null());
56  auto team_size = team.is_null() ? 0 : team.size();
57  _rank = 1;
58  this->_extents[0] = team_size;
59  for (auto d = 1; d < MaxDimensions; ++d) {
60  this->_extents[d] = 1;
61  }
62  this->resize(this->_extents);
63  }
void resize(SizeType arg, Args... args)
Change the extent of the cartesian space in every dimension.
Definition: TeamSpec.h:412

◆ TeamSpec() [2/5]

template<dim_t MaxDimensions, typename IndexType = dash::default_index_t>
dash::TeamSpec< MaxDimensions, IndexType >::TeamSpec ( const self_t other,
const DistributionSpec< MaxDimensions > &  distribution,
Team team = dash::Team::All() 
)
inline

Constructor, creates an instance of TeamSpec with given extents from a team (set of units) and a distribution spec.

The number of elements in the distribution different from NONE must be equal to the rank of the extents.

This constructor adjusts extents according to given distribution spec if the passed team spec has been default constructed.

Example:

TeamSpec<2> ts(
// default-constructed, extents: [Team::All().size(), 1]
TeamSpec<2>(),
// distributed in dimension 1 (y)
DistSpec<2>(NONE, BLOCKED),
Team::All().split(2));
// Will be adjusted to:
size_t units_x = ts.extent(0); // -> 1
size_t units_y = ts.extent(1); // -> Team::All().size() / 2

Definition at line 88 of file TeamSpec.h.

92  : CartesianIndexSpace<MaxDimensions, ROW_MAJOR, IndexType>(
93  other.extents()),
94  _myid(team.myid())
95  {
96  DASH_LOG_TRACE_VAR("TeamSpec(ts, dist, t)", team.is_null());
97 #if 0
98  if (this->size() != team.size()) {
99  DASH_THROW(
101  "Size of team " << team.size() << " differs from " <<
102  "size of teamspec " << this->size() << " in TeamSpec()");
103  }
104 #endif
105  // Test if other teamspec has been default-constructed and has
106  // to be rearranged for a distribution with higher rank:
107  if (other._is_linear && distribution.rank() > 1) {
108  // Set extent of teamspec in the dimension the distribution is
109  // different from NONE:
110  if (distribution.is_tiled()) {
111  bool major_tiled_dim_set = false;
112  for (auto d = 0; d < MaxDimensions; ++d) {
113  this->_extents[d] = 1;
114  if (!major_tiled_dim_set &&
115  distribution[d].type == dash::internal::DIST_TILE) {
116  this->_extents[d] = team.size();
117  major_tiled_dim_set = true;
118  }
119  }
120  } else {
121  for (auto d = 0; d < MaxDimensions; ++d) {
122  if (distribution[d].type == dash::internal::DIST_NONE) {
123  this->_extents[d] = 1;
124  } else {
125  // Use size of given team; possibly different from size
126  // of default-constructed team spec:
127  this->_extents[d] = team.size();
128  }
129  }
130  }
131  }
132  update_rank();
133  DASH_LOG_TRACE_VAR("TeamSpec(ts, dist, t)", this->_extents);
134  this->resize(this->_extents);
135  DASH_LOG_TRACE_VAR("TeamSpec(ts, dist, t)", this->size());
136  }
constexpr SizeType size() const noexcept
The number of discrete elements within the space spanned by the coordinate.
Definition: Cartesian.h:395
void resize(SizeType arg, Args... args)
Change the extent of the cartesian space in every dimension.
Definition: TeamSpec.h:412

◆ TeamSpec() [3/5]

template<dim_t MaxDimensions, typename IndexType = dash::default_index_t>
dash::TeamSpec< MaxDimensions, IndexType >::TeamSpec ( const DistributionSpec< MaxDimensions > &  distribution,
Team team = dash::Team::All() 
)
inline

Constructor, creates an instance of TeamSpec from a team (set of units) and a distribution spec.

All but one element in the distribution spec must be NONE.

Definition at line 143 of file TeamSpec.h.

146  : _myid(team.myid())
147  {
148  DASH_LOG_TRACE_VAR("TeamSpec(dist, t)", team.is_null());
149  bool distrib_dim_set = false;
150  if (distribution.is_tiled()) {
151  bool major_tiled_dim_set = false;
152  for (auto d = 0; d < MaxDimensions; ++d) {
153  this->_extents[d] = 1;
154  if (!major_tiled_dim_set &&
155  distribution[d].type == dash::internal::DIST_TILE) {
156  this->_extents[d] = team.size();
157  major_tiled_dim_set = true;
158  }
159  }
160  } else {
161  for (auto d = 0; d < MaxDimensions; ++d) {
162  if (distribution[d].type == dash::internal::DIST_NONE) {
163  this->_extents[d] = 1;
164  } else {
165  this->_extents[d] = team.size();
166  if (distrib_dim_set) {
167  DASH_THROW(
169  "TeamSpec(DistributionSpec, Team) only allows "
170  "one distributed dimension");
171  }
172  distrib_dim_set = true;
173  }
174  }
175  }
176  update_rank();
177  DASH_LOG_TRACE_VAR("TeamSpec(dist, t)", this->_extents);
178  this->resize(this->_extents);
179  DASH_LOG_TRACE_VAR("TeamSpec(dist, t)", this->size());
180  }
constexpr SizeType size() const noexcept
The number of discrete elements within the space spanned by the coordinate.
Definition: Cartesian.h:395
void resize(SizeType arg, Args... args)
Change the extent of the cartesian space in every dimension.
Definition: TeamSpec.h:412

◆ TeamSpec() [4/5]

template<dim_t MaxDimensions, typename IndexType = dash::default_index_t>
template<typename ... Types>
dash::TeamSpec< MaxDimensions, IndexType >::TeamSpec ( SizeType  value,
Types ...  values 
)
inline

Constructor, initializes new instance of TeamSpec with extents specified in argument list.

Example:

TeamSpec<3> ts(1,2,3); // extents 1x2x3

Definition at line 193 of file TeamSpec.h.

195  CartesianIndexSpace(value, values...),
196  _myid(dash::Team::All().myid())
197  {
198  update_rank();
199  this->resize(this->_extents);
200  DASH_LOG_TRACE_VAR("TeamSpec(size,...)", this->_extents);
201  }
global_unit_t myid()
Shortcut to query the global unit ID of the calling unit.
constexpr CartesianIndexSpace()=default
Default constructor, creates a cartesian index space of extent 0 in all dimensions.
void resize(SizeType arg, Args... args)
Change the extent of the cartesian space in every dimension.
Definition: TeamSpec.h:412
static Team & All()
The invariant Team instance containing all available units.
Definition: Team.h:213

◆ TeamSpec() [5/5]

template<dim_t MaxDimensions, typename IndexType = dash::default_index_t>
dash::TeamSpec< MaxDimensions, IndexType >::TeamSpec ( const std::array< SizeType, MaxDimensions > &  extents)
inline

Constructor, initializes new instance of TeamSpec with extents specified in array by dimension.

Example:

TeamSpec<3> ts({ 1,2,3 }); // extents 1x2x3

Definition at line 213 of file TeamSpec.h.

216  _myid(dash::Team::All().myid())
217  {
218  update_rank();
219  this->resize(this->_extents);
220  DASH_LOG_TRACE_VAR("TeamSpec({extents})", this->_extents);
221  }
global_unit_t myid()
Shortcut to query the global unit ID of the calling unit.
constexpr CartesianIndexSpace()=default
Default constructor, creates a cartesian index space of extent 0 in all dimensions.
constexpr const extents_type & extents() const noexcept
Extents of the cartesian space, by dimension.
Definition: Cartesian.h:402
void resize(SizeType arg, Args... args)
Change the extent of the cartesian space in every dimension.
Definition: TeamSpec.h:412
static Team & All()
The invariant Team instance containing all available units.
Definition: Team.h:213

Member Function Documentation

◆ at() [1/3]

constexpr IndexType dash::CartesianIndexSpace< NumDimensions, Arrangement, IndexType >::at ( IndexType  arg,
Args...  args 
) const
inlineinherited

Convert the given coordinates to their respective linear index.

Parameters
argsAn argument list consisting of the coordinates, ordered by, dimension (x, y, z, ...)

Definition at line 429 of file Cartesian.h.

Referenced by dash::TeamSpec< NumDimensions, IndexType >::neighbor(), and dash::TeamSpec< NumDimensions, IndexType >::periodic_neighbor().

430  {
431  static_assert(
432  sizeof...(Args) == NumDimensions-1,
433  "Invalid number of arguments");
434  return at<AtArrangement>(
435  std::array<IndexType, NumDimensions> {{
436  arg, (IndexType)(args) ... }}
437  );
438  }

◆ at() [2/3]

IndexType dash::CartesianIndexSpace< NumDimensions, Arrangement, IndexType >::at ( const std::array< OffsetType, NumDimensions > &  point) const
inlineinherited

Convert the given cartesian point to its respective linear index.

Parameters
pointAn array containing the coordinates, ordered by dimension (x, y, z, ...)

Definition at line 449 of file Cartesian.h.

450  {
451  SizeType offs = 0;
452  DASH_ASSERT_GT(_size, 0, "CartesianIndexSpace has size 0");
453  for (auto i = 0; i < NumDimensions; i++) {
454  DASH_ASSERT_RANGE(
455  0,
456  static_cast<IndexType>(point[i]),
457  static_cast<IndexType>(_extents[i]-1),
458  "Given coordinate for CartesianIndexSpace::at() exceeds extent");
459  SizeType offset_dim = 0;
460  if (AtArrangement == ROW_MAJOR) {
461  offset_dim = _offset_row_major[i];
462  } else if (AtArrangement == COL_MAJOR) {
463  offset_dim = _offset_col_major[i];
464  }
465  offs += offset_dim * point[i];
466  }
467  return offs;
468  }

◆ at() [3/3]

IndexType dash::CartesianIndexSpace< NumDimensions, Arrangement, IndexType >::at ( const std::array< OffsetType, NumDimensions > &  point,
const ViewSpec_t viewspec 
) const
inlineinherited

Convert the given cartesian point to a linear index, respective to the offsets specified in the given ViewSpec.

Parameters
pointAn array containing the coordinates, ordered by dimension (x, y, z, ...)
viewspecAn instance of ViewSpec to apply to the given point before resolving the linear index.

Definition at line 482 of file Cartesian.h.

484  {
485  std::array<OffsetType, NumDimensions> coords{};
486  for (auto d = 0; d < NumDimensions; ++d) {
487  coords[d] = point[d] + viewspec.offset(d);
488  }
489  return at(coords);
490  }
std::array< IndexType, NumDimensions > coords(IndexType index) const
Convert given linear offset (index) to cartesian coordinates.
Definition: Cartesian.h:497
constexpr IndexType at(IndexType arg, Args... args) const
Convert the given coordinates to their respective linear index.
Definition: Cartesian.h:429

◆ balance_extents()

template<dim_t MaxDimensions, typename IndexType = dash::default_index_t>
void dash::TeamSpec< MaxDimensions, IndexType >::balance_extents ( )
inline

Tries to equally distribute the units across the dimensions.

The number of units is determined by the current state of the extents.

Example:

TeamSpec<3> ts({ 21,2,3 }); // extents 21x2x3 == 126 units
ts.balance_extents(); // extents 7x6x3

Definition at line 234 of file TeamSpec.h.

235  {
236  DASH_LOG_TRACE_VAR("TeamSpec.balance_extents()", this->_extents);
237  DASH_LOG_TRACE_VAR("TeamSpec.balance_extents()", this->size());
238  if(MaxDimensions <= 1) {
239  return;
240  }
241 
242  std::multiset<SizeType> new_extents;
243 
244  SizeType num_units = 1;
245  for (auto d = 0; d < MaxDimensions; ++d) {
246  num_units *= this->_extents[d];
247  this->_extents[d] = 1;
248  new_extents.insert(1);
249  }
250  _is_linear = false;
251 
252  // Find best surface-to-volume:
253  auto teamsize_prime_factors = dash::math::factorize(num_units);
254  // Equally distribute factors to extents.
255  // Start with the largest factors and multiply them onto the lowest
256  // value.
257  for (auto it = teamsize_prime_factors.rbegin();
258  it != teamsize_prime_factors.rend();
259  ++it) {
260  DASH_LOG_TRACE("TeamSpec.balance_extents()",
261  "factor:", it->first, "x", it->second);
262  for (auto i = 1; i < it->second + 1; ++i) {
263  new_extents.insert(it->first * *new_extents.begin());
264  new_extents.erase(new_extents.begin());
265  }
266  }
267 
268  int d = 0;
269  for (auto it = new_extents.rbegin();
270  it != new_extents.rend();
271  ++it, ++d) {
272  this->_extents[d] = *it;
273  }
274 
275  this->resize(this->_extents);
276  update_rank();
277  DASH_LOG_TRACE_VAR("TeamSpec.balance_extents() ->", this->_extents);
278  }
SizeType num_units(dim_t dimension) const
The number of units (extent) available in the given dimension.
Definition: TeamSpec.h:403
constexpr SizeType size() const noexcept
The number of discrete elements within the space spanned by the coordinate.
Definition: Cartesian.h:395
void resize(SizeType arg, Args... args)
Change the extent of the cartesian space in every dimension.
Definition: TeamSpec.h:412

◆ coords() [1/2]

std::array<IndexType, NumDimensions> dash::CartesianIndexSpace< NumDimensions, Arrangement, IndexType >::coords ( IndexType  index) const
inlineinherited

Convert given linear offset (index) to cartesian coordinates.

Inverse of at(...).

Definition at line 497 of file Cartesian.h.

Referenced by dash::TeamSpec< NumDimensions, IndexType >::neighbor(), and dash::TeamSpec< NumDimensions, IndexType >::periodic_neighbor().

499  {
500  DASH_ASSERT_GT(_size, 0, "CartesianIndexSpace has size 0");
501  DASH_ASSERT_RANGE(
502  0, index, static_cast<IndexType>(_size-1),
503  "Given index for CartesianIndexSpace::coords() is out of bounds");
504 
505  ::std::array<IndexType, NumDimensions> pos{};
506  if (CoordArrangement == ROW_MAJOR) {
507  for(auto i = 0; i < NumDimensions; ++i) {
508  pos[i] = index / _offset_row_major[i];
509  index = index % _offset_row_major[i];
510  }
511  } else if (CoordArrangement == COL_MAJOR) {
512  for(auto i = NumDimensions-1; i >= 0; --i) {
513  pos[i] = index / _offset_col_major[i];
514  index = index % _offset_col_major[i];
515  }
516  }
517  return pos;
518  }
constexpr std::enable_if< std::is_integral< IndexType >::value, IndexType >::type index(IndexType idx)
Definition: Iterator.h:60

◆ coords() [2/2]

std::array<IndexType, NumDimensions> dash::CartesianIndexSpace< NumDimensions, Arrangement, IndexType >::coords ( IndexType  index,
const ViewSpec_t viewspec 
) const
inlineinherited

Convert given linear offset (index) to cartesian coordinates with respect to a given viewspec.

Inverse of at(...).

Definition at line 526 of file Cartesian.h.

529  {
530  std::array<IndexType, NumDimensions> pos{};
531  extents_type offset;
532  if (CoordArrangement == ROW_MAJOR)
533  {
534  offset[NumDimensions-1] = 1;
535  for(auto i = NumDimensions-2; i >= 0; --i)
536  offset[i] = offset[i+1] * viewspec.extent(i+1);
537 
538  for(auto i = 0; i < NumDimensions; ++i)
539  {
540  pos[i] = index / offset[i] + viewspec.offset(i);
541  index = index % offset[i];
542  }
543  }
544  else if (CoordArrangement == COL_MAJOR)
545  {
546  offset[0] = 1;
547  for(auto i = 1; i < NumDimensions; ++i)
548  offset[i] = offset[i-1] * viewspec.extent(i-1);
549 
550  for(auto i = NumDimensions-1; i >= 0; --i)
551  {
552  pos[i] = index / offset[i] + viewspec.offset(i);
553  index = index % offset[i];
554  }
555  }
556  return pos;
557  }
constexpr std::enable_if< std::is_integral< IndexType >::value, IndexType >::type index(IndexType idx)
Definition: Iterator.h:60

◆ extent()

SizeType dash::CartesianIndexSpace< NumDimensions, Arrangement, IndexType >::extent ( dim_t  dim) const
inlineinherited

The extent of the cartesian space in the given dimension.

Parameters
dimThe dimension in the coordinate
Returns
The extent in the given dimension

Definition at line 412 of file Cartesian.h.

Referenced by dash::TeamSpec< NumDimensions, IndexType >::num_units(), and dash::TeamSpec< NumDimensions, IndexType >::resize_dim().

412  {
413  DASH_ASSERT_RANGE(
414  0, dim, NumDimensions-1,
415  "Given dimension " << dim <<
416  " for CartesianIndexSpace::extent(dim) is out of bounds");
417  return _extents[dim];
418  }

◆ extents()

constexpr const extents_type& dash::CartesianIndexSpace< NumDimensions, Arrangement, IndexType >::extents ( ) const
inlinenoexceptinherited

Extents of the cartesian space, by dimension.

Definition at line 402 of file Cartesian.h.

Referenced by dash::TeamSpec< NumDimensions, IndexType >::resize().

402  {
403  return _extents;
404  }

◆ includes_index()

template<dim_t MaxDimensions, typename IndexType = dash::default_index_t>
bool dash::TeamSpec< MaxDimensions, IndexType >::includes_index ( IndexType  index,
dim_t  dimension,
IndexType  dim_offset 
) const
inline

Whether the given index lies in the cartesian sub-space specified by a dimension and offset in the dimension.

Definition at line 385 of file TeamSpec.h.

389  {
390  if (_rank == 1) {
391  // Shortcut for trivial case
392  return (index >= 0 && index < this->size());
393  }
394  return parent_t::includes_index(index, dimension, dim_offset);
395  }
constexpr std::enable_if< std::is_integral< IndexType >::value, IndexType >::type index(IndexType idx)
Definition: Iterator.h:60
constexpr SizeType size() const noexcept
The number of discrete elements within the space spanned by the coordinate.
Definition: Cartesian.h:395

◆ neighbor()

template<dim_t MaxDimensions, typename IndexType = dash::default_index_t>
team_unit_t dash::TeamSpec< MaxDimensions, IndexType >::neighbor ( std::initializer_list< int >  offsets) const
inline

Resolve unit id at given offset in Cartesian team grid relative to the active unit's position in the team.

Example:

TeamSpec<2> teamspec(7,4);
// west neighbor is offset -1 in column dimension:
team_unit_t neighbor_west = teamspec.neigbor({ 0, -1 });
// second south neighbor is offset -2 in row dimension:
team_unit_t neighbor_west = teamspec.neigbor({ -2, 0 });
Returns
The unit id at given offset in the team grid, relative to the active unit's position in the team, or DART_UNDEFINED_UNIT_ID if the offset is out of bounds.

Definition at line 298 of file TeamSpec.h.

Referenced by dash::TeamSpec< NumDimensions, IndexType >::neighbor().

299  {
300  auto neighbor_coords = this->coords(_myid);
301  dim_t d = 0;
302  for (auto offset_d : offsets) {
303  neighbor_coords[d] += offset_d;
304  if (neighbor_coords[d] < 0 ||
305  neighbor_coords[d] >= this->_extents[d]) {
306  return UNDEFINED_TEAM_UNIT_ID;
307  }
308  ++d;
309  }
310  return team_unit_t(static_cast<dart_unit_t>(this->at(neighbor_coords)));
311  }
constexpr team_unit_t UNDEFINED_TEAM_UNIT_ID
Invalid local unit ID.
Definition: Types.h:341
int dim_t
Scalar type for a dimension value, with 0 indicating the first dimension.
Definition: Types.h:39
std::array< IndexType, NumDimensions > coords(IndexType index) const
Convert given linear offset (index) to cartesian coordinates.
Definition: Cartesian.h:497
constexpr IndexType at(IndexType arg, Args... args) const
Convert the given coordinates to their respective linear index.
Definition: Cartesian.h:429
struct dash::unit_id< dash::local_unit, dart_team_unit_t > team_unit_t
Unit ID to use for team-local IDs.
Definition: Types.h:319

◆ num_units()

template<dim_t MaxDimensions, typename IndexType = dash::default_index_t>
SizeType dash::TeamSpec< MaxDimensions, IndexType >::num_units ( dim_t  dimension) const
inline

The number of units (extent) available in the given dimension.

Parameters
dimensionThe dimension
Returns
The number of units in the given dimension

Definition at line 403 of file TeamSpec.h.

Referenced by dash::TeamSpec< NumDimensions, IndexType >::balance_extents().

404  {
405  return parent_t::extent(dimension);
406  }
SizeType extent(dim_t dim) const
The extent of the cartesian space in the given dimension.
Definition: Cartesian.h:412

◆ operator!=()

constexpr bool dash::CartesianIndexSpace< NumDimensions, Arrangement, IndexType >::operator!= ( const self_t other) const
inlineinherited

Inequality comparison operator.

Definition at line 342 of file Cartesian.h.

342  {
343  return !(*this == other);
344  }

◆ operator==()

bool dash::CartesianIndexSpace< NumDimensions, Arrangement, IndexType >::operator== ( const self_t other) const
inlineinherited

Equality comparison operator.

Definition at line 322 of file Cartesian.h.

322  {
323  if (this == &other) {
324  return true;
325  }
326  for(auto i = 0; i < NumDimensions; i++) {
327  if (_extents[i] != other._extents[i]) {
328  return false;
329  }
330  // Comparing either row- or column major offsets suffices:
331  if (_offset_row_major[i] != other._offset_row_major[i]) {
332  return false;
333  }
334  }
335  // No need to compare _size as it is derived from _extents.
336  return true;
337  }

◆ periodic_neighbor()

template<dim_t MaxDimensions, typename IndexType = dash::default_index_t>
team_unit_t dash::TeamSpec< MaxDimensions, IndexType >::periodic_neighbor ( std::initializer_list< int >  offsets) const
inline

Resolve unit id at given offset in Cartesian team grid relative to the active unit's position in the team.

Offsets wrap around in every dimension as in a torus topology.

Example:

// assuming dash::myid() == 1, i.e. team spec coordinates are (0,1)
TeamSpec<2> teamspec(2,2);
// west neighbor is offset -1 in column dimension:
team_unit_t neighbor_west = teamspec.neigbor_periodic({ 0, -1 });
// -> unit 0
// second south neighbor at offset -2 in row dimension wraps around
// to row coordinate 0:
team_unit_t neighbor_west = teamspec.neigbor_periodic({ -2, 0 });
// -> unit 1
Returns
The unit id at given offset in the team grid, relative to the active unit's position in the team. If an offset is out of bounds, it is wrapped around in the respective dimension as in a torus topology.

Definition at line 350 of file TeamSpec.h.

Referenced by dash::TeamSpec< NumDimensions, IndexType >::periodic_neighbor().

351  {
352  auto neighbor_coords = this->coords(_myid);
353  dim_t d = 0;
354  for (auto offset_d : offsets) {
355  neighbor_coords[d] += offset_d;
356  if (neighbor_coords[d] < 0) {
357  neighbor_coords[d] = this->_extents[d] + offset_d;
358  } else if(neighbor_coords[d] >= this->_extents[d]) {
359  neighbor_coords[d] %= this->_extents[d];
360  }
361  ++d;
362  }
363  return team_unit_t(static_cast<dart_unit_t>(this->at(neighbor_coords)));
364  }
int dim_t
Scalar type for a dimension value, with 0 indicating the first dimension.
Definition: Types.h:39
std::array< IndexType, NumDimensions > coords(IndexType index) const
Convert given linear offset (index) to cartesian coordinates.
Definition: Cartesian.h:497
constexpr IndexType at(IndexType arg, Args... args) const
Convert the given coordinates to their respective linear index.
Definition: Cartesian.h:429
struct dash::unit_id< dash::local_unit, dart_team_unit_t > team_unit_t
Unit ID to use for team-local IDs.
Definition: Types.h:319

◆ rank()

template<dim_t MaxDimensions, typename IndexType = dash::default_index_t>
dim_t dash::TeamSpec< MaxDimensions, IndexType >::rank ( ) const
inline

The actual number of dimensions with extent greater than 1 in this team arragement, that is the dimension of the vector space spanned by the team arrangement's extents.

Example:

TeamSpec<3> ts(1,2,3); // extents 1x2x3
ts.rank(); // returns 2, as one dimension has extent 1

Definition at line 454 of file TeamSpec.h.

455  {
456  return _rank;
457  }

◆ resize() [1/4]

void dash::CartesianIndexSpace< NumDimensions, Arrangement, IndexType >::resize ( const std::array< SizeType_, NumDimensions > &  extents)
inlineinherited

Change the extent of the cartesian space in every dimension.

Definition at line 363 of file Cartesian.h.

363  {
364  // Update size:
365  _size = 1;
366  for(auto i = 0; i < NumDimensions; i++ ) {
367  _extents[i] = static_cast<SizeType>(extents[i]);
368  _size *= _extents[i];
369  }
370  // Update offsets:
371  _offset_row_major[NumDimensions-1] = 1;
372  for(auto i = NumDimensions-2; i >= 0; --i) {
373  _offset_row_major[i] = _offset_row_major[i+1] * _extents[i+1];
374  }
375  _offset_col_major[0] = 1;
376  for(auto i = 1; i < NumDimensions; ++i) {
377  _offset_col_major[i] = _offset_col_major[i-1] * _extents[i-1];
378  }
379  }
constexpr const extents_type & extents() const noexcept
Extents of the cartesian space, by dimension.
Definition: Cartesian.h:402

◆ resize() [2/4]

void dash::CartesianIndexSpace< NumDimensions, Arrangement, IndexType >::resize ( dim_t  dim,
SizeType  extent 
)
inlineinherited

Change the extent of the cartesian space in the given dimension.

Definition at line 384 of file Cartesian.h.

384  {
385  _extents[dim] = extent;
386  resize(_extents);
387  }
void resize(SizeType arg, Args... args)
Change the extent of the cartesian space in every dimension.
Definition: Cartesian.h:350
SizeType extent(dim_t dim) const
The extent of the cartesian space in the given dimension.
Definition: Cartesian.h:412

◆ resize() [3/4]

template<dim_t MaxDimensions, typename IndexType = dash::default_index_t>
template<typename... Args>
void dash::TeamSpec< MaxDimensions, IndexType >::resize ( SizeType  arg,
Args...  args 
)
inline

Change the extent of the cartesian space in every dimension.

Definition at line 412 of file TeamSpec.h.

Referenced by dash::TeamSpec< NumDimensions, IndexType >::balance_extents(), dash::make_team_spec(), dash::TeamSpec< NumDimensions, IndexType >::resize(), dash::TeamSpec< NumDimensions, IndexType >::resize_dim(), and dash::TeamSpec< NumDimensions, IndexType >::TeamSpec().

413  {
414  static_assert(
415  sizeof...(Args) == MaxDimensions-1,
416  "Invalid number of arguments");
417  std::array<SizeType, MaxDimensions> extents =
418  {{ arg, (SizeType)(args)... }};
419  resize(extents);
420  }
constexpr const extents_type & extents() const noexcept
Extents of the cartesian space, by dimension.
Definition: Cartesian.h:402
void resize(SizeType arg, Args... args)
Change the extent of the cartesian space in every dimension.
Definition: TeamSpec.h:412

◆ resize() [4/4]

template<dim_t MaxDimensions, typename IndexType = dash::default_index_t>
template<typename SizeType_ >
void dash::TeamSpec< MaxDimensions, IndexType >::resize ( const std::array< SizeType_, MaxDimensions > &  extents)
inline

Change the extent of the cartesian space in every dimension.

Definition at line 426 of file TeamSpec.h.

427  {
428  _is_linear = false;
430  update_rank();
431  }
void resize(SizeType arg, Args... args)
Change the extent of the cartesian space in every dimension.
Definition: Cartesian.h:350
constexpr const extents_type & extents() const noexcept
Extents of the cartesian space, by dimension.
Definition: Cartesian.h:402

◆ resize_dim()

template<dim_t MaxDimensions, typename IndexType = dash::default_index_t>
void dash::TeamSpec< MaxDimensions, IndexType >::resize_dim ( dim_t  dim,
SizeType  extent 
)
inline

Change the extent of the cartesian space in the given dimension.

Definition at line 436 of file TeamSpec.h.

437  {
438  this->_extents[dim] = extent;
439  resize(this->_extents);
440  }
SizeType extent(dim_t dim) const
The extent of the cartesian space in the given dimension.
Definition: Cartesian.h:412
void resize(SizeType arg, Args... args)
Change the extent of the cartesian space in every dimension.
Definition: TeamSpec.h:412

◆ size()

constexpr SizeType dash::CartesianIndexSpace< NumDimensions, Arrangement, IndexType >::size ( ) const
inlinenoexceptinherited

The number of discrete elements within the space spanned by the coordinate.

Returns
The number of discrete elements in the coordinate's space

Definition at line 395 of file Cartesian.h.

Referenced by dash::TeamSpec< NumDimensions, IndexType >::balance_extents(), dash::TeamSpec< NumDimensions, IndexType >::includes_index(), dash::make_team_spec(), and dash::TeamSpec< NumDimensions, IndexType >::TeamSpec().

395  {
396  return _size;
397  }

◆ x()

constexpr std::enable_if< (U > 0), SizeType >::type dash::CartesianIndexSpace< NumDimensions, Arrangement, IndexType >::x ( SizeType  offs) const
inlineinherited

Accessor for dimension 1 (x), enabled for dimensionality > 0.

Definition at line 591 of file Cartesian.h.

591  {
592  return coords(offs)[0];
593  }
std::array< IndexType, NumDimensions > coords(IndexType index) const
Convert given linear offset (index) to cartesian coordinates.
Definition: Cartesian.h:497

◆ y()

constexpr std::enable_if< (U > 1), SizeType >::type dash::CartesianIndexSpace< NumDimensions, Arrangement, IndexType >::y ( SizeType  offs) const
inlineinherited

Accessor for dimension 2 (y), enabled for dimensionality > 1.

Definition at line 600 of file Cartesian.h.

600  {
601  return coords(offs)[1];
602  }
std::array< IndexType, NumDimensions > coords(IndexType index) const
Convert given linear offset (index) to cartesian coordinates.
Definition: Cartesian.h:497

◆ z()

constexpr std::enable_if< (U > 2), SizeType >::type dash::CartesianIndexSpace< NumDimensions, Arrangement, IndexType >::z ( SizeType  offs) const
inlineinherited

Accessor for dimension 3 (z), enabled for dimensionality > 2.

Definition at line 609 of file Cartesian.h.

609  {
610  return coords(offs)[2];
611  }
std::array< IndexType, NumDimensions > coords(IndexType index) const
Convert given linear offset (index) to cartesian coordinates.
Definition: Cartesian.h:497

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