1 #ifndef DASH__UTIL__LOCALITY_DOMAIN_H__INCLUDED 2 #define DASH__UTIL__LOCALITY_DOMAIN_H__INCLUDED 4 #include <dash/util/Locality.h> 9 #include <dash/algorithm/internal/String.h> 11 #include <dash/Exception.h> 15 #include <unordered_map> 30 template<
typename LocalityDomainT >
31 class LocalityDomainIterator
32 :
public std::iterator< std::random_access_iterator_tag, LocalityDomainT >
34 template<
typename LocalityDomainT_ >
35 friend class LocalityDomainIterator;
38 typedef LocalityDomainIterator<LocalityDomainT> self_t;
41 typedef LocalityDomainIterator<LocalityDomainT> self_type;
42 typedef int difference_type;
44 typedef LocalityDomainT value_type;
45 typedef LocalityDomainT * pointer;
46 typedef const LocalityDomainT * const_pointer;
47 typedef LocalityDomainT & reference;
48 typedef const LocalityDomainT & const_reference;
52 LocalityDomainIterator(
54 int subdomain_idx = 0)
59 LocalityDomainIterator() =
default;
61 template<
typename LocalityDomainT_Other >
62 LocalityDomainIterator(
63 const LocalityDomainIterator<LocalityDomainT_Other> & other)
64 : _domain(const_cast<LocalityDomainT *>(other._domain)),
68 bool operator==(
const self_type & rhs)
const {
69 return *_domain == *(rhs._domain) && _idx == rhs._idx;
72 bool operator!=(
const self_type & rhs)
const {
73 return !(*
this == rhs);
76 reference operator[](
int i)
78 DASH_ASSERT(_domain !=
nullptr);
79 int subdomain_idx = _idx + i;
80 return _domain->at(subdomain_idx);
83 const_reference operator[](
int i)
const 85 DASH_ASSERT(_domain !=
nullptr);
86 int subdomain_idx = _idx + i;
87 return _domain->at(subdomain_idx);
92 DASH_ASSERT(_domain !=
nullptr);
93 return _domain->at(_idx);
96 const_reference operator*()
const 98 DASH_ASSERT(_domain !=
nullptr);
99 return _domain->at(_idx);
104 DASH_ASSERT(_domain !=
nullptr);
105 return &(_domain->at(_idx));
108 const_pointer operator->()
const 110 DASH_ASSERT(_domain !=
nullptr);
111 return &(_domain->at(_idx));
114 self_t & operator++() { _idx++;
return *
this; }
115 self_t & operator--() { _idx--;
return *
this; }
116 self_t & operator+=(
int i) { _idx+= i;
return *
this; }
117 self_t & operator-=(
int i) { _idx-= i;
return *
this; }
118 self_t operator+(
int i) { self_t ret = *
this; ret += i;
return ret; }
119 self_t
operator-(
int i) { self_t ret = *
this; ret -= i;
return ret; }
120 self_t operator++(
int) { self_t ret = *
this; _idx++;
return ret; }
121 self_t operator--(
int) { self_t ret = *
this; _idx--;
return ret; }
124 LocalityDomainT * _domain =
nullptr;
158 typedef dash::util::Locality::Scope Scope_t;
161 typedef internal::LocalityDomainIterator<self_t> iterator;
162 typedef internal::LocalityDomainIterator<const self_t> const_iterator;
166 const self_t & parent,
173 std::string _domain_tag =
".";
177 mutable std::unordered_map<int, self_t> * _subdomains =
nullptr;
179 std::vector<global_unit_t> _unit_ids;
181 std::unordered_map<team_unit_t, UnitLocality_t> _unit_localities;
190 bool _is_owner =
false;
192 std::vector<iterator> _groups;
193 std::vector<std::string> _group_domain_tags;
195 std::vector<self_t> _parts;
209 const self_t & other);
215 const self_t & other);
220 inline bool operator==(
221 const self_t & rhs)
const {
222 return ( (_domain == rhs._domain)
224 ( (_domain !=
nullptr &&
225 rhs._domain !=
nullptr)
228 == rhs._domain->
team &&
233 inline bool operator!=(
234 const self_t & rhs)
const {
235 return !(*
this == rhs);
243 const std::vector<std::string> & subdomain_tags);
250 const std::vector<std::string> & subdomain_tags);
256 const std::vector<std::string> & group_subdomain_tags);
265 dash::util::Locality::Scope scope,
266 int num_split_parts);
271 self_t & split_groups();
278 int relative_index)
const;
291 const std::string & subdomain_tag)
const;
297 const std::string & subdomain_tag);
299 inline std::vector<iterator> & groups()
304 inline const std::vector<iterator> & groups()
const 309 inline std::vector<self_t> & parts()
314 inline const std::vector<self_t> & parts()
const 319 inline std::vector<self_t> scope_domains(
320 dash::util::Locality::Scope scope)
const 322 std::vector<self_t> scope_domains;
323 int num_scope_domains;
328 static_cast<dart_locality_scope_t>(scope),
330 &dart_scope_domains);
334 DASH_LOG_TRACE_VAR(
"LocalityDomain.scope_domains", num_scope_domains);
335 if (num_scope_domains > 0) {
336 scope_domains.reserve(num_scope_domains);
337 for (
int sd = 0; sd < num_scope_domains; sd++) {
338 DASH_LOG_TRACE(
"LocalityDomain.scope_domains",
339 "scope_domains[", sd,
"]",
":",
340 dart_scope_domains[sd]->domain_tag);
341 scope_domains.emplace_back(*dart_scope_domains[sd]);
343 free(dart_scope_domains);
345 return scope_domains;
349 inline const UnitLocality_t & unit_locality(
352 if (
nullptr == _parent) {
353 return (*_unit_localities.find(unit)).
second;
355 return _parent->unit_locality(unit);
358 inline UnitLocality_t & unit_locality(
361 if (
nullptr == _parent) {
362 return _unit_localities[unit];
364 return _parent->unit_locality(unit);
370 if (
nullptr == _domain) {
371 return DART_TEAM_NULL;
373 return _domain->
team;
376 inline const std::string & domain_tag()
const 383 DASH_ASSERT(_domain !=
nullptr);
387 inline std::string host()
const 389 DASH_ASSERT(_domain !=
nullptr);
390 return _domain->
host;
393 inline int shared_mem_bytes()
const 395 DASH_ASSERT(_domain !=
nullptr);
396 return _domain->shared_mem_bytes;
399 inline iterator
begin()
404 inline const_iterator
begin()
const 406 return const_iterator(_begin);
409 inline iterator
end()
414 inline const_iterator
end()
const 416 return const_iterator(_end);
419 inline size_t size()
const 421 return _domain ==
nullptr 426 inline const std::vector<global_unit_t> & units()
const 431 inline std::vector<global_unit_t> & units()
445 != _unit_ids.end()) {
448 return _unit_ids.front();
451 inline int level()
const 453 return (
nullptr == _domain ? -1 : _domain->
level);
456 inline Scope_t scope()
const 458 return _domain ==
nullptr 460 :
static_cast<Scope_t
>(_domain->
scope);
463 inline int node_id()
const 465 return (
nullptr == _domain ? -1 : _domain->node_id);
468 inline int num_nodes()
const 470 return (
nullptr == _domain ? -1 : _domain->num_nodes);
473 inline int num_cores()
const 475 return (
nullptr == _domain ? -1 : _domain->num_cores);
478 inline int global_index()
const 480 return (
nullptr == _domain ? -1 : _domain->
global_index);
483 inline int relative_index()
const 485 return (
nullptr == _domain ? -1 : _domain->num_cores);
493 inline void collect_groups(
494 const std::vector<std::string> & group_domain_tags)
497 for (
const auto& gdt : group_domain_tags) {
498 _groups.push_back(
find(gdt));
504 std::ostream & operator<<(
511 #endif // DASH__UTIL__LOCALITY_DOMAIN_H__INCLUDED
size_t size()
Return the number of units in the global team.
constexpr auto end(RangeType &&range) -> decltype(std::forward< RangeType >(range).end())
dart_ret_t dart_domain_scope_domains(const dart_domain_locality_t *domain_in, dart_locality_scope_t scope, int *num_domains_out, dart_domain_locality_t ***domains_out)
Locality domains at the specified locality scope.
This class is a simple memory pool which holds allocates elements of size ValueType.
constexpr auto begin(RangeType &&range) -> decltype(std::forward< RangeType >(range).begin())
char domain_tag[((int)(32))]
Hierarchical domain identifier, represented as dot-separated list of relative indices on every level ...
struct dash::unit_id< dash::global_unit, dart_global_unit_t > global_unit_t
Unit ID to use for global IDs.
global_unit_t leader_unit() const
ID of leader unit in the locality domain.
dart_team_t team
Team associated with the domain.
int num_domains
Number of subordinate domains.
DASH_CONSTEXPR auto operator-(const GlobIter< ElementType, Pattern, GlobMemType, Pointer, Reference > &lhs, const GlobIter< ElementType, Pattern, GlobMemType, Pointer, Reference > &rhs) DASH_NOEXCEPT
int level
Level in the domain locality hierarchy.
A domain is a group of processing entities such as cores in a specific NUMA domain or a Intel MIC ent...
char host[((int)(256))]
Hostname of the domain's node or 0 if unspecified.
int global_index
The domain's global index within its scope.
dart_locality_scope_t scope
Locality scope of the domain.
struct dash::unit_id< dash::local_unit, dart_team_unit_t > team_unit_t
Unit ID to use for team-local IDs.
Wrapper of a single dart_domain_locality_t object.
dart_ret_t
Return values of functions in the DART interface.
int16_t dart_team_t
Data type for storing a team ID.
GlobIter find(GlobIter first, GlobIter last, const ElementType &value)
Returns an iterator to the first element in the range [first,last) that compares equal to val...
Missing data encountered.
void init(int *argc, char ***argv)
Initialize the DASH library and the underlying runtime system.
constexpr auto domain(ViewT &&view) -> typename std::enable_if< dash::detail::has_type_domain_type< ViewValueT >::value, decltype(std::forward< ViewT >(view).domain()) >::type