DASH  0.3.0
dash::GlobHeapMem< ElementType, LocalMemorySpace, AllocationPolicy, LocalAlloc > Class Template Reference

Global memory region with dynamic size. More...

#include <GlobHeapMem.h>

Public Types

using value_type = typename allocator_traits::value_type
 
using allocator_type = typename allocator_traits::allocator_type
 
using local_memory_space = typename memory_traits::memory_space_type
 
typedef allocator_type::size_type size_type
 
typedef allocator_type::difference_type difference_type
 
typedef allocator_type::difference_type index_type
 
typedef allocator_type::pointer raw_pointer
 
typedef GlobHeapLocalPtr< value_type, index_type > local_pointer
 
typedef GlobHeapLocalPtr< value_type, index_type > const_local_pointer
 
typedef GlobHeapPtr< value_type, GlobHeapMempointer
 
typedef GlobHeapPtr< const value_type, GlobHeapMemconst_pointer
 
typedef value_type & local_reference
 
typedef const value_type & const_local_reference
 
typedef local_pointer::bucket_type bucket_type
 
template<typename U >
using rebind = GlobHeapMem< U, LocalMemorySpace, AllocationPolicy, LocalAlloc >
 
using local_void_pointer = void *
 

Public Member Functions

 GlobHeapMem (size_type n_local_elem=0)
 Constructor, collectively allocates the given number of elements in local memory of every unit in dash::Team::All(). More...
 
 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 team. More...
 
 GlobHeapMem (size_type n_local_elem, LocalMemorySpace *r)
 Constructor, collectively allocates the given number of elements in local memory of every unit in dash::Team::All(). More...
 
 GlobHeapMem (size_type n_local_elem, LocalMemorySpace *r, Team &team)
 
 ~GlobHeapMem ()
 Destructor, collectively frees underlying global memory. More...
 
 GlobHeapMem (const self_t &other)=default
 Copy constructor. More...
 
self_toperator= (const self_t &rhs)=default
 Assignment operator. More...
 
constexpr bool operator== (const self_t &rhs) const noexcept
 Equality comparison operator. More...
 
constexpr bool operator!= (const self_t &rhs) const noexcept
 Inequality comparison operator. More...
 
constexpr size_type size () const noexcept
 Total number of elements in attached memory space, including size of local unattached memory segments. More...
 
constexpr size_type local_size () const noexcept
 Number of elements in local memory space. More...
 
size_type local_size (team_unit_t unit) const
 Number of elements in local memory space of given unit. More...
 
constexpr dash::Teamteam () const noexcept
 The team containing all units accessing the global memory space. More...
 
local_pointer grow (size_type num_elements)
 Increase capacity of local segment of global memory region by the given number of elements. More...
 
void shrink (size_type num_elements)
 Decrease capacity of local segment of global memory region by the given number of elements. More...
 
void commit ()
 Commit changes of local memory region to global memory space. More...
 
void resize (size_type num_elements)
 Resize capacity of local segment of global memory region to the given number of elements. More...
 
pointer begin () noexcept
 Global pointer of the initial address of the global memory. More...
 
constexpr const_pointer begin () const noexcept
 Global pointer of the initial address of the global memory. More...
 
pointer end () noexcept
 Global pointer of the initial address of the global memory. More...
 
const_pointer end () const noexcept
 Global pointer of the initial address of the global memory. More...
 
local_pointerlbegin () noexcept
 Native pointer of the initial address of the local memory of the unit that initialized this GlobHeapMem instance. More...
 
const_local_pointer lbegin () const noexcept
 Native pointer of the initial address of the local memory of the unit that initialized this GlobHeapMem instance. More...
 
local_pointerlend () noexcept
 Native pointer of the initial address of the local memory of the unit that initialized this GlobHeapMem instance. More...
 
const_local_pointerlend () const noexcept
 Native pointer of the initial address of the local memory of the unit that initialized this GlobHeapMem instance. More...
 
template<typename ValueType = value_type>
void put_value (const ValueType &newval, index_type global_index)
 Write value to global memory at given offset. More...
 
template<typename ValueType = value_type>
void get_value (ValueType *ptr, index_type global_index) const
 Read value from global memory at given offset. More...
 
void barrier () const
 Synchronize all units associated with this global memory instance. More...
 
template<typename IndexT >
pointer at (team_unit_t unit, IndexT local_index)
 Resolve the global iterator referencing an element position in a unit's local memory. More...
 
template<typename IndexT >
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. More...
 
const bucket_list & local_buckets () const
 

Detailed Description

template<typename ElementType, class LocalMemorySpace = dash::HostSpace, global_allocation_policy AllocationPolicy = global_allocation_policy::epoch_synchronized, template< class > class LocalAlloc = allocator::DefaultAllocator>
class dash::GlobHeapMem< ElementType, LocalMemorySpace, AllocationPolicy, LocalAlloc >

