DASH  0.3.0
dash::allocator::GlobalAllocationPolicy< allocation_static, synchronization_single, memory_space_host_tag > Class Template Reference

LocalAllocationPolicy: Implements a mechanism to allocate locally, independent of the other units. More...

#include <AllocationPolicy.h>

Public Member Functions

dart_gptr_t allocate_segment (LocalMemorySpaceBase< memory_space_tag > *, std::size_t nbytes, std::size_t)
 Variant to allocate only locally in global memory space if we allocate in the default Host Space. More...
 
bool deallocate_segment (dart_gptr_t gptr, LocalMemorySpaceBase< memory_space_tag > *, void *, size_t, size_t)
 Similar to the allocation case above global memory is deallocated symmetrically in DART. More...
 

Detailed Description

template<>
class dash::allocator::GlobalAllocationPolicy< allocation_static, synchronization_single, memory_space_host_tag >

LocalAllocationPolicy: Implements a mechanism to allocate locally, independent of the other units.

This local memory portion is allocated from a memory pool which is already attached to global memory. This variant is a good fit in cases where only one units needs to allocate memory while the other units do not contribute any local portion. It is used for example used to implement dash::Shared.

Note: Both allocation and deallocation are non-collective. The user has to ensure that the owning unit does not release the memory while other units are still operating on it.

Definition at line 224 of file AllocationPolicy.h.

Member Function Documentation

◆ allocate_segment()

Variant to allocate only locally in global memory space if we allocate in the default Host Space.

In this case DART allocates from the internal buddy allocator.

Parameters
nbytesthe number of bytes to allocate

Definition at line 234 of file AllocationPolicy.h.

References DART_GPTR_NULL, dart_memalloc(), and DART_OK.

241  {
243 
244  if (nbytes > 0) {
245  dash::dart_storage<uint8_t> ds(nbytes);
246  auto const ret = dart_memalloc(ds.nelem, ds.dtype, &gptr);
247  if (ret != DART_OK) {
248  DASH_LOG_ERROR(
249  "LocalAllocationPolicy.do_global_allocate",
250  "cannot allocate local memory",
251  ret);
252  throw std::bad_alloc{};
253  }
254  DASH_LOG_DEBUG_VAR("LocalAllocator.allocate >", gptr);
255  }
256  return gptr;
257  }
Signals success.
Definition: dart_types.h:33
dart_ret_t dart_memalloc(size_t nelem, dart_datatype_t dtype, dart_gptr_t *gptr)
Allocates memory for nelem elements of type dtype in the global address space of the calling unit and...
#define DART_GPTR_NULL
A NULL global pointer.
Definition: dart_globmem.h:105
DART Global pointer type.
Definition: dart_globmem.h:77
Convencience wrapper to determine the DART type and number of elements required for the given templat...
Definition: Types.h:295

◆ deallocate_segment()

bool dash::allocator::GlobalAllocationPolicy< allocation_static, synchronization_single, memory_space_host_tag >::deallocate_segment ( dart_gptr_t  gptr,
LocalMemorySpaceBase< memory_space_tag > *  ,
void *  ,
size_t  ,
size_t   
)
inline

Similar to the allocation case above global memory is deallocated symmetrically in DART.

Definition at line 261 of file AllocationPolicy.h.

References dart_memfree(), and DART_OK.

267  {
268  auto const ret = dart_memfree(gptr) == DART_OK;
269  return ret;
270  }
Signals success.
Definition: dart_types.h:33
dart_ret_t dart_memfree(dart_gptr_t gptr)
Frees memory in the global address space allocated by a previous call of dart_memalloc.

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