1 \input texinfo @c -*-texinfo-*-
4 @setfilename libgomp.info
10 Copyright @copyright{} 2006-2024 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 N @tab
196 @item @code{declare variant} directive
197 @tab P @tab @emph{simd} traits not handled correctly
198 @item @var{target-offload-var} ICV and @code{OMP_TARGET_OFFLOAD}
199 env variable @tab Y @tab
200 @item Nested-parallel changes to @var{max-active-levels-var} ICV @tab Y @tab
201 @item @code{requires} directive @tab Y
202 @tab See also @ref{Offload-Target Specifics}
203 @item @code{teams} construct outside an enclosing target region @tab Y @tab
204 @item Non-rectangular loop nests @tab P
205 @tab Full support for C/C++, partial for Fortran
206 (@uref{https://gcc.gnu.org/PR110735,PR110735})
207 @item @code{!=} as relational-op in canonical loop form for C/C++ @tab Y @tab
208 @item @code{nonmonotonic} as default loop schedule modifier for worksharing-loop
209 constructs @tab Y @tab
210 @item Collapse of associated loops that are imperfectly nested loops @tab Y @tab
211 @item Clauses @code{if}, @code{nontemporal} and @code{order(concurrent)} in
212 @code{simd} construct @tab Y @tab
213 @item @code{atomic} constructs in @code{simd} @tab Y @tab
214 @item @code{loop} construct @tab Y @tab
215 @item @code{order(concurrent)} clause @tab Y @tab
216 @item @code{scan} directive and @code{in_scan} modifier for the
217 @code{reduction} clause @tab Y @tab
218 @item @code{in_reduction} clause on @code{task} constructs @tab Y @tab
219 @item @code{in_reduction} clause on @code{target} constructs @tab P
220 @tab @code{nowait} only stub
221 @item @code{task_reduction} clause with @code{taskgroup} @tab Y @tab
222 @item @code{task} modifier to @code{reduction} clause @tab Y @tab
223 @item @code{affinity} clause to @code{task} construct @tab Y @tab Stub only
224 @item @code{detach} clause to @code{task} construct @tab Y @tab
225 @item @code{omp_fulfill_event} runtime routine @tab Y @tab
226 @item @code{reduction} and @code{in_reduction} clauses on @code{taskloop}
227 and @code{taskloop simd} constructs @tab Y @tab
228 @item @code{taskloop} construct cancelable by @code{cancel} construct
230 @item @code{mutexinoutset} @emph{dependence-type} for @code{depend} clause
232 @item Predefined memory spaces, memory allocators, allocator traits
233 @tab Y @tab See also @ref{Memory allocation}
234 @item Memory management routines @tab Y @tab
235 @item @code{allocate} directive @tab P
236 @tab C++ unsupported; see also @ref{Memory allocation}
237 @item @code{allocate} clause @tab P @tab Clause has no effect on @code{target}
238 (@uref{https://gcc.gnu.org/PR113436,PR113436})
239 @item @code{use_device_addr} clause on @code{target data} @tab Y @tab
240 @item @code{ancestor} modifier on @code{device} clause @tab Y @tab
241 @item Implicit declare target directive @tab Y @tab
242 @item Discontiguous array section with @code{target update} construct
244 @item C/C++'s lvalue expressions in @code{to}, @code{from}
245 and @code{map} clauses @tab Y @tab
246 @item C/C++'s lvalue expressions in @code{depend} clauses @tab Y @tab
247 @item Nested @code{declare target} directive @tab Y @tab
248 @item Combined @code{master} constructs @tab Y @tab
249 @item @code{depend} clause on @code{taskwait} @tab Y @tab
250 @item Weak memory ordering clauses on @code{atomic} and @code{flush} construct
252 @item @code{hint} clause on the @code{atomic} construct @tab Y @tab Stub only
253 @item @code{depobj} construct and depend objects @tab Y @tab
254 @item Lock hints were renamed to synchronization hints @tab Y @tab
255 @item @code{conditional} modifier to @code{lastprivate} clause @tab Y @tab
256 @item Map-order clarifications @tab P @tab
257 @item @code{close} @emph{map-type-modifier} @tab Y @tab
258 @item Mapping C/C++ pointer variables and to assign the address of
259 device memory mapped by an array section @tab P @tab
260 @item Mapping of Fortran pointer and allocatable variables, including pointer
261 and allocatable components of variables
262 @tab P @tab Mapping of vars with allocatable components unsupported
263 @item @code{defaultmap} extensions @tab Y @tab
264 @item @code{declare mapper} directive @tab N @tab
265 @item @code{omp_get_supported_active_levels} routine @tab Y @tab
266 @item Runtime routines and environment variables to display runtime thread
267 affinity information @tab Y @tab
268 @item @code{omp_pause_resource} and @code{omp_pause_resource_all} runtime
270 @item @code{omp_get_device_num} runtime routine @tab Y @tab
271 @item OMPT interface @tab N @tab
272 @item OMPD interface @tab N @tab
275 @unnumberedsubsec Other new OpenMP 5.0 features
277 @multitable @columnfractions .60 .10 .25
278 @headitem Description @tab Status @tab Comments
279 @item Supporting C++'s range-based for loop @tab Y @tab
286 @unnumberedsubsec New features listed in Appendix B of the OpenMP specification
288 @multitable @columnfractions .60 .10 .25
289 @headitem Description @tab Status @tab Comments
290 @item OpenMP directive as C++ attribute specifiers @tab Y @tab
291 @item @code{omp_all_memory} reserved locator @tab Y @tab
292 @item @emph{target_device trait} in OpenMP Context @tab N @tab
293 @item @code{target_device} selector set in context selectors @tab N @tab
294 @item C/C++'s @code{declare variant} directive: elision support of
295 preprocessed code @tab N @tab
296 @item @code{declare variant}: new clauses @code{adjust_args} and
297 @code{append_args} @tab N @tab
298 @item @code{dispatch} construct @tab N @tab
299 @item device-specific ICV settings with environment variables @tab Y @tab
300 @item @code{assume} and @code{assumes} directives @tab Y @tab
301 @item @code{nothing} directive @tab Y @tab
302 @item @code{error} directive @tab Y @tab
303 @item @code{masked} construct @tab Y @tab
304 @item @code{scope} directive @tab Y @tab
305 @item Loop transformation constructs @tab Y @tab
306 @item @code{strict} modifier in the @code{grainsize} and @code{num_tasks}
307 clauses of the @code{taskloop} construct @tab Y @tab
308 @item @code{align} clause in @code{allocate} directive @tab P
309 @tab Only C and Fortran
310 @item @code{align} modifier in @code{allocate} clause @tab Y @tab
311 @item @code{thread_limit} clause to @code{target} construct @tab Y @tab
312 @item @code{has_device_addr} clause to @code{target} construct @tab Y @tab
313 @item Iterators in @code{target update} motion clauses and @code{map}
315 @item Indirect calls to the device version of a procedure or function in
316 @code{target} regions @tab Y @tab
317 @item @code{interop} directive @tab N @tab
318 @item @code{omp_interop_t} object support in runtime routines @tab N @tab
319 @item @code{nowait} clause in @code{taskwait} directive @tab Y @tab
320 @item Extensions to the @code{atomic} directive @tab Y @tab
321 @item @code{seq_cst} clause on a @code{flush} construct @tab Y @tab
322 @item @code{inoutset} argument to the @code{depend} clause @tab Y @tab
323 @item @code{private} and @code{firstprivate} argument to @code{default}
324 clause in C and C++ @tab Y @tab
325 @item @code{present} argument to @code{defaultmap} clause @tab Y @tab
326 @item @code{omp_set_num_teams}, @code{omp_set_teams_thread_limit},
327 @code{omp_get_max_teams}, @code{omp_get_teams_thread_limit} runtime
329 @item @code{omp_target_is_accessible} runtime routine @tab Y @tab
330 @item @code{omp_target_memcpy_async} and @code{omp_target_memcpy_rect_async}
331 runtime routines @tab Y @tab
332 @item @code{omp_get_mapped_ptr} runtime routine @tab Y @tab
333 @item @code{omp_calloc}, @code{omp_realloc}, @code{omp_aligned_alloc} and
334 @code{omp_aligned_calloc} runtime routines @tab Y @tab
335 @item @code{omp_alloctrait_key_t} enum: @code{omp_atv_serialized} added,
336 @code{omp_atv_default} changed @tab Y @tab
337 @item @code{omp_display_env} runtime routine @tab Y @tab
338 @item @code{ompt_scope_endpoint_t} enum: @code{ompt_scope_beginend} @tab N @tab
339 @item @code{ompt_sync_region_t} enum additions @tab N @tab
340 @item @code{ompt_state_t} enum: @code{ompt_state_wait_barrier_implementation}
341 and @code{ompt_state_wait_barrier_teams} @tab N @tab
342 @item @code{ompt_callback_target_data_op_emi_t},
343 @code{ompt_callback_target_emi_t}, @code{ompt_callback_target_map_emi_t}
344 and @code{ompt_callback_target_submit_emi_t} @tab N @tab
345 @item @code{ompt_callback_error_t} type @tab N @tab
346 @item @code{OMP_PLACES} syntax extensions @tab Y @tab
347 @item @code{OMP_NUM_TEAMS} and @code{OMP_TEAMS_THREAD_LIMIT} environment
348 variables @tab Y @tab
351 @unnumberedsubsec Other new OpenMP 5.1 features
353 @multitable @columnfractions .60 .10 .25
354 @headitem Description @tab Status @tab Comments
355 @item Support of strictly structured blocks in Fortran @tab Y @tab
356 @item Support of structured block sequences in C/C++ @tab Y @tab
357 @item @code{unconstrained} and @code{reproducible} modifiers on @code{order}
359 @item Support @code{begin/end declare target} syntax in C/C++ @tab Y @tab
360 @item Pointer predetermined firstprivate getting initialized
361 to address of matching mapped list item per 5.1, Sect. 2.21.7.2 @tab N @tab
362 @item For Fortran, diagnose placing declarative before/between @code{USE},
363 @code{IMPORT}, and @code{IMPLICIT} as invalid @tab N @tab
364 @item Optional comma between directive and clause in the @code{#pragma} form @tab Y @tab
365 @item @code{indirect} clause in @code{declare target} @tab Y @tab
366 @item @code{device_type(nohost)}/@code{device_type(host)} for variables @tab N @tab
367 @item @code{present} modifier to the @code{map}, @code{to} and @code{from}
375 @unnumberedsubsec New features listed in Appendix B of the OpenMP specification
377 @multitable @columnfractions .60 .10 .25
378 @headitem Description @tab Status @tab Comments
379 @item @code{omp_in_explicit_task} routine and @var{explicit-task-var} ICV
381 @item @code{omp}/@code{ompx}/@code{omx} sentinels and @code{omp_}/@code{ompx_}
383 @tab warning for @code{ompx/omx} sentinels@footnote{The @code{ompx}
384 sentinel as C/C++ pragma and C++ attributes are warned for with
385 @code{-Wunknown-pragmas} (implied by @code{-Wall}) and @code{-Wattributes}
386 (enabled by default), respectively; for Fortran free-source code, there is
387 a warning enabled by default and, for fixed-source code, the @code{omx}
388 sentinel is warned for with @code{-Wsurprising} (enabled by
389 @code{-Wall}). Unknown clauses are always rejected with an error.}
390 @item Clauses on @code{end} directive can be on directive @tab Y @tab
391 @item @code{destroy} clause with destroy-var argument on @code{depobj}
393 @item Deprecation of no-argument @code{destroy} clause on @code{depobj}
394 @tab N/A @tab undeprecated in OpenMP 6
395 @item @code{linear} clause syntax changes and @code{step} modifier @tab Y @tab
396 @item Deprecation of minus operator for reductions @tab N @tab
397 @item Deprecation of separating @code{map} modifiers without comma @tab N @tab
398 @item @code{declare mapper} with iterator and @code{present} modifiers
400 @item If a matching mapped list item is not found in the data environment, the
401 pointer retains its original value @tab Y @tab
402 @item New @code{enter} clause as alias for @code{to} on declare target directive
404 @item Deprecation of @code{to} clause on declare target directive @tab N @tab
405 @item Extended list of directives permitted in Fortran pure procedures
407 @item New @code{allocators} directive for Fortran @tab Y @tab
408 @item Deprecation of @code{allocate} directive for Fortran
409 allocatables/pointers @tab N @tab
410 @item Optional paired @code{end} directive with @code{dispatch} @tab N @tab
411 @item New @code{memspace} and @code{traits} modifiers for @code{uses_allocators}
413 @item Deprecation of traits array following the allocator_handle expression in
414 @code{uses_allocators} @tab N @tab
415 @item New @code{otherwise} clause as alias for @code{default} on metadirectives
417 @item Deprecation of @code{default} clause on metadirectives @tab N @tab
418 @item Deprecation of delimited form of @code{declare target} @tab N @tab
419 @item Reproducible semantics changed for @code{order(concurrent)} @tab N @tab
420 @item @code{allocate} and @code{firstprivate} clauses on @code{scope}
422 @item @code{ompt_callback_work} @tab N @tab
423 @item Default map-type for the @code{map} clause in @code{target enter/exit data}
425 @item New @code{doacross} clause as alias for @code{depend} with
426 @code{source}/@code{sink} modifier @tab Y @tab
427 @item Deprecation of @code{depend} with @code{source}/@code{sink} modifier
429 @item @code{omp_cur_iteration} keyword @tab Y @tab
432 @unnumberedsubsec Other new OpenMP 5.2 features
434 @multitable @columnfractions .60 .10 .25
435 @headitem Description @tab Status @tab Comments
436 @item For Fortran, optional comma between directive and clause @tab N @tab
437 @item Conforming device numbers and @code{omp_initial_device} and
438 @code{omp_invalid_device} enum/PARAMETER @tab Y @tab
439 @item Initial value of @var{default-device-var} ICV with
440 @code{OMP_TARGET_OFFLOAD=mandatory} @tab Y @tab
441 @item @code{all} as @emph{implicit-behavior} for @code{defaultmap} @tab Y @tab
442 @item @emph{interop_types} in any position of the modifier list for the @code{init} clause
443 of the @code{interop} construct @tab N @tab
444 @item Invoke virtual member functions of C++ objects created on the host device
445 on other devices @tab N @tab
446 @item @code{mapper} as map-type modifier in @code{declare mapper} @tab N @tab
453 @unnumberedsubsec New features listed in Appendix B of the OpenMP specification
454 @multitable @columnfractions .60 .10 .25
455 @item Features deprecated in versions 5.0, 5.1 and 5.2 were removed
456 @tab N/A @tab Backward compatibility
457 @item Full support for C23 was added @tab P @tab
458 @item Full support for C++23 was added @tab P @tab
459 @item Full support for Fortran 2023 was added @tab P @tab
460 @item @code{_ALL} suffix to the device-scope environment variables
461 @tab P @tab Host device number wrongly accepted
462 @item @code{num_threads} clause now accepts a list @tab N @tab
463 @item Abstract names added for @code{OMP_NUM_THREADS},
464 @code{OMP_THREAD_LIMIT} and @code{OMP_TEAMS_THREAD_LIMIT}
466 @item Supporting increments with abstract names in @code{OMP_PLACES} @tab N @tab
467 @item Extension of @code{OMP_DEFAULT_DEVICE} and new
468 @code{OMP_AVAILABLE_DEVICES} environment vars @tab N @tab
469 @item New @code{uid} trait for target devices and for
470 @code{OMP_AVAILABLE_DEVICES} and @code{OMP_DEFAULT_DEVICE} @tab N @tab
471 @item New @code{OMP_THREADS_RESERVE} environment variable @tab N @tab
472 @item The @code{decl} attribute was added to the C++ attribute syntax
474 @item The OpenMP directive syntax was extended to include C23 attribute
475 specifiers @tab Y @tab
476 @item Support for pure directives in Fortran's @code{do concurrent} @tab N @tab
477 @item All inarguable clauses take now an optional Boolean argument @tab N @tab
478 @item The @code{adjust_args} clause was extended to specify the argument by position
479 and supports variadic arguments @tab N @tab
480 @item For Fortran, @emph{locator list} can be also function reference with
481 data pointer result @tab N @tab
482 @item Concept of @emph{assumed-size arrays} in C and C++
484 @item @emph{directive-name-modifier} accepted in all clauses @tab N @tab
485 @item Extension of @code{interop} operation of @code{append_args}, allowing
486 all modifiers of the @code{init} clause @tab N @tab
487 @item New argument-free version of @code{depobj} with repeatable clauses and
488 the @code{init} clause @tab N @tab
489 @item Undeprecate omitting the argument to the @code{depend} clause of
490 the argument version of the @code{depend} construct @tab Y @tab
491 @item For Fortran, atomic with BLOCK construct and, for C/C++, with
492 unlimited curly braces supported @tab N @tab
493 @item For Fortran, atomic with pointer comparison @tab N @tab
494 @item For Fortran, atomic with enum and enumeration types @tab N @tab
495 @item For Fortran, atomic compare with storing the comparison result
497 @item Canonical loop sequences and new @code{looprange} clause @tab N @tab
498 @item For Fortran, handling polymorphic types in data-sharing-attribute
499 clauses @tab P @tab @code{private} not supported
500 @item For Fortran, rejecting polymorphic types in data-mapping clauses
501 @tab N @tab not diagnosed (and mostly unsupported)
502 @item New @code{taskgraph} construct including @code{saved} modifier and
503 @code{replayable} clause @tab N @tab
504 @item @code{default} clause on the @code{target} directive and accepting
505 variable categories @tab N @tab
506 @item Semantic change regarding the reference count update with
507 @code{use_device_ptr} and @code{use_device_addr} @tab N @tab
508 @item Support for inductions @tab N @tab
509 @item Reduction over private variables with @code{reduction} clause
511 @item Implicit reduction identifiers of C++ classes
513 @item New @code{init_complete} clause to the @code{scan} directive
515 @item @code{ref} modifier to the @code{map} clause @tab N @tab
516 @item New @code{storage} map-type modifier; context-dependent @code{alloc} and
517 @code{release} are aliases @tab N @tab
518 @item Change of the @emph{map-type} property from @emph{ultimate} to
519 @emph{default} @tab N @tab
520 @item @code{self} modifier to @code{map} and @code{self} as
521 @code{defaultmap} argument @tab N @tab
522 @item Mapping of @emph{assumed-size arrays} in C, C++ and Fortran
524 @item @code{delete} as delete-modifier not as map type @tab N @tab
525 @item For Fortran, the @code{automap} modifier to the @code{enter} clause
526 of @code{declare_target} @tab N @tab
527 @item @code{groupprivate} directive @tab N @tab
528 @item @code{local} clause to @code{declare_target} directive @tab N @tab
529 @item @code{part_size} allocator trait for @code{interleaved} allocator
530 partitions @tab N @tab
531 @item @code{pin_device}, @code{preferred_device} and @code{target_access}
534 @item @code{access} allocator trait changes @tab N @tab
535 @item New @code{partitioner} value to @code{partition} allocator trait
537 @item Semicolon-separated list to @code{uses_allocators} @tab N @tab
538 @item New @code{need_device_addr} modifier to @code{adjust_args} clause @tab N @tab
539 @item @code{interop} clause to @code{dispatch} @tab N @tab
540 @item Scope requirement changes for @code{declare_target} @tab N @tab
541 @item @code{message} and @code{severity} clauses to @code{parallel} directive
543 @item @code{self_maps} clause to @code{requires} directive @tab Y @tab
544 @item @code{no_openmp_constructs} assumptions clause @tab N @tab
545 @item Restriction for @code{ordered} regarding loop-transforming directives
547 @item @code{apply} clause to loop-transforming constructs @tab N @tab
548 @item Non-constant values in the @code{sizes} clause @tab N @tab
549 @item @code{fuse} loop-transformation construct @tab N @tab
550 @item @code{interchange} loop-transformation construct @tab N @tab
551 @item @code{reverse} loop-transformation construct @tab N @tab
552 @item @code{split} loop-transformation construct @tab N @tab
553 @item @code{stipe} loop-transformation construct @tab N @tab
554 @item @code{tile} permitting association of grid and inter-tile loops @tab N @tab
555 @item @code{strict} modifier keyword to @code{num_threads} @tab N @tab
556 @item @code{safesync} clause to the @code{parallel} construct @tab N @tab
557 @item @code{omp_curr_progress_width} identifier @tab N @tab
558 @item @code{omp_get_max_progress_width} runtime routine @tab N @tab
559 @item Lifted restrictions on @code{order(concurrent)} and, hence, the
560 @code{loop} construct @tab N @tab
561 @item @code{atomic} permitted in a construct with @code{order(concurrent)}
563 @item Lifted restrictions on not-strictly-nested regions with
564 @code{order(concurrent)} @tab N @tab
565 @item @code{workdistribute} directive for Fortran @tab N @tab
566 @item Fortran @code{DO CONCURRENT} as associated loop in a @code{loop} construct
568 @item New @code{task_iteration} directive inside @code{taskloop} @tab N @tab
569 @item @code{threadset} clause in task-generating constructs @tab N @tab
570 @item New @code{priority} clause to @code{target}, @code{target_enter_data},
571 @code{target_data}, @code{target_exit_data} and @code{target_update}
573 @item New @code{device_type} clause to the @code{target} directive
575 @item @code{target_data} as composite construct @tab N @tab
576 @item @code{nowait} clause with reverse-offload @code{target} directives
578 @item Extended @emph{prefer-type} modifier to @code{init} clause @tab N @tab
579 @item Boolean argument to @code{nowait} and @code{nogroup} may be non constant
581 @item @code{memscope} clause to @code{atomic} and @code{flush} @tab N @tab
582 @item New @code{transparent} clause for multi-generational task-dependence graphs
584 @item The @code{cancel} construct now completes tasks with unfulfilled events
586 @item @code{omp_fulfill_event} routine was restricted regarding fulfillment of
587 event variables @tab N @tab
588 @item Added rule for compound-directive names, permitting many more combinations
590 @item @code{omp_is_free_agent} and @code{omp_ancestor_is_free_agent} routines
592 @item @code{omp_get_device_from_uid} and @code{omp_get_uid_from_device} routines
594 @item @code{omp_get_device_num_teams}, @code{omp_set_device_num_teams},
595 @code{omp_get_device_teams_thread_limit}, and
596 @code{omp_set_device_teams_thread_limit} routines @tab N @tab
597 @item @code{omp_target_memset} and @code{omp_target_memset_async} routines
599 @item Fortran version of the interop runtime routines @tab N @tab
600 @item Routines for obtaining memory spaces/allocators for shared/device memory
602 @item @code{omp_get_memspace_num_resources} routine @tab N @tab
603 @item @code{omp_get_memspace_pagesize} routine @tab N @tab
604 @item @code{omp_get_submemspace} routine @tab N @tab
605 @item @code{omp_init_mempartitioner}, @code{omp_destroy_mempartitioner},
606 @code{omp_init_mempartition}, @code{omp_destroy_mempartition},
607 @code{omp_mempartition_set_part}, @code{omp_mempartition_get_user_data}
609 @item Deprecation of the @code{target_data_op}, @code{target},
610 @code{target_map} and @code{target_submit} callbacks and as values that
611 @code{set_callback} must return @tab N @tab
612 @item @code{ompt_target_data_transfer} and @code{ompt_target_data_transfer_async}
613 values in @code{ompt_target_data_op_t} enum @tab N @tab
614 @item The values @code{ompt_target_data_transfer_to_device},
615 @code{ompt_target_data_transfer_from_device},
616 @code{ompt_target_data_transfer_to_device_async} and
617 @code{ompt_target_data_transfer_from_device_async} of the @code{target_data_op}
618 OMPT type were deprecated @tab N @tab
619 @item @code{ompt_get_buffer_limits} OMPT routine @tab N @tab
622 @unnumberedsubsec Deprecated features, unless listed above
623 @multitable @columnfractions .60 .10 .25
624 @item Deprecation of omitting the optional white space to separate adjacent
625 keywords in the directive-name in Fortran (fixed and free source form)
627 @item Deprecation of the combiner expression in the @code{declare_reduction}
629 @item Deprecation of the Fortran include file @code{omp_lib.h}
633 @unnumberedsubsec Other new OpenMP 6.0 features
634 @multitable @columnfractions .60 .10 .25
635 @item Multi-word directives now use underscore by default @tab N @tab
636 @item Relaxed Fortran restrictions to the @code{aligned} clause @tab N @tab
637 @item Mapping lambda captures @tab N @tab
638 @item New @code{omp_pause_stop_tool} constant for omp_pause_resource @tab N @tab
639 @item In Fortran (fixed and free source form), spaces between directive names are mandatory
641 @item Update of the map-type decay for mapping and @code{declare_mapper}
647 @c ---------------------------------------------------------------------
648 @c OpenMP Runtime Library Routines
649 @c ---------------------------------------------------------------------
651 @node Runtime Library Routines
652 @chapter OpenMP Runtime Library Routines
654 The runtime routines described here are defined by Section 18 of the OpenMP
655 specification in version 5.2.
658 * Thread Team Routines::
659 * Thread Affinity Routines::
660 * Teams Region Routines::
662 * Resource Relinquishing Routines::
663 * Device Information Routines::
664 * Device Memory Routines::
668 * Interoperability Routines::
669 * Memory Management Routines::
670 @c * Tool Control Routine::
671 * Environment Display Routine::
676 @node Thread Team Routines
677 @section Thread Team Routines
679 Routines controlling threads in the current contention group.
680 They have C linkage and do not throw exceptions.
683 * omp_set_num_threads:: Set upper team size limit
684 * omp_get_num_threads:: Size of the active team
685 * omp_get_max_threads:: Maximum number of threads of parallel region
686 * omp_get_thread_num:: Current thread ID
687 * omp_in_parallel:: Whether a parallel region is active
688 * omp_set_dynamic:: Enable/disable dynamic teams
689 * omp_get_dynamic:: Dynamic teams setting
690 * omp_get_cancellation:: Whether cancellation support is enabled
691 * omp_set_nested:: Enable/disable nested parallel regions
692 * omp_get_nested:: Nested parallel regions
693 * omp_set_schedule:: Set the runtime scheduling method
694 * omp_get_schedule:: Obtain the runtime scheduling method
695 * omp_get_teams_thread_limit:: Maximum number of threads imposed by teams
696 * omp_get_supported_active_levels:: Maximum number of active regions supported
697 * omp_set_max_active_levels:: Limits the number of active parallel regions
698 * omp_get_max_active_levels:: Current maximum number of active regions
699 * omp_get_level:: Number of parallel regions
700 * omp_get_ancestor_thread_num:: Ancestor thread ID
701 * omp_get_team_size:: Number of threads in a team
702 * omp_get_active_level:: Number of active parallel regions
707 @node omp_set_num_threads
708 @subsection @code{omp_set_num_threads} -- Set upper team size limit
710 @item @emph{Description}:
711 Specifies the number of threads used by default in subsequent parallel
712 sections, if those do not specify a @code{num_threads} clause. The
713 argument of @code{omp_set_num_threads} shall be a positive integer.
716 @multitable @columnfractions .20 .80
717 @item @emph{Prototype}: @tab @code{void omp_set_num_threads(int num_threads);}
720 @item @emph{Fortran}:
721 @multitable @columnfractions .20 .80
722 @item @emph{Interface}: @tab @code{subroutine omp_set_num_threads(num_threads)}
723 @item @tab @code{integer, intent(in) :: num_threads}
726 @item @emph{See also}:
727 @ref{OMP_NUM_THREADS}, @ref{omp_get_num_threads}, @ref{omp_get_max_threads}
729 @item @emph{Reference}:
730 @uref{https://www.openmp.org, OpenMP specification v4.5}, Section 3.2.1.
735 @node omp_get_num_threads
736 @subsection @code{omp_get_num_threads} -- Size of the active team
738 @item @emph{Description}:
739 Returns the number of threads in the current team. In a sequential section of
740 the program @code{omp_get_num_threads} returns 1.
742 The default team size may be initialized at startup by the
743 @env{OMP_NUM_THREADS} environment variable. At runtime, the size
744 of the current team may be set either by the @code{NUM_THREADS}
745 clause or by @code{omp_set_num_threads}. If none of the above were
746 used to define a specific value and @env{OMP_DYNAMIC} is disabled,
747 one thread per CPU online is used.
750 @multitable @columnfractions .20 .80
751 @item @emph{Prototype}: @tab @code{int omp_get_num_threads(void);}
754 @item @emph{Fortran}:
755 @multitable @columnfractions .20 .80
756 @item @emph{Interface}: @tab @code{integer function omp_get_num_threads()}
759 @item @emph{See also}:
760 @ref{omp_get_max_threads}, @ref{omp_set_num_threads}, @ref{OMP_NUM_THREADS}
762 @item @emph{Reference}:
763 @uref{https://www.openmp.org, OpenMP specification v4.5}, Section 3.2.2.
768 @node omp_get_max_threads
769 @subsection @code{omp_get_max_threads} -- Maximum number of threads of parallel region
771 @item @emph{Description}:
772 Return the maximum number of threads used for the current parallel region
773 that does not use the clause @code{num_threads}.
776 @multitable @columnfractions .20 .80
777 @item @emph{Prototype}: @tab @code{int omp_get_max_threads(void);}
780 @item @emph{Fortran}:
781 @multitable @columnfractions .20 .80
782 @item @emph{Interface}: @tab @code{integer function omp_get_max_threads()}
785 @item @emph{See also}:
786 @ref{omp_set_num_threads}, @ref{omp_set_dynamic}, @ref{omp_get_thread_limit}
788 @item @emph{Reference}:
789 @uref{https://www.openmp.org, OpenMP specification v4.5}, Section 3.2.3.
794 @node omp_get_thread_num
795 @subsection @code{omp_get_thread_num} -- Current thread ID
797 @item @emph{Description}:
798 Returns a unique thread identification number within the current team.
799 In a sequential parts of the program, @code{omp_get_thread_num}
800 always returns 0. In parallel regions the return value varies
801 from 0 to @code{omp_get_num_threads}-1 inclusive. The return
802 value of the primary thread of a team is always 0.
805 @multitable @columnfractions .20 .80
806 @item @emph{Prototype}: @tab @code{int omp_get_thread_num(void);}
809 @item @emph{Fortran}:
810 @multitable @columnfractions .20 .80
811 @item @emph{Interface}: @tab @code{integer function omp_get_thread_num()}
814 @item @emph{See also}:
815 @ref{omp_get_num_threads}, @ref{omp_get_ancestor_thread_num}
817 @item @emph{Reference}:
818 @uref{https://www.openmp.org, OpenMP specification v4.5}, Section 3.2.4.
823 @node omp_in_parallel
824 @subsection @code{omp_in_parallel} -- Whether a parallel region is active
826 @item @emph{Description}:
827 This function returns @code{true} if currently running in parallel,
828 @code{false} otherwise. Here, @code{true} and @code{false} represent
829 their language-specific counterparts.
832 @multitable @columnfractions .20 .80
833 @item @emph{Prototype}: @tab @code{int omp_in_parallel(void);}
836 @item @emph{Fortran}:
837 @multitable @columnfractions .20 .80
838 @item @emph{Interface}: @tab @code{logical function omp_in_parallel()}
841 @item @emph{Reference}:
842 @uref{https://www.openmp.org, OpenMP specification v4.5}, Section 3.2.6.
846 @node omp_set_dynamic
847 @subsection @code{omp_set_dynamic} -- Enable/disable dynamic teams
849 @item @emph{Description}:
850 Enable or disable the dynamic adjustment of the number of threads
851 within a team. The function takes the language-specific equivalent
852 of @code{true} and @code{false}, where @code{true} enables dynamic
853 adjustment of team sizes and @code{false} disables it.
856 @multitable @columnfractions .20 .80
857 @item @emph{Prototype}: @tab @code{void omp_set_dynamic(int dynamic_threads);}
860 @item @emph{Fortran}:
861 @multitable @columnfractions .20 .80
862 @item @emph{Interface}: @tab @code{subroutine omp_set_dynamic(dynamic_threads)}
863 @item @tab @code{logical, intent(in) :: dynamic_threads}
866 @item @emph{See also}:
867 @ref{OMP_DYNAMIC}, @ref{omp_get_dynamic}
869 @item @emph{Reference}:
870 @uref{https://www.openmp.org, OpenMP specification v4.5}, Section 3.2.7.
875 @node omp_get_dynamic
876 @subsection @code{omp_get_dynamic} -- Dynamic teams setting
878 @item @emph{Description}:
879 This function returns @code{true} if enabled, @code{false} otherwise.
880 Here, @code{true} and @code{false} represent their language-specific
883 The dynamic team setting may be initialized at startup by the
884 @env{OMP_DYNAMIC} environment variable or at runtime using
885 @code{omp_set_dynamic}. If undefined, dynamic adjustment is
889 @multitable @columnfractions .20 .80
890 @item @emph{Prototype}: @tab @code{int omp_get_dynamic(void);}
893 @item @emph{Fortran}:
894 @multitable @columnfractions .20 .80
895 @item @emph{Interface}: @tab @code{logical function omp_get_dynamic()}
898 @item @emph{See also}:
899 @ref{omp_set_dynamic}, @ref{OMP_DYNAMIC}
901 @item @emph{Reference}:
902 @uref{https://www.openmp.org, OpenMP specification v4.5}, Section 3.2.8.
907 @node omp_get_cancellation
908 @subsection @code{omp_get_cancellation} -- Whether cancellation support is enabled
910 @item @emph{Description}:
911 This function returns @code{true} if cancellation is activated, @code{false}
912 otherwise. Here, @code{true} and @code{false} represent their language-specific
913 counterparts. Unless @env{OMP_CANCELLATION} is set true, cancellations are
917 @multitable @columnfractions .20 .80
918 @item @emph{Prototype}: @tab @code{int omp_get_cancellation(void);}
921 @item @emph{Fortran}:
922 @multitable @columnfractions .20 .80
923 @item @emph{Interface}: @tab @code{logical function omp_get_cancellation()}
926 @item @emph{See also}:
927 @ref{OMP_CANCELLATION}
929 @item @emph{Reference}:
930 @uref{https://www.openmp.org, OpenMP specification v4.5}, Section 3.2.9.
936 @subsection @code{omp_set_nested} -- Enable/disable nested parallel regions
938 @item @emph{Description}:
939 Enable or disable nested parallel regions, i.e., whether team members
940 are allowed to create new teams. The function takes the language-specific
941 equivalent of @code{true} and @code{false}, where @code{true} enables
942 dynamic adjustment of team sizes and @code{false} disables it.
944 Enabling nested parallel regions also sets the maximum number of
945 active nested regions to the maximum supported. Disabling nested parallel
946 regions sets the maximum number of active nested regions to one.
948 Note that the @code{omp_set_nested} API routine was deprecated
949 in the OpenMP specification 5.0 in favor of @code{omp_set_max_active_levels}.
952 @multitable @columnfractions .20 .80
953 @item @emph{Prototype}: @tab @code{void omp_set_nested(int nested);}
956 @item @emph{Fortran}:
957 @multitable @columnfractions .20 .80
958 @item @emph{Interface}: @tab @code{subroutine omp_set_nested(nested)}
959 @item @tab @code{logical, intent(in) :: nested}
962 @item @emph{See also}:
963 @ref{omp_get_nested}, @ref{omp_set_max_active_levels},
964 @ref{OMP_MAX_ACTIVE_LEVELS}, @ref{OMP_NESTED}
966 @item @emph{Reference}:
967 @uref{https://www.openmp.org, OpenMP specification v4.5}, Section 3.2.10.
973 @subsection @code{omp_get_nested} -- Nested parallel regions
975 @item @emph{Description}:
976 This function returns @code{true} if nested parallel regions are
977 enabled, @code{false} otherwise. Here, @code{true} and @code{false}
978 represent their language-specific counterparts.
980 The state of nested parallel regions at startup depends on several
981 environment variables. If @env{OMP_MAX_ACTIVE_LEVELS} is defined
982 and is set to greater than one, then nested parallel regions will be
983 enabled. If not defined, then the value of the @env{OMP_NESTED}
984 environment variable will be followed if defined. If neither are
985 defined, then if either @env{OMP_NUM_THREADS} or @env{OMP_PROC_BIND}
986 are defined with a list of more than one value, then nested parallel
987 regions are enabled. If none of these are defined, then nested parallel
988 regions are disabled by default.
990 Nested parallel regions can be enabled or disabled at runtime using
991 @code{omp_set_nested}, or by setting the maximum number of nested
992 regions with @code{omp_set_max_active_levels} to one to disable, or
995 Note that the @code{omp_get_nested} API routine was deprecated
996 in the OpenMP specification 5.0 in favor of @code{omp_get_max_active_levels}.
999 @multitable @columnfractions .20 .80
1000 @item @emph{Prototype}: @tab @code{int omp_get_nested(void);}
1003 @item @emph{Fortran}:
1004 @multitable @columnfractions .20 .80
1005 @item @emph{Interface}: @tab @code{logical function omp_get_nested()}
1008 @item @emph{See also}:
1009 @ref{omp_get_max_active_levels}, @ref{omp_set_nested},
1010 @ref{OMP_MAX_ACTIVE_LEVELS}, @ref{OMP_NESTED}
1012 @item @emph{Reference}:
1013 @uref{https://www.openmp.org, OpenMP specification v4.5}, Section 3.2.11.
1018 @node omp_set_schedule
1019 @subsection @code{omp_set_schedule} -- Set the runtime scheduling method
1021 @item @emph{Description}:
1022 Sets the runtime scheduling method. The @var{kind} argument can have the
1023 value @code{omp_sched_static}, @code{omp_sched_dynamic},
1024 @code{omp_sched_guided} or @code{omp_sched_auto}. Except for
1025 @code{omp_sched_auto}, the chunk size is set to the value of
1026 @var{chunk_size} if positive, or to the default value if zero or negative.
1027 For @code{omp_sched_auto} the @var{chunk_size} argument is ignored.
1030 @multitable @columnfractions .20 .80
1031 @item @emph{Prototype}: @tab @code{void omp_set_schedule(omp_sched_t kind, int chunk_size);}
1034 @item @emph{Fortran}:
1035 @multitable @columnfractions .20 .80
1036 @item @emph{Interface}: @tab @code{subroutine omp_set_schedule(kind, chunk_size)}
1037 @item @tab @code{integer(kind=omp_sched_kind) kind}
1038 @item @tab @code{integer chunk_size}
1041 @item @emph{See also}:
1042 @ref{omp_get_schedule}
1045 @item @emph{Reference}:
1046 @uref{https://www.openmp.org, OpenMP specification v4.5}, Section 3.2.12.
1051 @node omp_get_schedule
1052 @subsection @code{omp_get_schedule} -- Obtain the runtime scheduling method
1054 @item @emph{Description}:
1055 Obtain the runtime scheduling method. The @var{kind} argument is set to
1056 @code{omp_sched_static}, @code{omp_sched_dynamic},
1057 @code{omp_sched_guided} or @code{omp_sched_auto}. The second argument,
1058 @var{chunk_size}, is set to the chunk size.
1061 @multitable @columnfractions .20 .80
1062 @item @emph{Prototype}: @tab @code{void omp_get_schedule(omp_sched_t *kind, int *chunk_size);}
1065 @item @emph{Fortran}:
1066 @multitable @columnfractions .20 .80
1067 @item @emph{Interface}: @tab @code{subroutine omp_get_schedule(kind, chunk_size)}
1068 @item @tab @code{integer(kind=omp_sched_kind) kind}
1069 @item @tab @code{integer chunk_size}
1072 @item @emph{See also}:
1073 @ref{omp_set_schedule}, @ref{OMP_SCHEDULE}
1075 @item @emph{Reference}:
1076 @uref{https://www.openmp.org, OpenMP specification v4.5}, Section 3.2.13.
1080 @node omp_get_teams_thread_limit
1081 @subsection @code{omp_get_teams_thread_limit} -- Maximum number of threads imposed by teams
1083 @item @emph{Description}:
1084 Return the maximum number of threads that are able to participate in
1085 each team created by a teams construct.
1088 @multitable @columnfractions .20 .80
1089 @item @emph{Prototype}: @tab @code{int omp_get_teams_thread_limit(void);}
1092 @item @emph{Fortran}:
1093 @multitable @columnfractions .20 .80
1094 @item @emph{Interface}: @tab @code{integer function omp_get_teams_thread_limit()}
1097 @item @emph{See also}:
1098 @ref{omp_set_teams_thread_limit}, @ref{OMP_TEAMS_THREAD_LIMIT}
1100 @item @emph{Reference}:
1101 @uref{https://www.openmp.org, OpenMP specification v5.1}, Section 3.4.6.
1106 @node omp_get_supported_active_levels
1107 @subsection @code{omp_get_supported_active_levels} -- Maximum number of active regions supported
1109 @item @emph{Description}:
1110 This function returns the maximum number of nested, active parallel regions
1111 supported by this implementation.
1114 @multitable @columnfractions .20 .80
1115 @item @emph{Prototype}: @tab @code{int omp_get_supported_active_levels(void);}
1118 @item @emph{Fortran}:
1119 @multitable @columnfractions .20 .80
1120 @item @emph{Interface}: @tab @code{integer function omp_get_supported_active_levels()}
1123 @item @emph{See also}:
1124 @ref{omp_get_max_active_levels}, @ref{omp_set_max_active_levels}
1126 @item @emph{Reference}:
1127 @uref{https://www.openmp.org, OpenMP specification v5.0}, Section 3.2.15.
1132 @node omp_set_max_active_levels
1133 @subsection @code{omp_set_max_active_levels} -- Limits the number of active parallel regions
1135 @item @emph{Description}:
1136 This function limits the maximum allowed number of nested, active
1137 parallel regions. @var{max_levels} must be less or equal to
1138 the value returned by @code{omp_get_supported_active_levels}.
1141 @multitable @columnfractions .20 .80
1142 @item @emph{Prototype}: @tab @code{void omp_set_max_active_levels(int max_levels);}
1145 @item @emph{Fortran}:
1146 @multitable @columnfractions .20 .80
1147 @item @emph{Interface}: @tab @code{subroutine omp_set_max_active_levels(max_levels)}
1148 @item @tab @code{integer max_levels}
1151 @item @emph{See also}:
1152 @ref{omp_get_max_active_levels}, @ref{omp_get_active_level},
1153 @ref{omp_get_supported_active_levels}
1155 @item @emph{Reference}:
1156 @uref{https://www.openmp.org, OpenMP specification v4.5}, Section 3.2.15.
1161 @node omp_get_max_active_levels
1162 @subsection @code{omp_get_max_active_levels} -- Current maximum number of active regions
1164 @item @emph{Description}:
1165 This function obtains the maximum allowed number of nested, active parallel regions.
1168 @multitable @columnfractions .20 .80
1169 @item @emph{Prototype}: @tab @code{int omp_get_max_active_levels(void);}
1172 @item @emph{Fortran}:
1173 @multitable @columnfractions .20 .80
1174 @item @emph{Interface}: @tab @code{integer function omp_get_max_active_levels()}
1177 @item @emph{See also}:
1178 @ref{omp_set_max_active_levels}, @ref{omp_get_active_level}
1180 @item @emph{Reference}:
1181 @uref{https://www.openmp.org, OpenMP specification v4.5}, Section 3.2.16.
1186 @subsection @code{omp_get_level} -- Obtain the current nesting level
1188 @item @emph{Description}:
1189 This function returns the nesting level for the parallel blocks,
1190 which enclose the calling call.
1193 @multitable @columnfractions .20 .80
1194 @item @emph{Prototype}: @tab @code{int omp_get_level(void);}
1197 @item @emph{Fortran}:
1198 @multitable @columnfractions .20 .80
1199 @item @emph{Interface}: @tab @code{integer function omp_level()}
1202 @item @emph{See also}:
1203 @ref{omp_get_active_level}
1205 @item @emph{Reference}:
1206 @uref{https://www.openmp.org, OpenMP specification v4.5}, Section 3.2.17.
1211 @node omp_get_ancestor_thread_num
1212 @subsection @code{omp_get_ancestor_thread_num} -- Ancestor thread ID
1214 @item @emph{Description}:
1215 This function returns the thread identification number for the given
1216 nesting level of the current thread. For values of @var{level} outside
1217 zero to @code{omp_get_level} -1 is returned; if @var{level} is
1218 @code{omp_get_level} the result is identical to @code{omp_get_thread_num}.
1221 @multitable @columnfractions .20 .80
1222 @item @emph{Prototype}: @tab @code{int omp_get_ancestor_thread_num(int level);}
1225 @item @emph{Fortran}:
1226 @multitable @columnfractions .20 .80
1227 @item @emph{Interface}: @tab @code{integer function omp_get_ancestor_thread_num(level)}
1228 @item @tab @code{integer level}
1231 @item @emph{See also}:
1232 @ref{omp_get_level}, @ref{omp_get_thread_num}, @ref{omp_get_team_size}
1234 @item @emph{Reference}:
1235 @uref{https://www.openmp.org, OpenMP specification v4.5}, Section 3.2.18.
1240 @node omp_get_team_size
1241 @subsection @code{omp_get_team_size} -- Number of threads in a team
1243 @item @emph{Description}:
1244 This function returns the number of threads in a thread team to which
1245 either the current thread or its ancestor belongs. For values of @var{level}
1246 outside zero to @code{omp_get_level}, -1 is returned; if @var{level} is zero,
1247 1 is returned, and for @code{omp_get_level}, the result is identical
1248 to @code{omp_get_num_threads}.
1251 @multitable @columnfractions .20 .80
1252 @item @emph{Prototype}: @tab @code{int omp_get_team_size(int level);}
1255 @item @emph{Fortran}:
1256 @multitable @columnfractions .20 .80
1257 @item @emph{Interface}: @tab @code{integer function omp_get_team_size(level)}
1258 @item @tab @code{integer level}
1261 @item @emph{See also}:
1262 @ref{omp_get_num_threads}, @ref{omp_get_level}, @ref{omp_get_ancestor_thread_num}
1264 @item @emph{Reference}:
1265 @uref{https://www.openmp.org, OpenMP specification v4.5}, Section 3.2.19.
1270 @node omp_get_active_level
1271 @subsection @code{omp_get_active_level} -- Number of parallel regions
1273 @item @emph{Description}:
1274 This function returns the nesting level for the active parallel blocks,
1275 which enclose the calling call.
1278 @multitable @columnfractions .20 .80
1279 @item @emph{Prototype}: @tab @code{int omp_get_active_level(void);}
1282 @item @emph{Fortran}:
1283 @multitable @columnfractions .20 .80
1284 @item @emph{Interface}: @tab @code{integer function omp_get_active_level()}
1287 @item @emph{See also}:
1288 @ref{omp_get_level}, @ref{omp_get_max_active_levels}, @ref{omp_set_max_active_levels}
1290 @item @emph{Reference}:
1291 @uref{https://www.openmp.org, OpenMP specification v4.5}, Section 3.2.20.
1296 @node Thread Affinity Routines
1297 @section Thread Affinity Routines
1299 Routines controlling and accessing thread-affinity policies.
1300 They have C linkage and do not throw exceptions.
1303 * omp_get_proc_bind:: Whether threads may be moved between CPUs
1304 @c * omp_get_num_places:: Get the number of places available
1305 @c * omp_get_place_num_procs:: Get the number of processes associated with a place
1306 @c * omp_get_place_proc_ids:: Get number of processes associated with a place
1307 @c * omp_get_place_num:: Get place number of the associated task
1308 @c * omp_get_partition_num_places:: Get number of places of innermost task
1309 @c * omp_get_partition_place_nums:: <fixme>
1310 @c * omp_set_affinity_format:: <fixme>
1311 @c * omp_get_affinity_format:: <fixme>
1312 @c * omp_display_affinity:: <fixme>
1313 @c * omp_capture_affinity:: <fixme>
1318 @node omp_get_proc_bind
1319 @subsection @code{omp_get_proc_bind} -- Whether threads may be moved between CPUs
1321 @item @emph{Description}:
1322 This functions returns the currently active thread affinity policy, which is
1323 set via @env{OMP_PROC_BIND}. Possible values are @code{omp_proc_bind_false},
1324 @code{omp_proc_bind_true}, @code{omp_proc_bind_primary},
1325 @code{omp_proc_bind_master}, @code{omp_proc_bind_close} and @code{omp_proc_bind_spread},
1326 where @code{omp_proc_bind_master} is an alias for @code{omp_proc_bind_primary}.
1329 @multitable @columnfractions .20 .80
1330 @item @emph{Prototype}: @tab @code{omp_proc_bind_t omp_get_proc_bind(void);}
1333 @item @emph{Fortran}:
1334 @multitable @columnfractions .20 .80
1335 @item @emph{Interface}: @tab @code{integer(kind=omp_proc_bind_kind) function omp_get_proc_bind()}
1338 @item @emph{See also}:
1339 @ref{OMP_PROC_BIND}, @ref{OMP_PLACES}, @ref{GOMP_CPU_AFFINITY},
1341 @item @emph{Reference}:
1342 @uref{https://www.openmp.org, OpenMP specification v4.5}, Section 3.2.22.
1347 @node Teams Region Routines
1348 @section Teams Region Routines
1350 Routines controlling the league of teams that are executed in a @code{teams}
1351 region. They have C linkage and do not throw exceptions.
1354 * omp_get_num_teams:: Number of teams
1355 * omp_get_team_num:: Get team number
1356 * omp_set_num_teams:: Set upper teams limit for teams region
1357 * omp_get_max_teams:: Maximum number of teams for teams region
1358 * omp_set_teams_thread_limit:: Set upper thread limit for teams construct
1359 * omp_get_thread_limit:: Maximum number of threads
1364 @node omp_get_num_teams
1365 @subsection @code{omp_get_num_teams} -- Number of teams
1367 @item @emph{Description}:
1368 Returns the number of teams in the current team region.
1371 @multitable @columnfractions .20 .80
1372 @item @emph{Prototype}: @tab @code{int omp_get_num_teams(void);}
1375 @item @emph{Fortran}:
1376 @multitable @columnfractions .20 .80
1377 @item @emph{Interface}: @tab @code{integer function omp_get_num_teams()}
1380 @item @emph{Reference}:
1381 @uref{https://www.openmp.org, OpenMP specification v4.5}, Section 3.2.32.
1386 @node omp_get_team_num
1387 @subsection @code{omp_get_team_num} -- Get team number
1389 @item @emph{Description}:
1390 Returns the team number of the calling thread.
1393 @multitable @columnfractions .20 .80
1394 @item @emph{Prototype}: @tab @code{int omp_get_team_num(void);}
1397 @item @emph{Fortran}:
1398 @multitable @columnfractions .20 .80
1399 @item @emph{Interface}: @tab @code{integer function omp_get_team_num()}
1402 @item @emph{Reference}:
1403 @uref{https://www.openmp.org, OpenMP specification v4.5}, Section 3.2.33.
1408 @node omp_set_num_teams
1409 @subsection @code{omp_set_num_teams} -- Set upper teams limit for teams construct
1411 @item @emph{Description}:
1412 Specifies the upper bound for number of teams created by the teams construct
1413 which does not specify a @code{num_teams} clause. The
1414 argument of @code{omp_set_num_teams} shall be a positive integer.
1417 @multitable @columnfractions .20 .80
1418 @item @emph{Prototype}: @tab @code{void omp_set_num_teams(int num_teams);}
1421 @item @emph{Fortran}:
1422 @multitable @columnfractions .20 .80
1423 @item @emph{Interface}: @tab @code{subroutine omp_set_num_teams(num_teams)}
1424 @item @tab @code{integer, intent(in) :: num_teams}
1427 @item @emph{See also}:
1428 @ref{OMP_NUM_TEAMS}, @ref{omp_get_num_teams}, @ref{omp_get_max_teams}
1430 @item @emph{Reference}:
1431 @uref{https://www.openmp.org, OpenMP specification v5.1}, Section 3.4.3.
1436 @node omp_get_max_teams
1437 @subsection @code{omp_get_max_teams} -- Maximum number of teams of teams region
1439 @item @emph{Description}:
1440 Return the maximum number of teams used for the teams region
1441 that does not use the clause @code{num_teams}.
1444 @multitable @columnfractions .20 .80
1445 @item @emph{Prototype}: @tab @code{int omp_get_max_teams(void);}
1448 @item @emph{Fortran}:
1449 @multitable @columnfractions .20 .80
1450 @item @emph{Interface}: @tab @code{integer function omp_get_max_teams()}
1453 @item @emph{See also}:
1454 @ref{omp_set_num_teams}, @ref{omp_get_num_teams}
1456 @item @emph{Reference}:
1457 @uref{https://www.openmp.org, OpenMP specification v5.1}, Section 3.4.4.
1462 @node omp_set_teams_thread_limit
1463 @subsection @code{omp_set_teams_thread_limit} -- Set upper thread limit for teams construct
1465 @item @emph{Description}:
1466 Specifies the upper bound for number of threads that are available
1467 for each team created by the teams construct which does not specify a
1468 @code{thread_limit} clause. The argument of
1469 @code{omp_set_teams_thread_limit} shall be a positive integer.
1472 @multitable @columnfractions .20 .80
1473 @item @emph{Prototype}: @tab @code{void omp_set_teams_thread_limit(int thread_limit);}
1476 @item @emph{Fortran}:
1477 @multitable @columnfractions .20 .80
1478 @item @emph{Interface}: @tab @code{subroutine omp_set_teams_thread_limit(thread_limit)}
1479 @item @tab @code{integer, intent(in) :: thread_limit}
1482 @item @emph{See also}:
1483 @ref{OMP_TEAMS_THREAD_LIMIT}, @ref{omp_get_teams_thread_limit}, @ref{omp_get_thread_limit}
1485 @item @emph{Reference}:
1486 @uref{https://www.openmp.org, OpenMP specification v5.1}, Section 3.4.5.
1491 @node omp_get_thread_limit
1492 @subsection @code{omp_get_thread_limit} -- Maximum number of threads
1494 @item @emph{Description}:
1495 Return the maximum number of threads of the program.
1498 @multitable @columnfractions .20 .80
1499 @item @emph{Prototype}: @tab @code{int omp_get_thread_limit(void);}
1502 @item @emph{Fortran}:
1503 @multitable @columnfractions .20 .80
1504 @item @emph{Interface}: @tab @code{integer function omp_get_thread_limit()}
1507 @item @emph{See also}:
1508 @ref{omp_get_max_threads}, @ref{OMP_THREAD_LIMIT}
1510 @item @emph{Reference}:
1511 @uref{https://www.openmp.org, OpenMP specification v4.5}, Section 3.2.14.
1516 @node Tasking Routines
1517 @section Tasking Routines
1519 Routines relating to explicit tasks.
1520 They have C linkage and do not throw exceptions.
1523 * omp_get_max_task_priority:: Maximum task priority value that can be set
1524 * omp_in_explicit_task:: Whether a given task is an explicit task
1525 * omp_in_final:: Whether in final or included task region
1526 @c * omp_is_free_agent:: <fixme>/TR12
1527 @c * omp_ancestor_is_free_agent:: <fixme>/TR12
1532 @node omp_get_max_task_priority
1533 @subsection @code{omp_get_max_task_priority} -- Maximum priority value
1534 that can be set for tasks.
1536 @item @emph{Description}:
1537 This function obtains the maximum allowed priority number for tasks.
1540 @multitable @columnfractions .20 .80
1541 @item @emph{Prototype}: @tab @code{int omp_get_max_task_priority(void);}
1544 @item @emph{Fortran}:
1545 @multitable @columnfractions .20 .80
1546 @item @emph{Interface}: @tab @code{integer function omp_get_max_task_priority()}
1549 @item @emph{Reference}:
1550 @uref{https://www.openmp.org, OpenMP specification v4.5}, Section 3.2.29.
1555 @node omp_in_explicit_task
1556 @subsection @code{omp_in_explicit_task} -- Whether a given task is an explicit task
1558 @item @emph{Description}:
1559 The function returns the @var{explicit-task-var} ICV; it returns true when the
1560 encountering task was generated by a task-generating construct such as
1561 @code{target}, @code{task} or @code{taskloop}. Otherwise, the encountering task
1562 is in an implicit task region such as generated by the implicit or explicit
1563 @code{parallel} region and @code{omp_in_explicit_task} returns false.
1566 @multitable @columnfractions .20 .80
1567 @item @emph{Prototype}: @tab @code{int omp_in_explicit_task(void);}
1570 @item @emph{Fortran}:
1571 @multitable @columnfractions .20 .80
1572 @item @emph{Interface}: @tab @code{logical function omp_in_explicit_task()}
1575 @item @emph{Reference}:
1576 @uref{https://www.openmp.org, OpenMP specification v5.2}, Section 18.5.2.
1582 @subsection @code{omp_in_final} -- Whether in final or included task region
1584 @item @emph{Description}:
1585 This function returns @code{true} if currently running in a final
1586 or included task region, @code{false} otherwise. Here, @code{true}
1587 and @code{false} represent their language-specific counterparts.
1590 @multitable @columnfractions .20 .80
1591 @item @emph{Prototype}: @tab @code{int omp_in_final(void);}
1594 @item @emph{Fortran}:
1595 @multitable @columnfractions .20 .80
1596 @item @emph{Interface}: @tab @code{logical function omp_in_final()}
1599 @item @emph{Reference}:
1600 @uref{https://www.openmp.org, OpenMP specification v4.5}, Section 3.2.21.
1605 @node Resource Relinquishing Routines
1606 @section Resource Relinquishing Routines
1608 Routines releasing resources used by the OpenMP runtime.
1609 They have C linkage and do not throw exceptions.
1612 * omp_pause_resource:: Release OpenMP resources on a device
1613 * omp_pause_resource_all:: Release OpenMP resources on all devices
1618 @node omp_pause_resource
1619 @subsection @code{omp_pause_resource} -- Release OpenMP resources on a device
1621 @item @emph{Description}:
1622 Free resources used by the OpenMP program and the runtime library on and for the
1623 device specified by @var{device_num}; on success, zero is returned and non-zero
1626 The value of @var{device_num} must be a conforming device number. The routine
1627 may not be called from within any explicit region and all explicit threads that
1628 do not bind to the implicit parallel region have finalized execution.
1631 @multitable @columnfractions .20 .80
1632 @item @emph{Prototype}: @tab @code{int omp_pause_resource(omp_pause_resource_t kind, int device_num);}
1635 @item @emph{Fortran}:
1636 @multitable @columnfractions .20 .80
1637 @item @emph{Interface}: @tab @code{integer function omp_pause_resource(kind, device_num)}
1638 @item @tab @code{integer (kind=omp_pause_resource_kind) kind}
1639 @item @tab @code{integer device_num}
1642 @item @emph{Reference}:
1643 @uref{https://www.openmp.org, OpenMP specification v5.0}, Section 3.2.43.
1648 @node omp_pause_resource_all
1649 @subsection @code{omp_pause_resource_all} -- Release OpenMP resources on all devices
1651 @item @emph{Description}:
1652 Free resources used by the OpenMP program and the runtime library on all devices,
1653 including the host. On success, zero is returned and non-zero otherwise.
1655 The routine may not be called from within any explicit region and all explicit
1656 threads that do not bind to the implicit parallel region have finalized execution.
1659 @multitable @columnfractions .20 .80
1660 @item @emph{Prototype}: @tab @code{int omp_pause_resource(omp_pause_resource_t kind);}
1663 @item @emph{Fortran}:
1664 @multitable @columnfractions .20 .80
1665 @item @emph{Interface}: @tab @code{integer function omp_pause_resource(kind)}
1666 @item @tab @code{integer (kind=omp_pause_resource_kind) kind}
1669 @item @emph{See also}:
1670 @ref{omp_pause_resource}
1672 @item @emph{Reference}:
1673 @uref{https://www.openmp.org, OpenMP specification v5.0}, Section 3.2.44.
1678 @node Device Information Routines
1679 @section Device Information Routines
1681 Routines related to devices available to an OpenMP program.
1682 They have C linkage and do not throw exceptions.
1685 * omp_get_num_procs:: Number of processors online
1686 @c * omp_get_max_progress_width:: <fixme>/TR11
1687 * omp_set_default_device:: Set the default device for target regions
1688 * omp_get_default_device:: Get the default device for target regions
1689 * omp_get_num_devices:: Number of target devices
1690 * omp_get_device_num:: Get device that current thread is running on
1691 * omp_get_device_from_uid:: Obtain the device number to a unique id
1692 * omp_get_uid_from_device:: Obtain the unique id of a device
1693 * omp_is_initial_device:: Whether executing on the host device
1694 * omp_get_initial_device:: Device number of host device
1695 @c * omp_get_device_num_teams:: <fixme>/TR13
1696 @c * omp_set_device_num_teams:: <fixme>/TR13
1697 @c * omp_get_device_teams_thread_limit:: <fixme>/TR13
1698 @c * omp_set_device_teams_thread_limit:: <fixme>/TR13
1703 @node omp_get_num_procs
1704 @subsection @code{omp_get_num_procs} -- Number of processors online
1706 @item @emph{Description}:
1707 Returns the number of processors online on that device.
1710 @multitable @columnfractions .20 .80
1711 @item @emph{Prototype}: @tab @code{int omp_get_num_procs(void);}
1714 @item @emph{Fortran}:
1715 @multitable @columnfractions .20 .80
1716 @item @emph{Interface}: @tab @code{integer function omp_get_num_procs()}
1719 @item @emph{Reference}:
1720 @uref{https://www.openmp.org, OpenMP specification v4.5}, Section 3.2.5.
1725 @node omp_set_default_device
1726 @subsection @code{omp_set_default_device} -- Set the default device for target regions
1728 @item @emph{Description}:
1729 Get the value of the @emph{default-device-var} ICV, which is used
1730 for target regions without a device clause. The argument
1731 shall be a nonnegative device number, @code{omp_initial_device},
1732 or @code{omp_invalid_device}.
1734 The effect of running this routine in a @code{target} region is unspecified.
1737 @multitable @columnfractions .20 .80
1738 @item @emph{Prototype}: @tab @code{void omp_set_default_device(int device_num);}
1741 @item @emph{Fortran}:
1742 @multitable @columnfractions .20 .80
1743 @item @emph{Interface}: @tab @code{subroutine omp_set_default_device(device_num)}
1744 @item @tab @code{integer device_num}
1747 @item @emph{See also}:
1748 @ref{OMP_DEFAULT_DEVICE}, @ref{omp_get_default_device}
1750 @item @emph{Reference}:
1751 @uref{https://www.openmp.org, OpenMP specification v4.5}, Section 3.2.29.
1756 @node omp_get_default_device
1757 @subsection @code{omp_get_default_device} -- Get the default device for target regions
1759 @item @emph{Description}:
1760 Get the value of the @emph{default-device-var} ICV, which is used
1761 for target regions without a device clause. The value is either a
1762 nonnegative device number, @code{omp_initial_device} or
1763 @code{omp_invalid_device}. Note that for the host, the ICV can have two values
1764 and, hence, this routine might return either the value of the named constant
1765 @code{omp_initial_device} or the value returned by the
1766 @code{omp_get_initial_device} routine.
1768 The effect of running this routine in a @code{target} region is unspecified.
1771 @multitable @columnfractions .20 .80
1772 @item @emph{Prototype}: @tab @code{int omp_get_default_device(void);}
1775 @item @emph{Fortran}:
1776 @multitable @columnfractions .20 .80
1777 @item @emph{Interface}: @tab @code{integer function omp_get_default_device()}
1780 @item @emph{See also}:
1781 @ref{OMP_DEFAULT_DEVICE}, @ref{omp_set_default_device},
1782 @ref{omp_get_initial_device}
1784 @item @emph{Reference}:
1785 @uref{https://www.openmp.org, OpenMP specification v4.5}, Section 3.2.30.
1790 @node omp_get_num_devices
1791 @subsection @code{omp_get_num_devices} -- Number of target devices
1793 @item @emph{Description}:
1794 Returns the number of target devices.
1796 The effect of running this routine in a @code{target} region is unspecified.
1799 @multitable @columnfractions .20 .80
1800 @item @emph{Prototype}: @tab @code{int omp_get_num_devices(void);}
1803 @item @emph{Fortran}:
1804 @multitable @columnfractions .20 .80
1805 @item @emph{Interface}: @tab @code{integer function omp_get_num_devices()}
1808 @item @emph{Reference}:
1809 @uref{https://www.openmp.org, OpenMP specification v4.5}, Section 3.2.31.
1814 @node omp_get_device_num
1815 @subsection @code{omp_get_device_num} -- Return device number of current device
1817 @item @emph{Description}:
1818 This function returns a device number that represents the device that the
1819 current thread is executing on. When called on the host, it returns
1820 the same value as returned by the @code{omp_get_initial_device} function
1821 as required since OpenMP 5.0.
1824 @multitable @columnfractions .20 .80
1825 @item @emph{Prototype}: @tab @code{int omp_get_device_num(void);}
1828 @item @emph{Fortran}:
1829 @multitable @columnfractions .20 .80
1830 @item @emph{Interface}: @tab @code{integer function omp_get_device_num()}
1833 @item @emph{See also}:
1834 @ref{omp_get_initial_device}
1836 @item @emph{Reference}:
1837 @uref{https://www.openmp.org, OpenMP specification v5.0}, Section 3.2.37.
1842 @node omp_get_device_from_uid
1843 @subsection @code{omp_get_device_from_uid} -- Obtain the device number to a unique id
1845 @item @emph{Description}:
1846 This function returns the device number associated with the passed
1847 unique-identifier (UID) string. If no device with this UID is available, the value
1848 @code{omp_invalid_device} is returned. The effect of running this routine in a
1849 @code{target} region is unspecified.
1851 GCC treats the UID string case sensitive; for the initial device, GCC currently
1852 only accepts the value @code{OMP_INITIAL_DEVICE} and returns for it the value
1853 of @code{omp_initial_device}.
1856 @multitable @columnfractions .20 .80
1857 @item @emph{Prototype}: @tab @code{int omp_get_device_from_uid(const char *uid);}
1860 @item @emph{Fortran}:
1861 @multitable @columnfractions .20 .80
1862 @item @emph{Interface}: @tab @code{integer function omp_get_device_from_uid(uid)}
1863 @item @tab @code{character(len=*), intent(in) :: uid}
1866 @item @emph{See also}:
1867 @ref{omp_get_uid_from_device}, @ref{Offload-Target Specifics}
1869 @item @emph{Reference}:
1870 @uref{https://www.openmp.org, OpenMP specification v6.0}, Section 24.7
1875 @node omp_get_uid_from_device
1876 @subsection @code{omp_get_uid_from_device} -- Obtain the unique id of a device
1878 @item @emph{Description}:
1879 This function returns a pointer to a string that represents a unique identifier
1880 (UID) for the device specified by @var{device_num}. It returns a @code{NULL} (C/C++)
1881 or a disassociated pointer (Fortran) for @code{omp_invalid_device}. The effect of
1882 running this routine in a @code{target} region is unspecified.
1884 GCC currently returns for initial device the value @code{OMP_INITIAL_DEVICE}.
1887 @multitable @columnfractions .20 .80
1888 @item @emph{Prototype}: @tab @code{const char *omp_get_uid_from_device(int device_num);}
1891 @item @emph{Fortran}:
1892 @multitable @columnfractions .20 .80
1893 @item @emph{Interface}: @tab @code{character(:) function omp_get_uid_from_device(device_num)}
1894 @item @emph{Interface}: @tab @code{pointer :: omp_get_uid_from_device}
1895 @item @tab @code{integer, intent(in) :: device_num}
1898 @item @emph{See also}:
1899 @ref{omp_get_uid_from_device}, @ref{Offload-Target Specifics}
1901 @item @emph{Reference}:
1902 @uref{https://www.openmp.org, OpenMP specification v6.0}, Section 24.8
1907 @node omp_is_initial_device
1908 @subsection @code{omp_is_initial_device} -- Whether executing on the host device
1910 @item @emph{Description}:
1911 This function returns @code{true} if currently running on the host device,
1912 @code{false} otherwise. Here, @code{true} and @code{false} represent
1913 their language-specific counterparts.
1915 Note that in GCC this function call is already folded to a constant in the
1916 compiler; compile with @option{-fno-builtin-omp_is_initial_device} if a
1917 run-time function is desired.
1920 @multitable @columnfractions .20 .80
1921 @item @emph{Prototype}: @tab @code{int omp_is_initial_device(void);}
1924 @item @emph{Fortran}:
1925 @multitable @columnfractions .20 .80
1926 @item @emph{Interface}: @tab @code{logical function omp_is_initial_device()}
1929 @item @emph{Reference}:
1930 @uref{https://www.openmp.org, OpenMP specification v4.5}, Section 3.2.34.
1935 @node omp_get_initial_device
1936 @subsection @code{omp_get_initial_device} -- Return device number of initial device
1938 @item @emph{Description}:
1939 This function returns a device number that represents the host device.
1940 Since OpenMP 5.1, this is equal to the value returned by the
1941 @code{omp_get_num_devices} function.
1943 The effect of running this routine in a @code{target} region is unspecified.
1946 @multitable @columnfractions .20 .80
1947 @item @emph{Prototype}: @tab @code{int omp_get_initial_device(void);}
1950 @item @emph{Fortran}:
1951 @multitable @columnfractions .20 .80
1952 @item @emph{Interface}: @tab @code{integer function omp_get_initial_device()}
1955 @item @emph{See also}:
1956 @ref{omp_get_num_devices}
1958 @item @emph{Reference}:
1959 @uref{https://www.openmp.org, OpenMP specification v4.5}, Section 3.2.35.
1964 @node Device Memory Routines
1965 @section Device Memory Routines
1967 Routines related to memory allocation and managing corresponding
1968 pointers on devices. They have C linkage and do not throw exceptions.
1971 * omp_target_alloc:: Allocate device memory
1972 * omp_target_free:: Free device memory
1973 * omp_target_is_present:: Check whether storage is mapped
1974 * omp_target_is_accessible:: Check whether memory is device accessible
1975 * omp_target_memcpy:: Copy data between devices
1976 * omp_target_memcpy_async:: Copy data between devices asynchronously
1977 * omp_target_memcpy_rect:: Copy a subvolume of data between devices
1978 * omp_target_memcpy_rect_async:: Copy a subvolume of data between devices asynchronously
1979 @c * omp_target_memset:: <fixme>/TR12
1980 @c * omp_target_memset_async:: <fixme>/TR12
1981 * omp_target_associate_ptr:: Associate a device pointer with a host pointer
1982 * omp_target_disassociate_ptr:: Remove device--host pointer association
1983 * omp_get_mapped_ptr:: Return device pointer to a host pointer
1988 @node omp_target_alloc
1989 @subsection @code{omp_target_alloc} -- Allocate device memory
1991 @item @emph{Description}:
1992 This routine allocates @var{size} bytes of memory in the device environment
1993 associated with the device number @var{device_num}. If successful, a device
1994 pointer is returned, otherwise a null pointer.
1996 In GCC, when the device is the host or the device shares memory with the host,
1997 the memory is allocated on the host; in that case, when @var{size} is zero,
1998 either NULL or a unique pointer value that can later be successfully passed to
1999 @code{omp_target_free} is returned. When the allocation is not performed on
2000 the host, a null pointer is returned when @var{size} is zero; in that case,
2001 additionally a diagnostic might be printed to standard error (stderr).
2003 Running this routine in a @code{target} region except on the initial device
2007 @multitable @columnfractions .20 .80
2008 @item @emph{Prototype}: @tab @code{void *omp_target_alloc(size_t size, int device_num)}
2011 @item @emph{Fortran}:
2012 @multitable @columnfractions .20 .80
2013 @item @emph{Interface}: @tab @code{type(c_ptr) function omp_target_alloc(size, device_num) bind(C)}
2014 @item @tab @code{use, intrinsic :: iso_c_binding, only: c_ptr, c_int, c_size_t}
2015 @item @tab @code{integer(c_size_t), value :: size}
2016 @item @tab @code{integer(c_int), value :: device_num}
2019 @item @emph{See also}:
2020 @ref{omp_target_free}, @ref{omp_target_associate_ptr}
2022 @item @emph{Reference}:
2023 @uref{https://www.openmp.org, OpenMP specification v5.1}, Section 3.8.1
2028 @node omp_target_free
2029 @subsection @code{omp_target_free} -- Free device memory
2031 @item @emph{Description}:
2032 This routine frees memory allocated by the @code{omp_target_alloc} routine.
2033 The @var{device_ptr} argument must be either a null pointer or a device pointer
2034 returned by @code{omp_target_alloc} for the specified @code{device_num}. The
2035 device number @var{device_num} must be a conforming device number.
2037 Running this routine in a @code{target} region except on the initial device
2041 @multitable @columnfractions .20 .80
2042 @item @emph{Prototype}: @tab @code{void omp_target_free(void *device_ptr, int device_num)}
2045 @item @emph{Fortran}:
2046 @multitable @columnfractions .20 .80
2047 @item @emph{Interface}: @tab @code{subroutine omp_target_free(device_ptr, device_num) bind(C)}
2048 @item @tab @code{use, intrinsic :: iso_c_binding, only: c_ptr, c_int}
2049 @item @tab @code{type(c_ptr), value :: device_ptr}
2050 @item @tab @code{integer(c_int), value :: device_num}
2053 @item @emph{See also}:
2054 @ref{omp_target_alloc}, @ref{omp_target_disassociate_ptr}
2056 @item @emph{Reference}:
2057 @uref{https://www.openmp.org, OpenMP specification v5.1}, Section 3.8.2
2062 @node omp_target_is_present
2063 @subsection @code{omp_target_is_present} -- Check whether storage is mapped
2065 @item @emph{Description}:
2066 This routine tests whether storage, identified by the host pointer @var{ptr}
2067 is mapped to the device specified by @var{device_num}. If so, it returns
2068 a nonzero value and otherwise zero.
2070 In GCC, this includes self mapping such that @code{omp_target_is_present}
2071 returns @emph{true} when @var{device_num} specifies the host or when the host
2072 and the device share memory. If @var{ptr} is a null pointer, @var{true} is
2073 returned and if @var{device_num} is an invalid device number, @var{false} is
2076 If those conditions do not apply, @emph{true} is returned if the association has
2077 been established by an explicit or implicit @code{map} clause, the
2078 @code{declare target} directive or a call to the @code{omp_target_associate_ptr}
2081 Running this routine in a @code{target} region except on the initial device
2085 @multitable @columnfractions .20 .80
2086 @item @emph{Prototype}: @tab @code{int omp_target_is_present(const void *ptr,}
2087 @item @tab @code{ int device_num)}
2090 @item @emph{Fortran}:
2091 @multitable @columnfractions .20 .80
2092 @item @emph{Interface}: @tab @code{integer(c_int) function omp_target_is_present(ptr, &}
2093 @item @tab @code{ device_num) bind(C)}
2094 @item @tab @code{use, intrinsic :: iso_c_binding, only: c_ptr, c_int}
2095 @item @tab @code{type(c_ptr), value :: ptr}
2096 @item @tab @code{integer(c_int), value :: device_num}
2099 @item @emph{See also}:
2100 @ref{omp_target_associate_ptr}
2102 @item @emph{Reference}:
2103 @uref{https://www.openmp.org, OpenMP specification v5.1}, Section 3.8.3
2108 @node omp_target_is_accessible
2109 @subsection @code{omp_target_is_accessible} -- Check whether memory is device accessible
2111 @item @emph{Description}:
2112 This routine tests whether memory, starting at the address given by @var{ptr}
2113 and extending @var{size} bytes, is accessibly on the device specified by
2114 @var{device_num}. If so, it returns a nonzero value and otherwise zero.
2116 The address given by @var{ptr} is interpreted to be in the address space of
2117 the device and @var{size} must be positive.
2119 Note that GCC's current implementation assumes that @var{ptr} is a valid host
2120 pointer. Therefore, all addresses given by @var{ptr} are assumed to be
2121 accessible on the initial device. And, to err on the safe side, this memory
2122 is only available on a non-host device that can access all host memory
2123 ([uniform] shared memory access).
2125 Running this routine in a @code{target} region except on the initial device
2129 @multitable @columnfractions .20 .80
2130 @item @emph{Prototype}: @tab @code{int omp_target_is_accessible(const void *ptr,}
2131 @item @tab @code{ size_t size,}
2132 @item @tab @code{ int device_num)}
2135 @item @emph{Fortran}:
2136 @multitable @columnfractions .20 .80
2137 @item @emph{Interface}: @tab @code{integer(c_int) function omp_target_is_accessible(ptr, &}
2138 @item @tab @code{ size, device_num) bind(C)}
2139 @item @tab @code{use, intrinsic :: iso_c_binding, only: c_ptr, c_size_t, c_int}
2140 @item @tab @code{type(c_ptr), value :: ptr}
2141 @item @tab @code{integer(c_size_t), value :: size}
2142 @item @tab @code{integer(c_int), value :: device_num}
2145 @item @emph{See also}:
2146 @ref{omp_target_associate_ptr}
2148 @item @emph{Reference}:
2149 @uref{https://www.openmp.org, OpenMP specification v5.1}, Section 3.8.4
2154 @node omp_target_memcpy
2155 @subsection @code{omp_target_memcpy} -- Copy data between devices
2157 @item @emph{Description}:
2158 This routine copies @var{length} of bytes of data from the device
2159 identified by device number @var{src_device_num} to device @var{dst_device_num}.
2160 The data is copied from the source device from the address provided by
2161 @var{src}, shifted by the offset of @var{src_offset} bytes, to the destination
2162 device's @var{dst} address shifted by @var{dst_offset}. The routine returns
2163 zero on success and non-zero otherwise.
2165 Running this routine in a @code{target} region except on the initial device
2169 @multitable @columnfractions .20 .80
2170 @item @emph{Prototype}: @tab @code{int omp_target_memcpy(void *dst,}
2171 @item @tab @code{ const void *src,}
2172 @item @tab @code{ size_t length,}
2173 @item @tab @code{ size_t dst_offset,}
2174 @item @tab @code{ size_t src_offset,}
2175 @item @tab @code{ int dst_device_num,}
2176 @item @tab @code{ int src_device_num)}
2179 @item @emph{Fortran}:
2180 @multitable @columnfractions .20 .80
2181 @item @emph{Interface}: @tab @code{integer(c_int) function omp_target_memcpy( &}
2182 @item @tab @code{ dst, src, length, dst_offset, src_offset, &}
2183 @item @tab @code{ dst_device_num, src_device_num) bind(C)}
2184 @item @tab @code{use, intrinsic :: iso_c_binding, only: c_ptr, c_size_t, c_int}
2185 @item @tab @code{type(c_ptr), value :: dst, src}
2186 @item @tab @code{integer(c_size_t), value :: length, dst_offset, src_offset}
2187 @item @tab @code{integer(c_int), value :: dst_device_num, src_device_num}
2190 @item @emph{See also}:
2191 @ref{omp_target_memcpy_async}, @ref{omp_target_memcpy_rect}
2193 @item @emph{Reference}:
2194 @uref{https://www.openmp.org, OpenMP specification v5.1}, Section 3.8.5
2199 @node omp_target_memcpy_async
2200 @subsection @code{omp_target_memcpy_async} -- Copy data between devices asynchronously
2202 @item @emph{Description}:
2203 This routine copies asynchronously @var{length} of bytes of data from the
2204 device identified by device number @var{src_device_num} to device
2205 @var{dst_device_num}. The data is copied from the source device from the
2206 address provided by @var{src}, shifted by the offset of @var{src_offset} bytes,
2207 to the destination device's @var{dst} address shifted by @var{dst_offset}.
2208 Task dependence is expressed by passing an array of depend objects to
2209 @var{depobj_list}, where the number of array elements is passed as
2210 @var{depobj_count}; if the count is zero, the @var{depobj_list} argument is
2211 ignored. In C++ and Fortran, the @var{depobj_list} argument can also be
2212 omitted in that case. The routine returns zero if the copying process has
2213 successfully been started and non-zero otherwise.
2215 Running this routine in a @code{target} region except on the initial device
2219 @multitable @columnfractions .20 .80
2220 @item @emph{Prototype}: @tab @code{int omp_target_memcpy_async(void *dst,}
2221 @item @tab @code{ const void *src,}
2222 @item @tab @code{ size_t length,}
2223 @item @tab @code{ size_t dst_offset,}
2224 @item @tab @code{ size_t src_offset,}
2225 @item @tab @code{ int dst_device_num,}
2226 @item @tab @code{ int src_device_num,}
2227 @item @tab @code{ int depobj_count,}
2228 @item @tab @code{ omp_depend_t *depobj_list)}
2231 @item @emph{Fortran}:
2232 @multitable @columnfractions .20 .80
2233 @item @emph{Interface}: @tab @code{integer(c_int) function omp_target_memcpy_async( &}
2234 @item @tab @code{ dst, src, length, dst_offset, src_offset, &}
2235 @item @tab @code{ dst_device_num, src_device_num, &}
2236 @item @tab @code{ depobj_count, depobj_list) bind(C)}
2237 @item @tab @code{use, intrinsic :: iso_c_binding, only: c_ptr, c_size_t, c_int}
2238 @item @tab @code{type(c_ptr), value :: dst, src}
2239 @item @tab @code{integer(c_size_t), value :: length, dst_offset, src_offset}
2240 @item @tab @code{integer(c_int), value :: dst_device_num, src_device_num, depobj_count}
2241 @item @tab @code{integer(omp_depend_kind), optional :: depobj_list(*)}
2244 @item @emph{See also}:
2245 @ref{omp_target_memcpy}, @ref{omp_target_memcpy_rect_async}
2247 @item @emph{Reference}:
2248 @uref{https://www.openmp.org, OpenMP specification v5.1}, Section 3.8.7
2253 @node omp_target_memcpy_rect
2254 @subsection @code{omp_target_memcpy_rect} -- Copy a subvolume of data between devices
2256 @item @emph{Description}:
2257 This routine copies a subvolume of data from the device identified by
2258 device number @var{src_device_num} to device @var{dst_device_num}.
2259 The array has @var{num_dims} dimensions and each array element has a size of
2260 @var{element_size} bytes. The @var{volume} array specifies how many elements
2261 per dimension are copied. The full sizes of the destination and source arrays
2262 are given by the @var{dst_dimensions} and @var{src_dimensions} arguments,
2263 respectively. The offset per dimension to the first element to be copied is
2264 given by the @var{dst_offset} and @var{src_offset} arguments. The routine
2265 returns zero on success and non-zero otherwise.
2267 The OpenMP specification only requires that @var{num_dims} up to three is
2268 supported. In order to find implementation-specific maximally supported number
2269 of dimensions, the routine returns this value when invoked with a null pointer
2270 to both the @var{dst} and @var{src} arguments. As GCC supports arbitrary
2271 dimensions, it returns @code{INT_MAX}.
2273 The device-number arguments must be conforming device numbers, the @var{src} and
2274 @var{dst} must be either both null pointers or all of the following must be
2275 fulfilled: @var{element_size} and @var{num_dims} must be positive and the
2276 @var{volume}, offset and dimension arrays must have at least @var{num_dims}
2279 Running this routine in a @code{target} region is not supported except on
2283 @multitable @columnfractions .20 .80
2284 @item @emph{Prototype}: @tab @code{int omp_target_memcpy_rect(void *dst,}
2285 @item @tab @code{ const void *src,}
2286 @item @tab @code{ size_t element_size,}
2287 @item @tab @code{ int num_dims,}
2288 @item @tab @code{ const size_t *volume,}
2289 @item @tab @code{ const size_t *dst_offset,}
2290 @item @tab @code{ const size_t *src_offset,}
2291 @item @tab @code{ const size_t *dst_dimensions,}
2292 @item @tab @code{ const size_t *src_dimensions,}
2293 @item @tab @code{ int dst_device_num,}
2294 @item @tab @code{ int src_device_num)}
2297 @item @emph{Fortran}:
2298 @multitable @columnfractions .20 .80
2299 @item @emph{Interface}: @tab @code{integer(c_int) function omp_target_memcpy_rect( &}
2300 @item @tab @code{ dst, src, element_size, num_dims, volume, &}
2301 @item @tab @code{ dst_offset, src_offset, dst_dimensions, &}
2302 @item @tab @code{ src_dimensions, dst_device_num, src_device_num) bind(C)}
2303 @item @tab @code{use, intrinsic :: iso_c_binding, only: c_ptr, c_size_t, c_int}
2304 @item @tab @code{type(c_ptr), value :: dst, src}
2305 @item @tab @code{integer(c_size_t), value :: element_size, dst_offset, src_offset}
2306 @item @tab @code{integer(c_size_t), value :: volume, dst_dimensions, src_dimensions}
2307 @item @tab @code{integer(c_int), value :: num_dims, dst_device_num, src_device_num}
2310 @item @emph{See also}:
2311 @ref{omp_target_memcpy_rect_async}, @ref{omp_target_memcpy}
2313 @item @emph{Reference}:
2314 @uref{https://www.openmp.org, OpenMP specification v5.1}, Section 3.8.6
2319 @node omp_target_memcpy_rect_async
2320 @subsection @code{omp_target_memcpy_rect_async} -- Copy a subvolume of data between devices asynchronously
2322 @item @emph{Description}:
2323 This routine copies asynchronously a subvolume of data from the device
2324 identified by device number @var{src_device_num} to device @var{dst_device_num}.
2325 The array has @var{num_dims} dimensions and each array element has a size of
2326 @var{element_size} bytes. The @var{volume} array specifies how many elements
2327 per dimension are copied. The full sizes of the destination and source arrays
2328 are given by the @var{dst_dimensions} and @var{src_dimensions} arguments,
2329 respectively. The offset per dimension to the first element to be copied is
2330 given by the @var{dst_offset} and @var{src_offset} arguments. Task dependence
2331 is expressed by passing an array of depend objects to @var{depobj_list}, where
2332 the number of array elements is passed as @var{depobj_count}; if the count is
2333 zero, the @var{depobj_list} argument is ignored. In C++ and Fortran, the
2334 @var{depobj_list} argument can also be omitted in that case. The routine
2335 returns zero on success and non-zero otherwise.
2337 The OpenMP specification only requires that @var{num_dims} up to three is
2338 supported. In order to find implementation-specific maximally supported number
2339 of dimensions, the routine returns this value when invoked with a null pointer
2340 to both the @var{dst} and @var{src} arguments. As GCC supports arbitrary
2341 dimensions, it returns @code{INT_MAX}.
2343 The device-number arguments must be conforming device numbers, the @var{src} and
2344 @var{dst} must be either both null pointers or all of the following must be
2345 fulfilled: @var{element_size} and @var{num_dims} must be positive and the
2346 @var{volume}, offset and dimension arrays must have at least @var{num_dims}
2349 Running this routine in a @code{target} region is not supported except on
2353 @multitable @columnfractions .20 .80
2354 @item @emph{Prototype}: @tab @code{int omp_target_memcpy_rect_async(void *dst,}
2355 @item @tab @code{ const void *src,}
2356 @item @tab @code{ size_t element_size,}
2357 @item @tab @code{ int num_dims,}
2358 @item @tab @code{ const size_t *volume,}
2359 @item @tab @code{ const size_t *dst_offset,}
2360 @item @tab @code{ const size_t *src_offset,}
2361 @item @tab @code{ const size_t *dst_dimensions,}
2362 @item @tab @code{ const size_t *src_dimensions,}
2363 @item @tab @code{ int dst_device_num,}
2364 @item @tab @code{ int src_device_num,}
2365 @item @tab @code{ int depobj_count,}
2366 @item @tab @code{ omp_depend_t *depobj_list)}
2369 @item @emph{Fortran}:
2370 @multitable @columnfractions .20 .80
2371 @item @emph{Interface}: @tab @code{integer(c_int) function omp_target_memcpy_rect_async( &}
2372 @item @tab @code{ dst, src, element_size, num_dims, volume, &}
2373 @item @tab @code{ dst_offset, src_offset, dst_dimensions, &}
2374 @item @tab @code{ src_dimensions, dst_device_num, src_device_num, &}
2375 @item @tab @code{ depobj_count, depobj_list) bind(C)}
2376 @item @tab @code{use, intrinsic :: iso_c_binding, only: c_ptr, c_size_t, c_int}
2377 @item @tab @code{type(c_ptr), value :: dst, src}
2378 @item @tab @code{integer(c_size_t), value :: element_size, dst_offset, src_offset}
2379 @item @tab @code{integer(c_size_t), value :: volume, dst_dimensions, src_dimensions}
2380 @item @tab @code{integer(c_int), value :: num_dims, dst_device_num, src_device_num}
2381 @item @tab @code{integer(c_int), value :: depobj_count}
2382 @item @tab @code{integer(omp_depend_kind), optional :: depobj_list(*)}
2385 @item @emph{See also}:
2386 @ref{omp_target_memcpy_rect}, @ref{omp_target_memcpy_async}
2388 @item @emph{Reference}:
2389 @uref{https://www.openmp.org, OpenMP specification v5.1}, Section 3.8.8
2394 @node omp_target_associate_ptr
2395 @subsection @code{omp_target_associate_ptr} -- Associate a device pointer with a host pointer
2397 @item @emph{Description}:
2398 This routine associates storage on the host with storage on a device identified
2399 by @var{device_num}. The device pointer is usually obtained by calling
2400 @code{omp_target_alloc} or by other means (but not by using the @code{map}
2401 clauses or the @code{declare target} directive). The host pointer should point
2402 to memory that has a storage size of at least @var{size}.
2404 The @var{device_offset} parameter specifies the offset into @var{device_ptr}
2405 that is used as the base address for the device side of the mapping; the
2406 storage size should be at least @var{device_offset} plus @var{size}.
2408 After the association, the host pointer can be used in a @code{map} clause and
2409 in the @code{to} and @code{from} clauses of the @code{target update} directive
2410 to transfer data between the associated pointers. The reference count of such
2411 associated storage is infinite. The association can be removed by calling
2412 @code{omp_target_disassociate_ptr} which should be done before the lifetime
2413 of either storage ends.
2415 The routine returns nonzero (@code{EINVAL}) when the @var{device_num} invalid,
2416 for when the initial device or the associated device shares memory with the
2417 host. @code{omp_target_associate_ptr} returns zero if @var{host_ptr} points
2418 into already associated storage that is fully inside of a previously associated
2419 memory. Otherwise, if the association was successful zero is returned; if none
2420 of the cases above apply, nonzero (@code{EINVAL}) is returned.
2422 The @code{omp_target_is_present} routine can be used to test whether
2423 associated storage for a device pointer exists.
2425 Running this routine in a @code{target} region except on the initial device
2429 @multitable @columnfractions .20 .80
2430 @item @emph{Prototype}: @tab @code{int omp_target_associate_ptr(const void *host_ptr,}
2431 @item @tab @code{ const void *device_ptr,}
2432 @item @tab @code{ size_t size,}
2433 @item @tab @code{ size_t device_offset,}
2434 @item @tab @code{ int device_num)}
2437 @item @emph{Fortran}:
2438 @multitable @columnfractions .20 .80
2439 @item @emph{Interface}: @tab @code{integer(c_int) function omp_target_associate_ptr(host_ptr, &}
2440 @item @tab @code{ device_ptr, size, device_offset, device_num) bind(C)}
2441 @item @tab @code{use, intrinsic :: iso_c_binding, only: c_ptr, c_int, c_size_t}
2442 @item @tab @code{type(c_ptr), value :: host_ptr, device_ptr}
2443 @item @tab @code{integer(c_size_t), value :: size, device_offset}
2444 @item @tab @code{integer(c_int), value :: device_num}
2447 @item @emph{See also}:
2448 @ref{omp_target_disassociate_ptr}, @ref{omp_target_is_present},
2449 @ref{omp_target_alloc}
2451 @item @emph{Reference}:
2452 @uref{https://www.openmp.org, OpenMP specification v5.1}, Section 3.8.9
2457 @node omp_target_disassociate_ptr
2458 @subsection @code{omp_target_disassociate_ptr} -- Remove device--host pointer association
2460 @item @emph{Description}:
2461 This routine removes the storage association established by calling
2462 @code{omp_target_associate_ptr} and sets the reference count to zero,
2463 even if @code{omp_target_associate_ptr} was invoked multiple times for
2464 for host pointer @code{ptr}. If applicable, the device memory needs
2465 to be freed by the user.
2467 If an associated device storage location for the @var{device_num} was
2468 found and has infinite reference count, the association is removed and
2469 zero is returned. In all other cases, nonzero (@code{EINVAL}) is returned
2470 and no other action is taken.
2472 Note that passing a host pointer where the association to the device pointer
2473 was established with the @code{declare target} directive yields undefined
2476 Running this routine in a @code{target} region except on the initial device
2480 @multitable @columnfractions .20 .80
2481 @item @emph{Prototype}: @tab @code{int omp_target_disassociate_ptr(const void *ptr,}
2482 @item @tab @code{ int device_num)}
2485 @item @emph{Fortran}:
2486 @multitable @columnfractions .20 .80
2487 @item @emph{Interface}: @tab @code{integer(c_int) function omp_target_disassociate_ptr(ptr, &}
2488 @item @tab @code{ device_num) bind(C)}
2489 @item @tab @code{use, intrinsic :: iso_c_binding, only: c_ptr, c_int}
2490 @item @tab @code{type(c_ptr), value :: ptr}
2491 @item @tab @code{integer(c_int), value :: device_num}
2494 @item @emph{See also}:
2495 @ref{omp_target_associate_ptr}
2497 @item @emph{Reference}:
2498 @uref{https://www.openmp.org, OpenMP specification v5.1}, Section 3.8.10
2503 @node omp_get_mapped_ptr
2504 @subsection @code{omp_get_mapped_ptr} -- Return device pointer to a host pointer
2506 @item @emph{Description}:
2507 If the device number is refers to the initial device or to a device with
2508 memory accessible from the host (shared memory), the @code{omp_get_mapped_ptr}
2509 routines returns the value of the passed @var{ptr}. Otherwise, if associated
2510 storage to the passed host pointer @var{ptr} exists on device associated with
2511 @var{device_num}, it returns that pointer. In all other cases and in cases of
2512 an error, a null pointer is returned.
2514 The association of storage location is established either via an explicit or
2515 implicit @code{map} clause, the @code{declare target} directive or the
2516 @code{omp_target_associate_ptr} routine.
2518 Running this routine in a @code{target} region except on the initial device
2522 @multitable @columnfractions .20 .80
2523 @item @emph{Prototype}: @tab @code{void *omp_get_mapped_ptr(const void *ptr, int device_num);}
2526 @item @emph{Fortran}:
2527 @multitable @columnfractions .20 .80
2528 @item @emph{Interface}: @tab @code{type(c_ptr) function omp_get_mapped_ptr(ptr, device_num) bind(C)}
2529 @item @tab @code{use, intrinsic :: iso_c_binding, only: c_ptr, c_int}
2530 @item @tab @code{type(c_ptr), value :: ptr}
2531 @item @tab @code{integer(c_int), value :: device_num}
2534 @item @emph{See also}:
2535 @ref{omp_target_associate_ptr}
2537 @item @emph{Reference}:
2538 @uref{https://www.openmp.org, OpenMP specification v5.1}, Section 3.8.11
2544 @section Lock Routines
2546 Initialize, set, test, unset and destroy simple and nested locks.
2547 The routines have C linkage and do not throw exceptions.
2550 * omp_init_lock:: Initialize simple lock
2551 * omp_init_nest_lock:: Initialize nested lock
2552 @c PR libgomp/109452
2553 @c * omp_init_lock_with_hint:: Initialize simple lock with sync hint
2554 @c * omp_init_nest_lock_with_hint:: Initialize nested lock with sync hint
2555 * omp_destroy_lock:: Destroy simple lock
2556 * omp_destroy_nest_lock:: Destroy nested lock
2557 * omp_set_lock:: Wait for and set simple lock
2558 * omp_set_nest_lock:: Wait for and set simple lock
2559 * omp_unset_lock:: Unset simple lock
2560 * omp_unset_nest_lock:: Unset nested lock
2561 * omp_test_lock:: Test and set simple lock if available
2562 * omp_test_nest_lock:: Test and set nested lock if available
2568 @subsection @code{omp_init_lock} -- Initialize simple lock
2570 @item @emph{Description}:
2571 Initialize a simple lock. After initialization, the lock is in
2575 @multitable @columnfractions .20 .80
2576 @item @emph{Prototype}: @tab @code{void omp_init_lock(omp_lock_t *lock);}
2579 @item @emph{Fortran}:
2580 @multitable @columnfractions .20 .80
2581 @item @emph{Interface}: @tab @code{subroutine omp_init_lock(svar)}
2582 @item @tab @code{integer(omp_lock_kind), intent(out) :: svar}
2585 @item @emph{See also}:
2586 @ref{omp_destroy_lock}
2588 @item @emph{Reference}:
2589 @uref{https://www.openmp.org, OpenMP specification v4.5}, Section 3.3.1.
2594 @node omp_init_nest_lock
2595 @subsection @code{omp_init_nest_lock} -- Initialize nested lock
2597 @item @emph{Description}:
2598 Initialize a nested lock. After initialization, the lock is in
2599 an unlocked state and the nesting count is set to zero.
2602 @multitable @columnfractions .20 .80
2603 @item @emph{Prototype}: @tab @code{void omp_init_nest_lock(omp_nest_lock_t *lock);}
2606 @item @emph{Fortran}:
2607 @multitable @columnfractions .20 .80
2608 @item @emph{Interface}: @tab @code{subroutine omp_init_nest_lock(nvar)}
2609 @item @tab @code{integer(omp_nest_lock_kind), intent(out) :: nvar}
2612 @item @emph{See also}:
2613 @ref{omp_destroy_nest_lock}
2615 @item @emph{Reference}:
2616 @uref{https://www.openmp.org, OpenMP specification v4.5}, Section 3.3.1.
2621 @node omp_destroy_lock
2622 @subsection @code{omp_destroy_lock} -- Destroy simple lock
2624 @item @emph{Description}:
2625 Destroy a simple lock. In order to be destroyed, a simple lock must be
2626 in the unlocked state.
2629 @multitable @columnfractions .20 .80
2630 @item @emph{Prototype}: @tab @code{void omp_destroy_lock(omp_lock_t *lock);}
2633 @item @emph{Fortran}:
2634 @multitable @columnfractions .20 .80
2635 @item @emph{Interface}: @tab @code{subroutine omp_destroy_lock(svar)}
2636 @item @tab @code{integer(omp_lock_kind), intent(inout) :: svar}
2639 @item @emph{See also}:
2642 @item @emph{Reference}:
2643 @uref{https://www.openmp.org, OpenMP specification v4.5}, Section 3.3.3.
2648 @node omp_destroy_nest_lock
2649 @subsection @code{omp_destroy_nest_lock} -- Destroy nested lock
2651 @item @emph{Description}:
2652 Destroy a nested lock. In order to be destroyed, a nested lock must be
2653 in the unlocked state and its nesting count must equal zero.
2656 @multitable @columnfractions .20 .80
2657 @item @emph{Prototype}: @tab @code{void omp_destroy_nest_lock(omp_nest_lock_t *);}
2660 @item @emph{Fortran}:
2661 @multitable @columnfractions .20 .80
2662 @item @emph{Interface}: @tab @code{subroutine omp_destroy_nest_lock(nvar)}
2663 @item @tab @code{integer(omp_nest_lock_kind), intent(inout) :: nvar}
2666 @item @emph{See also}:
2669 @item @emph{Reference}:
2670 @uref{https://www.openmp.org, OpenMP specification v4.5}, Section 3.3.3.
2676 @subsection @code{omp_set_lock} -- Wait for and set simple lock
2678 @item @emph{Description}:
2679 Before setting a simple lock, the lock variable must be initialized by
2680 @code{omp_init_lock}. The calling thread is blocked until the lock
2681 is available. If the lock is already held by the current thread,
2685 @multitable @columnfractions .20 .80
2686 @item @emph{Prototype}: @tab @code{void omp_set_lock(omp_lock_t *lock);}
2689 @item @emph{Fortran}:
2690 @multitable @columnfractions .20 .80
2691 @item @emph{Interface}: @tab @code{subroutine omp_set_lock(svar)}
2692 @item @tab @code{integer(omp_lock_kind), intent(inout) :: svar}
2695 @item @emph{See also}:
2696 @ref{omp_init_lock}, @ref{omp_test_lock}, @ref{omp_unset_lock}
2698 @item @emph{Reference}:
2699 @uref{https://www.openmp.org, OpenMP specification v4.5}, Section 3.3.4.
2704 @node omp_set_nest_lock
2705 @subsection @code{omp_set_nest_lock} -- Wait for and set nested lock
2707 @item @emph{Description}:
2708 Before setting a nested lock, the lock variable must be initialized by
2709 @code{omp_init_nest_lock}. The calling thread is blocked until the lock
2710 is available. If the lock is already held by the current thread, the
2711 nesting count for the lock is incremented.
2714 @multitable @columnfractions .20 .80
2715 @item @emph{Prototype}: @tab @code{void omp_set_nest_lock(omp_nest_lock_t *lock);}
2718 @item @emph{Fortran}:
2719 @multitable @columnfractions .20 .80
2720 @item @emph{Interface}: @tab @code{subroutine omp_set_nest_lock(nvar)}
2721 @item @tab @code{integer(omp_nest_lock_kind), intent(inout) :: nvar}
2724 @item @emph{See also}:
2725 @ref{omp_init_nest_lock}, @ref{omp_unset_nest_lock}
2727 @item @emph{Reference}:
2728 @uref{https://www.openmp.org, OpenMP specification v4.5}, Section 3.3.4.
2733 @node omp_unset_lock
2734 @subsection @code{omp_unset_lock} -- Unset simple lock
2736 @item @emph{Description}:
2737 A simple lock about to be unset must have been locked by @code{omp_set_lock}
2738 or @code{omp_test_lock} before. In addition, the lock must be held by the
2739 thread calling @code{omp_unset_lock}. Then, the lock becomes unlocked. If one
2740 or more threads attempted to set the lock before, one of them is chosen to,
2741 again, set the lock to itself.
2744 @multitable @columnfractions .20 .80
2745 @item @emph{Prototype}: @tab @code{void omp_unset_lock(omp_lock_t *lock);}
2748 @item @emph{Fortran}:
2749 @multitable @columnfractions .20 .80
2750 @item @emph{Interface}: @tab @code{subroutine omp_unset_lock(svar)}
2751 @item @tab @code{integer(omp_lock_kind), intent(inout) :: svar}
2754 @item @emph{See also}:
2755 @ref{omp_set_lock}, @ref{omp_test_lock}
2757 @item @emph{Reference}:
2758 @uref{https://www.openmp.org, OpenMP specification v4.5}, Section 3.3.5.
2763 @node omp_unset_nest_lock
2764 @subsection @code{omp_unset_nest_lock} -- Unset nested lock
2766 @item @emph{Description}:
2767 A nested lock about to be unset must have been locked by @code{omp_set_nested_lock}
2768 or @code{omp_test_nested_lock} before. In addition, the lock must be held by the
2769 thread calling @code{omp_unset_nested_lock}. If the nesting count drops to zero, the
2770 lock becomes unlocked. If one ore more threads attempted to set the lock before,
2771 one of them is chosen to, again, set the lock to itself.
2774 @multitable @columnfractions .20 .80
2775 @item @emph{Prototype}: @tab @code{void omp_unset_nest_lock(omp_nest_lock_t *lock);}
2778 @item @emph{Fortran}:
2779 @multitable @columnfractions .20 .80
2780 @item @emph{Interface}: @tab @code{subroutine omp_unset_nest_lock(nvar)}
2781 @item @tab @code{integer(omp_nest_lock_kind), intent(inout) :: nvar}
2784 @item @emph{See also}:
2785 @ref{omp_set_nest_lock}
2787 @item @emph{Reference}:
2788 @uref{https://www.openmp.org, OpenMP specification v4.5}, Section 3.3.5.
2794 @subsection @code{omp_test_lock} -- Test and set simple lock if available
2796 @item @emph{Description}:
2797 Before setting a simple lock, the lock variable must be initialized by
2798 @code{omp_init_lock}. Contrary to @code{omp_set_lock}, @code{omp_test_lock}
2799 does not block if the lock is not available. This function returns
2800 @code{true} upon success, @code{false} otherwise. Here, @code{true} and
2801 @code{false} represent their language-specific counterparts.
2804 @multitable @columnfractions .20 .80
2805 @item @emph{Prototype}: @tab @code{int omp_test_lock(omp_lock_t *lock);}
2808 @item @emph{Fortran}:
2809 @multitable @columnfractions .20 .80
2810 @item @emph{Interface}: @tab @code{logical function omp_test_lock(svar)}
2811 @item @tab @code{integer(omp_lock_kind), intent(inout) :: svar}
2814 @item @emph{See also}:
2815 @ref{omp_init_lock}, @ref{omp_set_lock}, @ref{omp_set_lock}
2817 @item @emph{Reference}:
2818 @uref{https://www.openmp.org, OpenMP specification v4.5}, Section 3.3.6.
2823 @node omp_test_nest_lock
2824 @subsection @code{omp_test_nest_lock} -- Test and set nested lock if available
2826 @item @emph{Description}:
2827 Before setting a nested lock, the lock variable must be initialized by
2828 @code{omp_init_nest_lock}. Contrary to @code{omp_set_nest_lock},
2829 @code{omp_test_nest_lock} does not block if the lock is not available.
2830 If the lock is already held by the current thread, the new nesting count
2831 is returned. Otherwise, the return value equals zero.
2834 @multitable @columnfractions .20 .80
2835 @item @emph{Prototype}: @tab @code{int omp_test_nest_lock(omp_nest_lock_t *lock);}
2838 @item @emph{Fortran}:
2839 @multitable @columnfractions .20 .80
2840 @item @emph{Interface}: @tab @code{logical function omp_test_nest_lock(nvar)}
2841 @item @tab @code{integer(omp_nest_lock_kind), intent(inout) :: nvar}
2845 @item @emph{See also}:
2846 @ref{omp_init_lock}, @ref{omp_set_lock}, @ref{omp_set_lock}
2848 @item @emph{Reference}:
2849 @uref{https://www.openmp.org, OpenMP specification v4.5}, Section 3.3.6.
2854 @node Timing Routines
2855 @section Timing Routines
2857 Portable, thread-based, wall clock timer.
2858 The routines have C linkage and do not throw exceptions.
2861 * omp_get_wtick:: Get timer precision.
2862 * omp_get_wtime:: Elapsed wall clock time.
2868 @subsection @code{omp_get_wtick} -- Get timer precision
2870 @item @emph{Description}:
2871 Gets the timer precision, i.e., the number of seconds between two
2872 successive clock ticks.
2875 @multitable @columnfractions .20 .80
2876 @item @emph{Prototype}: @tab @code{double omp_get_wtick(void);}
2879 @item @emph{Fortran}:
2880 @multitable @columnfractions .20 .80
2881 @item @emph{Interface}: @tab @code{double precision function omp_get_wtick()}
2884 @item @emph{See also}:
2887 @item @emph{Reference}:
2888 @uref{https://www.openmp.org, OpenMP specification v4.5}, Section 3.4.2.
2894 @subsection @code{omp_get_wtime} -- Elapsed wall clock time
2896 @item @emph{Description}:
2897 Elapsed wall clock time in seconds. The time is measured per thread, no
2898 guarantee can be made that two distinct threads measure the same time.
2899 Time is measured from some "time in the past", which is an arbitrary time
2900 guaranteed not to change during the execution of the program.
2903 @multitable @columnfractions .20 .80
2904 @item @emph{Prototype}: @tab @code{double omp_get_wtime(void);}
2907 @item @emph{Fortran}:
2908 @multitable @columnfractions .20 .80
2909 @item @emph{Interface}: @tab @code{double precision function omp_get_wtime()}
2912 @item @emph{See also}:
2915 @item @emph{Reference}:
2916 @uref{https://www.openmp.org, OpenMP specification v4.5}, Section 3.4.1.
2922 @section Event Routine
2924 Support for event objects.
2925 The routine has C linkage and do not throw exceptions.
2928 * omp_fulfill_event:: Fulfill and destroy an OpenMP event.
2933 @node omp_fulfill_event
2934 @subsection @code{omp_fulfill_event} -- Fulfill and destroy an OpenMP event
2936 @item @emph{Description}:
2937 Fulfill the event associated with the event handle argument. Currently, it
2938 is only used to fulfill events generated by detach clauses on task
2939 constructs - the effect of fulfilling the event is to allow the task to
2942 The result of calling @code{omp_fulfill_event} with an event handle other
2943 than that generated by a detach clause is undefined. Calling it with an
2944 event handle that has already been fulfilled is also undefined.
2947 @multitable @columnfractions .20 .80
2948 @item @emph{Prototype}: @tab @code{void omp_fulfill_event(omp_event_handle_t event);}
2951 @item @emph{Fortran}:
2952 @multitable @columnfractions .20 .80
2953 @item @emph{Interface}: @tab @code{subroutine omp_fulfill_event(event)}
2954 @item @tab @code{integer (kind=omp_event_handle_kind) :: event}
2957 @item @emph{Reference}:
2958 @uref{https://www.openmp.org, OpenMP specification v5.0}, Section 3.5.1.
2963 @node Interoperability Routines
2964 @section Interoperability Routines
2966 Routines to obtain properties from an object of OpenMP interop type.
2967 They have C linkage and do not throw exceptions.
2970 * omp_get_num_interop_properties:: Get the number of implementation-specific properties
2971 * omp_get_interop_int:: Obtain integer-valued interoperability property
2972 * omp_get_interop_ptr:: Obtain pointer-valued interoperability property
2973 * omp_get_interop_str:: Obtain string-valued interoperability property
2974 * omp_get_interop_name:: Obtain the name of an interop_property value as string
2975 * omp_get_interop_type_desc:: Obtain type and description to an interop_property
2976 * omp_get_interop_rc_desc:: Obtain error string to an interop_rc error code
2981 @node omp_get_num_interop_properties
2982 @subsection @code{omp_get_num_interop_properties} -- Get the number of implementation-specific properties
2984 @item @emph{Description}:
2985 The @code{omp_get_num_interop_properties} function returns the number of
2986 implementation-defined interoperability properties available for the passed
2987 @var{interop}, extending the OpenMP-defined properties. The available OpenMP
2988 interop_property-type values range from @code{omp_ipr_first} to the value
2989 returned by @code{omp_get_num_interop_properties} minus one.
2991 No implementation-defined properties are currently defined in GCC.
2993 @c Implementation remark: In GCC, the Fortran interface differs from the one shown
2994 @c below: the function has C binding, @var{interop} is passed by value and an
2995 @c integer of @code{c_int} kind is returned, which permits use of the same ABI as
2996 @c the C function. This does not affect the usage of the function when GCC's
2997 @c @code{omp_lib} module or @code{omp_lib.h} header is used.
3000 @multitable @columnfractions .20 .80
3001 @item @emph{Prototype}: @tab @code{int omp_get_num_interop_properties(const omp_interop_t interop)}
3004 @item @emph{Fortran}:
3005 @multitable @columnfractions .20 .80
3006 @item @emph{Interface}: @tab @code{integer function omp_get_num_interop_properties(interop)}
3007 @item @tab @code{integer(omp_interop_kind), intent(in) :: interop}
3010 @item @emph{See also}:
3011 @ref{omp_get_interop_name}, @ref{omp_get_interop_type_desc}
3013 @item @emph{Reference}:
3014 @uref{https://www.openmp.org, OpenMP specification v5.1}, Section 3.12.1,
3015 @uref{https://www.openmp.org, OpenMP specification v6.0}, Section 26.1
3020 @node omp_get_interop_int
3021 @subsection @code{omp_get_interop_int} -- Obtain integer-valued interoperability property
3023 @item @emph{Description}:
3024 The @code{omp_get_interop_int} function returns the integer value associated
3025 with the @var{property_id} interoperability property of the passed @var{interop}
3026 object. The @var{ret_code} argument is optional, i.e. it can be omitted in C++
3027 and Fortran or used with @code{NULL} as argument in C and C++. If successful,
3028 @var{ret_code} (if present) is set to @code{omp_irc_success}.
3030 In GCC, the effect of running this routine in a @code{target} region that is not
3031 the initial device is unspecified.
3033 @c Implementation remark: In GCC, the Fortran interface differs from the one shown
3034 @c below: the function has C binding and @var{interop} and @var{property_id} are
3035 @c passed by value, which permits use of the same ABI as the C function. This does
3036 @c not affect the usage of the function when GCC's @code{omp_lib} module or
3037 @c @code{omp_lib.h} header is used.
3040 @multitable @columnfractions .20 .80
3041 @item @emph{Prototype}: @tab @code{omp_intptr_t omp_get_interop_int(const omp_interop_t interop,
3042 omp_interop_property_t property_id, int *ret_code)}
3045 @item @emph{Fortran}:
3046 @multitable @columnfractions .20 .80
3047 @item @emph{Interface}: @tab @code{integer(c_intptr_t) function omp_get_interop_int(interop,
3048 property_id, ret_code)}
3049 @item @tab @code{use, intrinsic :: iso_c_binding, only : c_intptr_t}
3050 @item @tab @code{integer(omp_interop_kind), intent(in) :: interop}
3051 @item @tab @code{integer(omp_interop_property_kind) property_id}
3052 @item @tab @code{integer(omp_interop_rc_kind), optional, intent(out) :: ret_code}
3055 @item @emph{See also}:
3056 @ref{omp_get_interop_ptr}, @ref{omp_get_interop_str}, @ref{omp_get_interop_rc_desc}
3058 @item @emph{Reference}:
3059 @uref{https://www.openmp.org, OpenMP specification v5.1}, Section 3.12.2,
3060 @uref{https://www.openmp.org, OpenMP specification v6.0}, Section 26.2
3065 @node omp_get_interop_ptr
3066 @subsection @code{omp_get_interop_ptr} -- Obtain pointer-valued interoperability property
3068 @item @emph{Description}:
3069 The @code{omp_get_interop_int} function returns the pointer value associated with
3070 the @var{property_id} interoperability property of the passed @var{interop}
3071 object. The @var{ret_code} argument is optional, i.e. it can be omitted in C++
3072 and Fortran or used with @code{NULL} as argument in C and C++. If successful,
3073 @var{ret_code} (if present) is set to @code{omp_irc_success}.
3075 In GCC, the effect of running this routine in a @code{target} region that is not
3076 the initial device is unspecified.
3078 @c Implementation remark: In GCC, the Fortran interface differs from the one shown
3079 @c below: the function has C binding and @var{interop} and @var{property_id} are
3080 @c passed by value, which permits use of the same ABI as the C function. This does
3081 @c not affect the usage of the function when GCC's @code{omp_lib} module or
3082 @c @code{omp_lib.h} header is used.
3085 @multitable @columnfractions .20 .80
3086 @item @emph{Prototype}: @tab @code{void *omp_get_interop_ptr(const omp_interop_t interop,
3087 omp_interop_property_t property_id, int *ret_code)}
3090 @item @emph{Fortran}:
3091 @multitable @columnfractions .20 .80
3092 @item @emph{Interface}: @tab @code{type(c_ptr) function omp_get_interop_int(interop,
3093 property_id, ret_code)}
3094 @item @tab @code{use, intrinsic :: iso_c_binding, only : c_ptr}
3095 @item @tab @code{integer(omp_interop_kind), intent(in) :: interop}
3096 @item @tab @code{integer(omp_interop_property_kind) property_id}
3097 @item @tab @code{integer(omp_interop_rc_kind), optional, intent(out) :: ret_code}
3100 @item @emph{See also}:
3101 @ref{omp_get_interop_int}, @ref{omp_get_interop_str}, @ref{omp_get_interop_rc_desc}
3103 @item @emph{Reference}:
3104 @uref{https://www.openmp.org, OpenMP specification v5.1}, Section 3.12.3,
3105 @uref{https://www.openmp.org, OpenMP specification v6.0}, Section 26.3
3110 @node omp_get_interop_str
3111 @subsection @code{omp_get_interop_str} -- Obtain string-valued interoperability property
3113 @item @emph{Description}:
3114 The @code{omp_get_interop_str} function returns the string value associated with
3115 the @var{property_id} interoperability property of the passed @var{interop}
3116 object. The @var{ret_code} argument is optional, i.e. it can be omitted in C++
3117 and Fortran or used with @code{NULL} as argument in C and C++. If successful,
3118 @var{ret_code} (if present) is set to @code{omp_irc_success}.
3120 In GCC, the effect of running this routine in a @code{target} region that is not
3121 the initial device is unspecified.
3123 @c Implementation remark: In GCC, the Fortran interface differs from the one shown
3124 @c below: @var{interop} and @var{property_id} are passed by value. This does not
3125 @c affect the usage of the function when GCC's @code{omp_lib} module or
3126 @c @code{omp_lib.h} header is used.
3129 @multitable @columnfractions .20 .80
3130 @item @emph{Prototype}: @tab @code{const char *omp_get_interop_str(const omp_interop_t interop,
3131 omp_interop_property_t property_id, int *ret_code)}
3134 @item @emph{Fortran}:
3135 @multitable @columnfractions .20 .80
3136 @item @emph{Interface}: @tab @code{character(:) function omp_get_interop_str(interop,
3137 property_id, ret_code)}
3138 @item @tab @code{pointer :: omp_get_interop_str}
3139 @item @tab @code{integer(omp_interop_kind), intent(in) :: interop}
3140 @item @tab @code{integer(omp_interop_property_kind) property_id}
3141 @item @tab @code{integer(omp_interop_rc_kind), optional, intent(out) :: ret_code}
3144 @item @emph{See also}:
3145 @ref{omp_get_interop_int}, @ref{omp_get_interop_ptr}, @ref{omp_get_interop_rc_desc}
3147 @item @emph{Reference}:
3148 @uref{https://www.openmp.org, OpenMP specification v5.1}, Section 3.12.4,
3149 @uref{https://www.openmp.org, OpenMP specification v6.0}, Section 26.4
3154 @node omp_get_interop_name
3155 @subsection @code{omp_get_interop_name} -- Obtain the name of an @code{interop_property} value as string
3157 @item @emph{Description}:
3158 The @code{omp_get_interop_name} function returns the name of the property
3159 itself as string; for the properties specified by the OpenMP specification,
3160 the name matches the name of the named constant with the @samp{omp_ipr_}
3163 @c Implementation remark: In GCC, the Fortran interface differs from the one shown
3164 @c below: @var{interop} and @var{property_id} are passed by value. This does not
3165 @c affect the usage of the function when GCC's @code{omp_lib} module or
3166 @c @code{omp_lib.h} header is used.
3169 @multitable @columnfractions .20 .80
3170 @item @emph{Prototype}: @tab @code{const char *omp_get_interop_name(const omp_interop_t interop,
3171 omp_interop_property_t property_id)}
3174 @item @emph{Fortran}:
3175 @multitable @columnfractions .20 .80
3176 @item @emph{Interface}: @tab @code{character(:) function omp_get_interop_name(interop,
3178 @item @tab @code{pointer :: omp_get_interop_name}
3179 @item @tab @code{integer(omp_interop_kind), intent(in) :: interop}
3180 @item @tab @code{integer(omp_interop_property_kind) property_id}
3183 @item @emph{See also}:
3184 @ref{omp_get_num_interop_properties}, @ref{omp_get_interop_type_desc}
3186 @item @emph{Reference}:
3187 @uref{https://www.openmp.org, OpenMP specification v5.1}, Section 3.12.5,
3188 @uref{https://www.openmp.org, OpenMP specification v6.0}, Section 26.5
3193 @node omp_get_interop_type_desc
3194 @subsection @code{omp_get_interop_type_desc} -- Obtain type and description to an @code{interop_property}
3196 @item @emph{Description}:
3197 The @code{omp_get_interop_type_desc} function returns a string that describes in
3198 human-readable form the data type associated with the @var{property_id}
3199 interoperability property of the passed @var{interop} object.
3201 In GCC, this function returns the name of the C/C++ data type for this property
3202 or @samp{N/A} if this property is not available for the given foreign runtime.
3203 If @var{interop} is @code{omp_interop_none} or for invalid property values,
3204 a null pointer is returned. The effect of running this routine in a
3205 @code{target} region that is not the initial device is unspecified.
3207 @c Implementation remark: In GCC, the Fortran interface differs from the one shown
3208 @c below: @var{interop} and @var{property_id} are passed by value. This does not
3209 @c affect the usage of the function when GCC's @code{omp_lib} module or
3210 @c @code{omp_lib.h} header is used.
3213 @multitable @columnfractions .20 .80
3214 @item @emph{Prototype}: @tab @code{const char *omp_get_interop_type_desc(const omp_interop_t interop,
3215 omp_interop_property_t property_id)}
3218 @item @emph{Fortran}:
3219 @multitable @columnfractions .20 .80
3220 @item @emph{Interface}: @tab @code{character(:) function omp_get_interop_type_desc(interop,
3222 @item @tab @code{pointer :: omp_get_interop_type_desc}
3223 @item @tab @code{integer(omp_interop_kind), intent(in) :: interop}
3224 @item @tab @code{integer(omp_interop_property_kind) property_id}
3227 @item @emph{See also}:
3228 @ref{omp_get_num_interop_properties}, @ref{omp_get_interop_name}
3230 @item @emph{Reference}:
3231 @uref{https://www.openmp.org, OpenMP specification v5.1}, Section 3.12.6,
3232 @uref{https://www.openmp.org, OpenMP specification v6.0}, Section 26.6
3237 @node omp_get_interop_rc_desc
3238 @subsection @code{omp_get_interop_rc_desc} -- Obtain error string to an @code{interop_rc} error code
3240 @item @emph{Description}:
3241 The @code{omp_get_interop_rc_desc} function returns a string value describing
3242 the @var{ret_code} in human-readable form.
3244 The behavior is unspecified if value of @var{ret_code} was not set by an
3245 interoperability routine invoked for @var{interop}.
3248 @multitable @columnfractions .20 .80
3249 @item @emph{Prototype}: @tab @code{const char *omp_get_interop_rc_desc(const omp_interop_t interop,
3250 omp_interop_rc_t ret_code)}
3253 @item @emph{Fortran}:
3254 @multitable @columnfractions .20 .80
3255 @item @emph{Interface}: @tab @code{character(:) function omp_get_interop_rc_desc(interop,
3256 property_id, ret_code)}
3257 @item @tab @code{pointer :: omp_get_interop_rc_desc}
3258 @item @tab @code{integer(omp_interop_kind), intent(in) :: interop}
3259 @item @tab @code{integer (omp_interop_rc_kind) ret_code}
3262 @item @emph{Reference}:
3263 @uref{https://www.openmp.org, OpenMP specification v5.1}, Section 3.12.7,
3264 @uref{https://www.openmp.org, OpenMP specification v6.0}, Section 26.7
3269 @node Memory Management Routines
3270 @section Memory Management Routines
3272 Routines to manage and allocate memory on the current device.
3273 They have C linkage and do not throw exceptions.
3276 @c * omp_get_devices_memspace:: <fixme>/TR13
3277 @c * omp_get_device_memspace:: <fixme>/TR13
3278 @c * omp_get_devices_and_host_memspace:: <fixme>/TR13
3279 @c * omp_get_device_and_host_memspace:: <fixme>/TR13
3280 @c * omp_get_devices_all_memspace:: <fixme>/TR13
3281 @c * omp_get_memspace_num_resources:: <fixme>/TR11
3282 @c * omp_get_memspace_pagesize:: <fixme>/TR13
3283 @c * omp_get_submemspace:: <fixme>/TR11
3284 @c * omp_init_mempartitioner:: <fixme>/TR13
3285 @c * omp_destroy_mempartitioner:: <fixme>/TR13
3286 @c * omp_init_mempartition:: <fixme>/TR13
3287 @c * omp_destroy_mempartition:: <fixme>/TR13
3288 @c * omp_mempartition_set_part:: <fixme>/TR13
3289 @c * omp_mempartition_get_user_data:: <fixme>/TR13
3290 * omp_init_allocator:: Create an allocator
3291 * omp_destroy_allocator:: Destroy an allocator
3292 @c * omp_get_devices_allocator:: <fixme>/TR13
3293 @c * omp_get_device_allocator:: <fixme>/TR13
3294 @c * omp_get_devices_and_host_allocator:: <fixme>/TR13
3295 @c * omp_get_device_and_host_allocator:: <fixme>/TR13
3296 @c * omp_get_devices_all_allocator:: <fixme>/TR13
3297 * omp_set_default_allocator:: Set the default allocator
3298 * omp_get_default_allocator:: Get the default allocator
3299 * omp_alloc:: Memory allocation with an allocator
3300 * omp_aligned_alloc:: Memory allocation with an allocator and alignment
3301 * omp_free:: Freeing memory allocated with OpenMP routines
3302 * omp_calloc:: Allocate nullified memory with an allocator
3303 * omp_aligned_calloc:: Allocate nullified aligned memory with an allocator
3304 * omp_realloc:: Reallocate memory allocated with OpenMP routines
3309 @node omp_init_allocator
3310 @subsection @code{omp_init_allocator} -- Create an allocator
3312 @item @emph{Description}:
3313 Create an allocator that uses the specified memory space and has the specified
3314 traits; if an allocator that fulfills the requirements cannot be created,
3315 @code{omp_null_allocator} is returned.
3317 The predefined memory spaces and available traits can be found at
3318 @ref{OMP_ALLOCATOR}, where the trait names have to be prefixed by
3319 @code{omp_atk_} (e.g. @code{omp_atk_pinned}) and the named trait values by
3320 @code{omp_atv_} (e.g. @code{omp_atv_true}); additionally, @code{omp_atv_default}
3321 may be used as trait value to specify that the default value should be used.
3324 @multitable @columnfractions .20 .80
3325 @item @emph{Prototype}: @tab @code{omp_allocator_handle_t omp_init_allocator(}
3326 @item @tab @code{ omp_memspace_handle_t memspace,}
3327 @item @tab @code{ int ntraits,}
3328 @item @tab @code{ const omp_alloctrait_t traits[]);}
3331 @item @emph{Fortran}:
3332 @multitable @columnfractions .20 .80
3333 @item @emph{Interface}: @tab @code{function omp_init_allocator(memspace, ntraits, traits)}
3334 @item @tab @code{integer (omp_allocator_handle_kind) :: omp_init_allocator}
3335 @item @tab @code{integer (omp_memspace_handle_kind), intent(in) :: memspace}
3336 @item @tab @code{integer, intent(in) :: ntraits}
3337 @item @tab @code{type (omp_alloctrait), intent(in) :: traits(*)}
3340 @item @emph{See also}:
3341 @ref{OMP_ALLOCATOR}, @ref{Memory allocation}, @ref{omp_destroy_allocator}
3343 @item @emph{Reference}:
3344 @uref{https://www.openmp.org, OpenMP specification v5.0}, Section 3.7.2
3349 @node omp_destroy_allocator
3350 @subsection @code{omp_destroy_allocator} -- Destroy an allocator
3352 @item @emph{Description}:
3353 Releases all resources used by a memory allocator, which must not represent
3354 a predefined memory allocator. Accessing memory after its allocator has been
3355 destroyed has unspecified behavior. Passing @code{omp_null_allocator} to the
3356 routine is permitted but has no effect.
3360 @multitable @columnfractions .20 .80
3361 @item @emph{Prototype}: @tab @code{void omp_destroy_allocator (omp_allocator_handle_t allocator);}
3364 @item @emph{Fortran}:
3365 @multitable @columnfractions .20 .80
3366 @item @emph{Interface}: @tab @code{subroutine omp_destroy_allocator(allocator)}
3367 @item @tab @code{integer (omp_allocator_handle_kind), intent(in) :: allocator}
3370 @item @emph{See also}:
3371 @ref{omp_init_allocator}
3373 @item @emph{Reference}:
3374 @uref{https://www.openmp.org, OpenMP specification v5.0}, Section 3.7.3
3379 @node omp_set_default_allocator
3380 @subsection @code{omp_set_default_allocator} -- Set the default allocator
3382 @item @emph{Description}:
3383 Sets the default allocator that is used when no allocator has been specified
3384 in the @code{allocate} or @code{allocator} clause or if an OpenMP memory
3385 routine is invoked with the @code{omp_null_allocator} allocator.
3388 @multitable @columnfractions .20 .80
3389 @item @emph{Prototype}: @tab @code{void omp_set_default_allocator(omp_allocator_handle_t allocator);}
3392 @item @emph{Fortran}:
3393 @multitable @columnfractions .20 .80
3394 @item @emph{Interface}: @tab @code{subroutine omp_set_default_allocator(allocator)}
3395 @item @tab @code{integer (omp_allocator_handle_kind), intent(in) :: allocator}
3398 @item @emph{See also}:
3399 @ref{omp_get_default_allocator}, @ref{omp_init_allocator}, @ref{OMP_ALLOCATOR},
3400 @ref{Memory allocation}
3402 @item @emph{Reference}:
3403 @uref{https://www.openmp.org, OpenMP specification v5.0}, Section 3.7.4
3408 @node omp_get_default_allocator
3409 @subsection @code{omp_get_default_allocator} -- Get the default allocator
3411 @item @emph{Description}:
3412 The routine returns the default allocator that is used when no allocator has
3413 been specified in the @code{allocate} or @code{allocator} clause or if an
3414 OpenMP memory routine is invoked with the @code{omp_null_allocator} allocator.
3417 @multitable @columnfractions .20 .80
3418 @item @emph{Prototype}: @tab @code{omp_allocator_handle_t omp_get_default_allocator();}
3421 @item @emph{Fortran}:
3422 @multitable @columnfractions .20 .80
3423 @item @emph{Interface}: @tab @code{function omp_get_default_allocator()}
3424 @item @tab @code{integer (omp_allocator_handle_kind) :: omp_get_default_allocator}
3427 @item @emph{See also}:
3428 @ref{omp_set_default_allocator}, @ref{OMP_ALLOCATOR}
3430 @item @emph{Reference}:
3431 @uref{https://www.openmp.org, OpenMP specification v5.0}, Section 3.7.5
3437 @subsection @code{omp_alloc} -- Memory allocation with an allocator
3439 @item @emph{Description}:
3440 Allocate memory with the specified allocator, which can either be a predefined
3441 allocator, an allocator handle or @code{omp_null_allocator}. If the allocators
3442 is @code{omp_null_allocator}, the allocator specified by the
3443 @var{def-allocator-var} ICV is used. @var{size} must be a nonnegative number
3444 denoting the number of bytes to be allocated; if @var{size} is zero,
3445 @code{omp_alloc} will return a null pointer. If successful, a pointer to the
3446 allocated memory is returned, otherwise the @code{fallback} trait of the
3447 allocator determines the behavior. The content of the allocated memory is
3450 In @code{target} regions, either the @code{dynamic_allocators} clause must
3451 appear on a @code{requires} directive in the same compilation unit -- or the
3452 @var{allocator} argument may only be a constant expression with the value of
3453 one of the predefined allocators and may not be @code{omp_null_allocator}.
3455 Memory allocated by @code{omp_alloc} must be freed using @code{omp_free}.
3458 @multitable @columnfractions .20 .80
3459 @item @emph{Prototype}: @tab @code{void* omp_alloc(size_t size,}
3460 @item @tab @code{ omp_allocator_handle_t allocator)}
3464 @multitable @columnfractions .20 .80
3465 @item @emph{Prototype}: @tab @code{void* omp_alloc(size_t size,}
3466 @item @tab @code{ omp_allocator_handle_t allocator=omp_null_allocator)}
3469 @item @emph{Fortran}:
3470 @multitable @columnfractions .20 .80
3471 @item @emph{Interface}: @tab @code{type(c_ptr) function omp_alloc(size, allocator) bind(C)}
3472 @item @tab @code{use, intrinsic :: iso_c_binding, only : c_ptr, c_size_t}
3473 @item @tab @code{integer (c_size_t), value :: size}
3474 @item @tab @code{integer (omp_allocator_handle_kind), value :: allocator}
3477 @item @emph{See also}:
3478 @ref{OMP_ALLOCATOR}, @ref{Memory allocation}, @ref{omp_set_default_allocator},
3479 @ref{omp_free}, @ref{omp_init_allocator}
3481 @item @emph{Reference}:
3482 @uref{https://www.openmp.org, OpenMP specification v5.0}, Section 3.7.6
3487 @node omp_aligned_alloc
3488 @subsection @code{omp_aligned_alloc} -- Memory allocation with an allocator and alignment
3490 @item @emph{Description}:
3491 Allocate memory with the specified allocator, which can either be a predefined
3492 allocator, an allocator handle or @code{omp_null_allocator}. If the allocators
3493 is @code{omp_null_allocator}, the allocator specified by the
3494 @var{def-allocator-var} ICV is used. @var{alignment} must be a positive power
3495 of two and @var{size} must be a nonnegative number that is a multiple of the
3496 alignment and denotes the number of bytes to be allocated; if @var{size} is
3497 zero, @code{omp_aligned_alloc} will return a null pointer. The alignment will
3498 be at least the maximal value required by @code{alignment} trait of the
3499 allocator and the value of the passed @var{alignment} argument. If successful,
3500 a pointer to the allocated memory is returned, otherwise the @code{fallback}
3501 trait of the allocator determines the behavior. The content of the allocated
3502 memory is unspecified.
3504 In @code{target} regions, either the @code{dynamic_allocators} clause must
3505 appear on a @code{requires} directive in the same compilation unit -- or the
3506 @var{allocator} argument may only be a constant expression with the value of
3507 one of the predefined allocators and may not be @code{omp_null_allocator}.
3509 Memory allocated by @code{omp_aligned_alloc} must be freed using
3513 @multitable @columnfractions .20 .80
3514 @item @emph{Prototype}: @tab @code{void* omp_aligned_alloc(size_t alignment,}
3515 @item @tab @code{ size_t size,}
3516 @item @tab @code{ omp_allocator_handle_t allocator)}
3520 @multitable @columnfractions .20 .80
3521 @item @emph{Prototype}: @tab @code{void* omp_aligned_alloc(size_t alignment,}
3522 @item @tab @code{ size_t size,}
3523 @item @tab @code{ omp_allocator_handle_t allocator=omp_null_allocator)}
3526 @item @emph{Fortran}:
3527 @multitable @columnfractions .20 .80
3528 @item @emph{Interface}: @tab @code{type(c_ptr) function omp_aligned_alloc(alignment, size, allocator) bind(C)}
3529 @item @tab @code{use, intrinsic :: iso_c_binding, only : c_ptr, c_size_t}
3530 @item @tab @code{integer (c_size_t), value :: alignment, size}
3531 @item @tab @code{integer (omp_allocator_handle_kind), value :: allocator}
3534 @item @emph{See also}:
3535 @ref{OMP_ALLOCATOR}, @ref{Memory allocation}, @ref{omp_set_default_allocator},
3536 @ref{omp_free}, @ref{omp_init_allocator}
3538 @item @emph{Reference}:
3539 @uref{https://www.openmp.org, OpenMP specification v5.1}, Section 3.13.6
3545 @subsection @code{omp_free} -- Freeing memory allocated with OpenMP routines
3547 @item @emph{Description}:
3548 The @code{omp_free} routine deallocates memory previously allocated by an
3549 OpenMP memory-management routine. The @var{ptr} argument must point to such
3550 memory or be a null pointer; if it is a null pointer, no operation is
3551 performed. If specified, the @var{allocator} argument must be either the
3552 memory allocator that was used for the allocation or @code{omp_null_allocator};
3553 if it is @code{omp_null_allocator}, the implementation will determine the value
3556 Calling @code{omp_free} invokes undefined behavior if the memory
3557 was already deallocated or when the used allocator has already been destroyed.
3560 @multitable @columnfractions .20 .80
3561 @item @emph{Prototype}: @tab @code{void omp_free(void *ptr,}
3562 @item @tab @code{ omp_allocator_handle_t allocator)}
3566 @multitable @columnfractions .20 .80
3567 @item @emph{Prototype}: @tab @code{void omp_free(void *ptr,}
3568 @item @tab @code{ omp_allocator_handle_t allocator=omp_null_allocator)}
3571 @item @emph{Fortran}:
3572 @multitable @columnfractions .20 .80
3573 @item @emph{Interface}: @tab @code{subroutine omp_free(ptr, allocator) bind(C)}
3574 @item @tab @code{use, intrinsic :: iso_c_binding, only : c_ptr}
3575 @item @tab @code{type (c_ptr), value :: ptr}
3576 @item @tab @code{integer (omp_allocator_handle_kind), value :: allocator}
3579 @item @emph{See also}:
3580 @ref{omp_alloc}, @ref{omp_aligned_alloc}, @ref{omp_calloc},
3581 @ref{omp_aligned_calloc}, @ref{omp_realloc}
3583 @item @emph{Reference}:
3584 @uref{https://www.openmp.org, OpenMP specification v5.0}, Section 3.7.7
3590 @subsection @code{omp_calloc} -- Allocate nullified memory with an allocator
3592 @item @emph{Description}:
3593 Allocate zero-initialized memory with the specified allocator, which can either
3594 be a predefined allocator, an allocator handle or @code{omp_null_allocator}. If
3595 the allocators is @code{omp_null_allocator}, the allocator specified by the
3596 @var{def-allocator-var} ICV is used. The to-be allocated memory is for an
3597 array with @var{nmemb} elements, each having a size of @var{size} bytes. Both
3598 @var{nmemb} and @var{size} must be nonnegative numbers; if either of them is
3599 zero, @code{omp_calloc} will return a null pointer. If successful, a pointer to
3600 the zero-initialized allocated memory is returned, otherwise the @code{fallback}
3601 trait of the allocator determines the behavior.
3603 In @code{target} regions, either the @code{dynamic_allocators} clause must
3604 appear on a @code{requires} directive in the same compilation unit -- or the
3605 @var{allocator} argument may only be a constant expression with the value of
3606 one of the predefined allocators and may not be @code{omp_null_allocator}.
3608 Memory allocated by @code{omp_calloc} must be freed using @code{omp_free}.
3611 @multitable @columnfractions .20 .80
3612 @item @emph{Prototype}: @tab @code{void* omp_calloc(size_t nmemb, size_t size,}
3613 @item @tab @code{ omp_allocator_handle_t allocator)}
3617 @multitable @columnfractions .20 .80
3618 @item @emph{Prototype}: @tab @code{void* omp_calloc(size_t nmemb, size_t size,}
3619 @item @tab @code{ omp_allocator_handle_t allocator=omp_null_allocator)}
3622 @item @emph{Fortran}:
3623 @multitable @columnfractions .20 .80
3624 @item @emph{Interface}: @tab @code{type(c_ptr) function omp_calloc(nmemb, size, allocator) bind(C)}
3625 @item @tab @code{use, intrinsic :: iso_c_binding, only : c_ptr, c_size_t}
3626 @item @tab @code{integer (c_size_t), value :: nmemb, size}
3627 @item @tab @code{integer (omp_allocator_handle_kind), value :: allocator}
3630 @item @emph{See also}:
3631 @ref{OMP_ALLOCATOR}, @ref{Memory allocation}, @ref{omp_set_default_allocator},
3632 @ref{omp_free}, @ref{omp_init_allocator}
3634 @item @emph{Reference}:
3635 @uref{https://www.openmp.org, OpenMP specification v5.1}, Section 3.13.8
3640 @node omp_aligned_calloc
3641 @subsection @code{omp_aligned_calloc} -- Allocate aligned nullified memory with an allocator
3643 @item @emph{Description}:
3644 Allocate zero-initialized memory with the specified allocator, which can either
3645 be a predefined allocator, an allocator handle or @code{omp_null_allocator}. If
3646 the allocators is @code{omp_null_allocator}, the allocator specified by the
3647 @var{def-allocator-var} ICV is used. The to-be allocated memory is for an
3648 array with @var{nmemb} elements, each having a size of @var{size} bytes. Both
3649 @var{nmemb} and @var{size} must be nonnegative numbers; if either of them is
3650 zero, @code{omp_aligned_calloc} will return a null pointer. @var{alignment}
3651 must be a positive power of two and @var{size} must be a multiple of the
3652 alignment; the alignment will be at least the maximal value required by
3653 @code{alignment} trait of the allocator and the value of the passed
3654 @var{alignment} argument. If successful, a pointer to the zero-initialized
3655 allocated memory is returned, otherwise the @code{fallback} trait of the
3656 allocator determines the behavior.
3658 In @code{target} regions, either the @code{dynamic_allocators} clause must
3659 appear on a @code{requires} directive in the same compilation unit -- or the
3660 @var{allocator} argument may only be a constant expression with the value of
3661 one of the predefined allocators and may not be @code{omp_null_allocator}.
3663 Memory allocated by @code{omp_aligned_calloc} must be freed using
3667 @multitable @columnfractions .20 .80
3668 @item @emph{Prototype}: @tab @code{void* omp_aligned_calloc(size_t nmemb, size_t size,}
3669 @item @tab @code{ omp_allocator_handle_t allocator)}
3673 @multitable @columnfractions .20 .80
3674 @item @emph{Prototype}: @tab @code{void* omp_aligned_calloc(size_t nmemb, size_t size,}
3675 @item @tab @code{ omp_allocator_handle_t allocator=omp_null_allocator)}
3678 @item @emph{Fortran}:
3679 @multitable @columnfractions .20 .80
3680 @item @emph{Interface}: @tab @code{type(c_ptr) function omp_aligned_calloc(nmemb, size, allocator) bind(C)}
3681 @item @tab @code{use, intrinsic :: iso_c_binding, only : c_ptr, c_size_t}
3682 @item @tab @code{integer (c_size_t), value :: nmemb, size}
3683 @item @tab @code{integer (omp_allocator_handle_kind), value :: allocator}
3686 @item @emph{See also}:
3687 @ref{OMP_ALLOCATOR}, @ref{Memory allocation}, @ref{omp_set_default_allocator},
3688 @ref{omp_free}, @ref{omp_init_allocator}
3690 @item @emph{Reference}:
3691 @uref{https://www.openmp.org, OpenMP specification v5.1}, Section 3.13.8
3697 @subsection @code{omp_realloc} -- Reallocate memory allocated with OpenMP routines
3699 @item @emph{Description}:
3700 The @code{omp_realloc} routine deallocates memory to which @var{ptr} points to
3701 and allocates new memory with the specified @var{allocator} argument; the
3702 new memory will have the content of the old memory up to the minimum of the
3703 old size and the new @var{size}, otherwise the content of the returned memory
3704 is unspecified. If the new allocator is the same as the old one, the routine
3705 tries to resize the existing memory allocation, returning the same address as
3706 @var{ptr} if successful. @var{ptr} must point to memory allocated by an OpenMP
3707 memory-management routine.
3709 The @var{allocator} and @var{free_allocator} arguments must be a predefined
3710 allocator, an allocator handle or @code{omp_null_allocator}. If
3711 @var{free_allocator} is @code{omp_null_allocator}, the implementation
3712 automatically determines the allocator used for the allocation of @var{ptr}.
3713 If @var{allocator} is @code{omp_null_allocator} and @var{ptr} is not a
3714 null pointer, the same allocator as @code{free_allocator} is used and
3715 when @var{ptr} is a null pointer the allocator specified by the
3716 @var{def-allocator-var} ICV is used.
3718 The @var{size} must be a nonnegative number denoting the number of bytes to be
3719 allocated; if @var{size} is zero, @code{omp_realloc} will return free the
3720 memory and return a null pointer. When @var{size} is nonzero: if successful,
3721 a pointer to the allocated memory is returned, otherwise the @code{fallback}
3722 trait of the allocator determines the behavior.
3724 In @code{target} regions, either the @code{dynamic_allocators} clause must
3725 appear on a @code{requires} directive in the same compilation unit -- or the
3726 @var{free_allocator} and @var{allocator} arguments may only be a constant
3727 expression with the value of one of the predefined allocators and may not be
3728 @code{omp_null_allocator}.
3730 Memory allocated by @code{omp_realloc} must be freed using @code{omp_free}.
3731 Calling @code{omp_free} invokes undefined behavior if the memory
3732 was already deallocated or when the used allocator has already been destroyed.
3735 @multitable @columnfractions .20 .80
3736 @item @emph{Prototype}: @tab @code{void* omp_realloc(void *ptr, size_t size,}
3737 @item @tab @code{ omp_allocator_handle_t allocator,}
3738 @item @tab @code{ omp_allocator_handle_t free_allocator)}
3742 @multitable @columnfractions .20 .80
3743 @item @emph{Prototype}: @tab @code{void* omp_realloc(void *ptr, size_t size,}
3744 @item @tab @code{ omp_allocator_handle_t allocator=omp_null_allocator,}
3745 @item @tab @code{ omp_allocator_handle_t free_allocator=omp_null_allocator)}
3748 @item @emph{Fortran}:
3749 @multitable @columnfractions .20 .80
3750 @item @emph{Interface}: @tab @code{type(c_ptr) function omp_realloc(ptr, size, allocator, free_allocator) bind(C)}
3751 @item @tab @code{use, intrinsic :: iso_c_binding, only : c_ptr, c_size_t}
3752 @item @tab @code{type(C_ptr), value :: ptr}
3753 @item @tab @code{integer (c_size_t), value :: size}
3754 @item @tab @code{integer (omp_allocator_handle_kind), value :: allocator, free_allocator}
3757 @item @emph{See also}:
3758 @ref{OMP_ALLOCATOR}, @ref{Memory allocation}, @ref{omp_set_default_allocator},
3759 @ref{omp_free}, @ref{omp_init_allocator}
3761 @item @emph{Reference}:
3762 @uref{https://www.openmp.org, OpenMP specification v5.0}, Section 3.7.9
3767 @c @node Tool Control Routine
3768 @c @section Tool Control Routine
3772 @node Environment Display Routine
3773 @section Environment Display Routine
3775 Routine to display the OpenMP version number and the initial value of ICVs.
3776 It has C linkage and does not throw exceptions.
3779 * omp_display_env:: print the initial ICV values
3782 @node omp_display_env
3783 @subsection @code{omp_display_env} -- print the initial ICV values
3785 @item @emph{Description}:
3786 Each time this routine is invoked, the OpenMP version number and initial value
3787 of internal control variables (ICVs) is printed on @code{stderr}. The displayed
3788 values are those at startup after evaluating the environment variables; later
3789 calls to API routines or clauses used in enclosing constructs do not affect
3792 If the @var{verbose} argument is @code{false}, only the OpenMP version and
3793 standard OpenMP ICVs are shown; if it is @code{true}, additionally, the
3794 GCC-specific ICVs are shown.
3796 The output consists of multiple lines and starts with
3797 @samp{OPENMP DISPLAY ENVIRONMENT BEGIN} followed by the name-value lines and
3798 ends with @samp{OPENMP DISPLAY ENVIRONMENT END}. The @var{name} is followed by
3799 an equal sign and the @var{value} is enclosed in single quotes.
3801 The first line has as @var{name} either @samp{_OPENMP} or @samp{openmp_version}
3802 and shows as value the supported OpenMP version number (4-digit year, 2-digit
3803 month) of the implementation, matching the value of the @code{_OPENMP} macro
3804 and, in Fortran, the named constant @code{openmp_version}.
3806 In each of the succeeding lines, the @var{name} matches the environment-variable
3807 name of an ICV and shows its value. Those line are might be prefixed by pair of
3808 brackets and a space, where the brackets enclose a comma-separated list of
3809 devices to which the ICV-value combination applies to; the value can either be a
3810 numeric device number or an abstract name denoting all devices (@code{all}), the
3811 initial host device (@code{host}) or all devices but the host (@code{device}).
3812 Note that the same ICV might be printed multiple times for multiple devices,
3813 even if all have the same value.
3815 The effect when invoked from within a @code{target} region is unspecified.
3818 @multitable @columnfractions .20 .80
3819 @item @emph{Prototype}: @tab @code{void omp_display_env(int verbose)}
3822 @item @emph{Fortran}:
3823 @multitable @columnfractions .20 .80
3824 @item @emph{Interface}: @tab @code{subroutine omp_display_env(verbose)}
3825 @item @tab @code{logical, intent(in) :: verbose}
3828 @item @emph{Example}:
3829 Note that the GCC-specific ICVs, such as the shown @code{GOMP_SPINCOUNT},
3830 are only printed when @var{verbose} set to @code{true}.
3833 OPENMP DISPLAY ENVIRONMENT BEGIN
3835 [host] OMP_DYNAMIC = 'FALSE'
3836 [host] OMP_NESTED = 'FALSE'
3837 [all] OMP_CANCELLATION = 'FALSE'
3839 [host] GOMP_SPINCOUNT = '300000'
3840 OPENMP DISPLAY ENVIRONMENT END
3844 @item @emph{See also}:
3845 @ref{OMP_DISPLAY_ENV}, @ref{Environment Variables},
3846 @ref{Implementation-defined ICV Initialization}
3848 @item @emph{Reference}:
3849 @uref{https://www.openmp.org, OpenMP specification v5.1}, Section 3.15
3853 @c ---------------------------------------------------------------------
3854 @c OpenMP Environment Variables
3855 @c ---------------------------------------------------------------------
3857 @node Environment Variables
3858 @chapter OpenMP Environment Variables
3860 The environment variables which beginning with @env{OMP_} are defined by
3861 section 4 of the OpenMP specification in version 4.5 or in a later version
3862 of the specification, while those beginning with @env{GOMP_} are GNU extensions.
3863 Most @env{OMP_} environment variables have an associated internal control
3866 For any OpenMP environment variable that sets an ICV and is neither
3867 @code{OMP_DEFAULT_DEVICE} nor has global ICV scope, associated
3868 device-specific environment variables exist. For them, the environment
3869 variable without suffix affects the host. The suffix @code{_DEV_} followed
3870 by a non-negative device number less that the number of available devices sets
3871 the ICV for the corresponding device. The suffix @code{_DEV} sets the ICV
3872 of all non-host devices for which a device-specific corresponding environment
3873 variable has not been set while the @code{_ALL} suffix sets the ICV of all
3874 host and non-host devices for which a more specific corresponding environment
3875 variable is not set.
3878 * OMP_ALLOCATOR:: Set the default allocator
3879 * OMP_AFFINITY_FORMAT:: Set the format string used for affinity display
3880 * OMP_CANCELLATION:: Set whether cancellation is activated
3881 * OMP_DISPLAY_AFFINITY:: Display thread affinity information
3882 * OMP_DISPLAY_ENV:: Show OpenMP version and environment variables
3883 * OMP_DEFAULT_DEVICE:: Set the device used in target regions
3884 * OMP_DYNAMIC:: Dynamic adjustment of threads
3885 * OMP_MAX_ACTIVE_LEVELS:: Set the maximum number of nested parallel regions
3886 * OMP_MAX_TASK_PRIORITY:: Set the maximum task priority value
3887 * OMP_NESTED:: Nested parallel regions
3888 * OMP_NUM_TEAMS:: Specifies the number of teams to use by teams region
3889 * OMP_NUM_THREADS:: Specifies the number of threads to use
3890 * OMP_PROC_BIND:: Whether threads may be moved between CPUs
3891 * OMP_PLACES:: Specifies on which CPUs the threads should be placed
3892 * OMP_STACKSIZE:: Set default thread stack size
3893 * OMP_SCHEDULE:: How threads are scheduled
3894 * OMP_TARGET_OFFLOAD:: Controls offloading behavior
3895 * OMP_TEAMS_THREAD_LIMIT:: Set the maximum number of threads imposed by teams
3896 * OMP_THREAD_LIMIT:: Set the maximum number of threads
3897 * OMP_WAIT_POLICY:: How waiting threads are handled
3898 * GOMP_CPU_AFFINITY:: Bind threads to specific CPUs
3899 * GOMP_DEBUG:: Enable debugging output
3900 * GOMP_STACKSIZE:: Set default thread stack size
3901 * GOMP_SPINCOUNT:: Set the busy-wait spin count
3902 * GOMP_RTEMS_THREAD_POOLS:: Set the RTEMS specific thread pools
3907 @section @env{OMP_ALLOCATOR} -- Set the default allocator
3908 @cindex Environment Variable
3910 @item @emph{ICV:} @var{def-allocator-var}
3911 @item @emph{Scope:} data environment
3912 @item @emph{Description}:
3913 Sets the default allocator that is used when no allocator has been specified
3914 in the @code{allocate} or @code{allocator} clause or if an OpenMP memory
3915 routine is invoked with the @code{omp_null_allocator} allocator.
3916 If unset, @code{omp_default_mem_alloc} is used.
3918 The value can either be a predefined allocator or a predefined memory space
3919 or a predefined memory space followed by a colon and a comma-separated list
3920 of memory trait and value pairs, separated by @code{=}.
3922 Note: The corresponding device environment variables are currently not
3923 supported. Therefore, the non-host @var{def-allocator-var} ICVs are always
3924 initialized to @code{omp_default_mem_alloc}. However, on all devices,
3925 the @code{omp_set_default_allocator} API routine can be used to change
3928 @multitable @columnfractions .45 .45
3929 @headitem Predefined allocators @tab Associated predefined memory spaces
3930 @item omp_default_mem_alloc @tab omp_default_mem_space
3931 @item omp_large_cap_mem_alloc @tab omp_large_cap_mem_space
3932 @item omp_const_mem_alloc @tab omp_const_mem_space
3933 @item omp_high_bw_mem_alloc @tab omp_high_bw_mem_space
3934 @item omp_low_lat_mem_alloc @tab omp_low_lat_mem_space
3935 @item omp_cgroup_mem_alloc @tab omp_low_lat_mem_space (implementation defined)
3936 @item omp_pteam_mem_alloc @tab omp_low_lat_mem_space (implementation defined)
3937 @item omp_thread_mem_alloc @tab omp_low_lat_mem_space (implementation defined)
3938 @item ompx_gnu_pinned_mem_alloc @tab omp_default_mem_space (GNU extension)
3941 The predefined allocators use the default values for the traits,
3942 as listed below. Except that the last three allocators have the
3943 @code{access} trait set to @code{cgroup}, @code{pteam}, and
3944 @code{thread}, respectively.
3946 @multitable @columnfractions .25 .40 .25
3947 @headitem Trait @tab Allowed values @tab Default value
3948 @item @code{sync_hint} @tab @code{contended}, @code{uncontended},
3949 @code{serialized}, @code{private}
3950 @tab @code{contended}
3951 @item @code{alignment} @tab Positive integer being a power of two
3953 @item @code{access} @tab @code{all}, @code{cgroup},
3954 @code{pteam}, @code{thread}
3956 @item @code{pool_size} @tab Positive integer
3957 @tab See @ref{Memory allocation}
3958 @item @code{fallback} @tab @code{default_mem_fb}, @code{null_fb},
3959 @code{abort_fb}, @code{allocator_fb}
3961 @item @code{fb_data} @tab @emph{unsupported as it needs an allocator handle}
3963 @item @code{pinned} @tab @code{true}, @code{false}
3965 @item @code{partition} @tab @code{environment}, @code{nearest},
3966 @code{blocked}, @code{interleaved}
3967 @tab @code{environment}
3970 For the @code{fallback} trait, the default value is @code{null_fb} for the
3971 @code{omp_default_mem_alloc} allocator and any allocator that is associated
3972 with device memory; for all other allocators, it is @code{default_mem_fb}
3975 For the @code{pinned} trait, the default value is @code{true} for
3976 predefined allocator @code{ompx_gnu_pinned_mem_alloc} (a GNU extension), and
3977 @code{false} for all others.
3981 OMP_ALLOCATOR=omp_high_bw_mem_alloc
3982 OMP_ALLOCATOR=omp_large_cap_mem_space
3983 OMP_ALLOCATOR=omp_low_lat_mem_space:pinned=true,partition=nearest
3986 @item @emph{See also}:
3987 @ref{Memory allocation}, @ref{omp_get_default_allocator},
3988 @ref{omp_set_default_allocator}, @ref{Offload-Target Specifics}
3990 @item @emph{Reference}:
3991 @uref{https://www.openmp.org, OpenMP specification v5.0}, Section 6.21
3996 @node OMP_AFFINITY_FORMAT
3997 @section @env{OMP_AFFINITY_FORMAT} -- Set the format string used for affinity display
3998 @cindex Environment Variable
4000 @item @emph{ICV:} @var{affinity-format-var}
4001 @item @emph{Scope:} device
4002 @item @emph{Description}:
4003 Sets the format string used when displaying OpenMP thread affinity information.
4004 Special values are output using @code{%} followed by an optional size
4005 specification and then either the single-character field type or its long
4006 name enclosed in curly braces; using @code{%%} displays a literal percent.
4007 The size specification consists of an optional @code{0.} or @code{.} followed
4008 by a positive integer, specifying the minimal width of the output. With
4009 @code{0.} and numerical values, the output is padded with zeros on the left;
4010 with @code{.}, the output is padded by spaces on the left; otherwise, the
4011 output is padded by spaces on the right. If unset, the value is
4012 ``@code{level %L thread %i affinity %A}''.
4014 Supported field types are:
4016 @multitable @columnfractions .10 .25 .60
4017 @item t @tab team_num @tab value returned by @code{omp_get_team_num}
4018 @item T @tab num_teams @tab value returned by @code{omp_get_num_teams}
4019 @item L @tab nesting_level @tab value returned by @code{omp_get_level}
4020 @item n @tab thread_num @tab value returned by @code{omp_get_thread_num}
4021 @item N @tab num_threads @tab value returned by @code{omp_get_num_threads}
4022 @item a @tab ancestor_tnum
4023 @tab value returned by
4024 @code{omp_get_ancestor_thread_num(omp_get_level()-1)}
4025 @item H @tab host @tab name of the host that executes the thread
4026 @item P @tab process_id @tab process identifier
4027 @item i @tab native_thread_id @tab native thread identifier
4028 @item A @tab thread_affinity
4029 @tab comma separated list of integer values or ranges, representing the
4030 processors on which a process might execute, subject to affinity
4034 For instance, after setting
4037 OMP_AFFINITY_FORMAT="%0.2a!%n!%.4L!%N;%.2t;%0.2T;%@{team_num@};%@{num_teams@};%A"
4040 with either @code{OMP_DISPLAY_AFFINITY} being set or when calling
4041 @code{omp_display_affinity} with @code{NULL} or an empty string, the program
4042 might display the following:
4045 00!0! 1!4; 0;01;0;1;0-11
4046 00!3! 1!4; 0;01;0;1;0-11
4047 00!2! 1!4; 0;01;0;1;0-11
4048 00!1! 1!4; 0;01;0;1;0-11
4051 @item @emph{See also}:
4052 @ref{OMP_DISPLAY_AFFINITY}
4054 @item @emph{Reference}:
4055 @uref{https://www.openmp.org, OpenMP specification v5.0}, Section 6.14
4060 @node OMP_CANCELLATION
4061 @section @env{OMP_CANCELLATION} -- Set whether cancellation is activated
4062 @cindex Environment Variable
4064 @item @emph{ICV:} @var{cancel-var}
4065 @item @emph{Scope:} global
4066 @item @emph{Description}:
4067 If set to @code{TRUE}, the cancellation is activated. If set to @code{FALSE} or
4068 if unset, cancellation is disabled and the @code{cancel} construct is ignored.
4070 @item @emph{See also}:
4071 @ref{omp_get_cancellation}
4073 @item @emph{Reference}:
4074 @uref{https://www.openmp.org, OpenMP specification v4.5}, Section 4.11
4079 @node OMP_DISPLAY_AFFINITY
4080 @section @env{OMP_DISPLAY_AFFINITY} -- Display thread affinity information
4081 @cindex Environment Variable
4083 @item @emph{ICV:} @var{display-affinity-var}
4084 @item @emph{Scope:} global
4085 @item @emph{Description}:
4086 If set to @code{FALSE} or if unset, affinity displaying is disabled.
4087 If set to @code{TRUE}, the runtime displays affinity information about
4088 OpenMP threads in a parallel region upon entering the region and every time
4091 @item @emph{See also}:
4092 @ref{OMP_AFFINITY_FORMAT}
4094 @item @emph{Reference}:
4095 @uref{https://www.openmp.org, OpenMP specification v5.0}, Section 6.13
4101 @node OMP_DISPLAY_ENV
4102 @section @env{OMP_DISPLAY_ENV} -- Show OpenMP version and environment variables
4103 @cindex Environment Variable
4105 @item @emph{ICV:} none
4106 @item @emph{Scope:} not applicable
4107 @item @emph{Description}:
4108 If set to @code{TRUE}, the runtime displays the same information to
4109 @code{stderr} as shown by the @code{omp_display_env} routine invoked with
4110 @var{verbose} argument set to @code{false}. If set to @code{VERBOSE}, the same
4111 information is shown as invoking the routine with @var{verbose} set to
4112 @code{true}. If unset or set to @code{FALSE}, this information is not shown.
4113 The result for any other value is unspecified.
4115 @item @emph{See also}:
4116 @ref{omp_display_env}
4118 @item @emph{Reference}:
4119 @uref{https://www.openmp.org, OpenMP specification v4.5}, Section 4.12
4124 @node OMP_DEFAULT_DEVICE
4125 @section @env{OMP_DEFAULT_DEVICE} -- Set the device used in target regions
4126 @cindex Environment Variable
4128 @item @emph{ICV:} @var{default-device-var}
4129 @item @emph{Scope:} data environment
4130 @item @emph{Description}:
4131 Set to choose the device which is used in a @code{target} region, unless the
4132 value is overridden by @code{omp_set_default_device} or by a @code{device}
4133 clause. The value shall be the nonnegative device number. If no device with
4134 the given device number exists, the code is executed on the host. If unset,
4135 @env{OMP_TARGET_OFFLOAD} is @code{mandatory} and no non-host devices are
4136 available, it is set to @code{omp_invalid_device}. Otherwise, if unset,
4137 device number 0 is used.
4140 @item @emph{See also}:
4141 @ref{omp_get_default_device}, @ref{omp_set_default_device},
4142 @ref{OMP_TARGET_OFFLOAD}
4144 @item @emph{Reference}:
4145 @uref{https://www.openmp.org, OpenMP specification v5.2}, Section 21.2.7
4151 @section @env{OMP_DYNAMIC} -- Dynamic adjustment of threads
4152 @cindex Environment Variable
4154 @item @emph{ICV:} @var{dyn-var}
4155 @item @emph{Scope:} global
4156 @item @emph{Description}:
4157 Enable or disable the dynamic adjustment of the number of threads
4158 within a team. The value of this environment variable shall be
4159 @code{TRUE} or @code{FALSE}. If undefined, dynamic adjustment is
4160 disabled by default.
4162 @item @emph{See also}:
4163 @ref{omp_set_dynamic}
4165 @item @emph{Reference}:
4166 @uref{https://www.openmp.org, OpenMP specification v4.5}, Section 4.3
4171 @node OMP_MAX_ACTIVE_LEVELS
4172 @section @env{OMP_MAX_ACTIVE_LEVELS} -- Set the maximum number of nested parallel regions
4173 @cindex Environment Variable
4175 @item @emph{ICV:} @var{max-active-levels-var}
4176 @item @emph{Scope:} data environment
4177 @item @emph{Description}:
4178 Specifies the initial value for the maximum number of nested parallel
4179 regions. The value of this variable shall be a positive integer.
4180 If undefined, then if @env{OMP_NESTED} is defined and set to true, or
4181 if @env{OMP_NUM_THREADS} or @env{OMP_PROC_BIND} are defined and set to
4182 a list with more than one item, the maximum number of nested parallel
4183 regions is initialized to the largest number supported, otherwise
4186 @item @emph{See also}:
4187 @ref{omp_set_max_active_levels}, @ref{OMP_NESTED}, @ref{OMP_PROC_BIND},
4188 @ref{OMP_NUM_THREADS}
4191 @item @emph{Reference}:
4192 @uref{https://www.openmp.org, OpenMP specification v4.5}, Section 4.9
4197 @node OMP_MAX_TASK_PRIORITY
4198 @section @env{OMP_MAX_TASK_PRIORITY} -- Set the maximum priority
4199 number that can be set for a task.
4200 @cindex Environment Variable
4202 @item @emph{ICV:} @var{max-task-priority-var}
4203 @item @emph{Scope:} global
4204 @item @emph{Description}:
4205 Specifies the initial value for the maximum priority value that can be
4206 set for a task. The value of this variable shall be a non-negative
4207 integer, and zero is allowed. If undefined, the default priority is
4210 @item @emph{See also}:
4211 @ref{omp_get_max_task_priority}
4213 @item @emph{Reference}:
4214 @uref{https://www.openmp.org, OpenMP specification v4.5}, Section 4.14
4220 @section @env{OMP_NESTED} -- Nested parallel regions
4221 @cindex Environment Variable
4222 @cindex Implementation specific setting
4224 @item @emph{ICV:} @var{max-active-levels-var}
4225 @item @emph{Scope:} data environment
4226 @item @emph{Description}:
4227 Enable or disable nested parallel regions, i.e., whether team members
4228 are allowed to create new teams. The value of this environment variable
4229 shall be @code{TRUE} or @code{FALSE}. If set to @code{TRUE}, the number
4230 of maximum active nested regions supported is by default set to the
4231 maximum supported, otherwise it is set to one. If
4232 @env{OMP_MAX_ACTIVE_LEVELS} is defined, its setting overrides this
4233 setting. If both are undefined, nested parallel regions are enabled if
4234 @env{OMP_NUM_THREADS} or @env{OMP_PROC_BINDS} are defined to a list with
4235 more than one item, otherwise they are disabled by default.
4237 Note that the @code{OMP_NESTED} environment variable was deprecated in
4238 the OpenMP specification 5.0 in favor of @code{OMP_MAX_ACTIVE_LEVELS}.
4240 @item @emph{See also}:
4241 @ref{omp_set_max_active_levels}, @ref{omp_set_nested},
4242 @ref{OMP_MAX_ACTIVE_LEVELS}
4244 @item @emph{Reference}:
4245 @uref{https://www.openmp.org, OpenMP specification v4.5}, Section 4.6
4251 @section @env{OMP_NUM_TEAMS} -- Specifies the number of teams to use by teams region
4252 @cindex Environment Variable
4254 @item @emph{ICV:} @var{nteams-var}
4255 @item @emph{Scope:} device
4256 @item @emph{Description}:
4257 Specifies the upper bound for number of teams to use in teams regions
4258 without explicit @code{num_teams} clause. The value of this variable shall
4259 be a positive integer. If undefined it defaults to 0 which means
4260 implementation defined upper bound.
4262 @item @emph{See also}:
4263 @ref{omp_set_num_teams}
4265 @item @emph{Reference}:
4266 @uref{https://www.openmp.org, OpenMP specification v5.1}, Section 6.23
4271 @node OMP_NUM_THREADS
4272 @section @env{OMP_NUM_THREADS} -- Specifies the number of threads to use
4273 @cindex Environment Variable
4274 @cindex Implementation specific setting
4276 @item @emph{ICV:} @var{nthreads-var}
4277 @item @emph{Scope:} data environment
4278 @item @emph{Description}:
4279 Specifies the default number of threads to use in parallel regions. The
4280 value of this variable shall be a comma-separated list of positive integers;
4281 the value specifies the number of threads to use for the corresponding nested
4282 level. Specifying more than one item in the list automatically enables
4283 nesting by default. If undefined one thread per CPU is used.
4285 When a list with more than value is specified, it also affects the
4286 @var{max-active-levels-var} ICV as described in @ref{OMP_MAX_ACTIVE_LEVELS}.
4288 @item @emph{See also}:
4289 @ref{omp_set_num_threads}, @ref{OMP_MAX_ACTIVE_LEVELS}
4291 @item @emph{Reference}:
4292 @uref{https://www.openmp.org, OpenMP specification v4.5}, Section 4.2
4298 @section @env{OMP_PROC_BIND} -- Whether threads may be moved between CPUs
4299 @cindex Environment Variable
4301 @item @emph{ICV:} @var{bind-var}
4302 @item @emph{Scope:} data environment
4303 @item @emph{Description}:
4304 Specifies whether threads may be moved between processors. If set to
4305 @code{TRUE}, OpenMP threads should not be moved; if set to @code{FALSE}
4306 they may be moved. Alternatively, a comma separated list with the
4307 values @code{PRIMARY}, @code{MASTER}, @code{CLOSE} and @code{SPREAD} can
4308 be used to specify the thread affinity policy for the corresponding nesting
4309 level. With @code{PRIMARY} and @code{MASTER} the worker threads are in the
4310 same place partition as the primary thread. With @code{CLOSE} those are
4311 kept close to the primary thread in contiguous place partitions. And
4312 with @code{SPREAD} a sparse distribution
4313 across the place partitions is used. Specifying more than one item in the
4314 list automatically enables nesting by default.
4316 When a list is specified, it also affects the @var{max-active-levels-var} ICV
4317 as described in @ref{OMP_MAX_ACTIVE_LEVELS}.
4319 When undefined, @env{OMP_PROC_BIND} defaults to @code{TRUE} when
4320 @env{OMP_PLACES} or @env{GOMP_CPU_AFFINITY} is set and @code{FALSE} otherwise.
4322 @item @emph{See also}:
4323 @ref{omp_get_proc_bind}, @ref{GOMP_CPU_AFFINITY}, @ref{OMP_PLACES},
4324 @ref{OMP_MAX_ACTIVE_LEVELS}
4326 @item @emph{Reference}:
4327 @uref{https://www.openmp.org, OpenMP specification v4.5}, Section 4.4
4333 @section @env{OMP_PLACES} -- Specifies on which CPUs the threads should be placed
4334 @cindex Environment Variable
4336 @item @emph{ICV:} @var{place-partition-var}
4337 @item @emph{Scope:} implicit tasks
4338 @item @emph{Description}:
4339 The thread placement can be either specified using an abstract name or by an
4340 explicit list of the places. The abstract names @code{threads}, @code{cores},
4341 @code{sockets}, @code{ll_caches} and @code{numa_domains} can be optionally
4342 followed by a positive number in parentheses, which denotes the how many places
4343 shall be created. With @code{threads} each place corresponds to a single
4344 hardware thread; @code{cores} to a single core with the corresponding number of
4345 hardware threads; with @code{sockets} the place corresponds to a single
4346 socket; with @code{ll_caches} to a set of cores that shares the last level
4347 cache on the device; and @code{numa_domains} to a set of cores for which their
4348 closest memory on the device is the same memory and at a similar distance from
4349 the cores. The resulting placement can be shown by setting the
4350 @env{OMP_DISPLAY_ENV} environment variable.
4352 Alternatively, the placement can be specified explicitly as comma-separated
4353 list of places. A place is specified by set of nonnegative numbers in curly
4354 braces, denoting the hardware threads. The curly braces can be omitted
4355 when only a single number has been specified. The hardware threads
4356 belonging to a place can either be specified as comma-separated list of
4357 nonnegative thread numbers or using an interval. Multiple places can also be
4358 either specified by a comma-separated list of places or by an interval. To
4359 specify an interval, a colon followed by the count is placed after
4360 the hardware thread number or the place. Optionally, the length can be
4361 followed by a colon and the stride number -- otherwise a unit stride is
4362 assumed. Placing an exclamation mark (@code{!}) directly before a curly
4363 brace or numbers inside the curly braces (excluding intervals)
4364 excludes those hardware threads.
4366 For instance, the following specifies the same places list:
4367 @code{"@{0,1,2@}, @{3,4,6@}, @{7,8,9@}, @{10,11,12@}"};
4368 @code{"@{0:3@}, @{3:3@}, @{7:3@}, @{10:3@}"}; and @code{"@{0:2@}:4:3"}.
4370 If @env{OMP_PLACES} and @env{GOMP_CPU_AFFINITY} are unset and
4371 @env{OMP_PROC_BIND} is either unset or @code{false}, threads may be moved
4372 between CPUs following no placement policy.
4374 @item @emph{See also}:
4375 @ref{OMP_PROC_BIND}, @ref{GOMP_CPU_AFFINITY}, @ref{omp_get_proc_bind},
4376 @ref{OMP_DISPLAY_ENV}
4378 @item @emph{Reference}:
4379 @uref{https://www.openmp.org, OpenMP specification v4.5}, Section 4.5
4385 @section @env{OMP_STACKSIZE} -- Set default thread stack size
4386 @cindex Environment Variable
4388 @item @emph{ICV:} @var{stacksize-var}
4389 @item @emph{Scope:} device
4390 @item @emph{Description}:
4391 Set the default thread stack size in kilobytes, unless the number
4392 is suffixed by @code{B}, @code{K}, @code{M} or @code{G}, in which
4393 case the size is, respectively, in bytes, kilobytes, megabytes
4394 or gigabytes. This is different from @code{pthread_attr_setstacksize}
4395 which gets the number of bytes as an argument. If the stack size cannot
4396 be set due to system constraints, an error is reported and the initial
4397 stack size is left unchanged. If undefined, the stack size is system
4400 @item @emph{See also}:
4401 @ref{GOMP_STACKSIZE}
4403 @item @emph{Reference}:
4404 @uref{https://www.openmp.org, OpenMP specification v4.5}, Section 4.7
4410 @section @env{OMP_SCHEDULE} -- How threads are scheduled
4411 @cindex Environment Variable
4412 @cindex Implementation specific setting
4414 @item @emph{ICV:} @var{run-sched-var}
4415 @item @emph{Scope:} data environment
4416 @item @emph{Description}:
4417 Allows to specify @code{schedule type} and @code{chunk size}.
4418 The value of the variable shall have the form: @code{type[,chunk]} where
4419 @code{type} is one of @code{static}, @code{dynamic}, @code{guided} or @code{auto}
4420 The optional @code{chunk} size shall be a positive integer. If undefined,
4421 dynamic scheduling and a chunk size of 1 is used.
4423 @item @emph{See also}:
4424 @ref{omp_set_schedule}
4426 @item @emph{Reference}:
4427 @uref{https://www.openmp.org, OpenMP specification v4.5}, Sections 2.7.1.1 and 4.1
4432 @node OMP_TARGET_OFFLOAD
4433 @section @env{OMP_TARGET_OFFLOAD} -- Controls offloading behavior
4434 @cindex Environment Variable
4435 @cindex Implementation specific setting
4437 @item @emph{ICV:} @var{target-offload-var}
4438 @item @emph{Scope:} global
4439 @item @emph{Description}:
4440 Specifies the behavior with regard to offloading code to a device. This
4441 variable can be set to one of three values - @code{MANDATORY}, @code{DISABLED}
4444 If set to @code{MANDATORY}, the program terminates with an error if
4445 any device construct or device memory routine uses a device that is unavailable
4446 or not supported by the implementation, or uses a non-conforming device number.
4447 If set to @code{DISABLED}, then offloading is disabled and all code runs on
4448 the host. If set to @code{DEFAULT}, the program tries offloading to the
4449 device first, then falls back to running code on the host if it cannot.
4451 If undefined, then the program behaves as if @code{DEFAULT} was set.
4453 Note: Even with @code{MANDATORY}, no run-time termination is performed when
4454 the device number in a @code{device} clause or argument to a device memory
4455 routine is for host, which includes using the device number in the
4456 @var{default-device-var} ICV. However, the initial value of
4457 the @var{default-device-var} ICV is affected by @code{MANDATORY}.
4459 @item @emph{See also}:
4460 @ref{OMP_DEFAULT_DEVICE}
4462 @item @emph{Reference}:
4463 @uref{https://www.openmp.org, OpenMP specification v5.2}, Section 21.2.8
4468 @node OMP_TEAMS_THREAD_LIMIT
4469 @section @env{OMP_TEAMS_THREAD_LIMIT} -- Set the maximum number of threads imposed by teams
4470 @cindex Environment Variable
4472 @item @emph{ICV:} @var{teams-thread-limit-var}
4473 @item @emph{Scope:} device
4474 @item @emph{Description}:
4475 Specifies an upper bound for the number of threads to use by each contention
4476 group created by a teams construct without explicit @code{thread_limit}
4477 clause. The value of this variable shall be a positive integer. If undefined,
4478 the value of 0 is used which stands for an implementation defined upper
4481 @item @emph{See also}:
4482 @ref{OMP_THREAD_LIMIT}, @ref{omp_set_teams_thread_limit}
4484 @item @emph{Reference}:
4485 @uref{https://www.openmp.org, OpenMP specification v5.1}, Section 6.24
4490 @node OMP_THREAD_LIMIT
4491 @section @env{OMP_THREAD_LIMIT} -- Set the maximum number of threads
4492 @cindex Environment Variable
4494 @item @emph{ICV:} @var{thread-limit-var}
4495 @item @emph{Scope:} data environment
4496 @item @emph{Description}:
4497 Specifies the number of threads to use for the whole program. The
4498 value of this variable shall be a positive integer. If undefined,
4499 the number of threads is not limited.
4501 @item @emph{See also}:
4502 @ref{OMP_NUM_THREADS}, @ref{omp_get_thread_limit}
4504 @item @emph{Reference}:
4505 @uref{https://www.openmp.org, OpenMP specification v4.5}, Section 4.10
4510 @node OMP_WAIT_POLICY
4511 @section @env{OMP_WAIT_POLICY} -- How waiting threads are handled
4512 @cindex Environment Variable
4514 @item @emph{Description}:
4515 Specifies whether waiting threads should be active or passive. If
4516 the value is @code{PASSIVE}, waiting threads should not consume CPU
4517 power while waiting; while the value is @code{ACTIVE} specifies that
4518 they should. If undefined, threads wait actively for a short time
4519 before waiting passively.
4521 @item @emph{See also}:
4522 @ref{GOMP_SPINCOUNT}
4524 @item @emph{Reference}:
4525 @uref{https://www.openmp.org, OpenMP specification v4.5}, Section 4.8
4530 @node GOMP_CPU_AFFINITY
4531 @section @env{GOMP_CPU_AFFINITY} -- Bind threads to specific CPUs
4532 @cindex Environment Variable
4534 @item @emph{Description}:
4535 Binds threads to specific CPUs. The variable should contain a space-separated
4536 or comma-separated list of CPUs. This list may contain different kinds of
4537 entries: either single CPU numbers in any order, a range of CPUs (M-N)
4538 or a range with some stride (M-N:S). CPU numbers are zero based. For example,
4539 @code{GOMP_CPU_AFFINITY="0 3 1-2 4-15:2"} binds the initial thread
4540 to CPU 0, the second to CPU 3, the third to CPU 1, the fourth to
4541 CPU 2, the fifth to CPU 4, the sixth through tenth to CPUs 6, 8, 10, 12,
4542 and 14 respectively and then starts assigning back from the beginning of
4543 the list. @code{GOMP_CPU_AFFINITY=0} binds all threads to CPU 0.
4545 There is no libgomp library routine to determine whether a CPU affinity
4546 specification is in effect. As a workaround, language-specific library
4547 functions, e.g., @code{getenv} in C or @code{GET_ENVIRONMENT_VARIABLE} in
4548 Fortran, may be used to query the setting of the @code{GOMP_CPU_AFFINITY}
4549 environment variable. A defined CPU affinity on startup cannot be changed
4550 or disabled during the runtime of the application.
4552 If both @env{GOMP_CPU_AFFINITY} and @env{OMP_PROC_BIND} are set,
4553 @env{OMP_PROC_BIND} has a higher precedence. If neither has been set and
4554 @env{OMP_PROC_BIND} is unset, or when @env{OMP_PROC_BIND} is set to
4555 @code{FALSE}, the host system handles the assignment of threads to CPUs.
4557 @item @emph{See also}:
4558 @ref{OMP_PLACES}, @ref{OMP_PROC_BIND}
4564 @section @env{GOMP_DEBUG} -- Enable debugging output
4565 @cindex Environment Variable
4567 @item @emph{Description}:
4568 Enable debugging output. The variable should be set to @code{0}
4569 (disabled, also the default if not set), or @code{1} (enabled).
4571 If enabled, some debugging output is printed during execution.
4572 This is currently not specified in more detail, and subject to change.
4577 @node GOMP_STACKSIZE
4578 @section @env{GOMP_STACKSIZE} -- Set default thread stack size
4579 @cindex Environment Variable
4580 @cindex Implementation specific setting
4582 @item @emph{Description}:
4583 Set the default thread stack size in kilobytes. This is different from
4584 @code{pthread_attr_setstacksize} which gets the number of bytes as an
4585 argument. If the stack size cannot be set due to system constraints, an
4586 error is reported and the initial stack size is left unchanged. If undefined,
4587 the stack size is system dependent.
4589 @item @emph{See also}:
4592 @item @emph{Reference}:
4593 @uref{https://gcc.gnu.org/ml/gcc-patches/2006-06/msg00493.html,
4594 GCC Patches Mailinglist},
4595 @uref{https://gcc.gnu.org/ml/gcc-patches/2006-06/msg00496.html,
4596 GCC Patches Mailinglist}
4601 @node GOMP_SPINCOUNT
4602 @section @env{GOMP_SPINCOUNT} -- Set the busy-wait spin count
4603 @cindex Environment Variable
4604 @cindex Implementation specific setting
4606 @item @emph{Description}:
4607 Determines how long a threads waits actively with consuming CPU power
4608 before waiting passively without consuming CPU power. The value may be
4609 either @code{INFINITE}, @code{INFINITY} to always wait actively or an
4610 integer which gives the number of spins of the busy-wait loop. The
4611 integer may optionally be followed by the following suffixes acting
4612 as multiplication factors: @code{k} (kilo, thousand), @code{M} (mega,
4613 million), @code{G} (giga, billion), or @code{T} (tera, trillion).
4614 If undefined, 0 is used when @env{OMP_WAIT_POLICY} is @code{PASSIVE},
4615 300,000 is used when @env{OMP_WAIT_POLICY} is undefined and
4616 30 billion is used when @env{OMP_WAIT_POLICY} is @code{ACTIVE}.
4617 If there are more OpenMP threads than available CPUs, 1000 and 100
4618 spins are used for @env{OMP_WAIT_POLICY} being @code{ACTIVE} or
4619 undefined, respectively; unless the @env{GOMP_SPINCOUNT} is lower
4620 or @env{OMP_WAIT_POLICY} is @code{PASSIVE}.
4622 @item @emph{See also}:
4623 @ref{OMP_WAIT_POLICY}
4628 @node GOMP_RTEMS_THREAD_POOLS
4629 @section @env{GOMP_RTEMS_THREAD_POOLS} -- Set the RTEMS specific thread pools
4630 @cindex Environment Variable
4631 @cindex Implementation specific setting
4633 @item @emph{Description}:
4634 This environment variable is only used on the RTEMS real-time operating system.
4635 It determines the scheduler instance specific thread pools. The format for
4636 @env{GOMP_RTEMS_THREAD_POOLS} is a list of optional
4637 @code{<thread-pool-count>[$<priority>]@@<scheduler-name>} configurations
4638 separated by @code{:} where:
4640 @item @code{<thread-pool-count>} is the thread pool count for this scheduler
4642 @item @code{$<priority>} is an optional priority for the worker threads of a
4643 thread pool according to @code{pthread_setschedparam}. In case a priority
4644 value is omitted, then a worker thread inherits the priority of the OpenMP
4645 primary thread that created it. The priority of the worker thread is not
4646 changed after creation, even if a new OpenMP primary thread using the worker has
4647 a different priority.
4648 @item @code{@@<scheduler-name>} is the scheduler instance name according to the
4649 RTEMS application configuration.
4651 In case no thread pool configuration is specified for a scheduler instance,
4652 then each OpenMP primary thread of this scheduler instance uses its own
4653 dynamically allocated thread pool. To limit the worker thread count of the
4654 thread pools, each OpenMP primary thread must call @code{omp_set_num_threads}.
4655 @item @emph{Example}:
4656 Lets suppose we have three scheduler instances @code{IO}, @code{WRK0}, and
4657 @code{WRK1} with @env{GOMP_RTEMS_THREAD_POOLS} set to
4658 @code{"1@@WRK0:3$4@@WRK1"}. Then there are no thread pool restrictions for
4659 scheduler instance @code{IO}. In the scheduler instance @code{WRK0} there is
4660 one thread pool available. Since no priority is specified for this scheduler
4661 instance, the worker thread inherits the priority of the OpenMP primary thread
4662 that created it. In the scheduler instance @code{WRK1} there are three thread
4663 pools available and their worker threads run at priority four.
4668 @c ---------------------------------------------------------------------
4670 @c ---------------------------------------------------------------------
4672 @node Enabling OpenACC
4673 @chapter Enabling OpenACC
4675 To activate the OpenACC extensions for C/C++ and Fortran, the compile-time
4676 flag @option{-fopenacc} must be specified. This enables the OpenACC directive
4677 @samp{#pragma acc} in C/C++ and, in Fortran, the @samp{!$acc} sentinel in free
4678 source form and the @samp{c$acc}, @samp{*$acc} and @samp{!$acc} sentinels in
4679 fixed source form. The flag also arranges for automatic linking of the OpenACC
4680 runtime library (@ref{OpenACC Runtime Library Routines}).
4682 See @uref{https://gcc.gnu.org/wiki/OpenACC} for more information.
4684 A complete description of all OpenACC directives accepted may be found in
4685 the @uref{https://www.openacc.org, OpenACC} Application Programming
4686 Interface manual, version 2.6.
4690 @c ---------------------------------------------------------------------
4691 @c OpenACC Runtime Library Routines
4692 @c ---------------------------------------------------------------------
4694 @node OpenACC Runtime Library Routines
4695 @chapter OpenACC Runtime Library Routines
4697 The runtime routines described here are defined by section 3 of the OpenACC
4698 specifications in version 2.6.
4699 They have C linkage, and do not throw exceptions.
4700 Generally, they are available only for the host, with the exception of
4701 @code{acc_on_device}, which is available for both the host and the
4702 acceleration device.
4705 * acc_get_num_devices:: Get number of devices for the given device
4707 * acc_set_device_type:: Set type of device accelerator to use.
4708 * acc_get_device_type:: Get type of device accelerator to be used.
4709 * acc_set_device_num:: Set device number to use.
4710 * acc_get_device_num:: Get device number to be used.
4711 * acc_get_property:: Get device property.
4712 * acc_async_test:: Tests for completion of a specific asynchronous
4714 * acc_async_test_all:: Tests for completion of all asynchronous
4716 * acc_wait:: Wait for completion of a specific asynchronous
4718 * acc_wait_all:: Waits for completion of all asynchronous
4720 * acc_wait_all_async:: Wait for completion of all asynchronous
4722 * acc_wait_async:: Wait for completion of asynchronous operations.
4723 * acc_init:: Initialize runtime for a specific device type.
4724 * acc_shutdown:: Shuts down the runtime for a specific device
4726 * acc_on_device:: Whether executing on a particular device
4727 * acc_malloc:: Allocate device memory.
4728 * acc_free:: Free device memory.
4729 * acc_copyin:: Allocate device memory and copy host memory to
4731 * acc_present_or_copyin:: If the data is not present on the device,
4732 allocate device memory and copy from host
4734 * acc_create:: Allocate device memory and map it to host
4736 * acc_present_or_create:: If the data is not present on the device,
4737 allocate device memory and map it to host
4739 * acc_copyout:: Copy device memory to host memory.
4740 * acc_delete:: Free device memory.
4741 * acc_update_device:: Update device memory from mapped host memory.
4742 * acc_update_self:: Update host memory from mapped device memory.
4743 * acc_map_data:: Map previously allocated device memory to host
4745 * acc_unmap_data:: Unmap device memory from host memory.
4746 * acc_deviceptr:: Get device pointer associated with specific
4748 * acc_hostptr:: Get host pointer associated with specific
4750 * acc_is_present:: Indicate whether host variable / array is
4752 * acc_memcpy_to_device:: Copy host memory to device memory.
4753 * acc_memcpy_from_device:: Copy device memory to host memory.
4754 * acc_attach:: Let device pointer point to device-pointer target.
4755 * acc_detach:: Let device pointer point to host-pointer target.
4757 API routines for target platforms.
4759 * acc_get_current_cuda_device:: Get CUDA device handle.
4760 * acc_get_current_cuda_context::Get CUDA context handle.
4761 * acc_get_cuda_stream:: Get CUDA stream handle.
4762 * acc_set_cuda_stream:: Set CUDA stream handle.
4764 API routines for the OpenACC Profiling Interface.
4766 * acc_prof_register:: Register callbacks.
4767 * acc_prof_unregister:: Unregister callbacks.
4768 * acc_prof_lookup:: Obtain inquiry functions.
4769 * acc_register_library:: Library registration.
4774 @node acc_get_num_devices
4775 @section @code{acc_get_num_devices} -- Get number of devices for given device type
4777 @item @emph{Description}
4778 This function returns a value indicating the number of devices available
4779 for the device type specified in @var{devicetype}.
4782 @multitable @columnfractions .20 .80
4783 @item @emph{Prototype}: @tab @code{int acc_get_num_devices(acc_device_t devicetype);}
4786 @item @emph{Fortran}:
4787 @multitable @columnfractions .20 .80
4788 @item @emph{Interface}: @tab @code{integer function acc_get_num_devices(devicetype)}
4789 @item @tab @code{integer(kind=acc_device_kind) devicetype}
4792 @item @emph{Reference}:
4793 @uref{https://www.openacc.org, OpenACC specification v2.6}, section
4799 @node acc_set_device_type
4800 @section @code{acc_set_device_type} -- Set type of device accelerator to use.
4802 @item @emph{Description}
4803 This function indicates to the runtime library which device type, specified
4804 in @var{devicetype}, to use when executing a parallel or kernels region.
4807 @multitable @columnfractions .20 .80
4808 @item @emph{Prototype}: @tab @code{acc_set_device_type(acc_device_t devicetype);}
4811 @item @emph{Fortran}:
4812 @multitable @columnfractions .20 .80
4813 @item @emph{Interface}: @tab @code{subroutine acc_set_device_type(devicetype)}
4814 @item @tab @code{integer(kind=acc_device_kind) devicetype}
4817 @item @emph{Reference}:
4818 @uref{https://www.openacc.org, OpenACC specification v2.6}, section
4824 @node acc_get_device_type
4825 @section @code{acc_get_device_type} -- Get type of device accelerator to be used.
4827 @item @emph{Description}
4828 This function returns what device type will be used when executing a
4829 parallel or kernels region.
4831 This function returns @code{acc_device_none} if
4832 @code{acc_get_device_type} is called from
4833 @code{acc_ev_device_init_start}, @code{acc_ev_device_init_end}
4834 callbacks of the OpenACC Profiling Interface (@ref{OpenACC Profiling
4835 Interface}), that is, if the device is currently being initialized.
4838 @multitable @columnfractions .20 .80
4839 @item @emph{Prototype}: @tab @code{acc_device_t acc_get_device_type(void);}
4842 @item @emph{Fortran}:
4843 @multitable @columnfractions .20 .80
4844 @item @emph{Interface}: @tab @code{function acc_get_device_type(void)}
4845 @item @tab @code{integer(kind=acc_device_kind) acc_get_device_type}
4848 @item @emph{Reference}:
4849 @uref{https://www.openacc.org, OpenACC specification v2.6}, section
4855 @node acc_set_device_num
4856 @section @code{acc_set_device_num} -- Set device number to use.
4858 @item @emph{Description}
4859 This function will indicate to the runtime which device number,
4860 specified by @var{devicenum}, associated with the specified device
4861 type @var{devicetype}.
4864 @multitable @columnfractions .20 .80
4865 @item @emph{Prototype}: @tab @code{acc_set_device_num(int devicenum, acc_device_t devicetype);}
4868 @item @emph{Fortran}:
4869 @multitable @columnfractions .20 .80
4870 @item @emph{Interface}: @tab @code{subroutine acc_set_device_num(devicenum, devicetype)}
4871 @item @tab @code{integer devicenum}
4872 @item @tab @code{integer(kind=acc_device_kind) devicetype}
4875 @item @emph{Reference}:
4876 @uref{https://www.openacc.org, OpenACC specification v2.6}, section
4882 @node acc_get_device_num
4883 @section @code{acc_get_device_num} -- Get device number to be used.
4885 @item @emph{Description}
4886 This function returns which device number associated with the specified device
4887 type @var{devicetype}, will be used when executing a parallel or kernels
4891 @multitable @columnfractions .20 .80
4892 @item @emph{Prototype}: @tab @code{int acc_get_device_num(acc_device_t devicetype);}
4895 @item @emph{Fortran}:
4896 @multitable @columnfractions .20 .80
4897 @item @emph{Interface}: @tab @code{function acc_get_device_num(devicetype)}
4898 @item @tab @code{integer(kind=acc_device_kind) devicetype}
4899 @item @tab @code{integer acc_get_device_num}
4902 @item @emph{Reference}:
4903 @uref{https://www.openacc.org, OpenACC specification v2.6}, section
4909 @node acc_get_property
4910 @section @code{acc_get_property} -- Get device property.
4911 @cindex acc_get_property
4912 @cindex acc_get_property_string
4914 @item @emph{Description}
4915 These routines return the value of the specified @var{property} for the
4916 device being queried according to @var{devicenum} and @var{devicetype}.
4917 Integer-valued and string-valued properties are returned by
4918 @code{acc_get_property} and @code{acc_get_property_string} respectively.
4919 The Fortran @code{acc_get_property_string} subroutine returns the string
4920 retrieved in its fourth argument while the remaining entry points are
4921 functions, which pass the return value as their result.
4923 Note for Fortran, only: the OpenACC technical committee corrected and, hence,
4924 modified the interface introduced in OpenACC 2.6. The kind-value parameter
4925 @code{acc_device_property} has been renamed to @code{acc_device_property_kind}
4926 for consistency and the return type of the @code{acc_get_property} function is
4927 now a @code{c_size_t} integer instead of a @code{acc_device_property} integer.
4928 The parameter @code{acc_device_property} is still provided,
4929 but might be removed in a future version of GCC.
4932 @multitable @columnfractions .20 .80
4933 @item @emph{Prototype}: @tab @code{size_t acc_get_property(int devicenum, acc_device_t devicetype, acc_device_property_t property);}
4934 @item @emph{Prototype}: @tab @code{const char *acc_get_property_string(int devicenum, acc_device_t devicetype, acc_device_property_t property);}
4937 @item @emph{Fortran}:
4938 @multitable @columnfractions .20 .80
4939 @item @emph{Interface}: @tab @code{function acc_get_property(devicenum, devicetype, property)}
4940 @item @emph{Interface}: @tab @code{subroutine acc_get_property_string(devicenum, devicetype, property, string)}
4941 @item @tab @code{use ISO_C_Binding, only: c_size_t}
4942 @item @tab @code{integer devicenum}
4943 @item @tab @code{integer(kind=acc_device_kind) devicetype}
4944 @item @tab @code{integer(kind=acc_device_property_kind) property}
4945 @item @tab @code{integer(kind=c_size_t) acc_get_property}
4946 @item @tab @code{character(*) string}
4949 @item @emph{Reference}:
4950 @uref{https://www.openacc.org, OpenACC specification v2.6}, section
4956 @node acc_async_test
4957 @section @code{acc_async_test} -- Test for completion of a specific asynchronous operation.
4959 @item @emph{Description}
4960 This function tests for completion of the asynchronous operation specified
4961 in @var{arg}. In C/C++, a non-zero value is returned to indicate
4962 the specified asynchronous operation has completed while Fortran returns
4963 @code{true}. If the asynchronous operation has not completed, C/C++ returns
4964 zero and Fortran returns @code{false}.
4967 @multitable @columnfractions .20 .80
4968 @item @emph{Prototype}: @tab @code{int acc_async_test(int arg);}
4971 @item @emph{Fortran}:
4972 @multitable @columnfractions .20 .80
4973 @item @emph{Interface}: @tab @code{function acc_async_test(arg)}
4974 @item @tab @code{integer(kind=acc_handle_kind) arg}
4975 @item @tab @code{logical acc_async_test}
4978 @item @emph{Reference}:
4979 @uref{https://www.openacc.org, OpenACC specification v2.6}, section
4985 @node acc_async_test_all
4986 @section @code{acc_async_test_all} -- Tests for completion of all asynchronous operations.
4988 @item @emph{Description}
4989 This function tests for completion of all asynchronous operations.
4990 In C/C++, a non-zero value is returned to indicate all asynchronous
4991 operations have completed while Fortran returns @code{true}. If
4992 any asynchronous operation has not completed, C/C++ returns zero and
4993 Fortran returns @code{false}.
4996 @multitable @columnfractions .20 .80
4997 @item @emph{Prototype}: @tab @code{int acc_async_test_all(void);}
5000 @item @emph{Fortran}:
5001 @multitable @columnfractions .20 .80
5002 @item @emph{Interface}: @tab @code{function acc_async_test()}
5003 @item @tab @code{logical acc_get_device_num}
5006 @item @emph{Reference}:
5007 @uref{https://www.openacc.org, OpenACC specification v2.6}, section
5014 @section @code{acc_wait} -- Wait for completion of a specific asynchronous operation.
5016 @item @emph{Description}
5017 This function waits for completion of the asynchronous operation
5018 specified in @var{arg}.
5021 @multitable @columnfractions .20 .80
5022 @item @emph{Prototype}: @tab @code{acc_wait(arg);}
5023 @item @emph{Prototype (OpenACC 1.0 compatibility)}: @tab @code{acc_async_wait(arg);}
5026 @item @emph{Fortran}:
5027 @multitable @columnfractions .20 .80
5028 @item @emph{Interface}: @tab @code{subroutine acc_wait(arg)}
5029 @item @tab @code{integer(acc_handle_kind) arg}
5030 @item @emph{Interface (OpenACC 1.0 compatibility)}: @tab @code{subroutine acc_async_wait(arg)}
5031 @item @tab @code{integer(acc_handle_kind) arg}
5034 @item @emph{Reference}:
5035 @uref{https://www.openacc.org, OpenACC specification v2.6}, section
5042 @section @code{acc_wait_all} -- Waits for completion of all asynchronous operations.
5044 @item @emph{Description}
5045 This function waits for the completion of all asynchronous operations.
5048 @multitable @columnfractions .20 .80
5049 @item @emph{Prototype}: @tab @code{acc_wait_all(void);}
5050 @item @emph{Prototype (OpenACC 1.0 compatibility)}: @tab @code{acc_async_wait_all(void);}
5053 @item @emph{Fortran}:
5054 @multitable @columnfractions .20 .80
5055 @item @emph{Interface}: @tab @code{subroutine acc_wait_all()}
5056 @item @emph{Interface (OpenACC 1.0 compatibility)}: @tab @code{subroutine acc_async_wait_all()}
5059 @item @emph{Reference}:
5060 @uref{https://www.openacc.org, OpenACC specification v2.6}, section
5066 @node acc_wait_all_async
5067 @section @code{acc_wait_all_async} -- Wait for completion of all asynchronous operations.
5069 @item @emph{Description}
5070 This function enqueues a wait operation on the queue @var{async} for any
5071 and all asynchronous operations that have been previously enqueued on
5075 @multitable @columnfractions .20 .80
5076 @item @emph{Prototype}: @tab @code{acc_wait_all_async(int async);}
5079 @item @emph{Fortran}:
5080 @multitable @columnfractions .20 .80
5081 @item @emph{Interface}: @tab @code{subroutine acc_wait_all_async(async)}
5082 @item @tab @code{integer(acc_handle_kind) async}
5085 @item @emph{Reference}:
5086 @uref{https://www.openacc.org, OpenACC specification v2.6}, section
5092 @node acc_wait_async
5093 @section @code{acc_wait_async} -- Wait for completion of asynchronous operations.
5095 @item @emph{Description}
5096 This function enqueues a wait operation on queue @var{async} for any and all
5097 asynchronous operations enqueued on queue @var{arg}.
5100 @multitable @columnfractions .20 .80
5101 @item @emph{Prototype}: @tab @code{acc_wait_async(int arg, int async);}
5104 @item @emph{Fortran}:
5105 @multitable @columnfractions .20 .80
5106 @item @emph{Interface}: @tab @code{subroutine acc_wait_async(arg, async)}
5107 @item @tab @code{integer(acc_handle_kind) arg, async}
5110 @item @emph{Reference}:
5111 @uref{https://www.openacc.org, OpenACC specification v2.6}, section
5118 @section @code{acc_init} -- Initialize runtime for a specific device type.
5120 @item @emph{Description}
5121 This function initializes the runtime for the device type specified in
5125 @multitable @columnfractions .20 .80
5126 @item @emph{Prototype}: @tab @code{acc_init(acc_device_t devicetype);}
5129 @item @emph{Fortran}:
5130 @multitable @columnfractions .20 .80
5131 @item @emph{Interface}: @tab @code{subroutine acc_init(devicetype)}
5132 @item @tab @code{integer(acc_device_kind) devicetype}
5135 @item @emph{Reference}:
5136 @uref{https://www.openacc.org, OpenACC specification v2.6}, section
5143 @section @code{acc_shutdown} -- Shuts down the runtime for a specific device type.
5145 @item @emph{Description}
5146 This function shuts down the runtime for the device type specified in
5150 @multitable @columnfractions .20 .80
5151 @item @emph{Prototype}: @tab @code{acc_shutdown(acc_device_t devicetype);}
5154 @item @emph{Fortran}:
5155 @multitable @columnfractions .20 .80
5156 @item @emph{Interface}: @tab @code{subroutine acc_shutdown(devicetype)}
5157 @item @tab @code{integer(acc_device_kind) devicetype}
5160 @item @emph{Reference}:
5161 @uref{https://www.openacc.org, OpenACC specification v2.6}, section
5168 @section @code{acc_on_device} -- Whether executing on a particular device
5170 @item @emph{Description}:
5171 This function returns whether the program is executing on a particular
5172 device specified in @var{devicetype}. In C/C++ a non-zero value is
5173 returned to indicate the device is executing on the specified device type.
5174 In Fortran, @code{true} is returned. If the program is not executing
5175 on the specified device type C/C++ returns zero, while Fortran
5176 returns @code{false}.
5178 Note that in GCC, depending on @var{devicetype}, the function call might
5179 be folded to a constant in the compiler; compile with
5180 @option{-fno-builtin-acc_on_device} if a run-time function is desired.
5183 @multitable @columnfractions .20 .80
5184 @item @emph{Prototype}: @tab @code{acc_on_device(acc_device_t devicetype);}
5187 @item @emph{Fortran}:
5188 @multitable @columnfractions .20 .80
5189 @item @emph{Interface}: @tab @code{function acc_on_device(devicetype)}
5190 @item @tab @code{integer(acc_device_kind) devicetype}
5191 @item @tab @code{logical acc_on_device}
5194 @item @emph{Reference}:
5195 @uref{https://www.openacc.org, OpenACC specification v2.6}, section
5202 @section @code{acc_malloc} -- Allocate device memory.
5204 @item @emph{Description}
5205 This function allocates @var{bytes} bytes of device memory. It returns
5206 the device address of the allocated memory.
5209 @multitable @columnfractions .20 .80
5210 @item @emph{Prototype}: @tab @code{d_void* acc_malloc(size_t bytes);}
5213 @item @emph{Fortran}:
5214 @multitable @columnfractions .20 .80
5215 @item @emph{Interface}: @tab @code{type(c_ptr) function acc_malloc(bytes)}
5216 @item @tab @code{integer(c_size_t), value :: bytes}
5219 @item @emph{Reference}:
5220 @uref{https://www.openacc.org, OpenACC specification v2.6}, section
5221 3.2.18. @uref{https://www.openacc.org, openacc specification v3.3}, section
5228 @section @code{acc_free} -- Free device memory.
5230 @item @emph{Description}
5231 Free previously allocated device memory at the device address @code{data_dev}.
5234 @multitable @columnfractions .20 .80
5235 @item @emph{Prototype}: @tab @code{void acc_free(d_void *data_dev);}
5238 @item @emph{Fortran}:
5239 @multitable @columnfractions .20 .80
5240 @item @emph{Interface}: @tab @code{subroutine acc_free(data_dev)}
5241 @item @tab @code{type(c_ptr), value :: data_dev}
5244 @item @emph{Reference}:
5245 @uref{https://www.openacc.org, OpenACC specification v2.6}, section
5246 3.2.19. @uref{https://www.openacc.org, openacc specification v3.3}, section
5253 @section @code{acc_copyin} -- Allocate device memory and copy host memory to it.
5255 @item @emph{Description}
5256 In C/C++, this function allocates @var{len} bytes of device memory
5257 and maps it to the specified host address in @var{a}. The device
5258 address of the newly allocated device memory is returned.
5260 In Fortran, two (2) forms are supported. In the first form, @var{a} specifies
5261 a contiguous array section. The second form @var{a} specifies a
5262 variable or array element and @var{len} specifies the length in bytes.
5265 @multitable @columnfractions .20 .80
5266 @item @emph{Prototype}: @tab @code{void *acc_copyin(h_void *a, size_t len);}
5267 @item @emph{Prototype}: @tab @code{void *acc_copyin_async(h_void *a, size_t len, int async);}
5270 @item @emph{Fortran}:
5271 @multitable @columnfractions .20 .80
5272 @item @emph{Interface}: @tab @code{subroutine acc_copyin(a)}
5273 @item @tab @code{type, dimension(:[,:]...) :: a}
5274 @item @emph{Interface}: @tab @code{subroutine acc_copyin(a, len)}
5275 @item @tab @code{type, dimension(:[,:]...) :: a}
5276 @item @tab @code{integer len}
5277 @item @emph{Interface}: @tab @code{subroutine acc_copyin_async(a, async)}
5278 @item @tab @code{type, dimension(:[,:]...) :: a}
5279 @item @tab @code{integer(acc_handle_kind) :: async}
5280 @item @emph{Interface}: @tab @code{subroutine acc_copyin_async(a, len, async)}
5281 @item @tab @code{type, dimension(:[,:]...) :: a}
5282 @item @tab @code{integer len}
5283 @item @tab @code{integer(acc_handle_kind) :: async}
5286 @item @emph{Reference}:
5287 @uref{https://www.openacc.org, OpenACC specification v2.6}, section
5293 @node acc_present_or_copyin
5294 @section @code{acc_present_or_copyin} -- If the data is not present on the device, allocate device memory and copy from host memory.
5296 @item @emph{Description}
5297 This function tests if the host data specified by @var{a} and of length
5298 @var{len} is present or not. If it is not present, device memory
5299 is allocated and the host memory copied. The device address of
5300 the newly allocated device memory is returned.
5302 In Fortran, two (2) forms are supported. In the first form, @var{a} specifies
5303 a contiguous array section. The second form @var{a} specifies a variable or
5304 array element and @var{len} specifies the length in bytes.
5306 Note that @code{acc_present_or_copyin} and @code{acc_pcopyin} exist for
5307 backward compatibility with OpenACC 2.0; use @ref{acc_copyin} instead.
5310 @multitable @columnfractions .20 .80
5311 @item @emph{Prototype}: @tab @code{void *acc_present_or_copyin(h_void *a, size_t len);}
5312 @item @emph{Prototype}: @tab @code{void *acc_pcopyin(h_void *a, size_t len);}
5315 @item @emph{Fortran}:
5316 @multitable @columnfractions .20 .80
5317 @item @emph{Interface}: @tab @code{subroutine acc_present_or_copyin(a)}
5318 @item @tab @code{type, dimension(:[,:]...) :: a}
5319 @item @emph{Interface}: @tab @code{subroutine acc_present_or_copyin(a, len)}
5320 @item @tab @code{type, dimension(:[,:]...) :: a}
5321 @item @tab @code{integer len}
5322 @item @emph{Interface}: @tab @code{subroutine acc_pcopyin(a)}
5323 @item @tab @code{type, dimension(:[,:]...) :: a}
5324 @item @emph{Interface}: @tab @code{subroutine acc_pcopyin(a, len)}
5325 @item @tab @code{type, dimension(:[,:]...) :: a}
5326 @item @tab @code{integer len}
5329 @item @emph{Reference}:
5330 @uref{https://www.openacc.org, OpenACC specification v2.6}, section
5337 @section @code{acc_create} -- Allocate device memory and map it to host memory.
5339 @item @emph{Description}
5340 This function allocates device memory and maps it to host memory specified
5341 by the host address @var{a} with a length of @var{len} bytes. In C/C++,
5342 the function returns the device address of the allocated device memory.
5344 In Fortran, two (2) forms are supported. In the first form, @var{a} specifies
5345 a contiguous array section. The second form @var{a} specifies a variable or
5346 array element and @var{len} specifies the length in bytes.
5349 @multitable @columnfractions .20 .80
5350 @item @emph{Prototype}: @tab @code{void *acc_create(h_void *a, size_t len);}
5351 @item @emph{Prototype}: @tab @code{void *acc_create_async(h_void *a, size_t len, int async);}
5354 @item @emph{Fortran}:
5355 @multitable @columnfractions .20 .80
5356 @item @emph{Interface}: @tab @code{subroutine acc_create(a)}
5357 @item @tab @code{type, dimension(:[,:]...) :: a}
5358 @item @emph{Interface}: @tab @code{subroutine acc_create(a, len)}
5359 @item @tab @code{type, dimension(:[,:]...) :: a}
5360 @item @tab @code{integer len}
5361 @item @emph{Interface}: @tab @code{subroutine acc_create_async(a, async)}
5362 @item @tab @code{type, dimension(:[,:]...) :: a}
5363 @item @tab @code{integer(acc_handle_kind) :: async}
5364 @item @emph{Interface}: @tab @code{subroutine acc_create_async(a, len, async)}
5365 @item @tab @code{type, dimension(:[,:]...) :: a}
5366 @item @tab @code{integer len}
5367 @item @tab @code{integer(acc_handle_kind) :: async}
5370 @item @emph{Reference}:
5371 @uref{https://www.openacc.org, OpenACC specification v2.6}, section
5377 @node acc_present_or_create
5378 @section @code{acc_present_or_create} -- If the data is not present on the device, allocate device memory and map it to host memory.
5380 @item @emph{Description}
5381 This function tests if the host data specified by @var{a} and of length
5382 @var{len} is present or not. If it is not present, device memory
5383 is allocated and mapped to host memory. In C/C++, the device address
5384 of the newly allocated device memory is returned.
5386 In Fortran, two (2) forms are supported. In the first form, @var{a} specifies
5387 a contiguous array section. The second form @var{a} specifies a variable or
5388 array element and @var{len} specifies the length in bytes.
5390 Note that @code{acc_present_or_create} and @code{acc_pcreate} exist for
5391 backward compatibility with OpenACC 2.0; use @ref{acc_create} instead.
5394 @multitable @columnfractions .20 .80
5395 @item @emph{Prototype}: @tab @code{void *acc_present_or_create(h_void *a, size_t len)}
5396 @item @emph{Prototype}: @tab @code{void *acc_pcreate(h_void *a, size_t len)}
5399 @item @emph{Fortran}:
5400 @multitable @columnfractions .20 .80
5401 @item @emph{Interface}: @tab @code{subroutine acc_present_or_create(a)}
5402 @item @tab @code{type, dimension(:[,:]...) :: a}
5403 @item @emph{Interface}: @tab @code{subroutine acc_present_or_create(a, len)}
5404 @item @tab @code{type, dimension(:[,:]...) :: a}
5405 @item @tab @code{integer len}
5406 @item @emph{Interface}: @tab @code{subroutine acc_pcreate(a)}
5407 @item @tab @code{type, dimension(:[,:]...) :: a}
5408 @item @emph{Interface}: @tab @code{subroutine acc_pcreate(a, len)}
5409 @item @tab @code{type, dimension(:[,:]...) :: a}
5410 @item @tab @code{integer len}
5413 @item @emph{Reference}:
5414 @uref{https://www.openacc.org, OpenACC specification v2.6}, section
5421 @section @code{acc_copyout} -- Copy device memory to host memory.
5423 @item @emph{Description}
5424 This function copies mapped device memory to host memory which is specified
5425 by host address @var{a} for a length @var{len} bytes in C/C++.
5427 In Fortran, two (2) forms are supported. In the first form, @var{a} specifies
5428 a contiguous array section. The second form @var{a} specifies a variable or
5429 array element and @var{len} specifies the length in bytes.
5432 @multitable @columnfractions .20 .80
5433 @item @emph{Prototype}: @tab @code{acc_copyout(h_void *a, size_t len);}
5434 @item @emph{Prototype}: @tab @code{acc_copyout_async(h_void *a, size_t len, int async);}
5435 @item @emph{Prototype}: @tab @code{acc_copyout_finalize(h_void *a, size_t len);}
5436 @item @emph{Prototype}: @tab @code{acc_copyout_finalize_async(h_void *a, size_t len, int async);}
5439 @item @emph{Fortran}:
5440 @multitable @columnfractions .20 .80
5441 @item @emph{Interface}: @tab @code{subroutine acc_copyout(a)}
5442 @item @tab @code{type, dimension(:[,:]...) :: a}
5443 @item @emph{Interface}: @tab @code{subroutine acc_copyout(a, len)}
5444 @item @tab @code{type, dimension(:[,:]...) :: a}
5445 @item @tab @code{integer len}
5446 @item @emph{Interface}: @tab @code{subroutine acc_copyout_async(a, async)}
5447 @item @tab @code{type, dimension(:[,:]...) :: a}
5448 @item @tab @code{integer(acc_handle_kind) :: async}
5449 @item @emph{Interface}: @tab @code{subroutine acc_copyout_async(a, len, async)}
5450 @item @tab @code{type, dimension(:[,:]...) :: a}
5451 @item @tab @code{integer len}
5452 @item @tab @code{integer(acc_handle_kind) :: async}
5453 @item @emph{Interface}: @tab @code{subroutine acc_copyout_finalize(a)}
5454 @item @tab @code{type, dimension(:[,:]...) :: a}
5455 @item @emph{Interface}: @tab @code{subroutine acc_copyout_finalize(a, len)}
5456 @item @tab @code{type, dimension(:[,:]...) :: a}
5457 @item @tab @code{integer len}
5458 @item @emph{Interface}: @tab @code{subroutine acc_copyout_finalize_async(a, async)}
5459 @item @tab @code{type, dimension(:[,:]...) :: a}
5460 @item @tab @code{integer(acc_handle_kind) :: async}
5461 @item @emph{Interface}: @tab @code{subroutine acc_copyout_finalize_async(a, len, async)}
5462 @item @tab @code{type, dimension(:[,:]...) :: a}
5463 @item @tab @code{integer len}
5464 @item @tab @code{integer(acc_handle_kind) :: async}
5467 @item @emph{Reference}:
5468 @uref{https://www.openacc.org, OpenACC specification v2.6}, section
5475 @section @code{acc_delete} -- Free device memory.
5477 @item @emph{Description}
5478 This function frees previously allocated device memory specified by
5479 the device address @var{a} and the length of @var{len} bytes.
5481 In Fortran, two (2) forms are supported. In the first form, @var{a} specifies
5482 a contiguous array section. The second form @var{a} specifies a variable or
5483 array element and @var{len} specifies the length in bytes.
5486 @multitable @columnfractions .20 .80
5487 @item @emph{Prototype}: @tab @code{acc_delete(h_void *a, size_t len);}
5488 @item @emph{Prototype}: @tab @code{acc_delete_async(h_void *a, size_t len, int async);}
5489 @item @emph{Prototype}: @tab @code{acc_delete_finalize(h_void *a, size_t len);}
5490 @item @emph{Prototype}: @tab @code{acc_delete_finalize_async(h_void *a, size_t len, int async);}
5493 @item @emph{Fortran}:
5494 @multitable @columnfractions .20 .80
5495 @item @emph{Interface}: @tab @code{subroutine acc_delete(a)}
5496 @item @tab @code{type, dimension(:[,:]...) :: a}
5497 @item @emph{Interface}: @tab @code{subroutine acc_delete(a, len)}
5498 @item @tab @code{type, dimension(:[,:]...) :: a}
5499 @item @tab @code{integer len}
5500 @item @emph{Interface}: @tab @code{subroutine acc_delete_async(a, async)}
5501 @item @tab @code{type, dimension(:[,:]...) :: a}
5502 @item @tab @code{integer(acc_handle_kind) :: async}
5503 @item @emph{Interface}: @tab @code{subroutine acc_delete_async(a, len, async)}
5504 @item @tab @code{type, dimension(:[,:]...) :: a}
5505 @item @tab @code{integer len}
5506 @item @tab @code{integer(acc_handle_kind) :: async}
5507 @item @emph{Interface}: @tab @code{subroutine acc_delete_finalize(a)}
5508 @item @tab @code{type, dimension(:[,:]...) :: a}
5509 @item @emph{Interface}: @tab @code{subroutine acc_delete_finalize(a, len)}
5510 @item @tab @code{type, dimension(:[,:]...) :: a}
5511 @item @tab @code{integer len}
5512 @item @emph{Interface}: @tab @code{subroutine acc_delete_async_finalize(a, async)}
5513 @item @tab @code{type, dimension(:[,:]...) :: a}
5514 @item @tab @code{integer(acc_handle_kind) :: async}
5515 @item @emph{Interface}: @tab @code{subroutine acc_delete_async_finalize(a, len, async)}
5516 @item @tab @code{type, dimension(:[,:]...) :: a}
5517 @item @tab @code{integer len}
5518 @item @tab @code{integer(acc_handle_kind) :: async}
5521 @item @emph{Reference}:
5522 @uref{https://www.openacc.org, OpenACC specification v2.6}, section
5528 @node acc_update_device
5529 @section @code{acc_update_device} -- Update device memory from mapped host memory.
5531 @item @emph{Description}
5532 This function updates the device copy from the previously mapped host memory.
5533 The host memory is specified with the host address @var{a} and a length of
5536 In Fortran, two (2) forms are supported. In the first form, @var{a} specifies
5537 a contiguous array section. The second form @var{a} specifies a variable or
5538 array element and @var{len} specifies the length in bytes.
5541 @multitable @columnfractions .20 .80
5542 @item @emph{Prototype}: @tab @code{acc_update_device(h_void *a, size_t len);}
5543 @item @emph{Prototype}: @tab @code{acc_update_device(h_void *a, size_t len, async);}
5546 @item @emph{Fortran}:
5547 @multitable @columnfractions .20 .80
5548 @item @emph{Interface}: @tab @code{subroutine acc_update_device(a)}
5549 @item @tab @code{type, dimension(:[,:]...) :: a}
5550 @item @emph{Interface}: @tab @code{subroutine acc_update_device(a, len)}
5551 @item @tab @code{type, dimension(:[,:]...) :: a}
5552 @item @tab @code{integer len}
5553 @item @emph{Interface}: @tab @code{subroutine acc_update_device_async(a, async)}
5554 @item @tab @code{type, dimension(:[,:]...) :: a}
5555 @item @tab @code{integer(acc_handle_kind) :: async}
5556 @item @emph{Interface}: @tab @code{subroutine acc_update_device_async(a, len, async)}
5557 @item @tab @code{type, dimension(:[,:]...) :: a}
5558 @item @tab @code{integer len}
5559 @item @tab @code{integer(acc_handle_kind) :: async}
5562 @item @emph{Reference}:
5563 @uref{https://www.openacc.org, OpenACC specification v2.6}, section
5569 @node acc_update_self
5570 @section @code{acc_update_self} -- Update host memory from mapped device memory.
5572 @item @emph{Description}
5573 This function updates the host copy from the previously mapped device memory.
5574 The host memory is specified with the host address @var{a} and a length of
5577 In Fortran, two (2) forms are supported. In the first form, @var{a} specifies
5578 a contiguous array section. The second form @var{a} specifies a variable or
5579 array element and @var{len} specifies the length in bytes.
5582 @multitable @columnfractions .20 .80
5583 @item @emph{Prototype}: @tab @code{acc_update_self(h_void *a, size_t len);}
5584 @item @emph{Prototype}: @tab @code{acc_update_self_async(h_void *a, size_t len, int async);}
5587 @item @emph{Fortran}:
5588 @multitable @columnfractions .20 .80
5589 @item @emph{Interface}: @tab @code{subroutine acc_update_self(a)}
5590 @item @tab @code{type, dimension(:[,:]...) :: a}
5591 @item @emph{Interface}: @tab @code{subroutine acc_update_self(a, len)}
5592 @item @tab @code{type, dimension(:[,:]...) :: a}
5593 @item @tab @code{integer len}
5594 @item @emph{Interface}: @tab @code{subroutine acc_update_self_async(a, async)}
5595 @item @tab @code{type, dimension(:[,:]...) :: a}
5596 @item @tab @code{integer(acc_handle_kind) :: async}
5597 @item @emph{Interface}: @tab @code{subroutine acc_update_self_async(a, len, async)}
5598 @item @tab @code{type, dimension(:[,:]...) :: a}
5599 @item @tab @code{integer len}
5600 @item @tab @code{integer(acc_handle_kind) :: async}
5603 @item @emph{Reference}:
5604 @uref{https://www.openacc.org, OpenACC specification v2.6}, section
5611 @section @code{acc_map_data} -- Map previously allocated device memory to host memory.
5613 @item @emph{Description}
5614 This function maps previously allocated device and host memory. The device
5615 memory is specified with the device address @var{data_dev}. The host memory is
5616 specified with the host address @var{data_arg} and a length of @var{bytes}.
5619 @multitable @columnfractions .20 .80
5620 @item @emph{Prototype}: @tab @code{void acc_map_data(h_void *data_arg, d_void *data_dev, size_t bytes);}
5623 @item @emph{Fortran}:
5624 @multitable @columnfractions .20 .80
5625 @item @emph{Interface}: @tab @code{subroutine acc_map_data(data_arg, data_dev, bytes)}
5626 @item @tab @code{type(*), dimension(*) :: data_arg}
5627 @item @tab @code{type(c_ptr), value :: data_dev}
5628 @item @tab @code{integer(c_size_t), value :: bytes}
5631 @item @emph{Reference}:
5632 @uref{https://www.openacc.org, OpenACC specification v2.6}, section
5633 3.2.26. @uref{https://www.openacc.org, OpenACC specification v3.3}, section
5639 @node acc_unmap_data
5640 @section @code{acc_unmap_data} -- Unmap device memory from host memory.
5642 @item @emph{Description}
5643 This function unmaps previously mapped device and host memory. The latter
5644 specified by @var{data_arg}.
5647 @multitable @columnfractions .20 .80
5648 @item @emph{Prototype}: @tab @code{void acc_unmap_data(h_void *data_arg);}
5651 @item @emph{Fortran}:
5652 @multitable @columnfractions .20 .80
5653 @item @emph{Interface}: @tab @code{subroutine acc_unmap_data(data_arg)}
5654 @item @tab @code{type(*), dimension(*) :: data_arg}
5657 @item @emph{Reference}:
5658 @uref{https://www.openacc.org, OpenACC specification v2.6}, section
5659 3.2.27. @uref{https://www.openacc.org, OpenACC specification v3.3}, section
5666 @section @code{acc_deviceptr} -- Get device pointer associated with specific host address.
5668 @item @emph{Description}
5669 This function returns the device address that has been mapped to the
5670 host address specified by @var{data_arg}.
5673 @multitable @columnfractions .20 .80
5674 @item @emph{Prototype}: @tab @code{void *acc_deviceptr(h_void *data_arg);}
5677 @item @emph{Fortran}:
5678 @multitable @columnfractions .20 .80
5679 @item @emph{Interface}: @tab @code{type(c_ptr) function acc_deviceptr(data_arg)}
5680 @item @tab @code{type(*), dimension(*) :: data_arg}
5683 @item @emph{Reference}:
5684 @uref{https://www.openacc.org, OpenACC specification v2.6}, section
5685 3.2.28. @uref{https://www.openacc.org, OpenACC specification v3.3}, section
5692 @section @code{acc_hostptr} -- Get host pointer associated with specific device address.
5694 @item @emph{Description}
5695 This function returns the host address that has been mapped to the
5696 device address specified by @var{data_dev}.
5699 @multitable @columnfractions .20 .80
5700 @item @emph{Prototype}: @tab @code{void *acc_hostptr(d_void *data_dev);}
5703 @item @emph{Fortran}:
5704 @multitable @columnfractions .20 .80
5705 @item @emph{Interface}: @tab @code{type(c_ptr) function acc_hostptr(data_dev)}
5706 @item @tab @code{type(c_ptr), value :: data_dev}
5709 @item @emph{Reference}:
5710 @uref{https://www.openacc.org, OpenACC specification v2.6}, section
5711 3.2.29. @uref{https://www.openacc.org, OpenACC specification v3.3}, section
5717 @node acc_is_present
5718 @section @code{acc_is_present} -- Indicate whether host variable / array is present on device.
5720 @item @emph{Description}
5721 This function indicates whether the specified host address in @var{a} and a
5722 length of @var{len} bytes is present on the device. In C/C++, a non-zero
5723 value is returned to indicate the presence of the mapped memory on the
5724 device. A zero is returned to indicate the memory is not mapped on the
5727 In Fortran, two (2) forms are supported. In the first form, @var{a} specifies
5728 a contiguous array section. The second form @var{a} specifies a variable or
5729 array element and @var{len} specifies the length in bytes. If the host
5730 memory is mapped to device memory, then a @code{true} is returned. Otherwise,
5731 a @code{false} is return to indicate the mapped memory is not present.
5734 @multitable @columnfractions .20 .80
5735 @item @emph{Prototype}: @tab @code{int acc_is_present(h_void *a, size_t len);}
5738 @item @emph{Fortran}:
5739 @multitable @columnfractions .20 .80
5740 @item @emph{Interface}: @tab @code{function acc_is_present(a)}
5741 @item @tab @code{type, dimension(:[,:]...) :: a}
5742 @item @tab @code{logical acc_is_present}
5743 @item @emph{Interface}: @tab @code{function acc_is_present(a, len)}
5744 @item @tab @code{type, dimension(:[,:]...) :: a}
5745 @item @tab @code{integer len}
5746 @item @tab @code{logical acc_is_present}
5749 @item @emph{Reference}:
5750 @uref{https://www.openacc.org, OpenACC specification v2.6}, section
5756 @node acc_memcpy_to_device
5757 @section @code{acc_memcpy_to_device} -- Copy host memory to device memory.
5759 @item @emph{Description}
5760 This function copies host memory specified by host address of
5761 @var{data_host_src} to device memory specified by the device address
5762 @var{data_dev_dest} for a length of @var{bytes} bytes.
5765 @multitable @columnfractions .20 .80
5766 @item @emph{Prototype}: @tab @code{void acc_memcpy_to_device(d_void* data_dev_dest,}
5767 @item @tab @code{h_void* data_host_src, size_t bytes);}
5768 @item @emph{Prototype}: @tab @code{void acc_memcpy_to_device_async(d_void* data_dev_dest,}
5769 @item @tab @code{h_void* data_host_src, size_t bytes, int async_arg);}
5772 @item @emph{Fortran}:
5773 @multitable @columnfractions .20 .80
5774 @item @emph{Interface}: @tab @code{subroutine acc_memcpy_to_device(data_dev_dest, &}
5775 @item @tab @code{data_host_src, bytes)}
5776 @item @emph{Interface}: @tab @code{subroutine acc_memcpy_to_device_async(data_dev_dest, &}
5777 @item @tab @code{data_host_src, bytes, async_arg)}
5778 @item @tab @code{type(c_ptr), value :: data_dev_dest}
5779 @item @tab @code{type(*), dimension(*) :: data_host_src}
5780 @item @tab @code{integer(c_size_t), value :: bytes}
5781 @item @tab @code{integer(acc_handle_kind), value :: async_arg}
5784 @item @emph{Reference}:
5785 @uref{https://www.openacc.org, OpenACC specification v2.6}, section
5786 3.2.31 @uref{https://www.openacc.org, OpenACC specification v3.3}, section
5792 @node acc_memcpy_from_device
5793 @section @code{acc_memcpy_from_device} -- Copy device memory to host memory.
5795 @item @emph{Description}
5796 This function copies device memory specified by device address of
5797 @var{data_dev_src} to host memory specified by the host address
5798 @var{data_host_dest} for a length of @var{bytes} bytes.
5801 @multitable @columnfractions .20 .80
5802 @item @emph{Prototype}: @tab @code{void acc_memcpy_from_device(h_void* data_host_dest,}
5803 @item @tab @code{d_void* data_dev_src, size_t bytes);}
5804 @item @emph{Prototype}: @tab @code{void acc_memcpy_from_device_async(h_void* data_host_dest,}
5805 @item @tab @code{d_void* data_dev_src, size_t bytes, int async_arg);}
5808 @item @emph{Fortran}:
5809 @multitable @columnfractions .20 .80
5810 @item @emph{Interface}: @tab @code{subroutine acc_memcpy_from_device(data_host_dest, &}
5811 @item @tab @code{data_dev_src, bytes)}
5812 @item @emph{Interface}: @tab @code{subroutine acc_memcpy_from_device_async(data_host_dest, &}
5813 @item @tab @code{data_dev_src, bytes, async_arg)}
5814 @item @tab @code{type(*), dimension(*) :: data_host_dest}
5815 @item @tab @code{type(c_ptr), value :: data_dev_src}
5816 @item @tab @code{integer(c_size_t), value :: bytes}
5817 @item @tab @code{integer(acc_handle_kind), value :: async_arg}
5820 @item @emph{Reference}:
5821 @uref{https://www.openacc.org, OpenACC specification v2.6}, section
5822 3.2.32. @uref{https://www.openacc.org, OpenACC specification v3.3}, section
5829 @section @code{acc_attach} -- Let device pointer point to device-pointer target.
5831 @item @emph{Description}
5832 This function updates a pointer on the device from pointing to a host-pointer
5833 address to pointing to the corresponding device data.
5836 @multitable @columnfractions .20 .80
5837 @item @emph{Prototype}: @tab @code{void acc_attach(h_void **ptr_addr);}
5838 @item @emph{Prototype}: @tab @code{void acc_attach_async(h_void **ptr_addr, int async);}
5841 @c @item @emph{Fortran}:
5842 @c @multitable @columnfractions .20 .80
5843 @c @item @emph{Interface}: @tab @code{subroutine acc_attach(ptr_addr)}
5844 @c @item @emph{Interface}: @tab @code{subroutine acc_attach_async(ptr_addr, async_arg)}
5845 @c @item @tab @code{type(*), dimension(..) :: ptr_addr}
5846 @c @item @tab @code{integer(acc_handle_kind), value :: async_arg}
5849 @item @emph{Reference}:
5850 @uref{https://www.openacc.org, OpenACC specification v2.6}, section
5852 @c @uref{https://www.openacc.org, OpenACC specification v3.3}, section
5859 @section @code{acc_detach} -- Let device pointer point to host-pointer target.
5861 @item @emph{Description}
5862 This function updates a pointer on the device from pointing to a device-pointer
5863 address to pointing to the corresponding host data.
5866 @multitable @columnfractions .20 .80
5867 @item @emph{Prototype}: @tab @code{void acc_detach(h_void **ptr_addr);}
5868 @item @emph{Prototype}: @tab @code{void acc_detach_async(h_void **ptr_addr, int async);}
5869 @item @emph{Prototype}: @tab @code{void acc_detach_finalize(h_void **ptr_addr);}
5870 @item @emph{Prototype}: @tab @code{void acc_detach_finalize_async(h_void **ptr_addr, int async);}
5873 @c @item @emph{Fortran}:
5874 @c @multitable @columnfractions .20 .80
5875 @c @item @emph{Interface}: @tab @code{subroutine acc_detach(ptr_addr)}
5876 @c @item @emph{Interface}: @tab @code{subroutine acc_detach_async(ptr_addr, async_arg)}
5877 @c @item @emph{Interface}: @tab @code{subroutine acc_detach_finalize(ptr_addr)}
5878 @c @item @emph{Interface}: @tab @code{subroutine acc_detach_finalize_async(ptr_addr, async_arg)}
5879 @c @item @tab @code{type(*), dimension(..) :: ptr_addr}
5880 @c @item @tab @code{integer(acc_handle_kind), value :: async_arg}
5883 @item @emph{Reference}:
5884 @uref{https://www.openacc.org, OpenACC specification v2.6}, section
5886 @c @uref{https://www.openacc.org, OpenACC specification v3.3}, section
5892 @node acc_get_current_cuda_device
5893 @section @code{acc_get_current_cuda_device} -- Get CUDA device handle.
5895 @item @emph{Description}
5896 This function returns the CUDA device handle. This handle is the same
5897 as used by the CUDA Runtime or Driver API's.
5900 @multitable @columnfractions .20 .80
5901 @item @emph{Prototype}: @tab @code{void *acc_get_current_cuda_device(void);}
5904 @item @emph{Reference}:
5905 @uref{https://www.openacc.org, OpenACC specification v2.6}, section
5911 @node acc_get_current_cuda_context
5912 @section @code{acc_get_current_cuda_context} -- Get CUDA context handle.
5914 @item @emph{Description}
5915 This function returns the CUDA context handle. This handle is the same
5916 as used by the CUDA Runtime or Driver API's.
5919 @multitable @columnfractions .20 .80
5920 @item @emph{Prototype}: @tab @code{void *acc_get_current_cuda_context(void);}
5923 @item @emph{Reference}:
5924 @uref{https://www.openacc.org, OpenACC specification v2.6}, section
5930 @node acc_get_cuda_stream
5931 @section @code{acc_get_cuda_stream} -- Get CUDA stream handle.
5933 @item @emph{Description}
5934 This function returns the CUDA stream handle for the queue @var{async}.
5935 This handle is the same as used by the CUDA Runtime or Driver API's.
5938 @multitable @columnfractions .20 .80
5939 @item @emph{Prototype}: @tab @code{void *acc_get_cuda_stream(int async);}
5942 @item @emph{Reference}:
5943 @uref{https://www.openacc.org, OpenACC specification v2.6}, section
5949 @node acc_set_cuda_stream
5950 @section @code{acc_set_cuda_stream} -- Set CUDA stream handle.
5952 @item @emph{Description}
5953 This function associates the stream handle specified by @var{stream} with
5954 the queue @var{async}.
5956 This cannot be used to change the stream handle associated with
5957 @code{acc_async_sync}.
5959 The return value is not specified.
5962 @multitable @columnfractions .20 .80
5963 @item @emph{Prototype}: @tab @code{int acc_set_cuda_stream(int async, void *stream);}
5966 @item @emph{Reference}:
5967 @uref{https://www.openacc.org, OpenACC specification v2.6}, section
5973 @node acc_prof_register
5974 @section @code{acc_prof_register} -- Register callbacks.
5976 @item @emph{Description}:
5977 This function registers callbacks.
5980 @multitable @columnfractions .20 .80
5981 @item @emph{Prototype}: @tab @code{void acc_prof_register (acc_event_t, acc_prof_callback, acc_register_t);}
5984 @item @emph{See also}:
5985 @ref{OpenACC Profiling Interface}
5987 @item @emph{Reference}:
5988 @uref{https://www.openacc.org, OpenACC specification v2.6}, section
5994 @node acc_prof_unregister
5995 @section @code{acc_prof_unregister} -- Unregister callbacks.
5997 @item @emph{Description}:
5998 This function unregisters callbacks.
6001 @multitable @columnfractions .20 .80
6002 @item @emph{Prototype}: @tab @code{void acc_prof_unregister (acc_event_t, acc_prof_callback, acc_register_t);}
6005 @item @emph{See also}:
6006 @ref{OpenACC Profiling Interface}
6008 @item @emph{Reference}:
6009 @uref{https://www.openacc.org, OpenACC specification v2.6}, section
6015 @node acc_prof_lookup
6016 @section @code{acc_prof_lookup} -- Obtain inquiry functions.
6018 @item @emph{Description}:
6019 Function to obtain inquiry functions.
6022 @multitable @columnfractions .20 .80
6023 @item @emph{Prototype}: @tab @code{acc_query_fn acc_prof_lookup (const char *);}
6026 @item @emph{See also}:
6027 @ref{OpenACC Profiling Interface}
6029 @item @emph{Reference}:
6030 @uref{https://www.openacc.org, OpenACC specification v2.6}, section
6036 @node acc_register_library
6037 @section @code{acc_register_library} -- Library registration.
6039 @item @emph{Description}:
6040 Function for library registration.
6043 @multitable @columnfractions .20 .80
6044 @item @emph{Prototype}: @tab @code{void acc_register_library (acc_prof_reg, acc_prof_reg, acc_prof_lookup_func);}
6047 @item @emph{See also}:
6048 @ref{OpenACC Profiling Interface}, @ref{ACC_PROFLIB}
6050 @item @emph{Reference}:
6051 @uref{https://www.openacc.org, OpenACC specification v2.6}, section
6057 @c ---------------------------------------------------------------------
6058 @c OpenACC Environment Variables
6059 @c ---------------------------------------------------------------------
6061 @node OpenACC Environment Variables
6062 @chapter OpenACC Environment Variables
6064 The variables @env{ACC_DEVICE_TYPE} and @env{ACC_DEVICE_NUM}
6065 are defined by section 4 of the OpenACC specification in version 2.0.
6066 The variable @env{ACC_PROFLIB}
6067 is defined by section 4 of the OpenACC specification in version 2.6.
6077 @node ACC_DEVICE_TYPE
6078 @section @code{ACC_DEVICE_TYPE}
6080 @item @emph{Description}:
6081 Control the default device type to use when executing compute regions.
6082 If unset, the code can be run on any device type, favoring a non-host
6085 Supported values in GCC (if compiled in) are
6091 @item @emph{Reference}:
6092 @uref{https://www.openacc.org, OpenACC specification v2.6}, section
6098 @node ACC_DEVICE_NUM
6099 @section @code{ACC_DEVICE_NUM}
6101 @item @emph{Description}:
6102 Control which device, identified by device number, is the default device.
6103 The value must be a nonnegative integer less than the number of devices.
6104 If unset, device number zero is used.
6105 @item @emph{Reference}:
6106 @uref{https://www.openacc.org, OpenACC specification v2.6}, section
6113 @section @code{ACC_PROFLIB}
6115 @item @emph{Description}:
6116 Semicolon-separated list of dynamic libraries that are loaded as profiling
6117 libraries. Each library must provide at least the @code{acc_register_library}
6118 routine. Each library file is found as described by the documentation of
6119 @code{dlopen} of your operating system.
6120 @item @emph{See also}:
6121 @ref{acc_register_library}, @ref{OpenACC Profiling Interface}
6123 @item @emph{Reference}:
6124 @uref{https://www.openacc.org, OpenACC specification v2.6}, section
6130 @c ---------------------------------------------------------------------
6131 @c CUDA Streams Usage
6132 @c ---------------------------------------------------------------------
6134 @node CUDA Streams Usage
6135 @chapter CUDA Streams Usage
6137 This applies to the @code{nvptx} plugin only.
6139 The library provides elements that perform asynchronous movement of
6140 data and asynchronous operation of computing constructs. This
6141 asynchronous functionality is implemented by making use of CUDA
6142 streams@footnote{See "Stream Management" in "CUDA Driver API",
6143 TRM-06703-001, Version 5.5, for additional information}.
6145 The primary means by that the asynchronous functionality is accessed
6146 is through the use of those OpenACC directives which make use of the
6147 @code{async} and @code{wait} clauses. When the @code{async} clause is
6148 first used with a directive, it creates a CUDA stream. If an
6149 @code{async-argument} is used with the @code{async} clause, then the
6150 stream is associated with the specified @code{async-argument}.
6152 Following the creation of an association between a CUDA stream and the
6153 @code{async-argument} of an @code{async} clause, both the @code{wait}
6154 clause and the @code{wait} directive can be used. When either the
6155 clause or directive is used after stream creation, it creates a
6156 rendezvous point whereby execution waits until all operations
6157 associated with the @code{async-argument}, that is, stream, have
6160 Normally, the management of the streams that are created as a result of
6161 using the @code{async} clause, is done without any intervention by the
6162 caller. This implies the association between the @code{async-argument}
6163 and the CUDA stream is maintained for the lifetime of the program.
6164 However, this association can be changed through the use of the library
6165 function @code{acc_set_cuda_stream}. When the function
6166 @code{acc_set_cuda_stream} is called, the CUDA stream that was
6167 originally associated with the @code{async} clause is destroyed.
6168 Caution should be taken when changing the association as subsequent
6169 references to the @code{async-argument} refer to a different
6174 @c ---------------------------------------------------------------------
6175 @c OpenACC Library Interoperability
6176 @c ---------------------------------------------------------------------
6178 @node OpenACC Library Interoperability
6179 @chapter OpenACC Library Interoperability
6181 @section Introduction
6183 The OpenACC library uses the CUDA Driver API, and may interact with
6184 programs that use the Runtime library directly, or another library
6185 based on the Runtime library, e.g., CUBLAS@footnote{See section 2.26,
6186 "Interactions with the CUDA Driver API" in
6187 "CUDA Runtime API", Version 5.5, and section 2.27, "VDPAU
6188 Interoperability", in "CUDA Driver API", TRM-06703-001, Version 5.5,
6189 for additional information on library interoperability.}.
6190 This chapter describes the use cases and what changes are
6191 required in order to use both the OpenACC library and the CUBLAS and Runtime
6192 libraries within a program.
6194 @section First invocation: NVIDIA CUBLAS library API
6196 In this first use case (see below), a function in the CUBLAS library is called
6197 prior to any of the functions in the OpenACC library. More specifically, the
6198 function @code{cublasCreate()}.
6200 When invoked, the function initializes the library and allocates the
6201 hardware resources on the host and the device on behalf of the caller. Once
6202 the initialization and allocation has completed, a handle is returned to the
6203 caller. The OpenACC library also requires initialization and allocation of
6204 hardware resources. Since the CUBLAS library has already allocated the
6205 hardware resources for the device, all that is left to do is to initialize
6206 the OpenACC library and acquire the hardware resources on the host.
6208 Prior to calling the OpenACC function that initializes the library and
6209 allocate the host hardware resources, you need to acquire the device number
6210 that was allocated during the call to @code{cublasCreate()}. The invoking of the
6211 runtime library function @code{cudaGetDevice()} accomplishes this. Once
6212 acquired, the device number is passed along with the device type as
6213 parameters to the OpenACC library function @code{acc_set_device_num()}.
6215 Once the call to @code{acc_set_device_num()} has completed, the OpenACC
6216 library uses the context that was created during the call to
6217 @code{cublasCreate()}. In other words, both libraries share the
6221 /* Create the handle */
6222 s = cublasCreate(&h);
6223 if (s != CUBLAS_STATUS_SUCCESS)
6225 fprintf(stderr, "cublasCreate failed %d\n", s);
6229 /* Get the device number */
6230 e = cudaGetDevice(&dev);
6231 if (e != cudaSuccess)
6233 fprintf(stderr, "cudaGetDevice failed %d\n", e);
6237 /* Initialize OpenACC library and use device 'dev' */
6238 acc_set_device_num(dev, acc_device_nvidia);
6243 @section First invocation: OpenACC library API
6245 In this second use case (see below), a function in the OpenACC library is
6246 called prior to any of the functions in the CUBLAS library. More specifically,
6247 the function @code{acc_set_device_num()}.
6249 In the use case presented here, the function @code{acc_set_device_num()}
6250 is used to both initialize the OpenACC library and allocate the hardware
6251 resources on the host and the device. In the call to the function, the
6252 call parameters specify which device to use and what device
6253 type to use, i.e., @code{acc_device_nvidia}. It should be noted that this
6254 is but one method to initialize the OpenACC library and allocate the
6255 appropriate hardware resources. Other methods are available through the
6256 use of environment variables and these is discussed in the next section.
6258 Once the call to @code{acc_set_device_num()} has completed, other OpenACC
6259 functions can be called as seen with multiple calls being made to
6260 @code{acc_copyin()}. In addition, calls can be made to functions in the
6261 CUBLAS library. In the use case a call to @code{cublasCreate()} is made
6262 subsequent to the calls to @code{acc_copyin()}.
6263 As seen in the previous use case, a call to @code{cublasCreate()}
6264 initializes the CUBLAS library and allocates the hardware resources on the
6265 host and the device. However, since the device has already been allocated,
6266 @code{cublasCreate()} only initializes the CUBLAS library and allocates
6267 the appropriate hardware resources on the host. The context that was created
6268 as part of the OpenACC initialization is shared with the CUBLAS library,
6269 similarly to the first use case.
6274 acc_set_device_num(dev, acc_device_nvidia);
6276 /* Copy the first set to the device */
6277 d_X = acc_copyin(&h_X[0], N * sizeof (float));
6280 fprintf(stderr, "copyin error h_X\n");
6284 /* Copy the second set to the device */
6285 d_Y = acc_copyin(&h_Y1[0], N * sizeof (float));
6288 fprintf(stderr, "copyin error h_Y1\n");
6292 /* Create the handle */
6293 s = cublasCreate(&h);
6294 if (s != CUBLAS_STATUS_SUCCESS)
6296 fprintf(stderr, "cublasCreate failed %d\n", s);
6300 /* Perform saxpy using CUBLAS library function */
6301 s = cublasSaxpy(h, N, &alpha, d_X, 1, d_Y, 1);
6302 if (s != CUBLAS_STATUS_SUCCESS)
6304 fprintf(stderr, "cublasSaxpy failed %d\n", s);
6308 /* Copy the results from the device */
6309 acc_memcpy_from_device(&h_Y1[0], d_Y, N * sizeof (float));
6314 @section OpenACC library and environment variables
6316 There are two environment variables associated with the OpenACC library
6317 that may be used to control the device type and device number:
6318 @env{ACC_DEVICE_TYPE} and @env{ACC_DEVICE_NUM}, respectively. These two
6319 environment variables can be used as an alternative to calling
6320 @code{acc_set_device_num()}. As seen in the second use case, the device
6321 type and device number were specified using @code{acc_set_device_num()}.
6322 If however, the aforementioned environment variables were set, then the
6323 call to @code{acc_set_device_num()} would not be required.
6326 The use of the environment variables is only relevant when an OpenACC function
6327 is called prior to a call to @code{cudaCreate()}. If @code{cudaCreate()}
6328 is called prior to a call to an OpenACC function, then you must call
6329 @code{acc_set_device_num()}@footnote{More complete information
6330 about @env{ACC_DEVICE_TYPE} and @env{ACC_DEVICE_NUM} can be found in
6331 sections 4.1 and 4.2 of the @uref{https://www.openacc.org, OpenACC}
6332 Application Programming Interface”, Version 2.6.}
6336 @c ---------------------------------------------------------------------
6337 @c OpenACC Profiling Interface
6338 @c ---------------------------------------------------------------------
6340 @node OpenACC Profiling Interface
6341 @chapter OpenACC Profiling Interface
6343 @section Implementation Status and Implementation-Defined Behavior
6345 We're implementing the OpenACC Profiling Interface as defined by the
6346 OpenACC 2.6 specification. We're clarifying some aspects here as
6347 @emph{implementation-defined behavior}, while they're still under
6348 discussion within the OpenACC Technical Committee.
6350 This implementation is tuned to keep the performance impact as low as
6351 possible for the (very common) case that the Profiling Interface is
6352 not enabled. This is relevant, as the Profiling Interface affects all
6353 the @emph{hot} code paths (in the target code, not in the offloaded
6354 code). Users of the OpenACC Profiling Interface can be expected to
6355 understand that performance is impacted to some degree once the
6356 Profiling Interface is enabled: for example, because of the
6357 @emph{runtime} (libgomp) calling into a third-party @emph{library} for
6358 every event that has been registered.
6360 We're not yet accounting for the fact that @cite{OpenACC events may
6361 occur during event processing}.
6362 We just handle one case specially, as required by CUDA 9.0
6363 @command{nvprof}, that @code{acc_get_device_type}
6364 (@ref{acc_get_device_type})) may be called from
6365 @code{acc_ev_device_init_start}, @code{acc_ev_device_init_end}
6368 We're not yet implementing initialization via a
6369 @code{acc_register_library} function that is either statically linked
6370 in, or dynamically via @env{LD_PRELOAD}.
6371 Initialization via @code{acc_register_library} functions dynamically
6372 loaded via the @env{ACC_PROFLIB} environment variable does work, as
6373 does directly calling @code{acc_prof_register},
6374 @code{acc_prof_unregister}, @code{acc_prof_lookup}.
6376 As currently there are no inquiry functions defined, calls to
6377 @code{acc_prof_lookup} always returns @code{NULL}.
6379 There aren't separate @emph{start}, @emph{stop} events defined for the
6380 event types @code{acc_ev_create}, @code{acc_ev_delete},
6381 @code{acc_ev_alloc}, @code{acc_ev_free}. It's not clear if these
6382 should be triggered before or after the actual device-specific call is
6383 made. We trigger them after.
6385 Remarks about data provided to callbacks:
6389 @item @code{acc_prof_info.event_type}
6390 It's not clear if for @emph{nested} event callbacks (for example,
6391 @code{acc_ev_enqueue_launch_start} as part of a parent compute
6392 construct), this should be set for the nested event
6393 (@code{acc_ev_enqueue_launch_start}), or if the value of the parent
6394 construct should remain (@code{acc_ev_compute_construct_start}). In
6395 this implementation, the value generally corresponds to the
6396 innermost nested event type.
6398 @item @code{acc_prof_info.device_type}
6402 For @code{acc_ev_compute_construct_start}, and in presence of an
6403 @code{if} clause with @emph{false} argument, this still refers to
6404 the offloading device type.
6405 It's not clear if that's the expected behavior.
6408 Complementary to the item before, for
6409 @code{acc_ev_compute_construct_end}, this is set to
6410 @code{acc_device_host} in presence of an @code{if} clause with
6411 @emph{false} argument.
6412 It's not clear if that's the expected behavior.
6416 @item @code{acc_prof_info.thread_id}
6417 Always @code{-1}; not yet implemented.
6419 @item @code{acc_prof_info.async}
6423 Not yet implemented correctly for
6424 @code{acc_ev_compute_construct_start}.
6427 In a compute construct, for host-fallback
6428 execution/@code{acc_device_host} it always is
6429 @code{acc_async_sync}.
6430 It is unclear if that is the expected behavior.
6433 For @code{acc_ev_device_init_start} and @code{acc_ev_device_init_end},
6434 it will always be @code{acc_async_sync}.
6435 It is unclear if that is the expected behavior.
6439 @item @code{acc_prof_info.async_queue}
6440 There is no @cite{limited number of asynchronous queues} in libgomp.
6441 This always has the same value as @code{acc_prof_info.async}.
6443 @item @code{acc_prof_info.src_file}
6444 Always @code{NULL}; not yet implemented.
6446 @item @code{acc_prof_info.func_name}
6447 Always @code{NULL}; not yet implemented.
6449 @item @code{acc_prof_info.line_no}
6450 Always @code{-1}; not yet implemented.
6452 @item @code{acc_prof_info.end_line_no}
6453 Always @code{-1}; not yet implemented.
6455 @item @code{acc_prof_info.func_line_no}
6456 Always @code{-1}; not yet implemented.
6458 @item @code{acc_prof_info.func_end_line_no}
6459 Always @code{-1}; not yet implemented.
6461 @item @code{acc_event_info.event_type}, @code{acc_event_info.*.event_type}
6462 Relating to @code{acc_prof_info.event_type} discussed above, in this
6463 implementation, this will always be the same value as
6464 @code{acc_prof_info.event_type}.
6466 @item @code{acc_event_info.*.parent_construct}
6470 Will be @code{acc_construct_parallel} for all OpenACC compute
6471 constructs as well as many OpenACC Runtime API calls; should be the
6472 one matching the actual construct, or
6473 @code{acc_construct_runtime_api}, respectively.
6476 Will be @code{acc_construct_enter_data} or
6477 @code{acc_construct_exit_data} when processing variable mappings
6478 specified in OpenACC @emph{declare} directives; should be
6479 @code{acc_construct_declare}.
6482 For implicit @code{acc_ev_device_init_start},
6483 @code{acc_ev_device_init_end}, and explicit as well as implicit
6484 @code{acc_ev_alloc}, @code{acc_ev_free},
6485 @code{acc_ev_enqueue_upload_start}, @code{acc_ev_enqueue_upload_end},
6486 @code{acc_ev_enqueue_download_start}, and
6487 @code{acc_ev_enqueue_download_end}, will be
6488 @code{acc_construct_parallel}; should reflect the real parent
6493 @item @code{acc_event_info.*.implicit}
6494 For @code{acc_ev_alloc}, @code{acc_ev_free},
6495 @code{acc_ev_enqueue_upload_start}, @code{acc_ev_enqueue_upload_end},
6496 @code{acc_ev_enqueue_download_start}, and
6497 @code{acc_ev_enqueue_download_end}, this currently will be @code{1}
6498 also for explicit usage.
6500 @item @code{acc_event_info.data_event.var_name}
6501 Always @code{NULL}; not yet implemented.
6503 @item @code{acc_event_info.data_event.host_ptr}
6504 For @code{acc_ev_alloc}, and @code{acc_ev_free}, this is always
6507 @item @code{typedef union acc_api_info}
6508 @dots{} as printed in @cite{5.2.3. Third Argument: API-Specific
6509 Information}. This should obviously be @code{typedef @emph{struct}
6512 @item @code{acc_api_info.device_api}
6513 Possibly not yet implemented correctly for
6514 @code{acc_ev_compute_construct_start},
6515 @code{acc_ev_device_init_start}, @code{acc_ev_device_init_end}:
6516 will always be @code{acc_device_api_none} for these event types.
6517 For @code{acc_ev_enter_data_start}, it will be
6518 @code{acc_device_api_none} in some cases.
6520 @item @code{acc_api_info.device_type}
6521 Always the same as @code{acc_prof_info.device_type}.
6523 @item @code{acc_api_info.vendor}
6524 Always @code{-1}; not yet implemented.
6526 @item @code{acc_api_info.device_handle}
6527 Always @code{NULL}; not yet implemented.
6529 @item @code{acc_api_info.context_handle}
6530 Always @code{NULL}; not yet implemented.
6532 @item @code{acc_api_info.async_handle}
6533 Always @code{NULL}; not yet implemented.
6537 Remarks about certain event types:
6541 @item @code{acc_ev_device_init_start}, @code{acc_ev_device_init_end}
6545 @c See 'DEVICE_INIT_INSIDE_COMPUTE_CONSTRUCT' in
6546 @c 'libgomp.oacc-c-c++-common/acc_prof-kernels-1.c',
6547 @c 'libgomp.oacc-c-c++-common/acc_prof-parallel-1.c'.
6548 When a compute construct triggers implicit
6549 @code{acc_ev_device_init_start} and @code{acc_ev_device_init_end}
6550 events, they currently aren't @emph{nested within} the corresponding
6551 @code{acc_ev_compute_construct_start} and
6552 @code{acc_ev_compute_construct_end}, but they're currently observed
6553 @emph{before} @code{acc_ev_compute_construct_start}.
6554 It's not clear what to do: the standard asks us provide a lot of
6555 details to the @code{acc_ev_compute_construct_start} callback, without
6556 (implicitly) initializing a device before?
6559 Callbacks for these event types will not be invoked for calls to the
6560 @code{acc_set_device_type} and @code{acc_set_device_num} functions.
6561 It's not clear if they should be.
6565 @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}
6569 Callbacks for these event types will also be invoked for OpenACC
6570 @emph{host_data} constructs.
6571 It's not clear if they should be.
6574 Callbacks for these event types will also be invoked when processing
6575 variable mappings specified in OpenACC @emph{declare} directives.
6576 It's not clear if they should be.
6582 Callbacks for the following event types will be invoked, but dispatch
6583 and information provided therein has not yet been thoroughly reviewed:
6586 @item @code{acc_ev_alloc}
6587 @item @code{acc_ev_free}
6588 @item @code{acc_ev_update_start}, @code{acc_ev_update_end}
6589 @item @code{acc_ev_enqueue_upload_start}, @code{acc_ev_enqueue_upload_end}
6590 @item @code{acc_ev_enqueue_download_start}, @code{acc_ev_enqueue_download_end}
6593 During device initialization, and finalization, respectively,
6594 callbacks for the following event types will not yet be invoked:
6597 @item @code{acc_ev_alloc}
6598 @item @code{acc_ev_free}
6601 Callbacks for the following event types have not yet been implemented,
6602 so currently won't be invoked:
6605 @item @code{acc_ev_device_shutdown_start}, @code{acc_ev_device_shutdown_end}
6606 @item @code{acc_ev_runtime_shutdown}
6607 @item @code{acc_ev_create}, @code{acc_ev_delete}
6608 @item @code{acc_ev_wait_start}, @code{acc_ev_wait_end}
6611 For the following runtime library functions, not all expected
6612 callbacks will be invoked (mostly concerning implicit device
6616 @item @code{acc_get_num_devices}
6617 @item @code{acc_set_device_type}
6618 @item @code{acc_get_device_type}
6619 @item @code{acc_set_device_num}
6620 @item @code{acc_get_device_num}
6621 @item @code{acc_init}
6622 @item @code{acc_shutdown}
6625 Aside from implicit device initialization, for the following runtime
6626 library functions, no callbacks will be invoked for shared-memory
6627 offloading devices (it's not clear if they should be):
6630 @item @code{acc_malloc}
6631 @item @code{acc_free}
6632 @item @code{acc_copyin}, @code{acc_present_or_copyin}, @code{acc_copyin_async}
6633 @item @code{acc_create}, @code{acc_present_or_create}, @code{acc_create_async}
6634 @item @code{acc_copyout}, @code{acc_copyout_async}, @code{acc_copyout_finalize}, @code{acc_copyout_finalize_async}
6635 @item @code{acc_delete}, @code{acc_delete_async}, @code{acc_delete_finalize}, @code{acc_delete_finalize_async}
6636 @item @code{acc_update_device}, @code{acc_update_device_async}
6637 @item @code{acc_update_self}, @code{acc_update_self_async}
6638 @item @code{acc_map_data}, @code{acc_unmap_data}
6639 @item @code{acc_memcpy_to_device}, @code{acc_memcpy_to_device_async}
6640 @item @code{acc_memcpy_from_device}, @code{acc_memcpy_from_device_async}
6643 @c ---------------------------------------------------------------------
6644 @c OpenMP-Implementation Specifics
6645 @c ---------------------------------------------------------------------
6647 @node OpenMP-Implementation Specifics
6648 @chapter OpenMP-Implementation Specifics
6651 * Implementation-defined ICV Initialization::
6652 * OpenMP Context Selectors::
6653 * Memory allocation::
6656 @node Implementation-defined ICV Initialization
6657 @section Implementation-defined ICV Initialization
6658 @cindex Implementation specific setting
6660 @multitable @columnfractions .30 .70
6661 @item @var{affinity-format-var} @tab See @ref{OMP_AFFINITY_FORMAT}.
6662 @item @var{def-allocator-var} @tab See @ref{OMP_ALLOCATOR}.
6663 @item @var{max-active-levels-var} @tab See @ref{OMP_MAX_ACTIVE_LEVELS}.
6664 @item @var{dyn-var} @tab See @ref{OMP_DYNAMIC}.
6665 @item @var{nthreads-var} @tab See @ref{OMP_NUM_THREADS}.
6666 @item @var{num-devices-var} @tab Number of non-host devices found
6667 by GCC's run-time library
6668 @item @var{num-procs-var} @tab The number of CPU cores on the
6669 initial device, except that affinity settings might lead to a
6670 smaller number. On non-host devices, the value of the
6671 @var{nthreads-var} ICV.
6672 @item @var{place-partition-var} @tab See @ref{OMP_PLACES}.
6673 @item @var{run-sched-var} @tab See @ref{OMP_SCHEDULE}.
6674 @item @var{stacksize-var} @tab See @ref{OMP_STACKSIZE}.
6675 @item @var{thread-limit-var} @tab See @ref{OMP_TEAMS_THREAD_LIMIT}
6676 @item @var{wait-policy-var} @tab See @ref{OMP_WAIT_POLICY} and
6677 @ref{GOMP_SPINCOUNT}
6680 @node OpenMP Context Selectors
6681 @section OpenMP Context Selectors
6683 @code{vendor} is always @code{gnu}. References are to the GCC manual.
6685 @c NOTE: Only the following selectors have been implemented. To add
6686 @c additional traits for target architecture, TARGET_OMP_DEVICE_KIND_ARCH_ISA
6687 @c has to be implemented; cf. also PR target/105640.
6688 @c For offload devices, add *additionally* gcc/config/*/t-omp-device.
6690 For the host compiler, @code{kind} always matches @code{host}; for the
6691 offloading architectures AMD GCN and Nvidia PTX, @code{kind} always matches
6692 @code{gpu}. For the x86 family of computers, AMD GCN and Nvidia PTX
6693 the following traits are supported in addition; while OpenMP is supported
6694 on more architectures, GCC currently does not match any @code{arch} or
6695 @code{isa} traits for those.
6697 @multitable @columnfractions .65 .30
6698 @headitem @code{arch} @tab @code{isa}
6699 @item @code{x86}, @code{x86_64}, @code{i386}, @code{i486},
6700 @code{i586}, @code{i686}, @code{ia32}
6701 @tab See @code{-m...} flags in ``x86 Options'' (without @code{-m})
6702 @item @code{amdgcn}, @code{gcn}
6703 @tab See @code{-march=} in ``AMD GCN Options''
6704 @item @code{nvptx}, @code{nvptx64}
6705 @tab See @code{-march=} in ``Nvidia PTX Options''
6708 @node Memory allocation
6709 @section Memory allocation
6711 The description below applies to:
6714 @item Explicit use of the OpenMP API routines, see
6715 @ref{Memory Management Routines}.
6716 @item The @code{allocate} clause, except when the @code{allocator} modifier is a
6717 constant expression with value @code{omp_default_mem_alloc} and no
6718 @code{align} modifier has been specified. (In that case, the normal
6719 @code{malloc} allocation is used.)
6720 @item The @code{allocate} directive for variables in static memory; while
6721 the alignment is honored, the normal static memory is used.
6722 @item Using the @code{allocate} directive for automatic/stack variables, except
6723 when the @code{allocator} clause is a constant expression with value
6724 @code{omp_default_mem_alloc} and no @code{align} clause has been
6725 specified. (In that case, the normal allocation is used: stack allocation
6726 and, sometimes for Fortran, also @code{malloc} [depending on flags such as
6727 @option{-fstack-arrays}].)
6728 @item In Fortran, the @code{allocators} directive and the executable
6729 @code{allocate} directive for Fortran pointers and allocatables is
6730 supported, but requires that files containing those directives has to be
6731 compiled with @option{-fopenmp-allocators}. Additionally, all files that
6732 might explicitly or implicitly deallocate memory allocated that way must
6733 also be compiled with that option.
6736 For the available predefined allocators and, as applicable, their associated
6737 predefined memory spaces and for the available traits and their default values,
6738 see @ref{OMP_ALLOCATOR}. Predefined allocators without an associated memory
6739 space use the @code{omp_default_mem_space} memory space. See additionally
6740 @ref{Offload-Target Specifics}.
6742 For the memory spaces, the following applies:
6744 @item @code{omp_default_mem_space} is supported
6745 @item @code{omp_const_mem_space} maps to @code{omp_default_mem_space}
6746 @item @code{omp_low_lat_mem_space} is only available on supported devices,
6747 and maps to @code{omp_default_mem_space} otherwise.
6748 @item @code{omp_large_cap_mem_space} maps to @code{omp_default_mem_space},
6749 unless the memkind library is available
6750 @item @code{omp_high_bw_mem_space} maps to @code{omp_default_mem_space},
6751 unless the memkind library is available
6754 On Linux systems, where the @uref{https://github.com/memkind/memkind, memkind
6755 library} (@code{libmemkind.so.0}) is available at runtime, it is used when
6756 creating memory allocators requesting
6759 @item the memory space @code{omp_high_bw_mem_space}
6760 @item the memory space @code{omp_large_cap_mem_space}
6761 @item the @code{partition} trait @code{interleaved}; note that for
6762 @code{omp_large_cap_mem_space} the allocation will not be interleaved
6765 On Linux systems, where the @uref{https://github.com/numactl/numactl, numa
6766 library} (@code{libnuma.so.1}) is available at runtime, it used when creating
6767 memory allocators requesting
6770 @item the @code{partition} trait @code{nearest}, except when both the
6771 libmemkind library is available and the memory space is either
6772 @code{omp_large_cap_mem_space} or @code{omp_high_bw_mem_space}
6775 Note that the numa library will round up the allocation size to a multiple of
6776 the system page size; therefore, consider using it only with large data or
6777 by sharing allocations via the @code{pool_size} trait. Furthermore, the Linux
6778 kernel does not guarantee that an allocation will always be on the nearest NUMA
6779 node nor that after reallocation the same node will be used. Note additionally
6780 that, on Linux, the default setting of the memory placement policy is to use the
6781 current node; therefore, unless the memory placement policy has been overridden,
6782 the @code{partition} trait @code{environment} (the default) will be effectively
6783 a @code{nearest} allocation.
6785 Additional notes regarding the traits:
6787 @item The @code{pinned} trait is supported on Linux hosts, but is subject to
6788 the OS @code{ulimit}/@code{rlimit} locked memory settings.
6789 @item The default for the @code{pool_size} trait is no pool and for every
6790 (re)allocation the associated library routine is called, which might
6791 internally use a memory pool.
6792 @item For the @code{partition} trait, the partition part size will be the same
6793 as the requested size (i.e. @code{interleaved} or @code{blocked} has no
6794 effect), except for @code{interleaved} when the memkind library is
6795 available. Furthermore, for @code{nearest} and unless the numa library
6796 is available, the memory might not be on the same NUMA node as thread
6797 that allocated the memory; on Linux, this is in particular the case when
6798 the memory placement policy is set to preferred.
6799 @item The @code{access} trait has no effect such that memory is always
6800 accessible by all threads.
6801 @item The @code{sync_hint} trait has no effect.
6805 @ref{Offload-Target Specifics}
6807 @c ---------------------------------------------------------------------
6808 @c Offload-Target Specifics
6809 @c ---------------------------------------------------------------------
6811 @node Offload-Target Specifics
6812 @chapter Offload-Target Specifics
6814 The following sections present notes on the offload-target specifics
6822 @section AMD Radeon (GCN)
6824 On the hardware side, there is the hierarchy (fine to coarse):
6826 @item work item (thread)
6829 @item compute unit (CU)
6832 All OpenMP and OpenACC levels are used, i.e.
6834 @item OpenMP's simd and OpenACC's vector map to work items (thread)
6835 @item OpenMP's threads (``parallel'') and OpenACC's workers map
6837 @item OpenMP's teams and OpenACC's gang use a threadpool with the
6838 size of the number of teams or gangs, respectively.
6843 @item Number of teams is the specified @code{num_teams} (OpenMP) or
6844 @code{num_gangs} (OpenACC) or otherwise the number of CU. It is limited
6845 by two times the number of CU.
6846 @item Number of wavefronts is 4 for gfx900 and 16 otherwise;
6847 @code{num_threads} (OpenMP) and @code{num_workers} (OpenACC)
6848 overrides this if smaller.
6849 @item The wavefront has 102 scalars and 64 vectors
6850 @item Number of workitems is always 64
6851 @item The hardware permits maximally 40 workgroups/CU and
6852 16 wavefronts/workgroup up to a limit of 40 wavefronts in total per CU.
6853 @item 80 scalars registers and 24 vector registers in non-kernel functions
6854 (the chosen procedure-calling API).
6855 @item For the kernel itself: as many as register pressure demands (number of
6856 teams and number of threads, scaled down if registers are exhausted)
6859 The implementation remark:
6861 @item I/O within OpenMP target regions and OpenACC compute regions is supported
6862 using the C library @code{printf} functions and the Fortran
6863 @code{print}/@code{write} statements.
6864 @item Reverse offload regions (i.e. @code{target} regions with
6865 @code{device(ancestor:1)}) are processed serially per @code{target} region
6866 such that the next reverse offload region is only executed after the previous
6868 @item OpenMP code that has a @code{requires} directive with
6869 @code{unified_shared_memory} is only supported if all AMD GPUs have the
6870 @code{HSA_AMD_SYSTEM_INFO_SVM_ACCESSIBLE_BY_DEFAULT} property; for
6871 discrete GPUs, this may require setting the @code{HSA_XNACK} environment
6872 variable to @samp{1}; for systems with both an APU and a discrete GPU that
6873 does not support XNACK, consider using @code{ROCR_VISIBLE_DEVICES} to
6874 enable only the APU. If not supported, all AMD GPU devices are removed
6875 from the list of available devices (``host fallback'').
6876 @item The available stack size can be changed using the @code{GCN_STACK_SIZE}
6877 environment variable; the default is 32 kiB per thread.
6878 @item Low-latency memory (@code{omp_low_lat_mem_space}) is supported when the
6879 the @code{access} trait is set to @code{cgroup}. The default pool size
6880 is automatically scaled to share the 64 kiB LDS memory between the number
6881 of teams configured to run on each compute-unit, but may be adjusted at
6882 runtime by setting environment variable
6883 @code{GOMP_GCN_LOWLAT_POOL=@var{bytes}}.
6884 @item @code{omp_low_lat_mem_alloc} cannot be used with true low-latency memory
6885 because the definition implies the @code{omp_atv_all} trait; main
6886 graphics memory is used instead.
6887 @item @code{omp_cgroup_mem_alloc}, @code{omp_pteam_mem_alloc}, and
6888 @code{omp_thread_mem_alloc}, all use low-latency memory as first
6889 preference, and fall back to main graphics memory when the low-latency
6891 @item The unique identifier (UID), used with OpenMP's API UID routines, is the
6892 value returned by the HSA runtime library for @code{HSA_AMD_AGENT_INFO_UUID}.
6893 For GPUs, it is currently @samp{GPU-} followed by 16 lower-case hex digits,
6894 yielding a string like @code{GPU-f914a2142fc3413a}. The output matches
6895 the one used by @code{rocminfo}.
6903 On the hardware side, there is the hierarchy (fine to coarse):
6908 @item streaming multiprocessor
6911 All OpenMP and OpenACC levels are used, i.e.
6913 @item OpenMP's simd and OpenACC's vector map to threads
6914 @item OpenMP's threads (``parallel'') and OpenACC's workers map to warps
6915 @item OpenMP's teams and OpenACC's gang use a threadpool with the
6916 size of the number of teams or gangs, respectively.
6921 @item The @code{warp_size} is always 32
6922 @item CUDA kernel launched: @code{dim=@{#teams,1,1@}, blocks=@{#threads,warp_size,1@}}.
6923 @item The number of teams is limited by the number of blocks the device can
6924 host simultaneously.
6927 Additional information can be obtained by setting the environment variable to
6928 @code{GOMP_DEBUG=1} (very verbose; grep for @code{kernel.*launch} for launch
6931 GCC generates generic PTX ISA code, which is just-in-time compiled by CUDA,
6932 which caches the JIT in the user's directory (see CUDA documentation; can be
6933 tuned by the environment variables @code{CUDA_CACHE_@{DISABLE,MAXSIZE,PATH@}}.
6935 Note: While PTX ISA is generic, the @code{-mptx=} and @code{-march=} commandline
6936 options still affect the used PTX ISA code and, thus, the requirements on
6937 CUDA version and hardware.
6939 The implementation remark:
6941 @item I/O within OpenMP target regions and OpenACC compute regions is supported
6942 using the C library @code{printf} functions.
6943 Additionally, the Fortran @code{print}/@code{write} statements are
6944 supported within OpenMP target regions, but not yet within OpenACC compute
6945 regions. @c The latter needs 'GOMP_NVPTX_NATIVE_GPU_THREAD_STACK_SIZE'.
6946 @item Compilation OpenMP code that contains @code{requires reverse_offload}
6947 requires at least @code{-march=sm_35}, compiling for @code{-march=sm_30}
6949 @item For code containing reverse offload (i.e. @code{target} regions with
6950 @code{device(ancestor:1)}), there is a slight performance penalty
6951 for @emph{all} target regions, consisting mostly of shutdown delay
6952 Per device, reverse offload regions are processed serially such that
6953 the next reverse offload region is only executed after the previous
6955 @item OpenMP code that has a @code{requires} directive with
6956 @code{unified_shared_memory} runs on nvptx devices if and only if
6957 all of those support the @code{pageableMemoryAccess} property;@footnote{
6958 @uref{https://docs.nvidia.com/cuda/cuda-c-programming-guide/index.html#um-requirements}}
6959 otherwise, all nvptx device are removed from the list of available
6960 devices (``host fallback'').
6961 @item The default per-warp stack size is 128 kiB; see also @code{-msoft-stack}
6963 @item The OpenMP routines @code{omp_target_memcpy_rect} and
6964 @code{omp_target_memcpy_rect_async} and the @code{target update}
6965 directive for non-contiguous list items will use the 2D and 3D
6966 memory-copy functions of the CUDA library. Higher dimensions will
6967 call those functions in a loop and are therefore supported.
6968 @item Low-latency memory (@code{omp_low_lat_mem_space}) is supported when the
6969 the @code{access} trait is set to @code{cgroup}, the ISA is at least
6970 @code{sm_53}, and the PTX version is at least 4.1. The default pool size
6971 is 8 kiB per team, but may be adjusted at runtime by setting environment
6972 variable @code{GOMP_NVPTX_LOWLAT_POOL=@var{bytes}}. The maximum value is
6973 limited by the available hardware, and care should be taken that the
6974 selected pool size does not unduly limit the number of teams that can
6976 @item @code{omp_low_lat_mem_alloc} cannot be used with true low-latency memory
6977 because the definition implies the @code{omp_atv_all} trait; main
6978 graphics memory is used instead.
6979 @item @code{omp_cgroup_mem_alloc}, @code{omp_pteam_mem_alloc}, and
6980 @code{omp_thread_mem_alloc}, all use low-latency memory as first
6981 preference, and fall back to main graphics memory when the low-latency
6983 @item The unique identifier (UID), used with OpenMP's API UID routines, consists
6984 of the @samp{GPU-} prefix followed by the 16-bytes UUID as returned by
6985 the CUDA runtime library. This UUID is output in grouped lower-case
6986 hex digits; the grouping of those 32 digits is: 8 digits, hyphen,
6987 4 digits, hyphen, 4 digits, hyphen, 16 digits. This leads to a string
6988 like @code{GPU-a8081c9e-f03e-18eb-1827-bf5ba95afa5d}. The output
6989 matches the format used by @code{nvidia-smi}.
6993 @c ---------------------------------------------------------------------
6995 @c ---------------------------------------------------------------------
6997 @node The libgomp ABI
6998 @chapter The libgomp ABI
7000 The following sections present notes on the external ABI as
7001 presented by libgomp. Only maintainers should need them.
7004 * Implementing MASTER construct::
7005 * Implementing CRITICAL construct::
7006 * Implementing ATOMIC construct::
7007 * Implementing FLUSH construct::
7008 * Implementing BARRIER construct::
7009 * Implementing THREADPRIVATE construct::
7010 * Implementing PRIVATE clause::
7011 * Implementing FIRSTPRIVATE LASTPRIVATE COPYIN and COPYPRIVATE clauses::
7012 * Implementing REDUCTION clause::
7013 * Implementing PARALLEL construct::
7014 * Implementing FOR construct::
7015 * Implementing ORDERED construct::
7016 * Implementing SECTIONS construct::
7017 * Implementing SINGLE construct::
7018 * Implementing OpenACC's PARALLEL construct::
7022 @node Implementing MASTER construct
7023 @section Implementing MASTER construct
7026 if (omp_get_thread_num () == 0)
7030 Alternately, we generate two copies of the parallel subfunction
7031 and only include this in the version run by the primary thread.
7032 Surely this is not worthwhile though...
7036 @node Implementing CRITICAL construct
7037 @section Implementing CRITICAL construct
7039 Without a specified name,
7042 void GOMP_critical_start (void);
7043 void GOMP_critical_end (void);
7046 so that we don't get COPY relocations from libgomp to the main
7049 With a specified name, use omp_set_lock and omp_unset_lock with
7050 name being transformed into a variable declared like
7053 omp_lock_t gomp_critical_user_<name> __attribute__((common))
7056 Ideally the ABI would specify that all zero is a valid unlocked
7057 state, and so we wouldn't need to initialize this at
7062 @node Implementing ATOMIC construct
7063 @section Implementing ATOMIC construct
7065 The target should implement the @code{__sync} builtins.
7067 Failing that we could add
7070 void GOMP_atomic_enter (void)
7071 void GOMP_atomic_exit (void)
7074 which reuses the regular lock code, but with yet another lock
7075 object private to the library.
7079 @node Implementing FLUSH construct
7080 @section Implementing FLUSH construct
7082 Expands to the @code{__sync_synchronize} builtin.
7086 @node Implementing BARRIER construct
7087 @section Implementing BARRIER construct
7090 void GOMP_barrier (void)
7094 @node Implementing THREADPRIVATE construct
7095 @section Implementing THREADPRIVATE construct
7097 In _most_ cases we can map this directly to @code{__thread}. Except
7098 that OMP allows constructors for C++ objects. We can either
7099 refuse to support this (how often is it used?) or we can
7100 implement something akin to .ctors.
7102 Even more ideally, this ctor feature is handled by extensions
7103 to the main pthreads library. Failing that, we can have a set
7104 of entry points to register ctor functions to be called.
7108 @node Implementing PRIVATE clause
7109 @section Implementing PRIVATE clause
7111 In association with a PARALLEL, or within the lexical extent
7112 of a PARALLEL block, the variable becomes a local variable in
7113 the parallel subfunction.
7115 In association with FOR or SECTIONS blocks, create a new
7116 automatic variable within the current function. This preserves
7117 the semantic of new variable creation.
7121 @node Implementing FIRSTPRIVATE LASTPRIVATE COPYIN and COPYPRIVATE clauses
7122 @section Implementing FIRSTPRIVATE LASTPRIVATE COPYIN and COPYPRIVATE clauses
7124 This seems simple enough for PARALLEL blocks. Create a private
7125 struct for communicating between the parent and subfunction.
7126 In the parent, copy in values for scalar and "small" structs;
7127 copy in addresses for others TREE_ADDRESSABLE types. In the
7128 subfunction, copy the value into the local variable.
7130 It is not clear what to do with bare FOR or SECTION blocks.
7131 The only thing I can figure is that we do something like:
7134 #pragma omp for firstprivate(x) lastprivate(y)
7135 for (int i = 0; i < n; ++i)
7152 where the "x=x" and "y=y" assignments actually have different
7153 uids for the two variables, i.e. not something you could write
7154 directly in C. Presumably this only makes sense if the "outer"
7155 x and y are global variables.
7157 COPYPRIVATE would work the same way, except the structure
7158 broadcast would have to happen via SINGLE machinery instead.
7162 @node Implementing REDUCTION clause
7163 @section Implementing REDUCTION clause
7165 The private struct mentioned in the previous section should have
7166 a pointer to an array of the type of the variable, indexed by the
7167 thread's @var{team_id}. The thread stores its final value into the
7168 array, and after the barrier, the primary thread iterates over the
7169 array to collect the values.
7172 @node Implementing PARALLEL construct
7173 @section Implementing PARALLEL construct
7176 #pragma omp parallel
7185 void subfunction (void *data)
7192 GOMP_parallel_start (subfunction, &data, num_threads);
7193 subfunction (&data);
7194 GOMP_parallel_end ();
7198 void GOMP_parallel_start (void (*fn)(void *), void *data, unsigned num_threads)
7201 The @var{FN} argument is the subfunction to be run in parallel.
7203 The @var{DATA} argument is a pointer to a structure used to
7204 communicate data in and out of the subfunction, as discussed
7205 above with respect to FIRSTPRIVATE et al.
7207 The @var{NUM_THREADS} argument is 1 if an IF clause is present
7208 and false, or the value of the NUM_THREADS clause, if
7211 The function needs to create the appropriate number of
7212 threads and/or launch them from the dock. It needs to
7213 create the team structure and assign team ids.
7216 void GOMP_parallel_end (void)
7219 Tears down the team and returns us to the previous @code{omp_in_parallel()} state.
7223 @node Implementing FOR construct
7224 @section Implementing FOR construct
7227 #pragma omp parallel for
7228 for (i = lb; i <= ub; i++)
7235 void subfunction (void *data)
7238 while (GOMP_loop_static_next (&_s0, &_e0))
7241 for (i = _s0; i < _e1; i++)
7244 GOMP_loop_end_nowait ();
7247 GOMP_parallel_loop_static (subfunction, NULL, 0, lb, ub+1, 1, 0);
7249 GOMP_parallel_end ();
7253 #pragma omp for schedule(runtime)
7254 for (i = 0; i < n; i++)
7263 if (GOMP_loop_runtime_start (0, n, 1, &_s0, &_e0))
7266 for (i = _s0, i < _e0; i++)
7268 @} while (GOMP_loop_runtime_next (&_s0, _&e0));
7273 Note that while it looks like there is trickiness to propagating
7274 a non-constant STEP, there isn't really. We're explicitly allowed
7275 to evaluate it as many times as we want, and any variables involved
7276 should automatically be handled as PRIVATE or SHARED like any other
7277 variables. So the expression should remain evaluable in the
7278 subfunction. We can also pull it into a local variable if we like,
7279 but since its supposed to remain unchanged, we can also not if we like.
7281 If we have SCHEDULE(STATIC), and no ORDERED, then we ought to be
7282 able to get away with no work-sharing context at all, since we can
7283 simply perform the arithmetic directly in each thread to divide up
7284 the iterations. Which would mean that we wouldn't need to call any
7287 There are separate routines for handling loops with an ORDERED
7288 clause. Bookkeeping for that is non-trivial...
7292 @node Implementing ORDERED construct
7293 @section Implementing ORDERED construct
7296 void GOMP_ordered_start (void)
7297 void GOMP_ordered_end (void)
7302 @node Implementing SECTIONS construct
7303 @section Implementing SECTIONS construct
7308 #pragma omp sections
7322 for (i = GOMP_sections_start (3); i != 0; i = GOMP_sections_next ())
7339 @node Implementing SINGLE construct
7340 @section Implementing SINGLE construct
7354 if (GOMP_single_start ())
7362 #pragma omp single copyprivate(x)
7369 datap = GOMP_single_copy_start ();
7374 GOMP_single_copy_end (&data);
7383 @node Implementing OpenACC's PARALLEL construct
7384 @section Implementing OpenACC's PARALLEL construct
7387 void GOACC_parallel ()
7392 @c ---------------------------------------------------------------------
7394 @c ---------------------------------------------------------------------
7396 @node Reporting Bugs
7397 @chapter Reporting Bugs
7399 Bugs in the GNU Offloading and Multi Processing Runtime Library should
7400 be reported via @uref{https://gcc.gnu.org/bugzilla/, Bugzilla}. Please add
7401 "openacc", or "openmp", or both to the keywords field in the bug
7402 report, as appropriate.
7406 @c ---------------------------------------------------------------------
7407 @c GNU General Public License
7408 @c ---------------------------------------------------------------------
7410 @include gpl_v3.texi
7414 @c ---------------------------------------------------------------------
7415 @c GNU Free Documentation License
7416 @c ---------------------------------------------------------------------
7422 @c ---------------------------------------------------------------------
7423 @c Funding Free Software
7424 @c ---------------------------------------------------------------------
7426 @include funding.texi
7428 @c ---------------------------------------------------------------------
7430 @c ---------------------------------------------------------------------
7433 @unnumbered Library Index