Global memory region with dynamic size.

For global memory spaces with static size, see dash::GlobStaticMem.

See also
dash::GlobStaticMem

Conventional global memory (see dash::GlobStaticMem) allocates a single contiguous range of fixed size in local memory at every unit. Iterating static memory space is trivial as native pointer arithmetics can be used to traverse elements in canonical storage order.

In global dynamic memory, units allocate multiple heap-allocated buckets in local memory. The number of local buckets and their sizes may differ between units. In effect, elements in local memory are distributed in non-contiguous address ranges and a custom iterator is used to access elements in logical storage order.

Usage examples:

size_t initial_local_capacity = 1024;
GlobHeapMem<double> gdmem(initial_local_capacity);
size_t initial_global_capacity = dash::size() * initial_local_capacity;
if (dash::myid() == 0) {
// Allocate another 512 elements in local memory space.
// This is a local operation, the additionally allocated memory
// space is only accessible by the local unit, however:
gdmem.grow(512);
}
if (dash::myid() == 1) {
// Decrease capacity of local memory space by 128 units.
// This is a local operation. New size of logical memory space is
// effective for the local unit immediately but memory is not
// physically freed yet and is still accessible by other units.
gdmem.shrink(128);
}
// Global memory space has not been updated yet, changes are only
// visible locally:
if (dash::myid() == 0) {
assert(gdmem.size() == initial_global_capacity + 512);
} else if (dash::myid() == 1) {
assert(gdmem.size() == initial_global_capacity - 128);
} else {
assert(gdmem.size() == initial_global_capacity);
}
auto unit_0_local_size = gdmem.lend(0) - gdmem.lbegin(0);
auto unit_1_local_size = gdmem.lend(1) - gdmem.lbegin(1);
if (dash::myid() == 0) {
assert(unit_0_local_size == 1024 + 512);
assert(unit_0_local_size == gdmem.local_size());
} else {
assert(unit_0_local_size == initial_local_capacity);
}
if (dash::myid() == 1) {
assert(unit_1_local_size == 1024 - 128);
assert(unit_1_local_size == gdmem.local_size());
} else {
assert(unit_1_local_size == initial_local_capacity);
}
// Memory marked for deallocation is still accessible by other units:
if (dash::myid() != 1) {
auto unit_1_last = gdmem.at(dash::myid(), initial_local_capacity-1);
double * value;
gdmem.get_value(value, unit_1_last);
}
// Collectively commit changes of local memory allocation to global
// memory space:
// register newly allocated local memory and remove local memory marked
// for deallocation.
gdmem.commit();
// Changes are globally visible now:
assert(gdmem.size() == initial_global_capacity + 512 - 128);
unit_0_local_size = gdmem.lend(0) - gdmem.lbegin(0);
unit_1_local_size = gdmem.lend(1) - gdmem.lbegin(1);
assert(unit_0_local_size == 1024 + 512);
assert(unit_1_local_size == 1024 - 128);
Implemented concept:
DashMemorySpaceConcept
Implemented concept:
Global Dynamic Memory Concept

Definition at line 204 of file GlobHeapMem.h.

Constructor & Destructor Documentation

◆ ~GlobHeapMem()

template<typename ElementType , class LocalMemorySpace = dash::HostSpace, global_allocation_policy AllocationPolicy = global_allocation_policy::epoch_synchronized, template< class > class LocalAlloc = allocator::DefaultAllocator>
dash::GlobHeapMem< ElementType, LocalMemorySpace, AllocationPolicy, LocalAlloc >::~GlobHeapMem ( )
inline

Destructor, collectively frees underlying global memory.

Definition at line 380 of file GlobHeapMem.h.

References dash::GlobHeapMem< ElementType, LocalMemorySpace, AllocationPolicy, LocalAlloc >::operator=().

381  {
382  DASH_LOG_TRACE("GlobHeapMem.~GlobHeapMem()");
383  }

◆ GlobHeapMem()

template<typename ElementType , class LocalMemorySpace = dash::HostSpace, global_allocation_policy AllocationPolicy = global_allocation_policy::epoch_synchronized, template< class > class LocalAlloc = allocator::DefaultAllocator>
dash::GlobHeapMem< ElementType, LocalMemorySpace, AllocationPolicy, LocalAlloc >::GlobHeapMem ( const self_t other)
default

Copy constructor.

Member Function Documentation

◆ at() [1/2]

template<typename ElementType , class LocalMemorySpace = dash::HostSpace, global_allocation_policy AllocationPolicy = global_allocation_policy::epoch_synchronized, template< class > class LocalAlloc = allocator::DefaultAllocator>
template<typename IndexT >
pointer dash::GlobHeapMem< ElementType, LocalMemorySpace, AllocationPolicy, LocalAlloc >::at ( team_unit_t  unit,
IndexT  local_index 
)
inline

