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.
Table 2.9 shows the allowed allocator traits, their possible values and the default value of each
trait.
Table 2.9:
Allocator Traits
Allocator trait
Allowed values
Default value
sync_hint
contended, uncontended,
serialized, private
contended
alignment
A positive integer value that is a power of
2
1 byte
access
all, cgroup, pteam, thread
all
pool_size
Positive integer value
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:
contended:
high
contention
is
expected
on
the
allocator;
that
is,
many
threads
are
expected
to
request
allocations
simultaneously.
uncontended:
low
contention
is
expected
on
the
allocator;
that
is,
few
threads
are
expected
to
request
allocations
simultaneously.
serialized:
only
one
thread
at
a
time
will
request
allocations
with
the
allocator.
Requesting
two
allocations
simultaneously
when
specifying
serialized
results
in
unspecified
behavior.
private:
the
same
thread
will
request
allocations
with
the
allocator
every
time.
Requesting
an
allocation
from
different
threads,
simultaneously
or
not,
when
specifying
private
results
in
unspecified
behavior.
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 the memory returned by an
allocator with the access trait defined to be cgroup from a thread that is not part of the
same contention group as the thread that allocated the memory 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 the memory returned by an allocator with the access trait defined to
be pteam from a thread that does not bind to the same parallel region as the thread that
allocated the memory 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 the memory returned by an allocator with the access trait defined to
be thread from a thread other than the one that allocated the memory 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, program execution will be terminated 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:
environment:
the
placement
of
allocated
memory
is
determined
by
the
execution
environment;
nearest:
allocated
memory
is
placed
in
the
storage
resource
that
is
nearest
to
the
thread
that
requests
the
allocation;
blocked:
allocated
memory
is
partitioned
into
parts
of
approximately
the
same
size
with
at
most
one
part
per
storage
resource;
and
interleaved:
allocated
memory
parts
are
distributed
in
a
round-robin
fashion
across
the
storage
resources.
Table 2.10 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.
Table 2.10:
Predefined 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
If any operation of the base language causes a reallocation of a variable that is allocated with a memory
allocator then that memory allocator will be used to deallocate the current memory and to allocate the new
memory. For allocated allocatable components of such variables, the allocator that will be used for the
deallocation and allocation is unspecified.