DASH  0.3.0
dash::Team Class Reference

A Team instance specifies a subset of all available units. More...

#include <Team.h>

Classes

struct  Deallocator
 
struct  iterator
 

Public Types

typedef struct dash::Team::iterator iterator
 
typedef struct dash::Team::Deallocator Deallocator
 

Public Member Functions

iterator begin ()
 
iterator end ()
 
 Team (Team &&t)
 Move-constructor. More...
 
Teamoperator= (Team &&t)
 Move-assignment operator. More...
 
 ~Team ()
 Destructor. More...
 
void register_deallocator (void *object, Deallocator::dealloc_function dealloc)
 Register a deallocator function for a team-allocated object. More...
 
void unregister_deallocator (void *object, Deallocator::dealloc_function dealloc)
 Unregister a deallocator function for a team-allocated object. More...
 
void free ()
 Call registered deallocator functions for all team-allocated objects. More...
 
Teamsplit (unsigned nParts)
 Split this Team's units into nParts child Team instances. More...
 
Teamlocality_split (dash::util::Locality::Scope scope, unsigned num_parts)
 Split this Team's units into child Team instances at the specified locality scope. More...
 
Teamlocality_split (dart_locality_scope_t scope, unsigned num_parts)
 Split this Team's units into child Team instances at the specified locality scope. More...
 
bool operator== (const Team &rhs) const
 Equality comparison operator. More...
 
bool operator!= (const Team &rhs) const
 Inequality comparison operator. More...
 
bool is_all () const
 Whether this Team contains all available units. More...
 
bool is_null () const
 Whether this Team is empty. More...
 
bool is_leaf () const
 Whether this Team is a leaf node in a Team hierarchy, i.e. More...
 
bool is_root () const
 Whether this Team is a root node in a Team hierarchy, i.e. More...
 
bool is_member (global_unit_t global_unit_id) const
 Whether the group associated with this Team instance contains the unit specified by global id. More...
 
Teamparent ()
 
Teamsub (size_t level=1)
 
Teambottom ()
 
void barrier () const
 
team_unit_t myid () const
 
size_t size () const
 The number of units in this team. More...
 
size_t position () const
 Index of this team relative to parent team. More...
 
size_t num_siblings () const
 Number of sibling teams relative to parent team. More...
 
dart_team_t dart_id () const
 Index of this team relative to global team dash::Team::All(). More...
 
size_t relative_id () const
 Index of this team relative to parent team. More...
 
team_unit_t relative_id (global_unit_t global_id)
 
global_unit_t global_id (team_unit_t local_id)
 Global unit id of specified local unit id. More...
 

Static Public Member Functions

static TeamAll ()
 The invariant Team instance containing all available units. More...
 
static global_unit_t GlobalUnitID ()
 The invariant unit ID in dash::Team::All(). More...
 
static TeamNull ()
 The invariant Team instance representing an undefined team. More...
 
static TeamGet (dart_team_t team_id)
 Get Team instance by id. More...
 
static void initialize ()
 Initialize the global team. More...
 
static void finalize ()
 Finalize all teams. More...
 

Friends

std::ostream & operator<< (std::ostream &os, const Team &team)
 

Detailed Description

A Team instance specifies a subset of all available units.

The Team containing the set of all units is always available via dash::Team::All().

Team is a move-only type:

  • no copy construction
  • no assignment operator
  • move-construction
  • move-assignment

Definition at line 41 of file Team.h.

Constructor & Destructor Documentation

◆ Team()

dash::Team::Team ( Team &&  t)
inline

Move-constructor.

Definition at line 133 of file Team.h.

134  : _dartid(t._dartid),
135  _myid(t._myid),
136  _size(t._size),
137  _parent(t._parent),
138  _child(t._child),
139  _position(t._position),
140  _num_siblings(t._num_siblings),
141  _group(t._group),
142  _deallocs(std::move(t._deallocs))
143  {
144  t._parent = nullptr;
145  t._group = nullptr;
146  t._dartid = DART_TEAM_NULL;
147  }

◆ ~Team()

dash::Team::~Team ( )
inline

Destructor.

Recursively frees this Team instance's child teams.

Definition at line 173 of file Team.h.

References dart_group_destroy(), DART_OK, DART_TEAM_ALL, dart_team_destroy(), and free().