Resolve the global iterator referencing an element position in a unit's local memory.

Parameters
unitThe unit id
local_indexThe unit's local address offset

Definition at line 913 of file GlobHeapMem.h.

Referenced by dash::UnorderedMapLocalIter< Key, Mapped, Hash, Pred, LMemSpace >::dart_gptr().

918  {
919  DASH_LOG_DEBUG("GlobHeapMem.at()",
920  "unit:", unit, "lidx:", local_index);
921  if (_nunits == 0) {
922  DASH_THROW(dash::exception::RuntimeError, "No units in team");
923  }
924  pointer git(this, unit, local_index);
925  DASH_LOG_DEBUG_VAR("GlobHeapMem.at >", git);
926  return git;
927  }

◆ at() [2/2]

template<typename ElementType , class LocalMemorySpace = dash::HostSpace, global_allocation_policy AllocationPolicy = global_allocation_policy::epoch_synchronized, template< class > class LocalAlloc = allocator::DefaultAllocator>
template<typename IndexT >
const_pointer dash::GlobHeapMem< ElementType, LocalMemorySpace, AllocationPolicy, LocalAlloc >::at ( team_unit_t  unit,
IndexT  local_index 
) const
inline

Resolve the global iterator referencing an element position in a unit's local memory.

Parameters
unitThe unit id
local_indexThe unit's local address offset

Definition at line 934 of file GlobHeapMem.h.

939  {
940  DASH_LOG_DEBUG("GlobHeapMem.at() const",
941  "unit:", unit, "lidx:", local_index);
942  if (_nunits == 0) {
943  DASH_THROW(dash::exception::RuntimeError, "No units in team");
944  }
945  const_pointer git(this, unit, local_index);
946  DASH_LOG_DEBUG_VAR("GlobHeapMem.at const >", git);
947  return git;
948  }

◆ barrier()

template<typename ElementType , class LocalMemorySpace = dash::HostSpace, global_allocation_policy AllocationPolicy = global_allocation_policy::epoch_synchronized, template< class > class LocalAlloc = allocator::DefaultAllocator>
void dash::GlobHeapMem< ElementType, LocalMemorySpace, AllocationPolicy, LocalAlloc >::barrier ( ) const
inline

Synchronize all units associated with this global memory instance.

Does not commit changes of local memory space.

See also
commit

Definition at line 901 of file GlobHeapMem.h.

References dart_barrier(), and DART_OK.

902  {
903  DASH_ASSERT_RETURNS(
904  dart_barrier(_teamid),
905  DART_OK);
906  }
Signals success.
Definition: dart_types.h:33
dart_ret_t dart_barrier(dart_team_t team)
DART Equivalent to MPI_Barrier.

◆ begin() [1/2]

template<typename ElementType , class LocalMemorySpace = dash::HostSpace, global_allocation_policy AllocationPolicy = global_allocation_policy::epoch_synchronized, template< class > class LocalAlloc = allocator::DefaultAllocator>
pointer dash::GlobHeapMem< ElementType, LocalMemorySpace, AllocationPolicy, LocalAlloc >::begin ( )
inlinenoexcept

Global pointer of the initial address of the global memory.

Definition at line 798 of file GlobHeapMem.h.

799  {
800  return pointer(this, _begin_idx);
801  }

◆ begin() [2/2]

template<typename ElementType , class LocalMemorySpace = dash::HostSpace, global_allocation_policy AllocationPolicy = global_allocation_policy::epoch_synchronized, template< class > class LocalAlloc = allocator::DefaultAllocator>
constexpr const_pointer dash::GlobHeapMem< ElementType, LocalMemorySpace, AllocationPolicy, LocalAlloc >::begin ( ) const
inlinenoexcept

Global pointer of the initial address of the global memory.

Definition at line 806 of file GlobHeapMem.h.

807  {
808  return const_pointer(this, _begin_idx);
809  }

◆ commit()

template<typename ElementType , class LocalMemorySpace = dash::HostSpace, global_allocation_policy AllocationPolicy = global_allocation_policy::epoch_synchronized, template< class > class LocalAlloc = allocator::DefaultAllocator>
void dash::GlobHeapMem< ElementType, LocalMemorySpace, AllocationPolicy, LocalAlloc >::commit ( )
inline

Commit changes of local memory region to global memory space.

Applies calls of grow(), shrink() and resize() to global memory.

Collective operation.

Attaches local memory allocated since the last call of commit() to global memory space and thus makes it accessible to other units. Frees local memory marked for deallocation and detaches it from global memory.

See also
resize
grow
shrink

Definition at line 739 of file GlobHeapMem.h.

References dash::GlobHeapMem< ElementType, LocalMemorySpace, AllocationPolicy, LocalAlloc >::size().

