1 #ifndef TEAM_H_INCLUDED 2 #define TEAM_H_INCLUDED 7 #include <dash/Types.h> 8 #include <dash/Exception.h> 10 #include <dash/util/Locality.h> 12 #include <dash/internal/Logging.h> 15 #include <unordered_map> 18 #include <type_traits> 26 std::ostream & operator<<(
45 template <
typename U,
class P,
class GM,
class Ptr,
class Ref >
49 friend std::ostream & operator<<(
69 inline int operator*()
const {
73 inline operator int()
const {
85 return {
static_cast<int>(
size())};
91 typedef std::function<void(void)> dealloc_function;
93 dealloc_function deallocator;
104 Team * parent =
nullptr,
108 size_t nsiblings = 0);
110 bool get_group()
const 113 DASH_LOG_DEBUG(
"Team.get_group()");
116 return _group != DART_GROUP_NULL;
127 Team & operator=(
const Team & t) =
delete;
134 : _dartid(t._dartid),
139 _position(t._position),
140 _num_siblings(t._num_siblings),
142 _deallocs(
std::move(t._deallocs))
146 t._dartid = DART_TEAM_NULL;
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;
175 DASH_LOG_DEBUG_VAR(
"Team.~Team()",
this);
179 if (DART_TEAM_NULL != _dartid &&
181 Team::unregister_team(
this);
184 if (_group != DART_GROUP_NULL) {
186 DASH_LOG_ERROR(
"dash::Team d'tor",
"Failed to destroy DART group!");
196 _parent->_child =
nullptr;
201 if (DART_TEAM_NULL != _dartid &&
205 DASH_LOG_ERROR(
"dash::Team d'tor",
"Failed to destroy DART group!");
215 return Team::_team_all;
231 return Team::_team_null;
240 if (DART_TEAM_NULL == team_id) {
246 return *(Team::_teams[team_id]);
263 DASH_LOG_TRACE(
"Team::finalize()");
271 while (Team::_teams.
size() > 0) {
272 Team *t = Team::_teams.begin()->second;
289 Deallocator::dealloc_function dealloc)
291 DASH_LOG_DEBUG_VAR(
"Team.register_deallocator()",
object);
292 _deallocs.push_back(
Deallocator { object, std::move(dealloc) });
304 Deallocator::dealloc_function dealloc)
306 DASH_LOG_DEBUG_VAR(
"Team.unregister_deallocator()",
object);
307 _deallocs.remove(
Deallocator { object, std::move(dealloc) });
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()) {
323 DASH_LOG_DEBUG_VAR(
"Team.free", dealloc->object);
324 (dealloc->deallocator)();
347 dash::util::Locality::Scope scope,
365 static_cast<dash::util::Locality::Scope>(
379 return _dartid == rhs._dartid;
416 return _child ==
nullptr;
425 return _parent ==
nullptr;
449 return (0 != ismember);
452 inline Team & parent()
454 if(_parent) {
return *_parent; }
455 else {
return Null(); }
458 Team & sub(
size_t level = 1)
461 while (t && level > 0 && !(t->
is_leaf())) {
464 DASH_ASSERT_MSG(t,
"node is neither leaf nor has child");
474 DASH_ASSERT_MSG(t,
"node is neither leaf nor has child");
516 return _num_siblings;
566 void register_team(
Team * team)
568 DASH_LOG_DEBUG(
"Team.register_team",
569 "team id:", team->_dartid);
573 dash::Team::_teams.insert(
574 std::make_pair(team->_dartid, team));
577 void unregister_team(
Team * team)
579 DASH_LOG_DEBUG(
"Team.unregister_team",
580 "team id:", team->_dartid);
586 dash::Team::_teams.erase(
612 mutable size_t _size = 0;
613 Team * _parent =
nullptr;
614 Team * _child =
nullptr;
615 size_t _position = 0;
616 size_t _num_siblings = 0;
621 std::list<Deallocator> _deallocs;
623 static std::unordered_map<dart_team_t, Team *> _teams;
625 static Team _team_all;
626 static Team _team_null;
636 std::shared_ptr<Team*> _teamptr;
645 struct iterator_traits<
dash::Team::iterator> {
650 typedef random_access_iterator_tag iterator_category;
constexpr team_unit_t UNDEFINED_TEAM_UNIT_ID
Invalid local unit ID.
bool operator!=(const Team &rhs) const
Inequality comparison operator.
global_unit_t myid()
Shortcut to query the global unit ID of the calling unit.
global_unit_t global_id(team_unit_t local_id)
Global unit id of specified local unit id.
struct dart_group_struct * dart_group_t
DART groups are represented by an opaque struct dart_group_struct.
constexpr auto end(RangeType &&range) -> decltype(std::forward< RangeType >(range).end())
dart_ret_t dart_team_myid(dart_team_t teamid, dart_team_unit_t *myid)
Return the unit id of the caller in the specified team.
This class is a simple memory pool which holds allocates elements of size ValueType.
dart_ret_t dart_team_destroy(dart_team_t *teamid)
Free up resources associated with the specified team.
constexpr auto begin(RangeType &&range) -> decltype(std::forward< RangeType >(range).begin())
bool is_root() const
Whether this Team is a root node in a Team hierarchy, i.e.
struct dash::unit_id< dash::global_unit, dart_global_unit_t > global_unit_t
Unit ID to use for global IDs.
dart_ret_t dart_team_size(dart_team_t teamid, size_t *size)
Return the size of the specified team.
#define DART_TEAM_ALL
The default team consisting of all units that run the application.
static global_unit_t GlobalUnitID()
The invariant unit ID in dash::Team::All().
dart_ret_t dart_team_locality_finalize(dart_team_t team)
Initialize information of the specified team.
Team & locality_split(dart_locality_scope_t scope, unsigned num_parts)
Split this Team's units into child Team instances at the specified locality scope.
static void finalize()
Finalize all teams.
void unregister_deallocator(void *object, Deallocator::dealloc_function dealloc)
Unregister a deallocator function for a team-allocated object.
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.
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.
bool is_initialized()
Check whether DASH has been initialized already.
bool operator==(const Team &rhs) const
Equality comparison operator.
size_t size() const
The number of units in this team.
dart_ret_t dart_team_get_group(dart_team_t teamid, dart_group_t *group)
Query the group associated with the specified team.
Team(Team &&t)
Move-constructor.
Iterator on Partitioned Global Address Space.
A Team instance specifies a subset of all available units.
bool is_all() const
Whether this Team contains all available units.
static void initialize()
Initialize the global team.
size_t position() const
Index of this team relative to parent team.
dart_ret_t dart_barrier(dart_team_t team)
DART Equivalent to MPI_Barrier.
dart_ret_t dart_team_locality_init(dart_team_t team)
Initialize information of the specified team.
struct dash::unit_id< dash::local_unit, dart_team_unit_t > team_unit_t
Unit ID to use for team-local IDs.
bool is_null() const
Whether this Team is empty.
Team & operator=(Team &&t)
Move-assignment operator.
dart_ret_t dart_group_destroy(dart_group_t *group)
Reclaim resources that might be associated with the group.
int16_t dart_team_t
Data type for storing a team ID.
static Team & Get(dart_team_t team_id)
Get Team instance by id.
static Team & Null()
The invariant Team instance representing an undefined team.
dart_ret_t dart_team_unit_g2l(dart_team_t team, dart_global_unit_t globalid, dart_team_unit_t *localid)
Convert from a global to a local unit ID.
void register_deallocator(void *object, Deallocator::dealloc_function dealloc)
Register a deallocator function for a team-allocated object.
Shared access to a value in global memory across a team.
Team & split(unsigned nParts)
Split this Team's units into nParts child Team instances.
void barrier()
A global barrier involving all units.
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.
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...
static Team & All()
The invariant Team instance containing all available units.
see https://en.cppreference.com/w/cpp/feature_test for recommended feature tests
bool is_leaf() const
Whether this Team is a leaf node in a Team hierarchy, i.e.
void free()
Call registered deallocator functions for all team-allocated objects.
size_t num_siblings() const
Number of sibling teams relative to parent team.
size_t relative_id() const
Index of this team relative to parent team.
dart_team_t dart_id() const
Index of this team relative to global team dash::Team::All().
dart_locality_scope_t
Scopes of locality domains.