174  {
175  DASH_LOG_DEBUG_VAR("Team.~Team()", this);
176 
177  // Do not register static Team instances as static variable _team might
178  // not be initialized at the time of their instantiation, yet:
179  if (DART_TEAM_NULL != _dartid &&
180  DART_TEAM_ALL != _dartid) {
181  Team::unregister_team(this);
182  }
183 
184  if (_group != DART_GROUP_NULL) {
185  if (DART_OK != dart_group_destroy(&_group)) {
186  DASH_LOG_ERROR("dash::Team d'tor", "Failed to destroy DART group!");
187  }
188  }
189 
190  if (_child) {
191  delete(_child);
192  _child = nullptr;
193  }
194 
195  if (_parent) {
196  _parent->_child = nullptr;
197  }
198 
199  free();
200 
201  if (DART_TEAM_NULL != _dartid &&
202  DART_TEAM_ALL != _dartid) {
203  if (DART_OK != dart_team_destroy(&_dartid))
204  {
205  DASH_LOG_ERROR("dash::Team d'tor", "Failed to destroy DART group!");
206  }
207  }
208  }
Signals success.
Definition: dart_types.h:33
dart_ret_t dart_team_destroy(dart_team_t *teamid)
Free up resources associated with the specified team.
#define DART_TEAM_ALL
The default team consisting of all units that run the application.
dart_ret_t dart_group_destroy(dart_group_t *group)
Reclaim resources that might be associated with the group.
void free()
Call registered deallocator functions for all team-allocated objects.
Definition: Team.h:314

Member Function Documentation

◆ All()

◆ dart_id()

◆ finalize()

static void dash::Team::finalize ( )
inlinestatic

Finalize all teams.

Frees global memory allocated by dash::Team::All().

we cannot iterate over Team::_teams directly and destroy teams simultaneously since it will be modified on call to d'tor (possibly multiple times)

Definition at line 261 of file Team.h.

References All(), free(), and size().

262  {
263  DASH_LOG_TRACE("Team::finalize()");
264 
271  while (Team::_teams.size() > 0) {
272  Team *t = Team::_teams.begin()->second;
273  delete t;
274  }
275 
276  Team::All().free();
277  Team::All().reset_team();
278  }
size_t size() const
The number of units in this team.
Definition: Team.h:498
static Team & All()
The invariant Team instance containing all available units.
Definition: Team.h:213
void free()
Call registered deallocator functions for all team-allocated objects.
Definition: Team.h:314

◆ free()

void dash::Team::free ( )
inline

Call registered deallocator functions for all team-allocated objects.

Definition at line 314 of file Team.h.

References dash::barrier(), locality_split(), and split().

Referenced by finalize(), operator=(), and ~Team().

315  {
316  DASH_LOG_DEBUG("Team.free()");
317  std::list<Deallocator>::iterator next = _deallocs.begin();
318  std::list<Deallocator>::iterator dealloc;
319  while ((dealloc = next) != _deallocs.end()) {
320  barrier();
321  // List changes in iterations
322  ++next;
323  DASH_LOG_DEBUG_VAR("Team.free", dealloc->object);
324  (dealloc->deallocator)();
325  }
326  _deallocs.clear();
327  }

◆ Get()

static Team& dash::Team::Get ( dart_team_t  team_id)
inlinestatic

Get Team instance by id.

Definition at line 237 of file Team.h.

References All(), DART_TEAM_ALL, and Null().

239  {
240  if (DART_TEAM_NULL == team_id) {
241  return dash::Team::Null();
242  }
243  if (DART_TEAM_ALL == team_id) {
244  return dash::Team::All();
245  }
246  return *(Team::_teams[team_id]);
247  }
#define DART_TEAM_ALL
The default team consisting of all units that run the application.
static Team & Null()
The invariant Team instance representing an undefined team.
Definition: Team.h:229
static Team & All()
The invariant Team instance containing all available units.
Definition: Team.h:213

◆ global_id()

global_unit_t dash::Team::global_id ( team_unit_t  local_id)
inline

Global unit id of specified local unit id.

Definition at line 551 of file Team.h.

References DART_OK, dart_team_locality_finalize(), dart_team_locality_init(), dart_team_myid(), dart_team_size(), dart_team_unit_l2g(), operator==(), and dash::UNDEFINED_TEAM_UNIT_ID.