Referenced by dash::List< ElementType, LocalMemorySpace >::barrier(), and dash::GlobHeapMem< ElementType, LocalMemorySpace, AllocationPolicy, LocalAlloc >::GlobHeapMem().

740  {
741  DASH_LOG_DEBUG("GlobHeapMem.commit()");
742  DASH_LOG_TRACE_VAR("GlobHeapMem.commit", _buckets.size());
743 
744  // First detach, then attach to minimize number of elements allocated
745  // at the same time:
746  size_type num_detached_elem = commit_detach();
747  size_type num_attached_elem = commit_attach();
748 
749  if (num_detached_elem > 0 || num_attached_elem > 0) {
750  // Update _begin iterator:
751  DASH_LOG_TRACE("GlobHeapMem.commit", "updating _begin");
752  _begin_idx = 0;
753  DASH_LOG_TRACE("GlobHeapMem.commit", "updating _end");
754  _end_idx = size();
755  }
756  // Update local iterators as bucket iterators might have changed:
757  DASH_LOG_TRACE("GlobHeapMem.commit", "updating _lbegin");
758  update_lbegin();
759  DASH_LOG_TRACE("GlobHeapMem.commit", "updating _lend");
760  update_lend();
761  DASH_LOG_DEBUG("GlobHeapMem.commit >", "finished");
762  }
constexpr size_type size() const noexcept
Total number of elements in attached memory space, including size of local unattached memory segments...
Definition: GlobHeapMem.h:422

◆ end() [1/2]

template<typename ElementType , class LocalMemorySpace = dash::HostSpace, global_allocation_policy AllocationPolicy = global_allocation_policy::epoch_synchronized, template< class > class LocalAlloc = allocator::DefaultAllocator>
pointer dash::GlobHeapMem< ElementType, LocalMemorySpace, AllocationPolicy, LocalAlloc >::end ( )
inlinenoexcept

Global pointer of the initial address of the global memory.

Definition at line 814 of file GlobHeapMem.h.

815  {
816  return pointer(this, _end_idx);
817  }

◆ end() [2/2]

template<typename ElementType , class LocalMemorySpace = dash::HostSpace, global_allocation_policy AllocationPolicy = global_allocation_policy::epoch_synchronized, template< class > class LocalAlloc = allocator::DefaultAllocator>
const_pointer dash::GlobHeapMem< ElementType, LocalMemorySpace, AllocationPolicy, LocalAlloc >::end ( ) const
inlinenoexcept

Global pointer of the initial address of the global memory.

Definition at line 822 of file GlobHeapMem.h.

823  {
824  return const_pointer(this, _end_idx);
825  }

◆ get_value()

template<typename ElementType , class LocalMemorySpace = dash::HostSpace, global_allocation_policy AllocationPolicy = global_allocation_policy::epoch_synchronized, template< class > class LocalAlloc = allocator::DefaultAllocator>
template<typename ValueType = value_type>
void dash::GlobHeapMem< ElementType, LocalMemorySpace, AllocationPolicy, LocalAlloc >::get_value ( ValueType ptr,
index_type  global_index 
) const
inline

Read value from global memory at given offset.

See also
dash::get_value

Definition at line 885 of file GlobHeapMem.h.

References dash::get_value().

888  {
889  DASH_LOG_TRACE("GlobHeapMem.get_value(newval, gidx = %d)",
890  global_index);
891  auto git = pointer(this, global_index);
892  dash::get_value(ptr, git);
893  }
void get_value(T *ptr, const GlobPtrType &gptr)
Read a value fom a global pointer.
Definition: Onesided.h:230

◆ grow()

template<typename ElementType , class LocalMemorySpace = dash::HostSpace, global_allocation_policy AllocationPolicy = global_allocation_policy::epoch_synchronized, template< class > class LocalAlloc = allocator::DefaultAllocator>
local_pointer dash::GlobHeapMem< ElementType, LocalMemorySpace, AllocationPolicy, LocalAlloc >::grow ( size_type  num_elements)
inline

Increase capacity of local segment of global memory region by the given number of elements.

Same as resize(size() + num_elements).

Local operation. Newly allocated memory is attached to global memory space by calling the collective operation attach().

Returns
Native pointer to beginning of new allocated memory.
See also
resize
shrink
commit

Definition at line 485 of file GlobHeapMem.h.

References DART_GPTR_NULL, and dash::Array< ElementType, IndexType, PatternType, LocalMemSpaceT >::local.

Referenced by dash::GlobHeapMem< ElementType, LocalMemorySpace, AllocationPolicy, LocalAlloc >::GlobHeapMem(), dash::LocalListRef< ElementType, LocalMemorySpace >::push_back(), and dash::GlobHeapMem< ElementType, LocalMemorySpace, AllocationPolicy, LocalAlloc >::resize().

