Memory allocation (GNU libgomp) (original) (raw)


11.3 Memory allocation

The description below applies to:

GCC supports the following predefined allocators and predefined memory spaces:

Predefined allocators Associated predefined memory spaces
omp_default_mem_alloc omp_default_mem_space
omp_large_cap_mem_alloc omp_large_cap_mem_space
omp_const_mem_alloc omp_const_mem_space
omp_high_bw_mem_alloc omp_high_bw_mem_space
omp_low_lat_mem_alloc omp_low_lat_mem_space
omp_cgroup_mem_alloc omp_low_lat_mem_space (implementation defined)
omp_pteam_mem_alloc omp_low_lat_mem_space (implementation defined)
omp_thread_mem_alloc omp_low_lat_mem_space (implementation defined)
ompx_gnu_pinned_mem_alloc omp_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 theompx::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> vec;

The following allocator templates are supported:

Predefined allocators Associated allocator template
omp_null_allocator omp::allocator::null_allocator
omp_default_mem_alloc omp::allocator::default_mem
omp_large_cap_mem_alloc omp::allocator::large_cap_mem
omp_const_mem_alloc omp::allocator::const_mem
omp_high_bw_mem_alloc omp::allocator::high_bw_mem
omp_low_lat_mem_alloc omp::allocator::low_lat_mem
omp_cgroup_mem_alloc omp::allocator::cgroup_mem
omp_pteam_mem_alloc omp::allocator::pteam_mem
omp_thread_mem_alloc omp::allocator::thread_mem
ompx_gnu_pinned_mem_alloc ompx::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 theomp_cgroup_mem_alloc, omp_pteam_mem_alloc, andomp_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.

Trait Allowed values Default value
sync_hint contended, uncontended,serialized, private contended
alignment Positive integer being a power of two 1 byte
access all, cgroup,pteam, thread all
pool_size Positive integer (bytes) See below.
fallback default_mem_fb, null_fb,abort_fb, allocator_fb See below
fb_data allocator handle (none)
pinned true, false See below
partition environment, nearest,blocked, interleaved environment

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

For the pinned trait, the default value is true for predefined allocator ompx_gnu_pinned_mem_alloc (a GNU extension), andfalse 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