Memory allocation (GNU libgomp) (original) (raw)
11.3 Memory allocation ¶
The description below applies to:
- Explicit use of the OpenMP API routines, seeMemory Management Routines.
- The
allocateclause, except when theallocatormodifier is a constant expression with valueomp_default_mem_allocand noalignmodifier has been specified. (In that case, the normalmallocallocation is used.) - The
allocatedirective for variables in static memory; while the alignment is honored, the normal static memory is used. - Using the
allocatedirective for automatic/stack variables, except when theallocatorclause is a constant expression with valueomp_default_mem_allocand noalignclause has been specified. (In that case, the normal allocation is used: stack allocation and, sometimes for Fortran, alsomalloc[depending on flags such as-fstack-arrays].) - In Fortran, the
allocatorsdirective and the executableallocatedirective for Fortran pointers and allocatables is supported, but requires that files containing those directives has to be compiled with -fopenmp-allocators. Additionally, all files that might explicitly or implicitly deallocate memory allocated that way must also be compiled with that option. - The used alignment is the maximum of the value the
alignclause and the alignment of the type after honoring, if present, thealigned(GNU::aligned) attribute and C’s_Alignasand C++’salignas. However, thealignclause of theallocatedirective has no effect on the value of C’s_Alignofand C++’salignof.
For the available predefined allocators and, as applicable, their associated predefined memory spaces and for the available traits and their default values, see OMP_ALLOCATOR – Set the default allocator. Predefined allocators without an associated memory space use the omp_default_mem_space memory space. See additionallyOffload-Target Specifics.
For the memory spaces, the following applies:
omp_default_mem_spaceis supportedomp_const_mem_spacemaps toomp_default_mem_spaceomp_low_lat_mem_spaceis only available on supported devices, and maps toomp_default_mem_spaceotherwise.omp_large_cap_mem_spacemaps toomp_default_mem_space, unless the memkind library is availableomp_high_bw_mem_spacemaps toomp_default_mem_space, unless the memkind library is available
On Linux systems, where the memkind library (libmemkind.so.0) is available at runtime, it is used when creating memory allocators requesting
- the memory space
omp_high_bw_mem_space - the memory space
omp_large_cap_mem_space - the
partitiontraitinterleaved; note that foromp_large_cap_mem_spacethe allocation will not be interleaved
On Linux systems, where the numa library (libnuma.so.1) is available at runtime, it used when creating memory allocators requesting
- the
partitiontraitnearest, except when both the libmemkind library is available and the memory space is eitheromp_large_cap_mem_spaceoromp_high_bw_mem_space
Note that the numa library will round up the allocation size to a multiple of the system page size; therefore, consider using it only with large data or by sharing allocations via the pool_size trait. Furthermore, the Linux kernel does not guarantee that an allocation will always be on the nearest NUMA node nor that after reallocation the same node will be used. Note additionally that, on Linux, the default setting of the memory placement policy is to use the current node; therefore, unless the memory placement policy has been overridden, the partition trait environment (the default) will be effectively a nearest allocation.
Additional notes regarding the traits:
- The
pinnedtrait is supported on Linux hosts, but is subject to the OSulimit/rlimitlocked memory settings. - The default for the
pool_sizetrait is no pool and for every (re)allocation the associated library routine is called, which might internally use a memory pool. - For the
partitiontrait, the partition part size will be the same as the requested size (i.e.interleavedorblockedhas no effect), except forinterleavedwhen the memkind library is available. Furthermore, fornearestand unless the numa library is available, the memory might not be on the same NUMA node as thread that allocated the memory; on Linux, this is in particular the case when the memory placement policy is set to preferred. - The
accesstrait has no effect such that memory is always accessible by all threads. - The
sync_hinttrait has no effect.
See also:Offload-Target Specifics