486  {
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");
493  return _lend;
494  }
495  // Update size of local memory space:
496  _local_sizes.local[0] += num_elements;
497  // Update number of local buckets marked for attach:
498  _num_attach_buckets.local[0] += 1;
499 
500  // Create new unattached bucket:
501  DASH_LOG_TRACE("GlobHeapMem.grow", "creating new unattached bucket:",
502  "size:", num_elements);
503  bucket_type bucket;
504  bucket.size = num_elements;
505  bucket.allocated_size = num_elements;
506  bucket.lptr = _allocator.allocate_local(bucket.size);
507  bucket.gptr = DART_GPTR_NULL;
508  bucket.attached = false;
509  // Add bucket to local memory space:
510  _buckets.push_back(bucket);
511  if (_attach_buckets_first == _buckets.end()) {
512  // Move iterator to first unattached bucket to position of new bucket:
513  _attach_buckets_first = _buckets.begin();
514  std::advance(_attach_buckets_first, _buckets.size() - 1);
515  }
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);
520  // Update local iteration space:
521  update_lbegin();
522  update_lend();
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 >");
531  // Return local iterator to start of allocated memory:
532  return _lbegin + local_size_old;
533  }
#define DART_GPTR_NULL
A NULL global pointer.
Definition: dart_globmem.h:105
local_type local
Local proxy object, allows use in range-based for loops.
Definition: Array.h:732

◆ lbegin() [1/2]

template<typename ElementType , class LocalMemorySpace = dash::HostSpace, global_allocation_policy AllocationPolicy = global_allocation_policy::epoch_synchronized, template< class > class LocalAlloc = allocator::DefaultAllocator>
local_pointer& dash::GlobHeapMem< ElementType, LocalMemorySpace, AllocationPolicy, LocalAlloc >::lbegin ( )
inlinenoexcept

◆ lbegin() [2/2]

template<typename ElementType , class LocalMemorySpace = dash::HostSpace, global_allocation_policy AllocationPolicy = global_allocation_policy::epoch_synchronized, template< class > class LocalAlloc = allocator::DefaultAllocator>
const_local_pointer dash::GlobHeapMem< ElementType, LocalMemorySpace, AllocationPolicy, LocalAlloc >::lbegin ( ) const
inlinenoexcept

Native pointer of the initial address of the local memory of the unit that initialized this GlobHeapMem instance.

Definition at line 840 of file GlobHeapMem.h.

841  {
842  return _lbegin;
843  }

◆ lend() [1/2]

template<typename ElementType , class LocalMemorySpace = dash::HostSpace, global_allocation_policy AllocationPolicy = global_allocation_policy::epoch_synchronized, template< class > class LocalAlloc = allocator::DefaultAllocator>
local_pointer& dash::GlobHeapMem< ElementType, LocalMemorySpace, AllocationPolicy, LocalAlloc >::lend ( )
inlinenoexcept

Native pointer of the initial address of the local memory of the unit that initialized this GlobHeapMem instance.

Definition at line 849 of file GlobHeapMem.h.

850  {
851  return _lend;
852  }

◆ lend() [2/2]

template<typename ElementType , class LocalMemorySpace = dash::HostSpace, global_allocation_policy AllocationPolicy = global_allocation_policy::epoch_synchronized, template< class > class LocalAlloc = allocator::DefaultAllocator>
const_local_pointer& dash::GlobHeapMem< ElementType, LocalMemorySpace, AllocationPolicy, LocalAlloc >::lend ( ) const
inlinenoexcept

Native pointer of the initial address of the local memory of the unit that initialized this GlobHeapMem instance.

Definition at line 858 of file GlobHeapMem.h.

859  {
860  return _lend;
861  }

◆ local_size() [1/2]

template<typename ElementType , class LocalMemorySpace = dash::HostSpace, global_allocation_policy AllocationPolicy = global_allocation_policy::epoch_synchronized, template< class > class LocalAlloc = allocator::DefaultAllocator>
constexpr size_type dash::GlobHeapMem< ElementType, LocalMemorySpace, AllocationPolicy, LocalAlloc >::local_size ( ) const
inlinenoexcept

◆ local_size() [2/2]

template<typename ElementType , class LocalMemorySpace = dash::HostSpace, global_allocation_policy AllocationPolicy = global_allocation_policy::epoch_synchronized, template< class > class LocalAlloc = allocator::DefaultAllocator>
size_type dash::GlobHeapMem< ElementType, LocalMemorySpace, AllocationPolicy, LocalAlloc >::local_size ( team_unit_t  unit) const
inline

Number of elements in local memory space of given unit.

Returns
Local capacity as published by the specified unit in last commit.

Definition at line 441 of file GlobHeapMem.h.

