OpenMP memory allocators can be used by a program to make allocation requests. When a memory allocator receives a request to allocate storage of a certain size, an allocation of logically consecutive memory in the resources of its associated memory space of at least the size that was requested will be returned if possible. This allocation will not overlap with any other existing allocation from an OpenMP memory allocator.
The behavior of the allocation process can be affected by the allocator traits that the user specifies. 6.2 shows the allowed allocator traits, their possible values and the default value of each trait.
tableAllocator Traits
Allocator trait | Allowed values | Default value |
sync_hint | contended, uncontended, serialized, private | contended |
alignment | Positive integer powers of 2 | 1 byte |
access | all, cgroup, pteam, thread | all |
pool_size | Any positive integer | Implementation defined |
fallback | default_mem_fb, null_fb, abort_fb, allocator_fb | default_mem_fb |
fb_data | an allocator handle | (none) |
pinned | true, false | false |
partition | environment, nearest, blocked, interleaved | environment |
The sync_hint trait describes the expected manner in which multiple threads may use the allocator. The values and their descriptions are:
Allocated memory will be byte aligned to at least the value specified for the alignment trait of the allocator. Some directives and API routines can specify additional requirements on alignment beyond those described in this section.
Memory allocated by allocators with the access trait defined to be all must be accessible by all threads in the device where the allocation was requested. Memory allocated by allocators with the access trait defined to be cgroup will be memory accessible by all threads in the same contention group as the thread that requested the allocation; attempts to access it by threads that are not part of the same contention group as the allocating thread result in unspecified behavior. Memory allocated by allocators with the access trait defined to be pteam will be memory accessible by all threads that bind to the same parallel region of the thread that requested the allocation; attempts to access it by threads that do not bind to the same parallel region as the allocating thread result in unspecified behavior. Memory allocated by allocators with the access trait defined to be thread will be memory accessible by the thread that requested the allocation; attempts to access it by threads other than the allocating thread result in unspecified behavior.
The total amount of storage in bytes that an allocator can use is limited by the pool_size trait. For allocators with the access trait defined to be all, this limit refers to allocations from all threads that access the allocator. For allocators with the access trait defined to be cgroup, this limit refers to allocations from threads that access the allocator from the same contention group. For allocators with the access trait defined to be pteam, this limit refers to allocations from threads that access the allocator from the same parallel team. For allocators with the access trait defined to be thread, this limit refers to allocations from each thread that accesses the allocator. Requests that would result in using more storage than pool_size will not be fulfilled by the allocator.
The fallback trait specifies how the allocator behaves when it cannot fulfill an allocation request. If the fallback trait is set to null_fb, the allocator returns the value zero if it fails to allocate the memory. If the fallback trait is set to abort_fb, the behavior is as if an error directive for which sev-level is fatal and action-time is execution is encountered if the allocation fails. If the fallback trait is set to allocator_fb then when an allocation fails the request will be delegated to the allocator specified in the fb_data trait. If the fallback trait is set to default_mem_fb then when an allocation fails another allocation will be tried in omp_default_mem_space, which assumes all allocator traits to be set to their default values except for fallback trait, which will be set to null_fb.
Allocators with the pinned trait defined to be true ensure that their allocations remain in the same storage resource at the same location for their entire lifetime.
The partition trait describes the partitioning of allocated memory over the storage resources represented by the memory space associated with the allocator. The partitioning will be done in parts with a minimum size that is implementation defined. The values are:
6.3 shows the list of predefined memory allocators and their associated memory spaces. The predefined memory allocators have default values for their allocator traits unless otherwise specified.
tablePredefined Allocators
Allocator name | Associated memory space | Non-default trait values |
omp_default_mem_alloc | omp_default_mem_space | fallback:null_fb |
omp_large_cap_mem_alloc | omp_large_cap_mem_space | (none) |
omp_const_mem_alloc | omp_const_mem_space | (none) |
omp_high_bw_mem_alloc | omp_high_bw_mem_space | (none) |
omp_low_lat_mem_alloc | omp_low_lat_mem_space | (none) |
omp_cgroup_mem_alloc | Implementation defined | access:cgroup |
omp_pteam_mem_alloc | Implementation defined | access:pteam |
omp_thread_mem_alloc | Implementation defined | access:thread |