1 \input texinfo @c -*-texinfo-*-
4 @setfilename libgomp.info
10 Copyright @copyright{} 2006-2025 Free Software Foundation, Inc.
12 Permission is granted to copy, distribute and/or modify this document
13 under the terms of the GNU Free Documentation License, Version 1.3 or
14 any later version published by the Free Software Foundation; with the
15 Invariant Sections being ``Funding Free Software'', the Front-Cover
16 texts being (a) (see below), and with the Back-Cover Texts being (b)
17 (see below). A copy of the license is included in the section entitled
18 ``GNU Free Documentation License''.
20 (a) The FSF's Front-Cover Text is:
24 (b) The FSF's Back-Cover Text is:
26 You have freedom to copy and modify this GNU Manual, like GNU
27 software. Copies published by the Free Software Foundation raise
28 funds for GNU development.
32 @dircategory GNU Libraries
34 * libgomp: (libgomp). GNU Offloading and Multi Processing Runtime Library.
37 This manual documents libgomp, the GNU Offloading and Multi Processing
38 Runtime library. This is the GNU implementation of the OpenMP and
39 OpenACC APIs for parallel and accelerator programming in C/C++ and
42 Published by the Free Software Foundation
43 51 Franklin Street, Fifth Floor
44 Boston, MA 02110-1301 USA
50 @setchapternewpage odd
53 @title GNU Offloading and Multi Processing Runtime Library
54 @subtitle The GNU OpenMP and OpenACC Implementation
56 @vskip 0pt plus 1filll
57 @comment For the @value{version-GCC} Version*
59 Published by the Free Software Foundation @*
60 51 Franklin Street, Fifth Floor@*
61 Boston, MA 02110-1301, USA@*
71 @node Top, Enabling OpenMP
75 This manual documents the usage of libgomp, the GNU Offloading and
76 Multi Processing Runtime Library. This includes the GNU
77 implementation of the @uref{https://www.openmp.org, OpenMP} Application
78 Programming Interface (API) for multi-platform shared-memory parallel
79 programming in C/C++ and Fortran, and the GNU implementation of the
80 @uref{https://www.openacc.org, OpenACC} Application Programming
81 Interface (API) for offloading of code to accelerator devices in C/C++
84 Originally, libgomp implemented the GNU OpenMP Runtime Library. Based
85 on this, support for OpenACC and offloading (both OpenACC and OpenMP
86 4's target construct) has been added later on, and the library's name
87 changed to GNU Offloading and Multi Processing Runtime Library.
92 @comment When you add a new menu item, please keep the right hand
93 @comment aligned to the same column. Do not use tabs. This provides
94 @comment better formatting.
97 * Enabling OpenMP:: How to enable OpenMP for your applications.
98 * OpenMP Implementation Status:: List of implemented features by OpenMP version
99 * OpenMP Runtime Library Routines: Runtime Library Routines.
100 The OpenMP runtime application programming
102 * OpenMP Environment Variables: Environment Variables.
103 Influencing OpenMP runtime behavior with
104 environment variables.
105 * Enabling OpenACC:: How to enable OpenACC for your
107 * OpenACC Runtime Library Routines:: The OpenACC runtime application
108 programming interface.
109 * OpenACC Environment Variables:: Influencing OpenACC runtime behavior with
110 environment variables.
111 * CUDA Streams Usage:: Notes on the implementation of
112 asynchronous operations.
113 * OpenACC Library Interoperability:: OpenACC library interoperability with the
114 NVIDIA CUBLAS library.
115 * OpenACC Profiling Interface::
116 * OpenMP-Implementation Specifics:: Notes specifics of this OpenMP
118 * Offload-Target Specifics:: Notes on offload-target specific internals
119 * The libgomp ABI:: Notes on the external ABI presented by libgomp.
120 * Reporting Bugs:: How to report bugs in the GNU Offloading and
121 Multi Processing Runtime Library.
122 * Copying:: GNU general public license says
123 how you can copy and share libgomp.
124 * GNU Free Documentation License::
125 How you can copy and share this manual.
126 * Funding:: How to help assure continued work for free
128 * Library Index:: Index of this documentation.
132 @c ---------------------------------------------------------------------
134 @c ---------------------------------------------------------------------
136 @node Enabling OpenMP
137 @chapter Enabling OpenMP
139 To activate the OpenMP extensions for C/C++ and Fortran, the compile-time
140 flag @option{-fopenmp} must be specified. For C and C++, this enables
141 the handling of the OpenMP directives using @code{#pragma omp} and the
142 @code{[[omp::directive(...)]]}, @code{[[omp::sequence(...)]]} and
143 @code{[[omp::decl(...)]]} attributes. For Fortran, it enables for
144 free source form the @code{!$omp} sentinel for directives and the
145 @code{!$} conditional compilation sentinel and for fixed source form the
146 @code{c$omp}, @code{*$omp} and @code{!$omp} sentinels for directives and
147 the @code{c$}, @code{*$} and @code{!$} conditional compilation sentinels.
148 The flag also arranges for automatic linking of the OpenMP runtime library
149 (@ref{Runtime Library Routines}).
151 The @option{-fopenmp-simd} flag can be used to enable a subset of
152 OpenMP directives that do not require the linking of either the
153 OpenMP runtime library or the POSIX threads library.
155 A complete description of all OpenMP directives may be found in the
156 @uref{https://www.openmp.org, OpenMP Application Program Interface} manuals.
157 See also @ref{OpenMP Implementation Status}.
160 @c ---------------------------------------------------------------------
161 @c OpenMP Implementation Status
162 @c ---------------------------------------------------------------------
164 @node OpenMP Implementation Status
165 @chapter OpenMP Implementation Status
168 * OpenMP 4.5:: Feature completion status to 4.5 specification
169 * OpenMP 5.0:: Feature completion status to 5.0 specification
170 * OpenMP 5.1:: Feature completion status to 5.1 specification
171 * OpenMP 5.2:: Feature completion status to 5.2 specification
172 * OpenMP 6.0:: Feature completion status to 6.0 specification
175 The @code{_OPENMP} preprocessor macro and Fortran's @code{openmp_version}
176 parameter, provided by @code{omp_lib.h} and the @code{omp_lib} module, have
177 the value @code{201511} (i.e. OpenMP 4.5).
182 The OpenMP 4.5 specification is fully supported.
187 @unnumberedsubsec New features listed in Appendix B of the OpenMP specification
188 @c This list is sorted as in OpenMP 5.1's B.3 not as in OpenMP 5.0's B.2
190 @multitable @columnfractions .60 .10 .25
191 @headitem Description @tab Status @tab Comments
192 @item Array shaping @tab N @tab
193 @item Array sections with non-unit strides in C and C++ @tab N @tab
194 @item Iterators @tab Y @tab
195 @item @code{metadirective} directive @tab Y @tab
196 @item @code{declare variant} directive @tab Y @tab
197 @item @var{target-offload-var} ICV and @code{OMP_TARGET_OFFLOAD}
198 env variable @tab Y @tab
199 @item Nested-parallel changes to @var{max-active-levels-var} ICV @tab Y @tab
200 @item @code{requires} directive @tab Y
201 @tab See also @ref{Offload-Target Specifics}
202 @item @code{teams} construct outside an enclosing target region @tab Y @tab
203 @item Non-rectangular loop nests @tab P
204 @tab Full support for C/C++, partial for Fortran
205 (@uref{https://gcc.gnu.org/PR110735,PR110735})
206 @item @code{!=} as relational-op in canonical loop form for C/C++ @tab Y @tab
207 @item @code{nonmonotonic} as default loop schedule modifier for worksharing-loop
208 constructs @tab Y @tab
209 @item Collapse of associated loops that are imperfectly nested loops @tab Y @tab
210 @item Clauses @code{if}, @code{nontemporal} and @code{order(concurrent)} in
211 @code{simd} construct @tab Y @tab
212 @item @code{atomic} constructs in @code{simd} @tab Y @tab
213 @item @code{loop} construct @tab Y @tab
214 @item @code{order(concurrent)} clause @tab Y @tab
215 @item @code{scan} directive and @code{in_scan} modifier for the
216 @code{reduction} clause @tab Y @tab
217 @item @code{in_reduction} clause on @code{task} constructs @tab Y @tab
218 @item @code{in_reduction} clause on @code{target} constructs @tab P
219 @tab @code{nowait} only stub
220 @item @code{task_reduction} clause with @code{taskgroup} @tab Y @tab
221 @item @code{task} modifier to @code{reduction} clause @tab Y @tab
222 @item @code{affinity} clause to @code{task} construct @tab Y @tab Stub only
223 @item @code{detach} clause to @code{task} construct @tab Y @tab
224 @item @code{omp_fulfill_event} runtime routine @tab Y @tab
225 @item @code{reduction} and @code{in_reduction} clauses on @code{taskloop}
226 and @code{taskloop simd} constructs @tab Y @tab
227 @item @code{taskloop} construct cancelable by @code{cancel} construct
229 @item @code{mutexinoutset} @emph{dependence-type} for @code{depend} clause
231 @item Predefined memory spaces, memory allocators, allocator traits
232 @tab Y @tab See also @ref{Memory allocation}
233 @item Memory management routines @tab Y @tab
234 @item @code{allocate} directive @tab P
235 @tab C++ unsupported; see also @ref{Memory allocation}
236 @item @code{allocate} clause @tab P @tab Clause has no effect on @code{target}
237 (@uref{https://gcc.gnu.org/PR113436,PR113436})
238 @item @code{use_device_addr} clause on @code{target data} @tab Y @tab
239 @item @code{ancestor} modifier on @code{device} clause @tab Y @tab
240 @item Implicit declare target directive @tab Y @tab
241 @item Discontiguous array section with @code{target update} construct
243 @item C/C++'s lvalue expressions in @code{to}, @code{from}
244 and @code{map} clauses @tab Y @tab
245 @item C/C++'s lvalue expressions in @code{depend} clauses @tab Y @tab
246 @item Nested @code{declare target} directive @tab Y @tab
247 @item Combined @code{master} constructs @tab Y @tab
248 @item @code{depend} clause on @code{taskwait} @tab Y @tab
249 @item Weak memory ordering clauses on @code{atomic} and @code{flush} construct
251 @item @code{hint} clause on the @code{atomic} construct @tab Y @tab Stub only
252 @item @code{depobj} construct and depend objects @tab Y @tab
253 @item Lock hints were renamed to synchronization hints @tab Y @tab
254 @item @code{conditional} modifier to @code{lastprivate} clause @tab Y @tab
255 @item Map-order clarifications @tab P @tab
256 @item @code{close} @emph{map-type-modifier} @tab Y @tab
257 @item Mapping C/C++ pointer variables and to assign the address of
258 device memory mapped by an array section @tab P @tab
259 @item Mapping of Fortran pointer and allocatable variables, including pointer
260 and allocatable components of variables
262 @item @code{defaultmap} extensions @tab Y @tab
263 @item @code{declare mapper} directive @tab N @tab
264 @item @code{omp_get_supported_active_levels} routine @tab Y @tab
265 @item Runtime routines and environment variables to display runtime thread
266 affinity information @tab Y @tab
267 @item @code{omp_pause_resource} and @code{omp_pause_resource_all} runtime
269 @item @code{omp_get_device_num} runtime routine @tab Y @tab
270 @item OMPT interface @tab N @tab
271 @item OMPD interface @tab N @tab
274 @unnumberedsubsec Other new OpenMP 5.0 features
276 @multitable @columnfractions .60 .10 .25
277 @headitem Description @tab Status @tab Comments
278 @item Supporting C++'s range-based for loop @tab Y @tab
285 @unnumberedsubsec New features listed in Appendix B of the OpenMP specification
287 @multitable @columnfractions .60 .10 .25
288 @headitem Description @tab Status @tab Comments
289 @item OpenMP directive as C++ attribute specifiers @tab Y @tab
290 @item @code{omp_all_memory} reserved locator @tab Y @tab
291 @item @emph{target_device trait} in OpenMP Context @tab Y
292 @item @code{target_device} selector set in context selectors @tab Y @tab
293 @item C/C++'s @code{declare variant} directive: elision support of
294 preprocessed code @tab N @tab
295 @item @code{declare variant}: new clauses @code{adjust_args} and
296 @code{append_args} @tab Y @tab
297 @item @code{dispatch} construct @tab Y @tab
298 @item device-specific ICV settings with environment variables @tab Y @tab
299 @item @code{assume} and @code{assumes} directives @tab Y @tab
300 @item @code{nothing} directive @tab Y @tab
301 @item @code{error} directive @tab Y @tab
302 @item @code{masked} construct @tab Y @tab
303 @item @code{scope} directive @tab Y @tab
304 @item Loop transformation constructs @tab Y @tab
305 @item @code{strict} modifier in the @code{grainsize} and @code{num_tasks}
306 clauses of the @code{taskloop} construct @tab Y @tab
307 @item @code{align} clause in @code{allocate} directive @tab P
308 @tab Only C and Fortran
309 @item @code{align} modifier in @code{allocate} clause @tab Y @tab
310 @item @code{thread_limit} clause to @code{target} construct @tab Y @tab
311 @item @code{has_device_addr} clause to @code{target} construct @tab Y @tab
312 @item Iterators in @code{target update} motion clauses and @code{map}
314 @item Indirect calls to the device version of a procedure or function in
315 @code{target} regions @tab Y @tab
316 @item @code{interop} directive @tab Y @tab Cf. @ref{Offload-Target Specifics}
317 @item @code{omp_interop_t} object support in runtime routines @tab Y @tab
318 @item @code{nowait} clause in @code{taskwait} directive @tab Y @tab
319 @item Extensions to the @code{atomic} directive @tab Y @tab
320 @item @code{seq_cst} clause on a @code{flush} construct @tab Y @tab
321 @item @code{inoutset} argument to the @code{depend} clause @tab Y @tab
322 @item @code{private} and @code{firstprivate} argument to @code{default}
323 clause in C and C++ @tab Y @tab
324 @item @code{present} argument to @code{defaultmap} clause @tab Y @tab
325 @item @code{omp_set_num_teams}, @code{omp_set_teams_thread_limit},
326 @code{omp_get_max_teams}, @code{omp_get_teams_thread_limit} runtime
328 @item @code{omp_target_is_accessible} runtime routine @tab Y @tab
329 @item @code{omp_target_memcpy_async} and @code{omp_target_memcpy_rect_async}
330 runtime routines @tab Y @tab
331 @item @code{omp_get_mapped_ptr} runtime routine @tab Y @tab
332 @item @code{omp_calloc}, @code{omp_realloc}, @code{omp_aligned_alloc} and
333 @code{omp_aligned_calloc} runtime routines @tab Y @tab
334 @item @code{omp_alloctrait_key_t} enum: @code{omp_atv_serialized} added,
335 @code{omp_atv_default} changed @tab Y @tab
336 @item @code{omp_display_env} runtime routine @tab Y @tab
337 @item @code{ompt_scope_endpoint_t} enum: @code{ompt_scope_beginend} @tab N @tab
338 @item @code{ompt_sync_region_t} enum additions @tab N @tab
339 @item @code{ompt_state_t} enum: @code{ompt_state_wait_barrier_implementation}
340 and @code{ompt_state_wait_barrier_teams} @tab N @tab
341 @item @code{ompt_callback_target_data_op_emi_t},
342 @code{ompt_callback_target_emi_t}, @code{ompt_callback_target_map_emi_t}
343 and @code{ompt_callback_target_submit_emi_t} @tab N @tab
344 @item @code{ompt_callback_error_t} type @tab N @tab
345 @item @code{OMP_PLACES} syntax extensions @tab Y @tab
346 @item @code{OMP_NUM_TEAMS} and @code{OMP_TEAMS_THREAD_LIMIT} environment
347 variables @tab Y @tab
350 @unnumberedsubsec Other new OpenMP 5.1 features
352 @multitable @columnfractions .60 .10 .25
353 @headitem Description @tab Status @tab Comments
354 @item Support of strictly structured blocks in Fortran @tab Y @tab
355 @item Support of structured block sequences in C/C++ @tab Y @tab
356 @item @code{unconstrained} and @code{reproducible} modifiers on @code{order}
358 @item Support @code{begin/end declare target} syntax in C/C++ @tab Y @tab
359 @item Pointer predetermined firstprivate getting initialized
360 to address of matching mapped list item per 5.1, Sect. 2.21.7.2 @tab N @tab
361 @item For Fortran, diagnose placing declarative before/between @code{USE},
362 @code{IMPORT}, and @code{IMPLICIT} as invalid @tab N @tab
363 @item Optional comma between directive and clause in the @code{#pragma} form @tab Y @tab
364 @item @code{indirect} clause in @code{declare target} @tab Y @tab
365 @item @code{device_type(nohost)}/@code{device_type(host)} for variables @tab N @tab
366 @item @code{present} modifier to the @code{map}, @code{to} and @code{from}
368 @item Changed interaction between @code{declare target} and OpenMP context
370 @item Dynamic selector support in @code{metadirective} @tab Y @tab
371 @item Dynamic selector support in @code{declare variant} @tab P
372 @tab Fortran rejects non-constant expressions in dynamic selectors;
373 C/C++ reject expressions using argument variables.
374 (@uref{https://gcc.gnu.org/PR113904,PR113904})
381 @unnumberedsubsec New features listed in Appendix B of the OpenMP specification
383 @multitable @columnfractions .60 .10 .25
384 @headitem Description @tab Status @tab Comments
385 @item @code{omp_in_explicit_task} routine and @var{explicit-task-var} ICV
387 @item @code{omp}/@code{ompx}/@code{omx} sentinels and @code{omp_}/@code{ompx_}
389 @tab warning for @code{ompx/omx} sentinels@footnote{The @code{ompx}
390 sentinel as C/C++ pragma and C++ attributes are warned for with
391 @code{-Wunknown-pragmas} (implied by @code{-Wall}) and @code{-Wattributes}
392 (enabled by default), respectively; for Fortran free-source code, there is
393 a warning enabled by default and, for fixed-source code, the @code{omx}
394 sentinel is warned for with @code{-Wsurprising} (enabled by
395 @code{-Wall}). Unknown clauses are always rejected with an error.}
396 @item Clauses on @code{end} directive can be on directive @tab Y @tab
397 @item @code{destroy} clause with destroy-var argument on @code{depobj}
399 @item Deprecation of no-argument @code{destroy} clause on @code{depobj}
400 @tab N/A @tab undeprecated in OpenMP 6
401 @item @code{linear} clause syntax changes and @code{step} modifier @tab Y @tab
402 @item Deprecation of minus operator for reductions @tab N @tab
403 @item Deprecation of separating @code{map} modifiers without comma @tab N @tab
404 @item @code{declare mapper} with iterator and @code{present} modifiers
406 @item If a matching mapped list item is not found in the data environment, the
407 pointer retains its original value @tab Y @tab
408 @item New @code{enter} clause as alias for @code{to} on declare target directive
410 @item Deprecation of @code{to} clause on declare target directive @tab N @tab
411 @item Extended list of directives permitted in Fortran pure procedures
413 @item New @code{allocators} directive for Fortran @tab Y @tab
414 @item Deprecation of @code{allocate} directive for Fortran
415 allocatables/pointers @tab N @tab
416 @item Optional paired @code{end} directive with @code{dispatch} @tab Y @tab
417 @item New @code{memspace} and @code{traits} modifiers for @code{uses_allocators}
419 @item Deprecation of traits array following the allocator_handle expression in
420 @code{uses_allocators} @tab N @tab
421 @item New @code{otherwise} clause as alias for @code{default} on metadirectives
423 @item Deprecation of @code{default} clause on metadirectives @tab N
424 @tab Both @code{otherwise} and @code{default} are accepted
426 @item Deprecation of delimited form of @code{declare target} @tab N @tab
427 @item Reproducible semantics changed for @code{order(concurrent)} @tab N @tab
428 @item @code{allocate} and @code{firstprivate} clauses on @code{scope}
430 @item @code{ompt_callback_work} @tab N @tab
431 @item Default map-type for the @code{map} clause in @code{target enter/exit data}
433 @item New @code{doacross} clause as alias for @code{depend} with
434 @code{source}/@code{sink} modifier @tab Y @tab
435 @item Deprecation of @code{depend} with @code{source}/@code{sink} modifier
437 @item @code{omp_cur_iteration} keyword @tab Y @tab
440 @unnumberedsubsec Other new OpenMP 5.2 features
442 @multitable @columnfractions .60 .10 .25
443 @headitem Description @tab Status @tab Comments
444 @item For Fortran, optional comma between directive and clause @tab N @tab
445 @item Conforming device numbers and @code{omp_initial_device} and
446 @code{omp_invalid_device} enum/PARAMETER @tab Y @tab
447 @item Initial value of @var{default-device-var} ICV with
448 @code{OMP_TARGET_OFFLOAD=mandatory} @tab Y @tab
449 @item @code{all} as @emph{implicit-behavior} for @code{defaultmap} @tab Y @tab
450 @item @emph{interop_types} in any position of the modifier list for the @code{init} clause
451 of the @code{interop} construct @tab Y @tab
452 @item Invoke virtual member functions of C++ objects created on the host device
453 on other devices @tab N @tab
454 @item @code{mapper} as map-type modifier in @code{declare mapper} @tab N @tab
461 @unnumberedsubsec New features listed in Appendix B of the OpenMP specification
462 @multitable @columnfractions .60 .10 .25
463 @item Features deprecated in versions 5.0, 5.1 and 5.2 were removed
464 @tab N/A @tab Backward compatibility
465 @item Full support for C23 was added @tab P @tab
466 @item Full support for C++23 was added @tab P @tab
467 @item Full support for Fortran 2023 was added @tab P @tab
468 @item @code{_ALL} suffix to the device-scope environment variables
469 @tab P @tab Host device number wrongly accepted
470 @item @code{num_threads} clause now accepts a list @tab N @tab
471 @item Abstract names added for @code{OMP_NUM_THREADS},
472 @code{OMP_THREAD_LIMIT} and @code{OMP_TEAMS_THREAD_LIMIT}
474 @item Supporting increments with abstract names in @code{OMP_PLACES} @tab N @tab
475 @item Extension of @code{OMP_DEFAULT_DEVICE} and new
476 @code{OMP_AVAILABLE_DEVICES} environment vars @tab N @tab
477 @item New @code{uid} trait for target devices and for
478 @code{OMP_AVAILABLE_DEVICES} and @code{OMP_DEFAULT_DEVICE} @tab N @tab
479 @item New @code{OMP_THREADS_RESERVE} environment variable @tab N @tab
480 @item The @code{decl} attribute was added to the C++ attribute syntax
482 @item The OpenMP directive syntax was extended to include C23 attribute
483 specifiers @tab Y @tab
484 @item Support for pure directives in Fortran's @code{do concurrent} @tab N @tab
485 @item All inarguable clauses take now an optional Boolean argument @tab N @tab
486 @item The @code{adjust_args} clause was extended to specify the argument by position
487 and supports variadic arguments @tab N @tab
488 @item For Fortran, @emph{locator list} can be also function reference with
489 data pointer result @tab N @tab
490 @item Concept of @emph{assumed-size arrays} in C and C++
492 @item @emph{directive-name-modifier} accepted in all clauses @tab N @tab
493 @item Extension of @code{interop} operation of @code{append_args}, allowing
494 all modifiers of the @code{init} clause @tab Y @tab
495 @item New argument-free version of @code{depobj} with repeatable clauses and
496 the @code{init} clause @tab N @tab
497 @item Undeprecate omitting the argument to the @code{depend} clause of
498 the argument version of the @code{depend} construct @tab Y @tab
499 @item For Fortran, atomic with BLOCK construct and, for C/C++, with
500 unlimited curly braces supported @tab N @tab
501 @item For Fortran, atomic with pointer comparison @tab N @tab
502 @item For Fortran, atomic with enum and enumeration types @tab N @tab
503 @item For Fortran, atomic compare with storing the comparison result
505 @item Canonical loop sequences and new @code{looprange} clause @tab N @tab
506 @item For Fortran, handling polymorphic types in data-sharing-attribute
507 clauses @tab P @tab @code{private} not supported
508 @item For Fortran, rejecting polymorphic types in data-mapping clauses
509 @tab N @tab not diagnosed (and mostly unsupported)
510 @item New @code{taskgraph} construct including @code{saved} modifier and
511 @code{replayable} clause @tab N @tab
512 @item @code{default} clause on the @code{target} directive and accepting
513 variable categories @tab N @tab
514 @item Semantic change regarding the reference count update with
515 @code{use_device_ptr} and @code{use_device_addr} @tab N @tab
516 @item Support for inductions @tab N @tab
517 @item Reduction over private variables with @code{reduction} clause
519 @item Implicit reduction identifiers of C++ classes
521 @item New @code{init_complete} clause to the @code{scan} directive
523 @item @code{ref} modifier to the @code{map} clause @tab N @tab
524 @item New @code{storage} map-type modifier; context-dependent @code{alloc} and
525 @code{release} are aliases @tab N @tab
526 @item Change of the @emph{map-type} property from @emph{ultimate} to
527 @emph{default} @tab N @tab
528 @item @code{self} modifier to @code{map} and @code{self} as
529 @code{defaultmap} argument @tab N @tab
530 @item Mapping of @emph{assumed-size arrays} in C, C++ and Fortran
532 @item @code{delete} as delete-modifier not as map type @tab N @tab
533 @item For Fortran, the @code{automap} modifier to the @code{enter} clause
534 of @code{declare_target} @tab N @tab
535 @item @code{groupprivate} directive @tab N @tab
536 @item @code{local} clause to @code{declare_target} directive @tab N @tab
537 @item @code{part_size} allocator trait for @code{interleaved} allocator
538 partitions @tab N @tab
539 @item @code{pin_device}, @code{preferred_device} and @code{target_access}
542 @item @code{access} allocator trait changes @tab N @tab
543 @item New @code{partitioner} value to @code{partition} allocator trait
545 @item Semicolon-separated list to @code{uses_allocators} @tab N @tab
546 @item New @code{need_device_addr} modifier to @code{adjust_args} clause @tab N @tab
547 @item @code{interop} clause to @code{dispatch} @tab Y @tab
548 @item Scope requirement changes for @code{declare_target} @tab N @tab
549 @item @code{message} and @code{severity} clauses to @code{parallel} directive
551 @item @code{self_maps} clause to @code{requires} directive @tab Y @tab
552 @item @code{no_openmp_constructs} assumptions clause @tab N @tab
553 @item Restriction for @code{ordered} regarding loop-transforming directives
555 @item @code{apply} clause to loop-transforming constructs @tab N @tab
556 @item Non-constant values in the @code{sizes} clause @tab N @tab
557 @item @code{fuse} loop-transformation construct @tab N @tab
558 @item @code{interchange} loop-transformation construct @tab N @tab
559 @item @code{reverse} loop-transformation construct @tab N @tab
560 @item @code{split} loop-transformation construct @tab N @tab
561 @item @code{stripe} loop-transformation construct @tab N @tab
562 @item @code{tile} permitting association of grid and inter-tile loops @tab N @tab
563 @item @code{strict} modifier keyword to @code{num_threads} @tab N @tab
564 @item @code{safesync} clause to the @code{parallel} construct @tab N @tab
565 @item @code{omp_curr_progress_width} identifier @tab N @tab
566 @item @code{omp_get_max_progress_width} runtime routine @tab N @tab
567 @item Lifted restrictions on @code{order(concurrent)} and, hence, the
568 @code{loop} construct @tab N @tab
569 @item @code{atomic} permitted in a construct with @code{order(concurrent)}
571 @item Lifted restrictions on not-strictly-nested regions with
572 @code{order(concurrent)} @tab N @tab
573 @item @code{workdistribute} directive for Fortran @tab N @tab
574 @item Fortran @code{DO CONCURRENT} as associated loop in a @code{loop} construct
576 @item New @code{task_iteration} directive inside @code{taskloop} @tab N @tab
577 @item @code{threadset} clause in task-generating constructs @tab N @tab
578 @item New @code{priority} clause to @code{target}, @code{target_enter_data},
579 @code{target_data}, @code{target_exit_data} and @code{target_update}
581 @item New @code{device_type} clause to the @code{target} directive
583 @item @code{target_data} as composite construct @tab N @tab
584 @item @code{nowait} clause with reverse-offload @code{target} directives
586 @item Extended @emph{prefer-type} modifier to @code{init} clause @tab Y @tab
587 @item Boolean argument to @code{nowait} and @code{nogroup} may be non constant
589 @item @code{memscope} clause to @code{atomic} and @code{flush} @tab N @tab
590 @item New @code{transparent} clause for multi-generational task-dependence graphs
592 @item The @code{cancel} construct now completes tasks with unfulfilled events
594 @item @code{omp_fulfill_event} routine was restricted regarding fulfillment of
595 event variables @tab N @tab
596 @item Added rule for compound-directive names, permitting many more combinations
598 @item @code{omp_is_free_agent} and @code{omp_ancestor_is_free_agent} routines
600 @item @code{omp_get_device_from_uid} and @code{omp_get_uid_from_device} routines
602 @item @code{omp_get_device_num_teams}, @code{omp_set_device_num_teams},
603 @code{omp_get_device_teams_thread_limit}, and
604 @code{omp_set_device_teams_thread_limit} routines @tab N @tab
605 @item @code{omp_target_memset} and @code{omp_target_memset_async} routines
607 @item Fortran version of the interop runtime routines @tab Y @tab
608 @item Routines for obtaining memory spaces/allocators for shared/device memory
610 @item @code{omp_get_memspace_num_resources} routine @tab N @tab
611 @item @code{omp_get_memspace_pagesize} routine @tab N @tab
612 @item @code{omp_get_submemspace} routine @tab N @tab
613 @item @code{omp_init_mempartitioner}, @code{omp_destroy_mempartitioner},
614 @code{omp_init_mempartition}, @code{omp_destroy_mempartition},
615 @code{omp_mempartition_set_part}, @code{omp_mempartition_get_user_data}
617 @item Deprecation of the @code{target_data_op}, @code{target},
618 @code{target_map} and @code{target_submit} callbacks and as values that
619 @code{set_callback} must return @tab N @tab
620 @item @code{ompt_target_data_transfer} and @code{ompt_target_data_transfer_async}
621 values in @code{ompt_target_data_op_t} enum @tab N @tab
622 @item The values @code{ompt_target_data_transfer_to_device},
623 @code{ompt_target_data_transfer_from_device},
624 @code{ompt_target_data_transfer_to_device_async} and
625 @code{ompt_target_data_transfer_from_device_async} of the @code{target_data_op}
626 OMPT type were deprecated @tab N @tab
627 @item @code{ompt_get_buffer_limits} OMPT routine @tab N @tab
630 @unnumberedsubsec Deprecated features, unless listed above
631 @multitable @columnfractions .60 .10 .25
632 @item Deprecation of omitting the optional white space to separate adjacent
633 keywords in the directive-name in Fortran (fixed and free source form)
635 @item Deprecation of the combiner expression in the @code{declare_reduction}
637 @item Deprecation of the Fortran include file @code{omp_lib.h}
641 @unnumberedsubsec Other new OpenMP 6.0 features
642 @multitable @columnfractions .60 .10 .25
643 @item Multi-word directives now use underscore by default @tab N @tab
644 @item Relaxed Fortran restrictions to the @code{aligned} clause @tab N @tab
645 @item Mapping lambda captures @tab N @tab
646 @item New @code{omp_pause_stop_tool} constant for omp_pause_resource @tab N @tab
647 @item In Fortran (fixed and free source form), spaces between directive names are mandatory
649 @item Update of the map-type decay for mapping and @code{declare_mapper}
655 @c ---------------------------------------------------------------------
656 @c OpenMP Runtime Library Routines
657 @c ---------------------------------------------------------------------
659 @node Runtime Library Routines
660 @chapter OpenMP Runtime Library Routines
662 The runtime routines described here are defined by Section 18 of the OpenMP
663 specification in version 5.2.
666 * Thread Team Routines::
667 * Thread Affinity Routines::
668 * Teams Region Routines::
670 * Resource Relinquishing Routines::
671 * Device Information Routines::
672 * Device Memory Routines::
676 * Interoperability Routines::
677 * Memory Management Routines::
678 @c * Tool Control Routine::
679 * Environment Display Routine::
684 @node Thread Team Routines
685 @section Thread Team Routines
687 Routines controlling threads in the current contention group.
688 They have C linkage and do not throw exceptions.
691 * omp_set_num_threads:: Set upper team size limit
692 * omp_get_num_threads:: Size of the active team
693 * omp_get_max_threads:: Maximum number of threads of parallel region
694 * omp_get_thread_num:: Current thread ID
695 * omp_in_parallel:: Whether a parallel region is active
696 * omp_set_dynamic:: Enable/disable dynamic teams
697 * omp_get_dynamic:: Dynamic teams setting
698 * omp_get_cancellation:: Whether cancellation support is enabled
699 * omp_set_nested:: Enable/disable nested parallel regions
700 * omp_get_nested:: Nested parallel regions
701 * omp_set_schedule:: Set the runtime scheduling method
702 * omp_get_schedule:: Obtain the runtime scheduling method
703 * omp_get_teams_thread_limit:: Maximum number of threads imposed by teams
704 * omp_get_supported_active_levels:: Maximum number of active regions supported
705 * omp_set_max_active_levels:: Limits the number of active parallel regions
706 * omp_get_max_active_levels:: Current maximum number of active regions
707 * omp_get_level:: Number of parallel regions
708 * omp_get_ancestor_thread_num:: Ancestor thread ID
709 * omp_get_team_size:: Number of threads in a team
710 * omp_get_active_level:: Number of active parallel regions
715 @node omp_set_num_threads
716 @subsection @code{omp_set_num_threads} -- Set upper team size limit
718 @item @emph{Description}:
719 Specifies the number of threads used by default in subsequent parallel
720 sections, if those do not specify a @code{num_threads} clause. The
721 argument of @code{omp_set_num_threads} shall be a positive integer.
724 @multitable @columnfractions .20 .80
725 @item @emph{Prototype}: @tab @code{void omp_set_num_threads(int num_threads);}
728 @item @emph{Fortran}:
729 @multitable @columnfractions .20 .80
730 @item @emph{Interface}: @tab @code{subroutine omp_set_num_threads(num_threads)}
731 @item @tab @code{integer, intent(in) :: num_threads}
734 @item @emph{See also}:
735 @ref{OMP_NUM_THREADS}, @ref{omp_get_num_threads}, @ref{omp_get_max_threads}
737 @item @emph{Reference}:
738 @uref{https://www.openmp.org, OpenMP specification v4.5}, Section 3.2.1.
743 @node omp_get_num_threads
744 @subsection @code{omp_get_num_threads} -- Size of the active team
746 @item @emph{Description}:
747 Returns the number of threads in the current team. In a sequential section of
748 the program @code{omp_get_num_threads} returns 1.
750 The default team size may be initialized at startup by the
751 @env{OMP_NUM_THREADS} environment variable. At runtime, the size
752 of the current team may be set either by the @code{NUM_THREADS}
753 clause or by @code{omp_set_num_threads}. If none of the above were
754 used to define a specific value and @env{OMP_DYNAMIC} is disabled,
755 one thread per CPU online is used.
758 @multitable @columnfractions .20 .80
759 @item @emph{Prototype}: @tab @code{int omp_get_num_threads(void);}
762 @item @emph{Fortran}:
763 @multitable @columnfractions .20 .80
764 @item @emph{Interface}: @tab @code{integer function omp_get_num_threads()}
767 @item @emph{See also}:
768 @ref{omp_get_max_threads}, @ref{omp_set_num_threads}, @ref{OMP_NUM_THREADS}
770 @item @emph{Reference}:
771 @uref{https://www.openmp.org, OpenMP specification v4.5}, Section 3.2.2.
776 @node omp_get_max_threads
777 @subsection @code{omp_get_max_threads} -- Maximum number of threads of parallel region
779 @item @emph{Description}:
780 Return the maximum number of threads used for the current parallel region
781 that does not use the clause @code{num_threads}.
784 @multitable @columnfractions .20 .80
785 @item @emph{Prototype}: @tab @code{int omp_get_max_threads(void);}
788 @item @emph{Fortran}:
789 @multitable @columnfractions .20 .80
790 @item @emph{Interface}: @tab @code{integer function omp_get_max_threads()}
793 @item @emph{See also}:
794 @ref{omp_set_num_threads}, @ref{omp_set_dynamic}, @ref{omp_get_thread_limit}
796 @item @emph{Reference}:
797 @uref{https://www.openmp.org, OpenMP specification v4.5}, Section 3.2.3.
802 @node omp_get_thread_num
803 @subsection @code{omp_get_thread_num} -- Current thread ID
805 @item @emph{Description}:
806 Returns a unique thread identification number within the current team.
807 In a sequential parts of the program, @code{omp_get_thread_num}
808 always returns 0. In parallel regions the return value varies
809 from 0 to @code{omp_get_num_threads}-1 inclusive. The return
810 value of the primary thread of a team is always 0.
813 @multitable @columnfractions .20 .80
814 @item @emph{Prototype}: @tab @code{int omp_get_thread_num(void);}
817 @item @emph{Fortran}:
818 @multitable @columnfractions .20 .80
819 @item @emph{Interface}: @tab @code{integer function omp_get_thread_num()}
822 @item @emph{See also}:
823 @ref{omp_get_num_threads}, @ref{omp_get_ancestor_thread_num}
825 @item @emph{Reference}:
826 @uref{https://www.openmp.org, OpenMP specification v4.5}, Section 3.2.4.
831 @node omp_in_parallel
832 @subsection @code{omp_in_parallel} -- Whether a parallel region is active
834 @item @emph{Description}:
835 This function returns @code{true} if currently running in parallel,
836 @code{false} otherwise. Here, @code{true} and @code{false} represent
837 their language-specific counterparts.
840 @multitable @columnfractions .20 .80
841 @item @emph{Prototype}: @tab @code{int omp_in_parallel(void);}
844 @item @emph{Fortran}:
845 @multitable @columnfractions .20 .80
846 @item @emph{Interface}: @tab @code{logical function omp_in_parallel()}
849 @item @emph{Reference}:
850 @uref{https://www.openmp.org, OpenMP specification v4.5}, Section 3.2.6.
854 @node omp_set_dynamic
855 @subsection @code{omp_set_dynamic} -- Enable/disable dynamic teams
857 @item @emph{Description}:
858 Enable or disable the dynamic adjustment of the number of threads
859 within a team. The function takes the language-specific equivalent
860 of @code{true} and @code{false}, where @code{true} enables dynamic
861 adjustment of team sizes and @code{false} disables it.
864 @multitable @columnfractions .20 .80
865 @item @emph{Prototype}: @tab @code{void omp_set_dynamic(int dynamic_threads);}
868 @item @emph{Fortran}:
869 @multitable @columnfractions .20 .80
870 @item @emph{Interface}: @tab @code{subroutine omp_set_dynamic(dynamic_threads)}
871 @item @tab @code{logical, intent(in) :: dynamic_threads}
874 @item @emph{See also}:
875 @ref{OMP_DYNAMIC}, @ref{omp_get_dynamic}
877 @item @emph{Reference}:
878 @uref{https://www.openmp.org, OpenMP specification v4.5}, Section 3.2.7.
883 @node omp_get_dynamic
884 @subsection @code{omp_get_dynamic} -- Dynamic teams setting
886 @item @emph{Description}:
887 This function returns @code{true} if enabled, @code{false} otherwise.
888 Here, @code{true} and @code{false} represent their language-specific
891 The dynamic team setting may be initialized at startup by the
892 @env{OMP_DYNAMIC} environment variable or at runtime using
893 @code{omp_set_dynamic}. If undefined, dynamic adjustment is
897 @multitable @columnfractions .20 .80
898 @item @emph{Prototype}: @tab @code{int omp_get_dynamic(void);}
901 @item @emph{Fortran}:
902 @multitable @columnfractions .20 .80
903 @item @emph{Interface}: @tab @code{logical function omp_get_dynamic()}
906 @item @emph{See also}:
907 @ref{omp_set_dynamic}, @ref{OMP_DYNAMIC}
909 @item @emph{Reference}:
910 @uref{https://www.openmp.org, OpenMP specification v4.5}, Section 3.2.8.
915 @node omp_get_cancellation
916 @subsection @code{omp_get_cancellation} -- Whether cancellation support is enabled
918 @item @emph{Description}:
919 This function returns @code{true} if cancellation is activated, @code{false}
920 otherwise. Here, @code{true} and @code{false} represent their language-specific
921 counterparts. Unless @env{OMP_CANCELLATION} is set true, cancellations are
925 @multitable @columnfractions .20 .80
926 @item @emph{Prototype}: @tab @code{int omp_get_cancellation(void);}
929 @item @emph{Fortran}:
930 @multitable @columnfractions .20 .80
931 @item @emph{Interface}: @tab @code{logical function omp_get_cancellation()}
934 @item @emph{See also}:
935 @ref{OMP_CANCELLATION}
937 @item @emph{Reference}:
938 @uref{https://www.openmp.org, OpenMP specification v4.5}, Section 3.2.9.
944 @subsection @code{omp_set_nested} -- Enable/disable nested parallel regions
946 @item @emph{Description}:
947 Enable or disable nested parallel regions, i.e., whether team members
948 are allowed to create new teams. The function takes the language-specific
949 equivalent of @code{true} and @code{false}, where @code{true} enables
950 dynamic adjustment of team sizes and @code{false} disables it.
952 Enabling nested parallel regions also sets the maximum number of
953 active nested regions to the maximum supported. Disabling nested parallel
954 regions sets the maximum number of active nested regions to one.
956 Note that the @code{omp_set_nested} API routine was deprecated
957 in the OpenMP specification 5.0 in favor of @code{omp_set_max_active_levels}.
960 @multitable @columnfractions .20 .80
961 @item @emph{Prototype}: @tab @code{void omp_set_nested(int nested);}
964 @item @emph{Fortran}:
965 @multitable @columnfractions .20 .80
966 @item @emph{Interface}: @tab @code{subroutine omp_set_nested(nested)}
967 @item @tab @code{logical, intent(in) :: nested}
970 @item @emph{See also}:
971 @ref{omp_get_nested}, @ref{omp_set_max_active_levels},
972 @ref{OMP_MAX_ACTIVE_LEVELS}, @ref{OMP_NESTED}
974 @item @emph{Reference}:
975 @uref{https://www.openmp.org, OpenMP specification v4.5}, Section 3.2.10.
981 @subsection @code{omp_get_nested} -- Nested parallel regions
983 @item @emph{Description}:
984 This function returns @code{true} if nested parallel regions are
985 enabled, @code{false} otherwise. Here, @code{true} and @code{false}
986 represent their language-specific counterparts.
988 The state of nested parallel regions at startup depends on several
989 environment variables. If @env{OMP_MAX_ACTIVE_LEVELS} is defined
990 and is set to greater than one, then nested parallel regions will be
991 enabled. If not defined, then the value of the @env{OMP_NESTED}
992 environment variable will be followed if defined. If neither are
993 defined, then if either @env{OMP_NUM_THREADS} or @env{OMP_PROC_BIND}
994 are defined with a list of more than one value, then nested parallel
995 regions are enabled. If none of these are defined, then nested parallel
996 regions are disabled by default.
998 Nested parallel regions can be enabled or disabled at runtime using
999 @code{omp_set_nested}, or by setting the maximum number of nested
1000 regions with @code{omp_set_max_active_levels} to one to disable, or
1001 above one to enable.
1003 Note that the @code{omp_get_nested} API routine was deprecated
1004 in the OpenMP specification 5.0 in favor of @code{omp_get_max_active_levels}.
1007 @multitable @columnfractions .20 .80
1008 @item @emph{Prototype}: @tab @code{int omp_get_nested(void);}
1011 @item @emph{Fortran}:
1012 @multitable @columnfractions .20 .80
1013 @item @emph{Interface}: @tab @code{logical function omp_get_nested()}
1016 @item @emph{See also}:
1017 @ref{omp_get_max_active_levels}, @ref{omp_set_nested},
1018 @ref{OMP_MAX_ACTIVE_LEVELS}, @ref{OMP_NESTED}
1020 @item @emph{Reference}:
1021 @uref{https://www.openmp.org, OpenMP specification v4.5}, Section 3.2.11.
1026 @node omp_set_schedule
1027 @subsection @code{omp_set_schedule} -- Set the runtime scheduling method
1029 @item @emph{Description}:
1030 Sets the runtime scheduling method. The @var{kind} argument can have the
1031 value @code{omp_sched_static}, @code{omp_sched_dynamic},
1032 @code{omp_sched_guided} or @code{omp_sched_auto}. Except for
1033 @code{omp_sched_auto}, the chunk size is set to the value of
1034 @var{chunk_size} if positive, or to the default value if zero or negative.
1035 For @code{omp_sched_auto} the @var{chunk_size} argument is ignored.
1038 @multitable @columnfractions .20 .80
1039 @item @emph{Prototype}: @tab @code{void omp_set_schedule(omp_sched_t kind, int chunk_size);}
1042 @item @emph{Fortran}:
1043 @multitable @columnfractions .20 .80
1044 @item @emph{Interface}: @tab @code{subroutine omp_set_schedule(kind, chunk_size)}
1045 @item @tab @code{integer(kind=omp_sched_kind) kind}
1046 @item @tab @code{integer chunk_size}
1049 @item @emph{See also}:
1050 @ref{omp_get_schedule}
1053 @item @emph{Reference}:
1054 @uref{https://www.openmp.org, OpenMP specification v4.5}, Section 3.2.12.
1059 @node omp_get_schedule
1060 @subsection @code{omp_get_schedule} -- Obtain the runtime scheduling method
1062 @item @emph{Description}:
1063 Obtain the runtime scheduling method. The @var{kind} argument is set to
1064 @code{omp_sched_static}, @code{omp_sched_dynamic},
1065 @code{omp_sched_guided} or @code{omp_sched_auto}. The second argument,
1066 @var{chunk_size}, is set to the chunk size.
1069 @multitable @columnfractions .20 .80
1070 @item @emph{Prototype}: @tab @code{void omp_get_schedule(omp_sched_t *kind, int *chunk_size);}
1073 @item @emph{Fortran}:
1074 @multitable @columnfractions .20 .80
1075 @item @emph{Interface}: @tab @code{subroutine omp_get_schedule(kind, chunk_size)}
1076 @item @tab @code{integer(kind=omp_sched_kind) kind}
1077 @item @tab @code{integer chunk_size}
1080 @item @emph{See also}:
1081 @ref{omp_set_schedule}, @ref{OMP_SCHEDULE}
1083 @item @emph{Reference}:
1084 @uref{https://www.openmp.org, OpenMP specification v4.5}, Section 3.2.13.
1088 @node omp_get_teams_thread_limit
1089 @subsection @code{omp_get_teams_thread_limit} -- Maximum number of threads imposed by teams
1091 @item @emph{Description}:
1092 Return the maximum number of threads that are able to participate in
1093 each team created by a teams construct.
1096 @multitable @columnfractions .20 .80
1097 @item @emph{Prototype}: @tab @code{int omp_get_teams_thread_limit(void);}
1100 @item @emph{Fortran}:
1101 @multitable @columnfractions .20 .80
1102 @item @emph{Interface}: @tab @code{integer function omp_get_teams_thread_limit()}
1105 @item @emph{See also}:
1106 @ref{omp_set_teams_thread_limit}, @ref{OMP_TEAMS_THREAD_LIMIT}
1108 @item @emph{Reference}:
1109 @uref{https://www.openmp.org, OpenMP specification v5.1}, Section 3.4.6.
1114 @node omp_get_supported_active_levels
1115 @subsection @code{omp_get_supported_active_levels} -- Maximum number of active regions supported
1117 @item @emph{Description}:
1118 This function returns the maximum number of nested, active parallel regions
1119 supported by this implementation.
1122 @multitable @columnfractions .20 .80
1123 @item @emph{Prototype}: @tab @code{int omp_get_supported_active_levels(void);}
1126 @item @emph{Fortran}:
1127 @multitable @columnfractions .20 .80
1128 @item @emph{Interface}: @tab @code{integer function omp_get_supported_active_levels()}
1131 @item @emph{See also}:
1132 @ref{omp_get_max_active_levels}, @ref{omp_set_max_active_levels}
1134 @item @emph{Reference}:
1135 @uref{https://www.openmp.org, OpenMP specification v5.0}, Section 3.2.15.
1140 @node omp_set_max_active_levels
1141 @subsection @code{omp_set_max_active_levels} -- Limits the number of active parallel regions
1143 @item @emph{Description}:
1144 This function limits the maximum allowed number of nested, active
1145 parallel regions. @var{max_levels} must be less or equal to
1146 the value returned by @code{omp_get_supported_active_levels}.
1149 @multitable @columnfractions .20 .80
1150 @item @emph{Prototype}: @tab @code{void omp_set_max_active_levels(int max_levels);}
1153 @item @emph{Fortran}:
1154 @multitable @columnfractions .20 .80
1155 @item @emph{Interface}: @tab @code{subroutine omp_set_max_active_levels(max_levels)}
1156 @item @tab @code{integer max_levels}
1159 @item @emph{See also}:
1160 @ref{omp_get_max_active_levels}, @ref{omp_get_active_level},
1161 @ref{omp_get_supported_active_levels}
1163 @item @emph{Reference}:
1164 @uref{https://www.openmp.org, OpenMP specification v4.5}, Section 3.2.15.
1169 @node omp_get_max_active_levels
1170 @subsection @code{omp_get_max_active_levels} -- Current maximum number of active regions
1172 @item @emph{Description}:
1173 This function obtains the maximum allowed number of nested, active parallel regions.
1176 @multitable @columnfractions .20 .80
1177 @item @emph{Prototype}: @tab @code{int omp_get_max_active_levels(void);}
1180 @item @emph{Fortran}:
1181 @multitable @columnfractions .20 .80
1182 @item @emph{Interface}: @tab @code{integer function omp_get_max_active_levels()}
1185 @item @emph{See also}:
1186 @ref{omp_set_max_active_levels}, @ref{omp_get_active_level}
1188 @item @emph{Reference}:
1189 @uref{https://www.openmp.org, OpenMP specification v4.5}, Section 3.2.16.
1194 @subsection @code{omp_get_level} -- Obtain the current nesting level
1196 @item @emph{Description}:
1197 This function returns the nesting level for the parallel blocks,
1198 which enclose the calling call.
1201 @multitable @columnfractions .20 .80
1202 @item @emph{Prototype}: @tab @code{int omp_get_level(void);}
1205 @item @emph{Fortran}:
1206 @multitable @columnfractions .20 .80
1207 @item @emph{Interface}: @tab @code{integer function omp_level()}
1210 @item @emph{See also}:
1211 @ref{omp_get_active_level}
1213 @item @emph{Reference}:
1214 @uref{https://www.openmp.org, OpenMP specification v4.5}, Section 3.2.17.
1219 @node omp_get_ancestor_thread_num
1220 @subsection @code{omp_get_ancestor_thread_num} -- Ancestor thread ID
1222 @item @emph{Description}:
1223 This function returns the thread identification number for the given
1224 nesting level of the current thread. For values of @var{level} outside
1225 zero to @code{omp_get_level} -1 is returned; if @var{level} is
1226 @code{omp_get_level} the result is identical to @code{omp_get_thread_num}.
1229 @multitable @columnfractions .20 .80
1230 @item @emph{Prototype}: @tab @code{int omp_get_ancestor_thread_num(int level);}
1233 @item @emph{Fortran}:
1234 @multitable @columnfractions .20 .80
1235 @item @emph{Interface}: @tab @code{integer function omp_get_ancestor_thread_num(level)}
1236 @item @tab @code{integer level}
1239 @item @emph{See also}:
1240 @ref{omp_get_level}, @ref{omp_get_thread_num}, @ref{omp_get_team_size}
1242 @item @emph{Reference}:
1243 @uref{https://www.openmp.org, OpenMP specification v4.5}, Section 3.2.18.
1248 @node omp_get_team_size
1249 @subsection @code{omp_get_team_size} -- Number of threads in a team
1251 @item @emph{Description}:
1252 This function returns the number of threads in a thread team to which
1253 either the current thread or its ancestor belongs. For values of @var{level}
1254 outside zero to @code{omp_get_level}, -1 is returned; if @var{level} is zero,
1255 1 is returned, and for @code{omp_get_level}, the result is identical
1256 to @code{omp_get_num_threads}.
1259 @multitable @columnfractions .20 .80
1260 @item @emph{Prototype}: @tab @code{int omp_get_team_size(int level);}
1263 @item @emph{Fortran}:
1264 @multitable @columnfractions .20 .80
1265 @item @emph{Interface}: @tab @code{integer function omp_get_team_size(level)}
1266 @item @tab @code{integer level}
1269 @item @emph{See also}:
1270 @ref{omp_get_num_threads}, @ref{omp_get_level}, @ref{omp_get_ancestor_thread_num}
1272 @item @emph{Reference}:
1273 @uref{https://www.openmp.org, OpenMP specification v4.5}, Section 3.2.19.
1278 @node omp_get_active_level
1279 @subsection @code{omp_get_active_level} -- Number of parallel regions
1281 @item @emph{Description}:
1282 This function returns the nesting level for the active parallel blocks,
1283 which enclose the calling call.
1286 @multitable @columnfractions .20 .80
1287 @item @emph{Prototype}: @tab @code{int omp_get_active_level(void);}
1290 @item @emph{Fortran}:
1291 @multitable @columnfractions .20 .80
1292 @item @emph{Interface}: @tab @code{integer function omp_get_active_level()}
1295 @item @emph{See also}:
1296 @ref{omp_get_level}, @ref{omp_get_max_active_levels}, @ref{omp_set_max_active_levels}
1298 @item @emph{Reference}:
1299 @uref{https://www.openmp.org, OpenMP specification v4.5}, Section 3.2.20.
1304 @node Thread Affinity Routines
1305 @section Thread Affinity Routines
1307 Routines controlling and accessing thread-affinity policies.
1308 They have C linkage and do not throw exceptions.
1311 * omp_get_proc_bind:: Whether threads may be moved between CPUs
1312 @c * omp_get_num_places:: Get the number of places available
1313 @c * omp_get_place_num_procs:: Get the number of processes associated with a place
1314 @c * omp_get_place_proc_ids:: Get number of processes associated with a place
1315 @c * omp_get_place_num:: Get place number of the associated task
1316 @c * omp_get_partition_num_places:: Get number of places of innermost task
1317 @c * omp_get_partition_place_nums:: <fixme>
1318 @c * omp_set_affinity_format:: <fixme>
1319 @c * omp_get_affinity_format:: <fixme>
1320 @c * omp_display_affinity:: <fixme>
1321 @c * omp_capture_affinity:: <fixme>
1326 @node omp_get_proc_bind
1327 @subsection @code{omp_get_proc_bind} -- Whether threads may be moved between CPUs
1329 @item @emph{Description}:
1330 This functions returns the currently active thread affinity policy, which is
1331 set via @env{OMP_PROC_BIND}. Possible values are @code{omp_proc_bind_false},
1332 @code{omp_proc_bind_true}, @code{omp_proc_bind_primary},
1333 @code{omp_proc_bind_master}, @code{omp_proc_bind_close} and @code{omp_proc_bind_spread},
1334 where @code{omp_proc_bind_master} is an alias for @code{omp_proc_bind_primary}.
1337 @multitable @columnfractions .20 .80
1338 @item @emph{Prototype}: @tab @code{omp_proc_bind_t omp_get_proc_bind(void);}
1341 @item @emph{Fortran}:
1342 @multitable @columnfractions .20 .80
1343 @item @emph{Interface}: @tab @code{integer(kind=omp_proc_bind_kind) function omp_get_proc_bind()}
1346 @item @emph{See also}:
1347 @ref{OMP_PROC_BIND}, @ref{OMP_PLACES}, @ref{GOMP_CPU_AFFINITY},
1349 @item @emph{Reference}:
1350 @uref{https://www.openmp.org, OpenMP specification v4.5}, Section 3.2.22.
1355 @node Teams Region Routines
1356 @section Teams Region Routines
1358 Routines controlling the league of teams that are executed in a @code{teams}
1359 region. They have C linkage and do not throw exceptions.
1362 * omp_get_num_teams:: Number of teams
1363 * omp_get_team_num:: Get team number
1364 * omp_set_num_teams:: Set upper teams limit for teams region
1365 * omp_get_max_teams:: Maximum number of teams for teams region
1366 * omp_set_teams_thread_limit:: Set upper thread limit for teams construct
1367 * omp_get_thread_limit:: Maximum number of threads
1372 @node omp_get_num_teams
1373 @subsection @code{omp_get_num_teams} -- Number of teams
1375 @item @emph{Description}:
1376 Returns the number of teams in the current team region.
1379 @multitable @columnfractions .20 .80
1380 @item @emph{Prototype}: @tab @code{int omp_get_num_teams(void);}
1383 @item @emph{Fortran}:
1384 @multitable @columnfractions .20 .80
1385 @item @emph{Interface}: @tab @code{integer function omp_get_num_teams()}
1388 @item @emph{Reference}:
1389 @uref{https://www.openmp.org, OpenMP specification v4.5}, Section 3.2.32.
1394 @node omp_get_team_num
1395 @subsection @code{omp_get_team_num} -- Get team number
1397 @item @emph{Description}:
1398 Returns the team number of the calling thread.
1401 @multitable @columnfractions .20 .80
1402 @item @emph{Prototype}: @tab @code{int omp_get_team_num(void);}
1405 @item @emph{Fortran}:
1406 @multitable @columnfractions .20 .80
1407 @item @emph{Interface}: @tab @code{integer function omp_get_team_num()}
1410 @item @emph{Reference}:
1411 @uref{https://www.openmp.org, OpenMP specification v4.5}, Section 3.2.33.
1416 @node omp_set_num_teams
1417 @subsection @code{omp_set_num_teams} -- Set upper teams limit for teams construct
1419 @item @emph{Description}:
1420 Specifies the upper bound for number of teams created by the teams construct
1421 which does not specify a @code{num_teams} clause. The
1422 argument of @code{omp_set_num_teams} shall be a positive integer.
1425 @multitable @columnfractions .20 .80
1426 @item @emph{Prototype}: @tab @code{void omp_set_num_teams(int num_teams);}
1429 @item @emph{Fortran}:
1430 @multitable @columnfractions .20 .80
1431 @item @emph{Interface}: @tab @code{subroutine omp_set_num_teams(num_teams)}
1432 @item @tab @code{integer, intent(in) :: num_teams}
1435 @item @emph{See also}:
1436 @ref{OMP_NUM_TEAMS}, @ref{omp_get_num_teams}, @ref{omp_get_max_teams}
1438 @item @emph{Reference}:
1439 @uref{https://www.openmp.org, OpenMP specification v5.1}, Section 3.4.3.
1444 @node omp_get_max_teams
1445 @subsection @code{omp_get_max_teams} -- Maximum number of teams of teams region
1447 @item @emph{Description}:
1448 Return the maximum number of teams used for the teams region
1449 that does not use the clause @code{num_teams}.
1452 @multitable @columnfractions .20 .80
1453 @item @emph{Prototype}: @tab @code{int omp_get_max_teams(void);}
1456 @item @emph{Fortran}:
1457 @multitable @columnfractions .20 .80
1458 @item @emph{Interface}: @tab @code{integer function omp_get_max_teams()}
1461 @item @emph{See also}:
1462 @ref{omp_set_num_teams}, @ref{omp_get_num_teams}
1464 @item @emph{Reference}:
1465 @uref{https://www.openmp.org, OpenMP specification v5.1}, Section 3.4.4.
1470 @node omp_set_teams_thread_limit
1471 @subsection @code{omp_set_teams_thread_limit} -- Set upper thread limit for teams construct
1473 @item @emph{Description}:
1474 Specifies the upper bound for number of threads that are available
1475 for each team created by the teams construct which does not specify a
1476 @code{thread_limit} clause. The argument of
1477 @code{omp_set_teams_thread_limit} shall be a positive integer.
1480 @multitable @columnfractions .20 .80
1481 @item @emph{Prototype}: @tab @code{void omp_set_teams_thread_limit(int thread_limit);}
1484 @item @emph{Fortran}:
1485 @multitable @columnfractions .20 .80
1486 @item @emph{Interface}: @tab @code{subroutine omp_set_teams_thread_limit(thread_limit)}
1487 @item @tab @code{integer, intent(in) :: thread_limit}
1490 @item @emph{See also}:
1491 @ref{OMP_TEAMS_THREAD_LIMIT}, @ref{omp_get_teams_thread_limit}, @ref{omp_get_thread_limit}
1493 @item @emph{Reference}:
1494 @uref{https://www.openmp.org, OpenMP specification v5.1}, Section 3.4.5.
1499 @node omp_get_thread_limit
1500 @subsection @code{omp_get_thread_limit} -- Maximum number of threads
1502 @item @emph{Description}:
1503 Return the maximum number of threads of the program.
1506 @multitable @columnfractions .20 .80
1507 @item @emph{Prototype}: @tab @code{int omp_get_thread_limit(void);}
1510 @item @emph{Fortran}:
1511 @multitable @columnfractions .20 .80
1512 @item @emph{Interface}: @tab @code{integer function omp_get_thread_limit()}
1515 @item @emph{See also}:
1516 @ref{omp_get_max_threads}, @ref{OMP_THREAD_LIMIT}
1518 @item @emph{Reference}:
1519 @uref{https://www.openmp.org, OpenMP specification v4.5}, Section 3.2.14.
1524 @node Tasking Routines
1525 @section Tasking Routines
1527 Routines relating to explicit tasks.
1528 They have C linkage and do not throw exceptions.
1531 * omp_get_max_task_priority:: Maximum task priority value that can be set
1532 * omp_in_explicit_task:: Whether a given task is an explicit task
1533 * omp_in_final:: Whether in final or included task region
1534 @c * omp_is_free_agent:: <fixme>/TR12
1535 @c * omp_ancestor_is_free_agent:: <fixme>/TR12
1540 @node omp_get_max_task_priority
1541 @subsection @code{omp_get_max_task_priority} -- Maximum priority value
1542 that can be set for tasks.
1544 @item @emph{Description}:
1545 This function obtains the maximum allowed priority number for tasks.
1548 @multitable @columnfractions .20 .80
1549 @item @emph{Prototype}: @tab @code{int omp_get_max_task_priority(void);}
1552 @item @emph{Fortran}:
1553 @multitable @columnfractions .20 .80
1554 @item @emph{Interface}: @tab @code{integer function omp_get_max_task_priority()}
1557 @item @emph{Reference}:
1558 @uref{https://www.openmp.org, OpenMP specification v4.5}, Section 3.2.29.
1563 @node omp_in_explicit_task
1564 @subsection @code{omp_in_explicit_task} -- Whether a given task is an explicit task
1566 @item @emph{Description}:
1567 The function returns the @var{explicit-task-var} ICV; it returns true when the
1568 encountering task was generated by a task-generating construct such as
1569 @code{target}, @code{task} or @code{taskloop}. Otherwise, the encountering task
1570 is in an implicit task region such as generated by the implicit or explicit
1571 @code{parallel} region and @code{omp_in_explicit_task} returns false.
1574 @multitable @columnfractions .20 .80
1575 @item @emph{Prototype}: @tab @code{int omp_in_explicit_task(void);}
1578 @item @emph{Fortran}:
1579 @multitable @columnfractions .20 .80
1580 @item @emph{Interface}: @tab @code{logical function omp_in_explicit_task()}
1583 @item @emph{Reference}:
1584 @uref{https://www.openmp.org, OpenMP specification v5.2}, Section 18.5.2.
1590 @subsection @code{omp_in_final} -- Whether in final or included task region
1592 @item @emph{Description}:
1593 This function returns @code{true} if currently running in a final
1594 or included task region, @code{false} otherwise. Here, @code{true}
1595 and @code{false} represent their language-specific counterparts.
1598 @multitable @columnfractions .20 .80
1599 @item @emph{Prototype}: @tab @code{int omp_in_final(void);}
1602 @item @emph{Fortran}:
1603 @multitable @columnfractions .20 .80
1604 @item @emph{Interface}: @tab @code{logical function omp_in_final()}
1607 @item @emph{Reference}:
1608 @uref{https://www.openmp.org, OpenMP specification v4.5}, Section 3.2.21.
1613 @node Resource Relinquishing Routines
1614 @section Resource Relinquishing Routines
1616 Routines releasing resources used by the OpenMP runtime.
1617 They have C linkage and do not throw exceptions.
1620 * omp_pause_resource:: Release OpenMP resources on a device
1621 * omp_pause_resource_all:: Release OpenMP resources on all devices
1626 @node omp_pause_resource
1627 @subsection @code{omp_pause_resource} -- Release OpenMP resources on a device
1629 @item @emph{Description}:
1630 Free resources used by the OpenMP program and the runtime library on and for the
1631 device specified by @var{device_num}; on success, zero is returned and non-zero
1634 The value of @var{device_num} must be a conforming device number. The routine
1635 may not be called from within any explicit region and all explicit threads that
1636 do not bind to the implicit parallel region have finalized execution.
1639 @multitable @columnfractions .20 .80
1640 @item @emph{Prototype}: @tab @code{int omp_pause_resource(omp_pause_resource_t kind, int device_num);}
1643 @item @emph{Fortran}:
1644 @multitable @columnfractions .20 .80
1645 @item @emph{Interface}: @tab @code{integer function omp_pause_resource(kind, device_num)}
1646 @item @tab @code{integer (kind=omp_pause_resource_kind) kind}
1647 @item @tab @code{integer device_num}
1650 @item @emph{Reference}:
1651 @uref{https://www.openmp.org, OpenMP specification v5.0}, Section 3.2.43.
1656 @node omp_pause_resource_all
1657 @subsection @code{omp_pause_resource_all} -- Release OpenMP resources on all devices
1659 @item @emph{Description}:
1660 Free resources used by the OpenMP program and the runtime library on all devices,
1661 including the host. On success, zero is returned and non-zero otherwise.
1663 The routine may not be called from within any explicit region and all explicit
1664 threads that do not bind to the implicit parallel region have finalized execution.
1667 @multitable @columnfractions .20 .80
1668 @item @emph{Prototype}: @tab @code{int omp_pause_resource(omp_pause_resource_t kind);}
1671 @item @emph{Fortran}:
1672 @multitable @columnfractions .20 .80
1673 @item @emph{Interface}: @tab @code{integer function omp_pause_resource(kind)}
1674 @item @tab @code{integer (kind=omp_pause_resource_kind) kind}
1677 @item @emph{See also}:
1678 @ref{omp_pause_resource}
1680 @item @emph{Reference}:
1681 @uref{https://www.openmp.org, OpenMP specification v5.0}, Section 3.2.44.
1686 @node Device Information Routines
1687 @section Device Information Routines
1689 Routines related to devices available to an OpenMP program.
1690 They have C linkage and do not throw exceptions.
1693 * omp_get_num_procs:: Number of processors online
1694 @c * omp_get_max_progress_width:: <fixme>/TR11
1695 * omp_set_default_device:: Set the default device for target regions
1696 * omp_get_default_device:: Get the default device for target regions
1697 * omp_get_num_devices:: Number of target devices
1698 * omp_get_device_num:: Get device that current thread is running on
1699 * omp_get_device_from_uid:: Obtain the device number to a unique id
1700 * omp_get_uid_from_device:: Obtain the unique id of a device
1701 * omp_is_initial_device:: Whether executing on the host device
1702 * omp_get_initial_device:: Device number of host device
1703 @c * omp_get_device_num_teams:: <fixme>/TR13
1704 @c * omp_set_device_num_teams:: <fixme>/TR13
1705 @c * omp_get_device_teams_thread_limit:: <fixme>/TR13
1706 @c * omp_set_device_teams_thread_limit:: <fixme>/TR13
1711 @node omp_get_num_procs
1712 @subsection @code{omp_get_num_procs} -- Number of processors online
1714 @item @emph{Description}:
1715 Returns the number of processors online on that device.
1718 @multitable @columnfractions .20 .80
1719 @item @emph{Prototype}: @tab @code{int omp_get_num_procs(void);}
1722 @item @emph{Fortran}:
1723 @multitable @columnfractions .20 .80
1724 @item @emph{Interface}: @tab @code{integer function omp_get_num_procs()}
1727 @item @emph{Reference}:
1728 @uref{https://www.openmp.org, OpenMP specification v4.5}, Section 3.2.5.
1733 @node omp_set_default_device
1734 @subsection @code{omp_set_default_device} -- Set the default device for target regions
1736 @item @emph{Description}:
1737 Get the value of the @emph{default-device-var} ICV, which is used
1738 for target regions without a device clause. The argument
1739 shall be a nonnegative device number, @code{omp_initial_device},
1740 or @code{omp_invalid_device}.
1742 The effect of running this routine in a @code{target} region is unspecified.
1745 @multitable @columnfractions .20 .80
1746 @item @emph{Prototype}: @tab @code{void omp_set_default_device(int device_num);}
1749 @item @emph{Fortran}:
1750 @multitable @columnfractions .20 .80
1751 @item @emph{Interface}: @tab @code{subroutine omp_set_default_device(device_num)}
1752 @item @tab @code{integer device_num}
1755 @item @emph{See also}:
1756 @ref{OMP_DEFAULT_DEVICE}, @ref{omp_get_default_device}
1758 @item @emph{Reference}:
1759 @uref{https://www.openmp.org, OpenMP specification v4.5}, Section 3.2.29.
1764 @node omp_get_default_device
1765 @subsection @code{omp_get_default_device} -- Get the default device for target regions
1767 @item @emph{Description}:
1768 Get the value of the @emph{default-device-var} ICV, which is used
1769 for target regions without a device clause. The value is either a
1770 nonnegative device number, @code{omp_initial_device} or
1771 @code{omp_invalid_device}. Note that for the host, the ICV can have two values:
1772 either the value of the named constant @code{omp_initial_device} or the value
1773 returned by the @code{omp_get_num_devices} routine.
1775 The effect of running this routine in a @code{target} region is unspecified.
1778 @multitable @columnfractions .20 .80
1779 @item @emph{Prototype}: @tab @code{int omp_get_default_device(void);}
1782 @item @emph{Fortran}:
1783 @multitable @columnfractions .20 .80
1784 @item @emph{Interface}: @tab @code{integer function omp_get_default_device()}
1787 @item @emph{See also}:
1788 @ref{OMP_DEFAULT_DEVICE}, @ref{omp_set_default_device},
1789 @ref{omp_get_initial_device}
1791 @item @emph{Reference}:
1792 @uref{https://www.openmp.org, OpenMP specification v4.5}, Section 3.2.30.
1797 @node omp_get_num_devices
1798 @subsection @code{omp_get_num_devices} -- Number of target devices
1800 @item @emph{Description}:
1801 Returns the number of available non-host devices.
1803 The effect of running this routine in a @code{target} region is unspecified.
1805 Note that in GCC the function is marked pure, i.e. as returning always the
1806 same number. When GCC was not configured to support offloading, it is replaced
1807 by zero; compile with @option{-fno-builtin-omp_get_num_devices} if a run-time
1808 function is desired.
1811 @multitable @columnfractions .20 .80
1812 @item @emph{Prototype}: @tab @code{int omp_get_num_devices(void);}
1815 @item @emph{Fortran}:
1816 @multitable @columnfractions .20 .80
1817 @item @emph{Interface}: @tab @code{integer function omp_get_num_devices()}
1820 @item @emph{See also}:
1821 @ref{omp_get_initial_device}
1823 @item @emph{Reference}:
1824 @uref{https://www.openmp.org, OpenMP specification v4.5}, Section 3.2.31.
1829 @node omp_get_device_num
1830 @subsection @code{omp_get_device_num} -- Return device number of current device
1832 @item @emph{Description}:
1833 This function returns a device number that represents the device that the
1834 current thread is executing on. When called on the host, it returns
1835 the same value as returned by the @code{omp_get_initial_device} function
1836 as required since OpenMP 5.0.
1839 @multitable @columnfractions .20 .80
1840 @item @emph{Prototype}: @tab @code{int omp_get_device_num(void);}
1843 @item @emph{Fortran}:
1844 @multitable @columnfractions .20 .80
1845 @item @emph{Interface}: @tab @code{integer function omp_get_device_num()}
1848 @item @emph{See also}:
1849 @ref{omp_get_initial_device}
1851 @item @emph{Reference}:
1852 @uref{https://www.openmp.org, OpenMP specification v5.0}, Section 3.2.37.
1857 @node omp_get_device_from_uid
1858 @subsection @code{omp_get_device_from_uid} -- Obtain the device number to a unique id
1860 @item @emph{Description}:
1861 This function returns the device number associated with the passed
1862 unique-identifier (UID) string. If no device with this UID is available, the value
1863 @code{omp_invalid_device} is returned. The effect of running this routine in a
1864 @code{target} region is unspecified.
1866 GCC treats the UID string case sensitive; for the initial device, GCC currently
1867 only accepts the value @code{OMP_INITIAL_DEVICE} and returns for it the value
1868 of @code{omp_initial_device}.
1871 @multitable @columnfractions .20 .80
1872 @item @emph{Prototype}: @tab @code{int omp_get_device_from_uid(const char *uid);}
1875 @item @emph{Fortran}:
1876 @multitable @columnfractions .20 .80
1877 @item @emph{Interface}: @tab @code{integer function omp_get_device_from_uid(uid)}
1878 @item @tab @code{character(len=*), intent(in) :: uid}
1881 @item @emph{See also}:
1882 @ref{omp_get_uid_from_device}, @ref{Offload-Target Specifics}
1884 @item @emph{Reference}:
1885 @uref{https://www.openmp.org, OpenMP specification v6.0}, Section 24.7
1890 @node omp_get_uid_from_device
1891 @subsection @code{omp_get_uid_from_device} -- Obtain the unique id of a device
1893 @item @emph{Description}:
1894 This function returns a pointer to a string that represents a unique identifier
1895 (UID) for the device specified by @var{device_num}. It returns a @code{NULL} (C/C++)
1896 or a disassociated pointer (Fortran) for @code{omp_invalid_device}. The effect of
1897 running this routine in a @code{target} region is unspecified.
1899 GCC currently returns for initial device the value @code{OMP_INITIAL_DEVICE}.
1902 @multitable @columnfractions .20 .80
1903 @item @emph{Prototype}: @tab @code{const char *omp_get_uid_from_device(int device_num);}
1906 @item @emph{Fortran}:
1907 @multitable @columnfractions .20 .80
1908 @item @emph{Interface}: @tab @code{character(:) function omp_get_uid_from_device(device_num)}
1909 @item @emph{Interface}: @tab @code{pointer :: omp_get_uid_from_device}
1910 @item @tab @code{integer, intent(in) :: device_num}
1913 @item @emph{See also}:
1914 @ref{omp_get_uid_from_device}, @ref{Offload-Target Specifics}
1916 @item @emph{Reference}:
1917 @uref{https://www.openmp.org, OpenMP specification v6.0}, Section 24.8
1922 @node omp_is_initial_device
1923 @subsection @code{omp_is_initial_device} -- Whether executing on the host device
1925 @item @emph{Description}:
1926 This function returns @code{true} if currently running on the host device,
1927 @code{false} otherwise. Here, @code{true} and @code{false} represent
1928 their language-specific counterparts.
1930 Note that in GCC this function call is already folded to a constant in the
1931 compiler; compile with @option{-fno-builtin-omp_is_initial_device} if a
1932 run-time function is desired.
1935 @multitable @columnfractions .20 .80
1936 @item @emph{Prototype}: @tab @code{int omp_is_initial_device(void);}
1939 @item @emph{Fortran}:
1940 @multitable @columnfractions .20 .80
1941 @item @emph{Interface}: @tab @code{logical function omp_is_initial_device()}
1944 @item @emph{Reference}:
1945 @uref{https://www.openmp.org, OpenMP specification v4.5}, Section 3.2.34.
1950 @node omp_get_initial_device
1951 @subsection @code{omp_get_initial_device} -- Return device number of initial device
1953 @item @emph{Description}:
1954 This function returns a device number that represents the host device.
1955 Since OpenMP 5.1, this is equal to the value returned by the
1956 @code{omp_get_num_devices} function; since OpenMP 6.0 it may also return
1957 the value of @code{omp_initial_device}.
1959 The effect of running this routine in a @code{target} region is unspecified.
1961 Note that GCC inlines this function unless you compile with
1962 @option{-fno-builtin-omp_get_initial_device}. If GCC was not configured to
1963 support offloading, it expands to constant zero; in non-host code it expands
1964 to @code{omp_initial_device}; and otherwise it is replaced with a call to
1965 @code{omp_get_num_devices}.
1968 @multitable @columnfractions .20 .80
1969 @item @emph{Prototype}: @tab @code{int omp_get_initial_device(void);}
1972 @item @emph{Fortran}:
1973 @multitable @columnfractions .20 .80
1974 @item @emph{Interface}: @tab @code{integer function omp_get_initial_device()}
1977 @item @emph{See also}:
1978 @ref{omp_get_num_devices}
1980 @item @emph{Reference}:
1981 @uref{https://www.openmp.org, OpenMP specification v4.5}, Section 3.2.35.
1986 @node Device Memory Routines
1987 @section Device Memory Routines
1989 Routines related to memory allocation and managing corresponding
1990 pointers on devices. They have C linkage and do not throw exceptions.
1993 * omp_target_alloc:: Allocate device memory
1994 * omp_target_free:: Free device memory
1995 * omp_target_is_present:: Check whether storage is mapped
1996 * omp_target_is_accessible:: Check whether memory is device accessible
1997 * omp_target_memcpy:: Copy data between devices
1998 * omp_target_memcpy_async:: Copy data between devices asynchronously
1999 * omp_target_memcpy_rect:: Copy a subvolume of data between devices
2000 * omp_target_memcpy_rect_async:: Copy a subvolume of data between devices asynchronously
2001 * omp_target_memset:: Set bytes in device memory
2002 * omp_target_memset_async:: Set bytes in device memory asynchronously
2003 * omp_target_associate_ptr:: Associate a device pointer with a host pointer
2004 * omp_target_disassociate_ptr:: Remove device--host pointer association
2005 * omp_get_mapped_ptr:: Return device pointer to a host pointer
2010 @node omp_target_alloc
2011 @subsection @code{omp_target_alloc} -- Allocate device memory
2013 @item @emph{Description}:
2014 This routine allocates @var{size} bytes of memory in the device environment
2015 associated with the device number @var{device_num}. If successful, a device
2016 pointer is returned, otherwise a null pointer.
2018 In GCC, when the device is the host or the device shares memory with the host,
2019 the memory is allocated on the host; in that case, when @var{size} is zero,
2020 either NULL or a unique pointer value that can later be successfully passed to
2021 @code{omp_target_free} is returned. When the allocation is not performed on
2022 the host, a null pointer is returned when @var{size} is zero; in that case,
2023 additionally a diagnostic might be printed to standard error (stderr).
2025 Running this routine in a @code{target} region except on the initial device
2029 @multitable @columnfractions .20 .80
2030 @item @emph{Prototype}: @tab @code{void *omp_target_alloc(size_t size, int device_num)}
2033 @item @emph{Fortran}:
2034 @multitable @columnfractions .20 .80
2035 @item @emph{Interface}: @tab @code{type(c_ptr) function omp_target_alloc(size, device_num) bind(C)}
2036 @item @tab @code{use, intrinsic :: iso_c_binding, only: c_ptr, c_int, c_size_t}
2037 @item @tab @code{integer(c_size_t), value :: size}
2038 @item @tab @code{integer(c_int), value :: device_num}
2041 @item @emph{See also}:
2042 @ref{omp_target_free}, @ref{omp_target_associate_ptr}
2044 @item @emph{Reference}:
2045 @uref{https://www.openmp.org, OpenMP specification v5.1}, Section 3.8.1
2050 @node omp_target_free
2051 @subsection @code{omp_target_free} -- Free device memory
2053 @item @emph{Description}:
2054 This routine frees memory allocated by the @code{omp_target_alloc} routine.
2055 The @var{device_ptr} argument must be either a null pointer or a device pointer
2056 returned by @code{omp_target_alloc} for the specified @code{device_num}. The
2057 device number @var{device_num} must be a conforming device number.
2059 Running this routine in a @code{target} region except on the initial device
2063 @multitable @columnfractions .20 .80
2064 @item @emph{Prototype}: @tab @code{void omp_target_free(void *device_ptr, int device_num)}
2067 @item @emph{Fortran}:
2068 @multitable @columnfractions .20 .80
2069 @item @emph{Interface}: @tab @code{subroutine omp_target_free(device_ptr, device_num) bind(C)}
2070 @item @tab @code{use, intrinsic :: iso_c_binding, only: c_ptr, c_int}
2071 @item @tab @code{type(c_ptr), value :: device_ptr}
2072 @item @tab @code{integer(c_int), value :: device_num}
2075 @item @emph{See also}:
2076 @ref{omp_target_alloc}, @ref{omp_target_disassociate_ptr}
2078 @item @emph{Reference}:
2079 @uref{https://www.openmp.org, OpenMP specification v5.1}, Section 3.8.2
2084 @node omp_target_is_present
2085 @subsection @code{omp_target_is_present} -- Check whether storage is mapped
2087 @item @emph{Description}:
2088 This routine tests whether storage, identified by the host pointer @var{ptr}
2089 is mapped to the device specified by @var{device_num}. If so, it returns
2090 a nonzero value and otherwise zero.
2092 In GCC, this includes self mapping such that @code{omp_target_is_present}
2093 returns @emph{true} when @var{device_num} specifies the host or when the host
2094 and the device share memory. If @var{ptr} is a null pointer, @var{true} is
2095 returned and if @var{device_num} is an invalid device number, @var{false} is
2098 If those conditions do not apply, @emph{true} is returned if the association has
2099 been established by an explicit or implicit @code{map} clause, the
2100 @code{declare target} directive or a call to the @code{omp_target_associate_ptr}
2103 Running this routine in a @code{target} region except on the initial device
2107 @multitable @columnfractions .20 .80
2108 @item @emph{Prototype}: @tab @code{int omp_target_is_present(const void *ptr,}
2109 @item @tab @code{ int device_num)}
2112 @item @emph{Fortran}:
2113 @multitable @columnfractions .20 .80
2114 @item @emph{Interface}: @tab @code{integer(c_int) function omp_target_is_present(ptr, &}
2115 @item @tab @code{ device_num) bind(C)}
2116 @item @tab @code{use, intrinsic :: iso_c_binding, only: c_ptr, c_int}
2117 @item @tab @code{type(c_ptr), value :: ptr}
2118 @item @tab @code{integer(c_int), value :: device_num}
2121 @item @emph{See also}:
2122 @ref{omp_target_associate_ptr}
2124 @item @emph{Reference}:
2125 @uref{https://www.openmp.org, OpenMP specification v5.1}, Section 3.8.3
2130 @node omp_target_is_accessible
2131 @subsection @code{omp_target_is_accessible} -- Check whether memory is device accessible
2133 @item @emph{Description}:
2134 This routine tests whether memory, starting at the address given by @var{ptr}
2135 and extending @var{size} bytes, is accessibly on the device specified by
2136 @var{device_num}. If so, it returns a nonzero value and otherwise zero.
2138 The address given by @var{ptr} is interpreted to be in the address space of
2139 the device and @var{size} must be positive.
2141 Note that GCC's current implementation assumes that @var{ptr} is a valid host
2142 pointer. Therefore, all addresses given by @var{ptr} are assumed to be
2143 accessible on the initial device. And, to err on the safe side, this memory
2144 is only available on a non-host device that can access all host memory
2145 ([uniform] shared memory access).
2147 Running this routine in a @code{target} region except on the initial device
2151 @multitable @columnfractions .20 .80
2152 @item @emph{Prototype}: @tab @code{int omp_target_is_accessible(const void *ptr,}
2153 @item @tab @code{ size_t size,}
2154 @item @tab @code{ int device_num)}
2157 @item @emph{Fortran}:
2158 @multitable @columnfractions .20 .80
2159 @item @emph{Interface}: @tab @code{integer(c_int) function omp_target_is_accessible(ptr, &}
2160 @item @tab @code{ size, device_num) bind(C)}
2161 @item @tab @code{use, intrinsic :: iso_c_binding, only: c_ptr, c_size_t, c_int}
2162 @item @tab @code{type(c_ptr), value :: ptr}
2163 @item @tab @code{integer(c_size_t), value :: size}
2164 @item @tab @code{integer(c_int), value :: device_num}
2167 @item @emph{See also}:
2168 @ref{omp_target_associate_ptr}
2170 @item @emph{Reference}:
2171 @uref{https://www.openmp.org, OpenMP specification v5.1}, Section 3.8.4
2176 @node omp_target_memcpy
2177 @subsection @code{omp_target_memcpy} -- Copy data between devices
2179 @item @emph{Description}:
2180 This routine copies @var{length} of bytes of data from the device
2181 identified by device number @var{src_device_num} to device @var{dst_device_num}.
2182 The data is copied from the source device from the address provided by
2183 @var{src}, shifted by the offset of @var{src_offset} bytes, to the destination
2184 device's @var{dst} address shifted by @var{dst_offset}. The routine returns
2185 zero on success and non-zero otherwise.
2187 Running this routine in a @code{target} region except on the initial device
2191 @multitable @columnfractions .20 .80
2192 @item @emph{Prototype}: @tab @code{int omp_target_memcpy(void *dst,}
2193 @item @tab @code{ const void *src,}
2194 @item @tab @code{ size_t length,}
2195 @item @tab @code{ size_t dst_offset,}
2196 @item @tab @code{ size_t src_offset,}
2197 @item @tab @code{ int dst_device_num,}
2198 @item @tab @code{ int src_device_num)}
2201 @item @emph{Fortran}:
2202 @multitable @columnfractions .20 .80
2203 @item @emph{Interface}: @tab @code{integer(c_int) function omp_target_memcpy( &}
2204 @item @tab @code{ dst, src, length, dst_offset, src_offset, &}
2205 @item @tab @code{ dst_device_num, src_device_num) bind(C)}
2206 @item @tab @code{use, intrinsic :: iso_c_binding, only: c_ptr, c_size_t, c_int}
2207 @item @tab @code{type(c_ptr), value :: dst, src}
2208 @item @tab @code{integer(c_size_t), value :: length, dst_offset, src_offset}
2209 @item @tab @code{integer(c_int), value :: dst_device_num, src_device_num}
2212 @item @emph{See also}:
2213 @ref{omp_target_memcpy_async}, @ref{omp_target_memcpy_rect}
2215 @item @emph{Reference}:
2216 @uref{https://www.openmp.org, OpenMP specification v5.1}, Section 3.8.5
2221 @node omp_target_memcpy_async
2222 @subsection @code{omp_target_memcpy_async} -- Copy data between devices asynchronously
2224 @item @emph{Description}:
2225 This routine copies asynchronously @var{length} of bytes of data from the
2226 device identified by device number @var{src_device_num} to device
2227 @var{dst_device_num}. The data is copied from the source device from the
2228 address provided by @var{src}, shifted by the offset of @var{src_offset} bytes,
2229 to the destination device's @var{dst} address shifted by @var{dst_offset}.
2230 Task dependence is expressed by passing an array of depend objects to
2231 @var{depobj_list}, where the number of array elements is passed as
2232 @var{depobj_count}; if the count is zero, the @var{depobj_list} argument is
2233 ignored. In C++ and Fortran, the @var{depobj_list} argument can also be
2234 omitted in that case. The routine returns zero if the copying process has
2235 successfully been started and non-zero otherwise.
2237 Running this routine in a @code{target} region except on the initial device
2241 @multitable @columnfractions .20 .80
2242 @item @emph{Prototype}: @tab @code{int omp_target_memcpy_async(void *dst,}
2243 @item @tab @code{ const void *src,}
2244 @item @tab @code{ size_t length,}
2245 @item @tab @code{ size_t dst_offset,}
2246 @item @tab @code{ size_t src_offset,}
2247 @item @tab @code{ int dst_device_num,}
2248 @item @tab @code{ int src_device_num,}
2249 @item @tab @code{ int depobj_count,}
2250 @item @tab @code{ omp_depend_t *depobj_list)}
2253 @item @emph{Fortran}:
2254 @multitable @columnfractions .20 .80
2255 @item @emph{Interface}: @tab @code{integer(c_int) function omp_target_memcpy_async( &}
2256 @item @tab @code{ dst, src, length, dst_offset, src_offset, &}
2257 @item @tab @code{ dst_device_num, src_device_num, &}
2258 @item @tab @code{ depobj_count, depobj_list) bind(C)}
2259 @item @tab @code{use, intrinsic :: iso_c_binding, only: c_ptr, c_size_t, c_int}
2260 @item @tab @code{type(c_ptr), value :: dst, src}
2261 @item @tab @code{integer(c_size_t), value :: length, dst_offset, src_offset}
2262 @item @tab @code{integer(c_int), value :: dst_device_num, src_device_num, depobj_count}
2263 @item @tab @code{integer(omp_depend_kind), optional :: depobj_list(*)}
2266 @item @emph{See also}:
2267 @ref{omp_target_memcpy}, @ref{omp_target_memcpy_rect_async}
2269 @item @emph{Reference}:
2270 @uref{https://www.openmp.org, OpenMP specification v5.1}, Section 3.8.7
2275 @node omp_target_memcpy_rect
2276 @subsection @code{omp_target_memcpy_rect} -- Copy a subvolume of data between devices
2278 @item @emph{Description}:
2279 This routine copies a subvolume of data from the device identified by
2280 device number @var{src_device_num} to device @var{dst_device_num}.
2281 The array has @var{num_dims} dimensions and each array element has a size of
2282 @var{element_size} bytes. The @var{volume} array specifies how many elements
2283 per dimension are copied. The full sizes of the destination and source arrays
2284 are given by the @var{dst_dimensions} and @var{src_dimensions} arguments,
2285 respectively. The offset per dimension to the first element to be copied is
2286 given by the @var{dst_offset} and @var{src_offset} arguments. The routine
2287 returns zero on success and non-zero otherwise.
2289 The OpenMP specification only requires that @var{num_dims} up to three is
2290 supported. In order to find implementation-specific maximally supported number
2291 of dimensions, the routine returns this value when invoked with a null pointer
2292 to both the @var{dst} and @var{src} arguments. As GCC supports arbitrary
2293 dimensions, it returns @code{INT_MAX}.
2295 The device-number arguments must be conforming device numbers, the @var{src} and
2296 @var{dst} must be either both null pointers or all of the following must be
2297 fulfilled: @var{element_size} and @var{num_dims} must be positive and the
2298 @var{volume}, offset and dimension arrays must have at least @var{num_dims}
2301 Running this routine in a @code{target} region is not supported except on
2305 @multitable @columnfractions .20 .80
2306 @item @emph{Prototype}: @tab @code{int omp_target_memcpy_rect(void *dst,}
2307 @item @tab @code{ const void *src,}
2308 @item @tab @code{ size_t element_size,}
2309 @item @tab @code{ int num_dims,}
2310 @item @tab @code{ const size_t *volume,}
2311 @item @tab @code{ const size_t *dst_offset,}
2312 @item @tab @code{ const size_t *src_offset,}
2313 @item @tab @code{ const size_t *dst_dimensions,}
2314 @item @tab @code{ const size_t *src_dimensions,}
2315 @item @tab @code{ int dst_device_num,}
2316 @item @tab @code{ int src_device_num)}
2319 @item @emph{Fortran}:
2320 @multitable @columnfractions .20 .80
2321 @item @emph{Interface}: @tab @code{integer(c_int) function omp_target_memcpy_rect( &}
2322 @item @tab @code{ dst, src, element_size, num_dims, volume, &}
2323 @item @tab @code{ dst_offset, src_offset, dst_dimensions, &}
2324 @item @tab @code{ src_dimensions, dst_device_num, src_device_num) bind(C)}
2325 @item @tab @code{use, intrinsic :: iso_c_binding, only: c_ptr, c_size_t, c_int}
2326 @item @tab @code{type(c_ptr), value :: dst, src}
2327 @item @tab @code{integer(c_size_t), value :: element_size, dst_offset, src_offset}
2328 @item @tab @code{integer(c_size_t), value :: volume, dst_dimensions, src_dimensions}
2329 @item @tab @code{integer(c_int), value :: num_dims, dst_device_num, src_device_num}
2332 @item @emph{See also}:
2333 @ref{omp_target_memcpy_rect_async}, @ref{omp_target_memcpy}, @ref{Offload-Target Specifics}
2335 @item @emph{Reference}:
2336 @uref{https://www.openmp.org, OpenMP specification v5.1}, Section 3.8.6
2341 @node omp_target_memcpy_rect_async
2342 @subsection @code{omp_target_memcpy_rect_async} -- Copy a subvolume of data between devices asynchronously
2344 @item @emph{Description}:
2345 This routine copies asynchronously a subvolume of data from the device
2346 identified by device number @var{src_device_num} to device @var{dst_device_num}.
2347 The array has @var{num_dims} dimensions and each array element has a size of
2348 @var{element_size} bytes. The @var{volume} array specifies how many elements
2349 per dimension are copied. The full sizes of the destination and source arrays
2350 are given by the @var{dst_dimensions} and @var{src_dimensions} arguments,
2351 respectively. The offset per dimension to the first element to be copied is
2352 given by the @var{dst_offset} and @var{src_offset} arguments. Task dependence
2353 is expressed by passing an array of depend objects to @var{depobj_list}, where
2354 the number of array elements is passed as @var{depobj_count}; if the count is
2355 zero, the @var{depobj_list} argument is ignored. In C++ and Fortran, the
2356 @var{depobj_list} argument can also be omitted in that case. The routine
2357 returns zero on success and non-zero otherwise.
2359 The OpenMP specification only requires that @var{num_dims} up to three is
2360 supported. In order to find implementation-specific maximally supported number
2361 of dimensions, the routine returns this value when invoked with a null pointer
2362 to both the @var{dst} and @var{src} arguments. As GCC supports arbitrary
2363 dimensions, it returns @code{INT_MAX}.
2365 The device-number arguments must be conforming device numbers, the @var{src} and
2366 @var{dst} must be either both null pointers or all of the following must be
2367 fulfilled: @var{element_size} and @var{num_dims} must be positive and the
2368 @var{volume}, offset and dimension arrays must have at least @var{num_dims}
2371 Running this routine in a @code{target} region is not supported except on
2375 @multitable @columnfractions .20 .80
2376 @item @emph{Prototype}: @tab @code{int omp_target_memcpy_rect_async(void *dst,}
2377 @item @tab @code{ const void *src,}
2378 @item @tab @code{ size_t element_size,}
2379 @item @tab @code{ int num_dims,}
2380 @item @tab @code{ const size_t *volume,}
2381 @item @tab @code{ const size_t *dst_offset,}
2382 @item @tab @code{ const size_t *src_offset,}
2383 @item @tab @code{ const size_t *dst_dimensions,}
2384 @item @tab @code{ const size_t *src_dimensions,}
2385 @item @tab @code{ int dst_device_num,}
2386 @item @tab @code{ int src_device_num,}
2387 @item @tab @code{ int depobj_count,}
2388 @item @tab @code{ omp_depend_t *depobj_list)}
2391 @item @emph{Fortran}:
2392 @multitable @columnfractions .20 .80
2393 @item @emph{Interface}: @tab @code{integer(c_int) function omp_target_memcpy_rect_async( &}
2394 @item @tab @code{ dst, src, element_size, num_dims, volume, &}
2395 @item @tab @code{ dst_offset, src_offset, dst_dimensions, &}
2396 @item @tab @code{ src_dimensions, dst_device_num, src_device_num, &}
2397 @item @tab @code{ depobj_count, depobj_list) bind(C)}
2398 @item @tab @code{use, intrinsic :: iso_c_binding, only: c_ptr, c_size_t, c_int}
2399 @item @tab @code{type(c_ptr), value :: dst, src}
2400 @item @tab @code{integer(c_size_t), value :: element_size, dst_offset, src_offset}
2401 @item @tab @code{integer(c_size_t), value :: volume, dst_dimensions, src_dimensions}
2402 @item @tab @code{integer(c_int), value :: num_dims, dst_device_num, src_device_num}
2403 @item @tab @code{integer(c_int), value :: depobj_count}
2404 @item @tab @code{integer(omp_depend_kind), optional :: depobj_list(*)}
2407 @item @emph{See also}:
2408 @ref{omp_target_memcpy_rect}, @ref{omp_target_memcpy_async}, @ref{Offload-Target Specifics}
2410 @item @emph{Reference}:
2411 @uref{https://www.openmp.org, OpenMP specification v5.1}, Section 3.8.8
2415 @node omp_target_memset
2416 @subsection @code{omp_target_memset} -- Set bytes in device memory
2418 @item @emph{Description}:
2419 This routine fills memory on the device identified by device number
2420 @var{device_num}. Starting from the device address @var{ptr}, the first
2421 @var{count} bytes are set to the value @var{val}, converted to
2422 @code{unsigned char}. If @var{count} is zero, the routine has no effect;
2423 if @var{ptr} is @code{NULL}, the behavior is unspecified. The function
2426 The @var{device_num} must be a conforming device number and @var{ptr} must be
2427 a valid device pointer for that device. Running this routine in a
2428 @code{target} region except on the initial device is not supported.
2431 @multitable @columnfractions .20 .80
2432 @item @emph{Prototype}: @tab @code{void *omp_target_memcpy(void *ptr,}
2433 @item @tab @code{ int val,}
2434 @item @tab @code{ size_t count,}
2435 @item @tab @code{ int device_num)}
2438 @item @emph{Fortran}:
2439 @multitable @columnfractions .20 .80
2440 @item @emph{Interface}: @tab @code{type(c_ptr) function omp_target_memset( &}
2441 @item @tab @code{ ptr, val, count, device_num) bind(C)}
2442 @item @tab @code{use, intrinsic :: iso_c_binding, only: c_ptr, c_size_t, c_int}
2443 @item @tab @code{type(c_ptr), value :: ptr}
2444 @item @tab @code{integer(c_size_t), value :: count}
2445 @item @tab @code{integer(c_int), value :: val, device_num}
2448 @item @emph{See also}:
2449 @ref{omp_target_memset_async}
2451 @item @emph{Reference}:
2452 @uref{https://www.openmp.org, OpenMP specification v6.0}, Section 25.8.1
2457 @node omp_target_memset_async
2458 @subsection @code{omp_target_memset} -- Set bytes in device memory asynchronously
2460 @item @emph{Description}:
2461 This routine fills memory on the device identified by device number
2462 @var{device_num}. Starting from the device address @var{ptr}, the first
2463 @var{count} bytes are set to the value @var{val}, converted to
2464 @code{unsigned char}. If @var{count} is zero, the routine has no effect;
2465 if @var{ptr} is @code{NULL}, the behavior is unspecified. Task dependence
2466 is expressed by passing an array of depend objects to @var{depobj_list}, where
2467 the number of array elements is passed as @var{depobj_count}; if the count is
2468 zero, the @var{depobj_list} argument is ignored. In C++ and Fortran, the
2469 @var{depobj_list} argument can also be omitted in that case. The function
2472 The @var{device_num} must be a conforming device number and @var{ptr} must be
2473 a valid device pointer for that device. Running this routine in a
2474 @code{target} region except on the initial device is not supported.
2477 @multitable @columnfractions .20 .80
2478 @item @emph{Prototype}: @tab @code{void *omp_target_memcpy_async(void *ptr,}
2479 @item @tab @code{ int val,}
2480 @item @tab @code{ size_t count,}
2481 @item @tab @code{ int device_num,}
2482 @item @tab @code{ int depobj_count,}
2483 @item @tab @code{ omp_depend_t *depobj_list)}
2486 @item @emph{Fortran}:
2487 @multitable @columnfractions .20 .80
2488 @item @emph{Interface}: @tab @code{type(c_ptr) function omp_target_memset_async( &}
2489 @item @tab @code{ ptr, val, count, device_num, &}
2490 @item @tab @code{ depobj_count, depobj_list) bind(C)}
2491 @item @tab @code{use, intrinsic :: iso_c_binding, only: c_ptr, c_size_t, c_int}
2492 @item @tab @code{type(c_ptr), value :: ptr}
2493 @item @tab @code{integer(c_size_t), value :: count}
2494 @item @tab @code{integer(c_int), value :: val, device_num, depobj_count}
2495 @item @tab @code{integer(omp_depend_kind), optional :: depobj_list(*)}
2499 @item @emph{See also}:
2500 @ref{omp_target_memset}
2502 @item @emph{Reference}:
2503 @uref{https://www.openmp.org, OpenMP specification v6.0}, Section 25.8.2
2508 @node omp_target_associate_ptr
2509 @subsection @code{omp_target_associate_ptr} -- Associate a device pointer with a host pointer
2511 @item @emph{Description}:
2512 This routine associates storage on the host with storage on a device identified
2513 by @var{device_num}. The device pointer is usually obtained by calling
2514 @code{omp_target_alloc} or by other means (but not by using the @code{map}
2515 clauses or the @code{declare target} directive). The host pointer should point
2516 to memory that has a storage size of at least @var{size}.
2518 The @var{device_offset} parameter specifies the offset into @var{device_ptr}
2519 that is used as the base address for the device side of the mapping; the
2520 storage size should be at least @var{device_offset} plus @var{size}.
2522 After the association, the host pointer can be used in a @code{map} clause and
2523 in the @code{to} and @code{from} clauses of the @code{target update} directive
2524 to transfer data between the associated pointers. The reference count of such
2525 associated storage is infinite. The association can be removed by calling
2526 @code{omp_target_disassociate_ptr} which should be done before the lifetime
2527 of either storage ends.
2529 The routine returns nonzero (@code{EINVAL}) when the @var{device_num} invalid,
2530 for when the initial device or the associated device shares memory with the
2531 host. @code{omp_target_associate_ptr} returns zero if @var{host_ptr} points
2532 into already associated storage that is fully inside of a previously associated
2533 memory. Otherwise, if the association was successful zero is returned; if none
2534 of the cases above apply, nonzero (@code{EINVAL}) is returned.
2536 The @code{omp_target_is_present} routine can be used to test whether
2537 associated storage for a device pointer exists.
2539 Running this routine in a @code{target} region except on the initial device
2543 @multitable @columnfractions .20 .80
2544 @item @emph{Prototype}: @tab @code{int omp_target_associate_ptr(const void *host_ptr,}
2545 @item @tab @code{ const void *device_ptr,}
2546 @item @tab @code{ size_t size,}
2547 @item @tab @code{ size_t device_offset,}
2548 @item @tab @code{ int device_num)}
2551 @item @emph{Fortran}:
2552 @multitable @columnfractions .20 .80
2553 @item @emph{Interface}: @tab @code{integer(c_int) function omp_target_associate_ptr(host_ptr, &}
2554 @item @tab @code{ device_ptr, size, device_offset, device_num) bind(C)}
2555 @item @tab @code{use, intrinsic :: iso_c_binding, only: c_ptr, c_int, c_size_t}
2556 @item @tab @code{type(c_ptr), value :: host_ptr, device_ptr}
2557 @item @tab @code{integer(c_size_t), value :: size, device_offset}
2558 @item @tab @code{integer(c_int), value :: device_num}
2561 @item @emph{See also}:
2562 @ref{omp_target_disassociate_ptr}, @ref{omp_target_is_present},
2563 @ref{omp_target_alloc}
2565 @item @emph{Reference}:
2566 @uref{https://www.openmp.org, OpenMP specification v5.1}, Section 3.8.9
2571 @node omp_target_disassociate_ptr
2572 @subsection @code{omp_target_disassociate_ptr} -- Remove device--host pointer association
2574 @item @emph{Description}:
2575 This routine removes the storage association established by calling
2576 @code{omp_target_associate_ptr} and sets the reference count to zero,
2577 even if @code{omp_target_associate_ptr} was invoked multiple times for
2578 for host pointer @code{ptr}. If applicable, the device memory needs
2579 to be freed by the user.
2581 If an associated device storage location for the @var{device_num} was
2582 found and has infinite reference count, the association is removed and
2583 zero is returned. In all other cases, nonzero (@code{EINVAL}) is returned
2584 and no other action is taken.
2586 Note that passing a host pointer where the association to the device pointer
2587 was established with the @code{declare target} directive yields undefined
2590 Running this routine in a @code{target} region except on the initial device
2594 @multitable @columnfractions .20 .80
2595 @item @emph{Prototype}: @tab @code{int omp_target_disassociate_ptr(const void *ptr,}
2596 @item @tab @code{ int device_num)}
2599 @item @emph{Fortran}:
2600 @multitable @columnfractions .20 .80
2601 @item @emph{Interface}: @tab @code{integer(c_int) function omp_target_disassociate_ptr(ptr, &}
2602 @item @tab @code{ device_num) bind(C)}
2603 @item @tab @code{use, intrinsic :: iso_c_binding, only: c_ptr, c_int}
2604 @item @tab @code{type(c_ptr), value :: ptr}
2605 @item @tab @code{integer(c_int), value :: device_num}
2608 @item @emph{See also}:
2609 @ref{omp_target_associate_ptr}
2611 @item @emph{Reference}:
2612 @uref{https://www.openmp.org, OpenMP specification v5.1}, Section 3.8.10
2617 @node omp_get_mapped_ptr
2618 @subsection @code{omp_get_mapped_ptr} -- Return device pointer to a host pointer
2620 @item @emph{Description}:
2621 If the device number is refers to the initial device or to a device with
2622 memory accessible from the host (shared memory), the @code{omp_get_mapped_ptr}
2623 routines returns the value of the passed @var{ptr}. Otherwise, if associated
2624 storage to the passed host pointer @var{ptr} exists on device associated with
2625 @var{device_num}, it returns that pointer. In all other cases and in cases of
2626 an error, a null pointer is returned.
2628 The association of storage location is established either via an explicit or
2629 implicit @code{map} clause, the @code{declare target} directive or the
2630 @code{omp_target_associate_ptr} routine.
2632 Running this routine in a @code{target} region except on the initial device
2636 @multitable @columnfractions .20 .80
2637 @item @emph{Prototype}: @tab @code{void *omp_get_mapped_ptr(const void *ptr, int device_num);}
2640 @item @emph{Fortran}:
2641 @multitable @columnfractions .20 .80
2642 @item @emph{Interface}: @tab @code{type(c_ptr) function omp_get_mapped_ptr(ptr, device_num) bind(C)}
2643 @item @tab @code{use, intrinsic :: iso_c_binding, only: c_ptr, c_int}
2644 @item @tab @code{type(c_ptr), value :: ptr}
2645 @item @tab @code{integer(c_int), value :: device_num}
2648 @item @emph{See also}:
2649 @ref{omp_target_associate_ptr}
2651 @item @emph{Reference}:
2652 @uref{https://www.openmp.org, OpenMP specification v5.1}, Section 3.8.11
2658 @section Lock Routines
2660 Initialize, set, test, unset and destroy simple and nested locks.
2661 The routines have C linkage and do not throw exceptions.
2664 * omp_init_lock:: Initialize simple lock
2665 * omp_init_nest_lock:: Initialize nested lock
2666 @c PR libgomp/109452
2667 @c * omp_init_lock_with_hint:: Initialize simple lock with sync hint
2668 @c * omp_init_nest_lock_with_hint:: Initialize nested lock with sync hint
2669 * omp_destroy_lock:: Destroy simple lock
2670 * omp_destroy_nest_lock:: Destroy nested lock
2671 * omp_set_lock:: Wait for and set simple lock
2672 * omp_set_nest_lock:: Wait for and set simple lock
2673 * omp_unset_lock:: Unset simple lock
2674 * omp_unset_nest_lock:: Unset nested lock
2675 * omp_test_lock:: Test and set simple lock if available
2676 * omp_test_nest_lock:: Test and set nested lock if available
2682 @subsection @code{omp_init_lock} -- Initialize simple lock
2684 @item @emph{Description}:
2685 Initialize a simple lock. After initialization, the lock is in
2689 @multitable @columnfractions .20 .80
2690 @item @emph{Prototype}: @tab @code{void omp_init_lock(omp_lock_t *lock);}
2693 @item @emph{Fortran}:
2694 @multitable @columnfractions .20 .80
2695 @item @emph{Interface}: @tab @code{subroutine omp_init_lock(svar)}
2696 @item @tab @code{integer(omp_lock_kind), intent(out) :: svar}
2699 @item @emph{See also}:
2700 @ref{omp_destroy_lock}
2702 @item @emph{Reference}:
2703 @uref{https://www.openmp.org, OpenMP specification v4.5}, Section 3.3.1.
2708 @node omp_init_nest_lock
2709 @subsection @code{omp_init_nest_lock} -- Initialize nested lock
2711 @item @emph{Description}:
2712 Initialize a nested lock. After initialization, the lock is in
2713 an unlocked state and the nesting count is set to zero.
2716 @multitable @columnfractions .20 .80
2717 @item @emph{Prototype}: @tab @code{void omp_init_nest_lock(omp_nest_lock_t *lock);}
2720 @item @emph{Fortran}:
2721 @multitable @columnfractions .20 .80
2722 @item @emph{Interface}: @tab @code{subroutine omp_init_nest_lock(nvar)}
2723 @item @tab @code{integer(omp_nest_lock_kind), intent(out) :: nvar}
2726 @item @emph{See also}:
2727 @ref{omp_destroy_nest_lock}
2729 @item @emph{Reference}:
2730 @uref{https://www.openmp.org, OpenMP specification v4.5}, Section 3.3.1.
2735 @node omp_destroy_lock
2736 @subsection @code{omp_destroy_lock} -- Destroy simple lock
2738 @item @emph{Description}:
2739 Destroy a simple lock. In order to be destroyed, a simple lock must be
2740 in the unlocked state.
2743 @multitable @columnfractions .20 .80
2744 @item @emph{Prototype}: @tab @code{void omp_destroy_lock(omp_lock_t *lock);}
2747 @item @emph{Fortran}:
2748 @multitable @columnfractions .20 .80
2749 @item @emph{Interface}: @tab @code{subroutine omp_destroy_lock(svar)}
2750 @item @tab @code{integer(omp_lock_kind), intent(inout) :: svar}
2753 @item @emph{See also}:
2756 @item @emph{Reference}:
2757 @uref{https://www.openmp.org, OpenMP specification v4.5}, Section 3.3.3.
2762 @node omp_destroy_nest_lock
2763 @subsection @code{omp_destroy_nest_lock} -- Destroy nested lock
2765 @item @emph{Description}:
2766 Destroy a nested lock. In order to be destroyed, a nested lock must be
2767 in the unlocked state and its nesting count must equal zero.
2770 @multitable @columnfractions .20 .80
2771 @item @emph{Prototype}: @tab @code{void omp_destroy_nest_lock(omp_nest_lock_t *);}
2774 @item @emph{Fortran}:
2775 @multitable @columnfractions .20 .80
2776 @item @emph{Interface}: @tab @code{subroutine omp_destroy_nest_lock(nvar)}
2777 @item @tab @code{integer(omp_nest_lock_kind), intent(inout) :: nvar}
2780 @item @emph{See also}:
2783 @item @emph{Reference}:
2784 @uref{https://www.openmp.org, OpenMP specification v4.5}, Section 3.3.3.
2790 @subsection @code{omp_set_lock} -- Wait for and set simple lock
2792 @item @emph{Description}:
2793 Before setting a simple lock, the lock variable must be initialized by
2794 @code{omp_init_lock}. The calling thread is blocked until the lock
2795 is available. If the lock is already held by the current thread,
2799 @multitable @columnfractions .20 .80
2800 @item @emph{Prototype}: @tab @code{void omp_set_lock(omp_lock_t *lock);}
2803 @item @emph{Fortran}:
2804 @multitable @columnfractions .20 .80
2805 @item @emph{Interface}: @tab @code{subroutine omp_set_lock(svar)}
2806 @item @tab @code{integer(omp_lock_kind), intent(inout) :: svar}
2809 @item @emph{See also}:
2810 @ref{omp_init_lock}, @ref{omp_test_lock}, @ref{omp_unset_lock}
2812 @item @emph{Reference}:
2813 @uref{https://www.openmp.org, OpenMP specification v4.5}, Section 3.3.4.
2818 @node omp_set_nest_lock
2819 @subsection @code{omp_set_nest_lock} -- Wait for and set nested lock
2821 @item @emph{Description}:
2822 Before setting a nested lock, the lock variable must be initialized by
2823 @code{omp_init_nest_lock}. The calling thread is blocked until the lock
2824 is available. If the lock is already held by the current thread, the
2825 nesting count for the lock is incremented.
2828 @multitable @columnfractions .20 .80
2829 @item @emph{Prototype}: @tab @code{void omp_set_nest_lock(omp_nest_lock_t *lock);}
2832 @item @emph{Fortran}:
2833 @multitable @columnfractions .20 .80
2834 @item @emph{Interface}: @tab @code{subroutine omp_set_nest_lock(nvar)}
2835 @item @tab @code{integer(omp_nest_lock_kind), intent(inout) :: nvar}
2838 @item @emph{See also}:
2839 @ref{omp_init_nest_lock}, @ref{omp_unset_nest_lock}
2841 @item @emph{Reference}:
2842 @uref{https://www.openmp.org, OpenMP specification v4.5}, Section 3.3.4.
2847 @node omp_unset_lock
2848 @subsection @code{omp_unset_lock} -- Unset simple lock
2850 @item @emph{Description}:
2851 A simple lock about to be unset must have been locked by @code{omp_set_lock}
2852 or @code{omp_test_lock} before. In addition, the lock must be held by the
2853 thread calling @code{omp_unset_lock}. Then, the lock becomes unlocked. If one
2854 or more threads attempted to set the lock before, one of them is chosen to,
2855 again, set the lock to itself.
2858 @multitable @columnfractions .20 .80
2859 @item @emph{Prototype}: @tab @code{void omp_unset_lock(omp_lock_t *lock);}
2862 @item @emph{Fortran}:
2863 @multitable @columnfractions .20 .80
2864 @item @emph{Interface}: @tab @code{subroutine omp_unset_lock(svar)}
2865 @item @tab @code{integer(omp_lock_kind), intent(inout) :: svar}
2868 @item @emph{See also}:
2869 @ref{omp_set_lock}, @ref{omp_test_lock}
2871 @item @emph{Reference}:
2872 @uref{https://www.openmp.org, OpenMP specification v4.5}, Section 3.3.5.
2877 @node omp_unset_nest_lock
2878 @subsection @code{omp_unset_nest_lock} -- Unset nested lock
2880 @item @emph{Description}:
2881 A nested lock about to be unset must have been locked by @code{omp_set_nested_lock}
2882 or @code{omp_test_nested_lock} before. In addition, the lock must be held by the
2883 thread calling @code{omp_unset_nested_lock}. If the nesting count drops to zero, the
2884 lock becomes unlocked. If one ore more threads attempted to set the lock before,
2885 one of them is chosen to, again, set the lock to itself.
2888 @multitable @columnfractions .20 .80
2889 @item @emph{Prototype}: @tab @code{void omp_unset_nest_lock(omp_nest_lock_t *lock);}
2892 @item @emph{Fortran}:
2893 @multitable @columnfractions .20 .80
2894 @item @emph{Interface}: @tab @code{subroutine omp_unset_nest_lock(nvar)}
2895 @item @tab @code{integer(omp_nest_lock_kind), intent(inout) :: nvar}
2898 @item @emph{See also}:
2899 @ref{omp_set_nest_lock}
2901 @item @emph{Reference}:
2902 @uref{https://www.openmp.org, OpenMP specification v4.5}, Section 3.3.5.
2908 @subsection @code{omp_test_lock} -- Test and set simple lock if available
2910 @item @emph{Description}:
2911 Before setting a simple lock, the lock variable must be initialized by
2912 @code{omp_init_lock}. Contrary to @code{omp_set_lock}, @code{omp_test_lock}
2913 does not block if the lock is not available. This function returns
2914 @code{true} upon success, @code{false} otherwise. Here, @code{true} and
2915 @code{false} represent their language-specific counterparts.
2918 @multitable @columnfractions .20 .80
2919 @item @emph{Prototype}: @tab @code{int omp_test_lock(omp_lock_t *lock);}
2922 @item @emph{Fortran}:
2923 @multitable @columnfractions .20 .80
2924 @item @emph{Interface}: @tab @code{logical function omp_test_lock(svar)}
2925 @item @tab @code{integer(omp_lock_kind), intent(inout) :: svar}
2928 @item @emph{See also}:
2929 @ref{omp_init_lock}, @ref{omp_set_lock}, @ref{omp_set_lock}
2931 @item @emph{Reference}:
2932 @uref{https://www.openmp.org, OpenMP specification v4.5}, Section 3.3.6.
2937 @node omp_test_nest_lock
2938 @subsection @code{omp_test_nest_lock} -- Test and set nested lock if available
2940 @item @emph{Description}:
2941 Before setting a nested lock, the lock variable must be initialized by
2942 @code{omp_init_nest_lock}. Contrary to @code{omp_set_nest_lock},
2943 @code{omp_test_nest_lock} does not block if the lock is not available.
2944 If the lock is already held by the current thread, the new nesting count
2945 is returned. Otherwise, the return value equals zero.
2948 @multitable @columnfractions .20 .80
2949 @item @emph{Prototype}: @tab @code{int omp_test_nest_lock(omp_nest_lock_t *lock);}
2952 @item @emph{Fortran}:
2953 @multitable @columnfractions .20 .80
2954 @item @emph{Interface}: @tab @code{logical function omp_test_nest_lock(nvar)}
2955 @item @tab @code{integer(omp_nest_lock_kind), intent(inout) :: nvar}
2959 @item @emph{See also}:
2960 @ref{omp_init_lock}, @ref{omp_set_lock}, @ref{omp_set_lock}
2962 @item @emph{Reference}:
2963 @uref{https://www.openmp.org, OpenMP specification v4.5}, Section 3.3.6.
2968 @node Timing Routines
2969 @section Timing Routines
2971 Portable, thread-based, wall clock timer.
2972 The routines have C linkage and do not throw exceptions.
2975 * omp_get_wtick:: Get timer precision.
2976 * omp_get_wtime:: Elapsed wall clock time.
2982 @subsection @code{omp_get_wtick} -- Get timer precision
2984 @item @emph{Description}:
2985 Gets the timer precision, i.e., the number of seconds between two
2986 successive clock ticks.
2989 @multitable @columnfractions .20 .80
2990 @item @emph{Prototype}: @tab @code{double omp_get_wtick(void);}
2993 @item @emph{Fortran}:
2994 @multitable @columnfractions .20 .80
2995 @item @emph{Interface}: @tab @code{double precision function omp_get_wtick()}
2998 @item @emph{See also}:
3001 @item @emph{Reference}:
3002 @uref{https://www.openmp.org, OpenMP specification v4.5}, Section 3.4.2.
3008 @subsection @code{omp_get_wtime} -- Elapsed wall clock time
3010 @item @emph{Description}:
3011 Elapsed wall clock time in seconds. The time is measured per thread, no
3012 guarantee can be made that two distinct threads measure the same time.
3013 Time is measured from some "time in the past", which is an arbitrary time
3014 guaranteed not to change during the execution of the program.
3017 @multitable @columnfractions .20 .80
3018 @item @emph{Prototype}: @tab @code{double omp_get_wtime(void);}
3021 @item @emph{Fortran}:
3022 @multitable @columnfractions .20 .80
3023 @item @emph{Interface}: @tab @code{double precision function omp_get_wtime()}
3026 @item @emph{See also}:
3029 @item @emph{Reference}:
3030 @uref{https://www.openmp.org, OpenMP specification v4.5}, Section 3.4.1.
3036 @section Event Routine
3038 Support for event objects.
3039 The routine has C linkage and do not throw exceptions.
3042 * omp_fulfill_event:: Fulfill and destroy an OpenMP event.
3047 @node omp_fulfill_event
3048 @subsection @code{omp_fulfill_event} -- Fulfill and destroy an OpenMP event
3050 @item @emph{Description}:
3051 Fulfill the event associated with the event handle argument. Currently, it
3052 is only used to fulfill events generated by detach clauses on task
3053 constructs - the effect of fulfilling the event is to allow the task to
3056 The result of calling @code{omp_fulfill_event} with an event handle other
3057 than that generated by a detach clause is undefined. Calling it with an
3058 event handle that has already been fulfilled is also undefined.
3061 @multitable @columnfractions .20 .80
3062 @item @emph{Prototype}: @tab @code{void omp_fulfill_event(omp_event_handle_t event);}
3065 @item @emph{Fortran}:
3066 @multitable @columnfractions .20 .80
3067 @item @emph{Interface}: @tab @code{subroutine omp_fulfill_event(event)}
3068 @item @tab @code{integer (kind=omp_event_handle_kind) :: event}
3071 @item @emph{Reference}:
3072 @uref{https://www.openmp.org, OpenMP specification v5.0}, Section 3.5.1.
3077 @node Interoperability Routines
3078 @section Interoperability Routines
3080 Routines to obtain properties from an object of OpenMP interop type.
3081 They have C linkage and do not throw exceptions.
3084 * omp_get_num_interop_properties:: Get the number of implementation-specific properties
3085 * omp_get_interop_int:: Obtain integer-valued interoperability property
3086 * omp_get_interop_ptr:: Obtain pointer-valued interoperability property
3087 * omp_get_interop_str:: Obtain string-valued interoperability property
3088 * omp_get_interop_name:: Obtain the name of an interop_property value as string
3089 * omp_get_interop_type_desc:: Obtain type and description to an interop_property
3090 * omp_get_interop_rc_desc:: Obtain error string to an interop_rc error code
3095 @node omp_get_num_interop_properties
3096 @subsection @code{omp_get_num_interop_properties} -- Get the number of implementation-specific properties
3098 @item @emph{Description}:
3099 The @code{omp_get_num_interop_properties} function returns the number of
3100 implementation-defined interoperability properties available for the passed
3101 @var{interop}, extending the OpenMP-defined properties. The available OpenMP
3102 interop_property-type values range from @code{omp_ipr_first} to the value
3103 returned by @code{omp_get_num_interop_properties} minus one.
3105 No implementation-defined properties are currently defined in GCC.
3107 @c Implementation remark: In GCC, the Fortran interface differs from the one shown
3108 @c below: the function has C binding, @var{interop} is passed by value and an
3109 @c integer of @code{c_int} kind is returned, which permits use of the same ABI as
3110 @c the C function. This does not affect the usage of the function when GCC's
3111 @c @code{omp_lib} module or @code{omp_lib.h} header is used.
3114 @multitable @columnfractions .20 .80
3115 @item @emph{Prototype}: @tab @code{int omp_get_num_interop_properties(const omp_interop_t interop)}
3118 @item @emph{Fortran}:
3119 @multitable @columnfractions .20 .80
3120 @item @emph{Interface}: @tab @code{integer function omp_get_num_interop_properties(interop)}
3121 @item @tab @code{integer(omp_interop_kind), intent(in) :: interop}
3124 @item @emph{See also}:
3125 @ref{omp_get_interop_name}, @ref{omp_get_interop_type_desc}
3127 @item @emph{Reference}:
3128 @uref{https://www.openmp.org, OpenMP specification v5.1}, Section 3.12.1,
3129 @uref{https://www.openmp.org, OpenMP specification v6.0}, Section 26.1
3134 @node omp_get_interop_int
3135 @subsection @code{omp_get_interop_int} -- Obtain integer-valued interoperability property
3137 @item @emph{Description}:
3138 The @code{omp_get_interop_int} function returns the integer value associated
3139 with the @var{property_id} interoperability property of the passed @var{interop}
3140 object. The @var{ret_code} argument is optional, i.e. it can be omitted in C++
3141 and Fortran or used with @code{NULL} as argument in C and C++. If successful,
3142 @var{ret_code} (if present) is set to @code{omp_irc_success}.
3144 In GCC, the effect of running this routine in a @code{target} region that is not
3145 the initial device is unspecified.
3147 GCC implements the OpenMP 6.0 version of this function for C and C++, which is not
3148 compatible with its type signature in previous versions of the OpenMP specification.
3149 In older versions, the type @code{int*} was used for the @var{ret_code} argument
3150 in place of a pointer to the enumerated type @code{omp_interop_rc_t}.
3152 @c Implementation remark: In GCC, the Fortran interface differs from the one shown
3153 @c below: the function has C binding and @var{interop} and @var{property_id} are
3154 @c passed by value, which permits use of the same ABI as the C function. This does
3155 @c not affect the usage of the function when GCC's @code{omp_lib} module or
3156 @c @code{omp_lib.h} header is used.
3159 @multitable @columnfractions .20 .80
3160 @item @emph{Prototype}: @tab @code{omp_intptr_t omp_get_interop_int(const omp_interop_t interop,
3161 omp_interop_property_t property_id, omp_interop_rc_t *ret_code)}
3164 @item @emph{Fortran}:
3165 @multitable @columnfractions .20 .80
3166 @item @emph{Interface}: @tab @code{integer(c_intptr_t) function omp_get_interop_int(interop,
3167 property_id, ret_code)}
3168 @item @tab @code{use, intrinsic :: iso_c_binding, only : c_intptr_t}
3169 @item @tab @code{integer(omp_interop_kind), intent(in) :: interop}
3170 @item @tab @code{integer(omp_interop_property_kind) property_id}
3171 @item @tab @code{integer(omp_interop_rc_kind), optional, intent(out) :: ret_code}
3174 @item @emph{See also}:
3175 @ref{omp_get_interop_ptr}, @ref{omp_get_interop_str}, @ref{omp_get_interop_rc_desc},
3176 @ref{Offload-Target Specifics}
3178 @item @emph{Reference}:
3179 @uref{https://www.openmp.org, OpenMP specification v5.1}, Section 3.12.2,
3180 @uref{https://www.openmp.org, OpenMP specification v6.0}, Section 26.2
3185 @node omp_get_interop_ptr
3186 @subsection @code{omp_get_interop_ptr} -- Obtain pointer-valued interoperability property
3188 @item @emph{Description}:
3189 The @code{omp_get_interop_int} function returns the pointer value associated with
3190 the @var{property_id} interoperability property of the passed @var{interop}
3191 object. The @var{ret_code} argument is optional, i.e. it can be omitted in C++
3192 and Fortran or used with @code{NULL} as argument in C and C++. If successful,
3193 @var{ret_code} (if present) is set to @code{omp_irc_success}.
3195 In GCC, the effect of running this routine in a @code{target} region that is not
3196 the initial device is unspecified.
3198 GCC implements the OpenMP 6.0 version of this function for C and C++, which is not
3199 compatible with its type signature in previous versions of the OpenMP specification.
3200 In older versions, the type @code{int*} was used for the @var{ret_code} argument
3201 in place of a pointer to the enumerated type @code{omp_interop_rc_t}.
3203 @c Implementation remark: In GCC, the Fortran interface differs from the one shown
3204 @c below: the function has C binding and @var{interop} and @var{property_id} are
3205 @c passed by value, which permits use of the same ABI as the C function. This does
3206 @c not affect the usage of the function when GCC's @code{omp_lib} module or
3207 @c @code{omp_lib.h} header is used.
3210 @multitable @columnfractions .20 .80
3211 @item @emph{Prototype}: @tab @code{void *omp_get_interop_ptr(const omp_interop_t interop,
3212 omp_interop_property_t property_id, omp_interop_rc_t *ret_code)}
3215 @item @emph{Fortran}:
3216 @multitable @columnfractions .20 .80
3217 @item @emph{Interface}: @tab @code{type(c_ptr) function omp_get_interop_int(interop,
3218 property_id, ret_code)}
3219 @item @tab @code{use, intrinsic :: iso_c_binding, only : c_ptr}
3220 @item @tab @code{integer(omp_interop_kind), intent(in) :: interop}
3221 @item @tab @code{integer(omp_interop_property_kind) property_id}
3222 @item @tab @code{integer(omp_interop_rc_kind), optional, intent(out) :: ret_code}
3225 @item @emph{See also}:
3226 @ref{omp_get_interop_int}, @ref{omp_get_interop_str}, @ref{omp_get_interop_rc_desc},
3227 @ref{Offload-Target Specifics}
3229 @item @emph{Reference}:
3230 @uref{https://www.openmp.org, OpenMP specification v5.1}, Section 3.12.3,
3231 @uref{https://www.openmp.org, OpenMP specification v6.0}, Section 26.3
3236 @node omp_get_interop_str
3237 @subsection @code{omp_get_interop_str} -- Obtain string-valued interoperability property
3239 @item @emph{Description}:
3240 The @code{omp_get_interop_str} function returns the string value associated with
3241 the @var{property_id} interoperability property of the passed @var{interop}
3242 object. The @var{ret_code} argument is optional, i.e. it can be omitted in C++
3243 and Fortran or used with @code{NULL} as argument in C and C++. If successful,
3244 @var{ret_code} (if present) is set to @code{omp_irc_success}.
3246 In GCC, the effect of running this routine in a @code{target} region that is not
3247 the initial device is unspecified.
3249 GCC implements the OpenMP 6.0 version of this function for C and C++, which is not
3250 compatible with its type signature in previous versions of the OpenMP specification.
3251 In older versions, the type @code{int*} was used for the @var{ret_code} argument
3252 in place of a pointer to the enumerated type @code{omp_interop_rc_t}.
3254 @c Implementation remark: In GCC, the Fortran interface differs from the one shown
3255 @c below: @var{interop} and @var{property_id} are passed by value. This does not
3256 @c affect the usage of the function when GCC's @code{omp_lib} module or
3257 @c @code{omp_lib.h} header is used.
3260 @multitable @columnfractions .20 .80
3261 @item @emph{Prototype}: @tab @code{const char *omp_get_interop_str(const omp_interop_t interop,
3262 omp_interop_property_t property_id, omp_interop_rc_t *ret_code)}
3265 @item @emph{Fortran}:
3266 @multitable @columnfractions .20 .80
3267 @item @emph{Interface}: @tab @code{character(:) function omp_get_interop_str(interop,
3268 property_id, ret_code)}
3269 @item @tab @code{pointer :: omp_get_interop_str}
3270 @item @tab @code{integer(omp_interop_kind), intent(in) :: interop}
3271 @item @tab @code{integer(omp_interop_property_kind) property_id}
3272 @item @tab @code{integer(omp_interop_rc_kind), optional, intent(out) :: ret_code}
3275 @item @emph{See also}:
3276 @ref{omp_get_interop_int}, @ref{omp_get_interop_ptr}, @ref{omp_get_interop_rc_desc},
3277 @ref{Offload-Target Specifics}
3279 @item @emph{Reference}:
3280 @uref{https://www.openmp.org, OpenMP specification v5.1}, Section 3.12.4,
3281 @uref{https://www.openmp.org, OpenMP specification v6.0}, Section 26.4
3286 @node omp_get_interop_name
3287 @subsection @code{omp_get_interop_name} -- Obtain the name of an @code{interop_property} value as string
3289 @item @emph{Description}:
3290 The @code{omp_get_interop_name} function returns the name of the property
3291 itself as string; for the properties specified by the OpenMP specification,
3292 the name matches the name of the named constant with the @samp{omp_ipr_}
3295 @c Implementation remark: In GCC, the Fortran interface differs from the one shown
3296 @c below: @var{interop} and @var{property_id} are passed by value. This does not
3297 @c affect the usage of the function when GCC's @code{omp_lib} module or
3298 @c @code{omp_lib.h} header is used.
3301 @multitable @columnfractions .20 .80
3302 @item @emph{Prototype}: @tab @code{const char *omp_get_interop_name(const omp_interop_t interop,
3303 omp_interop_property_t property_id)}
3306 @item @emph{Fortran}:
3307 @multitable @columnfractions .20 .80
3308 @item @emph{Interface}: @tab @code{character(:) function omp_get_interop_name(interop,
3310 @item @tab @code{pointer :: omp_get_interop_name}
3311 @item @tab @code{integer(omp_interop_kind), intent(in) :: interop}
3312 @item @tab @code{integer(omp_interop_property_kind) property_id}
3315 @item @emph{See also}:
3316 @ref{omp_get_num_interop_properties}, @ref{omp_get_interop_type_desc}
3318 @item @emph{Reference}:
3319 @uref{https://www.openmp.org, OpenMP specification v5.1}, Section 3.12.5,
3320 @uref{https://www.openmp.org, OpenMP specification v6.0}, Section 26.5
3325 @node omp_get_interop_type_desc
3326 @subsection @code{omp_get_interop_type_desc} -- Obtain type and description to an @code{interop_property}
3328 @item @emph{Description}:
3329 The @code{omp_get_interop_type_desc} function returns a string that describes in
3330 human-readable form the data type associated with the @var{property_id}
3331 interoperability property of the passed @var{interop} object.
3333 In GCC, this function returns the name of the C/C++ data type for this property
3334 or @samp{N/A} if this property is not available for the given foreign runtime.
3335 If @var{interop} is @code{omp_interop_none} or for invalid property values,
3336 a null pointer is returned. The effect of running this routine in a
3337 @code{target} region that is not the initial device is unspecified.
3339 @c Implementation remark: In GCC, the Fortran interface differs from the one shown
3340 @c below: @var{interop} and @var{property_id} are passed by value. This does not
3341 @c affect the usage of the function when GCC's @code{omp_lib} module or
3342 @c @code{omp_lib.h} header is used.
3345 @multitable @columnfractions .20 .80
3346 @item @emph{Prototype}: @tab @code{const char *omp_get_interop_type_desc(const omp_interop_t interop,
3347 omp_interop_property_t property_id)}
3350 @item @emph{Fortran}:
3351 @multitable @columnfractions .20 .80
3352 @item @emph{Interface}: @tab @code{character(:) function omp_get_interop_type_desc(interop,
3354 @item @tab @code{pointer :: omp_get_interop_type_desc}
3355 @item @tab @code{integer(omp_interop_kind), intent(in) :: interop}
3356 @item @tab @code{integer(omp_interop_property_kind) property_id}
3359 @item @emph{See also}:
3360 @ref{omp_get_num_interop_properties}, @ref{omp_get_interop_name},
3361 @ref{Offload-Target Specifics}
3363 @item @emph{Reference}:
3364 @uref{https://www.openmp.org, OpenMP specification v5.1}, Section 3.12.6,
3365 @uref{https://www.openmp.org, OpenMP specification v6.0}, Section 26.6
3370 @node omp_get_interop_rc_desc
3371 @subsection @code{omp_get_interop_rc_desc} -- Obtain error string to an @code{interop_rc} error code
3373 @item @emph{Description}:
3374 The @code{omp_get_interop_rc_desc} function returns a string value describing
3375 the @var{ret_code} in human-readable form.
3377 The behavior is unspecified if value of @var{ret_code} was not set by an
3378 interoperability routine invoked for @var{interop}.
3380 GCC implements the OpenMP 6.0 version of this function for C and C++, which is not
3381 compatible with its type signature in previous versions of the OpenMP specification.
3382 In older versions, the type @code{int} was used for the @var{ret_code} argument
3383 in place of the enumerated type @code{omp_interop_rc_t}.
3386 @multitable @columnfractions .20 .80
3387 @item @emph{Prototype}: @tab @code{const char *omp_get_interop_rc_desc(const omp_interop_t interop,
3388 omp_interop_rc_t ret_code)}
3391 @item @emph{Fortran}:
3392 @multitable @columnfractions .20 .80
3393 @item @emph{Interface}: @tab @code{character(:) function omp_get_interop_rc_desc(interop,
3394 property_id, ret_code)}
3395 @item @tab @code{pointer :: omp_get_interop_rc_desc}
3396 @item @tab @code{integer(omp_interop_kind), intent(in) :: interop}
3397 @item @tab @code{integer (omp_interop_rc_kind) ret_code}
3400 @item @emph{Reference}:
3401 @uref{https://www.openmp.org, OpenMP specification v5.1}, Section 3.12.7,
3402 @uref{https://www.openmp.org, OpenMP specification v6.0}, Section 26.7
3407 @node Memory Management Routines
3408 @section Memory Management Routines
3410 Routines to manage and allocate memory on the current device.
3411 They have C linkage and do not throw exceptions.
3414 @c * omp_get_devices_memspace:: <fixme>/TR13
3415 @c * omp_get_device_memspace:: <fixme>/TR13
3416 @c * omp_get_devices_and_host_memspace:: <fixme>/TR13
3417 @c * omp_get_device_and_host_memspace:: <fixme>/TR13
3418 @c * omp_get_devices_all_memspace:: <fixme>/TR13
3419 @c * omp_get_memspace_num_resources:: <fixme>/TR11
3420 @c * omp_get_memspace_pagesize:: <fixme>/TR13
3421 @c * omp_get_submemspace:: <fixme>/TR11
3422 @c * omp_init_mempartitioner:: <fixme>/TR13
3423 @c * omp_destroy_mempartitioner:: <fixme>/TR13
3424 @c * omp_init_mempartition:: <fixme>/TR13
3425 @c * omp_destroy_mempartition:: <fixme>/TR13
3426 @c * omp_mempartition_set_part:: <fixme>/TR13
3427 @c * omp_mempartition_get_user_data:: <fixme>/TR13
3428 * omp_init_allocator:: Create an allocator
3429 * omp_destroy_allocator:: Destroy an allocator
3430 @c * omp_get_devices_allocator:: <fixme>/TR13
3431 @c * omp_get_device_allocator:: <fixme>/TR13
3432 @c * omp_get_devices_and_host_allocator:: <fixme>/TR13
3433 @c * omp_get_device_and_host_allocator:: <fixme>/TR13
3434 @c * omp_get_devices_all_allocator:: <fixme>/TR13
3435 * omp_set_default_allocator:: Set the default allocator
3436 * omp_get_default_allocator:: Get the default allocator
3437 * omp_alloc:: Memory allocation with an allocator
3438 * omp_aligned_alloc:: Memory allocation with an allocator and alignment
3439 * omp_free:: Freeing memory allocated with OpenMP routines
3440 * omp_calloc:: Allocate nullified memory with an allocator
3441 * omp_aligned_calloc:: Allocate nullified aligned memory with an allocator
3442 * omp_realloc:: Reallocate memory allocated with OpenMP routines
3447 @node omp_init_allocator
3448 @subsection @code{omp_init_allocator} -- Create an allocator
3450 @item @emph{Description}:
3451 Create an allocator that uses the specified memory space and has the specified
3452 traits; if an allocator that fulfills the requirements cannot be created,
3453 @code{omp_null_allocator} is returned.
3455 The predefined memory spaces and available traits can be found at
3456 @ref{Memory allocation}, where the trait names have to be prefixed by
3457 @code{omp_atk_} (e.g. @code{omp_atk_pinned}) and the named trait values by
3458 @code{omp_atv_} (e.g. @code{omp_atv_true}); additionally, @code{omp_atv_default}
3459 may be used as trait value to specify that the default value should be used.
3462 @multitable @columnfractions .20 .80
3463 @item @emph{Prototype}: @tab @code{omp_allocator_handle_t omp_init_allocator(}
3464 @item @tab @code{ omp_memspace_handle_t memspace,}
3465 @item @tab @code{ int ntraits,}
3466 @item @tab @code{ const omp_alloctrait_t traits[]);}
3469 @item @emph{Fortran}:
3470 @multitable @columnfractions .20 .80
3471 @item @emph{Interface}: @tab @code{function omp_init_allocator(memspace, ntraits, traits)}
3472 @item @tab @code{integer (omp_allocator_handle_kind) :: omp_init_allocator}
3473 @item @tab @code{integer (omp_memspace_handle_kind), intent(in) :: memspace}
3474 @item @tab @code{integer, intent(in) :: ntraits}
3475 @item @tab @code{type (omp_alloctrait), intent(in) :: traits(*)}
3478 @item @emph{See also}:
3479 @ref{Memory allocation}, @ref{OMP_ALLOCATOR}, @ref{omp_destroy_allocator}
3481 @item @emph{Reference}:
3482 @uref{https://www.openmp.org, OpenMP specification v5.0}, Section 3.7.2
3487 @node omp_destroy_allocator
3488 @subsection @code{omp_destroy_allocator} -- Destroy an allocator
3490 @item @emph{Description}:
3491 Releases all resources used by a memory allocator, which must not represent
3492 a predefined memory allocator. Accessing memory after its allocator has been
3493 destroyed has unspecified behavior. Passing @code{omp_null_allocator} to the
3494 routine is permitted but has no effect.
3498 @multitable @columnfractions .20 .80
3499 @item @emph{Prototype}: @tab @code{void omp_destroy_allocator (omp_allocator_handle_t allocator);}
3502 @item @emph{Fortran}:
3503 @multitable @columnfractions .20 .80
3504 @item @emph{Interface}: @tab @code{subroutine omp_destroy_allocator(allocator)}
3505 @item @tab @code{integer (omp_allocator_handle_kind), intent(in) :: allocator}
3508 @item @emph{See also}:
3509 @ref{omp_init_allocator}
3511 @item @emph{Reference}:
3512 @uref{https://www.openmp.org, OpenMP specification v5.0}, Section 3.7.3
3517 @node omp_set_default_allocator
3518 @subsection @code{omp_set_default_allocator} -- Set the default allocator
3520 @item @emph{Description}:
3521 Sets the default allocator that is used when no allocator has been specified
3522 in the @code{allocate} or @code{allocator} clause or if an OpenMP memory
3523 routine is invoked with the @code{omp_null_allocator} allocator.
3526 @multitable @columnfractions .20 .80
3527 @item @emph{Prototype}: @tab @code{void omp_set_default_allocator(omp_allocator_handle_t allocator);}
3530 @item @emph{Fortran}:
3531 @multitable @columnfractions .20 .80
3532 @item @emph{Interface}: @tab @code{subroutine omp_set_default_allocator(allocator)}
3533 @item @tab @code{integer (omp_allocator_handle_kind), intent(in) :: allocator}
3536 @item @emph{See also}:
3537 @ref{omp_get_default_allocator}, @ref{omp_init_allocator}, @ref{OMP_ALLOCATOR},
3538 @ref{Memory allocation}
3540 @item @emph{Reference}:
3541 @uref{https://www.openmp.org, OpenMP specification v5.0}, Section 3.7.4
3546 @node omp_get_default_allocator
3547 @subsection @code{omp_get_default_allocator} -- Get the default allocator
3549 @item @emph{Description}:
3550 The routine returns the default allocator that is used when no allocator has
3551 been specified in the @code{allocate} or @code{allocator} clause or if an
3552 OpenMP memory routine is invoked with the @code{omp_null_allocator} allocator.
3555 @multitable @columnfractions .20 .80
3556 @item @emph{Prototype}: @tab @code{omp_allocator_handle_t omp_get_default_allocator();}
3559 @item @emph{Fortran}:
3560 @multitable @columnfractions .20 .80
3561 @item @emph{Interface}: @tab @code{function omp_get_default_allocator()}
3562 @item @tab @code{integer (omp_allocator_handle_kind) :: omp_get_default_allocator}
3565 @item @emph{See also}:
3566 @ref{omp_set_default_allocator}, @ref{OMP_ALLOCATOR}
3568 @item @emph{Reference}:
3569 @uref{https://www.openmp.org, OpenMP specification v5.0}, Section 3.7.5
3575 @subsection @code{omp_alloc} -- Memory allocation with an allocator
3577 @item @emph{Description}:
3578 Allocate memory with the specified allocator, which can either be a predefined
3579 allocator, an allocator handle or @code{omp_null_allocator}. If the allocators
3580 is @code{omp_null_allocator}, the allocator specified by the
3581 @var{def-allocator-var} ICV is used. @var{size} must be a nonnegative number
3582 denoting the number of bytes to be allocated; if @var{size} is zero,
3583 @code{omp_alloc} will return a null pointer. If successful, a pointer to the
3584 allocated memory is returned, otherwise the @code{fallback} trait of the
3585 allocator determines the behavior. The content of the allocated memory is
3588 In @code{target} regions, either the @code{dynamic_allocators} clause must
3589 appear on a @code{requires} directive in the same compilation unit -- or the
3590 @var{allocator} argument may only be a constant expression with the value of
3591 one of the predefined allocators and may not be @code{omp_null_allocator}.
3593 Memory allocated by @code{omp_alloc} must be freed using @code{omp_free}.
3596 @multitable @columnfractions .20 .80
3597 @item @emph{Prototype}: @tab @code{void* omp_alloc(size_t size,}
3598 @item @tab @code{ omp_allocator_handle_t allocator)}
3602 @multitable @columnfractions .20 .80
3603 @item @emph{Prototype}: @tab @code{void* omp_alloc(size_t size,}
3604 @item @tab @code{ omp_allocator_handle_t allocator=omp_null_allocator)}
3607 @item @emph{Fortran}:
3608 @multitable @columnfractions .20 .80
3609 @item @emph{Interface}: @tab @code{type(c_ptr) function omp_alloc(size, allocator) bind(C)}
3610 @item @tab @code{use, intrinsic :: iso_c_binding, only : c_ptr, c_size_t}
3611 @item @tab @code{integer (c_size_t), value :: size}
3612 @item @tab @code{integer (omp_allocator_handle_kind), value :: allocator}
3615 @item @emph{See also}:
3616 @ref{OMP_ALLOCATOR}, @ref{Memory allocation}, @ref{omp_set_default_allocator},
3617 @ref{omp_free}, @ref{omp_init_allocator}
3619 @item @emph{Reference}:
3620 @uref{https://www.openmp.org, OpenMP specification v5.0}, Section 3.7.6
3625 @node omp_aligned_alloc
3626 @subsection @code{omp_aligned_alloc} -- Memory allocation with an allocator and alignment
3628 @item @emph{Description}:
3629 Allocate memory with the specified allocator, which can either be a predefined
3630 allocator, an allocator handle or @code{omp_null_allocator}. If the allocators
3631 is @code{omp_null_allocator}, the allocator specified by the
3632 @var{def-allocator-var} ICV is used. @var{alignment} must be a positive power
3633 of two and @var{size} must be a nonnegative number that is a multiple of the
3634 alignment and denotes the number of bytes to be allocated; if @var{size} is
3635 zero, @code{omp_aligned_alloc} will return a null pointer. The alignment will
3636 be at least the maximal value required by @code{alignment} trait of the
3637 allocator and the value of the passed @var{alignment} argument. If successful,
3638 a pointer to the allocated memory is returned, otherwise the @code{fallback}
3639 trait of the allocator determines the behavior. The content of the allocated
3640 memory is unspecified.
3642 In @code{target} regions, either the @code{dynamic_allocators} clause must
3643 appear on a @code{requires} directive in the same compilation unit -- or the
3644 @var{allocator} argument may only be a constant expression with the value of
3645 one of the predefined allocators and may not be @code{omp_null_allocator}.
3647 Memory allocated by @code{omp_aligned_alloc} must be freed using
3651 @multitable @columnfractions .20 .80
3652 @item @emph{Prototype}: @tab @code{void* omp_aligned_alloc(size_t alignment,}
3653 @item @tab @code{ size_t size,}
3654 @item @tab @code{ omp_allocator_handle_t allocator)}
3658 @multitable @columnfractions .20 .80
3659 @item @emph{Prototype}: @tab @code{void* omp_aligned_alloc(size_t alignment,}
3660 @item @tab @code{ size_t size,}
3661 @item @tab @code{ omp_allocator_handle_t allocator=omp_null_allocator)}
3664 @item @emph{Fortran}:
3665 @multitable @columnfractions .20 .80
3666 @item @emph{Interface}: @tab @code{type(c_ptr) function omp_aligned_alloc(alignment, size, allocator) bind(C)}
3667 @item @tab @code{use, intrinsic :: iso_c_binding, only : c_ptr, c_size_t}
3668 @item @tab @code{integer (c_size_t), value :: alignment, size}
3669 @item @tab @code{integer (omp_allocator_handle_kind), value :: allocator}
3672 @item @emph{See also}:
3673 @ref{OMP_ALLOCATOR}, @ref{Memory allocation}, @ref{omp_set_default_allocator},
3674 @ref{omp_free}, @ref{omp_init_allocator}
3676 @item @emph{Reference}:
3677 @uref{https://www.openmp.org, OpenMP specification v5.1}, Section 3.13.6
3683 @subsection @code{omp_free} -- Freeing memory allocated with OpenMP routines
3685 @item @emph{Description}:
3686 The @code{omp_free} routine deallocates memory previously allocated by an
3687 OpenMP memory-management routine. The @var{ptr} argument must point to such
3688 memory or be a null pointer; if it is a null pointer, no operation is
3689 performed. If specified, the @var{allocator} argument must be either the
3690 memory allocator that was used for the allocation or @code{omp_null_allocator};
3691 if it is @code{omp_null_allocator}, the implementation will determine the value
3694 Calling @code{omp_free} invokes undefined behavior if the memory
3695 was already deallocated or when the used allocator has already been destroyed.
3698 @multitable @columnfractions .20 .80
3699 @item @emph{Prototype}: @tab @code{void omp_free(void *ptr,}
3700 @item @tab @code{ omp_allocator_handle_t allocator)}
3704 @multitable @columnfractions .20 .80
3705 @item @emph{Prototype}: @tab @code{void omp_free(void *ptr,}
3706 @item @tab @code{ omp_allocator_handle_t allocator=omp_null_allocator)}
3709 @item @emph{Fortran}:
3710 @multitable @columnfractions .20 .80
3711 @item @emph{Interface}: @tab @code{subroutine omp_free(ptr, allocator) bind(C)}
3712 @item @tab @code{use, intrinsic :: iso_c_binding, only : c_ptr}
3713 @item @tab @code{type (c_ptr), value :: ptr}
3714 @item @tab @code{integer (omp_allocator_handle_kind), value :: allocator}
3717 @item @emph{See also}:
3718 @ref{omp_alloc}, @ref{omp_aligned_alloc}, @ref{omp_calloc},
3719 @ref{omp_aligned_calloc}, @ref{omp_realloc}
3721 @item @emph{Reference}:
3722 @uref{https://www.openmp.org, OpenMP specification v5.0}, Section 3.7.7
3728 @subsection @code{omp_calloc} -- Allocate nullified memory with an allocator
3730 @item @emph{Description}:
3731 Allocate zero-initialized memory with the specified allocator, which can either
3732 be a predefined allocator, an allocator handle or @code{omp_null_allocator}. If
3733 the allocators is @code{omp_null_allocator}, the allocator specified by the
3734 @var{def-allocator-var} ICV is used. The to-be allocated memory is for an
3735 array with @var{nmemb} elements, each having a size of @var{size} bytes. Both
3736 @var{nmemb} and @var{size} must be nonnegative numbers; if either of them is
3737 zero, @code{omp_calloc} will return a null pointer. If successful, a pointer to
3738 the zero-initialized allocated memory is returned, otherwise the @code{fallback}
3739 trait of the allocator determines the behavior.
3741 In @code{target} regions, either the @code{dynamic_allocators} clause must
3742 appear on a @code{requires} directive in the same compilation unit -- or the
3743 @var{allocator} argument may only be a constant expression with the value of
3744 one of the predefined allocators and may not be @code{omp_null_allocator}.
3746 Memory allocated by @code{omp_calloc} must be freed using @code{omp_free}.
3749 @multitable @columnfractions .20 .80
3750 @item @emph{Prototype}: @tab @code{void* omp_calloc(size_t nmemb, size_t size,}
3751 @item @tab @code{ omp_allocator_handle_t allocator)}
3755 @multitable @columnfractions .20 .80
3756 @item @emph{Prototype}: @tab @code{void* omp_calloc(size_t nmemb, size_t size,}
3757 @item @tab @code{ omp_allocator_handle_t allocator=omp_null_allocator)}
3760 @item @emph{Fortran}:
3761 @multitable @columnfractions .20 .80
3762 @item @emph{Interface}: @tab @code{type(c_ptr) function omp_calloc(nmemb, size, allocator) bind(C)}
3763 @item @tab @code{use, intrinsic :: iso_c_binding, only : c_ptr, c_size_t}
3764 @item @tab @code{integer (c_size_t), value :: nmemb, size}
3765 @item @tab @code{integer (omp_allocator_handle_kind), value :: allocator}
3768 @item @emph{See also}:
3769 @ref{OMP_ALLOCATOR}, @ref{Memory allocation}, @ref{omp_set_default_allocator},
3770 @ref{omp_free}, @ref{omp_init_allocator}
3772 @item @emph{Reference}:
3773 @uref{https://www.openmp.org, OpenMP specification v5.1}, Section 3.13.8
3778 @node omp_aligned_calloc
3779 @subsection @code{omp_aligned_calloc} -- Allocate aligned nullified memory with an allocator
3781 @item @emph{Description}:
3782 Allocate zero-initialized memory with the specified allocator, which can either
3783 be a predefined allocator, an allocator handle or @code{omp_null_allocator}. If
3784 the allocators is @code{omp_null_allocator}, the allocator specified by the
3785 @var{def-allocator-var} ICV is used. The to-be allocated memory is for an
3786 array with @var{nmemb} elements, each having a size of @var{size} bytes. Both
3787 @var{nmemb} and @var{size} must be nonnegative numbers; if either of them is
3788 zero, @code{omp_aligned_calloc} will return a null pointer. @var{alignment}
3789 must be a positive power of two and @var{size} must be a multiple of the
3790 alignment; the alignment will be at least the maximal value required by
3791 @code{alignment} trait of the allocator and the value of the passed
3792 @var{alignment} argument. If successful, a pointer to the zero-initialized
3793 allocated memory is returned, otherwise the @code{fallback} trait of the
3794 allocator determines the behavior.
3796 In @code{target} regions, either the @code{dynamic_allocators} clause must
3797 appear on a @code{requires} directive in the same compilation unit -- or the
3798 @var{allocator} argument may only be a constant expression with the value of
3799 one of the predefined allocators and may not be @code{omp_null_allocator}.
3801 Memory allocated by @code{omp_aligned_calloc} must be freed using
3805 @multitable @columnfractions .20 .80
3806 @item @emph{Prototype}: @tab @code{void* omp_aligned_calloc(size_t nmemb, size_t size,}
3807 @item @tab @code{ omp_allocator_handle_t allocator)}
3811 @multitable @columnfractions .20 .80
3812 @item @emph{Prototype}: @tab @code{void* omp_aligned_calloc(size_t nmemb, size_t size,}
3813 @item @tab @code{ omp_allocator_handle_t allocator=omp_null_allocator)}
3816 @item @emph{Fortran}:
3817 @multitable @columnfractions .20 .80
3818 @item @emph{Interface}: @tab @code{type(c_ptr) function omp_aligned_calloc(nmemb, size, allocator) bind(C)}
3819 @item @tab @code{use, intrinsic :: iso_c_binding, only : c_ptr, c_size_t}
3820 @item @tab @code{integer (c_size_t), value :: nmemb, size}
3821 @item @tab @code{integer (omp_allocator_handle_kind), value :: allocator}
3824 @item @emph{See also}:
3825 @ref{OMP_ALLOCATOR}, @ref{Memory allocation}, @ref{omp_set_default_allocator},
3826 @ref{omp_free}, @ref{omp_init_allocator}
3828 @item @emph{Reference}:
3829 @uref{https://www.openmp.org, OpenMP specification v5.1}, Section 3.13.8
3835 @subsection @code{omp_realloc} -- Reallocate memory allocated with OpenMP routines
3837 @item @emph{Description}:
3838 The @code{omp_realloc} routine deallocates memory to which @var{ptr} points to
3839 and allocates new memory with the specified @var{allocator} argument; the
3840 new memory will have the content of the old memory up to the minimum of the
3841 old size and the new @var{size}, otherwise the content of the returned memory
3842 is unspecified. If the new allocator is the same as the old one, the routine
3843 tries to resize the existing memory allocation, returning the same address as
3844 @var{ptr} if successful. @var{ptr} must point to memory allocated by an OpenMP
3845 memory-management routine.
3847 The @var{allocator} and @var{free_allocator} arguments must be a predefined
3848 allocator, an allocator handle or @code{omp_null_allocator}. If
3849 @var{free_allocator} is @code{omp_null_allocator}, the implementation
3850 automatically determines the allocator used for the allocation of @var{ptr}.
3851 If @var{allocator} is @code{omp_null_allocator} and @var{ptr} is not a
3852 null pointer, the same allocator as @code{free_allocator} is used and
3853 when @var{ptr} is a null pointer the allocator specified by the
3854 @var{def-allocator-var} ICV is used.
3856 The @var{size} must be a nonnegative number denoting the number of bytes to be
3857 allocated; if @var{size} is zero, @code{omp_realloc} will return free the
3858 memory and return a null pointer. When @var{size} is nonzero: if successful,
3859 a pointer to the allocated memory is returned, otherwise the @code{fallback}
3860 trait of the allocator determines the behavior.
3862 In @code{target} regions, either the @code{dynamic_allocators} clause must
3863 appear on a @code{requires} directive in the same compilation unit -- or the
3864 @var{free_allocator} and @var{allocator} arguments may only be a constant
3865 expression with the value of one of the predefined allocators and may not be
3866 @code{omp_null_allocator}.
3868 Memory allocated by @code{omp_realloc} must be freed using @code{omp_free}.
3869 Calling @code{omp_free} invokes undefined behavior if the memory
3870 was already deallocated or when the used allocator has already been destroyed.
3873 @multitable @columnfractions .20 .80
3874 @item @emph{Prototype}: @tab @code{void* omp_realloc(void *ptr, size_t size,}
3875 @item @tab @code{ omp_allocator_handle_t allocator,}
3876 @item @tab @code{ omp_allocator_handle_t free_allocator)}
3880 @multitable @columnfractions .20 .80
3881 @item @emph{Prototype}: @tab @code{void* omp_realloc(void *ptr, size_t size,}
3882 @item @tab @code{ omp_allocator_handle_t allocator=omp_null_allocator,}
3883 @item @tab @code{ omp_allocator_handle_t free_allocator=omp_null_allocator)}
3886 @item @emph{Fortran}:
3887 @multitable @columnfractions .20 .80
3888 @item @emph{Interface}: @tab @code{type(c_ptr) function omp_realloc(ptr, size, allocator, free_allocator) bind(C)}
3889 @item @tab @code{use, intrinsic :: iso_c_binding, only : c_ptr, c_size_t}
3890 @item @tab @code{type(C_ptr), value :: ptr}
3891 @item @tab @code{integer (c_size_t), value :: size}
3892 @item @tab @code{integer (omp_allocator_handle_kind), value :: allocator, free_allocator}
3895 @item @emph{See also}:
3896 @ref{OMP_ALLOCATOR}, @ref{Memory allocation}, @ref{omp_set_default_allocator},
3897 @ref{omp_free}, @ref{omp_init_allocator}
3899 @item @emph{Reference}:
3900 @uref{https://www.openmp.org, OpenMP specification v5.0}, Section 3.7.9
3905 @c @node Tool Control Routine
3906 @c @section Tool Control Routine
3910 @node Environment Display Routine
3911 @section Environment Display Routine
3913 Routine to display the OpenMP version number and the initial value of ICVs.
3914 It has C linkage and does not throw exceptions.
3917 * omp_display_env:: print the initial ICV values
3920 @node omp_display_env
3921 @subsection @code{omp_display_env} -- print the initial ICV values
3923 @item @emph{Description}:
3924 Each time this routine is invoked, the OpenMP version number and initial value
3925 of internal control variables (ICVs) is printed on @code{stderr}. The displayed
3926 values are those at startup after evaluating the environment variables; later
3927 calls to API routines or clauses used in enclosing constructs do not affect
3930 If the @var{verbose} argument is @code{false}, only the OpenMP version and
3931 standard OpenMP ICVs are shown; if it is @code{true}, additionally, the
3932 GCC-specific ICVs are shown.
3934 The output consists of multiple lines and starts with
3935 @samp{OPENMP DISPLAY ENVIRONMENT BEGIN} followed by the name-value lines and
3936 ends with @samp{OPENMP DISPLAY ENVIRONMENT END}. The @var{name} is followed by
3937 an equal sign and the @var{value} is enclosed in single quotes.
3939 The first line has as @var{name} either @samp{_OPENMP} or @samp{openmp_version}
3940 and shows as value the supported OpenMP version number (4-digit year, 2-digit
3941 month) of the implementation, matching the value of the @code{_OPENMP} macro
3942 and, in Fortran, the named constant @code{openmp_version}.
3944 In each of the succeeding lines, the @var{name} matches the environment-variable
3945 name of an ICV and shows its value. Those line are might be prefixed by pair of
3946 brackets and a space, where the brackets enclose a comma-separated list of
3947 devices to which the ICV-value combination applies to; the value can either be a
3948 numeric device number or an abstract name denoting all devices (@code{all}), the
3949 initial host device (@code{host}) or all devices but the host (@code{device}).
3950 Note that the same ICV might be printed multiple times for multiple devices,
3951 even if all have the same value.
3953 The effect when invoked from within a @code{target} region is unspecified.
3956 @multitable @columnfractions .20 .80
3957 @item @emph{Prototype}: @tab @code{void omp_display_env(int verbose)}
3960 @item @emph{Fortran}:
3961 @multitable @columnfractions .20 .80
3962 @item @emph{Interface}: @tab @code{subroutine omp_display_env(verbose)}
3963 @item @tab @code{logical, intent(in) :: verbose}
3966 @item @emph{Example}:
3967 Note that the GCC-specific ICVs, such as the shown @code{GOMP_SPINCOUNT},
3968 are only printed when @var{verbose} set to @code{true}.
3971 OPENMP DISPLAY ENVIRONMENT BEGIN
3973 [host] OMP_DYNAMIC = 'FALSE'
3974 [host] OMP_NESTED = 'FALSE'
3975 [all] OMP_CANCELLATION = 'FALSE'
3977 [host] GOMP_SPINCOUNT = '300000'
3978 OPENMP DISPLAY ENVIRONMENT END
3982 @item @emph{See also}:
3983 @ref{OMP_DISPLAY_ENV}, @ref{Environment Variables},
3984 @ref{Implementation-defined ICV Initialization}
3986 @item @emph{Reference}:
3987 @uref{https://www.openmp.org, OpenMP specification v5.1}, Section 3.15
3991 @c ---------------------------------------------------------------------
3992 @c OpenMP Environment Variables
3993 @c ---------------------------------------------------------------------
3995 @node Environment Variables
3996 @chapter OpenMP Environment Variables
3998 The environment variables which beginning with @env{OMP_} are defined by
3999 section 4 of the OpenMP specification in version 4.5 or in a later version
4000 of the specification, while those beginning with @env{GOMP_} are GNU extensions.
4001 Most @env{OMP_} environment variables have an associated internal control
4004 For any OpenMP environment variable that sets an ICV and is neither
4005 @code{OMP_DEFAULT_DEVICE} nor has global ICV scope, associated
4006 device-specific environment variables exist. For them, the environment
4007 variable without suffix affects the host. The suffix @code{_DEV_} followed
4008 by a non-negative device number less that the number of available devices sets
4009 the ICV for the corresponding device. The suffix @code{_DEV} sets the ICV
4010 of all non-host devices for which a device-specific corresponding environment
4011 variable has not been set while the @code{_ALL} suffix sets the ICV of all
4012 host and non-host devices for which a more specific corresponding environment
4013 variable is not set.
4016 * OMP_ALLOCATOR:: Set the default allocator
4017 * OMP_AFFINITY_FORMAT:: Set the format string used for affinity display
4018 * OMP_CANCELLATION:: Set whether cancellation is activated
4019 * OMP_DISPLAY_AFFINITY:: Display thread affinity information
4020 * OMP_DISPLAY_ENV:: Show OpenMP version and environment variables
4021 * OMP_DEFAULT_DEVICE:: Set the device used in target regions
4022 * OMP_DYNAMIC:: Dynamic adjustment of threads
4023 * OMP_MAX_ACTIVE_LEVELS:: Set the maximum number of nested parallel regions
4024 * OMP_MAX_TASK_PRIORITY:: Set the maximum task priority value
4025 * OMP_NESTED:: Nested parallel regions
4026 * OMP_NUM_TEAMS:: Specifies the number of teams to use by teams region
4027 * OMP_NUM_THREADS:: Specifies the number of threads to use
4028 * OMP_PROC_BIND:: Whether threads may be moved between CPUs
4029 * OMP_PLACES:: Specifies on which CPUs the threads should be placed
4030 * OMP_STACKSIZE:: Set default thread stack size
4031 * OMP_SCHEDULE:: How threads are scheduled
4032 * OMP_TARGET_OFFLOAD:: Controls offloading behavior
4033 * OMP_TEAMS_THREAD_LIMIT:: Set the maximum number of threads imposed by teams
4034 * OMP_THREAD_LIMIT:: Set the maximum number of threads
4035 * OMP_WAIT_POLICY:: How waiting threads are handled
4036 * GOMP_CPU_AFFINITY:: Bind threads to specific CPUs
4037 * GOMP_DEBUG:: Enable debugging output
4038 * GOMP_STACKSIZE:: Set default thread stack size
4039 * GOMP_SPINCOUNT:: Set the busy-wait spin count
4040 * GOMP_RTEMS_THREAD_POOLS:: Set the RTEMS specific thread pools
4045 @section @env{OMP_ALLOCATOR} -- Set the default allocator
4046 @cindex Environment Variable
4048 @item @emph{ICV:} @var{def-allocator-var}
4049 @item @emph{Scope:} data environment
4050 @item @emph{Description}:
4051 Sets the default allocator that is used when no allocator has been specified
4052 in the @code{allocate} or @code{allocator} clause or if an OpenMP memory
4053 routine is invoked with the @code{omp_null_allocator} allocator.
4054 If unset, @code{omp_default_mem_alloc} is used.
4056 The value can either be a predefined allocator or a predefined memory space
4057 or a predefined memory space followed by a colon and a comma-separated list
4058 of memory trait and value pairs, separated by @code{=}.
4060 See @ref{Memory allocation} for a list of supported prefedined allocators,
4061 memory spaces, and traits.
4063 Note: The corresponding device environment variables are currently not
4064 supported. Therefore, the non-host @var{def-allocator-var} ICVs are always
4065 initialized to @code{omp_default_mem_alloc}. However, on all devices,
4066 the @code{omp_set_default_allocator} API routine can be used to change
4071 OMP_ALLOCATOR=omp_high_bw_mem_alloc
4072 OMP_ALLOCATOR=omp_large_cap_mem_space
4073 OMP_ALLOCATOR=omp_low_lat_mem_space:pinned=true,partition=nearest
4076 @item @emph{See also}:
4077 @ref{Memory allocation}, @ref{omp_get_default_allocator},
4078 @ref{omp_set_default_allocator}, @ref{Offload-Target Specifics}
4080 @item @emph{Reference}:
4081 @uref{https://www.openmp.org, OpenMP specification v5.0}, Section 6.21
4086 @node OMP_AFFINITY_FORMAT
4087 @section @env{OMP_AFFINITY_FORMAT} -- Set the format string used for affinity display
4088 @cindex Environment Variable
4090 @item @emph{ICV:} @var{affinity-format-var}
4091 @item @emph{Scope:} device
4092 @item @emph{Description}:
4093 Sets the format string used when displaying OpenMP thread affinity information.
4094 Special values are output using @code{%} followed by an optional size
4095 specification and then either the single-character field type or its long
4096 name enclosed in curly braces; using @code{%%} displays a literal percent.
4097 The size specification consists of an optional @code{0.} or @code{.} followed
4098 by a positive integer, specifying the minimal width of the output. With
4099 @code{0.} and numerical values, the output is padded with zeros on the left;
4100 with @code{.}, the output is padded by spaces on the left; otherwise, the
4101 output is padded by spaces on the right. If unset, the value is
4102 ``@code{level %L thread %i affinity %A}''.
4104 Supported field types are:
4106 @multitable @columnfractions .10 .25 .60
4107 @item t @tab team_num @tab value returned by @code{omp_get_team_num}
4108 @item T @tab num_teams @tab value returned by @code{omp_get_num_teams}
4109 @item L @tab nesting_level @tab value returned by @code{omp_get_level}
4110 @item n @tab thread_num @tab value returned by @code{omp_get_thread_num}
4111 @item N @tab num_threads @tab value returned by @code{omp_get_num_threads}
4112 @item a @tab ancestor_tnum
4113 @tab value returned by
4114 @code{omp_get_ancestor_thread_num(omp_get_level()-1)}
4115 @item H @tab host @tab name of the host that executes the thread
4116 @item P @tab process_id @tab process identifier
4117 @item i @tab native_thread_id @tab native thread identifier
4118 @item A @tab thread_affinity
4119 @tab comma separated list of integer values or ranges, representing the
4120 processors on which a process might execute, subject to affinity
4124 For instance, after setting
4127 OMP_AFFINITY_FORMAT="%0.2a!%n!%.4L!%N;%.2t;%0.2T;%@{team_num@};%@{num_teams@};%A"
4130 with either @code{OMP_DISPLAY_AFFINITY} being set or when calling
4131 @code{omp_display_affinity} with @code{NULL} or an empty string, the program
4132 might display the following:
4135 00!0! 1!4; 0;01;0;1;0-11
4136 00!3! 1!4; 0;01;0;1;0-11
4137 00!2! 1!4; 0;01;0;1;0-11
4138 00!1! 1!4; 0;01;0;1;0-11
4141 @item @emph{See also}:
4142 @ref{OMP_DISPLAY_AFFINITY}
4144 @item @emph{Reference}:
4145 @uref{https://www.openmp.org, OpenMP specification v5.0}, Section 6.14
4150 @node OMP_CANCELLATION
4151 @section @env{OMP_CANCELLATION} -- Set whether cancellation is activated
4152 @cindex Environment Variable
4154 @item @emph{ICV:} @var{cancel-var}
4155 @item @emph{Scope:} global
4156 @item @emph{Description}:
4157 If set to @code{TRUE}, the cancellation is activated. If set to @code{FALSE} or
4158 if unset, cancellation is disabled and the @code{cancel} construct is ignored.
4160 @item @emph{See also}:
4161 @ref{omp_get_cancellation}
4163 @item @emph{Reference}:
4164 @uref{https://www.openmp.org, OpenMP specification v4.5}, Section 4.11
4169 @node OMP_DISPLAY_AFFINITY
4170 @section @env{OMP_DISPLAY_AFFINITY} -- Display thread affinity information
4171 @cindex Environment Variable
4173 @item @emph{ICV:} @var{display-affinity-var}
4174 @item @emph{Scope:} global
4175 @item @emph{Description}:
4176 If set to @code{FALSE} or if unset, affinity displaying is disabled.
4177 If set to @code{TRUE}, the runtime displays affinity information about
4178 OpenMP threads in a parallel region upon entering the region and every time
4181 @item @emph{See also}:
4182 @ref{OMP_AFFINITY_FORMAT}
4184 @item @emph{Reference}:
4185 @uref{https://www.openmp.org, OpenMP specification v5.0}, Section 6.13
4191 @node OMP_DISPLAY_ENV
4192 @section @env{OMP_DISPLAY_ENV} -- Show OpenMP version and environment variables
4193 @cindex Environment Variable
4195 @item @emph{ICV:} none
4196 @item @emph{Scope:} not applicable
4197 @item @emph{Description}:
4198 If set to @code{TRUE}, the runtime displays the same information to
4199 @code{stderr} as shown by the @code{omp_display_env} routine invoked with
4200 @var{verbose} argument set to @code{false}. If set to @code{VERBOSE}, the same
4201 information is shown as invoking the routine with @var{verbose} set to
4202 @code{true}. If unset or set to @code{FALSE}, this information is not shown.
4203 The result for any other value is unspecified.
4205 @item @emph{See also}:
4206 @ref{omp_display_env}
4208 @item @emph{Reference}:
4209 @uref{https://www.openmp.org, OpenMP specification v4.5}, Section 4.12
4214 @node OMP_DEFAULT_DEVICE
4215 @section @env{OMP_DEFAULT_DEVICE} -- Set the device used in target regions
4216 @cindex Environment Variable
4218 @item @emph{ICV:} @var{default-device-var}
4219 @item @emph{Scope:} data environment
4220 @item @emph{Description}:
4221 Set to choose the device which is used in a @code{target} region, unless the
4222 value is overridden by @code{omp_set_default_device} or by a @code{device}
4223 clause. The value shall be the nonnegative device number. If no device with
4224 the given device number exists, the code is executed on the host. If unset,
4225 @env{OMP_TARGET_OFFLOAD} is @code{mandatory} and no non-host devices are
4226 available, it is set to @code{omp_invalid_device}. Otherwise, if unset,
4227 device number 0 is used.
4230 @item @emph{See also}:
4231 @ref{omp_get_default_device}, @ref{omp_set_default_device},
4232 @ref{OMP_TARGET_OFFLOAD}
4234 @item @emph{Reference}:
4235 @uref{https://www.openmp.org, OpenMP specification v5.2}, Section 21.2.7
4241 @section @env{OMP_DYNAMIC} -- Dynamic adjustment of threads
4242 @cindex Environment Variable
4244 @item @emph{ICV:} @var{dyn-var}
4245 @item @emph{Scope:} global
4246 @item @emph{Description}:
4247 Enable or disable the dynamic adjustment of the number of threads
4248 within a team. The value of this environment variable shall be
4249 @code{TRUE} or @code{FALSE}. If undefined, dynamic adjustment is
4250 disabled by default.
4252 @item @emph{See also}:
4253 @ref{omp_set_dynamic}
4255 @item @emph{Reference}:
4256 @uref{https://www.openmp.org, OpenMP specification v4.5}, Section 4.3
4261 @node OMP_MAX_ACTIVE_LEVELS
4262 @section @env{OMP_MAX_ACTIVE_LEVELS} -- Set the maximum number of nested parallel regions
4263 @cindex Environment Variable
4265 @item @emph{ICV:} @var{max-active-levels-var}
4266 @item @emph{Scope:} data environment
4267 @item @emph{Description}:
4268 Specifies the initial value for the maximum number of nested parallel
4269 regions. The value of this variable shall be a positive integer.
4270 If undefined, then if @env{OMP_NESTED} is defined and set to true, or
4271 if @env{OMP_NUM_THREADS} or @env{OMP_PROC_BIND} are defined and set to
4272 a list with more than one item, the maximum number of nested parallel
4273 regions is initialized to the largest number supported, otherwise
4276 @item @emph{See also}:
4277 @ref{omp_set_max_active_levels}, @ref{OMP_NESTED}, @ref{OMP_PROC_BIND},
4278 @ref{OMP_NUM_THREADS}
4281 @item @emph{Reference}:
4282 @uref{https://www.openmp.org, OpenMP specification v4.5}, Section 4.9
4287 @node OMP_MAX_TASK_PRIORITY
4288 @section @env{OMP_MAX_TASK_PRIORITY} -- Set the maximum priority
4289 number that can be set for a task.
4290 @cindex Environment Variable
4292 @item @emph{ICV:} @var{max-task-priority-var}
4293 @item @emph{Scope:} global
4294 @item @emph{Description}:
4295 Specifies the initial value for the maximum priority value that can be
4296 set for a task. The value of this variable shall be a non-negative
4297 integer, and zero is allowed. If undefined, the default priority is
4300 @item @emph{See also}:
4301 @ref{omp_get_max_task_priority}
4303 @item @emph{Reference}:
4304 @uref{https://www.openmp.org, OpenMP specification v4.5}, Section 4.14
4310 @section @env{OMP_NESTED} -- Nested parallel regions
4311 @cindex Environment Variable
4312 @cindex Implementation specific setting
4314 @item @emph{ICV:} @var{max-active-levels-var}
4315 @item @emph{Scope:} data environment
4316 @item @emph{Description}:
4317 Enable or disable nested parallel regions, i.e., whether team members
4318 are allowed to create new teams. The value of this environment variable
4319 shall be @code{TRUE} or @code{FALSE}. If set to @code{TRUE}, the number
4320 of maximum active nested regions supported is by default set to the
4321 maximum supported, otherwise it is set to one. If
4322 @env{OMP_MAX_ACTIVE_LEVELS} is defined, its setting overrides this
4323 setting. If both are undefined, nested parallel regions are enabled if
4324 @env{OMP_NUM_THREADS} or @env{OMP_PROC_BINDS} are defined to a list with
4325 more than one item, otherwise they are disabled by default.
4327 Note that the @code{OMP_NESTED} environment variable was deprecated in
4328 the OpenMP specification 5.0 in favor of @code{OMP_MAX_ACTIVE_LEVELS}.
4330 @item @emph{See also}:
4331 @ref{omp_set_max_active_levels}, @ref{omp_set_nested},
4332 @ref{OMP_MAX_ACTIVE_LEVELS}
4334 @item @emph{Reference}:
4335 @uref{https://www.openmp.org, OpenMP specification v4.5}, Section 4.6
4341 @section @env{OMP_NUM_TEAMS} -- Specifies the number of teams to use by teams region
4342 @cindex Environment Variable
4344 @item @emph{ICV:} @var{nteams-var}
4345 @item @emph{Scope:} device
4346 @item @emph{Description}:
4347 Specifies the upper bound for number of teams to use in teams regions
4348 without explicit @code{num_teams} clause. The value of this variable shall
4349 be a positive integer. If undefined it defaults to 0 which means
4350 implementation defined upper bound.
4352 @item @emph{See also}:
4353 @ref{omp_set_num_teams}
4355 @item @emph{Reference}:
4356 @uref{https://www.openmp.org, OpenMP specification v5.1}, Section 6.23
4361 @node OMP_NUM_THREADS
4362 @section @env{OMP_NUM_THREADS} -- Specifies the number of threads to use
4363 @cindex Environment Variable
4364 @cindex Implementation specific setting
4366 @item @emph{ICV:} @var{nthreads-var}
4367 @item @emph{Scope:} data environment
4368 @item @emph{Description}:
4369 Specifies the default number of threads to use in parallel regions. The
4370 value of this variable shall be a comma-separated list of positive integers;
4371 the value specifies the number of threads to use for the corresponding nested
4372 level. Specifying more than one item in the list automatically enables
4373 nesting by default. If undefined one thread per CPU is used.
4375 When a list with more than value is specified, it also affects the
4376 @var{max-active-levels-var} ICV as described in @ref{OMP_MAX_ACTIVE_LEVELS}.
4378 @item @emph{See also}:
4379 @ref{omp_set_num_threads}, @ref{OMP_MAX_ACTIVE_LEVELS}
4381 @item @emph{Reference}:
4382 @uref{https://www.openmp.org, OpenMP specification v4.5}, Section 4.2
4388 @section @env{OMP_PROC_BIND} -- Whether threads may be moved between CPUs
4389 @cindex Environment Variable
4391 @item @emph{ICV:} @var{bind-var}
4392 @item @emph{Scope:} data environment
4393 @item @emph{Description}:
4394 Specifies whether threads may be moved between processors. If set to
4395 @code{TRUE}, OpenMP threads should not be moved; if set to @code{FALSE}
4396 they may be moved. Alternatively, a comma separated list with the
4397 values @code{PRIMARY}, @code{MASTER}, @code{CLOSE} and @code{SPREAD} can
4398 be used to specify the thread affinity policy for the corresponding nesting
4399 level. With @code{PRIMARY} and @code{MASTER} the worker threads are in the
4400 same place partition as the primary thread. With @code{CLOSE} those are
4401 kept close to the primary thread in contiguous place partitions. And
4402 with @code{SPREAD} a sparse distribution
4403 across the place partitions is used. Specifying more than one item in the
4404 list automatically enables nesting by default.
4406 When a list is specified, it also affects the @var{max-active-levels-var} ICV
4407 as described in @ref{OMP_MAX_ACTIVE_LEVELS}.
4409 When undefined, @env{OMP_PROC_BIND} defaults to @code{TRUE} when
4410 @env{OMP_PLACES} or @env{GOMP_CPU_AFFINITY} is set and @code{FALSE} otherwise.
4412 @item @emph{See also}:
4413 @ref{omp_get_proc_bind}, @ref{GOMP_CPU_AFFINITY}, @ref{OMP_PLACES},
4414 @ref{OMP_MAX_ACTIVE_LEVELS}
4416 @item @emph{Reference}:
4417 @uref{https://www.openmp.org, OpenMP specification v4.5}, Section 4.4
4423 @section @env{OMP_PLACES} -- Specifies on which CPUs the threads should be placed
4424 @cindex Environment Variable
4426 @item @emph{ICV:} @var{place-partition-var}
4427 @item @emph{Scope:} implicit tasks
4428 @item @emph{Description}:
4429 The thread placement can be either specified using an abstract name or by an
4430 explicit list of the places. The abstract names @code{threads}, @code{cores},
4431 @code{sockets}, @code{ll_caches} and @code{numa_domains} can be optionally
4432 followed by a positive number in parentheses, which denotes the how many places
4433 shall be created. With @code{threads} each place corresponds to a single
4434 hardware thread; @code{cores} to a single core with the corresponding number of
4435 hardware threads; with @code{sockets} the place corresponds to a single
4436 socket; with @code{ll_caches} to a set of cores that shares the last level
4437 cache on the device; and @code{numa_domains} to a set of cores for which their
4438 closest memory on the device is the same memory and at a similar distance from
4439 the cores. The resulting placement can be shown by setting the
4440 @env{OMP_DISPLAY_ENV} environment variable.
4442 Alternatively, the placement can be specified explicitly as comma-separated
4443 list of places. A place is specified by set of nonnegative numbers in curly
4444 braces, denoting the hardware threads. The curly braces can be omitted
4445 when only a single number has been specified. The hardware threads
4446 belonging to a place can either be specified as comma-separated list of
4447 nonnegative thread numbers or using an interval. Multiple places can also be
4448 either specified by a comma-separated list of places or by an interval. To
4449 specify an interval, a colon followed by the count is placed after
4450 the hardware thread number or the place. Optionally, the length can be
4451 followed by a colon and the stride number -- otherwise a unit stride is
4452 assumed. Placing an exclamation mark (@code{!}) directly before a curly
4453 brace or numbers inside the curly braces (excluding intervals)
4454 excludes those hardware threads.
4456 For instance, the following specifies the same places list:
4457 @code{"@{0,1,2@}, @{3,4,6@}, @{7,8,9@}, @{10,11,12@}"};
4458 @code{"@{0:3@}, @{3:3@}, @{7:3@}, @{10:3@}"}; and @code{"@{0:2@}:4:3"}.
4460 If @env{OMP_PLACES} and @env{GOMP_CPU_AFFINITY} are unset and
4461 @env{OMP_PROC_BIND} is either unset or @code{false}, threads may be moved
4462 between CPUs following no placement policy.
4464 @item @emph{See also}:
4465 @ref{OMP_PROC_BIND}, @ref{GOMP_CPU_AFFINITY}, @ref{omp_get_proc_bind},
4466 @ref{OMP_DISPLAY_ENV}
4468 @item @emph{Reference}:
4469 @uref{https://www.openmp.org, OpenMP specification v4.5}, Section 4.5
4475 @section @env{OMP_STACKSIZE} -- Set default thread stack size
4476 @cindex Environment Variable
4478 @item @emph{ICV:} @var{stacksize-var}
4479 @item @emph{Scope:} device
4480 @item @emph{Description}:
4481 Set the default thread stack size in kilobytes, unless the number
4482 is suffixed by @code{B}, @code{K}, @code{M} or @code{G}, in which
4483 case the size is, respectively, in bytes, kilobytes, megabytes
4484 or gigabytes. This is different from @code{pthread_attr_setstacksize}
4485 which gets the number of bytes as an argument. If the stack size cannot
4486 be set due to system constraints, an error is reported and the initial
4487 stack size is left unchanged. If undefined, the stack size is system
4490 @item @emph{See also}:
4491 @ref{GOMP_STACKSIZE}
4493 @item @emph{Reference}:
4494 @uref{https://www.openmp.org, OpenMP specification v4.5}, Section 4.7
4500 @section @env{OMP_SCHEDULE} -- How threads are scheduled
4501 @cindex Environment Variable
4502 @cindex Implementation specific setting
4504 @item @emph{ICV:} @var{run-sched-var}
4505 @item @emph{Scope:} data environment
4506 @item @emph{Description}:
4507 Allows to specify @code{schedule type} and @code{chunk size}.
4508 The value of the variable shall have the form: @code{type[,chunk]} where
4509 @code{type} is one of @code{static}, @code{dynamic}, @code{guided} or @code{auto}
4510 The optional @code{chunk} size shall be a positive integer. If undefined,
4511 dynamic scheduling and a chunk size of 1 is used.
4513 @item @emph{See also}:
4514 @ref{omp_set_schedule}
4516 @item @emph{Reference}:
4517 @uref{https://www.openmp.org, OpenMP specification v4.5}, Sections 2.7.1.1 and 4.1
4522 @node OMP_TARGET_OFFLOAD
4523 @section @env{OMP_TARGET_OFFLOAD} -- Controls offloading behavior
4524 @cindex Environment Variable
4525 @cindex Implementation specific setting
4527 @item @emph{ICV:} @var{target-offload-var}
4528 @item @emph{Scope:} global
4529 @item @emph{Description}:
4530 Specifies the behavior with regard to offloading code to a device. This
4531 variable can be set to one of three values - @code{MANDATORY}, @code{DISABLED}
4534 If set to @code{MANDATORY}, the program terminates with an error if
4535 any device construct or device memory routine uses a device that is unavailable
4536 or not supported by the implementation, or uses a non-conforming device number.
4537 If set to @code{DISABLED}, then offloading is disabled and all code runs on
4538 the host. If set to @code{DEFAULT}, the program tries offloading to the
4539 device first, then falls back to running code on the host if it cannot.
4541 If undefined, then the program behaves as if @code{DEFAULT} was set.
4543 Note: Even with @code{MANDATORY}, no run-time termination is performed when
4544 the device number in a @code{device} clause or argument to a device memory
4545 routine is for host, which includes using the device number in the
4546 @var{default-device-var} ICV. However, the initial value of
4547 the @var{default-device-var} ICV is affected by @code{MANDATORY}.
4549 @item @emph{See also}:
4550 @ref{OMP_DEFAULT_DEVICE}
4552 @item @emph{Reference}:
4553 @uref{https://www.openmp.org, OpenMP specification v5.2}, Section 21.2.8
4558 @node OMP_TEAMS_THREAD_LIMIT
4559 @section @env{OMP_TEAMS_THREAD_LIMIT} -- Set the maximum number of threads imposed by teams
4560 @cindex Environment Variable
4562 @item @emph{ICV:} @var{teams-thread-limit-var}
4563 @item @emph{Scope:} device
4564 @item @emph{Description}:
4565 Specifies an upper bound for the number of threads to use by each contention
4566 group created by a teams construct without explicit @code{thread_limit}
4567 clause. The value of this variable shall be a positive integer. If undefined,
4568 the value of 0 is used which stands for an implementation defined upper
4571 @item @emph{See also}:
4572 @ref{OMP_THREAD_LIMIT}, @ref{omp_set_teams_thread_limit}
4574 @item @emph{Reference}:
4575 @uref{https://www.openmp.org, OpenMP specification v5.1}, Section 6.24
4580 @node OMP_THREAD_LIMIT
4581 @section @env{OMP_THREAD_LIMIT} -- Set the maximum number of threads
4582 @cindex Environment Variable
4584 @item @emph{ICV:} @var{thread-limit-var}
4585 @item @emph{Scope:} data environment
4586 @item @emph{Description}:
4587 Specifies the number of threads to use for the whole program. The
4588 value of this variable shall be a positive integer. If undefined,
4589 the number of threads is not limited.
4591 @item @emph{See also}:
4592 @ref{OMP_NUM_THREADS}, @ref{omp_get_thread_limit}
4594 @item @emph{Reference}:
4595 @uref{https://www.openmp.org, OpenMP specification v4.5}, Section 4.10
4600 @node OMP_WAIT_POLICY
4601 @section @env{OMP_WAIT_POLICY} -- How waiting threads are handled
4602 @cindex Environment Variable
4604 @item @emph{Description}:
4605 Specifies whether waiting threads should be active or passive. If
4606 the value is @code{PASSIVE}, waiting threads should not consume CPU
4607 power while waiting; while the value is @code{ACTIVE} specifies that
4608 they should. If undefined, threads wait actively for a short time
4609 before waiting passively.
4611 @item @emph{See also}:
4612 @ref{GOMP_SPINCOUNT}
4614 @item @emph{Reference}:
4615 @uref{https://www.openmp.org, OpenMP specification v4.5}, Section 4.8
4620 @node GOMP_CPU_AFFINITY
4621 @section @env{GOMP_CPU_AFFINITY} -- Bind threads to specific CPUs
4622 @cindex Environment Variable
4624 @item @emph{Description}:
4625 Binds threads to specific CPUs. The variable should contain a space-separated
4626 or comma-separated list of CPUs. This list may contain different kinds of
4627 entries: either single CPU numbers in any order, a range of CPUs (M-N)
4628 or a range with some stride (M-N:S). CPU numbers are zero based. For example,
4629 @code{GOMP_CPU_AFFINITY="0 3 1-2 4-15:2"} binds the initial thread
4630 to CPU 0, the second to CPU 3, the third to CPU 1, the fourth to
4631 CPU 2, the fifth to CPU 4, the sixth through tenth to CPUs 6, 8, 10, 12,
4632 and 14 respectively and then starts assigning back from the beginning of
4633 the list. @code{GOMP_CPU_AFFINITY=0} binds all threads to CPU 0.
4635 There is no libgomp library routine to determine whether a CPU affinity
4636 specification is in effect. As a workaround, language-specific library
4637 functions, e.g., @code{getenv} in C or @code{GET_ENVIRONMENT_VARIABLE} in
4638 Fortran, may be used to query the setting of the @code{GOMP_CPU_AFFINITY}
4639 environment variable. A defined CPU affinity on startup cannot be changed
4640 or disabled during the runtime of the application.
4642 If both @env{GOMP_CPU_AFFINITY} and @env{OMP_PROC_BIND} are set,
4643 @env{OMP_PROC_BIND} has a higher precedence. If neither has been set and
4644 @env{OMP_PROC_BIND} is unset, or when @env{OMP_PROC_BIND} is set to
4645 @code{FALSE}, the host system handles the assignment of threads to CPUs.
4647 @item @emph{See also}:
4648 @ref{OMP_PLACES}, @ref{OMP_PROC_BIND}
4654 @section @env{GOMP_DEBUG} -- Enable debugging output
4655 @cindex Environment Variable
4657 @item @emph{Description}:
4658 Enable debugging output. The variable should be set to @code{0}
4659 (disabled, also the default if not set), or @code{1} (enabled).
4661 If enabled, some debugging output is printed during execution.
4662 This is currently not specified in more detail, and subject to change.
4667 @node GOMP_STACKSIZE
4668 @section @env{GOMP_STACKSIZE} -- Set default thread stack size
4669 @cindex Environment Variable
4670 @cindex Implementation specific setting
4672 @item @emph{Description}:
4673 Set the default thread stack size in kilobytes. This is different from
4674 @code{pthread_attr_setstacksize} which gets the number of bytes as an
4675 argument. If the stack size cannot be set due to system constraints, an
4676 error is reported and the initial stack size is left unchanged. If undefined,
4677 the stack size is system dependent.
4679 @item @emph{See also}:
4682 @item @emph{Reference}:
4683 @uref{https://gcc.gnu.org/ml/gcc-patches/2006-06/msg00493.html,
4684 GCC Patches Mailinglist},
4685 @uref{https://gcc.gnu.org/ml/gcc-patches/2006-06/msg00496.html,
4686 GCC Patches Mailinglist}
4691 @node GOMP_SPINCOUNT
4692 @section @env{GOMP_SPINCOUNT} -- Set the busy-wait spin count
4693 @cindex Environment Variable
4694 @cindex Implementation specific setting
4696 @item @emph{Description}:
4697 Determines how long a threads waits actively with consuming CPU power
4698 before waiting passively without consuming CPU power. The value may be
4699 either @code{INFINITE}, @code{INFINITY} to always wait actively or an
4700 integer which gives the number of spins of the busy-wait loop. The
4701 integer may optionally be followed by the following suffixes acting
4702 as multiplication factors: @code{k} (kilo, thousand), @code{M} (mega,
4703 million), @code{G} (giga, billion), or @code{T} (tera, trillion).
4704 If undefined, 0 is used when @env{OMP_WAIT_POLICY} is @code{PASSIVE},
4705 300,000 is used when @env{OMP_WAIT_POLICY} is undefined and
4706 30 billion is used when @env{OMP_WAIT_POLICY} is @code{ACTIVE}.
4707 If there are more OpenMP threads than available CPUs, 1000 and 100
4708 spins are used for @env{OMP_WAIT_POLICY} being @code{ACTIVE} or
4709 undefined, respectively; unless the @env{GOMP_SPINCOUNT} is lower
4710 or @env{OMP_WAIT_POLICY} is @code{PASSIVE}.
4712 @item @emph{See also}:
4713 @ref{OMP_WAIT_POLICY}
4718 @node GOMP_RTEMS_THREAD_POOLS
4719 @section @env{GOMP_RTEMS_THREAD_POOLS} -- Set the RTEMS specific thread pools
4720 @cindex Environment Variable
4721 @cindex Implementation specific setting
4723 @item @emph{Description}:
4724 This environment variable is only used on the RTEMS real-time operating system.
4725 It determines the scheduler instance specific thread pools. The format for
4726 @env{GOMP_RTEMS_THREAD_POOLS} is a list of optional
4727 @code{<thread-pool-count>[$<priority>]@@<scheduler-name>} configurations
4728 separated by @code{:} where:
4730 @item @code{<thread-pool-count>} is the thread pool count for this scheduler
4732 @item @code{$<priority>} is an optional priority for the worker threads of a
4733 thread pool according to @code{pthread_setschedparam}. In case a priority
4734 value is omitted, then a worker thread inherits the priority of the OpenMP
4735 primary thread that created it. The priority of the worker thread is not
4736 changed after creation, even if a new OpenMP primary thread using the worker has
4737 a different priority.
4738 @item @code{@@<scheduler-name>} is the scheduler instance name according to the
4739 RTEMS application configuration.
4741 In case no thread pool configuration is specified for a scheduler instance,
4742 then each OpenMP primary thread of this scheduler instance uses its own
4743 dynamically allocated thread pool. To limit the worker thread count of the
4744 thread pools, each OpenMP primary thread must call @code{omp_set_num_threads}.
4745 @item @emph{Example}:
4746 Lets suppose we have three scheduler instances @code{IO}, @code{WRK0}, and
4747 @code{WRK1} with @env{GOMP_RTEMS_THREAD_POOLS} set to
4748 @code{"1@@WRK0:3$4@@WRK1"}. Then there are no thread pool restrictions for
4749 scheduler instance @code{IO}. In the scheduler instance @code{WRK0} there is
4750 one thread pool available. Since no priority is specified for this scheduler
4751 instance, the worker thread inherits the priority of the OpenMP primary thread
4752 that created it. In the scheduler instance @code{WRK1} there are three thread
4753 pools available and their worker threads run at priority four.
4758 @c ---------------------------------------------------------------------
4760 @c ---------------------------------------------------------------------
4762 @node Enabling OpenACC
4763 @chapter Enabling OpenACC
4765 To activate the OpenACC extensions for C/C++ and Fortran, the compile-time
4766 flag @option{-fopenacc} must be specified. This enables the OpenACC directive
4767 @samp{#pragma acc} in C/C++ and, in Fortran, the @samp{!$acc} sentinel in free
4768 source form and the @samp{c$acc}, @samp{*$acc} and @samp{!$acc} sentinels in
4769 fixed source form. The flag also arranges for automatic linking of the OpenACC
4770 runtime library (@ref{OpenACC Runtime Library Routines}).
4772 See @uref{https://gcc.gnu.org/wiki/OpenACC} for more information.
4774 A complete description of all OpenACC directives accepted may be found in
4775 the @uref{https://www.openacc.org, OpenACC} Application Programming
4776 Interface manual, version 2.6.
4780 @c ---------------------------------------------------------------------
4781 @c OpenACC Runtime Library Routines
4782 @c ---------------------------------------------------------------------
4784 @node OpenACC Runtime Library Routines
4785 @chapter OpenACC Runtime Library Routines
4787 The runtime routines described here are defined by section 3 of the OpenACC
4788 specifications in version 2.6.
4789 They have C linkage, and do not throw exceptions.
4790 Generally, they are available only for the host, with the exception of
4791 @code{acc_on_device}, which is available for both the host and the
4792 acceleration device.
4795 * acc_get_num_devices:: Get number of devices for the given device
4797 * acc_set_device_type:: Set type of device accelerator to use.
4798 * acc_get_device_type:: Get type of device accelerator to be used.
4799 * acc_set_device_num:: Set device number to use.
4800 * acc_get_device_num:: Get device number to be used.
4801 * acc_get_property:: Get device property.
4802 * acc_async_test:: Tests for completion of a specific asynchronous
4804 * acc_async_test_all:: Tests for completion of all asynchronous
4806 * acc_wait:: Wait for completion of a specific asynchronous
4808 * acc_wait_all:: Waits for completion of all asynchronous
4810 * acc_wait_all_async:: Wait for completion of all asynchronous
4812 * acc_wait_async:: Wait for completion of asynchronous operations.
4813 * acc_init:: Initialize runtime for a specific device type.
4814 * acc_shutdown:: Shuts down the runtime for a specific device
4816 * acc_on_device:: Whether executing on a particular device
4817 * acc_malloc:: Allocate device memory.
4818 * acc_free:: Free device memory.
4819 * acc_copyin:: Allocate device memory and copy host memory to
4821 * acc_present_or_copyin:: If the data is not present on the device,
4822 allocate device memory and copy from host
4824 * acc_create:: Allocate device memory and map it to host
4826 * acc_present_or_create:: If the data is not present on the device,
4827 allocate device memory and map it to host
4829 * acc_copyout:: Copy device memory to host memory.
4830 * acc_delete:: Free device memory.
4831 * acc_update_device:: Update device memory from mapped host memory.
4832 * acc_update_self:: Update host memory from mapped device memory.
4833 * acc_map_data:: Map previously allocated device memory to host
4835 * acc_unmap_data:: Unmap device memory from host memory.
4836 * acc_deviceptr:: Get device pointer associated with specific
4838 * acc_hostptr:: Get host pointer associated with specific
4840 * acc_is_present:: Indicate whether host variable / array is
4842 * acc_memcpy_to_device:: Copy host memory to device memory.
4843 * acc_memcpy_from_device:: Copy device memory to host memory.
4844 * acc_memcpy_device:: Copy memory within a device.
4845 * acc_attach:: Let device pointer point to device-pointer target.
4846 * acc_detach:: Let device pointer point to host-pointer target.
4848 API routines for target platforms.
4850 * acc_get_current_cuda_device:: Get CUDA device handle.
4851 * acc_get_current_cuda_context::Get CUDA context handle.
4852 * acc_get_cuda_stream:: Get CUDA stream handle.
4853 * acc_set_cuda_stream:: Set CUDA stream handle.
4855 API routines for the OpenACC Profiling Interface.
4857 * acc_prof_register:: Register callbacks.
4858 * acc_prof_unregister:: Unregister callbacks.
4859 * acc_prof_lookup:: Obtain inquiry functions.
4860 * acc_register_library:: Library registration.
4865 @node acc_get_num_devices
4866 @section @code{acc_get_num_devices} -- Get number of devices for given device type
4868 @item @emph{Description}
4869 This function returns a value indicating the number of devices available
4870 for the device type specified in @var{devicetype}.
4873 @multitable @columnfractions .20 .80
4874 @item @emph{Prototype}: @tab @code{int acc_get_num_devices(acc_device_t devicetype);}
4877 @item @emph{Fortran}:
4878 @multitable @columnfractions .20 .80
4879 @item @emph{Interface}: @tab @code{integer function acc_get_num_devices(devicetype)}
4880 @item @tab @code{integer(kind=acc_device_kind) devicetype}
4883 @item @emph{Reference}:
4884 @uref{https://www.openacc.org, OpenACC specification v2.6}, section
4890 @node acc_set_device_type
4891 @section @code{acc_set_device_type} -- Set type of device accelerator to use.
4893 @item @emph{Description}
4894 This function indicates to the runtime library which device type, specified
4895 in @var{devicetype}, to use when executing a parallel or kernels region.
4898 @multitable @columnfractions .20 .80
4899 @item @emph{Prototype}: @tab @code{acc_set_device_type(acc_device_t devicetype);}
4902 @item @emph{Fortran}:
4903 @multitable @columnfractions .20 .80
4904 @item @emph{Interface}: @tab @code{subroutine acc_set_device_type(devicetype)}
4905 @item @tab @code{integer(kind=acc_device_kind) devicetype}
4908 @item @emph{Reference}:
4909 @uref{https://www.openacc.org, OpenACC specification v2.6}, section
4915 @node acc_get_device_type
4916 @section @code{acc_get_device_type} -- Get type of device accelerator to be used.
4918 @item @emph{Description}
4919 This function returns what device type will be used when executing a
4920 parallel or kernels region.
4922 This function returns @code{acc_device_none} if
4923 @code{acc_get_device_type} is called from
4924 @code{acc_ev_device_init_start}, @code{acc_ev_device_init_end}
4925 callbacks of the OpenACC Profiling Interface (@ref{OpenACC Profiling
4926 Interface}), that is, if the device is currently being initialized.
4929 @multitable @columnfractions .20 .80
4930 @item @emph{Prototype}: @tab @code{acc_device_t acc_get_device_type(void);}
4933 @item @emph{Fortran}:
4934 @multitable @columnfractions .20 .80
4935 @item @emph{Interface}: @tab @code{function acc_get_device_type(void)}
4936 @item @tab @code{integer(kind=acc_device_kind) acc_get_device_type}
4939 @item @emph{Reference}:
4940 @uref{https://www.openacc.org, OpenACC specification v2.6}, section
4946 @node acc_set_device_num
4947 @section @code{acc_set_device_num} -- Set device number to use.
4949 @item @emph{Description}
4950 This function will indicate to the runtime which device number,
4951 specified by @var{devicenum}, associated with the specified device
4952 type @var{devicetype}.
4955 @multitable @columnfractions .20 .80
4956 @item @emph{Prototype}: @tab @code{acc_set_device_num(int devicenum, acc_device_t devicetype);}
4959 @item @emph{Fortran}:
4960 @multitable @columnfractions .20 .80
4961 @item @emph{Interface}: @tab @code{subroutine acc_set_device_num(devicenum, devicetype)}
4962 @item @tab @code{integer devicenum}
4963 @item @tab @code{integer(kind=acc_device_kind) devicetype}
4966 @item @emph{Reference}:
4967 @uref{https://www.openacc.org, OpenACC specification v2.6}, section
4973 @node acc_get_device_num
4974 @section @code{acc_get_device_num} -- Get device number to be used.
4976 @item @emph{Description}
4977 This function returns which device number associated with the specified device
4978 type @var{devicetype}, will be used when executing a parallel or kernels
4982 @multitable @columnfractions .20 .80
4983 @item @emph{Prototype}: @tab @code{int acc_get_device_num(acc_device_t devicetype);}
4986 @item @emph{Fortran}:
4987 @multitable @columnfractions .20 .80
4988 @item @emph{Interface}: @tab @code{function acc_get_device_num(devicetype)}
4989 @item @tab @code{integer(kind=acc_device_kind) devicetype}
4990 @item @tab @code{integer acc_get_device_num}
4993 @item @emph{Reference}:
4994 @uref{https://www.openacc.org, OpenACC specification v2.6}, section
5000 @node acc_get_property
5001 @section @code{acc_get_property} -- Get device property.
5002 @cindex acc_get_property
5003 @cindex acc_get_property_string
5005 @item @emph{Description}
5006 These routines return the value of the specified @var{property} for the
5007 device being queried according to @var{devicenum} and @var{devicetype}.
5008 Integer-valued and string-valued properties are returned by
5009 @code{acc_get_property} and @code{acc_get_property_string} respectively.
5010 The Fortran @code{acc_get_property_string} subroutine returns the string
5011 retrieved in its fourth argument while the remaining entry points are
5012 functions, which pass the return value as their result.
5014 Note for Fortran, only: the OpenACC technical committee corrected and, hence,
5015 modified the interface introduced in OpenACC 2.6. The kind-value parameter
5016 @code{acc_device_property} has been renamed to @code{acc_device_property_kind}
5017 for consistency and the return type of the @code{acc_get_property} function is
5018 now a @code{c_size_t} integer instead of a @code{acc_device_property} integer.
5019 The parameter @code{acc_device_property} is still provided,
5020 but might be removed in a future version of GCC.
5023 @multitable @columnfractions .20 .80
5024 @item @emph{Prototype}: @tab @code{size_t acc_get_property(int devicenum, acc_device_t devicetype, acc_device_property_t property);}
5025 @item @emph{Prototype}: @tab @code{const char *acc_get_property_string(int devicenum, acc_device_t devicetype, acc_device_property_t property);}
5028 @item @emph{Fortran}:
5029 @multitable @columnfractions .20 .80
5030 @item @emph{Interface}: @tab @code{function acc_get_property(devicenum, devicetype, property)}
5031 @item @emph{Interface}: @tab @code{subroutine acc_get_property_string(devicenum, devicetype, property, string)}
5032 @item @tab @code{use ISO_C_Binding, only: c_size_t}
5033 @item @tab @code{integer devicenum}
5034 @item @tab @code{integer(kind=acc_device_kind) devicetype}
5035 @item @tab @code{integer(kind=acc_device_property_kind) property}
5036 @item @tab @code{integer(kind=c_size_t) acc_get_property}
5037 @item @tab @code{character(*) string}
5040 @item @emph{Reference}:
5041 @uref{https://www.openacc.org, OpenACC specification v2.6}, section
5047 @node acc_async_test
5048 @section @code{acc_async_test} -- Test for completion of a specific asynchronous operation.
5050 @item @emph{Description}
5051 This function tests for completion of the asynchronous operation specified
5052 in @var{arg}. In C/C++, a non-zero value is returned to indicate
5053 the specified asynchronous operation has completed while Fortran returns
5054 @code{true}. If the asynchronous operation has not completed, C/C++ returns
5055 zero and Fortran returns @code{false}.
5058 @multitable @columnfractions .20 .80
5059 @item @emph{Prototype}: @tab @code{int acc_async_test(int arg);}
5062 @item @emph{Fortran}:
5063 @multitable @columnfractions .20 .80
5064 @item @emph{Interface}: @tab @code{function acc_async_test(arg)}
5065 @item @tab @code{integer(kind=acc_handle_kind) arg}
5066 @item @tab @code{logical acc_async_test}
5069 @item @emph{Reference}:
5070 @uref{https://www.openacc.org, OpenACC specification v2.6}, section
5076 @node acc_async_test_all
5077 @section @code{acc_async_test_all} -- Tests for completion of all asynchronous operations.
5079 @item @emph{Description}
5080 This function tests for completion of all asynchronous operations.
5081 In C/C++, a non-zero value is returned to indicate all asynchronous
5082 operations have completed while Fortran returns @code{true}. If
5083 any asynchronous operation has not completed, C/C++ returns zero and
5084 Fortran returns @code{false}.
5087 @multitable @columnfractions .20 .80
5088 @item @emph{Prototype}: @tab @code{int acc_async_test_all(void);}
5091 @item @emph{Fortran}:
5092 @multitable @columnfractions .20 .80
5093 @item @emph{Interface}: @tab @code{function acc_async_test()}
5094 @item @tab @code{logical acc_get_device_num}
5097 @item @emph{Reference}:
5098 @uref{https://www.openacc.org, OpenACC specification v2.6}, section
5105 @section @code{acc_wait} -- Wait for completion of a specific asynchronous operation.
5107 @item @emph{Description}
5108 This function waits for completion of the asynchronous operation
5109 specified in @var{arg}.
5112 @multitable @columnfractions .20 .80
5113 @item @emph{Prototype}: @tab @code{acc_wait(arg);}
5114 @item @emph{Prototype (OpenACC 1.0 compatibility)}: @tab @code{acc_async_wait(arg);}
5117 @item @emph{Fortran}:
5118 @multitable @columnfractions .20 .80
5119 @item @emph{Interface}: @tab @code{subroutine acc_wait(arg)}
5120 @item @tab @code{integer(acc_handle_kind) arg}
5121 @item @emph{Interface (OpenACC 1.0 compatibility)}: @tab @code{subroutine acc_async_wait(arg)}
5122 @item @tab @code{integer(acc_handle_kind) arg}
5125 @item @emph{Reference}:
5126 @uref{https://www.openacc.org, OpenACC specification v2.6}, section
5133 @section @code{acc_wait_all} -- Waits for completion of all asynchronous operations.
5135 @item @emph{Description}
5136 This function waits for the completion of all asynchronous operations.
5139 @multitable @columnfractions .20 .80
5140 @item @emph{Prototype}: @tab @code{acc_wait_all(void);}
5141 @item @emph{Prototype (OpenACC 1.0 compatibility)}: @tab @code{acc_async_wait_all(void);}
5144 @item @emph{Fortran}:
5145 @multitable @columnfractions .20 .80
5146 @item @emph{Interface}: @tab @code{subroutine acc_wait_all()}
5147 @item @emph{Interface (OpenACC 1.0 compatibility)}: @tab @code{subroutine acc_async_wait_all()}
5150 @item @emph{Reference}:
5151 @uref{https://www.openacc.org, OpenACC specification v2.6}, section
5157 @node acc_wait_all_async
5158 @section @code{acc_wait_all_async} -- Wait for completion of all asynchronous operations.
5160 @item @emph{Description}
5161 This function enqueues a wait operation on the queue @var{async} for any
5162 and all asynchronous operations that have been previously enqueued on
5166 @multitable @columnfractions .20 .80
5167 @item @emph{Prototype}: @tab @code{acc_wait_all_async(int async);}
5170 @item @emph{Fortran}:
5171 @multitable @columnfractions .20 .80
5172 @item @emph{Interface}: @tab @code{subroutine acc_wait_all_async(async)}
5173 @item @tab @code{integer(acc_handle_kind) async}
5176 @item @emph{Reference}:
5177 @uref{https://www.openacc.org, OpenACC specification v2.6}, section
5183 @node acc_wait_async
5184 @section @code{acc_wait_async} -- Wait for completion of asynchronous operations.
5186 @item @emph{Description}
5187 This function enqueues a wait operation on queue @var{async} for any and all
5188 asynchronous operations enqueued on queue @var{arg}.
5191 @multitable @columnfractions .20 .80
5192 @item @emph{Prototype}: @tab @code{acc_wait_async(int arg, int async);}
5195 @item @emph{Fortran}:
5196 @multitable @columnfractions .20 .80
5197 @item @emph{Interface}: @tab @code{subroutine acc_wait_async(arg, async)}
5198 @item @tab @code{integer(acc_handle_kind) arg, async}
5201 @item @emph{Reference}:
5202 @uref{https://www.openacc.org, OpenACC specification v2.6}, section
5209 @section @code{acc_init} -- Initialize runtime for a specific device type.
5211 @item @emph{Description}
5212 This function initializes the runtime for the device type specified in
5216 @multitable @columnfractions .20 .80
5217 @item @emph{Prototype}: @tab @code{acc_init(acc_device_t devicetype);}
5220 @item @emph{Fortran}:
5221 @multitable @columnfractions .20 .80
5222 @item @emph{Interface}: @tab @code{subroutine acc_init(devicetype)}
5223 @item @tab @code{integer(acc_device_kind) devicetype}
5226 @item @emph{Reference}:
5227 @uref{https://www.openacc.org, OpenACC specification v2.6}, section
5234 @section @code{acc_shutdown} -- Shuts down the runtime for a specific device type.
5236 @item @emph{Description}
5237 This function shuts down the runtime for the device type specified in
5241 @multitable @columnfractions .20 .80
5242 @item @emph{Prototype}: @tab @code{acc_shutdown(acc_device_t devicetype);}
5245 @item @emph{Fortran}:
5246 @multitable @columnfractions .20 .80
5247 @item @emph{Interface}: @tab @code{subroutine acc_shutdown(devicetype)}
5248 @item @tab @code{integer(acc_device_kind) devicetype}
5251 @item @emph{Reference}:
5252 @uref{https://www.openacc.org, OpenACC specification v2.6}, section
5259 @section @code{acc_on_device} -- Whether executing on a particular device
5261 @item @emph{Description}:
5262 This function returns whether the program is executing on a particular
5263 device specified in @var{devicetype}. In C/C++ a non-zero value is
5264 returned to indicate the device is executing on the specified device type.
5265 In Fortran, @code{true} is returned. If the program is not executing
5266 on the specified device type C/C++ returns zero, while Fortran
5267 returns @code{false}.
5269 Note that in GCC, depending on @var{devicetype}, the function call might
5270 be folded to a constant in the compiler; compile with
5271 @option{-fno-builtin-acc_on_device} if a run-time function is desired.
5274 @multitable @columnfractions .20 .80
5275 @item @emph{Prototype}: @tab @code{acc_on_device(acc_device_t devicetype);}
5278 @item @emph{Fortran}:
5279 @multitable @columnfractions .20 .80
5280 @item @emph{Interface}: @tab @code{function acc_on_device(devicetype)}
5281 @item @tab @code{integer(acc_device_kind) devicetype}
5282 @item @tab @code{logical acc_on_device}
5285 @item @emph{Reference}:
5286 @uref{https://www.openacc.org, OpenACC specification v2.6}, section
5293 @section @code{acc_malloc} -- Allocate device memory.
5295 @item @emph{Description}
5296 This function allocates @var{bytes} bytes of device memory. It returns
5297 the device address of the allocated memory.
5300 @multitable @columnfractions .20 .80
5301 @item @emph{Prototype}: @tab @code{d_void* acc_malloc(size_t bytes);}
5304 @item @emph{Fortran}:
5305 @multitable @columnfractions .20 .80
5306 @item @emph{Interface}: @tab @code{type(c_ptr) function acc_malloc(bytes)}
5307 @item @tab @code{integer(c_size_t), value :: bytes}
5310 @item @emph{Reference}:
5311 @uref{https://www.openacc.org, OpenACC specification v2.6}, section
5312 3.2.18. @uref{https://www.openacc.org, openacc specification v3.3}, section
5319 @section @code{acc_free} -- Free device memory.
5321 @item @emph{Description}
5322 Free previously allocated device memory at the device address @code{data_dev}.
5325 @multitable @columnfractions .20 .80
5326 @item @emph{Prototype}: @tab @code{void acc_free(d_void *data_dev);}
5329 @item @emph{Fortran}:
5330 @multitable @columnfractions .20 .80
5331 @item @emph{Interface}: @tab @code{subroutine acc_free(data_dev)}
5332 @item @tab @code{type(c_ptr), value :: data_dev}
5335 @item @emph{Reference}:
5336 @uref{https://www.openacc.org, OpenACC specification v2.6}, section
5337 3.2.19. @uref{https://www.openacc.org, openacc specification v3.3}, section
5344 @section @code{acc_copyin} -- Allocate device memory and copy host memory to it.
5346 @item @emph{Description}
5347 In C/C++, this function allocates @var{len} bytes of device memory
5348 and maps it to the specified host address in @var{a}. The device
5349 address of the newly allocated device memory is returned.
5351 In Fortran, two (2) forms are supported. In the first form, @var{a} specifies
5352 a contiguous array section. The second form @var{a} specifies a
5353 variable or array element and @var{len} specifies the length in bytes.
5356 @multitable @columnfractions .20 .80
5357 @item @emph{Prototype}: @tab @code{void *acc_copyin(h_void *a, size_t len);}
5358 @item @emph{Prototype}: @tab @code{void *acc_copyin_async(h_void *a, size_t len, int async);}
5361 @item @emph{Fortran}:
5362 @multitable @columnfractions .20 .80
5363 @item @emph{Interface}: @tab @code{subroutine acc_copyin(a)}
5364 @item @tab @code{type, dimension(:[,:]...) :: a}
5365 @item @emph{Interface}: @tab @code{subroutine acc_copyin(a, len)}
5366 @item @tab @code{type, dimension(:[,:]...) :: a}
5367 @item @tab @code{integer len}
5368 @item @emph{Interface}: @tab @code{subroutine acc_copyin_async(a, async)}
5369 @item @tab @code{type, dimension(:[,:]...) :: a}
5370 @item @tab @code{integer(acc_handle_kind) :: async}
5371 @item @emph{Interface}: @tab @code{subroutine acc_copyin_async(a, len, async)}
5372 @item @tab @code{type, dimension(:[,:]...) :: a}
5373 @item @tab @code{integer len}
5374 @item @tab @code{integer(acc_handle_kind) :: async}
5377 @item @emph{Reference}:
5378 @uref{https://www.openacc.org, OpenACC specification v2.6}, section
5384 @node acc_present_or_copyin
5385 @section @code{acc_present_or_copyin} -- If the data is not present on the device, allocate device memory and copy from host memory.
5387 @item @emph{Description}
5388 This function tests if the host data specified by @var{a} and of length
5389 @var{len} is present or not. If it is not present, device memory
5390 is allocated and the host memory copied. The device address of
5391 the newly allocated device memory is returned.
5393 In Fortran, two (2) forms are supported. In the first form, @var{a} specifies
5394 a contiguous array section. The second form @var{a} specifies a variable or
5395 array element and @var{len} specifies the length in bytes.
5397 Note that @code{acc_present_or_copyin} and @code{acc_pcopyin} exist for
5398 backward compatibility with OpenACC 2.0; use @ref{acc_copyin} instead.
5401 @multitable @columnfractions .20 .80
5402 @item @emph{Prototype}: @tab @code{void *acc_present_or_copyin(h_void *a, size_t len);}
5403 @item @emph{Prototype}: @tab @code{void *acc_pcopyin(h_void *a, size_t len);}
5406 @item @emph{Fortran}:
5407 @multitable @columnfractions .20 .80
5408 @item @emph{Interface}: @tab @code{subroutine acc_present_or_copyin(a)}
5409 @item @tab @code{type, dimension(:[,:]...) :: a}
5410 @item @emph{Interface}: @tab @code{subroutine acc_present_or_copyin(a, len)}
5411 @item @tab @code{type, dimension(:[,:]...) :: a}
5412 @item @tab @code{integer len}
5413 @item @emph{Interface}: @tab @code{subroutine acc_pcopyin(a)}
5414 @item @tab @code{type, dimension(:[,:]...) :: a}
5415 @item @emph{Interface}: @tab @code{subroutine acc_pcopyin(a, len)}
5416 @item @tab @code{type, dimension(:[,:]...) :: a}
5417 @item @tab @code{integer len}
5420 @item @emph{Reference}:
5421 @uref{https://www.openacc.org, OpenACC specification v2.6}, section
5428 @section @code{acc_create} -- Allocate device memory and map it to host memory.
5430 @item @emph{Description}
5431 This function allocates device memory and maps it to host memory specified
5432 by the host address @var{a} with a length of @var{len} bytes. In C/C++,
5433 the function returns the device address of the allocated device memory.
5435 In Fortran, two (2) forms are supported. In the first form, @var{a} specifies
5436 a contiguous array section. The second form @var{a} specifies a variable or
5437 array element and @var{len} specifies the length in bytes.
5440 @multitable @columnfractions .20 .80
5441 @item @emph{Prototype}: @tab @code{void *acc_create(h_void *a, size_t len);}
5442 @item @emph{Prototype}: @tab @code{void *acc_create_async(h_void *a, size_t len, int async);}
5445 @item @emph{Fortran}:
5446 @multitable @columnfractions .20 .80
5447 @item @emph{Interface}: @tab @code{subroutine acc_create(a)}
5448 @item @tab @code{type, dimension(:[,:]...) :: a}
5449 @item @emph{Interface}: @tab @code{subroutine acc_create(a, len)}
5450 @item @tab @code{type, dimension(:[,:]...) :: a}
5451 @item @tab @code{integer len}
5452 @item @emph{Interface}: @tab @code{subroutine acc_create_async(a, async)}
5453 @item @tab @code{type, dimension(:[,:]...) :: a}
5454 @item @tab @code{integer(acc_handle_kind) :: async}
5455 @item @emph{Interface}: @tab @code{subroutine acc_create_async(a, len, async)}
5456 @item @tab @code{type, dimension(:[,:]...) :: a}
5457 @item @tab @code{integer len}
5458 @item @tab @code{integer(acc_handle_kind) :: async}
5461 @item @emph{Reference}:
5462 @uref{https://www.openacc.org, OpenACC specification v2.6}, section
5468 @node acc_present_or_create
5469 @section @code{acc_present_or_create} -- If the data is not present on the device, allocate device memory and map it to host memory.
5471 @item @emph{Description}
5472 This function tests if the host data specified by @var{a} and of length
5473 @var{len} is present or not. If it is not present, device memory
5474 is allocated and mapped to host memory. In C/C++, the device address
5475 of the newly allocated device memory is returned.
5477 In Fortran, two (2) forms are supported. In the first form, @var{a} specifies
5478 a contiguous array section. The second form @var{a} specifies a variable or
5479 array element and @var{len} specifies the length in bytes.
5481 Note that @code{acc_present_or_create} and @code{acc_pcreate} exist for
5482 backward compatibility with OpenACC 2.0; use @ref{acc_create} instead.
5485 @multitable @columnfractions .20 .80
5486 @item @emph{Prototype}: @tab @code{void *acc_present_or_create(h_void *a, size_t len)}
5487 @item @emph{Prototype}: @tab @code{void *acc_pcreate(h_void *a, size_t len)}
5490 @item @emph{Fortran}:
5491 @multitable @columnfractions .20 .80
5492 @item @emph{Interface}: @tab @code{subroutine acc_present_or_create(a)}
5493 @item @tab @code{type, dimension(:[,:]...) :: a}
5494 @item @emph{Interface}: @tab @code{subroutine acc_present_or_create(a, len)}
5495 @item @tab @code{type, dimension(:[,:]...) :: a}
5496 @item @tab @code{integer len}
5497 @item @emph{Interface}: @tab @code{subroutine acc_pcreate(a)}
5498 @item @tab @code{type, dimension(:[,:]...) :: a}
5499 @item @emph{Interface}: @tab @code{subroutine acc_pcreate(a, len)}
5500 @item @tab @code{type, dimension(:[,:]...) :: a}
5501 @item @tab @code{integer len}
5504 @item @emph{Reference}:
5505 @uref{https://www.openacc.org, OpenACC specification v2.6}, section
5512 @section @code{acc_copyout} -- Copy device memory to host memory.
5514 @item @emph{Description}
5515 This function copies mapped device memory to host memory which is specified
5516 by host address @var{a} for a length @var{len} bytes in C/C++.
5518 In Fortran, two (2) forms are supported. In the first form, @var{a} specifies
5519 a contiguous array section. The second form @var{a} specifies a variable or
5520 array element and @var{len} specifies the length in bytes.
5523 @multitable @columnfractions .20 .80
5524 @item @emph{Prototype}: @tab @code{acc_copyout(h_void *a, size_t len);}
5525 @item @emph{Prototype}: @tab @code{acc_copyout_async(h_void *a, size_t len, int async);}
5526 @item @emph{Prototype}: @tab @code{acc_copyout_finalize(h_void *a, size_t len);}
5527 @item @emph{Prototype}: @tab @code{acc_copyout_finalize_async(h_void *a, size_t len, int async);}
5530 @item @emph{Fortran}:
5531 @multitable @columnfractions .20 .80
5532 @item @emph{Interface}: @tab @code{subroutine acc_copyout(a)}
5533 @item @tab @code{type, dimension(:[,:]...) :: a}
5534 @item @emph{Interface}: @tab @code{subroutine acc_copyout(a, len)}
5535 @item @tab @code{type, dimension(:[,:]...) :: a}
5536 @item @tab @code{integer len}
5537 @item @emph{Interface}: @tab @code{subroutine acc_copyout_async(a, async)}
5538 @item @tab @code{type, dimension(:[,:]...) :: a}
5539 @item @tab @code{integer(acc_handle_kind) :: async}
5540 @item @emph{Interface}: @tab @code{subroutine acc_copyout_async(a, len, async)}
5541 @item @tab @code{type, dimension(:[,:]...) :: a}
5542 @item @tab @code{integer len}
5543 @item @tab @code{integer(acc_handle_kind) :: async}
5544 @item @emph{Interface}: @tab @code{subroutine acc_copyout_finalize(a)}
5545 @item @tab @code{type, dimension(:[,:]...) :: a}
5546 @item @emph{Interface}: @tab @code{subroutine acc_copyout_finalize(a, len)}
5547 @item @tab @code{type, dimension(:[,:]...) :: a}
5548 @item @tab @code{integer len}
5549 @item @emph{Interface}: @tab @code{subroutine acc_copyout_finalize_async(a, async)}
5550 @item @tab @code{type, dimension(:[,:]...) :: a}
5551 @item @tab @code{integer(acc_handle_kind) :: async}
5552 @item @emph{Interface}: @tab @code{subroutine acc_copyout_finalize_async(a, len, async)}
5553 @item @tab @code{type, dimension(:[,:]...) :: a}
5554 @item @tab @code{integer len}
5555 @item @tab @code{integer(acc_handle_kind) :: async}
5558 @item @emph{Reference}:
5559 @uref{https://www.openacc.org, OpenACC specification v2.6}, section
5566 @section @code{acc_delete} -- Free device memory.
5568 @item @emph{Description}
5569 This function frees previously allocated device memory specified by
5570 the device address @var{a} and the length of @var{len} bytes.
5572 In Fortran, two (2) forms are supported. In the first form, @var{a} specifies
5573 a contiguous array section. The second form @var{a} specifies a variable or
5574 array element and @var{len} specifies the length in bytes.
5577 @multitable @columnfractions .20 .80
5578 @item @emph{Prototype}: @tab @code{acc_delete(h_void *a, size_t len);}
5579 @item @emph{Prototype}: @tab @code{acc_delete_async(h_void *a, size_t len, int async);}
5580 @item @emph{Prototype}: @tab @code{acc_delete_finalize(h_void *a, size_t len);}
5581 @item @emph{Prototype}: @tab @code{acc_delete_finalize_async(h_void *a, size_t len, int async);}
5584 @item @emph{Fortran}:
5585 @multitable @columnfractions .20 .80
5586 @item @emph{Interface}: @tab @code{subroutine acc_delete(a)}
5587 @item @tab @code{type, dimension(:[,:]...) :: a}
5588 @item @emph{Interface}: @tab @code{subroutine acc_delete(a, len)}
5589 @item @tab @code{type, dimension(:[,:]...) :: a}
5590 @item @tab @code{integer len}
5591 @item @emph{Interface}: @tab @code{subroutine acc_delete_async(a, async)}
5592 @item @tab @code{type, dimension(:[,:]...) :: a}
5593 @item @tab @code{integer(acc_handle_kind) :: async}
5594 @item @emph{Interface}: @tab @code{subroutine acc_delete_async(a, len, async)}
5595 @item @tab @code{type, dimension(:[,:]...) :: a}
5596 @item @tab @code{integer len}
5597 @item @tab @code{integer(acc_handle_kind) :: async}
5598 @item @emph{Interface}: @tab @code{subroutine acc_delete_finalize(a)}
5599 @item @tab @code{type, dimension(:[,:]...) :: a}
5600 @item @emph{Interface}: @tab @code{subroutine acc_delete_finalize(a, len)}
5601 @item @tab @code{type, dimension(:[,:]...) :: a}
5602 @item @tab @code{integer len}
5603 @item @emph{Interface}: @tab @code{subroutine acc_delete_async_finalize(a, async)}
5604 @item @tab @code{type, dimension(:[,:]...) :: a}
5605 @item @tab @code{integer(acc_handle_kind) :: async}
5606 @item @emph{Interface}: @tab @code{subroutine acc_delete_async_finalize(a, len, async)}
5607 @item @tab @code{type, dimension(:[,:]...) :: a}
5608 @item @tab @code{integer len}
5609 @item @tab @code{integer(acc_handle_kind) :: async}
5612 @item @emph{Reference}:
5613 @uref{https://www.openacc.org, OpenACC specification v2.6}, section
5619 @node acc_update_device
5620 @section @code{acc_update_device} -- Update device memory from mapped host memory.
5622 @item @emph{Description}
5623 This function updates the device copy from the previously mapped host memory.
5624 The host memory is specified with the host address @var{a} and a length of
5627 In Fortran, two (2) forms are supported. In the first form, @var{a} specifies
5628 a contiguous array section. The second form @var{a} specifies a variable or
5629 array element and @var{len} specifies the length in bytes.
5632 @multitable @columnfractions .20 .80
5633 @item @emph{Prototype}: @tab @code{acc_update_device(h_void *a, size_t len);}
5634 @item @emph{Prototype}: @tab @code{acc_update_device(h_void *a, size_t len, async);}
5637 @item @emph{Fortran}:
5638 @multitable @columnfractions .20 .80
5639 @item @emph{Interface}: @tab @code{subroutine acc_update_device(a)}
5640 @item @tab @code{type, dimension(:[,:]...) :: a}
5641 @item @emph{Interface}: @tab @code{subroutine acc_update_device(a, len)}
5642 @item @tab @code{type, dimension(:[,:]...) :: a}
5643 @item @tab @code{integer len}
5644 @item @emph{Interface}: @tab @code{subroutine acc_update_device_async(a, async)}
5645 @item @tab @code{type, dimension(:[,:]...) :: a}
5646 @item @tab @code{integer(acc_handle_kind) :: async}
5647 @item @emph{Interface}: @tab @code{subroutine acc_update_device_async(a, len, async)}
5648 @item @tab @code{type, dimension(:[,:]...) :: a}
5649 @item @tab @code{integer len}
5650 @item @tab @code{integer(acc_handle_kind) :: async}
5653 @item @emph{Reference}:
5654 @uref{https://www.openacc.org, OpenACC specification v2.6}, section
5660 @node acc_update_self
5661 @section @code{acc_update_self} -- Update host memory from mapped device memory.
5663 @item @emph{Description}
5664 This function updates the host copy from the previously mapped device memory.
5665 The host memory is specified with the host address @var{a} and a length of
5668 In Fortran, two (2) forms are supported. In the first form, @var{a} specifies
5669 a contiguous array section. The second form @var{a} specifies a variable or
5670 array element and @var{len} specifies the length in bytes.
5673 @multitable @columnfractions .20 .80
5674 @item @emph{Prototype}: @tab @code{acc_update_self(h_void *a, size_t len);}
5675 @item @emph{Prototype}: @tab @code{acc_update_self_async(h_void *a, size_t len, int async);}
5678 @item @emph{Fortran}:
5679 @multitable @columnfractions .20 .80
5680 @item @emph{Interface}: @tab @code{subroutine acc_update_self(a)}
5681 @item @tab @code{type, dimension(:[,:]...) :: a}
5682 @item @emph{Interface}: @tab @code{subroutine acc_update_self(a, len)}
5683 @item @tab @code{type, dimension(:[,:]...) :: a}
5684 @item @tab @code{integer len}
5685 @item @emph{Interface}: @tab @code{subroutine acc_update_self_async(a, async)}
5686 @item @tab @code{type, dimension(:[,:]...) :: a}
5687 @item @tab @code{integer(acc_handle_kind) :: async}
5688 @item @emph{Interface}: @tab @code{subroutine acc_update_self_async(a, len, async)}
5689 @item @tab @code{type, dimension(:[,:]...) :: a}
5690 @item @tab @code{integer len}
5691 @item @tab @code{integer(acc_handle_kind) :: async}
5694 @item @emph{Reference}:
5695 @uref{https://www.openacc.org, OpenACC specification v2.6}, section
5702 @section @code{acc_map_data} -- Map previously allocated device memory to host memory.
5704 @item @emph{Description}
5705 This function maps previously allocated device and host memory. The device
5706 memory is specified with the device address @var{data_dev}. The host memory is
5707 specified with the host address @var{data_arg} and a length of @var{bytes}.
5710 @multitable @columnfractions .20 .80
5711 @item @emph{Prototype}: @tab @code{void acc_map_data(h_void *data_arg, d_void *data_dev, size_t bytes);}
5714 @item @emph{Fortran}:
5715 @multitable @columnfractions .20 .80
5716 @item @emph{Interface}: @tab @code{subroutine acc_map_data(data_arg, data_dev, bytes)}
5717 @item @tab @code{type(*), dimension(*) :: data_arg}
5718 @item @tab @code{type(c_ptr), value :: data_dev}
5719 @item @tab @code{integer(c_size_t), value :: bytes}
5722 @item @emph{Reference}:
5723 @uref{https://www.openacc.org, OpenACC specification v2.6}, section
5724 3.2.26. @uref{https://www.openacc.org, OpenACC specification v3.3}, section
5730 @node acc_unmap_data
5731 @section @code{acc_unmap_data} -- Unmap device memory from host memory.
5733 @item @emph{Description}
5734 This function unmaps previously mapped device and host memory. The latter
5735 specified by @var{data_arg}.
5738 @multitable @columnfractions .20 .80
5739 @item @emph{Prototype}: @tab @code{void acc_unmap_data(h_void *data_arg);}
5742 @item @emph{Fortran}:
5743 @multitable @columnfractions .20 .80
5744 @item @emph{Interface}: @tab @code{subroutine acc_unmap_data(data_arg)}
5745 @item @tab @code{type(*), dimension(*) :: data_arg}
5748 @item @emph{Reference}:
5749 @uref{https://www.openacc.org, OpenACC specification v2.6}, section
5750 3.2.27. @uref{https://www.openacc.org, OpenACC specification v3.3}, section
5757 @section @code{acc_deviceptr} -- Get device pointer associated with specific host address.
5759 @item @emph{Description}
5760 This function returns the device address that has been mapped to the
5761 host address specified by @var{data_arg}.
5764 @multitable @columnfractions .20 .80
5765 @item @emph{Prototype}: @tab @code{void *acc_deviceptr(h_void *data_arg);}
5768 @item @emph{Fortran}:
5769 @multitable @columnfractions .20 .80
5770 @item @emph{Interface}: @tab @code{type(c_ptr) function acc_deviceptr(data_arg)}
5771 @item @tab @code{type(*), dimension(*) :: data_arg}
5774 @item @emph{Reference}:
5775 @uref{https://www.openacc.org, OpenACC specification v2.6}, section
5776 3.2.28. @uref{https://www.openacc.org, OpenACC specification v3.3}, section
5783 @section @code{acc_hostptr} -- Get host pointer associated with specific device address.
5785 @item @emph{Description}
5786 This function returns the host address that has been mapped to the
5787 device address specified by @var{data_dev}.
5790 @multitable @columnfractions .20 .80
5791 @item @emph{Prototype}: @tab @code{void *acc_hostptr(d_void *data_dev);}
5794 @item @emph{Fortran}:
5795 @multitable @columnfractions .20 .80
5796 @item @emph{Interface}: @tab @code{type(c_ptr) function acc_hostptr(data_dev)}
5797 @item @tab @code{type(c_ptr), value :: data_dev}
5800 @item @emph{Reference}:
5801 @uref{https://www.openacc.org, OpenACC specification v2.6}, section
5802 3.2.29. @uref{https://www.openacc.org, OpenACC specification v3.3}, section
5808 @node acc_is_present
5809 @section @code{acc_is_present} -- Indicate whether host variable / array is present on device.
5811 @item @emph{Description}
5812 This function indicates whether the specified host address in @var{a} and a
5813 length of @var{len} bytes is present on the device. In C/C++, a non-zero
5814 value is returned to indicate the presence of the mapped memory on the
5815 device. A zero is returned to indicate the memory is not mapped on the
5818 In Fortran, two (2) forms are supported. In the first form, @var{a} specifies
5819 a contiguous array section. The second form @var{a} specifies a variable or
5820 array element and @var{len} specifies the length in bytes. If the host
5821 memory is mapped to device memory, then a @code{true} is returned. Otherwise,
5822 a @code{false} is return to indicate the mapped memory is not present.
5825 @multitable @columnfractions .20 .80
5826 @item @emph{Prototype}: @tab @code{int acc_is_present(h_void *a, size_t len);}
5829 @item @emph{Fortran}:
5830 @multitable @columnfractions .20 .80
5831 @item @emph{Interface}: @tab @code{function acc_is_present(a)}
5832 @item @tab @code{type, dimension(:[,:]...) :: a}
5833 @item @tab @code{logical acc_is_present}
5834 @item @emph{Interface}: @tab @code{function acc_is_present(a, len)}
5835 @item @tab @code{type, dimension(:[,:]...) :: a}
5836 @item @tab @code{integer len}
5837 @item @tab @code{logical acc_is_present}
5840 @item @emph{Reference}:
5841 @uref{https://www.openacc.org, OpenACC specification v2.6}, section
5847 @node acc_memcpy_to_device
5848 @section @code{acc_memcpy_to_device} -- Copy host memory to device memory.
5850 @item @emph{Description}
5851 This function copies host memory specified by host address of
5852 @var{data_host_src} to device memory specified by the device address
5853 @var{data_dev_dest} for a length of @var{bytes} bytes.
5856 @multitable @columnfractions .20 .80
5857 @item @emph{Prototype}: @tab @code{void acc_memcpy_to_device(d_void* data_dev_dest,}
5858 @item @tab @code{h_void* data_host_src, size_t bytes);}
5859 @item @emph{Prototype}: @tab @code{void acc_memcpy_to_device_async(d_void* data_dev_dest,}
5860 @item @tab @code{h_void* data_host_src, size_t bytes, int async_arg);}
5863 @item @emph{Fortran}:
5864 @multitable @columnfractions .20 .80
5865 @item @emph{Interface}: @tab @code{subroutine acc_memcpy_to_device(data_dev_dest, &}
5866 @item @tab @code{data_host_src, bytes)}
5867 @item @emph{Interface}: @tab @code{subroutine acc_memcpy_to_device_async(data_dev_dest, &}
5868 @item @tab @code{data_host_src, bytes, async_arg)}
5869 @item @tab @code{type(c_ptr), value :: data_dev_dest}
5870 @item @tab @code{type(*), dimension(*) :: data_host_src}
5871 @item @tab @code{integer(c_size_t), value :: bytes}
5872 @item @tab @code{integer(acc_handle_kind), value :: async_arg}
5875 @item @emph{Reference}:
5876 @uref{https://www.openacc.org, OpenACC specification v2.6}, section
5877 3.2.31 @uref{https://www.openacc.org, OpenACC specification v3.3}, section
5883 @node acc_memcpy_from_device
5884 @section @code{acc_memcpy_from_device} -- Copy device memory to host memory.
5886 @item @emph{Description}
5887 This function copies device memory specified by device address of
5888 @var{data_dev_src} to host memory specified by the host address
5889 @var{data_host_dest} for a length of @var{bytes} bytes.
5892 @multitable @columnfractions .20 .80
5893 @item @emph{Prototype}: @tab @code{void acc_memcpy_from_device(h_void* data_host_dest,}
5894 @item @tab @code{d_void* data_dev_src, size_t bytes);}
5895 @item @emph{Prototype}: @tab @code{void acc_memcpy_from_device_async(h_void* data_host_dest,}
5896 @item @tab @code{d_void* data_dev_src, size_t bytes, int async_arg);}
5899 @item @emph{Fortran}:
5900 @multitable @columnfractions .20 .80
5901 @item @emph{Interface}: @tab @code{subroutine acc_memcpy_from_device(data_host_dest, &}
5902 @item @tab @code{data_dev_src, bytes)}
5903 @item @emph{Interface}: @tab @code{subroutine acc_memcpy_from_device_async(data_host_dest, &}
5904 @item @tab @code{data_dev_src, bytes, async_arg)}
5905 @item @tab @code{type(*), dimension(*) :: data_host_dest}
5906 @item @tab @code{type(c_ptr), value :: data_dev_src}
5907 @item @tab @code{integer(c_size_t), value :: bytes}
5908 @item @tab @code{integer(acc_handle_kind), value :: async_arg}
5911 @item @emph{Reference}:
5912 @uref{https://www.openacc.org, OpenACC specification v2.6}, section
5913 3.2.32. @uref{https://www.openacc.org, OpenACC specification v3.3}, section
5919 @node acc_memcpy_device
5920 @section @code{acc_memcpy_device} -- Copy memory within a device.
5922 @item @emph{Description}
5923 This function copies device memory from one memory location to another
5924 on the current device. It copies @var{bytes} bytes of data from the device
5925 address, specified by @var{data_dev_src}, to the device address
5926 @var{data_dev_dest}. The @code{_async} version performs the transfer
5927 asynchronously using the queue associated with @var{async_arg}.
5930 @multitable @columnfractions .20 .80
5931 @item @emph{Prototype}: @tab @code{void acc_memcpy_device(d_void* data_dev_dest,}
5932 @item @tab @code{d_void* data_dev_src, size_t bytes);}
5933 @item @emph{Prototype}: @tab @code{void acc_memcpy_device_async(d_void* data_dev_dest,}
5934 @item @tab @code{d_void* data_dev_src, size_t bytes, int async_arg);}
5937 @item @emph{Fortran}:
5938 @multitable @columnfractions .20 .80
5939 @item @emph{Interface}: @tab @code{subroutine acc_memcpy_device(data_dev_dest, &}
5940 @item @tab @code{data_dev_src, bytes)}
5941 @item @emph{Interface}: @tab @code{subroutine acc_memcpy_device_async(data_dev_dest, &}
5942 @item @tab @code{data_dev_src, bytes, async_arg)}
5943 @item @tab @code{type(c_ptr), value :: data_dev_dest}
5944 @item @tab @code{type(c_ptr), value :: data_dev_src}
5945 @item @tab @code{integer(c_size_t), value :: bytes}
5946 @item @tab @code{integer(acc_handle_kind), value :: async_arg}
5949 @item @emph{Reference}:
5950 @uref{https://www.openacc.org, OpenACC specification v2.6}, section
5951 3.2.33. @uref{https://www.openacc.org, OpenACC specification v3.3}, section
5958 @section @code{acc_attach} -- Let device pointer point to device-pointer target.
5960 @item @emph{Description}
5961 This function updates a pointer on the device from pointing to a host-pointer
5962 address to pointing to the corresponding device data.
5965 @multitable @columnfractions .20 .80
5966 @item @emph{Prototype}: @tab @code{void acc_attach(h_void **ptr_addr);}
5967 @item @emph{Prototype}: @tab @code{void acc_attach_async(h_void **ptr_addr, int async);}
5970 @item @emph{Fortran}:
5971 @multitable @columnfractions .20 .80
5972 @item @emph{Interface}: @tab @code{subroutine acc_attach(ptr_addr)}
5973 @item @emph{Interface}: @tab @code{subroutine acc_attach_async(ptr_addr, async_arg)}
5974 @item @tab @code{type(*), dimension(..) :: ptr_addr}
5975 @item @tab @code{integer(acc_handle_kind), value :: async_arg}
5978 @item @emph{Reference}:
5979 @uref{https://www.openacc.org, OpenACC specification v2.6}, section
5981 @uref{https://www.openacc.org, OpenACC specification v3.3}, section
5988 @section @code{acc_detach} -- Let device pointer point to host-pointer target.
5990 @item @emph{Description}
5991 This function updates a pointer on the device from pointing to a device-pointer
5992 address to pointing to the corresponding host data.
5995 @multitable @columnfractions .20 .80
5996 @item @emph{Prototype}: @tab @code{void acc_detach(h_void **ptr_addr);}
5997 @item @emph{Prototype}: @tab @code{void acc_detach_async(h_void **ptr_addr, int async);}
5998 @item @emph{Prototype}: @tab @code{void acc_detach_finalize(h_void **ptr_addr);}
5999 @item @emph{Prototype}: @tab @code{void acc_detach_finalize_async(h_void **ptr_addr, int async);}
6002 @item @emph{Fortran}:
6003 @multitable @columnfractions .20 .80
6004 @item @emph{Interface}: @tab @code{subroutine acc_detach(ptr_addr)}
6005 @item @emph{Interface}: @tab @code{subroutine acc_detach_async(ptr_addr, async_arg)}
6006 @item @emph{Interface}: @tab @code{subroutine acc_detach_finalize(ptr_addr)}
6007 @item @emph{Interface}: @tab @code{subroutine acc_detach_finalize_async(ptr_addr, async_arg)}
6008 @item @tab @code{type(*), dimension(..) :: ptr_addr}
6009 @item @tab @code{integer(acc_handle_kind), value :: async_arg}
6012 @item @emph{Reference}:
6013 @uref{https://www.openacc.org, OpenACC specification v2.6}, section
6015 @uref{https://www.openacc.org, OpenACC specification v3.3}, section
6021 @node acc_get_current_cuda_device
6022 @section @code{acc_get_current_cuda_device} -- Get CUDA device handle.
6024 @item @emph{Description}
6025 This function returns the CUDA device handle. This handle is the same
6026 as used by the CUDA Runtime or Driver API's.
6029 @multitable @columnfractions .20 .80
6030 @item @emph{Prototype}: @tab @code{void *acc_get_current_cuda_device(void);}
6033 @item @emph{Reference}:
6034 @uref{https://www.openacc.org, OpenACC specification v2.6}, section
6040 @node acc_get_current_cuda_context
6041 @section @code{acc_get_current_cuda_context} -- Get CUDA context handle.
6043 @item @emph{Description}
6044 This function returns the CUDA context handle. This handle is the same
6045 as used by the CUDA Runtime or Driver API's.
6048 @multitable @columnfractions .20 .80
6049 @item @emph{Prototype}: @tab @code{void *acc_get_current_cuda_context(void);}
6052 @item @emph{Reference}:
6053 @uref{https://www.openacc.org, OpenACC specification v2.6}, section
6059 @node acc_get_cuda_stream
6060 @section @code{acc_get_cuda_stream} -- Get CUDA stream handle.
6062 @item @emph{Description}
6063 This function returns the CUDA stream handle for the queue @var{async}.
6064 This handle is the same as used by the CUDA Runtime or Driver API's.
6067 @multitable @columnfractions .20 .80
6068 @item @emph{Prototype}: @tab @code{void *acc_get_cuda_stream(int async);}
6071 @item @emph{Reference}:
6072 @uref{https://www.openacc.org, OpenACC specification v2.6}, section
6078 @node acc_set_cuda_stream
6079 @section @code{acc_set_cuda_stream} -- Set CUDA stream handle.
6081 @item @emph{Description}
6082 This function associates the stream handle specified by @var{stream} with
6083 the queue @var{async}.
6085 This cannot be used to change the stream handle associated with
6086 @code{acc_async_sync}.
6088 The return value is not specified.
6091 @multitable @columnfractions .20 .80
6092 @item @emph{Prototype}: @tab @code{int acc_set_cuda_stream(int async, void *stream);}
6095 @item @emph{Reference}:
6096 @uref{https://www.openacc.org, OpenACC specification v2.6}, section
6102 @node acc_prof_register
6103 @section @code{acc_prof_register} -- Register callbacks.
6105 @item @emph{Description}:
6106 This function registers callbacks.
6109 @multitable @columnfractions .20 .80
6110 @item @emph{Prototype}: @tab @code{void acc_prof_register (acc_event_t, acc_prof_callback, acc_register_t);}
6113 @item @emph{See also}:
6114 @ref{OpenACC Profiling Interface}
6116 @item @emph{Reference}:
6117 @uref{https://www.openacc.org, OpenACC specification v2.6}, section
6123 @node acc_prof_unregister
6124 @section @code{acc_prof_unregister} -- Unregister callbacks.
6126 @item @emph{Description}:
6127 This function unregisters callbacks.
6130 @multitable @columnfractions .20 .80
6131 @item @emph{Prototype}: @tab @code{void acc_prof_unregister (acc_event_t, acc_prof_callback, acc_register_t);}
6134 @item @emph{See also}:
6135 @ref{OpenACC Profiling Interface}
6137 @item @emph{Reference}:
6138 @uref{https://www.openacc.org, OpenACC specification v2.6}, section
6144 @node acc_prof_lookup
6145 @section @code{acc_prof_lookup} -- Obtain inquiry functions.
6147 @item @emph{Description}:
6148 Function to obtain inquiry functions.
6151 @multitable @columnfractions .20 .80
6152 @item @emph{Prototype}: @tab @code{acc_query_fn acc_prof_lookup (const char *);}
6155 @item @emph{See also}:
6156 @ref{OpenACC Profiling Interface}
6158 @item @emph{Reference}:
6159 @uref{https://www.openacc.org, OpenACC specification v2.6}, section
6165 @node acc_register_library
6166 @section @code{acc_register_library} -- Library registration.
6168 @item @emph{Description}:
6169 Function for library registration.
6172 @multitable @columnfractions .20 .80
6173 @item @emph{Prototype}: @tab @code{void acc_register_library (acc_prof_reg, acc_prof_reg, acc_prof_lookup_func);}
6176 @item @emph{See also}:
6177 @ref{OpenACC Profiling Interface}, @ref{ACC_PROFLIB}
6179 @item @emph{Reference}:
6180 @uref{https://www.openacc.org, OpenACC specification v2.6}, section
6186 @c ---------------------------------------------------------------------
6187 @c OpenACC Environment Variables
6188 @c ---------------------------------------------------------------------
6190 @node OpenACC Environment Variables
6191 @chapter OpenACC Environment Variables
6193 The variables @env{ACC_DEVICE_TYPE} and @env{ACC_DEVICE_NUM}
6194 are defined by section 4 of the OpenACC specification in version 2.0.
6195 The variable @env{ACC_PROFLIB}
6196 is defined by section 4 of the OpenACC specification in version 2.6.
6206 @node ACC_DEVICE_TYPE
6207 @section @code{ACC_DEVICE_TYPE}
6209 @item @emph{Description}:
6210 Control the default device type to use when executing compute regions.
6211 If unset, the code can be run on any device type, favoring a non-host
6214 Supported values in GCC (if compiled in) are
6220 @item @emph{Reference}:
6221 @uref{https://www.openacc.org, OpenACC specification v2.6}, section
6227 @node ACC_DEVICE_NUM
6228 @section @code{ACC_DEVICE_NUM}
6230 @item @emph{Description}:
6231 Control which device, identified by device number, is the default device.
6232 The value must be a nonnegative integer less than the number of devices.
6233 If unset, device number zero is used.
6234 @item @emph{Reference}:
6235 @uref{https://www.openacc.org, OpenACC specification v2.6}, section
6242 @section @code{ACC_PROFLIB}
6244 @item @emph{Description}:
6245 Semicolon-separated list of dynamic libraries that are loaded as profiling
6246 libraries. Each library must provide at least the @code{acc_register_library}
6247 routine. Each library file is found as described by the documentation of
6248 @code{dlopen} of your operating system.
6249 @item @emph{See also}:
6250 @ref{acc_register_library}, @ref{OpenACC Profiling Interface}
6252 @item @emph{Reference}:
6253 @uref{https://www.openacc.org, OpenACC specification v2.6}, section
6259 @c ---------------------------------------------------------------------
6260 @c CUDA Streams Usage
6261 @c ---------------------------------------------------------------------
6263 @node CUDA Streams Usage
6264 @chapter CUDA Streams Usage
6266 This applies to the @code{nvptx} plugin only.
6268 The library provides elements that perform asynchronous movement of
6269 data and asynchronous operation of computing constructs. This
6270 asynchronous functionality is implemented by making use of CUDA
6271 streams@footnote{See "Stream Management" in "CUDA Driver API",
6272 TRM-06703-001, Version 5.5, for additional information}.
6274 The primary means by that the asynchronous functionality is accessed
6275 is through the use of those OpenACC directives which make use of the
6276 @code{async} and @code{wait} clauses. When the @code{async} clause is
6277 first used with a directive, it creates a CUDA stream. If an
6278 @code{async-argument} is used with the @code{async} clause, then the
6279 stream is associated with the specified @code{async-argument}.
6281 Following the creation of an association between a CUDA stream and the
6282 @code{async-argument} of an @code{async} clause, both the @code{wait}
6283 clause and the @code{wait} directive can be used. When either the
6284 clause or directive is used after stream creation, it creates a
6285 rendezvous point whereby execution waits until all operations
6286 associated with the @code{async-argument}, that is, stream, have
6289 Normally, the management of the streams that are created as a result of
6290 using the @code{async} clause, is done without any intervention by the
6291 caller. This implies the association between the @code{async-argument}
6292 and the CUDA stream is maintained for the lifetime of the program.
6293 However, this association can be changed through the use of the library
6294 function @code{acc_set_cuda_stream}. When the function
6295 @code{acc_set_cuda_stream} is called, the CUDA stream that was
6296 originally associated with the @code{async} clause is destroyed.
6297 Caution should be taken when changing the association as subsequent
6298 references to the @code{async-argument} refer to a different
6303 @c ---------------------------------------------------------------------
6304 @c OpenACC Library Interoperability
6305 @c ---------------------------------------------------------------------
6307 @node OpenACC Library Interoperability
6308 @chapter OpenACC Library Interoperability
6310 @section Introduction
6312 The OpenACC library uses the CUDA Driver API, and may interact with
6313 programs that use the Runtime library directly, or another library
6314 based on the Runtime library, e.g., CUBLAS@footnote{See section 2.26,
6315 "Interactions with the CUDA Driver API" in
6316 "CUDA Runtime API", Version 5.5, and section 2.27, "VDPAU
6317 Interoperability", in "CUDA Driver API", TRM-06703-001, Version 5.5,
6318 for additional information on library interoperability.}.
6319 This chapter describes the use cases and what changes are
6320 required in order to use both the OpenACC library and the CUBLAS and Runtime
6321 libraries within a program.
6323 @section First invocation: NVIDIA CUBLAS library API
6325 In this first use case (see below), a function in the CUBLAS library is called
6326 prior to any of the functions in the OpenACC library. More specifically, the
6327 function @code{cublasCreate()}.
6329 When invoked, the function initializes the library and allocates the
6330 hardware resources on the host and the device on behalf of the caller. Once
6331 the initialization and allocation has completed, a handle is returned to the
6332 caller. The OpenACC library also requires initialization and allocation of
6333 hardware resources. Since the CUBLAS library has already allocated the
6334 hardware resources for the device, all that is left to do is to initialize
6335 the OpenACC library and acquire the hardware resources on the host.
6337 Prior to calling the OpenACC function that initializes the library and
6338 allocate the host hardware resources, you need to acquire the device number
6339 that was allocated during the call to @code{cublasCreate()}. The invoking of the
6340 runtime library function @code{cudaGetDevice()} accomplishes this. Once
6341 acquired, the device number is passed along with the device type as
6342 parameters to the OpenACC library function @code{acc_set_device_num()}.
6344 Once the call to @code{acc_set_device_num()} has completed, the OpenACC
6345 library uses the context that was created during the call to
6346 @code{cublasCreate()}. In other words, both libraries share the
6350 /* Create the handle */
6351 s = cublasCreate(&h);
6352 if (s != CUBLAS_STATUS_SUCCESS)
6354 fprintf(stderr, "cublasCreate failed %d\n", s);
6358 /* Get the device number */
6359 e = cudaGetDevice(&dev);
6360 if (e != cudaSuccess)
6362 fprintf(stderr, "cudaGetDevice failed %d\n", e);
6366 /* Initialize OpenACC library and use device 'dev' */
6367 acc_set_device_num(dev, acc_device_nvidia);
6372 @section First invocation: OpenACC library API
6374 In this second use case (see below), a function in the OpenACC library is
6375 called prior to any of the functions in the CUBLAS library. More specifically,
6376 the function @code{acc_set_device_num()}.
6378 In the use case presented here, the function @code{acc_set_device_num()}
6379 is used to both initialize the OpenACC library and allocate the hardware
6380 resources on the host and the device. In the call to the function, the
6381 call parameters specify which device to use and what device
6382 type to use, i.e., @code{acc_device_nvidia}. It should be noted that this
6383 is but one method to initialize the OpenACC library and allocate the
6384 appropriate hardware resources. Other methods are available through the
6385 use of environment variables and these is discussed in the next section.
6387 Once the call to @code{acc_set_device_num()} has completed, other OpenACC
6388 functions can be called as seen with multiple calls being made to
6389 @code{acc_copyin()}. In addition, calls can be made to functions in the
6390 CUBLAS library. In the use case a call to @code{cublasCreate()} is made
6391 subsequent to the calls to @code{acc_copyin()}.
6392 As seen in the previous use case, a call to @code{cublasCreate()}
6393 initializes the CUBLAS library and allocates the hardware resources on the
6394 host and the device. However, since the device has already been allocated,
6395 @code{cublasCreate()} only initializes the CUBLAS library and allocates
6396 the appropriate hardware resources on the host. The context that was created
6397 as part of the OpenACC initialization is shared with the CUBLAS library,
6398 similarly to the first use case.
6403 acc_set_device_num(dev, acc_device_nvidia);
6405 /* Copy the first set to the device */
6406 d_X = acc_copyin(&h_X[0], N * sizeof (float));
6409 fprintf(stderr, "copyin error h_X\n");
6413 /* Copy the second set to the device */
6414 d_Y = acc_copyin(&h_Y1[0], N * sizeof (float));
6417 fprintf(stderr, "copyin error h_Y1\n");
6421 /* Create the handle */
6422 s = cublasCreate(&h);
6423 if (s != CUBLAS_STATUS_SUCCESS)
6425 fprintf(stderr, "cublasCreate failed %d\n", s);
6429 /* Perform saxpy using CUBLAS library function */
6430 s = cublasSaxpy(h, N, &alpha, d_X, 1, d_Y, 1);
6431 if (s != CUBLAS_STATUS_SUCCESS)
6433 fprintf(stderr, "cublasSaxpy failed %d\n", s);
6437 /* Copy the results from the device */
6438 acc_memcpy_from_device(&h_Y1[0], d_Y, N * sizeof (float));
6443 @section OpenACC library and environment variables
6445 There are two environment variables associated with the OpenACC library
6446 that may be used to control the device type and device number:
6447 @env{ACC_DEVICE_TYPE} and @env{ACC_DEVICE_NUM}, respectively. These two
6448 environment variables can be used as an alternative to calling
6449 @code{acc_set_device_num()}. As seen in the second use case, the device
6450 type and device number were specified using @code{acc_set_device_num()}.
6451 If however, the aforementioned environment variables were set, then the
6452 call to @code{acc_set_device_num()} would not be required.
6455 The use of the environment variables is only relevant when an OpenACC function
6456 is called prior to a call to @code{cudaCreate()}. If @code{cudaCreate()}
6457 is called prior to a call to an OpenACC function, then you must call
6458 @code{acc_set_device_num()}@footnote{More complete information
6459 about @env{ACC_DEVICE_TYPE} and @env{ACC_DEVICE_NUM} can be found in
6460 sections 4.1 and 4.2 of the @uref{https://www.openacc.org, OpenACC}
6461 Application Programming Interface”, Version 2.6.}
6465 @c ---------------------------------------------------------------------
6466 @c OpenACC Profiling Interface
6467 @c ---------------------------------------------------------------------
6469 @node OpenACC Profiling Interface
6470 @chapter OpenACC Profiling Interface
6472 @section Implementation Status and Implementation-Defined Behavior
6474 We're implementing the OpenACC Profiling Interface as defined by the
6475 OpenACC 2.6 specification. We're clarifying some aspects here as
6476 @emph{implementation-defined behavior}, while they're still under
6477 discussion within the OpenACC Technical Committee.
6479 This implementation is tuned to keep the performance impact as low as
6480 possible for the (very common) case that the Profiling Interface is
6481 not enabled. This is relevant, as the Profiling Interface affects all
6482 the @emph{hot} code paths (in the target code, not in the offloaded
6483 code). Users of the OpenACC Profiling Interface can be expected to
6484 understand that performance is impacted to some degree once the
6485 Profiling Interface is enabled: for example, because of the
6486 @emph{runtime} (libgomp) calling into a third-party @emph{library} for
6487 every event that has been registered.
6489 We're not yet accounting for the fact that @cite{OpenACC events may
6490 occur during event processing}.
6491 We just handle one case specially, as required by CUDA 9.0
6492 @command{nvprof}, that @code{acc_get_device_type}
6493 (@ref{acc_get_device_type})) may be called from
6494 @code{acc_ev_device_init_start}, @code{acc_ev_device_init_end}
6497 We're not yet implementing initialization via a
6498 @code{acc_register_library} function that is either statically linked
6499 in, or dynamically via @env{LD_PRELOAD}.
6500 Initialization via @code{acc_register_library} functions dynamically
6501 loaded via the @env{ACC_PROFLIB} environment variable does work, as
6502 does directly calling @code{acc_prof_register},
6503 @code{acc_prof_unregister}, @code{acc_prof_lookup}.
6505 As currently there are no inquiry functions defined, calls to
6506 @code{acc_prof_lookup} always returns @code{NULL}.
6508 There aren't separate @emph{start}, @emph{stop} events defined for the
6509 event types @code{acc_ev_create}, @code{acc_ev_delete},
6510 @code{acc_ev_alloc}, @code{acc_ev_free}. It's not clear if these
6511 should be triggered before or after the actual device-specific call is
6512 made. We trigger them after.
6514 Remarks about data provided to callbacks:
6518 @item @code{acc_prof_info.event_type}
6519 It's not clear if for @emph{nested} event callbacks (for example,
6520 @code{acc_ev_enqueue_launch_start} as part of a parent compute
6521 construct), this should be set for the nested event
6522 (@code{acc_ev_enqueue_launch_start}), or if the value of the parent
6523 construct should remain (@code{acc_ev_compute_construct_start}). In
6524 this implementation, the value generally corresponds to the
6525 innermost nested event type.
6527 @item @code{acc_prof_info.device_type}
6531 For @code{acc_ev_compute_construct_start}, and in presence of an
6532 @code{if} clause with @emph{false} argument, this still refers to
6533 the offloading device type.
6534 It's not clear if that's the expected behavior.
6537 Complementary to the item before, for
6538 @code{acc_ev_compute_construct_end}, this is set to
6539 @code{acc_device_host} in presence of an @code{if} clause with
6540 @emph{false} argument.
6541 It's not clear if that's the expected behavior.
6545 @item @code{acc_prof_info.thread_id}
6546 Always @code{-1}; not yet implemented.
6548 @item @code{acc_prof_info.async}
6552 Not yet implemented correctly for
6553 @code{acc_ev_compute_construct_start}.
6556 In a compute construct, for host-fallback
6557 execution/@code{acc_device_host} it always is
6558 @code{acc_async_sync}.
6559 It is unclear if that is the expected behavior.
6562 For @code{acc_ev_device_init_start} and @code{acc_ev_device_init_end},
6563 it will always be @code{acc_async_sync}.
6564 It is unclear if that is the expected behavior.
6568 @item @code{acc_prof_info.async_queue}
6569 There is no @cite{limited number of asynchronous queues} in libgomp.
6570 This always has the same value as @code{acc_prof_info.async}.
6572 @item @code{acc_prof_info.src_file}
6573 Always @code{NULL}; not yet implemented.
6575 @item @code{acc_prof_info.func_name}
6576 Always @code{NULL}; not yet implemented.
6578 @item @code{acc_prof_info.line_no}
6579 Always @code{-1}; not yet implemented.
6581 @item @code{acc_prof_info.end_line_no}
6582 Always @code{-1}; not yet implemented.
6584 @item @code{acc_prof_info.func_line_no}
6585 Always @code{-1}; not yet implemented.
6587 @item @code{acc_prof_info.func_end_line_no}
6588 Always @code{-1}; not yet implemented.
6590 @item @code{acc_event_info.event_type}, @code{acc_event_info.*.event_type}
6591 Relating to @code{acc_prof_info.event_type} discussed above, in this
6592 implementation, this will always be the same value as
6593 @code{acc_prof_info.event_type}.
6595 @item @code{acc_event_info.*.parent_construct}
6599 Will be @code{acc_construct_parallel} for all OpenACC compute
6600 constructs as well as many OpenACC Runtime API calls; should be the
6601 one matching the actual construct, or
6602 @code{acc_construct_runtime_api}, respectively.
6605 Will be @code{acc_construct_enter_data} or
6606 @code{acc_construct_exit_data} when processing variable mappings
6607 specified in OpenACC @emph{declare} directives; should be
6608 @code{acc_construct_declare}.
6611 For implicit @code{acc_ev_device_init_start},
6612 @code{acc_ev_device_init_end}, and explicit as well as implicit
6613 @code{acc_ev_alloc}, @code{acc_ev_free},
6614 @code{acc_ev_enqueue_upload_start}, @code{acc_ev_enqueue_upload_end},
6615 @code{acc_ev_enqueue_download_start}, and
6616 @code{acc_ev_enqueue_download_end}, will be
6617 @code{acc_construct_parallel}; should reflect the real parent
6622 @item @code{acc_event_info.*.implicit}
6623 For @code{acc_ev_alloc}, @code{acc_ev_free},
6624 @code{acc_ev_enqueue_upload_start}, @code{acc_ev_enqueue_upload_end},
6625 @code{acc_ev_enqueue_download_start}, and
6626 @code{acc_ev_enqueue_download_end}, this currently will be @code{1}
6627 also for explicit usage.
6629 @item @code{acc_event_info.data_event.var_name}
6630 Always @code{NULL}; not yet implemented.
6632 @item @code{acc_event_info.data_event.host_ptr}
6633 For @code{acc_ev_alloc}, and @code{acc_ev_free}, this is always
6636 @item @code{typedef union acc_api_info}
6637 @dots{} as printed in @cite{5.2.3. Third Argument: API-Specific
6638 Information}. This should obviously be @code{typedef @emph{struct}
6641 @item @code{acc_api_info.device_api}
6642 Possibly not yet implemented correctly for
6643 @code{acc_ev_compute_construct_start},
6644 @code{acc_ev_device_init_start}, @code{acc_ev_device_init_end}:
6645 will always be @code{acc_device_api_none} for these event types.
6646 For @code{acc_ev_enter_data_start}, it will be
6647 @code{acc_device_api_none} in some cases.
6649 @item @code{acc_api_info.device_type}
6650 Always the same as @code{acc_prof_info.device_type}.
6652 @item @code{acc_api_info.vendor}
6653 Always @code{-1}; not yet implemented.
6655 @item @code{acc_api_info.device_handle}
6656 Always @code{NULL}; not yet implemented.
6658 @item @code{acc_api_info.context_handle}
6659 Always @code{NULL}; not yet implemented.
6661 @item @code{acc_api_info.async_handle}
6662 Always @code{NULL}; not yet implemented.
6666 Remarks about certain event types:
6670 @item @code{acc_ev_device_init_start}, @code{acc_ev_device_init_end}
6674 @c See 'DEVICE_INIT_INSIDE_COMPUTE_CONSTRUCT' in
6675 @c 'libgomp.oacc-c-c++-common/acc_prof-kernels-1.c',
6676 @c 'libgomp.oacc-c-c++-common/acc_prof-parallel-1.c'.
6677 When a compute construct triggers implicit
6678 @code{acc_ev_device_init_start} and @code{acc_ev_device_init_end}
6679 events, they currently aren't @emph{nested within} the corresponding
6680 @code{acc_ev_compute_construct_start} and
6681 @code{acc_ev_compute_construct_end}, but they're currently observed
6682 @emph{before} @code{acc_ev_compute_construct_start}.
6683 It's not clear what to do: the standard asks us provide a lot of
6684 details to the @code{acc_ev_compute_construct_start} callback, without
6685 (implicitly) initializing a device before?
6688 Callbacks for these event types will not be invoked for calls to the
6689 @code{acc_set_device_type} and @code{acc_set_device_num} functions.
6690 It's not clear if they should be.
6694 @item @code{acc_ev_enter_data_start}, @code{acc_ev_enter_data_end}, @code{acc_ev_exit_data_start}, @code{acc_ev_exit_data_end}
6698 Callbacks for these event types will also be invoked for OpenACC
6699 @emph{host_data} constructs.
6700 It's not clear if they should be.
6703 Callbacks for these event types will also be invoked when processing
6704 variable mappings specified in OpenACC @emph{declare} directives.
6705 It's not clear if they should be.
6711 Callbacks for the following event types will be invoked, but dispatch
6712 and information provided therein has not yet been thoroughly reviewed:
6715 @item @code{acc_ev_alloc}
6716 @item @code{acc_ev_free}
6717 @item @code{acc_ev_update_start}, @code{acc_ev_update_end}
6718 @item @code{acc_ev_enqueue_upload_start}, @code{acc_ev_enqueue_upload_end}
6719 @item @code{acc_ev_enqueue_download_start}, @code{acc_ev_enqueue_download_end}
6722 During device initialization, and finalization, respectively,
6723 callbacks for the following event types will not yet be invoked:
6726 @item @code{acc_ev_alloc}
6727 @item @code{acc_ev_free}
6730 Callbacks for the following event types have not yet been implemented,
6731 so currently won't be invoked:
6734 @item @code{acc_ev_device_shutdown_start}, @code{acc_ev_device_shutdown_end}
6735 @item @code{acc_ev_runtime_shutdown}
6736 @item @code{acc_ev_create}, @code{acc_ev_delete}
6737 @item @code{acc_ev_wait_start}, @code{acc_ev_wait_end}
6740 For the following runtime library functions, not all expected
6741 callbacks will be invoked (mostly concerning implicit device
6745 @item @code{acc_get_num_devices}
6746 @item @code{acc_set_device_type}
6747 @item @code{acc_get_device_type}
6748 @item @code{acc_set_device_num}
6749 @item @code{acc_get_device_num}
6750 @item @code{acc_init}
6751 @item @code{acc_shutdown}
6754 Aside from implicit device initialization, for the following runtime
6755 library functions, no callbacks will be invoked for shared-memory
6756 offloading devices (it's not clear if they should be):
6759 @item @code{acc_malloc}
6760 @item @code{acc_free}
6761 @item @code{acc_copyin}, @code{acc_present_or_copyin}, @code{acc_copyin_async}
6762 @item @code{acc_create}, @code{acc_present_or_create}, @code{acc_create_async}
6763 @item @code{acc_copyout}, @code{acc_copyout_async}, @code{acc_copyout_finalize}, @code{acc_copyout_finalize_async}
6764 @item @code{acc_delete}, @code{acc_delete_async}, @code{acc_delete_finalize}, @code{acc_delete_finalize_async}
6765 @item @code{acc_update_device}, @code{acc_update_device_async}
6766 @item @code{acc_update_self}, @code{acc_update_self_async}
6767 @item @code{acc_map_data}, @code{acc_unmap_data}
6768 @item @code{acc_memcpy_to_device}, @code{acc_memcpy_to_device_async}
6769 @item @code{acc_memcpy_from_device}, @code{acc_memcpy_from_device_async}
6772 @c ---------------------------------------------------------------------
6773 @c OpenMP-Implementation Specifics
6774 @c ---------------------------------------------------------------------
6776 @node OpenMP-Implementation Specifics
6777 @chapter OpenMP-Implementation Specifics
6780 * Implementation-defined ICV Initialization::
6781 * OpenMP Context Selectors::
6782 * Memory allocation::
6785 @node Implementation-defined ICV Initialization
6786 @section Implementation-defined ICV Initialization
6787 @cindex Implementation specific setting
6789 @multitable @columnfractions .30 .70
6790 @item @var{affinity-format-var} @tab See @ref{OMP_AFFINITY_FORMAT}.
6791 @item @var{def-allocator-var} @tab See @ref{OMP_ALLOCATOR}.
6792 @item @var{max-active-levels-var} @tab See @ref{OMP_MAX_ACTIVE_LEVELS}.
6793 @item @var{dyn-var} @tab See @ref{OMP_DYNAMIC}.
6794 @item @var{nthreads-var} @tab See @ref{OMP_NUM_THREADS}.
6795 @item @var{num-devices-var} @tab Number of non-host devices found
6796 by GCC's run-time library
6797 @item @var{num-procs-var} @tab The number of CPU cores on the
6798 initial device, except that affinity settings might lead to a
6799 smaller number. On non-host devices, the value of the
6800 @var{nthreads-var} ICV.
6801 @item @var{place-partition-var} @tab See @ref{OMP_PLACES}.
6802 @item @var{run-sched-var} @tab See @ref{OMP_SCHEDULE}.
6803 @item @var{stacksize-var} @tab See @ref{OMP_STACKSIZE}.
6804 @item @var{thread-limit-var} @tab See @ref{OMP_TEAMS_THREAD_LIMIT}
6805 @item @var{wait-policy-var} @tab See @ref{OMP_WAIT_POLICY} and
6806 @ref{GOMP_SPINCOUNT}
6809 @node OpenMP Context Selectors
6810 @section OpenMP Context Selectors
6812 @code{vendor} is always @code{gnu}. References are to the GCC manual.
6814 @c NOTE: Only the following selectors have been implemented. To add
6815 @c additional traits for target architecture, TARGET_OMP_DEVICE_KIND_ARCH_ISA
6816 @c has to be implemented; cf. also PR target/105640.
6817 @c For offload devices, add *additionally* gcc/config/*/t-omp-device.
6819 For the host compiler, @code{kind} always matches @code{host}, @code{cpu}
6820 and @code{any}; for the offloading architectures AMD GCN and Nvidia PTX,
6821 @code{kind} always matches @code{nohost}, @code{gpu} and @code{any}.
6822 For the x86 family of computers, AMD GCN and Nvidia PTX
6823 the following traits are supported in addition; while OpenMP is supported
6824 on more architectures, GCC currently does not match any @code{arch} or
6825 @code{isa} traits for those.
6827 @multitable @columnfractions .65 .30
6828 @headitem @code{arch} @tab @code{isa}
6829 @item @code{x86}, @code{x86_64}, @code{i386}, @code{i486},
6830 @code{i586}, @code{i686}, @code{ia32}
6831 @tab See @code{-m...} flags in ``x86 Options'' (without @code{-m})
6832 @item @code{amdgcn}, @code{gcn}
6833 @tab See @code{-march=} in ``AMD GCN Options''
6834 @item @code{nvptx}, @code{nvptx64}
6835 @tab See @code{-march=} in ``Nvidia PTX Options''
6839 @node Memory allocation
6840 @section Memory allocation
6842 The description below applies to:
6845 @item Explicit use of the OpenMP API routines, see
6846 @ref{Memory Management Routines}.
6847 @item The @code{allocate} clause, except when the @code{allocator} modifier is a
6848 constant expression with value @code{omp_default_mem_alloc} and no
6849 @code{align} modifier has been specified. (In that case, the normal
6850 @code{malloc} allocation is used.)
6851 @item The @code{allocate} directive for variables in static memory; while
6852 the alignment is honored, the normal static memory is used.
6853 @item Using the @code{allocate} directive for automatic/stack variables, except
6854 when the @code{allocator} clause is a constant expression with value
6855 @code{omp_default_mem_alloc} and no @code{align} clause has been
6856 specified. (In that case, the normal allocation is used: stack allocation
6857 and, sometimes for Fortran, also @code{malloc} [depending on flags such as
6858 @option{-fstack-arrays}].)
6859 @item In Fortran, the @code{allocators} directive and the executable
6860 @code{allocate} directive for Fortran pointers and allocatables is
6861 supported, but requires that files containing those directives has to be
6862 compiled with @option{-fopenmp-allocators}. Additionally, all files that
6863 might explicitly or implicitly deallocate memory allocated that way must
6864 also be compiled with that option.
6865 @item The used alignment is the maximum of the value the @code{align} clause
6866 and the alignment of the type after honoring, if present, the
6867 @code{aligned} (@code{GNU::aligned}) attribute and C's @code{_Alignas}
6868 and C++'s @code{alignas}. However, the @code{align} clause of the
6869 @code{allocate} directive has no effect on the value of C's
6870 @code{_Alignof} and C++'s @code{alignof}.
6873 GCC supports the following predefined allocators and predefined memory spaces:
6875 @multitable @columnfractions .45 .45
6876 @headitem Predefined allocators @tab Associated predefined memory spaces
6877 @item omp_default_mem_alloc @tab omp_default_mem_space
6878 @item omp_large_cap_mem_alloc @tab omp_large_cap_mem_space
6879 @item omp_const_mem_alloc @tab omp_const_mem_space
6880 @item omp_high_bw_mem_alloc @tab omp_high_bw_mem_space
6881 @item omp_low_lat_mem_alloc @tab omp_low_lat_mem_space
6882 @item omp_cgroup_mem_alloc @tab omp_low_lat_mem_space (implementation defined)
6883 @item omp_pteam_mem_alloc @tab omp_low_lat_mem_space (implementation defined)
6884 @item omp_thread_mem_alloc @tab omp_low_lat_mem_space (implementation defined)
6885 @item ompx_gnu_pinned_mem_alloc @tab omp_default_mem_space (GNU extension)
6888 Each predefined allocator, including @code{omp_null_allocator}, has a corresponding
6889 allocator class template that meet the C++ allocator completeness requirements.
6890 These are located in the @code{omp::allocator} namespace, and the
6891 @code{ompx::allocator} namespace for gnu extensions. This allows the
6892 allocator-aware C++ standard library containers to use OpenMP allocation routines;
6896 std::vector<int, omp::allocator::cgroup_mem<int>> vec;
6899 The following allocator templates are supported:
6901 @multitable @columnfractions .45 .45
6902 @headitem Predefined allocators @tab Associated allocator template
6903 @item omp_null_allocator @tab omp::allocator::null_allocator
6904 @item omp_default_mem_alloc @tab omp::allocator::default_mem
6905 @item omp_large_cap_mem_alloc @tab omp::allocator::large_cap_mem
6906 @item omp_const_mem_alloc @tab omp::allocator::const_mem
6907 @item omp_high_bw_mem_alloc @tab omp::allocator::high_bw_mem
6908 @item omp_low_lat_mem_alloc @tab omp::allocator::low_lat_mem
6909 @item omp_cgroup_mem_alloc @tab omp::allocator::cgroup_mem
6910 @item omp_pteam_mem_alloc @tab omp::allocator::pteam_mem
6911 @item omp_thread_mem_alloc @tab omp::allocator::thread_mem
6912 @item ompx_gnu_pinned_mem_alloc @tab ompx::allocator::gnu_pinned_mem
6915 The following traits are available when constructing a new allocator;
6916 if a trait is not specified or with the value @code{default}, the
6917 specified default value is used for that trait. The predefined
6918 allocators use the default values of each trait, except that the
6919 @code{omp_cgroup_mem_alloc}, @code{omp_pteam_mem_alloc}, and
6920 @code{omp_thread_mem_alloc} allocators have the @code{access} trait
6921 set to @code{cgroup}, @code{pteam}, and @code{thread}, respectively.
6922 For each trait, a named constant prefixed by @code{omp_atk_} exists;
6923 for each non-numeric value, a named constant prefixed by @code{omp_atv_}
6926 @multitable @columnfractions .25 .40 .25
6927 @headitem Trait @tab Allowed values @tab Default value
6928 @item @code{sync_hint} @tab @code{contended}, @code{uncontended},
6929 @code{serialized}, @code{private}
6930 @tab @code{contended}
6931 @item @code{alignment} @tab Positive integer being a power of two
6933 @item @code{access} @tab @code{all}, @code{cgroup},
6934 @code{pteam}, @code{thread}
6936 @item @code{pool_size} @tab Positive integer (bytes)
6938 @item @code{fallback} @tab @code{default_mem_fb}, @code{null_fb},
6939 @code{abort_fb}, @code{allocator_fb}
6941 @item @code{fb_data} @tab @emph{allocator handle}
6943 @item @code{pinned} @tab @code{true}, @code{false}
6945 @item @code{partition} @tab @code{environment}, @code{nearest},
6946 @code{blocked}, @code{interleaved}
6947 @tab @code{environment}
6950 For the @code{fallback} trait, the default value is @code{null_fb} for the
6951 @code{omp_default_mem_alloc} allocator and any allocator that is associated
6952 with device memory; for all other allocators, it is @code{default_mem_fb}
6955 For the @code{pinned} trait, the default value is @code{true} for
6956 predefined allocator @code{ompx_gnu_pinned_mem_alloc} (a GNU extension), and
6957 @code{false} for all others.
6959 The following description applies to the initial device (the host) and largely
6960 also to non-host devices; for the latter, also see @ref{Offload-Target Specifics}.
6962 For the memory spaces, the following applies:
6964 @item @code{omp_default_mem_space} is supported
6965 @item @code{omp_const_mem_space} maps to @code{omp_default_mem_space}
6966 @item @code{omp_low_lat_mem_space} is only available on supported devices,
6967 and maps to @code{omp_default_mem_space} otherwise.
6968 @item @code{omp_large_cap_mem_space} maps to @code{omp_default_mem_space},
6969 unless the memkind library is available
6970 @item @code{omp_high_bw_mem_space} maps to @code{omp_default_mem_space},
6971 unless the memkind library is available
6974 On Linux systems, where the @uref{https://github.com/memkind/memkind, memkind
6975 library} (@code{libmemkind.so.0}) is available at runtime and the respective
6976 memkind kind is supported, it is used when creating memory allocators requesting
6979 @item the @code{partition} trait @code{interleaved} except when the memory space
6980 is @code{omp_large_cap_mem_space} (uses @code{MEMKIND_HBW_INTERLEAVE})
6981 @item the memory space is @code{omp_high_bw_mem_space} (uses
6982 @code{MEMKIND_HBW_PREFERRED})
6983 @item the memory space is @code{omp_large_cap_mem_space} (uses
6984 @code{MEMKIND_DAX_KMEM_ALL} or, if not available, @code{MEMKIND_DAX_KMEM})
6987 On Linux systems, where the @uref{https://github.com/numactl/numactl, numa
6988 library} (@code{libnuma.so.1}) is available at runtime, it used when creating
6989 memory allocators requesting
6992 @item the @code{partition} trait @code{nearest}, except when both the
6993 libmemkind library is available and the memory space is either
6994 @code{omp_large_cap_mem_space} or @code{omp_high_bw_mem_space}
6997 Note that the numa library will round up the allocation size to a multiple of
6998 the system page size; therefore, consider using it only with large data or
6999 by sharing allocations via the @code{pool_size} trait. Furthermore, the Linux
7000 kernel does not guarantee that an allocation will always be on the nearest NUMA
7001 node nor that after reallocation the same node will be used. Note additionally
7002 that, on Linux, the default setting of the memory placement policy is to use the
7003 current node; therefore, unless the memory placement policy has been overridden,
7004 the @code{partition} trait @code{environment} (the default) will be effectively
7005 a @code{nearest} allocation.
7007 Additional notes regarding the traits:
7009 @item The @code{pinned} trait is supported on Linux hosts, but is subject to
7010 the OS @code{ulimit}/@code{rlimit} locked memory settings. It currently
7011 uses @code{mmap} and is therefore optimized for few allocations, including
7012 large data. If the conditions for numa or memkind allocations are
7013 fulfilled, those allocators are used instead.
7014 @item The default for the @code{pool_size} trait is no pool and for every
7015 (re)allocation the associated library routine is called, which might
7016 internally use a memory pool. Currently, the same applies when a
7017 @code{pool_size} has been specified, except that once allocations exceed
7018 the the pool size, the action of the @code{fallback} trait applies.
7019 @item For the @code{partition} trait, the partition part size will be the same
7020 as the requested size (i.e. @code{interleaved} or @code{blocked} has no
7021 effect), except for @code{interleaved} when the memkind library is
7022 available. Furthermore, for @code{nearest} and unless the numa library
7023 is available, the memory might not be on the same NUMA node as thread
7024 that allocated the memory; on Linux, this is in particular the case when
7025 the memory placement policy is set to preferred.
7026 @item The @code{access} trait has no effect such that memory is always
7027 accessible by all threads. (Except on supported no-host devices.)
7028 @item The @code{sync_hint} trait has no effect.
7032 @ref{Offload-Target Specifics}
7036 @c ---------------------------------------------------------------------
7037 @c Offload-Target Specifics
7038 @c ---------------------------------------------------------------------
7040 @node Offload-Target Specifics
7041 @chapter Offload-Target Specifics
7043 The following sections present notes on the offload-target specifics
7051 @section AMD Radeon (GCN)
7054 * Foreign-runtime support for AMD GPUs::
7057 On the hardware side, there is the hierarchy (fine to coarse):
7059 @item work item (thread)
7062 @item compute unit (CU)
7065 All OpenMP and OpenACC levels are used, i.e.
7067 @item OpenMP's simd and OpenACC's vector map to work items (thread)
7068 @item OpenMP's threads (``parallel'') and OpenACC's workers map
7070 @item OpenMP's teams and OpenACC's gang use a threadpool with the
7071 size of the number of teams or gangs, respectively.
7076 @item Number of teams is the specified @code{num_teams} (OpenMP) or
7077 @code{num_gangs} (OpenACC) or otherwise the number of CU. It is limited
7078 by two times the number of CU.
7079 @item Number of wavefronts is 4 for gfx900 and 16 otherwise;
7080 @code{num_threads} (OpenMP) and @code{num_workers} (OpenACC)
7081 overrides this if smaller.
7082 @item The wavefront has 102 scalars and 64 vectors
7083 @item Number of workitems is always 64
7084 @item The hardware permits maximally 40 workgroups/CU and
7085 16 wavefronts/workgroup up to a limit of 40 wavefronts in total per CU.
7086 @item 80 scalars registers and 24 vector registers in non-kernel functions
7087 (the chosen procedure-calling API).
7088 @item For the kernel itself: as many as register pressure demands (number of
7089 teams and number of threads, scaled down if registers are exhausted)
7092 The implementation remark:
7094 @item I/O within OpenMP target regions and OpenACC compute regions is supported
7095 using the C library @code{printf} functions and the Fortran
7096 @code{print}/@code{write} statements.
7097 @item Reverse offload regions (i.e. @code{target} regions with
7098 @code{device(ancestor:1)}) are processed serially per @code{target} region
7099 such that the next reverse offload region is only executed after the previous
7101 @item OpenMP code that has a @code{requires} directive with @code{self_maps} or
7102 @code{unified_shared_memory} is only supported if all AMD GPUs have the
7103 @code{HSA_AMD_SYSTEM_INFO_SVM_ACCESSIBLE_BY_DEFAULT} property; for
7104 discrete GPUs, this may require setting the @code{HSA_XNACK} environment
7105 variable to @samp{1}; for systems with both an APU and a discrete GPU that
7106 does not support XNACK, consider using @code{ROCR_VISIBLE_DEVICES} to
7107 enable only the APU. If not supported, all AMD GPU devices are removed
7108 from the list of available devices (``host fallback'').
7109 @item The available stack size can be changed using the @code{GCN_STACK_SIZE}
7110 environment variable; the default is 32 kiB per thread.
7111 @item Low-latency memory (@code{omp_low_lat_mem_space}) is supported when the
7112 the @code{access} trait is set to @code{cgroup}. The default pool size
7113 is automatically scaled to share the 64 kiB LDS memory between the number
7114 of teams configured to run on each compute-unit, but may be adjusted at
7115 runtime by setting environment variable
7116 @code{GOMP_GCN_LOWLAT_POOL=@var{bytes}}.
7117 @item @code{omp_low_lat_mem_alloc} cannot be used with true low-latency memory
7118 because the definition implies the @code{omp_atv_all} trait; main
7119 graphics memory is used instead.
7120 @item @code{omp_cgroup_mem_alloc}, @code{omp_pteam_mem_alloc}, and
7121 @code{omp_thread_mem_alloc}, all use low-latency memory as first
7122 preference, and fall back to main graphics memory when the low-latency
7124 @item The OpenMP routines @code{omp_target_memcpy_rect} and
7125 @code{omp_target_memcpy_rect_async} and the @code{target update}
7126 directive for non-contiguous list items use the 3D memory-copy function
7127 of the HSA library. Higher dimensions call this functions in a loop and
7128 are therefore supported.
7129 @item The unique identifier (UID), used with OpenMP's API UID routines, is the
7130 value returned by the HSA runtime library for @code{HSA_AMD_AGENT_INFO_UUID}.
7131 For GPUs, it is currently @samp{GPU-} followed by 16 lower-case hex digits,
7132 yielding a string like @code{GPU-f914a2142fc3413a}. The output matches
7133 the one used by @code{rocminfo}.
7137 @node Foreign-runtime support for AMD GPUs
7138 @subsection OpenMP @code{interop} -- Foreign-Runtime Support for AMD GPUs
7140 On AMD GPUs, the foreign runtimes are HIP (C++ Heterogeneous-Compute Interface
7141 for Portability) and HSA (Heterogeneous System Architecture),
7142 where HIP is the default. The interop object is created using OpenMP's
7143 @code{interop} directive or, implicitly, when invoking a @code{declare variant}
7144 procedure that has the @code{append_args} clause. In either case, the
7145 @code{prefer_type} modifier determines whether HIP or HSA is used.
7147 When specifying the @code{targetsync} modifier: For HIP, a stream is
7148 created using @code{hipStreamCreate}. For HSA, a queue is created of type
7149 @code{HSA_QUEUE_TYPE_MULTI} with a queue size of 64.
7151 Invoke the @ref{Interoperability Routines} on an interop object to obtain
7152 the following properties. For properties with integral (int), pointer (ptr),
7153 or string (str) data type, call @code{omp_get_interop_int},
7154 @code{omp_get_interop_ptr}, or @code{omp_get_interop_str}, respectively.
7155 Note that @code{device_num} is the OpenMP device number
7156 while @code{device} is the HIP device number or HSA device handle.
7158 When using HIP with C and C++, the @code{__HIP_PLATFORM_AMD__} preprocessor
7159 macro must be defined before including the HIP header files.
7161 For the API routine call, add the prefix @code{omp_ipr_} to the property name;
7164 omp_interop_rc_t ret;
7165 int device_num = omp_get_interop_int (my_interop_obj, omp_ipr_device_num, &ret);
7169 Available properties for an HIP interop object:
7171 @multitable @columnfractions .20 .35 .20 .20
7172 @headitem Property @tab C data type @tab API routine @tab value (if constant)
7173 @item @code{fr_id} @tab @code{omp_interop_fr_t} @tab int @tab @code{omp_fr_hip}
7174 @item @code{fr_name} @tab @code{const char *} @tab str @tab @code{"hip"}
7175 @item @code{vendor} @tab @code{int} @tab int @tab @code{1}
7176 @item @code{vendor_name} @tab @code{const char *} @tab str @tab @code{"amd"}
7177 @item @code{device_num} @tab @code{int} @tab int @tab
7178 @item @code{platform} @tab N/A @tab @tab
7179 @item @code{device} @tab @code{hipDevice_t} @tab int @tab
7180 @item @code{device_context} @tab @code{hipCtx_t} @tab ptr @tab
7181 @item @code{targetsync} @tab @code{hipStream_t} @tab ptr @tab
7185 Available properties for an HSA interop object:
7187 @multitable @columnfractions .20 .35 .20 .20
7188 @headitem Property @tab C data type @tab API routine @tab value (if constant)
7189 @item @code{fr_id} @tab @code{omp_interop_fr_t} @tab int @tab @code{omp_fr_hsa}
7190 @item @code{fr_name} @tab @code{const char *} @tab str @tab @code{"hsa"}
7191 @item @code{vendor} @tab @code{int} @tab int @tab @code{1}
7192 @item @code{vendor_name} @tab @code{const char *} @tab str @tab @code{"amd"}
7193 @item @code{device_num} @tab @code{int} @tab int @tab
7194 @item @code{platform} @tab N/A @tab @tab
7195 @item @code{device} @tab @code{hsa_agent *} @tab ptr @tab
7196 @item @code{device_context} @tab N/A @tab @tab
7197 @item @code{targetsync} @tab @code{hsa_queue *} @tab ptr @tab
7206 * Foreign-runtime support for Nvidia GPUs::
7209 On the hardware side, there is the hierarchy (fine to coarse):
7214 @item streaming multiprocessor
7217 All OpenMP and OpenACC levels are used, i.e.
7219 @item OpenMP's simd and OpenACC's vector map to threads
7220 @item OpenMP's threads (``parallel'') and OpenACC's workers map to warps
7221 @item OpenMP's teams and OpenACC's gang use a threadpool with the
7222 size of the number of teams or gangs, respectively.
7227 @item The @code{warp_size} is always 32
7228 @item CUDA kernel launched: @code{dim=@{#teams,1,1@}, blocks=@{#threads,warp_size,1@}}.
7229 @item The number of teams is limited by the number of blocks the device can
7230 host simultaneously.
7233 Additional information can be obtained by setting the environment variable to
7234 @code{GOMP_DEBUG=1} (very verbose; grep for @code{kernel.*launch} for launch
7237 GCC generates generic PTX ISA code, which is just-in-time compiled by CUDA,
7238 which caches the JIT in the user's directory (see CUDA documentation; can be
7239 tuned by the environment variables @code{CUDA_CACHE_@{DISABLE,MAXSIZE,PATH@}}.
7241 Note: While PTX ISA is generic, the @code{-mptx=} and @code{-march=} commandline
7242 options still affect the used PTX ISA code and, thus, the requirements on
7243 CUDA version and hardware.
7245 The implementation remark:
7247 @item I/O within OpenMP target regions and OpenACC compute regions is supported
7248 using the C library @code{printf} functions.
7249 Additionally, the Fortran @code{print}/@code{write} statements are
7250 supported within OpenMP target regions, but not yet within OpenACC compute
7251 regions. @c The latter needs 'GOMP_NVPTX_NATIVE_GPU_THREAD_STACK_SIZE'.
7252 @item Compilation OpenMP code that contains @code{requires reverse_offload}
7253 requires at least @code{-march=sm_35}, compiling for @code{-march=sm_30}
7255 @item For code containing reverse offload (i.e. @code{target} regions with
7256 @code{device(ancestor:1)}), there is a slight performance penalty
7257 for @emph{all} target regions, consisting mostly of shutdown delay
7258 Per device, reverse offload regions are processed serially such that
7259 the next reverse offload region is only executed after the previous
7261 @item OpenMP code that has a @code{requires} directive with @code{self_maps} or
7262 @code{unified_shared_memory} runs on nvptx devices if and only if
7263 all of those support the @code{pageableMemoryAccess} property;@footnote{
7264 @uref{https://docs.nvidia.com/cuda/cuda-c-programming-guide/index.html#um-requirements}}
7265 otherwise, all nvptx device are removed from the list of available
7266 devices (``host fallback'').
7267 @item The default per-warp stack size is 128 kiB; see also @code{-msoft-stack}
7269 @item Low-latency memory (@code{omp_low_lat_mem_space}) is supported when the
7270 the @code{access} trait is set to @code{cgroup}, and libgomp has
7271 been built for PTX ISA version 4.1 or higher (such as in GCC's
7272 default configuration). @c -mptx=4.1
7273 The default pool size
7274 is 8 kiB per team, but may be adjusted at runtime by setting environment
7275 variable @code{GOMP_NVPTX_LOWLAT_POOL=@var{bytes}}. The maximum value is
7276 limited by the available hardware, and care should be taken that the
7277 selected pool size does not unduly limit the number of teams that can
7279 @item @code{omp_low_lat_mem_alloc} cannot be used with true low-latency memory
7280 because the definition implies the @code{omp_atv_all} trait; main
7281 graphics memory is used instead.
7282 @item @code{omp_cgroup_mem_alloc}, @code{omp_pteam_mem_alloc}, and
7283 @code{omp_thread_mem_alloc}, all use low-latency memory as first
7284 preference, and fall back to main graphics memory when the low-latency
7286 @item The OpenMP routines @code{omp_target_memcpy_rect} and
7287 @code{omp_target_memcpy_rect_async} and the @code{target update}
7288 directive for non-contiguous list items use the 2D and 3D memory-copy
7289 functions of the CUDA library. Higher dimensions call those functions
7290 in a loop and are therefore supported.
7291 @item The unique identifier (UID), used with OpenMP's API UID routines, consists
7292 of the @samp{GPU-} prefix followed by the 16-bytes UUID as returned by
7293 the CUDA runtime library. This UUID is output in grouped lower-case
7294 hex digits; the grouping of those 32 digits is: 8 digits, hyphen,
7295 4 digits, hyphen, 4 digits, hyphen, 16 digits. This leads to a string
7296 like @code{GPU-a8081c9e-f03e-18eb-1827-bf5ba95afa5d}. The output
7297 matches the format used by @code{nvidia-smi}.
7301 @node Foreign-runtime support for Nvidia GPUs
7302 @subsection OpenMP @code{interop} -- Foreign-Runtime Support for Nvidia GPUs
7304 On Nvidia GPUs, the foreign runtimes APIs are the CUDA runtime API, the CUDA
7305 driver API, and HIP, the C++ Heterogeneous-Compute Interface for Portability
7306 that is---on CUDA-based systems---a very thin layer on top of the CUDA API. By
7307 default, CUDA is used. The interop object is created using OpenMP's
7308 @code{interop} directive or, implicitly, when invoking a @code{declare variant}
7309 procedure that has the @code{append_args} clause. In either case, the
7310 @code{prefer_type} modifier determines whether CUDA, CUDA driver, or HSA is
7313 When specifying the @code{targetsync} modifier, a CUDA stream is created using
7314 the @code{CU_STREAM_DEFAULT} flag.
7316 Invoke the @ref{Interoperability Routines} on an interop object to obtain
7317 the following properties. For properties with integral (int), pointer (ptr),
7318 or string (str) data type, call @code{omp_get_interop_int},
7319 @code{omp_get_interop_ptr}, or @code{omp_get_interop_str}, respectively.
7320 Note that @code{device_num} is the OpenMP device number while @code{device}
7321 is the CUDA, CUDA Driver, or HIP device number.
7323 When using HIP with C and C++, the @code{__HIP_PLATFORM_NVIDIA__} preprocessor
7324 macro must be defined before including the HIP header files.
7326 For the API routine call, add the prefix @code{omp_ipr_} to the property name;
7329 omp_interop_rc_t ret;
7330 int device_num = omp_get_interop_int (my_interop_obj, omp_ipr_device_num, &ret);
7334 Available properties for a CUDA runtime API interop object:
7336 @multitable @columnfractions .20 .35 .20 .20
7337 @headitem Property @tab C data type @tab API routine @tab value (if constant)
7338 @item @code{fr_id} @tab @code{omp_interop_fr_t} @tab int @tab @code{omp_fr_cuda}
7339 @item @code{fr_name} @tab @code{const char *} @tab str @tab @code{"cuda"}
7340 @item @code{vendor} @tab @code{int} @tab int @tab @code{11}
7341 @item @code{vendor_name} @tab @code{const char *} @tab str @tab @code{"nvidia"}
7342 @item @code{device_num} @tab @code{int} @tab int @tab
7343 @item @code{platform} @tab N/A @tab @tab
7344 @item @code{device} @tab @code{int} @tab int @tab
7345 @item @code{device_context} @tab N/A @tab @tab
7346 @item @code{targetsync} @tab @code{cudaStream_t} @tab ptr @tab
7350 Available properties for a CUDA driver API interop object:
7352 @multitable @columnfractions .20 .35 .20 .20
7353 @headitem Property @tab C data type @tab API routine @tab value (if constant)
7354 @item @code{fr_id} @tab @code{omp_interop_fr_t} @tab int @tab @code{omp_fr_cuda_driver}
7355 @item @code{fr_name} @tab @code{const char *} @tab str @tab @code{"cuda_driver"}
7356 @item @code{vendor} @tab @code{int} @tab int @tab @code{11}
7357 @item @code{vendor_name} @tab @code{const char *} @tab str @tab @code{"nvidia"}
7358 @item @code{device_num} @tab @code{int} @tab int @tab
7359 @item @code{platform} @tab N/A @tab @tab
7360 @item @code{device} @tab @code{CUdevice} @tab int @tab
7361 @item @code{device_context} @tab @code{CUcontext} @tab ptr @tab
7362 @item @code{targetsync} @tab @code{CUstream} @tab ptr @tab
7366 Available properties for an HIP interop object:
7368 @multitable @columnfractions .20 .35 .20 .20
7369 @headitem Property @tab C data type @tab API routine @tab value (if constant)
7370 @item @code{fr_id} @tab @code{omp_interop_fr_t} @tab int @tab @code{omp_fr_hip}
7371 @item @code{fr_name} @tab @code{const char *} @tab str @tab @code{"hip"}
7372 @item @code{vendor} @tab @code{int} @tab int @tab @code{11}
7373 @item @code{vendor_name} @tab @code{const char *} @tab str @tab @code{"nvidia"}
7374 @item @code{device_num} @tab @code{int} @tab int @tab
7375 @item @code{platform} @tab N/A @tab @tab
7376 @item @code{device} @tab @code{hipDevice_t} @tab int @tab
7377 @item @code{device_context} @tab @code{hipCtx_t} @tab ptr @tab
7378 @item @code{targetsync} @tab @code{hipStream_t} @tab ptr @tab
7383 @c ---------------------------------------------------------------------
7385 @c ---------------------------------------------------------------------
7387 @node The libgomp ABI
7388 @chapter The libgomp ABI
7390 The following sections present notes on the external ABI as
7391 presented by libgomp. Only maintainers should need them.
7394 * Implementing MASTER construct::
7395 * Implementing CRITICAL construct::
7396 * Implementing ATOMIC construct::
7397 * Implementing FLUSH construct::
7398 * Implementing BARRIER construct::
7399 * Implementing THREADPRIVATE construct::
7400 * Implementing PRIVATE clause::
7401 * Implementing FIRSTPRIVATE LASTPRIVATE COPYIN and COPYPRIVATE clauses::
7402 * Implementing REDUCTION clause::
7403 * Implementing PARALLEL construct::
7404 * Implementing FOR construct::
7405 * Implementing ORDERED construct::
7406 * Implementing SECTIONS construct::
7407 * Implementing SINGLE construct::
7408 * Implementing OpenACC's PARALLEL construct::
7412 @node Implementing MASTER construct
7413 @section Implementing MASTER construct
7416 if (omp_get_thread_num () == 0)
7420 Alternately, we generate two copies of the parallel subfunction
7421 and only include this in the version run by the primary thread.
7422 Surely this is not worthwhile though...
7426 @node Implementing CRITICAL construct
7427 @section Implementing CRITICAL construct
7429 Without a specified name,
7432 void GOMP_critical_start (void);
7433 void GOMP_critical_end (void);
7436 so that we don't get COPY relocations from libgomp to the main
7439 With a specified name, use omp_set_lock and omp_unset_lock with
7440 name being transformed into a variable declared like
7443 omp_lock_t gomp_critical_user_<name> __attribute__((common))
7446 Ideally the ABI would specify that all zero is a valid unlocked
7447 state, and so we wouldn't need to initialize this at
7452 @node Implementing ATOMIC construct
7453 @section Implementing ATOMIC construct
7455 The target should implement the @code{__sync} builtins.
7457 Failing that we could add
7460 void GOMP_atomic_enter (void)
7461 void GOMP_atomic_exit (void)
7464 which reuses the regular lock code, but with yet another lock
7465 object private to the library.
7469 @node Implementing FLUSH construct
7470 @section Implementing FLUSH construct
7472 Expands to the @code{__sync_synchronize} builtin.
7476 @node Implementing BARRIER construct
7477 @section Implementing BARRIER construct
7480 void GOMP_barrier (void)
7484 @node Implementing THREADPRIVATE construct
7485 @section Implementing THREADPRIVATE construct
7487 In _most_ cases we can map this directly to @code{__thread}. Except
7488 that OMP allows constructors for C++ objects. We can either
7489 refuse to support this (how often is it used?) or we can
7490 implement something akin to .ctors.
7492 Even more ideally, this ctor feature is handled by extensions
7493 to the main pthreads library. Failing that, we can have a set
7494 of entry points to register ctor functions to be called.
7498 @node Implementing PRIVATE clause
7499 @section Implementing PRIVATE clause
7501 In association with a PARALLEL, or within the lexical extent
7502 of a PARALLEL block, the variable becomes a local variable in
7503 the parallel subfunction.
7505 In association with FOR or SECTIONS blocks, create a new
7506 automatic variable within the current function. This preserves
7507 the semantic of new variable creation.
7511 @node Implementing FIRSTPRIVATE LASTPRIVATE COPYIN and COPYPRIVATE clauses
7512 @section Implementing FIRSTPRIVATE LASTPRIVATE COPYIN and COPYPRIVATE clauses
7514 This seems simple enough for PARALLEL blocks. Create a private
7515 struct for communicating between the parent and subfunction.
7516 In the parent, copy in values for scalar and "small" structs;
7517 copy in addresses for others TREE_ADDRESSABLE types. In the
7518 subfunction, copy the value into the local variable.
7520 It is not clear what to do with bare FOR or SECTION blocks.
7521 The only thing I can figure is that we do something like:
7524 #pragma omp for firstprivate(x) lastprivate(y)
7525 for (int i = 0; i < n; ++i)
7542 where the "x=x" and "y=y" assignments actually have different
7543 uids for the two variables, i.e. not something you could write
7544 directly in C. Presumably this only makes sense if the "outer"
7545 x and y are global variables.
7547 COPYPRIVATE would work the same way, except the structure
7548 broadcast would have to happen via SINGLE machinery instead.
7552 @node Implementing REDUCTION clause
7553 @section Implementing REDUCTION clause
7555 The private struct mentioned in the previous section should have
7556 a pointer to an array of the type of the variable, indexed by the
7557 thread's @var{team_id}. The thread stores its final value into the
7558 array, and after the barrier, the primary thread iterates over the
7559 array to collect the values.
7562 @node Implementing PARALLEL construct
7563 @section Implementing PARALLEL construct
7566 #pragma omp parallel
7575 void subfunction (void *data)
7582 GOMP_parallel_start (subfunction, &data, num_threads);
7583 subfunction (&data);
7584 GOMP_parallel_end ();
7588 void GOMP_parallel_start (void (*fn)(void *), void *data, unsigned num_threads)
7591 The @var{FN} argument is the subfunction to be run in parallel.
7593 The @var{DATA} argument is a pointer to a structure used to
7594 communicate data in and out of the subfunction, as discussed
7595 above with respect to FIRSTPRIVATE et al.
7597 The @var{NUM_THREADS} argument is 1 if an IF clause is present
7598 and false, or the value of the NUM_THREADS clause, if
7601 The function needs to create the appropriate number of
7602 threads and/or launch them from the dock. It needs to
7603 create the team structure and assign team ids.
7606 void GOMP_parallel_end (void)
7609 Tears down the team and returns us to the previous @code{omp_in_parallel()} state.
7613 @node Implementing FOR construct
7614 @section Implementing FOR construct
7617 #pragma omp parallel for
7618 for (i = lb; i <= ub; i++)
7625 void subfunction (void *data)
7628 while (GOMP_loop_static_next (&_s0, &_e0))
7631 for (i = _s0; i < _e1; i++)
7634 GOMP_loop_end_nowait ();
7637 GOMP_parallel_loop_static (subfunction, NULL, 0, lb, ub+1, 1, 0);
7639 GOMP_parallel_end ();
7643 #pragma omp for schedule(runtime)
7644 for (i = 0; i < n; i++)
7653 if (GOMP_loop_runtime_start (0, n, 1, &_s0, &_e0))
7656 for (i = _s0, i < _e0; i++)
7658 @} while (GOMP_loop_runtime_next (&_s0, _&e0));
7663 Note that while it looks like there is trickiness to propagating
7664 a non-constant STEP, there isn't really. We're explicitly allowed
7665 to evaluate it as many times as we want, and any variables involved
7666 should automatically be handled as PRIVATE or SHARED like any other
7667 variables. So the expression should remain evaluable in the
7668 subfunction. We can also pull it into a local variable if we like,
7669 but since its supposed to remain unchanged, we can also not if we like.
7671 If we have SCHEDULE(STATIC), and no ORDERED, then we ought to be
7672 able to get away with no work-sharing context at all, since we can
7673 simply perform the arithmetic directly in each thread to divide up
7674 the iterations. Which would mean that we wouldn't need to call any
7677 There are separate routines for handling loops with an ORDERED
7678 clause. Bookkeeping for that is non-trivial...
7682 @node Implementing ORDERED construct
7683 @section Implementing ORDERED construct
7686 void GOMP_ordered_start (void)
7687 void GOMP_ordered_end (void)
7692 @node Implementing SECTIONS construct
7693 @section Implementing SECTIONS construct
7698 #pragma omp sections
7712 for (i = GOMP_sections_start (3); i != 0; i = GOMP_sections_next ())
7729 @node Implementing SINGLE construct
7730 @section Implementing SINGLE construct
7744 if (GOMP_single_start ())
7752 #pragma omp single copyprivate(x)
7759 datap = GOMP_single_copy_start ();
7764 GOMP_single_copy_end (&data);
7773 @node Implementing OpenACC's PARALLEL construct
7774 @section Implementing OpenACC's PARALLEL construct
7777 void GOACC_parallel ()
7782 @c ---------------------------------------------------------------------
7784 @c ---------------------------------------------------------------------
7786 @node Reporting Bugs
7787 @chapter Reporting Bugs
7789 Bugs in the GNU Offloading and Multi Processing Runtime Library should
7790 be reported via @uref{https://gcc.gnu.org/bugzilla/, Bugzilla}. Please add
7791 "openacc", or "openmp", or both to the keywords field in the bug
7792 report, as appropriate.
7796 @c ---------------------------------------------------------------------
7797 @c GNU General Public License
7798 @c ---------------------------------------------------------------------
7800 @include gpl_v3.texi
7804 @c ---------------------------------------------------------------------
7805 @c GNU Free Documentation License
7806 @c ---------------------------------------------------------------------
7812 @c ---------------------------------------------------------------------
7813 @c Funding Free Software
7814 @c ---------------------------------------------------------------------
7816 @include funding.texi
7818 @c ---------------------------------------------------------------------
7820 @c ---------------------------------------------------------------------
7823 @unnumbered Library Index