442  {
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;
448  if (unit == _myid) {
449  // Value of _local_sizes[u] is the local size as visible by the unit,
450  // i.e. including size of unattached buckets.
451  unit_local_size = _local_sizes.local[0];
452  } else {
453  unit_local_size = _bucket_cumul_sizes[unit].back();
454  }
455  DASH_LOG_TRACE("GlobHeapMem.local_size >", unit_local_size);
456  return unit_local_size;
457  }
local_type local
Local proxy object, allows use in range-based for loops.
Definition: Array.h:732

◆ operator!=()

template<typename ElementType , class LocalMemorySpace = dash::HostSpace, global_allocation_policy AllocationPolicy = global_allocation_policy::epoch_synchronized, template< class > class LocalAlloc = allocator::DefaultAllocator>
constexpr bool dash::GlobHeapMem< ElementType, LocalMemorySpace, AllocationPolicy, LocalAlloc >::operator!= ( const self_t rhs) const
inlinenoexcept

Inequality comparison operator.

Definition at line 413 of file GlobHeapMem.h.

414  {
415  return !(*this == rhs);
416  }

◆ operator=()

template<typename ElementType , class LocalMemorySpace = dash::HostSpace, global_allocation_policy AllocationPolicy = global_allocation_policy::epoch_synchronized, template< class > class LocalAlloc = allocator::DefaultAllocator>
self_t& dash::GlobHeapMem< ElementType, LocalMemorySpace, AllocationPolicy, LocalAlloc >::operator= ( const self_t rhs)
default

◆ operator==()

template<typename ElementType , class LocalMemorySpace = dash::HostSpace, global_allocation_policy AllocationPolicy = global_allocation_policy::epoch_synchronized, template< class > class LocalAlloc = allocator::DefaultAllocator>
constexpr bool dash::GlobHeapMem< ElementType, LocalMemorySpace, AllocationPolicy, LocalAlloc >::operator== ( const self_t rhs) const
inlinenoexcept

Equality comparison operator.

Definition at line 400 of file GlobHeapMem.h.

401  {
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);
408  }

◆ put_value()

template<typename ElementType , class LocalMemorySpace = dash::HostSpace, global_allocation_policy AllocationPolicy = global_allocation_policy::epoch_synchronized, template< class > class LocalAlloc = allocator::DefaultAllocator>
template<typename ValueType = value_type>
void dash::GlobHeapMem< ElementType, LocalMemorySpace, AllocationPolicy, LocalAlloc >::put_value ( const ValueType newval,
index_type  global_index 
)
inline

Write value to global memory at given offset.

See also
dash::put_value

Definition at line 869 of file GlobHeapMem.h.

References dash::put_value().

872  {
873  DASH_LOG_TRACE("GlobHeapMem.put_value(newval, gidx = %d)",
874  global_index);
875  auto git = pointer(this, global_index);
876  dash::put_value(newval, git);
877  }
void put_value(const T &newval, const GlobPtrType &gptr)
Write a value to a global pointer.
Definition: Onesided.h:214

◆ resize()

template<typename ElementType , class LocalMemorySpace = dash::HostSpace, global_allocation_policy AllocationPolicy = global_allocation_policy::epoch_synchronized, template< class > class LocalAlloc = allocator::DefaultAllocator>
void dash::GlobHeapMem< ElementType, LocalMemorySpace, AllocationPolicy, LocalAlloc >::resize ( size_type  num_elements)
inline

Resize capacity of local segment of global memory region to the given number of elements.

Local operation.

If capacity is increased, newly allocated memory is only attached to global memory space and thus made accessible to other units by calling the collective operation commit(). If capacity is decreased, resizes logical local memory space but does not deallocate memory. Local memory is accessible by other units until deallocated and detached from global memory space by calling the collective operation commit().

See also
grow
shrink
commit

Definition at line 783 of file GlobHeapMem.h.

References dash::GlobHeapMem< ElementType, LocalMemorySpace, AllocationPolicy, LocalAlloc >::grow(), dash::GlobHeapMem< ElementType, LocalMemorySpace, AllocationPolicy, LocalAlloc >::shrink(), and dash::GlobHeapMem< ElementType, LocalMemorySpace, AllocationPolicy, LocalAlloc >::size().

784  {
785  DASH_LOG_DEBUG("GlobHeapMem.resize()", "new size:", num_elements);
786  index_type diff_capacity = num_elements - size();
787  if (diff_capacity > 0) {
788  grow(diff_capacity);
789  } else if (diff_capacity < 0) {
790  shrink(-diff_capacity);
791  }
792  DASH_LOG_DEBUG("GlobHeapMem.resize >");
793  }
constexpr size_type size() const noexcept
Total number of elements in attached memory space, including size of local unattached memory segments...
Definition: GlobHeapMem.h:422
local_pointer grow(size_type num_elements)
Increase capacity of local segment of global memory region by the given number of elements...
Definition: GlobHeapMem.h:485
void shrink(size_type num_elements)
Decrease capacity of local segment of global memory region by the given number of elements...
Definition: GlobHeapMem.h:553

