11.3 Memory allocation

The description below applies to:

GCC supports the following predefined allocators and predefined memory spaces:

Predefined allocatorsAssociated predefined memory spaces
omp_default_mem_allocomp_default_mem_space
omp_large_cap_mem_allocomp_large_cap_mem_space
omp_const_mem_allocomp_const_mem_space
omp_high_bw_mem_allocomp_high_bw_mem_space
omp_low_lat_mem_allocomp_low_lat_mem_space
omp_cgroup_mem_allocomp_low_lat_mem_space (implementation defined)
omp_pteam_mem_allocomp_low_lat_mem_space (implementation defined)
omp_thread_mem_allocomp_low_lat_mem_space (implementation defined)
ompx_gnu_pinned_mem_allocomp_default_mem_space (GNU extension)

Each predefined allocator, including omp_null_allocator, has a corresponding allocator class template that meet the C++ allocator completeness requirements. These are located in the omp::allocator namespace, and the ompx::allocator namespace for gnu extensions. This allows the allocator-aware C++ standard library containers to use OpenMP allocation routines; for instance:

std::vector<int, omp::allocator::cgroup_mem<int>> vec;

The following allocator templates are supported:

Predefined allocatorsAssociated allocator template
omp_null_allocatoromp::allocator::null_allocator
omp_default_mem_allocomp::allocator::default_mem
omp_large_cap_mem_allocomp::allocator::large_cap_mem
omp_const_mem_allocomp::allocator::const_mem
omp_high_bw_mem_allocomp::allocator::high_bw_mem
omp_low_lat_mem_allocomp::allocator::low_lat_mem
omp_cgroup_mem_allocomp::allocator::cgroup_mem
omp_pteam_mem_allocomp::allocator::pteam_mem
omp_thread_mem_allocomp::allocator::thread_mem
ompx_gnu_pinned_mem_allocompx::allocator::gnu_pinned_mem

The following traits are available when constructing a new allocator; if a trait is not specified or with the value default, the specified default value is used for that trait. The predefined allocators use the default values of each trait, except that the omp_cgroup_mem_alloc, omp_pteam_mem_alloc, and omp_thread_mem_alloc allocators have the access trait set to cgroup, pteam, and thread, respectively. For each trait, a named constant prefixed by omp_atk_ exists; for each non-numeric value, a named constant prefixed by omp_atv_ exists.

TraitAllowed valuesDefault value
sync_hintcontended, uncontended, serialized, privatecontended
alignmentPositive integer being a power of two1 byte
accessall, cgroup, pteam, threadall
pool_sizePositive integer (bytes)See below.
fallbackdefault_mem_fb, null_fb, abort_fb, allocator_fbSee below
fb_dataallocator handle(none)
pinnedtrue, falseSee below
partitionenvironment, nearest, blocked, interleavedenvironment

For the fallback trait, the default value is null_fb for the omp_default_mem_alloc allocator and any allocator that is associated with device memory; for all other allocators, it is default_mem_fb by default.

For the pinned trait, the default value is true for predefined allocator ompx_gnu_pinned_mem_alloc (a GNU extension), and false for all others.

The following description applies to the initial device (the host) and largely also to non-host devices; for the latter, also see Offload-Target Specifics.

For the memory spaces, the following applies:

On Linux systems, where the memkind library (libmemkind.so.0) is available at runtime and the respective memkind kind is supported, it is used when creating memory allocators requesting

On Linux systems, where the numa library (libnuma.so.1) is available at runtime, it used when creating memory allocators requesting

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:

See also: Offload-Target Specifics