1 #ifndef DASH__GLOB_HEAP_H__INCLUDED 2 #define DASH__GLOB_HEAP_H__INCLUDED 6 #include <dash/Types.h> 7 #include <dash/GlobPtr.h> 8 #include <dash/GlobSharedRef.h> 9 #include <dash/Allocator.h> 10 #include <dash/Team.h> 11 #include <dash/Array.h> 12 #include <dash/Onesided.h> 14 #include <dash/algorithm/MinMax.h> 15 #include <dash/algorithm/Copy.h> 17 #include <dash/memory/GlobHeapPtr.h> 18 #include <dash/memory/GlobHeapLocalPtr.h> 20 #include <dash/internal/Logging.h> 199 typename ElementType,
211 typename std::remove_const<ElementType>::type,
216 using local_allocator_traits =
217 std::allocator_traits<typename allocator_traits::local_allocator>;
220 using value_type =
typename allocator_traits::value_type;
222 using allocator_type =
typename allocator_traits::allocator_type;
226 typedef typename allocator_type::size_type size_type;
227 typedef typename allocator_type::difference_type difference_type;
228 typedef typename allocator_type::difference_type index_type;
230 typedef typename allocator_type::pointer raw_pointer;
238 typedef value_type & local_reference;
239 typedef const value_type & const_local_reference;
241 typedef typename local_pointer::bucket_type bucket_type;
243 template <
typename U>
247 using local_void_pointer =
void *;
250 typedef typename std::list<bucket_type> bucket_list;
251 typedef typename bucket_list::iterator bucket_iterator;
254 size_type, int, dash::CSRPattern<1, dash::ROW_MAJOR, int> >
257 typedef std::vector<std::vector<size_type> > bucket_cumul_sizes_map;
259 template<
typename T_,
class GMem_>
263 allocator_type _allocator;
266 size_type _nunits = 0;
267 local_pointer _lbegin =
nullptr;
268 local_pointer _lend =
nullptr;
273 bucket_list _buckets;
275 bucket_list _detach_buckets;
277 bucket_iterator _attach_buckets_first;
280 local_sizes_map _local_sizes;
286 bucket_cumul_sizes_map _bucket_cumul_sizes;
289 local_sizes_map _num_attach_buckets;
292 local_sizes_map _num_detach_buckets;
294 size_type _remote_size = 0;
296 index_type _begin_idx;
310 size_type n_local_elem = 0)
324 size_type n_local_elem,
341 size_type n_local_elem,
349 : _allocator(team, r),
352 _nunits(team.
size()),
354 _attach_buckets_first(_buckets.end()),
356 _bucket_cumul_sizes(team.
size()),
357 _num_attach_buckets(team.
size(),
team),
358 _num_detach_buckets(team.
size(),
team),
361 DASH_LOG_TRACE(
"GlobHeapMem.(ninit,nunits)",
362 n_local_elem, team.
size());
364 _local_sizes.
local[0] = 0;
365 _num_attach_buckets.
local[0] = 0;
366 _num_detach_buckets.
local[0] = 0;
368 DASH_LOG_TRACE(
"GlobHeapMem.GlobHeapMem",
369 "allocating initial memory space");
373 DASH_LOG_TRACE(
"GlobHeapMem.GlobHeapMem >");
382 DASH_LOG_TRACE(
"GlobHeapMem.~GlobHeapMem()");
395 self_t &
operator=(
const self_t & rhs) =
default;
402 return (_teamid == rhs._teamid &&
403 _nunits == rhs._nunits &&
404 _lbegin == rhs._lbegin &&
405 _lend == rhs._lend &&
406 _buckets == rhs._buckets &&
407 _detach_buckets == rhs._detach_buckets);
415 return !(*
this == rhs);
422 constexpr size_type
size() const noexcept
432 return _local_sizes.
local[0];
443 DASH_LOG_TRACE(
"GlobHeapMem.local_size(u)",
"unit:", unit);
444 DASH_ASSERT_RANGE(0, unit, _nunits-1,
"unit id out of range");
445 DASH_LOG_TRACE_VAR(
"GlobHeapMem.local_size",
446 _bucket_cumul_sizes[unit]);
447 size_type unit_local_size;
451 unit_local_size = _local_sizes.
local[0];
453 unit_local_size = _bucket_cumul_sizes[unit].back();
455 DASH_LOG_TRACE(
"GlobHeapMem.local_size >", unit_local_size);
456 return unit_local_size;
485 local_pointer
grow(size_type num_elements)
487 DASH_LOG_DEBUG_VAR(
"GlobHeapMem.grow()", num_elements);
488 size_type local_size_old = _local_sizes.
local[0];
489 DASH_LOG_TRACE(
"GlobHeapMem.grow",
490 "current local size:", local_size_old);
491 if (num_elements == 0) {
492 DASH_LOG_DEBUG(
"GlobHeapMem.grow >",
"no grow");
496 _local_sizes.
local[0] += num_elements;
498 _num_attach_buckets.
local[0] += 1;
501 DASH_LOG_TRACE(
"GlobHeapMem.grow",
"creating new unattached bucket:",
502 "size:", num_elements);
504 bucket.size = num_elements;
505 bucket.allocated_size = num_elements;
506 bucket.lptr = _allocator.allocate_local(bucket.size);
508 bucket.attached =
false;
510 _buckets.push_back(bucket);
511 if (_attach_buckets_first == _buckets.end()) {
513 _attach_buckets_first = _buckets.begin();
514 std::advance(_attach_buckets_first, _buckets.size() - 1);
516 _bucket_cumul_sizes[_myid].push_back(_local_sizes.
local[0]);
517 DASH_LOG_TRACE(
"GlobHeapMem.grow",
"added unattached bucket:",
518 "allocated size:", bucket.size,
519 "lptr:", bucket.lptr);
523 DASH_ASSERT_EQ(_local_sizes.
local[0], _lend - _lbegin,
524 "local size differs from local iteration space size");
525 DASH_LOG_TRACE(
"GlobHeapMem.grow",
526 "new local size:", _local_sizes.
local[0]);
527 DASH_LOG_TRACE(
"GlobHeapMem.grow",
528 "local buckets:", _buckets.size(),
529 "unattached buckets:", _num_attach_buckets.
local[0]);
530 DASH_LOG_TRACE(
"GlobHeapMem.grow >");
532 return _lbegin + local_size_old;
586 DASH_LOG_DEBUG_VAR(
"GlobHeapMem.shrink()", num_elements);
587 DASH_ASSERT_LT(num_elements,
local_size() + 1,
589 "by " << num_elements <<
" elements");
590 if (num_elements == 0) {
591 DASH_LOG_DEBUG(
"GlobHeapMem.shrink >",
"no shrink");
594 DASH_LOG_TRACE(
"GlobHeapMem.shrink",
595 "current local size:", _local_sizes.
local[0]);
596 DASH_LOG_TRACE(
"GlobHeapMem.shrink",
597 "current local buckets:", _buckets.size());
599 auto attach_buckets_first_pos =
std::distance(_buckets.begin(),
600 _attach_buckets_first);
601 DASH_LOG_TRACE_VAR(
"GlobHeapMem.shrink", attach_buckets_first_pos);
603 auto num_dealloc = num_elements;
608 while (!_buckets.back().attached && num_dealloc > 0) {
609 bucket_type & bucket_last = _buckets.back();
611 if (bucket_last.size <= num_dealloc) {
612 DASH_LOG_TRACE(
"GlobHeapMem.shrink",
"remove unattached bucket:",
613 "size:", bucket_last.size);
615 num_dealloc -= bucket_last.size;
616 _local_sizes.
local[0] -= bucket_last.
size;
617 _bucket_cumul_sizes[_myid].pop_back();
620 auto it_last_bucket = _buckets.end();
621 std::advance(it_last_bucket, -1);
622 if (_attach_buckets_first == it_last_bucket) {
624 DASH_LOG_TRACE(
"GlobHeapMem.shrink",
625 "updating iterator to first unattached bucket");
626 std::advance(_attach_buckets_first, -1);
628 _allocator.deallocate_local(bucket_last.lptr, bucket_last.allocated_size);
630 if (_attach_buckets_first->attached) {
633 _attach_buckets_first = _buckets.end();
636 DASH_ASSERT_GT(_num_attach_buckets.
local[0], 0,
637 "Last bucket unattached but number of buckets marked " 639 _num_attach_buckets.
local[0] -= 1;
640 }
else if (bucket_last.size > num_dealloc) {
641 auto const size_new = bucket_last.
size - num_dealloc;
643 DASH_LOG_TRACE(
"GlobHeapMem.shrink",
"shrink unattached bucket:",
644 "old size:", bucket_last.size,
645 "new size:", size_new);
646 _local_sizes.
local[0] -= num_dealloc;
647 _bucket_cumul_sizes[_myid].back() -= num_dealloc;
651 _allocator.deallocate_local(bucket_last.lptr, bucket_last.allocated_size);
653 bucket_last.lptr = _allocator.allocate_local(size_new);
654 if (bucket_last.lptr ==
nullptr) {
656 "GlobHeapMem.shrink: Allocating bucket of size failed");
658 bucket_last.size = size_new;
659 bucket_last.allocated_size = size_new;
664 auto num_dealloc_gbuckets = 0;
666 for (
auto bucket_it = _buckets.rbegin();
667 bucket_it != _buckets.rend();
669 if (!bucket_it->attached) {
672 if (num_dealloc == 0) {
675 if (bucket_it->size <= num_dealloc) {
677 num_dealloc_gbuckets++;
678 _num_detach_buckets.
local[0] += 1;
679 _local_sizes.
local[0] -= bucket_it->
size;
680 _bucket_cumul_sizes[_myid].back() -= bucket_it->size;
681 num_dealloc -= bucket_it->size;
682 }
else if (bucket_it->size > num_dealloc) {
683 DASH_LOG_TRACE(
"GlobHeapMem.shrink",
"shrink attached bucket:",
684 "old size:", bucket_it->size,
685 "new size:", bucket_it->size - num_dealloc);
686 bucket_it->size -= num_dealloc;
687 _local_sizes.
local[0] -= num_dealloc;
688 _bucket_cumul_sizes[_myid].back() -= num_dealloc;
694 DASH_LOG_DEBUG_VAR(
"GlobHeapMem.shrink", num_dealloc_gbuckets);
695 while (num_dealloc_gbuckets-- > 0) {
696 auto dealloc_bucket = _buckets.back();
697 DASH_LOG_TRACE(
"GlobHeapMem.shrink",
"deallocate attached bucket:" 698 "size:", dealloc_bucket.size,
699 "lptr:", dealloc_bucket.lptr);
701 _detach_buckets.push_back(dealloc_bucket);
709 DASH_LOG_TRACE(
"GlobHeapMem.shrink",
710 "cumulative bucket sizes:", _bucket_cumul_sizes[_myid]);
711 DASH_LOG_TRACE(
"GlobHeapMem.shrink",
712 "new local size:", _local_sizes.
local[0],
715 DASH_LOG_TRACE(
"GlobHeapMem.shrink",
716 "total number of buckets:", _buckets.size(),
718 _attach_buckets_first,
720 DASH_LOG_DEBUG(
"GlobHeapMem.shrink >");
741 DASH_LOG_DEBUG(
"GlobHeapMem.commit()");
742 DASH_LOG_TRACE_VAR(
"GlobHeapMem.commit", _buckets.size());
746 size_type num_detached_elem = commit_detach();
747 size_type num_attached_elem = commit_attach();
749 if (num_detached_elem > 0 || num_attached_elem > 0) {
751 DASH_LOG_TRACE(
"GlobHeapMem.commit",
"updating _begin");
753 DASH_LOG_TRACE(
"GlobHeapMem.commit",
"updating _end");
757 DASH_LOG_TRACE(
"GlobHeapMem.commit",
"updating _lbegin");
759 DASH_LOG_TRACE(
"GlobHeapMem.commit",
"updating _lend");
761 DASH_LOG_DEBUG(
"GlobHeapMem.commit >",
"finished");
785 DASH_LOG_DEBUG(
"GlobHeapMem.resize()",
"new size:", num_elements);
786 index_type diff_capacity = num_elements -
size();
787 if (diff_capacity > 0) {
789 }
else if (diff_capacity < 0) {
792 DASH_LOG_DEBUG(
"GlobHeapMem.resize >");
800 return pointer(
this, _begin_idx);
806 constexpr const_pointer
begin() const noexcept
808 return const_pointer(
this, _begin_idx);
816 return pointer(
this, _end_idx);
822 const_pointer
end() const noexcept
824 return const_pointer(
this, _end_idx);
840 inline const_local_pointer
lbegin() const noexcept
849 inline local_pointer &
lend() noexcept
858 inline const_local_pointer &
lend() const noexcept
868 template<
typename ValueType = value_type>
871 index_type global_index)
873 DASH_LOG_TRACE(
"GlobHeapMem.put_value(newval, gidx = %d)",
875 auto git = pointer(
this, global_index);
884 template<
typename ValueType = value_type>
887 index_type global_index)
const 889 DASH_LOG_TRACE(
"GlobHeapMem.get_value(newval, gidx = %d)",
891 auto git = pointer(
this, global_index);
912 template<
typename IndexT>
919 DASH_LOG_DEBUG(
"GlobHeapMem.at()",
920 "unit:", unit,
"lidx:", local_index);
924 pointer git(
this, unit, local_index);
925 DASH_LOG_DEBUG_VAR(
"GlobHeapMem.at >", git);
933 template<
typename IndexT>
938 IndexT local_index)
const 940 DASH_LOG_DEBUG(
"GlobHeapMem.at() const",
941 "unit:", unit,
"lidx:", local_index);
945 const_pointer git(
this, unit, local_index);
946 DASH_LOG_DEBUG_VAR(
"GlobHeapMem.at const >", git);
950 inline const bucket_list & local_buckets()
const 962 void update_lbegin() noexcept
964 DASH_LOG_TRACE(
"GlobHeapMem.update_lbegin()");
965 local_pointer unit_lbegin(
967 _buckets.begin(), _buckets.end(),
972 _buckets.begin(), 0);
973 DASH_LOG_TRACE(
"GlobHeapMem.update_lbegin >", unit_lbegin);
974 _lbegin = unit_lbegin;
981 void update_lend() noexcept
983 DASH_LOG_TRACE(
"GlobHeapMem.update_lend()");
984 local_pointer unit_lend(
986 _buckets.begin(), _buckets.end(),
992 DASH_LOG_TRACE(
"GlobHeapMem.update_lend >", unit_lend);
1000 size_type commit_detach()
1002 DASH_LOG_TRACE(
"GlobHeapMem.commit_detach()");
1003 DASH_LOG_TRACE(
"GlobHeapMem.commit_detach",
1004 "local buckets to detach:", _num_detach_buckets.
local[0]);
1007 size_type num_detached_elem = 0;
1008 for (
auto bucket_it = _detach_buckets.begin();
1009 bucket_it != _detach_buckets.cend(); ++bucket_it) {
1010 DASH_LOG_TRACE(
"GlobHeapMem.commit_detach",
"detaching bucket:",
1011 "size:", bucket_it->size,
1012 "lptr:", bucket_it->lptr,
1013 "gptr:", bucket_it->gptr);
1016 if (bucket_it->attached) {
1017 _allocator.deallocate(bucket_it->gptr, bucket_it->allocated_size);
1018 num_detached_elem += bucket_it->size;
1019 bucket_it->attached =
false;
1022 _detach_buckets.clear();
1023 DASH_LOG_TRACE(
"GlobHeapMem.commit_detach >",
1024 "globally deallocated elements:", num_detached_elem);
1025 return num_detached_elem;
1031 size_type commit_attach()
1033 DASH_LOG_TRACE(
"GlobHeapMem.commit_attach()");
1034 DASH_LOG_TRACE(
"GlobHeapMem.commit_attach",
1035 "local buckets to attach:", _num_attach_buckets.
local[0]);
1037 _num_attach_buckets.
barrier();
1039 auto min_max_attach = gather_min_max(_num_attach_buckets.
begin(),
1040 _num_attach_buckets.
end());
1041 auto min_attach_buckets = min_max_attach.first;
1042 auto max_attach_buckets = min_max_attach.second;
1043 DASH_LOG_TRACE(
"GlobHeapMem.commit_attach",
1044 "min. attach buckets:", min_attach_buckets);
1045 DASH_LOG_TRACE(
"GlobHeapMem.commit_attach",
1046 "max. attach buckets:", max_attach_buckets);
1048 size_type num_attached_buckets = 0;
1050 size_type num_attached_elem = 0;
1052 size_type old_remote_size = _remote_size;
1053 _remote_size = update_remote_size();
1056 bool has_remote_attach = _remote_size > old_remote_size;
1057 DASH_LOG_TRACE_VAR(
"GlobHeapMem.commit_attach", old_remote_size);
1058 DASH_LOG_TRACE_VAR(
"GlobHeapMem.commit_attach", _remote_size);
1059 DASH_LOG_TRACE_VAR(
"GlobHeapMem.commit_attach",
size());
1060 DASH_LOG_TRACE_VAR(
"GlobHeapMem.commit_attach", has_remote_attach);
1062 DASH_ASSERT(!has_remote_attach || max_attach_buckets > 0);
1069 if (min_attach_buckets == 0 && max_attach_buckets == 0) {
1070 DASH_LOG_TRACE(
"GlobHeapMem.commit_attach",
"no attach");
1071 DASH_ASSERT(_attach_buckets_first == _buckets.end());
1072 DASH_ASSERT(_buckets.empty() || _buckets.back().attached);
1074 DASH_LOG_TRACE(
"GlobHeapMem.commit_attach",
"attaching",
1077 for (; _attach_buckets_first != _buckets.end(); ++_attach_buckets_first) {
1078 bucket_type & bucket = *_attach_buckets_first;
1079 DASH_ASSERT(!bucket.attached);
1080 DASH_LOG_TRACE(
"GlobHeapMem.commit_attach",
"attaching bucket");
1081 DASH_LOG_TRACE_VAR(
"GlobHeapMem.commit_attach", bucket.size);
1082 DASH_LOG_TRACE_VAR(
"GlobHeapMem.commit_attach", bucket.lptr);
1084 bucket.gptr = _allocator.attach(bucket.lptr, bucket.size);
1085 bucket.attached =
true;
1086 DASH_LOG_TRACE(
"GlobHeapMem.commit_attach",
"attached bucket:",
1087 "gptr:", bucket.gptr);
1088 num_attached_elem += bucket.size;
1089 _num_attach_buckets.
local[0] -= 1;
1090 num_attached_buckets++;
1092 DASH_ASSERT(_attach_buckets_first == _buckets.end());
1096 DASH_LOG_TRACE(
"GlobHeapMem.commit_attach",
1097 "local buckets attached:", num_attached_buckets);
1098 DASH_LOG_TRACE(
"GlobHeapMem.commit_attach",
1099 "buckets required to attach:", max_attach_buckets);
1100 while (num_attached_buckets < max_attach_buckets) {
1101 DASH_LOG_TRACE(
"GlobHeapMem.commit_attach",
"attaching null bucket");
1104 bucket.allocated_size = 0;
1105 bucket.lptr = _allocator.allocate_local(0);
1106 bucket.gptr = _allocator.attach(bucket.lptr, bucket.size);
1107 bucket.attached =
true;
1109 _buckets.push_back(bucket);
1110 num_attached_buckets++;
1111 DASH_LOG_TRACE(
"GlobHeapMem.commit_attach",
"attached null bucket:",
1112 "gptr:", bucket.gptr,
1113 "left:", max_attach_buckets - num_attached_buckets);
1115 DASH_LOG_TRACE(
"GlobHeapMem.commit_attach >",
1116 "globally allocated elements:", num_attached_elem);
1117 return num_attached_elem;
1122 typename ValueType =
typename GlobalIt::value_type >
1123 std::pair<ValueType, ValueType> gather_min_max(
1124 const GlobalIt &
first,
1125 const GlobalIt & last)
1129 DASH_LOG_TRACE(
"GlobHeapMem.gather_min_max()");
1131 auto lcopy_end =
dash::copy(first, last, lcopy.data());
1134 std::pair<ValueType, ValueType> min_max;
1135 min_max.first = *min_lptr;
1136 min_max.second = *max_lptr;
1137 DASH_LOG_TRACE(
"GlobHeapMem.gather_min_max >",
1138 "min:", min_max.first,
1139 "max:", min_max.second);
1147 size_type update_remote_size()
1182 DASH_LOG_TRACE(
"GlobHeapMem.update_remote_size()");
1183 size_type new_remote_size = 0;
1185 std::vector<size_type> num_unattached_buckets(_nunits, 0);
1186 _num_attach_buckets.
barrier();
1188 num_unattached_buckets.data());
1190 #ifdef DASH_ENABLE_TRACE_LOGGING 1193 [](size_type
const& bsz) {
1194 DASH_LOG_TRACE(
"GlobMemHeap.update_remote_size()",
1195 "num_buckets at unit: ", bsz);
1199 std::vector<size_type> attach_buckets_sizes;
1200 std::vector<size_type> displs;
1201 std::vector<size_type> team_unattached_bucket_sizes;
1203 auto atLeast2 =
std::find_if(num_unattached_buckets.begin(),
1204 num_unattached_buckets.end(),
1205 [](size_type
const& sz) {
return sz > 1; });
1209 if (atLeast2 != num_unattached_buckets.end()) {
1213 for (
auto bit = _attach_buckets_first; bit != _buckets.end(); ++bit) {
1214 attach_buckets_sizes.push_back(bit->size);
1217 DASH_ASSERT(attach_buckets_sizes.size() ==
1218 _num_attach_buckets.
local[0]);
1219 DASH_LOG_TRACE_VAR(
"GlobHeapMem.update_remote_size",
1220 attach_buckets_sizes);
1225 auto const n_team_unattached_buckets =
1226 std::accumulate(
std::begin(num_unattached_buckets),
1227 std::end(num_unattached_buckets), 0);
1229 team_unattached_bucket_sizes.reserve(n_team_unattached_buckets);
1231 displs.reserve(_team->
size());
1235 std::partial_sum(
std::begin(num_unattached_buckets),
1237 std::end(num_unattached_buckets) - 1,
1243 attach_buckets_sizes.data(),
1249 team_unattached_bucket_sizes.data(),
1251 num_unattached_buckets.data(),
1259 for (size_type u = 0; u < _nunits; ++u) {
1263 DASH_LOG_TRACE(
"GlobHeapMem.update_remote_size",
1264 "collecting local bucket sizes of unit", u);
1266 auto& u_bucket_cumul_sizes = _bucket_cumul_sizes[u];
1268 size_type u_local_size_old = u_bucket_cumul_sizes.size() == 0
1270 : u_bucket_cumul_sizes.back();
1271 size_type u_local_size_new = _local_sizes[u];
1272 DASH_LOG_TRACE_VAR(
"GlobHeapMem.update_remote_size",
1274 DASH_LOG_TRACE_VAR(
"GlobHeapMem.update_remote_size",
1276 difference_type u_local_size_diff = u_local_size_new - u_local_size_old;
1277 new_remote_size += u_local_size_new;
1279 size_type u_num_attach_buckets = num_unattached_buckets[u];
1280 DASH_LOG_TRACE_VAR(
"GlobHeapMem.update_remote_size",
1281 u_num_attach_buckets);
1282 if (u_num_attach_buckets == 1) {
1285 u_bucket_cumul_sizes.push_back(u_local_size_new);
1287 else if (u_num_attach_buckets > 1) {
1288 auto const u_end = displs[u] + u_num_attach_buckets;
1289 for (
int bi = displs[u]; bi < u_end; ++bi) {
1290 size_type single_bkt_size = team_unattached_bucket_sizes[bi];
1291 size_type cumul_bkt_size = single_bkt_size;
1292 DASH_LOG_TRACE_VAR(
"GlobHeapMem.update_remote_size",
1294 if (u_bucket_cumul_sizes.size() > 0) {
1295 cumul_bkt_size += u_bucket_cumul_sizes.back();
1297 u_bucket_cumul_sizes.push_back(cumul_bkt_size);
1301 if (u_local_size_diff < 0 && u_bucket_cumul_sizes.size() > 0) {
1302 u_bucket_cumul_sizes.back() += u_local_size_diff;
1307 #if DASH_ENABLE_TRACE_LOGGING 1308 for (size_type u = 0; u < _nunits; ++u) {
1309 DASH_LOG_TRACE(
"GlobHeapMem.update_remote_size",
1311 "cumulative bucket sizes:", _bucket_cumul_sizes[u]);
1314 DASH_LOG_TRACE(
"GlobHeapMem.update_remote_size >", new_remote_size);
1315 _remote_size = new_remote_size;
1316 return _remote_size;
1326 index_type bucket_index,
1328 index_type bucket_phase)
const 1330 DASH_LOG_DEBUG(
"GlobHeapMem.dart_gptr_at(u,bi,bp)",
1331 unit, bucket_index, bucket_phase);
1336 auto bucket_it = _buckets.begin();
1337 std::advance(bucket_it, bucket_index);
1339 DASH_LOG_TRACE_VAR(
"GlobHeapMem.dart_gptr_at", bucket_it->attached);
1340 DASH_LOG_TRACE_VAR(
"GlobHeapMem.dart_gptr_at", bucket_it->gptr);
1341 if (unit == _myid) {
1342 DASH_LOG_TRACE_VAR(
"GlobHeapMem.dart_gptr_at", bucket_it->lptr);
1343 DASH_LOG_TRACE_VAR(
"GlobHeapMem.dart_gptr_at", bucket_it->size);
1344 DASH_ASSERT_LT(bucket_phase, bucket_it->size,
1345 "bucket phase out of bounds");
1348 DASH_LOG_TRACE(
"GlobHeapMem.dart_gptr_at",
1349 "bucket.gptr is DART_GPTR_NULL");
1353 DASH_ASSERT_RETURNS(
1356 DASH_ASSERT_RETURNS(
1359 bucket_phase *
sizeof(value_type)),
1362 DASH_LOG_DEBUG(
"GlobHeapMem.dart_gptr_at >",
dart_gptr);
1370 #endif // DASH__GLOB_HEAP_H__INCLUDED constexpr size_type size() const noexcept
Number of array elements in local memory.
const_pointer end() const noexcept
Global pointer of the initial address of the global memory.
constexpr auto end(RangeType &&range) -> decltype(std::forward< RangeType >(range).end())
This class is a simple memory pool which holds allocates elements of size ValueType.
RandomAccessIt::difference_type distance(const RandomAccessIt &first, const RandomAccessIt &last)
Resolve the number of elements between two iterators.
constexpr size_type size() const noexcept
Total number of elements in attached memory space, including size of local unattached memory segments...
const_pointer at(team_unit_t unit, IndexT local_index) const
Resolve the global iterator referencing an element position in a unit's local memory.
const_local_pointer & lend() const noexcept
Native pointer of the initial address of the local memory of the unit that initialized this GlobHeapM...
void put_value(const ValueType &newval, index_type global_index)
Write value to global memory at given offset.
constexpr auto begin(RangeType &&range) -> decltype(std::forward< RangeType >(range).begin())
iterator end() noexcept
Global pointer to the end of the array.
constexpr bool operator!=(const self_t &rhs) const noexcept
Inequality comparison operator.
GlobHeapMem(size_type n_local_elem, dash::Team &team)
Constructor, collectively allocates the given number of elements in local memory of every unit in a t...
Encapsulates a memory allocation and deallocation strategy of global memory regions distributed acros...
GlobIter find_if(GlobIter first, GlobIter last, UnaryPredicate predicate)
Returns an iterator to the first element in the range [first,last) that satisfies the predicate p...
void resize(size_type num_elements)
Resize capacity of local segment of global memory region to the given number of elements.
void commit()
Commit changes of local memory region to global memory space.
GlobHeapMem(size_type n_local_elem, LocalMemorySpace *r)
Constructor, collectively allocates the given number of elements in local memory of every unit in das...
local_pointer & lend() noexcept
Native pointer of the initial address of the local memory of the unit that initialized this GlobHeapM...
pointer begin() noexcept
Global pointer of the initial address of the global memory.
size_t size() const
The number of units in this team.
constexpr bool operator==(const self_t &rhs) const noexcept
Equality comparison operator.
const ElementType * min_element(const ElementType *l_range_begin, const ElementType *l_range_end, Compare compare=std::less< const ElementType &>())
Finds an iterator pointing to the element with the smallest value in the range [first,last).
MemSpace memory_space_type
The Memory Space Type.
dart_gptr_t dart_gptr() const
Explicit conversion to dart_gptr_t.
Global memory region with dynamic size.
#define DART_GPTR_NULL
A NULL global pointer.
A Team instance specifies a subset of all available units.
all units allocate invdividually in local memory and synchronize in epochs
local_pointer grow(size_type num_elements)
Increase capacity of local segment of global memory region by the given number of elements...
size_type local_size(team_unit_t unit) const
Number of elements in local memory space of given unit.
void put_value(const T &newval, const GlobPtrType &gptr)
Write a value to a global pointer.
pointer at(team_unit_t unit, IndexT local_index)
Resolve the global iterator referencing an element position in a unit's local memory.
void shrink(size_type num_elements)
Decrease capacity of local segment of global memory region by the given number of elements...
Iterator on global buckets.
DART Global pointer type.
dart_ret_t dart_barrier(dart_team_t team)
DART Equivalent to MPI_Barrier.
#define DART_GPTR_ISNULL(gptr_)
Test for NULL global pointer.
constexpr size_type local_size() const noexcept
Number of elements in local memory space.
const_local_pointer lbegin() const noexcept
Native pointer of the initial address of the local memory of the unit that initialized this GlobHeapM...
struct dash::unit_id< dash::local_unit, dart_team_unit_t > team_unit_t
Unit ID to use for team-local IDs.
void barrier() const
Synchronize all units associated with this global memory instance.
int16_t dart_team_t
Data type for storing a team ID.
void barrier() const
Establish a barrier for all units operating on the array, publishing all changes to all units...
OutputIt copy(InputIt in_first, InputIt in_last, OutputIt out_first)
Copies the elements in the range, defined by [in_first, in_last), to another range beginning at out_f...
GlobIter max_element(const GlobIter &first, const GlobIter &last, Compare compare=Compare())
Finds an iterator pointing to the element with the greatest value in the range [first,last).
~GlobHeapMem()
Destructor, collectively frees underlying global memory.
static Team & Null()
The invariant Team instance representing an undefined team.
GlobHeapMem(size_type n_local_elem=0)
Constructor, collectively allocates the given number of elements in local memory of every unit in das...
#define DART_UNDEFINED_UNIT_ID
Undefined unit ID.
struct dash::dart_operation ValueType
Reduce operands to their minimum value.
dart_ret_t dart_allgatherv(const void *sendbuf, size_t nsendelem, dart_datatype_t dtype, void *recvbuf, const size_t *nrecvelem, const size_t *recvdispls, dart_team_t teamid)
DART Equivalent to MPI allgatherv.
pointer end() noexcept
Global pointer of the initial address of the global memory.
constexpr const_pointer begin() const noexcept
Global pointer of the initial address of the global memory.
Convencience wrapper to determine the DART type and number of elements required for the given templat...
constexpr dash::Team & team() const noexcept
The team containing all units accessing the global memory space.
iterator begin() noexcept
Global pointer to the beginning of the array.
void for_each(const GlobInputIt &first, const GlobInputIt &last, UnaryFunction func)
Invoke a function on every element in a range distributed by a pattern.
self_t & operator=(const self_t &rhs)=default
Assignment operator.
dash::gptrdiff_t distance(GlobPtr< T, MemSpaceT > gbegin, GlobPtr< T, MemSpaceT > gend)
Returns the number of hops from gbegin to gend.
local_pointer & lbegin() noexcept
Native pointer of the initial address of the local memory of the unit that initialized this GlobHeapM...
void get_value(T *ptr, const GlobPtrType &gptr)
Read a value fom a global pointer.
dart_team_t dart_id() const
Index of this team relative to global team dash::Team::All().
void get_value(ValueType *ptr, index_type global_index) const
Read value from global memory at given offset.
local_type local
Local proxy object, allows use in range-based for loops.