Referenced by relative_id().

553  {
554  global_unit_t g_id;
555  DASH_ASSERT_RETURNS(
557  _dartid,
558  local_id,
559  &g_id),
560  DART_OK);
561  return g_id;
562  }
Signals success.
Definition: dart_types.h:33
struct dash::unit_id< dash::global_unit, dart_global_unit_t > global_unit_t
Unit ID to use for global IDs.
Definition: Types.h:332
dart_ret_t dart_team_unit_l2g(dart_team_t team, dart_team_unit_t localid, dart_global_unit_t *globalid)
Convert from a local to a global unit ID.

◆ GlobalUnitID()

static global_unit_t dash::Team::GlobalUnitID ( )
inlinestatic

The invariant unit ID in dash::Team::All().

Definition at line 221 of file Team.h.

References dash::myid().

222  {
223  return global_unit_t(Team::_team_all.myid());
224  }
struct dash::unit_id< dash::global_unit, dart_global_unit_t > global_unit_t
Unit ID to use for global IDs.
Definition: Types.h:332

◆ initialize()

static void dash::Team::initialize ( )
inlinestatic

Initialize the global team.

Definition at line 252 of file Team.h.

References All().

253  {
254  Team::All().init_team();
255  }
static Team & All()
The invariant Team instance containing all available units.
Definition: Team.h:213

◆ is_all()

bool dash::Team::is_all ( ) const
inline

Whether this Team contains all available units.

Definition at line 397 of file Team.h.

References All(), and operator==().

398  {
399  return operator==(All());
400  }
bool operator==(const Team &rhs) const
Equality comparison operator.
Definition: Team.h:377
static Team & All()
The invariant Team instance containing all available units.
Definition: Team.h:213

◆ is_leaf()

bool dash::Team::is_leaf ( ) const
inline

Whether this Team is a leaf node in a Team hierarchy, i.e.

does not have any child Teams assigned.

Definition at line 414 of file Team.h.

Referenced by is_member().

415  {
416  return _child == nullptr;
417  }

◆ is_member()

bool dash::Team::is_member ( global_unit_t  global_unit_id) const
inline

Whether the group associated with this Team instance contains the unit specified by global id.

id.

Parameters
groupIdthe id of the group to test for membership
Returns
true if and only if this Team instance is member of a group with given id

Definition at line 437 of file Team.h.

References dash::barrier(), dart_barrier(), dart_group_ismember(), DART_OK, is_leaf(), is_null(), dash::myid(), and Null().

438  {
439  if(!get_group()) {
440  return false;
441  }
442  int32_t ismember;
443  DASH_ASSERT_RETURNS(
445  _group,
446  global_unit_id,
447  &ismember),
448  DART_OK);
449  return (0 != ismember);
450  }
Signals success.
Definition: dart_types.h:33
dart_ret_t dart_group_ismember(const dart_group_t g, dart_global_unit_t unitid, int32_t *ismember)
Test if a unit is a member of the group.

◆ is_null()

bool dash::Team::is_null ( ) const
inline

Whether this Team is empty.

Definition at line 405 of file Team.h.

References Null(), and operator==().

Referenced by is_member().

406  {
407  return operator==(Null());
408  }
bool operator==(const Team &rhs) const
Equality comparison operator.
Definition: Team.h:377
static Team & Null()
The invariant Team instance representing an undefined team.
Definition: Team.h:229

◆ is_root()

bool dash::Team::is_root ( ) const
inline

Whether this Team is a root node in a Team hierarchy, i.e.

does not have a parent Team assigned.

Definition at line 423 of file Team.h.

424  {
425  return _parent == nullptr;
426  }

◆ locality_split() [1/2]

Team& dash::Team::locality_split ( dash::util::Locality::Scope  scope,
unsigned  num_parts 
)

Split this Team's units into child Team instances at the specified locality scope.

Returns
A new Team instance as a parent of the child teams.
Parameters
scopeLocality scope that determines the level in the topology hierarchy where the team is split.
num_partsNumber of parts to split this team's units into

Referenced by free(), and locality_split().

◆ locality_split() [2/2]

Team& dash::Team::locality_split ( dart_locality_scope_t  scope,
unsigned  num_parts 
)
inline

Split this Team's units into child Team instances at the specified locality scope.