◆ shrink()

template<typename ElementType , class LocalMemorySpace = dash::HostSpace, global_allocation_policy AllocationPolicy = global_allocation_policy::epoch_synchronized, template< class > class LocalAlloc = allocator::DefaultAllocator>
void dash::GlobHeapMem< ElementType, LocalMemorySpace, AllocationPolicy, LocalAlloc >::shrink ( size_type  num_elements)
inline

Decrease capacity of local segment of global memory region by the given number of elements.

Buckets are not deallocated until next commit as other units might still reference them. Same as resize(size() - num_elements).

Local operation.

Resizes logical local memory space but does not deallocate memory. Local memory is accessible by other units until deallocated and detached from global memory space by calling the collective operation commit().

See also
resize
grow
commit

Definition at line 553 of file GlobHeapMem.h.

References dash::distance(), dash::Array< ElementType, IndexType, PatternType, LocalMemSpaceT >::local, dash::GlobHeapMem< ElementType, LocalMemorySpace, AllocationPolicy, LocalAlloc >::local_size(), and dash::LocalArrayRef< T, IndexType, PatternType, LocalMemSpaceT >::size().

Referenced by dash::GlobHeapMem< ElementType, LocalMemorySpace, AllocationPolicy, LocalAlloc >::resize().

554  {
555  // This function updates the size of the local memory space of the
556  // calling unit u.
557  // The following members are updated:
558  //
559  // _local_sizes[u]:
560  // Size of local memory space as visible to unit u.
561  //
562  // _bucket_cumul_sizes:
563  // An array mapping units to a list of their cumulative bucket sizes
564  // (i.e. postfix sum) which is required to iterate over the
565  // non-contigous global dynamic memory space.
566  // For example, if unit 2 allocated buckets with sizes 1, 3 and 5,
567  // _bucket_cumul_sizes[2] is a list { 1, 4, 9 }.
568  //
569  // _buckets:
570  // List of local buckets that provide the underlying storage of the
571  // active unit's local memory space.
572  //
573  // Notes:
574  //
575  // It must be ensured that the updated cumulative bucket sizes of a
576  // remote unit can be resolved in \c update_local_size() after any
577  // possible combination of grow- and shrink-operations at the remote unit
578  // from the following information:
579  //
580  // - the cumulative bucket sizes of the remote unit at the time of the
581  // last commit
582  // - the remote unit's local size at the time of the last commit
583  // - the remote unit's current local size (including unattached buckets)
584  // - the number of the remote unit's unattached buckets and their size
585 
586  DASH_LOG_DEBUG_VAR("GlobHeapMem.shrink()", num_elements);
587  DASH_ASSERT_LT(num_elements, local_size() + 1,
588  "cannot shrink size " << local_size() << " "
589  "by " << num_elements << " elements");
590  if (num_elements == 0) {
591  DASH_LOG_DEBUG("GlobHeapMem.shrink >", "no shrink");
592  return;
593  }
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());
598  // Position of iterator to first unattached bucket:
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);
602  // Number of elements left to deallocate:
603  auto num_dealloc = num_elements;
604  // Try to reduce local capacity by deallocating un-attached local buckets
605  // as they do not have to be detached collectively.
606  // Unattached buckets can be removed from memory space immediately as
607  // remote units cannot have a pending reference on them.
608  while (!_buckets.back().attached && num_dealloc > 0) {
609  bucket_type & bucket_last = _buckets.back();
610  // Shrink / remove unattached buckets starting at newest bucket:
611  if (bucket_last.size <= num_dealloc) {
612  DASH_LOG_TRACE("GlobHeapMem.shrink", "remove unattached bucket:",
613  "size:", bucket_last.size);
614  // Mark entire bucket for deallocation below:
615  num_dealloc -= bucket_last.size;
616  _local_sizes.local[0] -= bucket_last.size;
617  _bucket_cumul_sizes[_myid].pop_back();
618  // End iterator of _buckets about to change, update iterator to first
619  // unattached bucket if it references the removed bucket:
620  auto it_last_bucket = _buckets.end();
621  std::advance(it_last_bucket, -1);
622  if (_attach_buckets_first == it_last_bucket) {
623  // Iterator to first unattached bucket references last bucket:
624  DASH_LOG_TRACE("GlobHeapMem.shrink",
625  "updating iterator to first unattached bucket");
626  std::advance(_attach_buckets_first, -1);
627  }
628  _allocator.deallocate_local(bucket_last.lptr, bucket_last.allocated_size);
629  _buckets.pop_back();
630  if (_attach_buckets_first->attached) {
631  // Updated iterator to first unattached bucket references attached
632  // bucket:
633  _attach_buckets_first = _buckets.end();
634  }
635  // Update number of local buckets marked for attach:
636  DASH_ASSERT_GT(_num_attach_buckets.local[0], 0,
637  "Last bucket unattached but number of buckets marked "
638  "for attach is 0");
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;
642 
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;
648  num_dealloc = 0;
649 
650  //Deallocate old local bucket
651  _allocator.deallocate_local(bucket_last.lptr, bucket_last.allocated_size);
652  //Allocate new bucket with specified size
653  bucket_last.lptr = _allocator.allocate_local(size_new);
654  if (bucket_last.lptr == nullptr) {
656  "GlobHeapMem.shrink: Allocating bucket of size failed");
657  }
658  bucket_last.size = size_new;
659  bucket_last.allocated_size = size_new;
660  }
661  }
662  // Number of elements to deallocate exceeds capacity of un-attached
663  // buckets, deallocate attached buckets:
664  auto num_dealloc_gbuckets = 0;
665  // Shrink attached buckets starting at newest bucket:
666  for (auto bucket_it = _buckets.rbegin();
667  bucket_it != _buckets.rend();
668  ++bucket_it) {
669  if (!bucket_it->attached) {
670  continue;
671  }
672  if (num_dealloc == 0) {
673  break;
674  }
675  if (bucket_it->size <= num_dealloc) {
676  // mark entire bucket for deallocation:
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;
689  num_dealloc = 0;
690  }
691  }
692  // Mark attached buckets for deallocation.
693  // Requires separate loop as iterators on _buckets could be invalidated.
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);
700  // Mark bucket to be detached in next call of commit():
701  _detach_buckets.push_back(dealloc_bucket);
702  // Unregister bucket:
703  _buckets.pop_back();
704  }
705  // Update local iterators as bucket iterators might have changed:
706  update_lbegin();
707  update_lend();
708 
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],
713  "new iteration space size:", std::distance(
714  _lbegin, _lend));
715  DASH_LOG_TRACE("GlobHeapMem.shrink",
716  "total number of buckets:", _buckets.size(),
717  "unattached buckets:", std::distance(
718  _attach_buckets_first,
719  _buckets.end()));
720  DASH_LOG_DEBUG("GlobHeapMem.shrink >");
721  }
constexpr size_type size() const noexcept
Number of array elements in local memory.
Definition: Array.h:209
RandomAccessIt::difference_type distance(const RandomAccessIt &first, const RandomAccessIt &last)
Resolve the number of elements between two iterators.
Definition: Iterator.h:90
constexpr size_type local_size() const noexcept
Number of elements in local memory space.
Definition: GlobHeapMem.h:430
local_type local
Local proxy object, allows use in range-based for loops.
Definition: Array.h:732

◆ size()

template<typename ElementType , class LocalMemorySpace = dash::HostSpace, global_allocation_policy AllocationPolicy = global_allocation_policy::epoch_synchronized, template< class > class LocalAlloc = allocator::DefaultAllocator>
constexpr size_type dash::GlobHeapMem< ElementType, LocalMemorySpace, AllocationPolicy, LocalAlloc >::size ( ) const
inlinenoexcept

Total number of elements in attached memory space, including size of local unattached memory segments.

Definition at line 422 of file GlobHeapMem.h.

References dash::GlobHeapMem< ElementType, LocalMemorySpace, AllocationPolicy, LocalAlloc >::local_size().

Referenced by dash::List< ElementType, LocalMemorySpace >::capacity(), dash::GlobHeapMem< ElementType, LocalMemorySpace, AllocationPolicy, LocalAlloc >::commit(), and dash::GlobHeapMem< ElementType, LocalMemorySpace, AllocationPolicy, LocalAlloc >::resize().

423  {
424  return _remote_size + local_size();
425  }
constexpr size_type local_size() const noexcept
Number of elements in local memory space.
Definition: GlobHeapMem.h:430

◆ team()

template<typename ElementType , class LocalMemorySpace = dash::HostSpace, global_allocation_policy AllocationPolicy = global_allocation_policy::epoch_synchronized, template< class > class LocalAlloc = allocator::DefaultAllocator>
constexpr dash::Team& dash::GlobHeapMem< ElementType, LocalMemorySpace, AllocationPolicy, LocalAlloc >::team ( ) const
inlinenoexcept

The team containing all units accessing the global memory space.

Returns
A reference to the Team containing the units associated with the global dynamic memory space.

Definition at line 465 of file GlobHeapMem.h.

References dash::Team::Null().

Referenced by dash::GlobHeapMem< ElementType, LocalMemorySpace, AllocationPolicy, LocalAlloc >::GlobHeapMem().

466  {
467  return (_team != nullptr) ? *_team : dash::Team::Null();
468  }
static Team & Null()
The invariant Team instance representing an undefined team.
Definition: Team.h:229

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