Returns
A new Team instance as a parent of the child teams.
Parameters
scopeLocality scope that determines the level in the topology hierarchy where the team is split.
num_partsNumber of parts to split this team's units into

Definition at line 357 of file Team.h.

References locality_split().

363  {
364  return locality_split(
365  static_cast<dash::util::Locality::Scope>(
366  scope),
367  num_parts);
368  }
Team & locality_split(dash::util::Locality::Scope scope, unsigned num_parts)
Split this Team&#39;s units into child Team instances at the specified locality scope.

◆ Null()

◆ num_siblings()

size_t dash::Team::num_siblings ( ) const
inline

Number of sibling teams relative to parent team.

Definition at line 514 of file Team.h.

515  {
516  return _num_siblings;
517  }

◆ operator!=()

bool dash::Team::operator!= ( const Team rhs) const
inline

Inequality comparison operator.

Parameters
rhsThe Team instance to compare
Returns
True if and only if the given Team instance and this Team do not share the same DART id

Definition at line 389 of file Team.h.

References operator==().

390  {
391  return !(operator == (rhs));
392  }
bool operator==(const Team &rhs) const
Equality comparison operator.
Definition: Team.h:377

◆ operator=()

Team& dash::Team::operator= ( Team &&  t)
inline

Move-assignment operator.

Definition at line 152 of file Team.h.

References free().

153  {
154  if (this != &t) {
155  // Free existing resources
156  free();
157  // Take ownership of data from source
158  _deallocs = std::move(t._deallocs);
159  std::swap(_parent, t._parent);
160  std::swap(_group, t._group);
161  std::swap(_dartid, t._dartid);
162  _position = t._position;
163  _num_siblings = t._num_siblings;
164  _myid = t._myid;
165  _size = t._size;
166  }
167  return *this;
168  }
void free()
Call registered deallocator functions for all team-allocated objects.
Definition: Team.h:314

◆ operator==()

bool dash::Team::operator== ( const Team rhs) const
inline

Equality comparison operator.

Parameters
rhsThe Team instance to compare
Returns
True if and only if the given Team instance and this Team share the same DART id

Definition at line 377 of file Team.h.

Referenced by global_id(), is_all(), is_null(), and operator!=().

378  {
379  return _dartid == rhs._dartid;
380  }

◆ position()

size_t dash::Team::position ( ) const
inline

Index of this team relative to parent team.

Definition at line 506 of file Team.h.

507  {
508  return _position;
509  }

◆ register_deallocator()

void dash::Team::register_deallocator ( void *  object,
Deallocator::dealloc_function  dealloc 
)
inline

Register a deallocator function for a team-allocated object.

All registered deallocators will be called in ~Team(), or explicitly using Team::free().

Parameters
objectObject to deallocate
deallocFunction deallocating the object

Definition at line 285 of file Team.h.

Referenced by dash::List< ElementType, LocalMemorySpace >::allocate().

290  {
291  DASH_LOG_DEBUG_VAR("Team.register_deallocator()", object);
292  _deallocs.push_back(Deallocator { object, std::move(dealloc) });
293  }

◆ relative_id()

size_t dash::Team::relative_id ( ) const
inline

Index of this team relative to parent team.

Definition at line 530 of file Team.h.

References DART_OK, dart_team_unit_g2l(), and global_id().

531  {
532  return _position;
533  }

◆ size()

◆ split()

Team& dash::Team::split ( unsigned  nParts)

Split this Team's units into nParts child Team instances.

Returns
A new Team instance as a parent of child Teams
Parameters
nPartsNumber of parts to split this team's units into

Referenced by free().

◆ unregister_deallocator()

void dash::Team::unregister_deallocator ( void *  object,
Deallocator::dealloc_function  dealloc 
)
inline

Unregister a deallocator function for a team-allocated object.

All registered deallocators will be called in ~Team(), or explicitly using Team::free().

Parameters
objectObject to deallocate
deallocFunction deallocating the object

Definition at line 300 of file Team.h.

Referenced by dash::Array< signal_t >::Array(), dash::List< ElementType, LocalMemorySpace >::deallocate(), and dash::Array< signal_t >::operator=().

305  {
306  DASH_LOG_DEBUG_VAR("Team.unregister_deallocator()", object);
307  _deallocs.remove(Deallocator { object, std::move(dealloc) });
308  }

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