libstdc++: Fix rounding in chrono::parse
[official-gcc.git] / libgomp / libgomp.texi
blobc6464ece32e3faba100dee9682e8a3611e74c62a
1 \input texinfo @c -*-texinfo-*-
3 @c %**start of header
4 @setfilename libgomp.info
5 @settitle GNU libgomp
6 @c %**end of header
9 @copying
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:
22      A GNU Manual
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.
29 @end copying
31 @ifinfo
32 @dircategory GNU Libraries
33 @direntry
34 * libgomp: (libgomp).          GNU Offloading and Multi Processing Runtime Library.
35 @end direntry
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
40 Fortran.
42 Published by the Free Software Foundation
43 51 Franklin Street, Fifth Floor
44 Boston, MA 02110-1301 USA
46 @insertcopying
47 @end ifinfo
50 @setchapternewpage odd
52 @titlepage
53 @title GNU Offloading and Multi Processing Runtime Library
54 @subtitle The GNU OpenMP and OpenACC Implementation
55 @page
56 @vskip 0pt plus 1filll
57 @comment For the @value{version-GCC} Version*
58 @sp 1
59 Published by the Free Software Foundation @*
60 51 Franklin Street, Fifth Floor@*
61 Boston, MA 02110-1301, USA@*
62 @sp 1
63 @insertcopying
64 @end titlepage
66 @summarycontents
67 @contents
68 @page
71 @node Top, Enabling OpenMP
72 @top Introduction
73 @cindex Introduction
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++
82 and Fortran.
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.
91 @comment
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.
95 @comment
96 @menu
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
101                                interface.
102 * OpenMP Environment Variables: Environment Variables.
103                                Influencing OpenMP runtime behavior with
104                                environment variables.
105 * Enabling OpenACC::           How to enable OpenACC for your
106                                applications.
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
117                                implementation
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 
127                                software.
128 * Library Index::              Index of this documentation.
129 @end menu
132 @c ---------------------------------------------------------------------
133 @c Enabling OpenMP
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
167 @menu
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 Technical Report 13:: Feature completion status to third 6.0 preview
173 @end menu
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).
179 @node OpenMP 4.5
180 @section OpenMP 4.5
182 The OpenMP 4.5 specification is fully supported.
184 @node OpenMP 5.0
185 @section OpenMP 5.0
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
229       @tab Y @tab
230 @item @code{mutexinoutset} @emph{dependence-type} for @code{depend} clause
231       @tab Y @tab
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 Only C for stack/automatic and Fortran for stack/automatic
237       and allocatable/pointer variables
238 @item @code{allocate} clause @tab P @tab Initial support
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
243       @tab N @tab
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
251       @tab Y @tab
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
269       routines @tab Y @tab
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
273 @end multitable
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
280 @end multitable
283 @node OpenMP 5.1
284 @section OpenMP 5.1
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 (and not for static variables)
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}
314       clauses @tab N @tab
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
328       routines @tab Y @tab
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
349 @end multitable
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}
358       clause @tab Y @tab
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}
368       clauses @tab Y @tab
369 @end multitable
372 @node OpenMP 5.2
373 @section OpenMP 5.2
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
380       @tab Y @tab
381 @item @code{omp}/@code{ompx}/@code{omx} sentinels and @code{omp_}/@code{ompx_}
382       namespaces @tab N/A
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}
392       @tab Y @tab
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
399       @tab N @tab
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
403       @tab Y @tab
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
406       @tab Y @tab
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}
412       @tab N @tab
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
416       @tab N @tab
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}
421       @tab Y @tab
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}
424       @tab Y @tab
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
428       @tab N @tab
429 @item @code{omp_cur_iteration} keyword @tab Y @tab
430 @end multitable
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{iterator} and @code{mapper} as map-type modifier in @code{declare mapper}
447       @tab N @tab
448 @end multitable
451 @node OpenMP Technical Report 13
452 @section OpenMP Technical Report 13
454 Technical Report (TR) 13 is the third preview for OpenMP 6.0.
456 @unnumberedsubsec New features listed in Appendix B of the OpenMP specification
457 @multitable @columnfractions .60 .10 .25
458 @item Features deprecated in versions 5.0, 5.1 and 5.2 were removed
459       @tab N/A @tab Backward compatibility
460 @item Full support for C23 was added @tab P @tab
461 @item Full support for C++23 was added @tab P @tab
462 @item Full support for Fortran 2023 was added @tab P @tab
463 @item @code{_ALL} suffix to the device-scope environment variables
464       @tab P @tab Host device number wrongly accepted
465 @item @code{num_threads} now accepts a list @tab N @tab
466 @item Abstract names added for @code{OMP_NUM_THREADS},
467       @code{OMP_THREAD_LIMIT} and @code{OMP_TEAMS_THREAD_LIMIT}
468       @tab N @tab
469 @item Supporting increments with abstract names in @code{OMP_PLACES} @tab N @tab
470 @item Extension of @code{OMP_DEFAULT_DEVICE} and new
471       @code{OMP_AVAILABLE_DEVICES} environment vars @tab N @tab
472 @item New @code{OMP_THREADS_RESERVE} environment variable @tab N @tab
473 @item The @code{decl} attribute was added to the C++ attribute syntax
474       @tab Y @tab
475 @item The OpenMP directive syntax was extended to include C 23 attribute
476       specifiers @tab Y @tab
477 @item Support for pure directives in Fortran's @code{do concurrent} @tab N @tab
478 @item All inarguable clauses take now an optional Boolean argument @tab N @tab
479 @item The @code{adjust_args} clause was extended to specify the argument by position
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++
483       @tab N @tab
484 @item @emph{directive-name-modifier} accepted in all clauses @tab N @tab
485 @item Argument-free version of @code{depobj} including added @code{init} clause
486       @tab N @tab
487 @item Undeprecate omitting the argument to the @code{depend} clause of
488       the argument version of the @code{depend} construct @tab Y @tab
489 @item For Fortran, atomic with BLOCK construct and, for C/C++, with
490       unlimited curly braces supported @tab N @tab
491 @item For Fortran, atomic with pointer comparison @tab N @tab
492 @item For Fortran, atomic with enum and enumeration types @tab N @tab
493 @item For Fortran, atomic compare with storing the comparison result
494       @tab N @tab
495 @item New @code{looprange} clause @tab N @tab
496 @item For Fortran, handling polymorphic types in data-sharing-attribute
497       clauses @tab P @tab @code{private} not supported
498 @item For Fortran, rejecting polymorphic types in data-mapping clauses
499       @tab N @tab not diagnosed (and mostly unsupported)
500 @item New @code{taskgraph} construct including @code{saved} modifier and
501       @code{replayable} clause @tab N @tab
502 @item @code{default} clause on the @code{target} directive @tab N @tab
503 @item Ref-count change for @code{use_device_ptr} and @code{use_device_addr}
504       @tab N @tab
505 @item Support for inductions @tab N @tab
506 @item Deprecation of the combiner expression in the @code{declare_reduction}
507       argument @tab N @tab
508 @item Implicit reduction identifiers of C++ classes
509       @tab N @tab
510 @item New @code{init_complete} clause to the @code{scan} directive
511       @tab N @tab
512 @item @code{ref} modifier to the @code{map} clause @tab N @tab
513 @item New @code{storage} map-type modifier; context-dependent @code{alloc} and
514       @code{release} are aliases @tab N @tab
515 @item Update of the map-type decay for mapping and @code{declare_mapper}
516       @tab N @tab
517 @item Change of the @emph{map-type} property from @emph{ultimate} to
518       @emph{default} @tab N @tab
519 @item @code{self} modifier to @code{map} and @code{self} as
520       @code{defaultmap} argument @tab N @tab
521 @item Mapping of @emph{assumed-size arrays} in C, C++ and Fortran
522       @tab N @tab
523 @item @code{delete} as delete-modifier not as map type @tab N @tab
524 @item For Fortran, the @code{automap} modifier to the @code{enter} clause
525       of @code{declare_target} @tab N @tab
526 @item @code{groupprivate} directive @tab N @tab
527 @item @code{local} clause to @code{declare target} directive @tab N @tab
528 @item @code{part_size} allocator trait @tab N @tab
529 @item @code{pin_device}, @code{preferred_device} and @code{target_access}
530       allocator traits
531       @tab N @tab
532 @item @code{access} allocator trait changes @tab N @tab
533 @item New @code{partitioner} value to @code{partition} allocator trait
534       @tab N @tab
535 @item Semicolon-separated list to @code{uses_allocators} @tab N @tab
536 @item New @code{uid} trait for target devices and for
537       @code{OMP_AVAILABLE_DEVICES} and @code{OMP_DEFAULT_DEVICE} @tab N @tab
538 @item Extension of @code{interop} operation of @code{append_args}, allowing
539       all modifiers of the @code{init} clause @tab N @tab
540 @item For @code{adjust_args}, new @code{need_device_addr} clause and
541       handling variadic arguments @tab N @tab
542 @item @code{interop} clause to @code{dispatch} @tab N @tab
543 @item Scope requirement changes for @code{declare_target} @tab N @tab
544 @item @code{message} and @code{severity} clauses to @code{parallel} directive
545       @tab N @tab
546 @item @code{self_maps} clause to @code{requires} directive @tab Y @tab
547 @item @code{no_openmp_constructs} assumptions clause @tab N @tab
548 @item Restriction for @code{ordered} regarding loop-transforming directives
549       @tab N @tab
550 @item @code{apply} code to loop-transforming constructs @tab N @tab
551 @item Non-constant values in the @code{sizes} clause @tab N @tab
552 @item @code{fuse} loop-transformation construct @tab N @tab
553 @item @code{interchange} loop-transformation construct @tab N @tab
554 @item @code{reverse} loop-transformation construct @tab N @tab
555 @item @code{split} loop-transformation construct @tab N @tab
556 @item @code{stipe} loop-transformation construct @tab N @tab
557 @item @code{tile} permitting association of grid and inter-tile loops @tab N @tab
558 @item @code{strict} modifier keyword to @code{num_threads} @tab N @tab
559 @item @code{safesync} clause to the @code{parallel} construct @tab N @tab
560 @item @code{omp_curr_progress_width} identifier @tab N @tab
561 @item @code{omp_get_max_progress_width} runtime routine @tab N @tab
562 @item Lifted restrictions on @code{order(concurrent)} and, hence, the
563       @code{loop} construct @tab N @tab
564 @item @code{atomic} permitted in a construct with @code{order(concurrent)}
565       @tab N @tab
566 @item @code{workdistribute} directive for Fortran @tab N @tab
567 @item Fortran DO CONCURRENT as associated loop in a @code{loop} construct
568       @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{ŧarget_exit_data} and @code{target_update}
572       @tab N @tab
573 @item New @code{device_type} clause to the @code{target} directive.
574       @tab N @tab
575 @item @code{target_data} as composite construct @tab N @tab
576 @item @code{nowait} clause with reverse-offload @code{target} directives
577       @tab N @tab
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
580       @tab N @tab
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
583       @tab N @tab
584 @item Added rule for compound-directive names, permitting many more combinations
585       @tab N @tab
586 @item @code{omp_is_free_agent} and @code{omp_ancestor_is_free_agent} routines
587       @tab N @tab
588 @item @code{omp_get_device_from_uid} and @code{omp_get_uid_from_device} routines
589       @tab Y @tab
590 @item @code{omp_get_device_num_teams}, @code{omp_set_device_num_teams},
591       @code{omp_get_device_teams_thread_limit}, and
592       @code{omp_set_device_teams_thread_limit} routines @tab N @tab
593 @item @code{omp_target_memset} and @code{omp_target_memset_rect_async} routines
594       @tab N @tab
595 @item Fortran version of the interop runtime routines @tab N @tab
596 @item Routines for obtaining memory spaces/allocators for shared/device memory
597       @tab N @tab
598 @item @code{omp_get_memspace_num_resources} routine @tab N @tab
599 @item @code{omp_get_submemspace} routine @tab N @tab
600 @item @code{omp_get_memspace_pagesize} routine @tab N @tab
601 @item @code{omp_init_mempartitioner}, @code{omp_destroy_mempartitioner},
602       @code{omp_init_mempartition}, @code{omp_destroy_mempartition},
603       @code{omp_mempartition_set_part}, @code{omp_mempartition_get_user_data}
604       routines @tab N @tab
605 @item Deprecation of the @code{target_data_op}, @code{target},
606       @code{target_map} and @code{target_submit} callbacks and as values that
607       @code{set_callback} must return @tab N @tab
608 @item @code{ompt_target_data_transfer} and @code{ompt_target_data_transfer_async}
609       values in @code{ompt_target_data_op_t} enum @tab N @tab
610 @item The values @code{ompt_target_data_transfer_to_device},
611       @code{ompt_target_data_transfer_from_device},
612       @code{ompt_target_data_transfer_to_device_async} and
613       @code{ompt_target_data_transfer_from_device_async} of the @code{target_data_op}
614       OMPT type were deprecated @tab N @tab
615 @item @code{ompt_get_buffer_limits} OMPT routine @tab N @tab
617 @c From the deprecation list, unless listed above.
619 @item Deprecation of omitting the optional white space to separate adjacent
620       keywords in the directive-name in Fortran @tab N @tab
621 @item Deprecation of the Fortran include file @code{omp_lib.h}
622       @tab N @tab
623 @end multitable
625 @unnumberedsubsec Other new TR 13 features
626 @multitable @columnfractions .60 .10 .25
627 @item Multi-word directives now use underscore by default @tab N @tab
628 @item Canonical loop nest enclosed in (multiple) curly braces (C/C++) or BLOCK constructs (Fortran)
629       @tab N @tab
630 @item Relaxed Fortran restrictions to the @code{aligned} clause @tab N @tab
631 @item Mapping lambda captures @tab N @tab
632 @item New @code{omp_pause_stop_tool} constant for omp_pause_resource @tab N @tab
633 @item Multi-word directive names are now permitted with underscore @tab N @tab
634 @item In Fortran (fixed + free), space between directive names is mandatory
635       @tab N @tab
636 @end multitable
640 @c ---------------------------------------------------------------------
641 @c OpenMP Runtime Library Routines
642 @c ---------------------------------------------------------------------
644 @node Runtime Library Routines
645 @chapter OpenMP Runtime Library Routines
647 The runtime routines described here are defined by Section 18 of the OpenMP
648 specification in version 5.2.
650 @menu
651 * Thread Team Routines::
652 * Thread Affinity Routines::
653 * Teams Region Routines::
654 * Tasking Routines::
655 * Resource Relinquishing Routines::
656 * Device Information Routines::
657 * Device Memory Routines::
658 * Lock Routines::
659 * Timing Routines::
660 * Event Routine::
661 @c * Interoperability Routines::
662 * Memory Management Routines::
663 @c * Tool Control Routine::
664 * Environment Display Routine::
665 @end menu
669 @node Thread Team Routines
670 @section Thread Team Routines
672 Routines controlling threads in the current contention group.
673 They have C linkage and do not throw exceptions.
675 @menu
676 * omp_set_num_threads::         Set upper team size limit
677 * omp_get_num_threads::         Size of the active team
678 * omp_get_max_threads::         Maximum number of threads of parallel region
679 * omp_get_thread_num::          Current thread ID
680 * omp_in_parallel::             Whether a parallel region is active
681 * omp_set_dynamic::             Enable/disable dynamic teams
682 * omp_get_dynamic::             Dynamic teams setting
683 * omp_get_cancellation::        Whether cancellation support is enabled
684 * omp_set_nested::              Enable/disable nested parallel regions
685 * omp_get_nested::              Nested parallel regions
686 * omp_set_schedule::            Set the runtime scheduling method
687 * omp_get_schedule::            Obtain the runtime scheduling method
688 * omp_get_teams_thread_limit::  Maximum number of threads imposed by teams
689 * omp_get_supported_active_levels:: Maximum number of active regions supported
690 * omp_set_max_active_levels::   Limits the number of active parallel regions
691 * omp_get_max_active_levels::   Current maximum number of active regions
692 * omp_get_level::               Number of parallel regions
693 * omp_get_ancestor_thread_num:: Ancestor thread ID
694 * omp_get_team_size::           Number of threads in a team
695 * omp_get_active_level::        Number of active parallel regions
696 @end menu
700 @node omp_set_num_threads
701 @subsection @code{omp_set_num_threads} -- Set upper team size limit
702 @table @asis
703 @item @emph{Description}:
704 Specifies the number of threads used by default in subsequent parallel
705 sections, if those do not specify a @code{num_threads} clause.  The
706 argument of @code{omp_set_num_threads} shall be a positive integer.
708 @item @emph{C/C++}:
709 @multitable @columnfractions .20 .80
710 @item @emph{Prototype}: @tab @code{void omp_set_num_threads(int num_threads);}
711 @end multitable
713 @item @emph{Fortran}:
714 @multitable @columnfractions .20 .80
715 @item @emph{Interface}: @tab @code{subroutine omp_set_num_threads(num_threads)}
716 @item                   @tab @code{integer, intent(in) :: num_threads}
717 @end multitable
719 @item @emph{See also}:
720 @ref{OMP_NUM_THREADS}, @ref{omp_get_num_threads}, @ref{omp_get_max_threads}
722 @item @emph{Reference}:
723 @uref{https://www.openmp.org, OpenMP specification v4.5}, Section 3.2.1.
724 @end table
728 @node omp_get_num_threads
729 @subsection @code{omp_get_num_threads} -- Size of the active team
730 @table @asis
731 @item @emph{Description}:
732 Returns the number of threads in the current team.  In a sequential section of
733 the program @code{omp_get_num_threads} returns 1.
735 The default team size may be initialized at startup by the
736 @env{OMP_NUM_THREADS} environment variable.  At runtime, the size
737 of the current team may be set either by the @code{NUM_THREADS}
738 clause or by @code{omp_set_num_threads}.  If none of the above were
739 used to define a specific value and @env{OMP_DYNAMIC} is disabled,
740 one thread per CPU online is used.
742 @item @emph{C/C++}:
743 @multitable @columnfractions .20 .80
744 @item @emph{Prototype}: @tab @code{int omp_get_num_threads(void);}
745 @end multitable
747 @item @emph{Fortran}:
748 @multitable @columnfractions .20 .80
749 @item @emph{Interface}: @tab @code{integer function omp_get_num_threads()}
750 @end multitable
752 @item @emph{See also}:
753 @ref{omp_get_max_threads}, @ref{omp_set_num_threads}, @ref{OMP_NUM_THREADS}
755 @item @emph{Reference}:
756 @uref{https://www.openmp.org, OpenMP specification v4.5}, Section 3.2.2.
757 @end table
761 @node omp_get_max_threads
762 @subsection @code{omp_get_max_threads} -- Maximum number of threads of parallel region
763 @table @asis
764 @item @emph{Description}:
765 Return the maximum number of threads used for the current parallel region
766 that does not use the clause @code{num_threads}.
768 @item @emph{C/C++}:
769 @multitable @columnfractions .20 .80
770 @item @emph{Prototype}: @tab @code{int omp_get_max_threads(void);}
771 @end multitable
773 @item @emph{Fortran}:
774 @multitable @columnfractions .20 .80
775 @item @emph{Interface}: @tab @code{integer function omp_get_max_threads()}
776 @end multitable
778 @item @emph{See also}:
779 @ref{omp_set_num_threads}, @ref{omp_set_dynamic}, @ref{omp_get_thread_limit}
781 @item @emph{Reference}:
782 @uref{https://www.openmp.org, OpenMP specification v4.5}, Section 3.2.3.
783 @end table
787 @node omp_get_thread_num
788 @subsection @code{omp_get_thread_num} -- Current thread ID
789 @table @asis
790 @item @emph{Description}:
791 Returns a unique thread identification number within the current team.
792 In a sequential parts of the program, @code{omp_get_thread_num}
793 always returns 0.  In parallel regions the return value varies
794 from 0 to @code{omp_get_num_threads}-1 inclusive.  The return
795 value of the primary thread of a team is always 0.
797 @item @emph{C/C++}:
798 @multitable @columnfractions .20 .80
799 @item @emph{Prototype}: @tab @code{int omp_get_thread_num(void);}
800 @end multitable
802 @item @emph{Fortran}:
803 @multitable @columnfractions .20 .80
804 @item @emph{Interface}: @tab @code{integer function omp_get_thread_num()}
805 @end multitable
807 @item @emph{See also}:
808 @ref{omp_get_num_threads}, @ref{omp_get_ancestor_thread_num}
810 @item @emph{Reference}:
811 @uref{https://www.openmp.org, OpenMP specification v4.5}, Section 3.2.4.
812 @end table
816 @node omp_in_parallel
817 @subsection @code{omp_in_parallel} -- Whether a parallel region is active
818 @table @asis
819 @item @emph{Description}:
820 This function returns @code{true} if currently running in parallel,
821 @code{false} otherwise.  Here, @code{true} and @code{false} represent
822 their language-specific counterparts.
824 @item @emph{C/C++}:
825 @multitable @columnfractions .20 .80
826 @item @emph{Prototype}: @tab @code{int omp_in_parallel(void);}
827 @end multitable
829 @item @emph{Fortran}:
830 @multitable @columnfractions .20 .80
831 @item @emph{Interface}: @tab @code{logical function omp_in_parallel()}
832 @end multitable
834 @item @emph{Reference}:
835 @uref{https://www.openmp.org, OpenMP specification v4.5}, Section 3.2.6.
836 @end table
839 @node omp_set_dynamic
840 @subsection @code{omp_set_dynamic} -- Enable/disable dynamic teams
841 @table @asis
842 @item @emph{Description}:
843 Enable or disable the dynamic adjustment of the number of threads 
844 within a team.  The function takes the language-specific equivalent
845 of @code{true} and @code{false}, where @code{true} enables dynamic 
846 adjustment of team sizes and @code{false} disables it.
848 @item @emph{C/C++}:
849 @multitable @columnfractions .20 .80
850 @item @emph{Prototype}: @tab @code{void omp_set_dynamic(int dynamic_threads);}
851 @end multitable
853 @item @emph{Fortran}:
854 @multitable @columnfractions .20 .80
855 @item @emph{Interface}: @tab @code{subroutine omp_set_dynamic(dynamic_threads)}
856 @item                   @tab @code{logical, intent(in) :: dynamic_threads}
857 @end multitable
859 @item @emph{See also}:
860 @ref{OMP_DYNAMIC}, @ref{omp_get_dynamic}
862 @item @emph{Reference}:
863 @uref{https://www.openmp.org, OpenMP specification v4.5}, Section 3.2.7.
864 @end table
868 @node omp_get_dynamic
869 @subsection @code{omp_get_dynamic} -- Dynamic teams setting
870 @table @asis
871 @item @emph{Description}:
872 This function returns @code{true} if enabled, @code{false} otherwise. 
873 Here, @code{true} and @code{false} represent their language-specific 
874 counterparts.
876 The dynamic team setting may be initialized at startup by the 
877 @env{OMP_DYNAMIC} environment variable or at runtime using
878 @code{omp_set_dynamic}.  If undefined, dynamic adjustment is
879 disabled by default.
881 @item @emph{C/C++}:
882 @multitable @columnfractions .20 .80
883 @item @emph{Prototype}: @tab @code{int omp_get_dynamic(void);}
884 @end multitable
886 @item @emph{Fortran}:
887 @multitable @columnfractions .20 .80
888 @item @emph{Interface}: @tab @code{logical function omp_get_dynamic()}
889 @end multitable
891 @item @emph{See also}:
892 @ref{omp_set_dynamic}, @ref{OMP_DYNAMIC}
894 @item @emph{Reference}:
895 @uref{https://www.openmp.org, OpenMP specification v4.5}, Section 3.2.8.
896 @end table
900 @node omp_get_cancellation
901 @subsection @code{omp_get_cancellation} -- Whether cancellation support is enabled
902 @table @asis
903 @item @emph{Description}:
904 This function returns @code{true} if cancellation is activated, @code{false}
905 otherwise.  Here, @code{true} and @code{false} represent their language-specific
906 counterparts.  Unless @env{OMP_CANCELLATION} is set true, cancellations are
907 deactivated.
909 @item @emph{C/C++}:
910 @multitable @columnfractions .20 .80
911 @item @emph{Prototype}: @tab @code{int omp_get_cancellation(void);}
912 @end multitable
914 @item @emph{Fortran}:
915 @multitable @columnfractions .20 .80
916 @item @emph{Interface}: @tab @code{logical function omp_get_cancellation()}
917 @end multitable
919 @item @emph{See also}:
920 @ref{OMP_CANCELLATION}
922 @item @emph{Reference}:
923 @uref{https://www.openmp.org, OpenMP specification v4.5}, Section 3.2.9.
924 @end table
928 @node omp_set_nested
929 @subsection @code{omp_set_nested} -- Enable/disable nested parallel regions
930 @table @asis
931 @item @emph{Description}:
932 Enable or disable nested parallel regions, i.e., whether team members
933 are allowed to create new teams.  The function takes the language-specific
934 equivalent of @code{true} and @code{false}, where @code{true} enables 
935 dynamic adjustment of team sizes and @code{false} disables it.
937 Enabling nested parallel regions also sets the maximum number of
938 active nested regions to the maximum supported.  Disabling nested parallel
939 regions sets the maximum number of active nested regions to one.
941 Note that the @code{omp_set_nested} API routine was deprecated
942 in the OpenMP specification 5.0 in favor of @code{omp_set_max_active_levels}.
944 @item @emph{C/C++}:
945 @multitable @columnfractions .20 .80
946 @item @emph{Prototype}: @tab @code{void omp_set_nested(int nested);}
947 @end multitable
949 @item @emph{Fortran}:
950 @multitable @columnfractions .20 .80
951 @item @emph{Interface}: @tab @code{subroutine omp_set_nested(nested)}
952 @item                   @tab @code{logical, intent(in) :: nested}
953 @end multitable
955 @item @emph{See also}:
956 @ref{omp_get_nested}, @ref{omp_set_max_active_levels},
957 @ref{OMP_MAX_ACTIVE_LEVELS}, @ref{OMP_NESTED}
959 @item @emph{Reference}:
960 @uref{https://www.openmp.org, OpenMP specification v4.5}, Section 3.2.10.
961 @end table
965 @node omp_get_nested
966 @subsection @code{omp_get_nested} -- Nested parallel regions
967 @table @asis
968 @item @emph{Description}:
969 This function returns @code{true} if nested parallel regions are
970 enabled, @code{false} otherwise.  Here, @code{true} and @code{false}
971 represent their language-specific counterparts.
973 The state of nested parallel regions at startup depends on several
974 environment variables.  If @env{OMP_MAX_ACTIVE_LEVELS} is defined
975 and is set to greater than one, then nested parallel regions will be
976 enabled.  If not defined, then the value of the @env{OMP_NESTED}
977 environment variable will be followed if defined.  If neither are
978 defined, then if either @env{OMP_NUM_THREADS} or @env{OMP_PROC_BIND}
979 are defined with a list of more than one value, then nested parallel
980 regions are enabled.  If none of these are defined, then nested parallel
981 regions are disabled by default.
983 Nested parallel regions can be enabled or disabled at runtime using
984 @code{omp_set_nested}, or by setting the maximum number of nested
985 regions with @code{omp_set_max_active_levels} to one to disable, or
986 above one to enable.
988 Note that the @code{omp_get_nested} API routine was deprecated
989 in the OpenMP specification 5.0 in favor of @code{omp_get_max_active_levels}.
991 @item @emph{C/C++}:
992 @multitable @columnfractions .20 .80
993 @item @emph{Prototype}: @tab @code{int omp_get_nested(void);}
994 @end multitable
996 @item @emph{Fortran}:
997 @multitable @columnfractions .20 .80
998 @item @emph{Interface}: @tab @code{logical function omp_get_nested()}
999 @end multitable
1001 @item @emph{See also}:
1002 @ref{omp_get_max_active_levels}, @ref{omp_set_nested},
1003 @ref{OMP_MAX_ACTIVE_LEVELS}, @ref{OMP_NESTED}
1005 @item @emph{Reference}:
1006 @uref{https://www.openmp.org, OpenMP specification v4.5}, Section 3.2.11.
1007 @end table
1011 @node omp_set_schedule
1012 @subsection @code{omp_set_schedule} -- Set the runtime scheduling method
1013 @table @asis
1014 @item @emph{Description}:
1015 Sets the runtime scheduling method.  The @var{kind} argument can have the
1016 value @code{omp_sched_static}, @code{omp_sched_dynamic},
1017 @code{omp_sched_guided} or @code{omp_sched_auto}.  Except for
1018 @code{omp_sched_auto}, the chunk size is set to the value of
1019 @var{chunk_size} if positive, or to the default value if zero or negative.
1020 For @code{omp_sched_auto} the @var{chunk_size} argument is ignored.
1022 @item @emph{C/C++}
1023 @multitable @columnfractions .20 .80
1024 @item @emph{Prototype}: @tab @code{void omp_set_schedule(omp_sched_t kind, int chunk_size);}
1025 @end multitable
1027 @item @emph{Fortran}:
1028 @multitable @columnfractions .20 .80
1029 @item @emph{Interface}: @tab @code{subroutine omp_set_schedule(kind, chunk_size)}
1030 @item                   @tab @code{integer(kind=omp_sched_kind) kind}
1031 @item                   @tab @code{integer chunk_size}
1032 @end multitable
1034 @item @emph{See also}:
1035 @ref{omp_get_schedule}
1036 @ref{OMP_SCHEDULE}
1038 @item @emph{Reference}:
1039 @uref{https://www.openmp.org, OpenMP specification v4.5}, Section 3.2.12.
1040 @end table
1044 @node omp_get_schedule
1045 @subsection @code{omp_get_schedule} -- Obtain the runtime scheduling method
1046 @table @asis
1047 @item @emph{Description}:
1048 Obtain the runtime scheduling method.  The @var{kind} argument is set to
1049 @code{omp_sched_static}, @code{omp_sched_dynamic},
1050 @code{omp_sched_guided} or @code{omp_sched_auto}.  The second argument,
1051 @var{chunk_size}, is set to the chunk size.
1053 @item @emph{C/C++}
1054 @multitable @columnfractions .20 .80
1055 @item @emph{Prototype}: @tab @code{void omp_get_schedule(omp_sched_t *kind, int *chunk_size);}
1056 @end multitable
1058 @item @emph{Fortran}:
1059 @multitable @columnfractions .20 .80
1060 @item @emph{Interface}: @tab @code{subroutine omp_get_schedule(kind, chunk_size)}
1061 @item                   @tab @code{integer(kind=omp_sched_kind) kind}
1062 @item                   @tab @code{integer chunk_size}
1063 @end multitable
1065 @item @emph{See also}:
1066 @ref{omp_set_schedule}, @ref{OMP_SCHEDULE}
1068 @item @emph{Reference}:
1069 @uref{https://www.openmp.org, OpenMP specification v4.5}, Section 3.2.13.
1070 @end table
1073 @node omp_get_teams_thread_limit
1074 @subsection @code{omp_get_teams_thread_limit} -- Maximum number of threads imposed by teams
1075 @table @asis
1076 @item @emph{Description}:
1077 Return the maximum number of threads that are able to participate in
1078 each team created by a teams construct.
1080 @item @emph{C/C++}:
1081 @multitable @columnfractions .20 .80
1082 @item @emph{Prototype}: @tab @code{int omp_get_teams_thread_limit(void);}
1083 @end multitable
1085 @item @emph{Fortran}:
1086 @multitable @columnfractions .20 .80
1087 @item @emph{Interface}: @tab @code{integer function omp_get_teams_thread_limit()}
1088 @end multitable
1090 @item @emph{See also}:
1091 @ref{omp_set_teams_thread_limit}, @ref{OMP_TEAMS_THREAD_LIMIT}
1093 @item @emph{Reference}:
1094 @uref{https://www.openmp.org, OpenMP specification v5.1}, Section 3.4.6.
1095 @end table
1099 @node omp_get_supported_active_levels
1100 @subsection @code{omp_get_supported_active_levels} -- Maximum number of active regions supported
1101 @table @asis
1102 @item @emph{Description}:
1103 This function returns the maximum number of nested, active parallel regions
1104 supported by this implementation.
1106 @item @emph{C/C++}
1107 @multitable @columnfractions .20 .80
1108 @item @emph{Prototype}: @tab @code{int omp_get_supported_active_levels(void);}
1109 @end multitable
1111 @item @emph{Fortran}:
1112 @multitable @columnfractions .20 .80
1113 @item @emph{Interface}: @tab @code{integer function omp_get_supported_active_levels()}
1114 @end multitable
1116 @item @emph{See also}:
1117 @ref{omp_get_max_active_levels}, @ref{omp_set_max_active_levels}
1119 @item @emph{Reference}:
1120 @uref{https://www.openmp.org, OpenMP specification v5.0}, Section 3.2.15.
1121 @end table
1125 @node omp_set_max_active_levels
1126 @subsection @code{omp_set_max_active_levels} -- Limits the number of active parallel regions
1127 @table @asis
1128 @item @emph{Description}:
1129 This function limits the maximum allowed number of nested, active
1130 parallel regions.  @var{max_levels} must be less or equal to
1131 the value returned by @code{omp_get_supported_active_levels}.
1133 @item @emph{C/C++}
1134 @multitable @columnfractions .20 .80
1135 @item @emph{Prototype}: @tab @code{void omp_set_max_active_levels(int max_levels);}
1136 @end multitable
1138 @item @emph{Fortran}:
1139 @multitable @columnfractions .20 .80
1140 @item @emph{Interface}: @tab @code{subroutine omp_set_max_active_levels(max_levels)}
1141 @item                   @tab @code{integer max_levels}
1142 @end multitable
1144 @item @emph{See also}:
1145 @ref{omp_get_max_active_levels}, @ref{omp_get_active_level},
1146 @ref{omp_get_supported_active_levels}
1148 @item @emph{Reference}:
1149 @uref{https://www.openmp.org, OpenMP specification v4.5}, Section 3.2.15.
1150 @end table
1154 @node omp_get_max_active_levels
1155 @subsection @code{omp_get_max_active_levels} -- Current maximum number of active regions
1156 @table @asis
1157 @item @emph{Description}:
1158 This function obtains the maximum allowed number of nested, active parallel regions.
1160 @item @emph{C/C++}
1161 @multitable @columnfractions .20 .80
1162 @item @emph{Prototype}: @tab @code{int omp_get_max_active_levels(void);}
1163 @end multitable
1165 @item @emph{Fortran}:
1166 @multitable @columnfractions .20 .80
1167 @item @emph{Interface}: @tab @code{integer function omp_get_max_active_levels()}
1168 @end multitable
1170 @item @emph{See also}:
1171 @ref{omp_set_max_active_levels}, @ref{omp_get_active_level}
1173 @item @emph{Reference}:
1174 @uref{https://www.openmp.org, OpenMP specification v4.5}, Section 3.2.16.
1175 @end table
1178 @node omp_get_level
1179 @subsection @code{omp_get_level} -- Obtain the current nesting level
1180 @table @asis
1181 @item @emph{Description}:
1182 This function returns the nesting level for the parallel blocks,
1183 which enclose the calling call.
1185 @item @emph{C/C++}
1186 @multitable @columnfractions .20 .80
1187 @item @emph{Prototype}: @tab @code{int omp_get_level(void);}
1188 @end multitable
1190 @item @emph{Fortran}:
1191 @multitable @columnfractions .20 .80
1192 @item @emph{Interface}: @tab @code{integer function omp_level()}
1193 @end multitable
1195 @item @emph{See also}:
1196 @ref{omp_get_active_level}
1198 @item @emph{Reference}:
1199 @uref{https://www.openmp.org, OpenMP specification v4.5}, Section 3.2.17.
1200 @end table
1204 @node omp_get_ancestor_thread_num
1205 @subsection @code{omp_get_ancestor_thread_num} -- Ancestor thread ID
1206 @table @asis
1207 @item @emph{Description}:
1208 This function returns the thread identification number for the given
1209 nesting level of the current thread.  For values of @var{level} outside
1210 zero to @code{omp_get_level} -1 is returned; if @var{level} is
1211 @code{omp_get_level} the result is identical to @code{omp_get_thread_num}.
1213 @item @emph{C/C++}
1214 @multitable @columnfractions .20 .80
1215 @item @emph{Prototype}: @tab @code{int omp_get_ancestor_thread_num(int level);}
1216 @end multitable
1218 @item @emph{Fortran}:
1219 @multitable @columnfractions .20 .80
1220 @item @emph{Interface}: @tab @code{integer function omp_get_ancestor_thread_num(level)}
1221 @item                   @tab @code{integer level}
1222 @end multitable
1224 @item @emph{See also}:
1225 @ref{omp_get_level}, @ref{omp_get_thread_num}, @ref{omp_get_team_size}
1227 @item @emph{Reference}:
1228 @uref{https://www.openmp.org, OpenMP specification v4.5}, Section 3.2.18.
1229 @end table
1233 @node omp_get_team_size
1234 @subsection @code{omp_get_team_size} -- Number of threads in a team
1235 @table @asis
1236 @item @emph{Description}:
1237 This function returns the number of threads in a thread team to which
1238 either the current thread or its ancestor belongs.  For values of @var{level}
1239 outside zero to @code{omp_get_level}, -1 is returned; if @var{level} is zero,
1240 1 is returned, and for @code{omp_get_level}, the result is identical
1241 to @code{omp_get_num_threads}.
1243 @item @emph{C/C++}:
1244 @multitable @columnfractions .20 .80
1245 @item @emph{Prototype}: @tab @code{int omp_get_team_size(int level);}
1246 @end multitable
1248 @item @emph{Fortran}:
1249 @multitable @columnfractions .20 .80
1250 @item @emph{Interface}: @tab @code{integer function omp_get_team_size(level)}
1251 @item                   @tab @code{integer level}
1252 @end multitable
1254 @item @emph{See also}:
1255 @ref{omp_get_num_threads}, @ref{omp_get_level}, @ref{omp_get_ancestor_thread_num}
1257 @item @emph{Reference}:
1258 @uref{https://www.openmp.org, OpenMP specification v4.5}, Section 3.2.19.
1259 @end table
1263 @node omp_get_active_level
1264 @subsection @code{omp_get_active_level} -- Number of parallel regions
1265 @table @asis
1266 @item @emph{Description}:
1267 This function returns the nesting level for the active parallel blocks,
1268 which enclose the calling call.
1270 @item @emph{C/C++}
1271 @multitable @columnfractions .20 .80
1272 @item @emph{Prototype}: @tab @code{int omp_get_active_level(void);}
1273 @end multitable
1275 @item @emph{Fortran}:
1276 @multitable @columnfractions .20 .80
1277 @item @emph{Interface}: @tab @code{integer function omp_get_active_level()}
1278 @end multitable
1280 @item @emph{See also}:
1281 @ref{omp_get_level}, @ref{omp_get_max_active_levels}, @ref{omp_set_max_active_levels}
1283 @item @emph{Reference}:
1284 @uref{https://www.openmp.org, OpenMP specification v4.5}, Section 3.2.20.
1285 @end table
1289 @node Thread Affinity Routines
1290 @section Thread Affinity Routines
1292 Routines controlling and accessing thread-affinity policies.
1293 They have C linkage and do not throw exceptions.
1295 @menu
1296 * omp_get_proc_bind::           Whether threads may be moved between CPUs
1297 @c * omp_get_num_places::       Get the number of places available
1298 @c * omp_get_place_num_procs::  Get the number of processes associated with a place
1299 @c * omp_get_place_proc_ids::   Get number of processes associated with a place
1300 @c * omp_get_place_num::        Get place number of the associated task
1301 @c * omp_get_partition_num_places:: Get number of places of innermost task
1302 @c * omp_get_partition_place_nums:: <fixme>
1303 @c * omp_set_affinity_format:: <fixme>
1304 @c * omp_get_affinity_format:: <fixme>
1305 @c * omp_display_affinity:: <fixme>
1306 @c * omp_capture_affinity:: <fixme>
1307 @end menu
1311 @node omp_get_proc_bind
1312 @subsection @code{omp_get_proc_bind} -- Whether threads may be moved between CPUs
1313 @table @asis
1314 @item @emph{Description}:
1315 This functions returns the currently active thread affinity policy, which is
1316 set via @env{OMP_PROC_BIND}.  Possible values are @code{omp_proc_bind_false},
1317 @code{omp_proc_bind_true}, @code{omp_proc_bind_primary},
1318 @code{omp_proc_bind_master}, @code{omp_proc_bind_close} and @code{omp_proc_bind_spread},
1319 where @code{omp_proc_bind_master} is an alias for @code{omp_proc_bind_primary}.
1321 @item @emph{C/C++}:
1322 @multitable @columnfractions .20 .80
1323 @item @emph{Prototype}: @tab @code{omp_proc_bind_t omp_get_proc_bind(void);}
1324 @end multitable
1326 @item @emph{Fortran}:
1327 @multitable @columnfractions .20 .80
1328 @item @emph{Interface}: @tab @code{integer(kind=omp_proc_bind_kind) function omp_get_proc_bind()}
1329 @end multitable
1331 @item @emph{See also}:
1332 @ref{OMP_PROC_BIND}, @ref{OMP_PLACES}, @ref{GOMP_CPU_AFFINITY},
1334 @item @emph{Reference}:
1335 @uref{https://www.openmp.org, OpenMP specification v4.5}, Section 3.2.22.
1336 @end table
1340 @node Teams Region Routines
1341 @section Teams Region Routines
1343 Routines controlling the league of teams that are executed in a @code{teams}
1344 region.  They have C linkage and do not throw exceptions.
1346 @menu
1347 * omp_get_num_teams::           Number of teams
1348 * omp_get_team_num::            Get team number
1349 * omp_set_num_teams::           Set upper teams limit for teams region
1350 * omp_get_max_teams::           Maximum number of teams for teams region
1351 * omp_set_teams_thread_limit::  Set upper thread limit for teams construct
1352 * omp_get_thread_limit::        Maximum number of threads
1353 @end menu
1357 @node omp_get_num_teams
1358 @subsection @code{omp_get_num_teams} -- Number of teams
1359 @table @asis
1360 @item @emph{Description}:
1361 Returns the number of teams in the current team region.
1363 @item @emph{C/C++}:
1364 @multitable @columnfractions .20 .80
1365 @item @emph{Prototype}: @tab @code{int omp_get_num_teams(void);}
1366 @end multitable
1368 @item @emph{Fortran}:
1369 @multitable @columnfractions .20 .80
1370 @item @emph{Interface}: @tab @code{integer function omp_get_num_teams()}
1371 @end multitable
1373 @item @emph{Reference}:
1374 @uref{https://www.openmp.org, OpenMP specification v4.5}, Section 3.2.32.
1375 @end table
1379 @node omp_get_team_num
1380 @subsection @code{omp_get_team_num} -- Get team number
1381 @table @asis
1382 @item @emph{Description}:
1383 Returns the team number of the calling thread.
1385 @item @emph{C/C++}:
1386 @multitable @columnfractions .20 .80
1387 @item @emph{Prototype}: @tab @code{int omp_get_team_num(void);}
1388 @end multitable
1390 @item @emph{Fortran}:
1391 @multitable @columnfractions .20 .80
1392 @item @emph{Interface}: @tab @code{integer function omp_get_team_num()}
1393 @end multitable
1395 @item @emph{Reference}:
1396 @uref{https://www.openmp.org, OpenMP specification v4.5}, Section 3.2.33.
1397 @end table
1401 @node omp_set_num_teams
1402 @subsection @code{omp_set_num_teams} -- Set upper teams limit for teams construct
1403 @table @asis
1404 @item @emph{Description}:
1405 Specifies the upper bound for number of teams created by the teams construct
1406 which does not specify a @code{num_teams} clause.  The
1407 argument of @code{omp_set_num_teams} shall be a positive integer.
1409 @item @emph{C/C++}:
1410 @multitable @columnfractions .20 .80
1411 @item @emph{Prototype}: @tab @code{void omp_set_num_teams(int num_teams);}
1412 @end multitable
1414 @item @emph{Fortran}:
1415 @multitable @columnfractions .20 .80
1416 @item @emph{Interface}: @tab @code{subroutine omp_set_num_teams(num_teams)}
1417 @item                   @tab @code{integer, intent(in) :: num_teams}
1418 @end multitable
1420 @item @emph{See also}:
1421 @ref{OMP_NUM_TEAMS}, @ref{omp_get_num_teams}, @ref{omp_get_max_teams}
1423 @item @emph{Reference}:
1424 @uref{https://www.openmp.org, OpenMP specification v5.1}, Section 3.4.3.
1425 @end table
1429 @node omp_get_max_teams
1430 @subsection @code{omp_get_max_teams} -- Maximum number of teams of teams region
1431 @table @asis
1432 @item @emph{Description}:
1433 Return the maximum number of teams used for the teams region
1434 that does not use the clause @code{num_teams}.
1436 @item @emph{C/C++}:
1437 @multitable @columnfractions .20 .80
1438 @item @emph{Prototype}: @tab @code{int omp_get_max_teams(void);}
1439 @end multitable
1441 @item @emph{Fortran}:
1442 @multitable @columnfractions .20 .80
1443 @item @emph{Interface}: @tab @code{integer function omp_get_max_teams()}
1444 @end multitable
1446 @item @emph{See also}:
1447 @ref{omp_set_num_teams}, @ref{omp_get_num_teams}
1449 @item @emph{Reference}:
1450 @uref{https://www.openmp.org, OpenMP specification v5.1}, Section 3.4.4.
1451 @end table
1455 @node omp_set_teams_thread_limit
1456 @subsection @code{omp_set_teams_thread_limit} -- Set upper thread limit for teams construct
1457 @table @asis
1458 @item @emph{Description}:
1459 Specifies the upper bound for number of threads that are available
1460 for each team created by the teams construct which does not specify a
1461 @code{thread_limit} clause.  The argument of
1462 @code{omp_set_teams_thread_limit} shall be a positive integer.
1464 @item @emph{C/C++}:
1465 @multitable @columnfractions .20 .80
1466 @item @emph{Prototype}: @tab @code{void omp_set_teams_thread_limit(int thread_limit);}
1467 @end multitable
1469 @item @emph{Fortran}:
1470 @multitable @columnfractions .20 .80
1471 @item @emph{Interface}: @tab @code{subroutine omp_set_teams_thread_limit(thread_limit)}
1472 @item                   @tab @code{integer, intent(in) :: thread_limit}
1473 @end multitable
1475 @item @emph{See also}:
1476 @ref{OMP_TEAMS_THREAD_LIMIT}, @ref{omp_get_teams_thread_limit}, @ref{omp_get_thread_limit}
1478 @item @emph{Reference}:
1479 @uref{https://www.openmp.org, OpenMP specification v5.1}, Section 3.4.5.
1480 @end table
1484 @node omp_get_thread_limit
1485 @subsection @code{omp_get_thread_limit} -- Maximum number of threads
1486 @table @asis
1487 @item @emph{Description}:
1488 Return the maximum number of threads of the program.
1490 @item @emph{C/C++}:
1491 @multitable @columnfractions .20 .80
1492 @item @emph{Prototype}: @tab @code{int omp_get_thread_limit(void);}
1493 @end multitable
1495 @item @emph{Fortran}:
1496 @multitable @columnfractions .20 .80
1497 @item @emph{Interface}: @tab @code{integer function omp_get_thread_limit()}
1498 @end multitable
1500 @item @emph{See also}:
1501 @ref{omp_get_max_threads}, @ref{OMP_THREAD_LIMIT}
1503 @item @emph{Reference}:
1504 @uref{https://www.openmp.org, OpenMP specification v4.5}, Section 3.2.14.
1505 @end table
1509 @node Tasking Routines
1510 @section Tasking Routines
1512 Routines relating to explicit tasks.
1513 They have C linkage and do not throw exceptions.
1515 @menu
1516 * omp_get_max_task_priority::   Maximum task priority value that can be set
1517 * omp_in_explicit_task::        Whether a given task is an explicit task
1518 * omp_in_final::                Whether in final or included task region
1519 @c * omp_is_free_agent:: <fixme>/TR12
1520 @c * omp_ancestor_is_free_agent:: <fixme>/TR12
1521 @end menu
1525 @node omp_get_max_task_priority
1526 @subsection @code{omp_get_max_task_priority} -- Maximum priority value
1527 that can be set for tasks.
1528 @table @asis
1529 @item @emph{Description}:
1530 This function obtains the maximum allowed priority number for tasks.
1532 @item @emph{C/C++}
1533 @multitable @columnfractions .20 .80
1534 @item @emph{Prototype}: @tab @code{int omp_get_max_task_priority(void);}
1535 @end multitable
1537 @item @emph{Fortran}:
1538 @multitable @columnfractions .20 .80
1539 @item @emph{Interface}: @tab @code{integer function omp_get_max_task_priority()}
1540 @end multitable
1542 @item @emph{Reference}:
1543 @uref{https://www.openmp.org, OpenMP specification v4.5}, Section 3.2.29.
1544 @end table
1548 @node omp_in_explicit_task
1549 @subsection @code{omp_in_explicit_task} -- Whether a given task is an explicit task
1550 @table @asis
1551 @item @emph{Description}:
1552 The function returns the @var{explicit-task-var} ICV; it returns true when the
1553 encountering task was generated by a task-generating construct such as
1554 @code{target}, @code{task} or @code{taskloop}.  Otherwise, the encountering task
1555 is in an implicit task region such as generated by the implicit or explicit
1556 @code{parallel} region and @code{omp_in_explicit_task} returns false.
1558 @item @emph{C/C++}
1559 @multitable @columnfractions .20 .80
1560 @item @emph{Prototype}: @tab @code{int omp_in_explicit_task(void);}
1561 @end multitable
1563 @item @emph{Fortran}:
1564 @multitable @columnfractions .20 .80
1565 @item @emph{Interface}: @tab @code{logical function omp_in_explicit_task()}
1566 @end multitable
1568 @item @emph{Reference}:
1569 @uref{https://www.openmp.org, OpenMP specification v5.2}, Section 18.5.2.
1570 @end table
1574 @node omp_in_final
1575 @subsection @code{omp_in_final} -- Whether in final or included task region
1576 @table @asis
1577 @item @emph{Description}:
1578 This function returns @code{true} if currently running in a final
1579 or included task region, @code{false} otherwise.  Here, @code{true}
1580 and @code{false} represent their language-specific counterparts.
1582 @item @emph{C/C++}:
1583 @multitable @columnfractions .20 .80
1584 @item @emph{Prototype}: @tab @code{int omp_in_final(void);}
1585 @end multitable
1587 @item @emph{Fortran}:
1588 @multitable @columnfractions .20 .80
1589 @item @emph{Interface}: @tab @code{logical function omp_in_final()}
1590 @end multitable
1592 @item @emph{Reference}:
1593 @uref{https://www.openmp.org, OpenMP specification v4.5}, Section 3.2.21.
1594 @end table
1598 @node Resource Relinquishing Routines
1599 @section Resource Relinquishing Routines
1601 Routines releasing resources used by the OpenMP runtime.
1602 They have C linkage and do not throw exceptions.
1604 @menu
1605 * omp_pause_resource:: Release OpenMP resources on a device
1606 * omp_pause_resource_all:: Release OpenMP resources on all devices
1607 @end menu
1611 @node omp_pause_resource
1612 @subsection @code{omp_pause_resource} -- Release OpenMP resources on a device
1613 @table @asis
1614 @item @emph{Description}:
1615 Free resources used by the OpenMP program and the runtime library on and for the
1616 device specified by @var{device_num}; on success, zero is returned and non-zero
1617 otherwise.
1619 The value of @var{device_num} must be a conforming device number.  The routine
1620 may not be called from within any explicit region and all explicit threads that
1621 do not bind to the implicit parallel region have finalized execution.
1623 @item @emph{C/C++}:
1624 @multitable @columnfractions .20 .80
1625 @item @emph{Prototype}: @tab @code{int omp_pause_resource(omp_pause_resource_t kind, int device_num);}
1626 @end multitable
1628 @item @emph{Fortran}:
1629 @multitable @columnfractions .20 .80
1630 @item @emph{Interface}: @tab @code{integer function omp_pause_resource(kind, device_num)}
1631 @item                   @tab @code{integer (kind=omp_pause_resource_kind) kind}
1632 @item                   @tab @code{integer device_num}
1633 @end multitable
1635 @item @emph{Reference}:
1636 @uref{https://www.openmp.org, OpenMP specification v5.0}, Section 3.2.43.
1637 @end table
1641 @node omp_pause_resource_all
1642 @subsection @code{omp_pause_resource_all} -- Release OpenMP resources on all devices
1643 @table @asis
1644 @item @emph{Description}:
1645 Free resources used by the OpenMP program and the runtime library on all devices,
1646 including the host. On success, zero is returned and non-zero otherwise.
1648 The routine may not be called from within any explicit region and all explicit
1649 threads that do not bind to the implicit parallel region have finalized execution.
1651 @item @emph{C/C++}:
1652 @multitable @columnfractions .20 .80
1653 @item @emph{Prototype}: @tab @code{int omp_pause_resource(omp_pause_resource_t kind);}
1654 @end multitable
1656 @item @emph{Fortran}:
1657 @multitable @columnfractions .20 .80
1658 @item @emph{Interface}: @tab @code{integer function omp_pause_resource(kind)}
1659 @item                   @tab @code{integer (kind=omp_pause_resource_kind) kind}
1660 @end multitable
1662 @item @emph{See also}:
1663 @ref{omp_pause_resource}
1665 @item @emph{Reference}:
1666 @uref{https://www.openmp.org, OpenMP specification v5.0}, Section 3.2.44.
1667 @end table
1671 @node Device Information Routines
1672 @section Device Information Routines
1674 Routines related to devices available to an OpenMP program.
1675 They have C linkage and do not throw exceptions.
1677 @menu
1678 * omp_get_num_procs::           Number of processors online
1679 @c * omp_get_max_progress_width:: <fixme>/TR11
1680 * omp_set_default_device::      Set the default device for target regions
1681 * omp_get_default_device::      Get the default device for target regions
1682 * omp_get_num_devices::         Number of target devices
1683 * omp_get_device_num::          Get device that current thread is running on
1684 * omp_get_device_from_uid::     Obtain the device number to a unique id
1685 * omp_get_uid_from_device::     Obtain the unique id of a device
1686 * omp_is_initial_device::       Whether executing on the host device
1687 * omp_get_initial_device::      Device number of host device
1688 @c * omp_get_device_num_teams::  <fixme>/TR13
1689 @c * omp_set_device_num_teams::  <fixme>/TR13
1690 @c * omp_get_device_teams_thread_limit::  <fixme>/TR13
1691 @c * omp_set_device_teams_thread_limit::  <fixme>/TR13
1692 @end menu
1696 @node omp_get_num_procs
1697 @subsection @code{omp_get_num_procs} -- Number of processors online
1698 @table @asis
1699 @item @emph{Description}:
1700 Returns the number of processors online on that device.
1702 @item @emph{C/C++}:
1703 @multitable @columnfractions .20 .80
1704 @item @emph{Prototype}: @tab @code{int omp_get_num_procs(void);}
1705 @end multitable
1707 @item @emph{Fortran}:
1708 @multitable @columnfractions .20 .80
1709 @item @emph{Interface}: @tab @code{integer function omp_get_num_procs()}
1710 @end multitable
1712 @item @emph{Reference}:
1713 @uref{https://www.openmp.org, OpenMP specification v4.5}, Section 3.2.5.
1714 @end table
1718 @node omp_set_default_device
1719 @subsection @code{omp_set_default_device} -- Set the default device for target regions
1720 @table @asis
1721 @item @emph{Description}:
1722 Get the value of the @emph{default-device-var} ICV, which is used
1723 for target regions without a device clause.  The argument
1724 shall be a nonnegative device number, @code{omp_initial_device},
1725 or @code{omp_invalid_device}.
1727 The effect of running this routine in a @code{target} region is unspecified.
1729 @item @emph{C/C++}:
1730 @multitable @columnfractions .20 .80
1731 @item @emph{Prototype}: @tab @code{void omp_set_default_device(int device_num);}
1732 @end multitable
1734 @item @emph{Fortran}:
1735 @multitable @columnfractions .20 .80
1736 @item @emph{Interface}: @tab @code{subroutine omp_set_default_device(device_num)}
1737 @item                   @tab @code{integer device_num}
1738 @end multitable
1740 @item @emph{See also}:
1741 @ref{OMP_DEFAULT_DEVICE}, @ref{omp_get_default_device}
1743 @item @emph{Reference}:
1744 @uref{https://www.openmp.org, OpenMP specification v4.5}, Section 3.2.29.
1745 @end table
1749 @node omp_get_default_device
1750 @subsection @code{omp_get_default_device} -- Get the default device for target regions
1751 @table @asis
1752 @item @emph{Description}:
1753 Get the value of the @emph{default-device-var} ICV, which is used
1754 for target regions without a device clause. The value is either a
1755 nonnegative device number, @code{omp_initial_device} or
1756 @code{omp_invalid_device}. Note that for the host, the ICV can have two values
1757 and, hence, this routine might return either the value of the named constant
1758 @code{omp_initial_device} or the value returned by the
1759 @code{omp_get_initial_device} routine.
1761 The effect of running this routine in a @code{target} region is unspecified.
1763 @item @emph{C/C++}:
1764 @multitable @columnfractions .20 .80
1765 @item @emph{Prototype}: @tab @code{int omp_get_default_device(void);}
1766 @end multitable
1768 @item @emph{Fortran}:
1769 @multitable @columnfractions .20 .80
1770 @item @emph{Interface}: @tab @code{integer function omp_get_default_device()}
1771 @end multitable
1773 @item @emph{See also}:
1774 @ref{OMP_DEFAULT_DEVICE}, @ref{omp_set_default_device},
1775 @ref{omp_get_initial_device}
1777 @item @emph{Reference}:
1778 @uref{https://www.openmp.org, OpenMP specification v4.5}, Section 3.2.30.
1779 @end table
1783 @node omp_get_num_devices
1784 @subsection @code{omp_get_num_devices} -- Number of target devices
1785 @table @asis
1786 @item @emph{Description}:
1787 Returns the number of target devices.
1789 The effect of running this routine in a @code{target} region is unspecified.
1791 @item @emph{C/C++}:
1792 @multitable @columnfractions .20 .80
1793 @item @emph{Prototype}: @tab @code{int omp_get_num_devices(void);}
1794 @end multitable
1796 @item @emph{Fortran}:
1797 @multitable @columnfractions .20 .80
1798 @item @emph{Interface}: @tab @code{integer function omp_get_num_devices()}
1799 @end multitable
1801 @item @emph{Reference}:
1802 @uref{https://www.openmp.org, OpenMP specification v4.5}, Section 3.2.31.
1803 @end table
1807 @node omp_get_device_num
1808 @subsection @code{omp_get_device_num} -- Return device number of current device
1809 @table @asis
1810 @item @emph{Description}:
1811 This function returns a device number that represents the device that the
1812 current thread is executing on. When called on the host, it returns
1813 the same value as returned by the @code{omp_get_initial_device} function
1814 as required since OpenMP 5.0.
1816 @item @emph{C/C++}
1817 @multitable @columnfractions .20 .80
1818 @item @emph{Prototype}: @tab @code{int omp_get_device_num(void);}
1819 @end multitable
1821 @item @emph{Fortran}:
1822 @multitable @columnfractions .20 .80
1823 @item @emph{Interface}: @tab @code{integer function omp_get_device_num()}
1824 @end multitable
1826 @item @emph{See also}:
1827 @ref{omp_get_initial_device}
1829 @item @emph{Reference}:
1830 @uref{https://www.openmp.org, OpenMP specification v5.0}, Section 3.2.37.
1831 @end table
1835 @node omp_get_device_from_uid
1836 @subsection @code{omp_get_device_from_uid} -- Obtain the device number to a unique id
1837 @table @asis
1838 @item @emph{Description}:
1839 This function returns the device number associated with the passed
1840 unique-identifier (UID) string.  If no device with this UID is available, the value
1841 @code{omp_invalid_device} is returned.  The effect of running this routine in a
1842 @code{target} region is unspecified.
1844 GCC treats the UID string case sensitive; for the initial device, GCC currently
1845 only accepts the value @code{OMP_INITIAL_DEVICE} and returns for it the value
1846 of @code{omp_initial_device}.
1848 @item @emph{C/C++}:
1849 @multitable @columnfractions .20 .80
1850 @item @emph{Prototype}: @tab @code{int omp_get_device_from_uid(const char *uid);}
1851 @end multitable
1853 @item @emph{Fortran}:
1854 @multitable @columnfractions .20 .80
1855 @item @emph{Interface}: @tab @code{integer function omp_get_device_from_uid(uid)}
1856 @item                   @tab @code{character(len=*), intent(in) :: uid}
1857 @end multitable
1859 @item @emph{See also}:
1860 @ref{omp_get_uid_from_device}, @ref{Offload-Target Specifics}
1862 @item @emph{Reference}:
1863 @uref{https://www.openmp.org, OpenMP specification v6.0}, Section 24.7
1864 @end table
1868 @node omp_get_uid_from_device
1869 @subsection @code{omp_get_uid_from_device} -- Obtain the unique id of a device
1870 @table @asis
1871 @item @emph{Description}:
1872 This function returns a pointer to a string that represents a unique identifier
1873 (UID) for the device specified by @var{device_num}.  It returns a @code{NULL} (C/C++)
1874 or a disassociated pointer (Fortran) for @code{omp_invalid_device}.  The effect of
1875 running this routine in a @code{target} region is unspecified.
1877 GCC currently returns for initial device the value @code{OMP_INITIAL_DEVICE}.
1879 @item @emph{C/C++}:
1880 @multitable @columnfractions .20 .80
1881 @item @emph{Prototype}: @tab @code{const char *omp_get_uid_from_device(int device_num);}
1882 @end multitable
1884 @item @emph{Fortran}:
1885 @multitable @columnfractions .20 .80
1886 @item @emph{Interface}: @tab @code{character(:) function omp_get_uid_from_device(device_num)}
1887 @item @emph{Interface}: @tab @code{pointer :: omp_get_uid_from_device}
1888 @item                   @tab @code{integer, intent(in) :: device_num}
1889 @end multitable
1891 @item @emph{See also}:
1892 @ref{omp_get_uid_from_device}, @ref{Offload-Target Specifics}
1894 @item @emph{Reference}:
1895 @uref{https://www.openmp.org, OpenMP specification v6.0}, Section 24.8
1896 @end table
1900 @node omp_is_initial_device
1901 @subsection @code{omp_is_initial_device} -- Whether executing on the host device
1902 @table @asis
1903 @item @emph{Description}:
1904 This function returns @code{true} if currently running on the host device,
1905 @code{false} otherwise.  Here, @code{true} and @code{false} represent
1906 their language-specific counterparts.
1908 Note that in GCC this value is already folded to a constant in the compiler;
1909 compile with @option{-fno-builtin-omp_is_initial_device} if a run-time function
1910 is desired.
1912 @item @emph{C/C++}:
1913 @multitable @columnfractions .20 .80
1914 @item @emph{Prototype}: @tab @code{int omp_is_initial_device(void);}
1915 @end multitable
1917 @item @emph{Fortran}:
1918 @multitable @columnfractions .20 .80
1919 @item @emph{Interface}: @tab @code{logical function omp_is_initial_device()}
1920 @end multitable
1922 @item @emph{Reference}:
1923 @uref{https://www.openmp.org, OpenMP specification v4.5}, Section 3.2.34.
1924 @end table
1928 @node omp_get_initial_device
1929 @subsection @code{omp_get_initial_device} -- Return device number of initial device
1930 @table @asis
1931 @item @emph{Description}:
1932 This function returns a device number that represents the host device.
1933 Since OpenMP 5.1, this is equal to the value returned by the
1934 @code{omp_get_num_devices} function.
1936 The effect of running this routine in a @code{target} region is unspecified.
1938 @item @emph{C/C++}
1939 @multitable @columnfractions .20 .80
1940 @item @emph{Prototype}: @tab @code{int omp_get_initial_device(void);}
1941 @end multitable
1943 @item @emph{Fortran}:
1944 @multitable @columnfractions .20 .80
1945 @item @emph{Interface}: @tab @code{integer function omp_get_initial_device()}
1946 @end multitable
1948 @item @emph{See also}:
1949 @ref{omp_get_num_devices}
1951 @item @emph{Reference}:
1952 @uref{https://www.openmp.org, OpenMP specification v4.5}, Section 3.2.35.
1953 @end table
1957 @node Device Memory Routines
1958 @section Device Memory Routines
1960 Routines related to memory allocation and managing corresponding
1961 pointers on devices. They have C linkage and do not throw exceptions.
1963 @menu
1964 * omp_target_alloc:: Allocate device memory
1965 * omp_target_free:: Free device memory
1966 * omp_target_is_present:: Check whether storage is mapped
1967 * omp_target_is_accessible:: Check whether memory is device accessible
1968 * omp_target_memcpy:: Copy data between devices
1969 * omp_target_memcpy_async:: Copy data between devices asynchronously
1970 * omp_target_memcpy_rect:: Copy a subvolume of data between devices
1971 * omp_target_memcpy_rect_async:: Copy a subvolume of data between devices asynchronously
1972 @c * omp_target_memset:: <fixme>/TR12
1973 @c * omp_target_memset_async:: <fixme>/TR12
1974 * omp_target_associate_ptr:: Associate a device pointer with a host pointer
1975 * omp_target_disassociate_ptr:: Remove device--host pointer association
1976 * omp_get_mapped_ptr:: Return device pointer to a host pointer
1977 @end menu
1981 @node omp_target_alloc
1982 @subsection @code{omp_target_alloc} -- Allocate device memory
1983 @table @asis
1984 @item @emph{Description}:
1985 This routine allocates @var{size} bytes of memory in the device environment
1986 associated with the device number @var{device_num}.  If successful, a device
1987 pointer is returned, otherwise a null pointer.
1989 In GCC, when the device is the host or the device shares memory with the host,
1990 the memory is allocated on the host; in that case, when @var{size} is zero,
1991 either NULL or a unique pointer value that can later be successfully passed to
1992 @code{omp_target_free} is returned.  When the allocation is not performed on
1993 the host, a null pointer is returned when @var{size} is zero; in that case,
1994 additionally a diagnostic might be printed to standard error (stderr).
1996 Running this routine in a @code{target} region except on the initial device
1997 is not supported.
1999 @item @emph{C/C++}
2000 @multitable @columnfractions .20 .80
2001 @item @emph{Prototype}: @tab @code{void *omp_target_alloc(size_t size, int device_num)}
2002 @end multitable
2004 @item @emph{Fortran}:
2005 @multitable @columnfractions .20 .80
2006 @item @emph{Interface}: @tab @code{type(c_ptr) function omp_target_alloc(size, device_num) bind(C)}
2007 @item                   @tab @code{use, intrinsic :: iso_c_binding, only: c_ptr, c_int, c_size_t}
2008 @item                   @tab @code{integer(c_size_t), value :: size}
2009 @item                   @tab @code{integer(c_int), value :: device_num}
2010 @end multitable
2012 @item @emph{See also}:
2013 @ref{omp_target_free}, @ref{omp_target_associate_ptr}
2015 @item @emph{Reference}:
2016 @uref{https://www.openmp.org, OpenMP specification v5.1}, Section 3.8.1
2017 @end table
2021 @node omp_target_free
2022 @subsection @code{omp_target_free} -- Free device memory
2023 @table @asis
2024 @item @emph{Description}:
2025 This routine frees memory allocated by the @code{omp_target_alloc} routine.
2026 The @var{device_ptr} argument must be either a null pointer or a device pointer
2027 returned by @code{omp_target_alloc} for the specified @code{device_num}.  The
2028 device number @var{device_num} must be a conforming device number.
2030 Running this routine in a @code{target} region except on the initial device
2031 is not supported.
2033 @item @emph{C/C++}
2034 @multitable @columnfractions .20 .80
2035 @item @emph{Prototype}: @tab @code{void omp_target_free(void *device_ptr, int device_num)}
2036 @end multitable
2038 @item @emph{Fortran}:
2039 @multitable @columnfractions .20 .80
2040 @item @emph{Interface}: @tab @code{subroutine omp_target_free(device_ptr, device_num) bind(C)}
2041 @item                   @tab @code{use, intrinsic :: iso_c_binding, only: c_ptr, c_int}
2042 @item                   @tab @code{type(c_ptr), value :: device_ptr}
2043 @item                   @tab @code{integer(c_int), value :: device_num}
2044 @end multitable
2046 @item @emph{See also}:
2047 @ref{omp_target_alloc}, @ref{omp_target_disassociate_ptr}
2049 @item @emph{Reference}:
2050 @uref{https://www.openmp.org, OpenMP specification v5.1}, Section 3.8.2
2051 @end table
2055 @node omp_target_is_present
2056 @subsection @code{omp_target_is_present} -- Check whether storage is mapped
2057 @table @asis
2058 @item @emph{Description}:
2059 This routine tests whether storage, identified by the host pointer @var{ptr}
2060 is mapped to the device specified by @var{device_num}.  If so, it returns
2061 a nonzero value and otherwise zero.
2063 In GCC, this includes self mapping such that @code{omp_target_is_present}
2064 returns @emph{true} when @var{device_num} specifies the host or when the host
2065 and the device share memory.  If @var{ptr} is a null pointer, @var{true} is
2066 returned and if @var{device_num} is an invalid device number, @var{false} is
2067 returned.
2069 If those conditions do not apply, @emph{true} is returned if the association has
2070 been established by an explicit or implicit @code{map} clause, the
2071 @code{declare target} directive or a call to the @code{omp_target_associate_ptr}
2072 routine.
2074 Running this routine in a @code{target} region except on the initial device
2075 is not supported.
2077 @item @emph{C/C++}
2078 @multitable @columnfractions .20 .80
2079 @item @emph{Prototype}: @tab @code{int omp_target_is_present(const void *ptr,}
2080 @item                   @tab @code{                          int device_num)}
2081 @end multitable
2083 @item @emph{Fortran}:
2084 @multitable @columnfractions .20 .80
2085 @item @emph{Interface}: @tab @code{integer(c_int) function omp_target_is_present(ptr, &}
2086 @item                   @tab @code{    device_num) bind(C)}
2087 @item                   @tab @code{use, intrinsic :: iso_c_binding, only: c_ptr, c_int}
2088 @item                   @tab @code{type(c_ptr), value :: ptr}
2089 @item                   @tab @code{integer(c_int), value :: device_num}
2090 @end multitable
2092 @item @emph{See also}:
2093 @ref{omp_target_associate_ptr}
2095 @item @emph{Reference}:
2096 @uref{https://www.openmp.org, OpenMP specification v5.1}, Section 3.8.3
2097 @end table
2101 @node omp_target_is_accessible
2102 @subsection @code{omp_target_is_accessible} -- Check whether memory is device accessible
2103 @table @asis
2104 @item @emph{Description}:
2105 This routine tests whether memory, starting at the address given by @var{ptr}
2106 and extending @var{size} bytes, is accessibly on the device specified by
2107 @var{device_num}.  If so, it returns a nonzero value and otherwise zero.
2109 The address given by @var{ptr} is interpreted to be in the address space of
2110 the device and @var{size} must be positive.
2112 Note that GCC's current implementation assumes that @var{ptr} is a valid host
2113 pointer. Therefore, all addresses given by @var{ptr} are assumed to be
2114 accessible on the initial device. And, to err on the safe side, this memory
2115 is only available on a non-host device that can access all host memory
2116 ([uniform] shared memory access).
2118 Running this routine in a @code{target} region except on the initial device
2119 is not supported.
2121 @item @emph{C/C++}
2122 @multitable @columnfractions .20 .80
2123 @item @emph{Prototype}: @tab @code{int omp_target_is_accessible(const void *ptr,}
2124 @item                   @tab @code{                             size_t size,}
2125 @item                   @tab @code{                             int device_num)}
2126 @end multitable
2128 @item @emph{Fortran}:
2129 @multitable @columnfractions .20 .80
2130 @item @emph{Interface}: @tab @code{integer(c_int) function omp_target_is_accessible(ptr, &}
2131 @item                   @tab @code{    size, device_num) bind(C)}
2132 @item                   @tab @code{use, intrinsic :: iso_c_binding, only: c_ptr, c_size_t, c_int}
2133 @item                   @tab @code{type(c_ptr), value :: ptr}
2134 @item                   @tab @code{integer(c_size_t), value :: size}
2135 @item                   @tab @code{integer(c_int), value :: device_num}
2136 @end multitable
2138 @item @emph{See also}:
2139 @ref{omp_target_associate_ptr}
2141 @item @emph{Reference}:
2142 @uref{https://www.openmp.org, OpenMP specification v5.1}, Section 3.8.4
2143 @end table
2147 @node omp_target_memcpy
2148 @subsection @code{omp_target_memcpy} -- Copy data between devices
2149 @table @asis
2150 @item @emph{Description}:
2151 This routine copies @var{length} of bytes of data from the device
2152 identified by device number @var{src_device_num} to device @var{dst_device_num}.
2153 The data is copied from the source device from the address provided by
2154 @var{src}, shifted by the offset of @var{src_offset} bytes, to the destination
2155 device's @var{dst} address shifted by @var{dst_offset}.  The routine returns
2156 zero on success and non-zero otherwise.
2158 Running this routine in a @code{target} region except on the initial device
2159 is not supported.
2161 @item @emph{C/C++}
2162 @multitable @columnfractions .20 .80
2163 @item @emph{Prototype}: @tab @code{int omp_target_memcpy(void *dst,}
2164 @item                   @tab @code{                           const void *src,}
2165 @item                   @tab @code{                           size_t length,}
2166 @item                   @tab @code{                           size_t dst_offset,}
2167 @item                   @tab @code{                           size_t src_offset,}
2168 @item                   @tab @code{                           int dst_device_num,}
2169 @item                   @tab @code{                           int src_device_num)}
2170 @end multitable
2172 @item @emph{Fortran}:
2173 @multitable @columnfractions .20 .80
2174 @item @emph{Interface}: @tab @code{integer(c_int) function omp_target_memcpy( &}
2175 @item                   @tab @code{    dst, src, length, dst_offset, src_offset, &}
2176 @item                   @tab @code{    dst_device_num, src_device_num) bind(C)}
2177 @item                   @tab @code{use, intrinsic :: iso_c_binding, only: c_ptr, c_size_t, c_int}
2178 @item                   @tab @code{type(c_ptr), value :: dst, src}
2179 @item                   @tab @code{integer(c_size_t), value :: length, dst_offset, src_offset}
2180 @item                   @tab @code{integer(c_int), value :: dst_device_num, src_device_num}
2181 @end multitable
2183 @item @emph{See also}:
2184 @ref{omp_target_memcpy_async}, @ref{omp_target_memcpy_rect}
2186 @item @emph{Reference}:
2187 @uref{https://www.openmp.org, OpenMP specification v5.1}, Section 3.8.5
2188 @end table
2192 @node omp_target_memcpy_async
2193 @subsection @code{omp_target_memcpy_async} -- Copy data between devices asynchronously
2194 @table @asis
2195 @item @emph{Description}:
2196 This routine copies asynchronously @var{length} of bytes of data from the
2197 device identified by device number @var{src_device_num} to device
2198 @var{dst_device_num}.  The data is copied from the source device from the
2199 address provided by @var{src}, shifted by the offset of @var{src_offset} bytes,
2200 to the destination device's @var{dst} address shifted by @var{dst_offset}.
2201 Task dependence is expressed by passing an array of depend objects to
2202 @var{depobj_list}, where the number of array elements is passed as
2203 @var{depobj_count}; if the count is zero, the @var{depobj_list} argument is
2204 ignored.  The routine returns zero if the copying process has successfully
2205 been started and non-zero otherwise.
2207 Running this routine in a @code{target} region except on the initial device
2208 is not supported.
2210 @item @emph{C/C++}
2211 @multitable @columnfractions .20 .80
2212 @item @emph{Prototype}: @tab @code{int omp_target_memcpy_async(void *dst,}
2213 @item                   @tab @code{                           const void *src,}
2214 @item                   @tab @code{                           size_t length,}
2215 @item                   @tab @code{                           size_t dst_offset,}
2216 @item                   @tab @code{                           size_t src_offset,}
2217 @item                   @tab @code{                           int dst_device_num,}
2218 @item                   @tab @code{                           int src_device_num,}
2219 @item                   @tab @code{                           int depobj_count,}
2220 @item                   @tab @code{                           omp_depend_t *depobj_list)}
2221 @end multitable
2223 @item @emph{Fortran}:
2224 @multitable @columnfractions .20 .80
2225 @item @emph{Interface}: @tab @code{integer(c_int) function omp_target_memcpy_async( &}
2226 @item                   @tab @code{    dst, src, length, dst_offset, src_offset, &}
2227 @item                   @tab @code{    dst_device_num, src_device_num, &}
2228 @item                   @tab @code{    depobj_count, depobj_list) bind(C)}
2229 @item                   @tab @code{use, intrinsic :: iso_c_binding, only: c_ptr, c_size_t, c_int}
2230 @item                   @tab @code{type(c_ptr), value :: dst, src}
2231 @item                   @tab @code{integer(c_size_t), value :: length, dst_offset, src_offset}
2232 @item                   @tab @code{integer(c_int), value :: dst_device_num, src_device_num, depobj_count}
2233 @item                   @tab @code{integer(omp_depend_kind), optional :: depobj_list(*)}
2234 @end multitable
2236 @item @emph{See also}:
2237 @ref{omp_target_memcpy}, @ref{omp_target_memcpy_rect_async}
2239 @item @emph{Reference}:
2240 @uref{https://www.openmp.org, OpenMP specification v5.1}, Section 3.8.7
2241 @end table
2245 @node omp_target_memcpy_rect
2246 @subsection @code{omp_target_memcpy_rect} -- Copy a subvolume of data between devices
2247 @table @asis
2248 @item @emph{Description}:
2249 This routine copies a subvolume of data from the device identified by
2250 device number @var{src_device_num} to device @var{dst_device_num}. 
2251 The array has @var{num_dims} dimensions and each array element has a size of
2252 @var{element_size} bytes.  The @var{volume} array specifies how many elements
2253 per dimension are copied.  The full sizes of the destination and source arrays
2254 are given by the @var{dst_dimensions} and @var{src_dimensions} arguments,
2255 respectively.  The offset per dimension to the first element to be copied is
2256 given by the @var{dst_offset} and @var{src_offset} arguments.  The routine
2257 returns zero on success and non-zero otherwise.
2259 The OpenMP specification only requires that @var{num_dims} up to three is
2260 supported.  In order to find implementation-specific maximally supported number
2261 of dimensions, the routine returns this value when invoked with a null pointer
2262 to both the @var{dst} and @var{src} arguments.  As GCC supports arbitrary
2263 dimensions, it returns @code{INT_MAX}.
2265 The device-number arguments must be conforming device numbers, the @var{src} and
2266 @var{dst} must be either both null pointers or all of the following must be
2267 fulfilled: @var{element_size} and @var{num_dims} must be positive and the
2268 @var{volume}, offset and dimension arrays must have at least @var{num_dims}
2269 dimensions.
2271 Running this routine in a @code{target} region is not supported except on
2272 the initial device.
2274 @item @emph{C/C++}
2275 @multitable @columnfractions .20 .80
2276 @item @emph{Prototype}: @tab @code{int omp_target_memcpy_rect(void *dst,}
2277 @item                   @tab @code{                           const void *src,}
2278 @item                   @tab @code{                           size_t element_size,}
2279 @item                   @tab @code{                           int num_dims,}
2280 @item                   @tab @code{                           const size_t *volume,}
2281 @item                   @tab @code{                           const size_t *dst_offset,}
2282 @item                   @tab @code{                           const size_t *src_offset,}
2283 @item                   @tab @code{                           const size_t *dst_dimensions,}
2284 @item                   @tab @code{                           const size_t *src_dimensions,}
2285 @item                   @tab @code{                           int dst_device_num,}
2286 @item                   @tab @code{                           int src_device_num)}
2287 @end multitable
2289 @item @emph{Fortran}:
2290 @multitable @columnfractions .20 .80
2291 @item @emph{Interface}: @tab @code{integer(c_int) function omp_target_memcpy_rect( &}
2292 @item                   @tab @code{    dst, src, element_size, num_dims, volume, &}
2293 @item                   @tab @code{    dst_offset, src_offset, dst_dimensions, &}
2294 @item                   @tab @code{    src_dimensions, dst_device_num, src_device_num) bind(C)}
2295 @item                   @tab @code{use, intrinsic :: iso_c_binding, only: c_ptr, c_size_t, c_int}
2296 @item                   @tab @code{type(c_ptr), value :: dst, src}
2297 @item                   @tab @code{integer(c_size_t), value :: element_size, dst_offset, src_offset}
2298 @item                   @tab @code{integer(c_size_t), value :: volume, dst_dimensions, src_dimensions}
2299 @item                   @tab @code{integer(c_int), value :: num_dims, dst_device_num, src_device_num}
2300 @end multitable
2302 @item @emph{See also}:
2303 @ref{omp_target_memcpy_rect_async}, @ref{omp_target_memcpy}
2305 @item @emph{Reference}:
2306 @uref{https://www.openmp.org, OpenMP specification v5.1}, Section 3.8.6
2307 @end table
2311 @node omp_target_memcpy_rect_async
2312 @subsection @code{omp_target_memcpy_rect_async} -- Copy a subvolume of data between devices asynchronously
2313 @table @asis
2314 @item @emph{Description}:
2315 This routine copies asynchronously a subvolume of data from the device
2316 identified by device number @var{src_device_num} to device @var{dst_device_num}.
2317 The array has @var{num_dims} dimensions and each array element has a size of
2318 @var{element_size} bytes.  The @var{volume} array specifies how many elements
2319 per dimension are copied.  The full sizes of the destination and source arrays
2320 are given by the @var{dst_dimensions} and @var{src_dimensions} arguments,
2321 respectively.  The offset per dimension to the first element to be copied is
2322 given by the @var{dst_offset} and @var{src_offset} arguments.  Task dependence
2323 is expressed by passing an array of depend objects to @var{depobj_list}, where
2324 the number of array elements is passed as @var{depobj_count}; if the count is
2325 zero, the @var{depobj_list} argument is ignored.  The routine
2326 returns zero on success and non-zero otherwise.
2328 The OpenMP specification only requires that @var{num_dims} up to three is
2329 supported.  In order to find implementation-specific maximally supported number
2330 of dimensions, the routine returns this value when invoked with a null pointer
2331 to both the @var{dst} and @var{src} arguments.  As GCC supports arbitrary
2332 dimensions, it returns @code{INT_MAX}.
2334 The device-number arguments must be conforming device numbers, the @var{src} and
2335 @var{dst} must be either both null pointers or all of the following must be
2336 fulfilled: @var{element_size} and @var{num_dims} must be positive and the
2337 @var{volume}, offset and dimension arrays must have at least @var{num_dims}
2338 dimensions.
2340 Running this routine in a @code{target} region is not supported except on
2341 the initial device.
2343 @item @emph{C/C++}
2344 @multitable @columnfractions .20 .80
2345 @item @emph{Prototype}: @tab @code{int omp_target_memcpy_rect_async(void *dst,}
2346 @item                   @tab @code{                           const void *src,}
2347 @item                   @tab @code{                           size_t element_size,}
2348 @item                   @tab @code{                           int num_dims,}
2349 @item                   @tab @code{                           const size_t *volume,}
2350 @item                   @tab @code{                           const size_t *dst_offset,}
2351 @item                   @tab @code{                           const size_t *src_offset,}
2352 @item                   @tab @code{                           const size_t *dst_dimensions,}
2353 @item                   @tab @code{                           const size_t *src_dimensions,}
2354 @item                   @tab @code{                           int dst_device_num,}
2355 @item                   @tab @code{                           int src_device_num,}
2356 @item                   @tab @code{                           int depobj_count,}
2357 @item                   @tab @code{                           omp_depend_t *depobj_list)}
2358 @end multitable
2360 @item @emph{Fortran}:
2361 @multitable @columnfractions .20 .80
2362 @item @emph{Interface}: @tab @code{integer(c_int) function omp_target_memcpy_rect_async( &}
2363 @item                   @tab @code{    dst, src, element_size, num_dims, volume, &}
2364 @item                   @tab @code{    dst_offset, src_offset, dst_dimensions, &}
2365 @item                   @tab @code{    src_dimensions, dst_device_num, src_device_num, &}
2366 @item                   @tab @code{    depobj_count, depobj_list) bind(C)}
2367 @item                   @tab @code{use, intrinsic :: iso_c_binding, only: c_ptr, c_size_t, c_int}
2368 @item                   @tab @code{type(c_ptr), value :: dst, src}
2369 @item                   @tab @code{integer(c_size_t), value :: element_size, dst_offset, src_offset}
2370 @item                   @tab @code{integer(c_size_t), value :: volume, dst_dimensions, src_dimensions}
2371 @item                   @tab @code{integer(c_int), value :: num_dims, dst_device_num, src_device_num}
2372 @item                   @tab @code{integer(c_int), value :: depobj_count}
2373 @item                   @tab @code{integer(omp_depend_kind), optional :: depobj_list(*)}
2374 @end multitable
2376 @item @emph{See also}:
2377 @ref{omp_target_memcpy_rect}, @ref{omp_target_memcpy_async}
2379 @item @emph{Reference}:
2380 @uref{https://www.openmp.org, OpenMP specification v5.1}, Section 3.8.8
2381 @end table
2385 @node omp_target_associate_ptr
2386 @subsection @code{omp_target_associate_ptr} -- Associate a device pointer with a host pointer
2387 @table @asis
2388 @item @emph{Description}:
2389 This routine associates storage on the host with storage on a device identified
2390 by @var{device_num}.  The device pointer is usually obtained by calling
2391 @code{omp_target_alloc} or by other means (but not by using the @code{map}
2392 clauses or the @code{declare target} directive).  The host pointer should point
2393 to memory that has a storage size of at least @var{size}.
2395 The @var{device_offset} parameter specifies the offset into @var{device_ptr}
2396 that is used as the base address for the device side of the mapping; the
2397 storage size should be at least @var{device_offset} plus @var{size}.
2399 After the association, the host pointer can be used in a @code{map} clause and
2400 in the @code{to} and @code{from} clauses of the @code{target update} directive
2401 to transfer data between the associated pointers. The reference count of such
2402 associated storage is infinite.  The association can be removed by calling
2403 @code{omp_target_disassociate_ptr} which should be done before the lifetime
2404 of either storage ends.
2406 The routine returns nonzero (@code{EINVAL}) when the @var{device_num} invalid,
2407 for when the initial device or the associated device shares memory with the
2408 host.  @code{omp_target_associate_ptr} returns zero if @var{host_ptr} points
2409 into already associated storage that is fully inside of a previously associated
2410 memory.  Otherwise, if the association was successful zero is returned; if none
2411 of the cases above apply, nonzero (@code{EINVAL}) is returned.
2413 The @code{omp_target_is_present} routine can be used to test whether
2414 associated storage for a device pointer exists.
2416 Running this routine in a @code{target} region except on the initial device
2417 is not supported.
2419 @item @emph{C/C++}
2420 @multitable @columnfractions .20 .80
2421 @item @emph{Prototype}: @tab @code{int omp_target_associate_ptr(const void *host_ptr,}
2422 @item                   @tab @code{                             const void *device_ptr,}
2423 @item                   @tab @code{                             size_t size,}
2424 @item                   @tab @code{                             size_t device_offset,}
2425 @item                   @tab @code{                             int device_num)}
2426 @end multitable
2428 @item @emph{Fortran}:
2429 @multitable @columnfractions .20 .80
2430 @item @emph{Interface}: @tab @code{integer(c_int) function omp_target_associate_ptr(host_ptr, &}
2431 @item                   @tab @code{    device_ptr, size, device_offset, device_num) bind(C)}
2432 @item                   @tab @code{use, intrinsic :: iso_c_binding, only: c_ptr, c_int, c_size_t}
2433 @item                   @tab @code{type(c_ptr), value :: host_ptr, device_ptr}
2434 @item                   @tab @code{integer(c_size_t), value :: size, device_offset}
2435 @item                   @tab @code{integer(c_int), value :: device_num}
2436 @end multitable
2438 @item @emph{See also}:
2439 @ref{omp_target_disassociate_ptr}, @ref{omp_target_is_present},
2440 @ref{omp_target_alloc}
2442 @item @emph{Reference}:
2443 @uref{https://www.openmp.org, OpenMP specification v5.1}, Section 3.8.9
2444 @end table
2448 @node omp_target_disassociate_ptr
2449 @subsection @code{omp_target_disassociate_ptr} -- Remove device--host pointer association
2450 @table @asis
2451 @item @emph{Description}:
2452 This routine removes the storage association established by calling
2453 @code{omp_target_associate_ptr} and sets the reference count to zero,
2454 even if @code{omp_target_associate_ptr} was invoked multiple times for
2455 for host pointer @code{ptr}.  If applicable, the device memory needs
2456 to be freed by the user.
2458 If an associated device storage location for the @var{device_num} was
2459 found and has infinite reference count, the association is removed and
2460 zero is returned.  In all other cases, nonzero (@code{EINVAL}) is returned
2461 and no other action is taken.
2463 Note that passing a host pointer where the association to the device pointer
2464 was established with the @code{declare target} directive yields undefined
2465 behavior.
2467 Running this routine in a @code{target} region except on the initial device
2468 is not supported.
2470 @item @emph{C/C++}
2471 @multitable @columnfractions .20 .80
2472 @item @emph{Prototype}: @tab @code{int omp_target_disassociate_ptr(const void *ptr,}
2473 @item                   @tab @code{                                int device_num)}
2474 @end multitable
2476 @item @emph{Fortran}:
2477 @multitable @columnfractions .20 .80
2478 @item @emph{Interface}: @tab @code{integer(c_int) function omp_target_disassociate_ptr(ptr, &}
2479 @item                   @tab @code{    device_num) bind(C)}
2480 @item                   @tab @code{use, intrinsic :: iso_c_binding, only: c_ptr, c_int}
2481 @item                   @tab @code{type(c_ptr), value :: ptr}
2482 @item                   @tab @code{integer(c_int), value :: device_num}
2483 @end multitable
2485 @item @emph{See also}:
2486 @ref{omp_target_associate_ptr}
2488 @item @emph{Reference}:
2489 @uref{https://www.openmp.org, OpenMP specification v5.1}, Section 3.8.10
2490 @end table
2494 @node omp_get_mapped_ptr
2495 @subsection @code{omp_get_mapped_ptr} -- Return device pointer to a host pointer
2496 @table @asis
2497 @item @emph{Description}:
2498 If the device number is refers to the initial device or to a device with
2499 memory accessible from the host (shared memory), the @code{omp_get_mapped_ptr}
2500 routines returns the value of the passed @var{ptr}.  Otherwise, if associated
2501 storage to the passed host pointer @var{ptr} exists on device associated with
2502 @var{device_num}, it returns that pointer. In all other cases and in cases of
2503 an error, a null pointer is returned.
2505 The association of storage location is established either via an explicit or
2506 implicit @code{map} clause, the @code{declare target} directive or the
2507 @code{omp_target_associate_ptr} routine.
2509 Running this routine in a @code{target} region except on the initial device
2510 is not supported.
2512 @item @emph{C/C++}
2513 @multitable @columnfractions .20 .80
2514 @item @emph{Prototype}: @tab @code{void *omp_get_mapped_ptr(const void *ptr, int device_num);}
2515 @end multitable
2517 @item @emph{Fortran}:
2518 @multitable @columnfractions .20 .80
2519 @item @emph{Interface}: @tab @code{type(c_ptr) function omp_get_mapped_ptr(ptr, device_num) bind(C)}
2520 @item                   @tab @code{use, intrinsic :: iso_c_binding, only: c_ptr, c_int}
2521 @item                   @tab @code{type(c_ptr), value :: ptr}
2522 @item                   @tab @code{integer(c_int), value :: device_num}
2523 @end multitable
2525 @item @emph{See also}:
2526 @ref{omp_target_associate_ptr}
2528 @item @emph{Reference}:
2529 @uref{https://www.openmp.org, OpenMP specification v5.1}, Section 3.8.11
2530 @end table
2534 @node Lock Routines
2535 @section Lock Routines
2537 Initialize, set, test, unset and destroy simple and nested locks.
2538 The routines have C linkage and do not throw exceptions.
2540 @menu
2541 * omp_init_lock::            Initialize simple lock
2542 * omp_init_nest_lock::       Initialize nested lock
2543 @c PR libgomp/109452
2544 @c * omp_init_lock_with_hint:: Initialize simple lock with sync hint
2545 @c * omp_init_nest_lock_with_hint:: Initialize nested lock with sync hint
2546 * omp_destroy_lock::         Destroy simple lock
2547 * omp_destroy_nest_lock::    Destroy nested lock
2548 * omp_set_lock::             Wait for and set simple lock
2549 * omp_set_nest_lock::        Wait for and set simple lock
2550 * omp_unset_lock::           Unset simple lock
2551 * omp_unset_nest_lock::      Unset nested lock
2552 * omp_test_lock::            Test and set simple lock if available
2553 * omp_test_nest_lock::       Test and set nested lock if available
2554 @end menu
2558 @node omp_init_lock
2559 @subsection @code{omp_init_lock} -- Initialize simple lock
2560 @table @asis
2561 @item @emph{Description}:
2562 Initialize a simple lock.  After initialization, the lock is in
2563 an unlocked state.
2565 @item @emph{C/C++}:
2566 @multitable @columnfractions .20 .80
2567 @item @emph{Prototype}: @tab @code{void omp_init_lock(omp_lock_t *lock);}
2568 @end multitable
2570 @item @emph{Fortran}:
2571 @multitable @columnfractions .20 .80
2572 @item @emph{Interface}: @tab @code{subroutine omp_init_lock(svar)}
2573 @item                   @tab @code{integer(omp_lock_kind), intent(out) :: svar}
2574 @end multitable
2576 @item @emph{See also}:
2577 @ref{omp_destroy_lock}
2579 @item @emph{Reference}: 
2580 @uref{https://www.openmp.org, OpenMP specification v4.5}, Section 3.3.1.
2581 @end table
2585 @node omp_init_nest_lock
2586 @subsection @code{omp_init_nest_lock} -- Initialize nested lock
2587 @table @asis
2588 @item @emph{Description}:
2589 Initialize a nested lock.  After initialization, the lock is in
2590 an unlocked state and the nesting count is set to zero.
2592 @item @emph{C/C++}:
2593 @multitable @columnfractions .20 .80
2594 @item @emph{Prototype}: @tab @code{void omp_init_nest_lock(omp_nest_lock_t *lock);}
2595 @end multitable
2597 @item @emph{Fortran}:
2598 @multitable @columnfractions .20 .80
2599 @item @emph{Interface}: @tab @code{subroutine omp_init_nest_lock(nvar)}
2600 @item                   @tab @code{integer(omp_nest_lock_kind), intent(out) :: nvar}
2601 @end multitable
2603 @item @emph{See also}:
2604 @ref{omp_destroy_nest_lock}
2606 @item @emph{Reference}:
2607 @uref{https://www.openmp.org, OpenMP specification v4.5}, Section 3.3.1.
2608 @end table
2612 @node omp_destroy_lock
2613 @subsection @code{omp_destroy_lock} -- Destroy simple lock
2614 @table @asis
2615 @item @emph{Description}:
2616 Destroy a simple lock.  In order to be destroyed, a simple lock must be
2617 in the unlocked state. 
2619 @item @emph{C/C++}:
2620 @multitable @columnfractions .20 .80
2621 @item @emph{Prototype}: @tab @code{void omp_destroy_lock(omp_lock_t *lock);}
2622 @end multitable
2624 @item @emph{Fortran}:
2625 @multitable @columnfractions .20 .80
2626 @item @emph{Interface}: @tab @code{subroutine omp_destroy_lock(svar)}
2627 @item                   @tab @code{integer(omp_lock_kind), intent(inout) :: svar}
2628 @end multitable
2630 @item @emph{See also}:
2631 @ref{omp_init_lock}
2633 @item @emph{Reference}: 
2634 @uref{https://www.openmp.org, OpenMP specification v4.5}, Section 3.3.3.
2635 @end table
2639 @node omp_destroy_nest_lock
2640 @subsection @code{omp_destroy_nest_lock} -- Destroy nested lock
2641 @table @asis
2642 @item @emph{Description}:
2643 Destroy a nested lock.  In order to be destroyed, a nested lock must be
2644 in the unlocked state and its nesting count must equal zero.
2646 @item @emph{C/C++}:
2647 @multitable @columnfractions .20 .80
2648 @item @emph{Prototype}: @tab @code{void omp_destroy_nest_lock(omp_nest_lock_t *);}
2649 @end multitable
2651 @item @emph{Fortran}:
2652 @multitable @columnfractions .20 .80
2653 @item @emph{Interface}: @tab @code{subroutine omp_destroy_nest_lock(nvar)}
2654 @item                   @tab @code{integer(omp_nest_lock_kind), intent(inout) :: nvar}
2655 @end multitable
2657 @item @emph{See also}:
2658 @ref{omp_init_lock}
2660 @item @emph{Reference}: 
2661 @uref{https://www.openmp.org, OpenMP specification v4.5}, Section 3.3.3.
2662 @end table
2666 @node omp_set_lock
2667 @subsection @code{omp_set_lock} -- Wait for and set simple lock
2668 @table @asis
2669 @item @emph{Description}:
2670 Before setting a simple lock, the lock variable must be initialized by 
2671 @code{omp_init_lock}.  The calling thread is blocked until the lock 
2672 is available.  If the lock is already held by the current thread, 
2673 a deadlock occurs.
2675 @item @emph{C/C++}:
2676 @multitable @columnfractions .20 .80
2677 @item @emph{Prototype}: @tab @code{void omp_set_lock(omp_lock_t *lock);}
2678 @end multitable
2680 @item @emph{Fortran}:
2681 @multitable @columnfractions .20 .80
2682 @item @emph{Interface}: @tab @code{subroutine omp_set_lock(svar)}
2683 @item                   @tab @code{integer(omp_lock_kind), intent(inout) :: svar}
2684 @end multitable
2686 @item @emph{See also}:
2687 @ref{omp_init_lock}, @ref{omp_test_lock}, @ref{omp_unset_lock}
2689 @item @emph{Reference}: 
2690 @uref{https://www.openmp.org, OpenMP specification v4.5}, Section 3.3.4.
2691 @end table
2695 @node omp_set_nest_lock
2696 @subsection @code{omp_set_nest_lock} -- Wait for and set nested lock
2697 @table @asis
2698 @item @emph{Description}:
2699 Before setting a nested lock, the lock variable must be initialized by 
2700 @code{omp_init_nest_lock}.  The calling thread is blocked until the lock
2701 is available.  If the lock is already held by the current thread, the
2702 nesting count for the lock is incremented.
2704 @item @emph{C/C++}:
2705 @multitable @columnfractions .20 .80
2706 @item @emph{Prototype}: @tab @code{void omp_set_nest_lock(omp_nest_lock_t *lock);}
2707 @end multitable
2709 @item @emph{Fortran}:
2710 @multitable @columnfractions .20 .80
2711 @item @emph{Interface}: @tab @code{subroutine omp_set_nest_lock(nvar)}
2712 @item                   @tab @code{integer(omp_nest_lock_kind), intent(inout) :: nvar}
2713 @end multitable
2715 @item @emph{See also}:
2716 @ref{omp_init_nest_lock}, @ref{omp_unset_nest_lock}
2718 @item @emph{Reference}: 
2719 @uref{https://www.openmp.org, OpenMP specification v4.5}, Section 3.3.4.
2720 @end table
2724 @node omp_unset_lock
2725 @subsection @code{omp_unset_lock} -- Unset simple lock
2726 @table @asis
2727 @item @emph{Description}:
2728 A simple lock about to be unset must have been locked by @code{omp_set_lock}
2729 or @code{omp_test_lock} before.  In addition, the lock must be held by the
2730 thread calling @code{omp_unset_lock}.  Then, the lock becomes unlocked.  If one
2731 or more threads attempted to set the lock before, one of them is chosen to,
2732 again, set the lock to itself.
2734 @item @emph{C/C++}:
2735 @multitable @columnfractions .20 .80
2736 @item @emph{Prototype}: @tab @code{void omp_unset_lock(omp_lock_t *lock);}
2737 @end multitable
2739 @item @emph{Fortran}:
2740 @multitable @columnfractions .20 .80
2741 @item @emph{Interface}: @tab @code{subroutine omp_unset_lock(svar)}
2742 @item                   @tab @code{integer(omp_lock_kind), intent(inout) :: svar}
2743 @end multitable
2745 @item @emph{See also}:
2746 @ref{omp_set_lock}, @ref{omp_test_lock}
2748 @item @emph{Reference}: 
2749 @uref{https://www.openmp.org, OpenMP specification v4.5}, Section 3.3.5.
2750 @end table
2754 @node omp_unset_nest_lock
2755 @subsection @code{omp_unset_nest_lock} -- Unset nested lock
2756 @table @asis
2757 @item @emph{Description}:
2758 A nested lock about to be unset must have been locked by @code{omp_set_nested_lock}
2759 or @code{omp_test_nested_lock} before.  In addition, the lock must be held by the
2760 thread calling @code{omp_unset_nested_lock}.  If the nesting count drops to zero, the
2761 lock becomes unlocked.  If one ore more threads attempted to set the lock before,
2762 one of them is chosen to, again, set the lock to itself.
2764 @item @emph{C/C++}:
2765 @multitable @columnfractions .20 .80
2766 @item @emph{Prototype}: @tab @code{void omp_unset_nest_lock(omp_nest_lock_t *lock);}
2767 @end multitable
2769 @item @emph{Fortran}:
2770 @multitable @columnfractions .20 .80
2771 @item @emph{Interface}: @tab @code{subroutine omp_unset_nest_lock(nvar)}
2772 @item                   @tab @code{integer(omp_nest_lock_kind), intent(inout) :: nvar}
2773 @end multitable
2775 @item @emph{See also}:
2776 @ref{omp_set_nest_lock}
2778 @item @emph{Reference}: 
2779 @uref{https://www.openmp.org, OpenMP specification v4.5}, Section 3.3.5.
2780 @end table
2784 @node omp_test_lock
2785 @subsection @code{omp_test_lock} -- Test and set simple lock if available
2786 @table @asis
2787 @item @emph{Description}:
2788 Before setting a simple lock, the lock variable must be initialized by 
2789 @code{omp_init_lock}.  Contrary to @code{omp_set_lock}, @code{omp_test_lock} 
2790 does not block if the lock is not available.  This function returns
2791 @code{true} upon success, @code{false} otherwise.  Here, @code{true} and
2792 @code{false} represent their language-specific counterparts.
2794 @item @emph{C/C++}:
2795 @multitable @columnfractions .20 .80
2796 @item @emph{Prototype}: @tab @code{int omp_test_lock(omp_lock_t *lock);}
2797 @end multitable
2799 @item @emph{Fortran}:
2800 @multitable @columnfractions .20 .80
2801 @item @emph{Interface}: @tab @code{logical function omp_test_lock(svar)}
2802 @item                   @tab @code{integer(omp_lock_kind), intent(inout) :: svar}
2803 @end multitable
2805 @item @emph{See also}:
2806 @ref{omp_init_lock}, @ref{omp_set_lock}, @ref{omp_set_lock}
2808 @item @emph{Reference}: 
2809 @uref{https://www.openmp.org, OpenMP specification v4.5}, Section 3.3.6.
2810 @end table
2814 @node omp_test_nest_lock
2815 @subsection @code{omp_test_nest_lock} -- Test and set nested lock if available
2816 @table @asis
2817 @item @emph{Description}:
2818 Before setting a nested lock, the lock variable must be initialized by 
2819 @code{omp_init_nest_lock}.  Contrary to @code{omp_set_nest_lock},
2820 @code{omp_test_nest_lock} does not block if the lock is not available. 
2821 If the lock is already held by the current thread, the new nesting count 
2822 is returned.  Otherwise, the return value equals zero.
2824 @item @emph{C/C++}:
2825 @multitable @columnfractions .20 .80
2826 @item @emph{Prototype}: @tab @code{int omp_test_nest_lock(omp_nest_lock_t *lock);}
2827 @end multitable
2829 @item @emph{Fortran}:
2830 @multitable @columnfractions .20 .80
2831 @item @emph{Interface}: @tab @code{logical function omp_test_nest_lock(nvar)}
2832 @item                   @tab @code{integer(omp_nest_lock_kind), intent(inout) :: nvar}
2833 @end multitable
2836 @item @emph{See also}:
2837 @ref{omp_init_lock}, @ref{omp_set_lock}, @ref{omp_set_lock}
2839 @item @emph{Reference}: 
2840 @uref{https://www.openmp.org, OpenMP specification v4.5}, Section 3.3.6.
2841 @end table
2845 @node Timing Routines
2846 @section Timing Routines
2848 Portable, thread-based, wall clock timer.
2849 The routines have C linkage and do not throw exceptions.
2851 @menu
2852 * omp_get_wtick::            Get timer precision.
2853 * omp_get_wtime::            Elapsed wall clock time.
2854 @end menu
2858 @node omp_get_wtick
2859 @subsection @code{omp_get_wtick} -- Get timer precision
2860 @table @asis
2861 @item @emph{Description}:
2862 Gets the timer precision, i.e., the number of seconds between two 
2863 successive clock ticks.
2865 @item @emph{C/C++}:
2866 @multitable @columnfractions .20 .80
2867 @item @emph{Prototype}: @tab @code{double omp_get_wtick(void);}
2868 @end multitable
2870 @item @emph{Fortran}:
2871 @multitable @columnfractions .20 .80
2872 @item @emph{Interface}: @tab @code{double precision function omp_get_wtick()}
2873 @end multitable
2875 @item @emph{See also}:
2876 @ref{omp_get_wtime}
2878 @item @emph{Reference}: 
2879 @uref{https://www.openmp.org, OpenMP specification v4.5}, Section 3.4.2.
2880 @end table
2884 @node omp_get_wtime
2885 @subsection @code{omp_get_wtime} -- Elapsed wall clock time
2886 @table @asis
2887 @item @emph{Description}:
2888 Elapsed wall clock time in seconds.  The time is measured per thread, no
2889 guarantee can be made that two distinct threads measure the same time.
2890 Time is measured from some "time in the past", which is an arbitrary time
2891 guaranteed not to change during the execution of the program.
2893 @item @emph{C/C++}:
2894 @multitable @columnfractions .20 .80
2895 @item @emph{Prototype}: @tab @code{double omp_get_wtime(void);}
2896 @end multitable
2898 @item @emph{Fortran}:
2899 @multitable @columnfractions .20 .80
2900 @item @emph{Interface}: @tab @code{double precision function omp_get_wtime()}
2901 @end multitable
2903 @item @emph{See also}:
2904 @ref{omp_get_wtick}
2906 @item @emph{Reference}: 
2907 @uref{https://www.openmp.org, OpenMP specification v4.5}, Section 3.4.1.
2908 @end table
2912 @node Event Routine
2913 @section Event Routine
2915 Support for event objects.
2916 The routine has C linkage and do not throw exceptions.
2918 @menu
2919 * omp_fulfill_event::        Fulfill and destroy an OpenMP event.
2920 @end menu
2924 @node omp_fulfill_event
2925 @subsection @code{omp_fulfill_event} -- Fulfill and destroy an OpenMP event
2926 @table @asis
2927 @item @emph{Description}:
2928 Fulfill the event associated with the event handle argument.  Currently, it
2929 is only used to fulfill events generated by detach clauses on task
2930 constructs - the effect of fulfilling the event is to allow the task to
2931 complete.
2933 The result of calling @code{omp_fulfill_event} with an event handle other
2934 than that generated by a detach clause is undefined.  Calling it with an
2935 event handle that has already been fulfilled is also undefined.
2937 @item @emph{C/C++}:
2938 @multitable @columnfractions .20 .80
2939 @item @emph{Prototype}: @tab @code{void omp_fulfill_event(omp_event_handle_t event);}
2940 @end multitable
2942 @item @emph{Fortran}:
2943 @multitable @columnfractions .20 .80
2944 @item @emph{Interface}: @tab @code{subroutine omp_fulfill_event(event)}
2945 @item                   @tab @code{integer (kind=omp_event_handle_kind) :: event}
2946 @end multitable
2948 @item @emph{Reference}:
2949 @uref{https://www.openmp.org, OpenMP specification v5.0}, Section 3.5.1.
2950 @end table
2954 @c @node Interoperability Routines
2955 @c @section Interoperability Routines
2957 @c Routines to obtain properties from an @code{omp_interop_t} object.
2958 @c They have C linkage and do not throw exceptions.
2960 @c @menu
2961 @c * omp_get_num_interop_properties:: <fixme>
2962 @c * omp_get_interop_int:: <fixme>
2963 @c * omp_get_interop_ptr:: <fixme>
2964 @c * omp_get_interop_str:: <fixme>
2965 @c * omp_get_interop_name:: <fixme>
2966 @c * omp_get_interop_type_desc:: <fixme>
2967 @c * omp_get_interop_rc_desc:: <fixme>
2968 @c @end menu
2970 @node Memory Management Routines
2971 @section Memory Management Routines
2973 Routines to manage and allocate memory on the current device.
2974 They have C linkage and do not throw exceptions.
2976 @menu
2977 @c * omp_get_devices_memspace:: <fixme>/TR13
2978 @c * omp_get_device_memspace:: <fixme>/TR13
2979 @c * omp_get_devices_and_host_memspace:: <fixme>/TR13
2980 @c * omp_get_device_and_host_memspace:: <fixme>/TR13
2981 @c * omp_get_devices_all_memspace:: <fixme>/TR13
2982 @c * omp_get_memspace_num_resources:: <fixme>/TR11
2983 @c * omp_get_memspace_pagesize:: <fixme>/TR13
2984 @c * omp_get_submemspace:: <fixme>/TR11
2985 @c * omp_init_mempartitioner:: <fixme>/TR13
2986 @c * omp_destroy_mempartitioner:: <fixme>/TR13
2987 @c * omp_init_mempartition:: <fixme>/TR13
2988 @c * omp_destroy_mempartition:: <fixme>/TR13
2989 @c * omp_mempartition_set_part:: <fixme>/TR13
2990 @c * omp_mempartition_get_user_data:: <fixme>/TR13
2991 * omp_init_allocator:: Create an allocator
2992 * omp_destroy_allocator:: Destroy an allocator
2993 @c * omp_get_devices_allocator:: <fixme>/TR13
2994 @c * omp_get_device_allocator:: <fixme>/TR13
2995 @c * omp_get_devices_and_host_allocator:: <fixme>/TR13
2996 @c * omp_get_device_and_host_allocator:: <fixme>/TR13
2997 @c * omp_get_devices_all_allocator:: <fixme>/TR13
2998 * omp_set_default_allocator:: Set the default allocator
2999 * omp_get_default_allocator:: Get the default allocator
3000 * omp_alloc:: Memory allocation with an allocator
3001 * omp_aligned_alloc:: Memory allocation with an allocator and alignment
3002 * omp_free:: Freeing memory allocated with OpenMP routines
3003 * omp_calloc:: Allocate nullified memory with an allocator
3004 * omp_aligned_calloc:: Allocate nullified aligned memory with an allocator
3005 * omp_realloc:: Reallocate memory allocated with OpenMP routines
3006 @end menu
3010 @node omp_init_allocator
3011 @subsection @code{omp_init_allocator} -- Create an allocator
3012 @table @asis
3013 @item @emph{Description}:
3014 Create an allocator that uses the specified memory space and has the specified
3015 traits; if an allocator that fulfills the requirements cannot be created,
3016 @code{omp_null_allocator} is returned.
3018 The predefined memory spaces and available traits can be found at
3019 @ref{OMP_ALLOCATOR}, where the trait names have to be prefixed by
3020 @code{omp_atk_} (e.g. @code{omp_atk_pinned}) and the named trait values by
3021 @code{omp_atv_} (e.g. @code{omp_atv_true}); additionally, @code{omp_atv_default}
3022 may be used as trait value to specify that the default value should be used.
3024 @item @emph{C/C++}:
3025 @multitable @columnfractions .20 .80
3026 @item @emph{Prototype}: @tab @code{omp_allocator_handle_t omp_init_allocator(}
3027 @item                   @tab @code{  omp_memspace_handle_t memspace,}
3028 @item                   @tab @code{  int ntraits,}
3029 @item                   @tab @code{  const omp_alloctrait_t traits[]);}
3030 @end multitable
3032 @item @emph{Fortran}:
3033 @multitable @columnfractions .20 .80
3034 @item @emph{Interface}: @tab @code{function omp_init_allocator(memspace, ntraits, traits)}
3035 @item                   @tab @code{integer (omp_allocator_handle_kind) :: omp_init_allocator}
3036 @item                   @tab @code{integer (omp_memspace_handle_kind), intent(in) :: memspace}
3037 @item                   @tab @code{integer, intent(in) :: ntraits}
3038 @item                   @tab @code{type (omp_alloctrait), intent(in) :: traits(*)}
3039 @end multitable
3041 @item @emph{See also}:
3042 @ref{OMP_ALLOCATOR}, @ref{Memory allocation}, @ref{omp_destroy_allocator}
3044 @item @emph{Reference}:
3045 @uref{https://www.openmp.org, OpenMP specification v5.0}, Section 3.7.2
3046 @end table
3050 @node omp_destroy_allocator
3051 @subsection @code{omp_destroy_allocator} -- Destroy an allocator
3052 @table @asis
3053 @item @emph{Description}:
3054 Releases all resources used by a memory allocator, which must not represent
3055 a predefined memory allocator.  Accessing memory after its allocator has been
3056 destroyed has unspecified behavior.  Passing @code{omp_null_allocator} to the
3057 routine is permitted but has no effect.
3060 @item @emph{C/C++}:
3061 @multitable @columnfractions .20 .80
3062 @item @emph{Prototype}: @tab @code{void omp_destroy_allocator (omp_allocator_handle_t allocator);}
3063 @end multitable
3065 @item @emph{Fortran}:
3066 @multitable @columnfractions .20 .80
3067 @item @emph{Interface}: @tab @code{subroutine omp_destroy_allocator(allocator)}
3068 @item                   @tab @code{integer (omp_allocator_handle_kind), intent(in) :: allocator}
3069 @end multitable
3071 @item @emph{See also}:
3072 @ref{omp_init_allocator}
3074 @item @emph{Reference}:
3075 @uref{https://www.openmp.org, OpenMP specification v5.0}, Section 3.7.3
3076 @end table
3080 @node omp_set_default_allocator
3081 @subsection @code{omp_set_default_allocator} -- Set the default allocator
3082 @table @asis
3083 @item @emph{Description}:
3084 Sets the default allocator that is used when no allocator has been specified
3085 in the @code{allocate} or @code{allocator} clause or if an OpenMP memory
3086 routine is invoked with the @code{omp_null_allocator} allocator.
3088 @item @emph{C/C++}:
3089 @multitable @columnfractions .20 .80
3090 @item @emph{Prototype}: @tab @code{void omp_set_default_allocator(omp_allocator_handle_t allocator);}
3091 @end multitable
3093 @item @emph{Fortran}:
3094 @multitable @columnfractions .20 .80
3095 @item @emph{Interface}: @tab @code{subroutine omp_set_default_allocator(allocator)}
3096 @item                   @tab @code{integer (omp_allocator_handle_kind), intent(in) :: allocator}
3097 @end multitable
3099 @item @emph{See also}:
3100 @ref{omp_get_default_allocator}, @ref{omp_init_allocator}, @ref{OMP_ALLOCATOR},
3101 @ref{Memory allocation}
3103 @item @emph{Reference}:
3104 @uref{https://www.openmp.org, OpenMP specification v5.0}, Section 3.7.4
3105 @end table
3109 @node omp_get_default_allocator
3110 @subsection @code{omp_get_default_allocator} -- Get the default allocator
3111 @table @asis
3112 @item @emph{Description}:
3113 The routine returns the default allocator that is used when no allocator has
3114 been specified in the @code{allocate} or @code{allocator} clause or if an
3115 OpenMP memory routine is invoked with the @code{omp_null_allocator} allocator.
3117 @item @emph{C/C++}:
3118 @multitable @columnfractions .20 .80
3119 @item @emph{Prototype}: @tab @code{omp_allocator_handle_t omp_get_default_allocator();}
3120 @end multitable
3122 @item @emph{Fortran}:
3123 @multitable @columnfractions .20 .80
3124 @item @emph{Interface}: @tab @code{function omp_get_default_allocator()}
3125 @item                   @tab @code{integer (omp_allocator_handle_kind) :: omp_get_default_allocator}
3126 @end multitable
3128 @item @emph{See also}:
3129 @ref{omp_set_default_allocator}, @ref{OMP_ALLOCATOR}
3131 @item @emph{Reference}:
3132 @uref{https://www.openmp.org, OpenMP specification v5.0}, Section 3.7.5
3133 @end table
3137 @node omp_alloc
3138 @subsection @code{omp_alloc} -- Memory allocation with an allocator
3139 @table @asis
3140 @item @emph{Description}:
3141 Allocate memory with the specified allocator, which can either be a predefined
3142 allocator, an allocator handle or @code{omp_null_allocator}.  If the allocators
3143 is @code{omp_null_allocator}, the allocator specified by the
3144 @var{def-allocator-var} ICV is used.  @var{size} must be a nonnegative number
3145 denoting the number of bytes to be allocated; if @var{size} is zero,
3146 @code{omp_alloc} will return a null pointer.  If successful, a pointer to the
3147 allocated memory is returned, otherwise the @code{fallback} trait of the
3148 allocator determines the behavior.  The content of the allocated memory is
3149 unspecified.
3151 In @code{target} regions, either the @code{dynamic_allocators} clause must
3152 appear on a @code{requires} directive in the same compilation unit -- or the
3153 @var{allocator} argument may only be a constant expression with the value of
3154 one of the predefined allocators and may not be @code{omp_null_allocator}.
3156 Memory allocated by @code{omp_alloc} must be freed using @code{omp_free}.
3158 @item @emph{C}:
3159 @multitable @columnfractions .20 .80
3160 @item @emph{Prototype}: @tab @code{void* omp_alloc(size_t size,}
3161 @item                   @tab @code{  omp_allocator_handle_t allocator)}
3162 @end multitable
3164 @item @emph{C++}:
3165 @multitable @columnfractions .20 .80
3166 @item @emph{Prototype}: @tab @code{void* omp_alloc(size_t size,}
3167 @item                   @tab @code{  omp_allocator_handle_t allocator=omp_null_allocator)}
3168 @end multitable
3170 @item @emph{Fortran}:
3171 @multitable @columnfractions .20 .80
3172 @item @emph{Interface}: @tab @code{type(c_ptr) function omp_alloc(size, allocator) bind(C)}
3173 @item                   @tab @code{use, intrinsic :: iso_c_binding, only : c_ptr, c_size_t}
3174 @item                   @tab @code{integer (c_size_t), value :: size}
3175 @item                   @tab @code{integer (omp_allocator_handle_kind), value :: allocator}
3176 @end multitable
3178 @item @emph{See also}:
3179 @ref{OMP_ALLOCATOR}, @ref{Memory allocation}, @ref{omp_set_default_allocator},
3180 @ref{omp_free}, @ref{omp_init_allocator}
3182 @item @emph{Reference}:
3183 @uref{https://www.openmp.org, OpenMP specification v5.0}, Section 3.7.6
3184 @end table
3188 @node omp_aligned_alloc
3189 @subsection @code{omp_aligned_alloc} -- Memory allocation with an allocator and alignment
3190 @table @asis
3191 @item @emph{Description}:
3192 Allocate memory with the specified allocator, which can either be a predefined
3193 allocator, an allocator handle or @code{omp_null_allocator}.  If the allocators
3194 is @code{omp_null_allocator}, the allocator specified by the
3195 @var{def-allocator-var} ICV is used.  @var{alignment} must be a positive power
3196 of two and @var{size} must be a nonnegative number that is a multiple of the
3197 alignment and denotes the number of bytes to be allocated; if @var{size} is
3198 zero, @code{omp_aligned_alloc} will return a null pointer.  The alignment will
3199 be at least the maximal value required by @code{alignment} trait of the
3200 allocator and the value of the  passed @var{alignment} argument.  If successful,
3201 a pointer to the allocated memory is returned, otherwise the @code{fallback}
3202 trait of the allocator determines the behavior.  The content of the allocated
3203 memory is unspecified.
3205 In @code{target} regions, either the @code{dynamic_allocators} clause must
3206 appear on a @code{requires} directive in the same compilation unit -- or the
3207 @var{allocator} argument may only be a constant expression with the value of
3208 one of the predefined allocators and may not be @code{omp_null_allocator}.
3210 Memory allocated by @code{omp_aligned_alloc} must be freed using
3211 @code{omp_free}.
3213 @item @emph{C}:
3214 @multitable @columnfractions .20 .80
3215 @item @emph{Prototype}: @tab @code{void* omp_aligned_alloc(size_t alignment,}
3216 @item                   @tab @code{  size_t size,}
3217 @item                   @tab @code{  omp_allocator_handle_t allocator)}
3218 @end multitable
3220 @item @emph{C++}:
3221 @multitable @columnfractions .20 .80
3222 @item @emph{Prototype}: @tab @code{void* omp_aligned_alloc(size_t alignment,}
3223 @item                   @tab @code{  size_t size,}
3224 @item                   @tab @code{  omp_allocator_handle_t allocator=omp_null_allocator)}
3225 @end multitable
3227 @item @emph{Fortran}:
3228 @multitable @columnfractions .20 .80
3229 @item @emph{Interface}: @tab @code{type(c_ptr) function omp_aligned_alloc(alignment, size, allocator) bind(C)}
3230 @item                   @tab @code{use, intrinsic :: iso_c_binding, only : c_ptr, c_size_t}
3231 @item                   @tab @code{integer (c_size_t), value :: alignment, size}
3232 @item                   @tab @code{integer (omp_allocator_handle_kind), value :: allocator}
3233 @end multitable
3235 @item @emph{See also}:
3236 @ref{OMP_ALLOCATOR}, @ref{Memory allocation}, @ref{omp_set_default_allocator},
3237 @ref{omp_free}, @ref{omp_init_allocator}
3239 @item @emph{Reference}:
3240 @uref{https://www.openmp.org, OpenMP specification v5.1}, Section 3.13.6
3241 @end table
3245 @node omp_free
3246 @subsection @code{omp_free} -- Freeing memory allocated with OpenMP routines
3247 @table @asis
3248 @item @emph{Description}:
3249 The @code{omp_free} routine deallocates memory previously allocated by an
3250 OpenMP memory-management routine. The @var{ptr} argument must point to such
3251 memory or be a null pointer; if it is a null pointer, no operation is
3252 performed.  If specified, the @var{allocator} argument must be either the
3253 memory allocator that was used for the allocation or @code{omp_null_allocator};
3254 if it is @code{omp_null_allocator}, the implementation will determine the value
3255 automatically.
3257 Calling @code{omp_free} invokes undefined behavior if the memory
3258 was already deallocated or when the used allocator has already been destroyed.
3260 @item @emph{C}:
3261 @multitable @columnfractions .20 .80
3262 @item @emph{Prototype}: @tab @code{void omp_free(void *ptr,}
3263 @item                   @tab @code{  omp_allocator_handle_t allocator)}
3264 @end multitable
3266 @item @emph{C++}:
3267 @multitable @columnfractions .20 .80
3268 @item @emph{Prototype}: @tab @code{void omp_free(void *ptr,}
3269 @item                   @tab @code{  omp_allocator_handle_t allocator=omp_null_allocator)}
3270 @end multitable
3272 @item @emph{Fortran}:
3273 @multitable @columnfractions .20 .80
3274 @item @emph{Interface}: @tab @code{subroutine omp_free(ptr, allocator) bind(C)}
3275 @item                   @tab @code{use, intrinsic :: iso_c_binding, only : c_ptr}
3276 @item                   @tab @code{type (c_ptr), value :: ptr}
3277 @item                   @tab @code{integer (omp_allocator_handle_kind), value :: allocator}
3278 @end multitable
3280 @item @emph{See also}:
3281 @ref{omp_alloc}, @ref{omp_aligned_alloc}, @ref{omp_calloc},
3282 @ref{omp_aligned_calloc}, @ref{omp_realloc}
3284 @item @emph{Reference}:
3285 @uref{https://www.openmp.org, OpenMP specification v5.0}, Section 3.7.7
3286 @end table
3290 @node omp_calloc
3291 @subsection @code{omp_calloc} -- Allocate nullified memory with an allocator
3292 @table @asis
3293 @item @emph{Description}:
3294 Allocate zero-initialized memory with the specified allocator, which can either
3295 be a predefined allocator, an allocator handle or @code{omp_null_allocator}.  If
3296 the allocators is @code{omp_null_allocator}, the allocator specified by the
3297 @var{def-allocator-var} ICV is used.  The to-be allocated memory is for an
3298 array with @var{nmemb} elements, each having a size of @var{size} bytes.  Both
3299 @var{nmemb} and @var{size} must be nonnegative numbers; if either of them is
3300 zero, @code{omp_calloc} will return a null pointer.  If successful, a pointer to
3301 the zero-initialized allocated memory is returned, otherwise the @code{fallback}
3302 trait of the allocator determines the behavior.
3304 In @code{target} regions, either the @code{dynamic_allocators} clause must
3305 appear on a @code{requires} directive in the same compilation unit -- or the
3306 @var{allocator} argument may only be a constant expression with the value of
3307 one of the predefined allocators and may not be @code{omp_null_allocator}.
3309 Memory allocated by @code{omp_calloc} must be freed using @code{omp_free}.
3311 @item @emph{C}:
3312 @multitable @columnfractions .20 .80
3313 @item @emph{Prototype}: @tab @code{void* omp_calloc(size_t nmemb, size_t size,}
3314 @item                   @tab @code{  omp_allocator_handle_t allocator)}
3315 @end multitable
3317 @item @emph{C++}:
3318 @multitable @columnfractions .20 .80
3319 @item @emph{Prototype}: @tab @code{void* omp_calloc(size_t nmemb, size_t size,}
3320 @item                   @tab @code{  omp_allocator_handle_t allocator=omp_null_allocator)}
3321 @end multitable
3323 @item @emph{Fortran}:
3324 @multitable @columnfractions .20 .80
3325 @item @emph{Interface}: @tab @code{type(c_ptr) function omp_calloc(nmemb, size, allocator) bind(C)}
3326 @item                   @tab @code{use, intrinsic :: iso_c_binding, only : c_ptr, c_size_t}
3327 @item                   @tab @code{integer (c_size_t), value :: nmemb, size}
3328 @item                   @tab @code{integer (omp_allocator_handle_kind), value :: allocator}
3329 @end multitable
3331 @item @emph{See also}:
3332 @ref{OMP_ALLOCATOR}, @ref{Memory allocation}, @ref{omp_set_default_allocator},
3333 @ref{omp_free}, @ref{omp_init_allocator}
3335 @item @emph{Reference}:
3336 @uref{https://www.openmp.org, OpenMP specification v5.1}, Section 3.13.8
3337 @end table
3341 @node omp_aligned_calloc
3342 @subsection @code{omp_aligned_calloc} -- Allocate aligned nullified memory with an allocator
3343 @table @asis
3344 @item @emph{Description}:
3345 Allocate zero-initialized memory with the specified allocator, which can either
3346 be a predefined allocator, an allocator handle or @code{omp_null_allocator}.  If
3347 the allocators is @code{omp_null_allocator}, the allocator specified by the
3348 @var{def-allocator-var} ICV is used.  The to-be allocated memory is for an
3349 array with @var{nmemb} elements, each having a size of @var{size} bytes.  Both
3350 @var{nmemb} and @var{size} must be nonnegative numbers; if either of them is
3351 zero, @code{omp_aligned_calloc} will return a null pointer.  @var{alignment}
3352 must be a positive power of two and @var{size} must be a multiple of the
3353 alignment; the alignment will be at least the maximal value required by
3354 @code{alignment} trait of the allocator and the value of the  passed
3355 @var{alignment} argument.  If successful, a pointer to the zero-initialized
3356 allocated memory is returned, otherwise the @code{fallback} trait of the
3357 allocator determines the behavior.
3359 In @code{target} regions, either the @code{dynamic_allocators} clause must
3360 appear on a @code{requires} directive in the same compilation unit -- or the
3361 @var{allocator} argument may only be a constant expression with the value of
3362 one of the predefined allocators and may not be @code{omp_null_allocator}.
3364 Memory allocated by @code{omp_aligned_calloc} must be freed using
3365 @code{omp_free}.
3367 @item @emph{C}:
3368 @multitable @columnfractions .20 .80
3369 @item @emph{Prototype}: @tab @code{void* omp_aligned_calloc(size_t nmemb, size_t size,}
3370 @item                   @tab @code{  omp_allocator_handle_t allocator)}
3371 @end multitable
3373 @item @emph{C++}:
3374 @multitable @columnfractions .20 .80
3375 @item @emph{Prototype}: @tab @code{void* omp_aligned_calloc(size_t nmemb, size_t size,}
3376 @item                   @tab @code{  omp_allocator_handle_t allocator=omp_null_allocator)}
3377 @end multitable
3379 @item @emph{Fortran}:
3380 @multitable @columnfractions .20 .80
3381 @item @emph{Interface}: @tab @code{type(c_ptr) function omp_aligned_calloc(nmemb, size, allocator) bind(C)}
3382 @item                   @tab @code{use, intrinsic :: iso_c_binding, only : c_ptr, c_size_t}
3383 @item                   @tab @code{integer (c_size_t), value :: nmemb, size}
3384 @item                   @tab @code{integer (omp_allocator_handle_kind), value :: allocator}
3385 @end multitable
3387 @item @emph{See also}:
3388 @ref{OMP_ALLOCATOR}, @ref{Memory allocation}, @ref{omp_set_default_allocator},
3389 @ref{omp_free}, @ref{omp_init_allocator}
3391 @item @emph{Reference}:
3392 @uref{https://www.openmp.org, OpenMP specification v5.1}, Section 3.13.8
3393 @end table
3397 @node omp_realloc
3398 @subsection @code{omp_realloc} -- Reallocate memory allocated with OpenMP routines
3399 @table @asis
3400 @item @emph{Description}:
3401 The @code{omp_realloc} routine deallocates memory to which @var{ptr} points to
3402 and allocates new memory with the specified @var{allocator} argument; the
3403 new memory will have the content of the old memory up to the minimum of the
3404 old size and the new @var{size}, otherwise the content of the returned memory
3405 is unspecified.  If the new allocator is the same as the old one, the routine
3406 tries to resize the existing memory allocation, returning the same address as
3407 @var{ptr} if successful.  @var{ptr} must point to memory allocated by an OpenMP
3408 memory-management routine.
3410 The @var{allocator} and @var{free_allocator} arguments must be a predefined
3411 allocator, an allocator handle or @code{omp_null_allocator}.  If
3412 @var{free_allocator} is @code{omp_null_allocator}, the implementation
3413 automatically determines the allocator used for the allocation of @var{ptr}.
3414 If @var{allocator} is @code{omp_null_allocator} and @var{ptr} is not a
3415 null pointer, the same allocator as @code{free_allocator} is used and
3416 when @var{ptr} is a null pointer the allocator specified by the
3417 @var{def-allocator-var} ICV is used.
3419 The @var{size} must be a nonnegative number denoting the number of bytes to be
3420 allocated; if @var{size} is zero, @code{omp_realloc} will return free the
3421 memory and return a null pointer.  When @var{size} is nonzero: if successful,
3422 a pointer to the allocated memory is returned, otherwise the @code{fallback}
3423 trait of the allocator determines the behavior.
3425 In @code{target} regions, either the @code{dynamic_allocators} clause must
3426 appear on a @code{requires} directive in the same compilation unit -- or the
3427 @var{free_allocator} and @var{allocator} arguments may only be a constant
3428 expression with the value of one of the predefined allocators and may not be
3429 @code{omp_null_allocator}.
3431 Memory allocated by @code{omp_realloc} must be freed using @code{omp_free}.
3432 Calling @code{omp_free} invokes undefined behavior if the memory
3433 was already deallocated or when the used allocator has already been destroyed.
3435 @item @emph{C}:
3436 @multitable @columnfractions .20 .80
3437 @item @emph{Prototype}: @tab @code{void* omp_realloc(void *ptr, size_t size,}
3438 @item                   @tab @code{  omp_allocator_handle_t allocator,}
3439 @item                   @tab @code{  omp_allocator_handle_t free_allocator)}
3440 @end multitable
3442 @item @emph{C++}:
3443 @multitable @columnfractions .20 .80
3444 @item @emph{Prototype}: @tab @code{void* omp_realloc(void *ptr, size_t size,}
3445 @item                   @tab @code{  omp_allocator_handle_t allocator=omp_null_allocator,}
3446 @item                   @tab @code{  omp_allocator_handle_t free_allocator=omp_null_allocator)}
3447 @end multitable
3449 @item @emph{Fortran}:
3450 @multitable @columnfractions .20 .80
3451 @item @emph{Interface}: @tab @code{type(c_ptr) function omp_realloc(ptr, size, allocator, free_allocator) bind(C)}
3452 @item                   @tab @code{use, intrinsic :: iso_c_binding, only : c_ptr, c_size_t}
3453 @item                   @tab @code{type(C_ptr), value :: ptr}
3454 @item                   @tab @code{integer (c_size_t), value :: size}
3455 @item                   @tab @code{integer (omp_allocator_handle_kind), value :: allocator, free_allocator}
3456 @end multitable
3458 @item @emph{See also}:
3459 @ref{OMP_ALLOCATOR}, @ref{Memory allocation}, @ref{omp_set_default_allocator},
3460 @ref{omp_free}, @ref{omp_init_allocator}
3462 @item @emph{Reference}:
3463 @uref{https://www.openmp.org, OpenMP specification v5.0}, Section 3.7.9
3464 @end table
3468 @c @node Tool Control Routine
3469 @c @section Tool Control Routine
3471 @c FIXME
3473 @node Environment Display Routine
3474 @section Environment Display Routine
3476 Routine to display the OpenMP version number and the initial value of ICVs.
3477 It has C linkage and does not throw exceptions.
3479 @menu
3480 * omp_display_env:: print the initial ICV values
3481 @end menu
3483 @node omp_display_env
3484 @subsection @code{omp_display_env} -- print the initial ICV values
3485 @table @asis
3486 @item @emph{Description}:
3487 Each time this routine is invoked, the OpenMP version number and initial value
3488 of internal control variables (ICVs) is printed on @code{stderr}.  The displayed
3489 values are those at startup after evaluating the environment variables; later
3490 calls to API routines or clauses used in enclosing constructs do not affect
3491 the output.
3493 If the @var{verbose} argument is @code{false}, only the OpenMP version and
3494 standard OpenMP ICVs are shown; if it is @code{true}, additionally, the
3495 GCC-specific ICVs are shown.
3497 The output consists of multiple lines and starts with
3498 @samp{OPENMP DISPLAY ENVIRONMENT BEGIN} followed by the name-value lines and
3499 ends with @samp{OPENMP DISPLAY ENVIRONMENT END}.  The @var{name} is followed by
3500 an equal sign and the @var{value} is enclosed in single quotes.
3502 The first line has as @var{name} either @samp{_OPENMP} or @samp{openmp_version}
3503 and shows as value the supported OpenMP version number (4-digit year, 2-digit
3504 month) of the implementation, matching the value of the @code{_OPENMP} macro
3505 and, in Fortran, the named constant @code{openmp_version}.
3507 In each of the succeeding lines, the @var{name} matches the environment-variable
3508 name of an ICV and shows its value.  Those line are might be prefixed by pair of
3509 brackets and a space, where the brackets enclose a comma-separated list of
3510 devices to which the ICV-value combination applies to; the value can either be a
3511 numeric device number or an abstract name denoting all devices (@code{all}), the
3512 initial host device (@code{host}) or all devices but the host (@code{device}).
3513 Note that the same ICV might be printed multiple times for multiple devices,
3514 even if all have the same value.
3516 The effect when invoked from within a @code{target} region is unspecified.
3518 @item @emph{C/C++}:
3519 @multitable @columnfractions .20 .80
3520 @item @emph{Prototype}: @tab @code{void omp_display_env(int verbose)}
3521 @end multitable
3523 @item @emph{Fortran}:
3524 @multitable @columnfractions .20 .80
3525 @item @emph{Interface}: @tab @code{subroutine omp_display_env(verbose)}
3526 @item                   @tab @code{logical, intent(in) :: verbose}
3527 @end multitable
3529 @item @emph{Example}:
3530 Note that the GCC-specific ICVs, such as the shown @code{GOMP_SPINCOUNT},
3531 are only printed when @var{verbose} set to @code{true}.
3533 @smallexample
3534 OPENMP DISPLAY ENVIRONMENT BEGIN
3535   _OPENMP = '201511'
3536   [host] OMP_DYNAMIC = 'FALSE'
3537   [host] OMP_NESTED = 'FALSE'
3538   [all] OMP_CANCELLATION = 'FALSE'
3539   ...
3540   [host] GOMP_SPINCOUNT = '300000'
3541 OPENMP DISPLAY ENVIRONMENT END
3542 @end smallexample
3545 @item @emph{See also}:
3546 @ref{OMP_DISPLAY_ENV}, @ref{Environment Variables},
3547 @ref{Implementation-defined ICV Initialization}
3549 @item @emph{Reference}:
3550 @uref{https://www.openmp.org, OpenMP specification v5.1}, Section 3.15
3551 @end table
3554 @c ---------------------------------------------------------------------
3555 @c OpenMP Environment Variables
3556 @c ---------------------------------------------------------------------
3558 @node Environment Variables
3559 @chapter OpenMP Environment Variables
3561 The environment variables which beginning with @env{OMP_} are defined by
3562 section 4 of the OpenMP specification in version 4.5 or in a later version
3563 of the specification, while those beginning with @env{GOMP_} are GNU extensions.
3564 Most @env{OMP_} environment variables have an associated internal control
3565 variable (ICV).
3567 For any OpenMP environment variable that sets an ICV and is neither
3568 @code{OMP_DEFAULT_DEVICE} nor has global ICV scope, associated
3569 device-specific environment variables exist.  For them, the environment
3570 variable without suffix affects the host.  The suffix @code{_DEV_} followed
3571 by a non-negative device number less that the number of available devices sets
3572 the ICV for the corresponding device.  The suffix @code{_DEV} sets the ICV
3573 of all non-host devices for which a device-specific corresponding environment
3574 variable has not been set while the @code{_ALL} suffix sets the ICV of all
3575 host and non-host devices for which a more specific corresponding environment
3576 variable is not set.
3578 @menu
3579 * OMP_ALLOCATOR::           Set the default allocator
3580 * OMP_AFFINITY_FORMAT::     Set the format string used for affinity display
3581 * OMP_CANCELLATION::        Set whether cancellation is activated
3582 * OMP_DISPLAY_AFFINITY::    Display thread affinity information
3583 * OMP_DISPLAY_ENV::         Show OpenMP version and environment variables
3584 * OMP_DEFAULT_DEVICE::      Set the device used in target regions
3585 * OMP_DYNAMIC::             Dynamic adjustment of threads
3586 * OMP_MAX_ACTIVE_LEVELS::   Set the maximum number of nested parallel regions
3587 * OMP_MAX_TASK_PRIORITY::   Set the maximum task priority value
3588 * OMP_NESTED::              Nested parallel regions
3589 * OMP_NUM_TEAMS::           Specifies the number of teams to use by teams region
3590 * OMP_NUM_THREADS::         Specifies the number of threads to use
3591 * OMP_PROC_BIND::           Whether threads may be moved between CPUs
3592 * OMP_PLACES::              Specifies on which CPUs the threads should be placed
3593 * OMP_STACKSIZE::           Set default thread stack size
3594 * OMP_SCHEDULE::            How threads are scheduled
3595 * OMP_TARGET_OFFLOAD::      Controls offloading behavior
3596 * OMP_TEAMS_THREAD_LIMIT::  Set the maximum number of threads imposed by teams
3597 * OMP_THREAD_LIMIT::        Set the maximum number of threads
3598 * OMP_WAIT_POLICY::         How waiting threads are handled
3599 * GOMP_CPU_AFFINITY::       Bind threads to specific CPUs
3600 * GOMP_DEBUG::              Enable debugging output
3601 * GOMP_STACKSIZE::          Set default thread stack size
3602 * GOMP_SPINCOUNT::          Set the busy-wait spin count
3603 * GOMP_RTEMS_THREAD_POOLS:: Set the RTEMS specific thread pools
3604 @end menu
3607 @node OMP_ALLOCATOR
3608 @section @env{OMP_ALLOCATOR} -- Set the default allocator
3609 @cindex Environment Variable
3610 @table @asis
3611 @item @emph{ICV:} @var{def-allocator-var}
3612 @item @emph{Scope:} data environment
3613 @item @emph{Description}:
3614 Sets the default allocator that is used when no allocator has been specified
3615 in the @code{allocate} or @code{allocator} clause or if an OpenMP memory
3616 routine is invoked with the @code{omp_null_allocator} allocator.
3617 If unset, @code{omp_default_mem_alloc} is used.
3619 The value can either be a predefined allocator or a predefined memory space
3620 or a predefined memory space followed by a colon and a comma-separated list
3621 of memory trait and value pairs, separated by @code{=}.
3623 Note: The corresponding device environment variables are currently not
3624 supported.  Therefore, the non-host @var{def-allocator-var} ICVs are always
3625 initialized to @code{omp_default_mem_alloc}.  However, on all devices,
3626 the @code{omp_set_default_allocator} API routine can be used to change
3627 value.
3629 @multitable @columnfractions .45 .45
3630 @headitem Predefined allocators @tab Associated predefined memory spaces
3631 @item omp_default_mem_alloc     @tab omp_default_mem_space
3632 @item omp_large_cap_mem_alloc   @tab omp_large_cap_mem_space
3633 @item omp_const_mem_alloc       @tab omp_const_mem_space
3634 @item omp_high_bw_mem_alloc     @tab omp_high_bw_mem_space
3635 @item omp_low_lat_mem_alloc     @tab omp_low_lat_mem_space
3636 @item omp_cgroup_mem_alloc      @tab omp_low_lat_mem_space (implementation defined)
3637 @item omp_pteam_mem_alloc       @tab omp_low_lat_mem_space (implementation defined)
3638 @item omp_thread_mem_alloc      @tab omp_low_lat_mem_space (implementation defined)
3639 @item ompx_gnu_pinned_mem_alloc @tab omp_default_mem_space (GNU extension)
3640 @end multitable
3642 The predefined allocators use the default values for the traits,
3643 as listed below.  Except that the last three allocators have the
3644 @code{access} trait set to @code{cgroup}, @code{pteam}, and
3645 @code{thread}, respectively.
3647 @multitable @columnfractions .25 .40 .25
3648 @headitem Trait @tab Allowed values @tab Default value
3649 @item @code{sync_hint} @tab @code{contended}, @code{uncontended},
3650                             @code{serialized}, @code{private}
3651                        @tab @code{contended}
3652 @item @code{alignment} @tab Positive integer being a power of two
3653                        @tab 1 byte
3654 @item @code{access}    @tab @code{all}, @code{cgroup},
3655                             @code{pteam}, @code{thread}
3656                        @tab @code{all}
3657 @item @code{pool_size} @tab Positive integer
3658                        @tab See @ref{Memory allocation}
3659 @item @code{fallback}  @tab @code{default_mem_fb}, @code{null_fb},
3660                             @code{abort_fb}, @code{allocator_fb}
3661                        @tab See below
3662 @item @code{fb_data}   @tab @emph{unsupported as it needs an allocator handle}
3663                        @tab (none)
3664 @item @code{pinned}    @tab @code{true}, @code{false}
3665                        @tab See below
3666 @item @code{partition} @tab @code{environment}, @code{nearest},
3667                             @code{blocked}, @code{interleaved}
3668                        @tab @code{environment}
3669 @end multitable
3671 For the @code{fallback} trait, the default value is @code{null_fb} for the
3672 @code{omp_default_mem_alloc} allocator and any allocator that is associated
3673 with device memory; for all other allocators, it is @code{default_mem_fb}
3674 by default.
3676 For the @code{pinned} trait, the default value is @code{true} for
3677 predefined allocator @code{ompx_gnu_pinned_mem_alloc} (a GNU extension), and
3678 @code{false} for all others.
3680 Examples:
3681 @smallexample
3682 OMP_ALLOCATOR=omp_high_bw_mem_alloc
3683 OMP_ALLOCATOR=omp_large_cap_mem_space
3684 OMP_ALLOCATOR=omp_low_lat_mem_space:pinned=true,partition=nearest
3685 @end smallexample
3687 @item @emph{See also}:
3688 @ref{Memory allocation}, @ref{omp_get_default_allocator},
3689 @ref{omp_set_default_allocator}, @ref{Offload-Target Specifics}
3691 @item @emph{Reference}:
3692 @uref{https://www.openmp.org, OpenMP specification v5.0}, Section 6.21
3693 @end table
3697 @node OMP_AFFINITY_FORMAT
3698 @section @env{OMP_AFFINITY_FORMAT} -- Set the format string used for affinity display
3699 @cindex Environment Variable
3700 @table @asis
3701 @item @emph{ICV:} @var{affinity-format-var}
3702 @item @emph{Scope:} device
3703 @item @emph{Description}:
3704 Sets the format string used when displaying OpenMP thread affinity information.
3705 Special values are output using @code{%} followed by an optional size
3706 specification and then either the single-character field type or its long
3707 name enclosed in curly braces; using @code{%%} displays a literal percent.
3708 The size specification consists of an optional @code{0.} or @code{.} followed
3709 by a positive integer, specifying the minimal width of the output.  With
3710 @code{0.} and numerical values, the output is padded with zeros on the left;
3711 with @code{.}, the output is padded by spaces on the left; otherwise, the
3712 output is padded by spaces on the right.  If unset, the value is
3713 ``@code{level %L thread %i affinity %A}''.
3715 Supported field types are:
3717 @multitable @columnfractions .10 .25 .60
3718 @item t @tab team_num @tab value returned by @code{omp_get_team_num}
3719 @item T @tab num_teams @tab value returned by @code{omp_get_num_teams}
3720 @item L @tab nesting_level @tab value returned by @code{omp_get_level}
3721 @item n @tab thread_num @tab value returned by @code{omp_get_thread_num}
3722 @item N @tab num_threads @tab value returned by @code{omp_get_num_threads}
3723 @item a @tab ancestor_tnum
3724       @tab value returned by
3725            @code{omp_get_ancestor_thread_num(omp_get_level()-1)}
3726 @item H @tab host @tab name of the host that executes the thread
3727 @item P @tab process_id @tab process identifier
3728 @item i @tab native_thread_id @tab native thread identifier
3729 @item A @tab thread_affinity
3730       @tab comma separated list of integer values or ranges, representing the
3731            processors on which a process might execute, subject to affinity
3732            mechanisms
3733 @end multitable
3735 For instance, after setting
3737 @smallexample
3738 OMP_AFFINITY_FORMAT="%0.2a!%n!%.4L!%N;%.2t;%0.2T;%@{team_num@};%@{num_teams@};%A"
3739 @end smallexample
3741 with either @code{OMP_DISPLAY_AFFINITY} being set or when calling
3742 @code{omp_display_affinity} with @code{NULL} or an empty string, the program
3743 might display the following:
3745 @smallexample
3746 00!0!   1!4; 0;01;0;1;0-11
3747 00!3!   1!4; 0;01;0;1;0-11
3748 00!2!   1!4; 0;01;0;1;0-11
3749 00!1!   1!4; 0;01;0;1;0-11
3750 @end smallexample
3752 @item @emph{See also}:
3753 @ref{OMP_DISPLAY_AFFINITY}
3755 @item @emph{Reference}:
3756 @uref{https://www.openmp.org, OpenMP specification v5.0}, Section 6.14
3757 @end table
3761 @node OMP_CANCELLATION
3762 @section @env{OMP_CANCELLATION} -- Set whether cancellation is activated
3763 @cindex Environment Variable
3764 @table @asis
3765 @item @emph{ICV:} @var{cancel-var}
3766 @item @emph{Scope:} global
3767 @item @emph{Description}:
3768 If set to @code{TRUE}, the cancellation is activated.  If set to @code{FALSE} or
3769 if unset, cancellation is disabled and the @code{cancel} construct is ignored.
3771 @item @emph{See also}:
3772 @ref{omp_get_cancellation}
3774 @item @emph{Reference}:
3775 @uref{https://www.openmp.org, OpenMP specification v4.5}, Section 4.11
3776 @end table
3780 @node OMP_DISPLAY_AFFINITY
3781 @section @env{OMP_DISPLAY_AFFINITY} -- Display thread affinity information
3782 @cindex Environment Variable
3783 @table @asis
3784 @item @emph{ICV:} @var{display-affinity-var}
3785 @item @emph{Scope:} global
3786 @item @emph{Description}:
3787 If set to @code{FALSE} or if unset, affinity displaying is disabled.
3788 If set to @code{TRUE}, the runtime displays affinity information about
3789 OpenMP threads in a parallel region upon entering the region and every time
3790 any change occurs.
3792 @item @emph{See also}:
3793 @ref{OMP_AFFINITY_FORMAT}
3795 @item @emph{Reference}:
3796 @uref{https://www.openmp.org, OpenMP specification v5.0}, Section 6.13
3797 @end table
3802 @node OMP_DISPLAY_ENV
3803 @section @env{OMP_DISPLAY_ENV} -- Show OpenMP version and environment variables
3804 @cindex Environment Variable
3805 @table @asis
3806 @item @emph{ICV:} none
3807 @item @emph{Scope:} not applicable
3808 @item @emph{Description}:
3809 If set to @code{TRUE}, the runtime displays the same information to
3810 @code{stderr} as shown by the @code{omp_display_env} routine invoked with
3811 @var{verbose} argument set to @code{false}.  If set to @code{VERBOSE}, the same
3812 information is shown as invoking the routine with @var{verbose} set to
3813 @code{true}. If unset or set to @code{FALSE}, this information is not shown.
3814 The result for any other value is unspecified.
3816 @item @emph{See also}:
3817 @ref{omp_display_env}
3819 @item @emph{Reference}:
3820 @uref{https://www.openmp.org, OpenMP specification v4.5}, Section 4.12
3821 @end table
3825 @node OMP_DEFAULT_DEVICE
3826 @section @env{OMP_DEFAULT_DEVICE} -- Set the device used in target regions
3827 @cindex Environment Variable
3828 @table @asis
3829 @item @emph{ICV:} @var{default-device-var}
3830 @item @emph{Scope:} data environment
3831 @item @emph{Description}:
3832 Set to choose the device which is used in a @code{target} region, unless the
3833 value is overridden by @code{omp_set_default_device} or by a @code{device}
3834 clause.  The value shall be the nonnegative device number. If no device with
3835 the given device number exists, the code is executed on the host.  If unset,
3836 @env{OMP_TARGET_OFFLOAD} is @code{mandatory} and no non-host devices are
3837 available, it is set to @code{omp_invalid_device}.  Otherwise, if unset,
3838 device number 0 is used.
3841 @item @emph{See also}:
3842 @ref{omp_get_default_device}, @ref{omp_set_default_device},
3843 @ref{OMP_TARGET_OFFLOAD}
3845 @item @emph{Reference}:
3846 @uref{https://www.openmp.org, OpenMP specification v5.2}, Section 21.2.7
3847 @end table
3851 @node OMP_DYNAMIC
3852 @section @env{OMP_DYNAMIC} -- Dynamic adjustment of threads
3853 @cindex Environment Variable
3854 @table @asis
3855 @item @emph{ICV:} @var{dyn-var}
3856 @item @emph{Scope:} global
3857 @item @emph{Description}:
3858 Enable or disable the dynamic adjustment of the number of threads 
3859 within a team.  The value of this environment variable shall be 
3860 @code{TRUE} or @code{FALSE}.  If undefined, dynamic adjustment is
3861 disabled by default.
3863 @item @emph{See also}:
3864 @ref{omp_set_dynamic}
3866 @item @emph{Reference}: 
3867 @uref{https://www.openmp.org, OpenMP specification v4.5}, Section 4.3
3868 @end table
3872 @node OMP_MAX_ACTIVE_LEVELS
3873 @section @env{OMP_MAX_ACTIVE_LEVELS} -- Set the maximum number of nested parallel regions
3874 @cindex Environment Variable
3875 @table @asis
3876 @item @emph{ICV:} @var{max-active-levels-var}
3877 @item @emph{Scope:} data environment
3878 @item @emph{Description}:
3879 Specifies the initial value for the maximum number of nested parallel
3880 regions.  The value of this variable shall be a positive integer.
3881 If undefined, then if @env{OMP_NESTED} is defined and set to true, or
3882 if @env{OMP_NUM_THREADS} or @env{OMP_PROC_BIND} are defined and set to
3883 a list with more than one item, the maximum number of nested parallel
3884 regions is initialized to the largest number supported, otherwise
3885 it is set to one.
3887 @item @emph{See also}:
3888 @ref{omp_set_max_active_levels}, @ref{OMP_NESTED}, @ref{OMP_PROC_BIND},
3889 @ref{OMP_NUM_THREADS}
3892 @item @emph{Reference}: 
3893 @uref{https://www.openmp.org, OpenMP specification v4.5}, Section 4.9
3894 @end table
3898 @node OMP_MAX_TASK_PRIORITY
3899 @section @env{OMP_MAX_TASK_PRIORITY} -- Set the maximum priority
3900 number that can be set for a task.
3901 @cindex Environment Variable
3902 @table @asis
3903 @item @emph{ICV:} @var{max-task-priority-var}
3904 @item @emph{Scope:} global
3905 @item @emph{Description}:
3906 Specifies the initial value for the maximum priority value that can be
3907 set for a task.  The value of this variable shall be a non-negative
3908 integer, and zero is allowed.  If undefined, the default priority is
3911 @item @emph{See also}:
3912 @ref{omp_get_max_task_priority}
3914 @item @emph{Reference}: 
3915 @uref{https://www.openmp.org, OpenMP specification v4.5}, Section 4.14
3916 @end table
3920 @node OMP_NESTED
3921 @section @env{OMP_NESTED} -- Nested parallel regions
3922 @cindex Environment Variable
3923 @cindex Implementation specific setting
3924 @table @asis
3925 @item @emph{ICV:} @var{max-active-levels-var}
3926 @item @emph{Scope:} data environment
3927 @item @emph{Description}:
3928 Enable or disable nested parallel regions, i.e., whether team members
3929 are allowed to create new teams.  The value of this environment variable 
3930 shall be @code{TRUE} or @code{FALSE}.  If set to @code{TRUE}, the number
3931 of maximum active nested regions supported is by default set to the
3932 maximum supported, otherwise it is set to one.  If
3933 @env{OMP_MAX_ACTIVE_LEVELS} is defined, its setting overrides this
3934 setting.  If both are undefined, nested parallel regions are enabled if
3935 @env{OMP_NUM_THREADS} or @env{OMP_PROC_BINDS} are defined to a list with
3936 more than one item, otherwise they are disabled by default.
3938 Note that the @code{OMP_NESTED} environment variable was deprecated in
3939 the OpenMP specification 5.0 in favor of @code{OMP_MAX_ACTIVE_LEVELS}.
3941 @item @emph{See also}:
3942 @ref{omp_set_max_active_levels}, @ref{omp_set_nested},
3943 @ref{OMP_MAX_ACTIVE_LEVELS}
3945 @item @emph{Reference}: 
3946 @uref{https://www.openmp.org, OpenMP specification v4.5}, Section 4.6
3947 @end table
3951 @node OMP_NUM_TEAMS
3952 @section @env{OMP_NUM_TEAMS} -- Specifies the number of teams to use by teams region
3953 @cindex Environment Variable
3954 @table @asis
3955 @item @emph{ICV:} @var{nteams-var}
3956 @item @emph{Scope:} device
3957 @item @emph{Description}:
3958 Specifies the upper bound for number of teams to use in teams regions
3959 without explicit @code{num_teams} clause.  The value of this variable shall
3960 be a positive integer.  If undefined it defaults to 0 which means
3961 implementation defined upper bound.
3963 @item @emph{See also}:
3964 @ref{omp_set_num_teams}
3966 @item @emph{Reference}: 
3967 @uref{https://www.openmp.org, OpenMP specification v5.1}, Section 6.23
3968 @end table
3972 @node OMP_NUM_THREADS
3973 @section @env{OMP_NUM_THREADS} -- Specifies the number of threads to use
3974 @cindex Environment Variable
3975 @cindex Implementation specific setting
3976 @table @asis
3977 @item @emph{ICV:} @var{nthreads-var}
3978 @item @emph{Scope:} data environment
3979 @item @emph{Description}:
3980 Specifies the default number of threads to use in parallel regions.  The 
3981 value of this variable shall be a comma-separated list of positive integers;
3982 the value specifies the number of threads to use for the corresponding nested
3983 level.  Specifying more than one item in the list automatically enables
3984 nesting by default.  If undefined one thread per CPU is used.
3986 When a list with more than value is specified, it also affects the
3987 @var{max-active-levels-var} ICV as described in @ref{OMP_MAX_ACTIVE_LEVELS}.
3989 @item @emph{See also}:
3990 @ref{omp_set_num_threads}, @ref{OMP_MAX_ACTIVE_LEVELS}
3992 @item @emph{Reference}: 
3993 @uref{https://www.openmp.org, OpenMP specification v4.5}, Section 4.2
3994 @end table
3998 @node OMP_PROC_BIND
3999 @section @env{OMP_PROC_BIND} -- Whether threads may be moved between CPUs
4000 @cindex Environment Variable
4001 @table @asis
4002 @item @emph{ICV:} @var{bind-var}
4003 @item @emph{Scope:} data environment
4004 @item @emph{Description}:
4005 Specifies whether threads may be moved between processors.  If set to
4006 @code{TRUE}, OpenMP threads should not be moved; if set to @code{FALSE}
4007 they may be moved.  Alternatively, a comma separated list with the
4008 values @code{PRIMARY}, @code{MASTER}, @code{CLOSE} and @code{SPREAD} can
4009 be used to specify the thread affinity policy for the corresponding nesting
4010 level.  With @code{PRIMARY} and @code{MASTER} the worker threads are in the
4011 same place partition as the primary thread.  With @code{CLOSE} those are
4012 kept close to the primary thread in contiguous place partitions.  And
4013 with @code{SPREAD} a sparse distribution
4014 across the place partitions is used.  Specifying more than one item in the
4015 list automatically enables nesting by default.
4017 When a list is specified, it also affects the @var{max-active-levels-var} ICV
4018 as described in @ref{OMP_MAX_ACTIVE_LEVELS}.
4020 When undefined, @env{OMP_PROC_BIND} defaults to @code{TRUE} when
4021 @env{OMP_PLACES} or @env{GOMP_CPU_AFFINITY} is set and @code{FALSE} otherwise.
4023 @item @emph{See also}:
4024 @ref{omp_get_proc_bind}, @ref{GOMP_CPU_AFFINITY}, @ref{OMP_PLACES},
4025 @ref{OMP_MAX_ACTIVE_LEVELS}
4027 @item @emph{Reference}:
4028 @uref{https://www.openmp.org, OpenMP specification v4.5}, Section 4.4
4029 @end table
4033 @node OMP_PLACES
4034 @section @env{OMP_PLACES} -- Specifies on which CPUs the threads should be placed
4035 @cindex Environment Variable
4036 @table @asis
4037 @item @emph{ICV:} @var{place-partition-var}
4038 @item @emph{Scope:} implicit tasks
4039 @item @emph{Description}:
4040 The thread placement can be either specified using an abstract name or by an
4041 explicit list of the places.  The abstract names @code{threads}, @code{cores},
4042 @code{sockets}, @code{ll_caches} and @code{numa_domains} can be optionally
4043 followed by a positive number in parentheses, which denotes the how many places
4044 shall be created.  With @code{threads} each place corresponds to a single
4045 hardware thread; @code{cores} to a single core with the corresponding number of
4046 hardware threads; with @code{sockets} the place corresponds to a single
4047 socket; with @code{ll_caches} to a set of cores that shares the last level
4048 cache on the device; and @code{numa_domains} to a set of cores for which their
4049 closest memory on the device is the same memory and at a similar distance from
4050 the cores.  The resulting placement can be shown by setting the
4051 @env{OMP_DISPLAY_ENV} environment variable.
4053 Alternatively, the placement can be specified explicitly as comma-separated
4054 list of places.  A place is specified by set of nonnegative numbers in curly
4055 braces, denoting the hardware threads.  The curly braces can be omitted
4056 when only a single number has been specified.  The hardware threads
4057 belonging to a place can either be specified as comma-separated list of
4058 nonnegative thread numbers or using an interval.  Multiple places can also be
4059 either specified by a comma-separated list of places or by an interval.  To
4060 specify an interval, a colon followed by the count is placed after
4061 the hardware thread number or the place.  Optionally, the length can be
4062 followed by a colon and the stride number -- otherwise a unit stride is
4063 assumed.  Placing an exclamation mark (@code{!}) directly before a curly
4064 brace or numbers inside the curly braces (excluding intervals)
4065 excludes those hardware threads.
4067 For instance, the following specifies the same places list:
4068 @code{"@{0,1,2@}, @{3,4,6@}, @{7,8,9@}, @{10,11,12@}"};
4069 @code{"@{0:3@}, @{3:3@}, @{7:3@}, @{10:3@}"}; and @code{"@{0:2@}:4:3"}.
4071 If @env{OMP_PLACES} and @env{GOMP_CPU_AFFINITY} are unset and
4072 @env{OMP_PROC_BIND} is either unset or @code{false}, threads may be moved
4073 between CPUs following no placement policy.
4075 @item @emph{See also}:
4076 @ref{OMP_PROC_BIND}, @ref{GOMP_CPU_AFFINITY}, @ref{omp_get_proc_bind},
4077 @ref{OMP_DISPLAY_ENV}
4079 @item @emph{Reference}:
4080 @uref{https://www.openmp.org, OpenMP specification v4.5}, Section 4.5
4081 @end table
4085 @node OMP_STACKSIZE
4086 @section @env{OMP_STACKSIZE} -- Set default thread stack size
4087 @cindex Environment Variable
4088 @table @asis
4089 @item @emph{ICV:} @var{stacksize-var}
4090 @item @emph{Scope:} device
4091 @item @emph{Description}:
4092 Set the default thread stack size in kilobytes, unless the number
4093 is suffixed by @code{B}, @code{K}, @code{M} or @code{G}, in which
4094 case the size is, respectively, in bytes, kilobytes, megabytes
4095 or gigabytes.  This is different from @code{pthread_attr_setstacksize}
4096 which gets the number of bytes as an argument.  If the stack size cannot
4097 be set due to system constraints, an error is reported and the initial
4098 stack size is left unchanged.  If undefined, the stack size is system
4099 dependent.
4101 @item @emph{See also}:
4102 @ref{GOMP_STACKSIZE}
4104 @item @emph{Reference}: 
4105 @uref{https://www.openmp.org, OpenMP specification v4.5}, Section 4.7
4106 @end table
4110 @node OMP_SCHEDULE
4111 @section @env{OMP_SCHEDULE} -- How threads are scheduled
4112 @cindex Environment Variable
4113 @cindex Implementation specific setting
4114 @table @asis
4115 @item @emph{ICV:} @var{run-sched-var}
4116 @item @emph{Scope:} data environment
4117 @item @emph{Description}:
4118 Allows to specify @code{schedule type} and @code{chunk size}. 
4119 The value of the variable shall have the form: @code{type[,chunk]} where
4120 @code{type} is one of @code{static}, @code{dynamic}, @code{guided} or @code{auto}
4121 The optional @code{chunk} size shall be a positive integer.  If undefined,
4122 dynamic scheduling and a chunk size of 1 is used.
4124 @item @emph{See also}:
4125 @ref{omp_set_schedule}
4127 @item @emph{Reference}: 
4128 @uref{https://www.openmp.org, OpenMP specification v4.5}, Sections 2.7.1.1 and 4.1
4129 @end table
4133 @node OMP_TARGET_OFFLOAD
4134 @section @env{OMP_TARGET_OFFLOAD} -- Controls offloading behavior
4135 @cindex Environment Variable
4136 @cindex Implementation specific setting
4137 @table @asis
4138 @item @emph{ICV:} @var{target-offload-var}
4139 @item @emph{Scope:} global
4140 @item @emph{Description}:
4141 Specifies the behavior with regard to offloading code to a device.  This
4142 variable can be set to one of three values - @code{MANDATORY}, @code{DISABLED}
4143 or @code{DEFAULT}.
4145 If set to @code{MANDATORY}, the program terminates with an error if
4146 any device construct or device memory routine uses a device that is unavailable
4147 or not supported by the implementation, or uses a non-conforming device number.
4148 If set to @code{DISABLED}, then offloading is disabled and all code runs on
4149 the host. If set to @code{DEFAULT}, the program tries offloading to the
4150 device first, then falls back to running code on the host if it cannot.
4152 If undefined, then the program behaves as if @code{DEFAULT} was set.
4154 Note: Even with @code{MANDATORY}, no run-time termination is performed when
4155 the device number in a @code{device} clause or argument to a device memory
4156 routine is for host, which includes using the device number in the
4157 @var{default-device-var} ICV.  However, the initial value of
4158 the @var{default-device-var} ICV is affected by @code{MANDATORY}.
4160 @item @emph{See also}:
4161 @ref{OMP_DEFAULT_DEVICE}
4163 @item @emph{Reference}:
4164 @uref{https://www.openmp.org, OpenMP specification v5.2}, Section 21.2.8
4165 @end table
4169 @node OMP_TEAMS_THREAD_LIMIT
4170 @section @env{OMP_TEAMS_THREAD_LIMIT} -- Set the maximum number of threads imposed by teams
4171 @cindex Environment Variable
4172 @table @asis
4173 @item @emph{ICV:} @var{teams-thread-limit-var}
4174 @item @emph{Scope:} device
4175 @item @emph{Description}:
4176 Specifies an upper bound for the number of threads to use by each contention
4177 group created by a teams construct without explicit @code{thread_limit}
4178 clause.  The value of this variable shall be a positive integer.  If undefined,
4179 the value of 0 is used which stands for an implementation defined upper
4180 limit.
4182 @item @emph{See also}:
4183 @ref{OMP_THREAD_LIMIT}, @ref{omp_set_teams_thread_limit}
4185 @item @emph{Reference}: 
4186 @uref{https://www.openmp.org, OpenMP specification v5.1}, Section 6.24
4187 @end table
4191 @node OMP_THREAD_LIMIT
4192 @section @env{OMP_THREAD_LIMIT} -- Set the maximum number of threads
4193 @cindex Environment Variable
4194 @table @asis
4195 @item @emph{ICV:} @var{thread-limit-var}
4196 @item @emph{Scope:} data environment
4197 @item @emph{Description}:
4198 Specifies the number of threads to use for the whole program.  The
4199 value of this variable shall be a positive integer.  If undefined,
4200 the number of threads is not limited.
4202 @item @emph{See also}:
4203 @ref{OMP_NUM_THREADS}, @ref{omp_get_thread_limit}
4205 @item @emph{Reference}: 
4206 @uref{https://www.openmp.org, OpenMP specification v4.5}, Section 4.10
4207 @end table
4211 @node OMP_WAIT_POLICY
4212 @section @env{OMP_WAIT_POLICY} -- How waiting threads are handled
4213 @cindex Environment Variable
4214 @table @asis
4215 @item @emph{Description}:
4216 Specifies whether waiting threads should be active or passive.  If
4217 the value is @code{PASSIVE}, waiting threads should not consume CPU
4218 power while waiting; while the value is @code{ACTIVE} specifies that
4219 they should.  If undefined, threads wait actively for a short time
4220 before waiting passively.
4222 @item @emph{See also}:
4223 @ref{GOMP_SPINCOUNT}
4225 @item @emph{Reference}: 
4226 @uref{https://www.openmp.org, OpenMP specification v4.5}, Section 4.8
4227 @end table
4231 @node GOMP_CPU_AFFINITY
4232 @section @env{GOMP_CPU_AFFINITY} -- Bind threads to specific CPUs
4233 @cindex Environment Variable
4234 @table @asis
4235 @item @emph{Description}:
4236 Binds threads to specific CPUs.  The variable should contain a space-separated
4237 or comma-separated list of CPUs.  This list may contain different kinds of 
4238 entries: either single CPU numbers in any order, a range of CPUs (M-N) 
4239 or a range with some stride (M-N:S).  CPU numbers are zero based.  For example,
4240 @code{GOMP_CPU_AFFINITY="0 3 1-2 4-15:2"} binds the initial thread
4241 to CPU 0, the second to CPU 3, the third to CPU 1, the fourth to 
4242 CPU 2, the fifth to CPU 4, the sixth through tenth to CPUs 6, 8, 10, 12,
4243 and 14 respectively and then starts assigning back from the beginning of
4244 the list.  @code{GOMP_CPU_AFFINITY=0} binds all threads to CPU 0.
4246 There is no libgomp library routine to determine whether a CPU affinity
4247 specification is in effect.  As a workaround, language-specific library 
4248 functions, e.g., @code{getenv} in C or @code{GET_ENVIRONMENT_VARIABLE} in 
4249 Fortran, may be used to query the setting of the @code{GOMP_CPU_AFFINITY} 
4250 environment variable.  A defined CPU affinity on startup cannot be changed 
4251 or disabled during the runtime of the application.
4253 If both @env{GOMP_CPU_AFFINITY} and @env{OMP_PROC_BIND} are set,
4254 @env{OMP_PROC_BIND} has a higher precedence.  If neither has been set and
4255 @env{OMP_PROC_BIND} is unset, or when @env{OMP_PROC_BIND} is set to
4256 @code{FALSE}, the host system handles the assignment of threads to CPUs.
4258 @item @emph{See also}:
4259 @ref{OMP_PLACES}, @ref{OMP_PROC_BIND}
4260 @end table
4264 @node GOMP_DEBUG
4265 @section @env{GOMP_DEBUG} -- Enable debugging output
4266 @cindex Environment Variable
4267 @table @asis
4268 @item @emph{Description}:
4269 Enable debugging output.  The variable should be set to @code{0}
4270 (disabled, also the default if not set), or @code{1} (enabled).
4272 If enabled, some debugging output is printed during execution.
4273 This is currently not specified in more detail, and subject to change.
4274 @end table
4278 @node GOMP_STACKSIZE
4279 @section @env{GOMP_STACKSIZE} -- Set default thread stack size
4280 @cindex Environment Variable
4281 @cindex Implementation specific setting
4282 @table @asis
4283 @item @emph{Description}:
4284 Set the default thread stack size in kilobytes.  This is different from
4285 @code{pthread_attr_setstacksize} which gets the number of bytes as an 
4286 argument.  If the stack size cannot be set due to system constraints, an 
4287 error is reported and the initial stack size is left unchanged.  If undefined,
4288 the stack size is system dependent.
4290 @item @emph{See also}:
4291 @ref{OMP_STACKSIZE}
4293 @item @emph{Reference}: 
4294 @uref{https://gcc.gnu.org/ml/gcc-patches/2006-06/msg00493.html,
4295 GCC Patches Mailinglist}, 
4296 @uref{https://gcc.gnu.org/ml/gcc-patches/2006-06/msg00496.html,
4297 GCC Patches Mailinglist}
4298 @end table
4302 @node GOMP_SPINCOUNT
4303 @section @env{GOMP_SPINCOUNT} -- Set the busy-wait spin count
4304 @cindex Environment Variable
4305 @cindex Implementation specific setting
4306 @table @asis
4307 @item @emph{Description}:
4308 Determines how long a threads waits actively with consuming CPU power
4309 before waiting passively without consuming CPU power.  The value may be
4310 either @code{INFINITE}, @code{INFINITY} to always wait actively or an
4311 integer which gives the number of spins of the busy-wait loop.  The
4312 integer may optionally be followed by the following suffixes acting
4313 as multiplication factors: @code{k} (kilo, thousand), @code{M} (mega,
4314 million), @code{G} (giga, billion), or @code{T} (tera, trillion).
4315 If undefined, 0 is used when @env{OMP_WAIT_POLICY} is @code{PASSIVE},
4316 300,000 is used when @env{OMP_WAIT_POLICY} is undefined and
4317 30 billion is used when @env{OMP_WAIT_POLICY} is @code{ACTIVE}.
4318 If there are more OpenMP threads than available CPUs, 1000 and 100
4319 spins are used for @env{OMP_WAIT_POLICY} being @code{ACTIVE} or
4320 undefined, respectively; unless the @env{GOMP_SPINCOUNT} is lower
4321 or @env{OMP_WAIT_POLICY} is @code{PASSIVE}.
4323 @item @emph{See also}:
4324 @ref{OMP_WAIT_POLICY}
4325 @end table
4329 @node GOMP_RTEMS_THREAD_POOLS
4330 @section @env{GOMP_RTEMS_THREAD_POOLS} -- Set the RTEMS specific thread pools
4331 @cindex Environment Variable
4332 @cindex Implementation specific setting
4333 @table @asis
4334 @item @emph{Description}:
4335 This environment variable is only used on the RTEMS real-time operating system.
4336 It determines the scheduler instance specific thread pools.  The format for
4337 @env{GOMP_RTEMS_THREAD_POOLS} is a list of optional
4338 @code{<thread-pool-count>[$<priority>]@@<scheduler-name>} configurations
4339 separated by @code{:} where:
4340 @itemize @bullet
4341 @item @code{<thread-pool-count>} is the thread pool count for this scheduler
4342 instance.
4343 @item @code{$<priority>} is an optional priority for the worker threads of a
4344 thread pool according to @code{pthread_setschedparam}.  In case a priority
4345 value is omitted, then a worker thread inherits the priority of the OpenMP
4346 primary thread that created it.  The priority of the worker thread is not
4347 changed after creation, even if a new OpenMP primary thread using the worker has
4348 a different priority.
4349 @item @code{@@<scheduler-name>} is the scheduler instance name according to the
4350 RTEMS application configuration.
4351 @end itemize
4352 In case no thread pool configuration is specified for a scheduler instance,
4353 then each OpenMP primary thread of this scheduler instance uses its own
4354 dynamically allocated thread pool.  To limit the worker thread count of the
4355 thread pools, each OpenMP primary thread must call @code{omp_set_num_threads}.
4356 @item @emph{Example}:
4357 Lets suppose we have three scheduler instances @code{IO}, @code{WRK0}, and
4358 @code{WRK1} with @env{GOMP_RTEMS_THREAD_POOLS} set to
4359 @code{"1@@WRK0:3$4@@WRK1"}.  Then there are no thread pool restrictions for
4360 scheduler instance @code{IO}.  In the scheduler instance @code{WRK0} there is
4361 one thread pool available.  Since no priority is specified for this scheduler
4362 instance, the worker thread inherits the priority of the OpenMP primary thread
4363 that created it.  In the scheduler instance @code{WRK1} there are three thread
4364 pools available and their worker threads run at priority four.
4365 @end table
4369 @c ---------------------------------------------------------------------
4370 @c Enabling OpenACC
4371 @c ---------------------------------------------------------------------
4373 @node Enabling OpenACC
4374 @chapter Enabling OpenACC
4376 To activate the OpenACC extensions for C/C++ and Fortran, the compile-time 
4377 flag @option{-fopenacc} must be specified.  This enables the OpenACC directive
4378 @samp{#pragma acc} in C/C++ and, in Fortran, the @samp{!$acc} sentinel in free
4379 source form and the @samp{c$acc}, @samp{*$acc} and @samp{!$acc} sentinels in
4380 fixed source form.  The flag also arranges for automatic linking of the OpenACC
4381 runtime library (@ref{OpenACC Runtime Library Routines}).
4383 See @uref{https://gcc.gnu.org/wiki/OpenACC} for more information.
4385 A complete description of all OpenACC directives accepted may be found in 
4386 the @uref{https://www.openacc.org, OpenACC} Application Programming
4387 Interface manual, version 2.6.
4391 @c ---------------------------------------------------------------------
4392 @c OpenACC Runtime Library Routines
4393 @c ---------------------------------------------------------------------
4395 @node OpenACC Runtime Library Routines
4396 @chapter OpenACC Runtime Library Routines
4398 The runtime routines described here are defined by section 3 of the OpenACC
4399 specifications in version 2.6.
4400 They have C linkage, and do not throw exceptions.
4401 Generally, they are available only for the host, with the exception of
4402 @code{acc_on_device}, which is available for both the host and the
4403 acceleration device.
4405 @menu
4406 * acc_get_num_devices::         Get number of devices for the given device
4407                                 type.
4408 * acc_set_device_type::         Set type of device accelerator to use.
4409 * acc_get_device_type::         Get type of device accelerator to be used.
4410 * acc_set_device_num::          Set device number to use.
4411 * acc_get_device_num::          Get device number to be used.
4412 * acc_get_property::            Get device property.
4413 * acc_async_test::              Tests for completion of a specific asynchronous
4414                                 operation.
4415 * acc_async_test_all::          Tests for completion of all asynchronous
4416                                 operations.
4417 * acc_wait::                    Wait for completion of a specific asynchronous
4418                                 operation.
4419 * acc_wait_all::                Waits for completion of all asynchronous
4420                                 operations.
4421 * acc_wait_all_async::          Wait for completion of all asynchronous
4422                                 operations.
4423 * acc_wait_async::              Wait for completion of asynchronous operations.
4424 * acc_init::                    Initialize runtime for a specific device type.
4425 * acc_shutdown::                Shuts down the runtime for a specific device
4426                                 type.
4427 * acc_on_device::               Whether executing on a particular device
4428 * acc_malloc::                  Allocate device memory.
4429 * acc_free::                    Free device memory.
4430 * acc_copyin::                  Allocate device memory and copy host memory to
4431                                 it.
4432 * acc_present_or_copyin::       If the data is not present on the device,
4433                                 allocate device memory and copy from host
4434                                 memory.
4435 * acc_create::                  Allocate device memory and map it to host
4436                                 memory.
4437 * acc_present_or_create::       If the data is not present on the device,
4438                                 allocate device memory and map it to host
4439                                 memory.
4440 * acc_copyout::                 Copy device memory to host memory.
4441 * acc_delete::                  Free device memory.
4442 * acc_update_device::           Update device memory from mapped host memory.
4443 * acc_update_self::             Update host memory from mapped device memory.
4444 * acc_map_data::                Map previously allocated device memory to host
4445                                 memory.
4446 * acc_unmap_data::              Unmap device memory from host memory.
4447 * acc_deviceptr::               Get device pointer associated with specific
4448                                 host address.
4449 * acc_hostptr::                 Get host pointer associated with specific
4450                                 device address.
4451 * acc_is_present::              Indicate whether host variable / array is
4452                                 present on device.
4453 * acc_memcpy_to_device::        Copy host memory to device memory.
4454 * acc_memcpy_from_device::      Copy device memory to host memory.
4455 * acc_attach::                  Let device pointer point to device-pointer target.
4456 * acc_detach::                  Let device pointer point to host-pointer target.
4458 API routines for target platforms.
4460 * acc_get_current_cuda_device:: Get CUDA device handle.
4461 * acc_get_current_cuda_context::Get CUDA context handle.
4462 * acc_get_cuda_stream::         Get CUDA stream handle.
4463 * acc_set_cuda_stream::         Set CUDA stream handle.
4465 API routines for the OpenACC Profiling Interface.
4467 * acc_prof_register::           Register callbacks.
4468 * acc_prof_unregister::         Unregister callbacks.
4469 * acc_prof_lookup::             Obtain inquiry functions.
4470 * acc_register_library::        Library registration.
4471 @end menu
4475 @node acc_get_num_devices
4476 @section @code{acc_get_num_devices} -- Get number of devices for given device type
4477 @table @asis
4478 @item @emph{Description}
4479 This function returns a value indicating the number of devices available
4480 for the device type specified in @var{devicetype}. 
4482 @item @emph{C/C++}:
4483 @multitable @columnfractions .20 .80
4484 @item @emph{Prototype}: @tab @code{int acc_get_num_devices(acc_device_t devicetype);}
4485 @end multitable
4487 @item @emph{Fortran}:
4488 @multitable @columnfractions .20 .80
4489 @item @emph{Interface}: @tab @code{integer function acc_get_num_devices(devicetype)}
4490 @item                  @tab @code{integer(kind=acc_device_kind) devicetype}
4491 @end multitable
4493 @item @emph{Reference}:
4494 @uref{https://www.openacc.org, OpenACC specification v2.6}, section
4495 3.2.1.
4496 @end table
4500 @node acc_set_device_type
4501 @section @code{acc_set_device_type} -- Set type of device accelerator to use.
4502 @table @asis
4503 @item @emph{Description}
4504 This function indicates to the runtime library which device type, specified
4505 in @var{devicetype}, to use when executing a parallel or kernels region. 
4507 @item @emph{C/C++}:
4508 @multitable @columnfractions .20 .80
4509 @item @emph{Prototype}: @tab @code{acc_set_device_type(acc_device_t devicetype);}
4510 @end multitable
4512 @item @emph{Fortran}:
4513 @multitable @columnfractions .20 .80
4514 @item @emph{Interface}: @tab @code{subroutine acc_set_device_type(devicetype)}
4515 @item                   @tab @code{integer(kind=acc_device_kind) devicetype}
4516 @end multitable
4518 @item @emph{Reference}:
4519 @uref{https://www.openacc.org, OpenACC specification v2.6}, section
4520 3.2.2.
4521 @end table
4525 @node acc_get_device_type
4526 @section @code{acc_get_device_type} -- Get type of device accelerator to be used.
4527 @table @asis
4528 @item @emph{Description}
4529 This function returns what device type will be used when executing a
4530 parallel or kernels region.
4532 This function returns @code{acc_device_none} if
4533 @code{acc_get_device_type} is called from
4534 @code{acc_ev_device_init_start}, @code{acc_ev_device_init_end}
4535 callbacks of the OpenACC Profiling Interface (@ref{OpenACC Profiling
4536 Interface}), that is, if the device is currently being initialized.
4538 @item @emph{C/C++}:
4539 @multitable @columnfractions .20 .80
4540 @item @emph{Prototype}: @tab @code{acc_device_t acc_get_device_type(void);}
4541 @end multitable
4543 @item @emph{Fortran}:
4544 @multitable @columnfractions .20 .80
4545 @item @emph{Interface}: @tab @code{function acc_get_device_type(void)}
4546 @item                  @tab @code{integer(kind=acc_device_kind) acc_get_device_type}
4547 @end multitable
4549 @item @emph{Reference}:
4550 @uref{https://www.openacc.org, OpenACC specification v2.6}, section
4551 3.2.3.
4552 @end table
4556 @node acc_set_device_num
4557 @section @code{acc_set_device_num} -- Set device number to use.
4558 @table @asis
4559 @item @emph{Description}
4560 This function will indicate to the runtime which device number,
4561 specified by @var{devicenum}, associated with the specified device
4562 type @var{devicetype}.
4564 @item @emph{C/C++}:
4565 @multitable @columnfractions .20 .80
4566 @item @emph{Prototype}: @tab @code{acc_set_device_num(int devicenum, acc_device_t devicetype);}
4567 @end multitable
4569 @item @emph{Fortran}:
4570 @multitable @columnfractions .20 .80
4571 @item @emph{Interface}: @tab @code{subroutine acc_set_device_num(devicenum, devicetype)}
4572 @item                   @tab @code{integer devicenum}
4573 @item                   @tab @code{integer(kind=acc_device_kind) devicetype}
4574 @end multitable
4576 @item @emph{Reference}:
4577 @uref{https://www.openacc.org, OpenACC specification v2.6}, section
4578 3.2.4.
4579 @end table
4583 @node acc_get_device_num
4584 @section @code{acc_get_device_num} -- Get device number to be used.
4585 @table @asis
4586 @item @emph{Description}
4587 This function returns which device number associated with the specified device
4588 type @var{devicetype}, will be used when executing a parallel or kernels
4589 region.
4591 @item @emph{C/C++}:
4592 @multitable @columnfractions .20 .80
4593 @item @emph{Prototype}: @tab @code{int acc_get_device_num(acc_device_t devicetype);}
4594 @end multitable
4596 @item @emph{Fortran}:
4597 @multitable @columnfractions .20 .80
4598 @item @emph{Interface}: @tab @code{function acc_get_device_num(devicetype)}
4599 @item                   @tab @code{integer(kind=acc_device_kind) devicetype}
4600 @item                   @tab @code{integer acc_get_device_num}
4601 @end multitable
4603 @item @emph{Reference}:
4604 @uref{https://www.openacc.org, OpenACC specification v2.6}, section
4605 3.2.5.
4606 @end table
4610 @node acc_get_property
4611 @section @code{acc_get_property} -- Get device property.
4612 @cindex acc_get_property
4613 @cindex acc_get_property_string
4614 @table @asis
4615 @item @emph{Description}
4616 These routines return the value of the specified @var{property} for the
4617 device being queried according to @var{devicenum} and @var{devicetype}.
4618 Integer-valued and string-valued properties are returned by
4619 @code{acc_get_property} and @code{acc_get_property_string} respectively.
4620 The Fortran @code{acc_get_property_string} subroutine returns the string
4621 retrieved in its fourth argument while the remaining entry points are
4622 functions, which pass the return value as their result.
4624 Note for Fortran, only: the OpenACC technical committee corrected and, hence,
4625 modified the interface introduced in OpenACC 2.6.  The kind-value parameter
4626 @code{acc_device_property} has been renamed to @code{acc_device_property_kind}
4627 for consistency and the return type of the @code{acc_get_property} function is
4628 now a @code{c_size_t} integer instead of a @code{acc_device_property} integer.
4629 The parameter @code{acc_device_property} is still provided,
4630 but might be removed in a future version of GCC.
4632 @item @emph{C/C++}:
4633 @multitable @columnfractions .20 .80
4634 @item @emph{Prototype}: @tab @code{size_t acc_get_property(int devicenum, acc_device_t devicetype, acc_device_property_t property);}
4635 @item @emph{Prototype}: @tab @code{const char *acc_get_property_string(int devicenum, acc_device_t devicetype, acc_device_property_t property);}
4636 @end multitable
4638 @item @emph{Fortran}:
4639 @multitable @columnfractions .20 .80
4640 @item @emph{Interface}: @tab @code{function acc_get_property(devicenum, devicetype, property)}
4641 @item @emph{Interface}: @tab @code{subroutine acc_get_property_string(devicenum, devicetype, property, string)}
4642 @item                   @tab @code{use ISO_C_Binding, only: c_size_t}
4643 @item                   @tab @code{integer devicenum}
4644 @item                   @tab @code{integer(kind=acc_device_kind) devicetype}
4645 @item                   @tab @code{integer(kind=acc_device_property_kind) property}
4646 @item                   @tab @code{integer(kind=c_size_t) acc_get_property}
4647 @item                   @tab @code{character(*) string}
4648 @end multitable
4650 @item @emph{Reference}:
4651 @uref{https://www.openacc.org, OpenACC specification v2.6}, section
4652 3.2.6.
4653 @end table
4657 @node acc_async_test
4658 @section @code{acc_async_test} -- Test for completion of a specific asynchronous operation.
4659 @table @asis
4660 @item @emph{Description}
4661 This function tests for completion of the asynchronous operation specified
4662 in @var{arg}. In C/C++, a non-zero value is returned to indicate
4663 the specified asynchronous operation has completed while Fortran returns
4664 @code{true}. If the asynchronous operation has not completed, C/C++ returns
4665 zero and Fortran returns @code{false}.
4667 @item @emph{C/C++}:
4668 @multitable @columnfractions .20 .80
4669 @item @emph{Prototype}: @tab @code{int acc_async_test(int arg);}
4670 @end multitable
4672 @item @emph{Fortran}:
4673 @multitable @columnfractions .20 .80
4674 @item @emph{Interface}: @tab @code{function acc_async_test(arg)}
4675 @item                   @tab @code{integer(kind=acc_handle_kind) arg}
4676 @item                   @tab @code{logical acc_async_test}
4677 @end multitable
4679 @item @emph{Reference}:
4680 @uref{https://www.openacc.org, OpenACC specification v2.6}, section
4681 3.2.9.
4682 @end table
4686 @node acc_async_test_all
4687 @section @code{acc_async_test_all} -- Tests for completion of all asynchronous operations.
4688 @table @asis
4689 @item @emph{Description}
4690 This function tests for completion of all asynchronous operations.
4691 In C/C++, a non-zero value is returned to indicate all asynchronous
4692 operations have completed while Fortran returns @code{true}. If
4693 any asynchronous operation has not completed, C/C++ returns zero and
4694 Fortran returns @code{false}.
4696 @item @emph{C/C++}:
4697 @multitable @columnfractions .20 .80
4698 @item @emph{Prototype}: @tab @code{int acc_async_test_all(void);}
4699 @end multitable
4701 @item @emph{Fortran}:
4702 @multitable @columnfractions .20 .80
4703 @item @emph{Interface}: @tab @code{function acc_async_test()}
4704 @item                   @tab @code{logical acc_get_device_num}
4705 @end multitable
4707 @item @emph{Reference}:
4708 @uref{https://www.openacc.org, OpenACC specification v2.6}, section
4709 3.2.10.
4710 @end table
4714 @node acc_wait
4715 @section @code{acc_wait} -- Wait for completion of a specific asynchronous operation.
4716 @table @asis
4717 @item @emph{Description}
4718 This function waits for completion of the asynchronous operation
4719 specified in @var{arg}.
4721 @item @emph{C/C++}:
4722 @multitable @columnfractions .20 .80
4723 @item @emph{Prototype}: @tab @code{acc_wait(arg);}
4724 @item @emph{Prototype (OpenACC 1.0 compatibility)}: @tab @code{acc_async_wait(arg);}
4725 @end multitable
4727 @item @emph{Fortran}:
4728 @multitable @columnfractions .20 .80
4729 @item @emph{Interface}: @tab @code{subroutine acc_wait(arg)}
4730 @item                   @tab @code{integer(acc_handle_kind) arg}
4731 @item @emph{Interface (OpenACC 1.0 compatibility)}: @tab @code{subroutine acc_async_wait(arg)}
4732 @item                                               @tab @code{integer(acc_handle_kind) arg}
4733 @end multitable
4735 @item @emph{Reference}:
4736 @uref{https://www.openacc.org, OpenACC specification v2.6}, section
4737 3.2.11.
4738 @end table
4742 @node acc_wait_all
4743 @section @code{acc_wait_all} -- Waits for completion of all asynchronous operations.
4744 @table @asis
4745 @item @emph{Description}
4746 This function waits for the completion of all asynchronous operations.
4748 @item @emph{C/C++}:
4749 @multitable @columnfractions .20 .80
4750 @item @emph{Prototype}: @tab @code{acc_wait_all(void);}
4751 @item @emph{Prototype (OpenACC 1.0 compatibility)}: @tab @code{acc_async_wait_all(void);}
4752 @end multitable
4754 @item @emph{Fortran}:
4755 @multitable @columnfractions .20 .80
4756 @item @emph{Interface}: @tab @code{subroutine acc_wait_all()}
4757 @item @emph{Interface (OpenACC 1.0 compatibility)}: @tab @code{subroutine acc_async_wait_all()}
4758 @end multitable
4760 @item @emph{Reference}:
4761 @uref{https://www.openacc.org, OpenACC specification v2.6}, section
4762 3.2.13.
4763 @end table
4767 @node acc_wait_all_async
4768 @section @code{acc_wait_all_async} -- Wait for completion of all asynchronous operations.
4769 @table @asis
4770 @item @emph{Description}
4771 This function enqueues a wait operation on the queue @var{async} for any
4772 and all asynchronous operations that have been previously enqueued on
4773 any queue.
4775 @item @emph{C/C++}:
4776 @multitable @columnfractions .20 .80
4777 @item @emph{Prototype}: @tab @code{acc_wait_all_async(int async);}
4778 @end multitable
4780 @item @emph{Fortran}:
4781 @multitable @columnfractions .20 .80
4782 @item @emph{Interface}: @tab @code{subroutine acc_wait_all_async(async)}
4783 @item                   @tab @code{integer(acc_handle_kind) async}
4784 @end multitable
4786 @item @emph{Reference}:
4787 @uref{https://www.openacc.org, OpenACC specification v2.6}, section
4788 3.2.14.
4789 @end table
4793 @node acc_wait_async
4794 @section @code{acc_wait_async} -- Wait for completion of asynchronous operations.
4795 @table @asis
4796 @item @emph{Description}
4797 This function enqueues a wait operation on queue @var{async} for any and all
4798 asynchronous operations enqueued on queue @var{arg}.
4800 @item @emph{C/C++}:
4801 @multitable @columnfractions .20 .80
4802 @item @emph{Prototype}: @tab @code{acc_wait_async(int arg, int async);}
4803 @end multitable
4805 @item @emph{Fortran}:
4806 @multitable @columnfractions .20 .80
4807 @item @emph{Interface}: @tab @code{subroutine acc_wait_async(arg, async)}
4808 @item                   @tab @code{integer(acc_handle_kind) arg, async}
4809 @end multitable
4811 @item @emph{Reference}:
4812 @uref{https://www.openacc.org, OpenACC specification v2.6}, section
4813 3.2.12.
4814 @end table
4818 @node acc_init
4819 @section @code{acc_init} -- Initialize runtime for a specific device type.
4820 @table @asis
4821 @item @emph{Description}
4822 This function initializes the runtime for the device type specified in
4823 @var{devicetype}.
4825 @item @emph{C/C++}:
4826 @multitable @columnfractions .20 .80
4827 @item @emph{Prototype}: @tab @code{acc_init(acc_device_t devicetype);}
4828 @end multitable
4830 @item @emph{Fortran}:
4831 @multitable @columnfractions .20 .80
4832 @item @emph{Interface}: @tab @code{subroutine acc_init(devicetype)}
4833 @item                   @tab @code{integer(acc_device_kind) devicetype}
4834 @end multitable
4836 @item @emph{Reference}:
4837 @uref{https://www.openacc.org, OpenACC specification v2.6}, section
4838 3.2.7.
4839 @end table
4843 @node acc_shutdown
4844 @section @code{acc_shutdown} -- Shuts down the runtime for a specific device type.
4845 @table @asis
4846 @item @emph{Description}
4847 This function shuts down the runtime for the device type specified in
4848 @var{devicetype}.
4850 @item @emph{C/C++}:
4851 @multitable @columnfractions .20 .80
4852 @item @emph{Prototype}: @tab @code{acc_shutdown(acc_device_t devicetype);}
4853 @end multitable
4855 @item @emph{Fortran}:
4856 @multitable @columnfractions .20 .80
4857 @item @emph{Interface}: @tab @code{subroutine acc_shutdown(devicetype)}
4858 @item                   @tab @code{integer(acc_device_kind) devicetype}
4859 @end multitable
4861 @item @emph{Reference}:
4862 @uref{https://www.openacc.org, OpenACC specification v2.6}, section
4863 3.2.8.
4864 @end table
4868 @node acc_on_device
4869 @section @code{acc_on_device} -- Whether executing on a particular device
4870 @table @asis
4871 @item @emph{Description}:
4872 This function returns whether the program is executing on a particular
4873 device specified in @var{devicetype}. In C/C++ a non-zero value is
4874 returned to indicate the device is executing on the specified device type.
4875 In Fortran, @code{true} is returned. If the program is not executing
4876 on the specified device type C/C++ returns zero, while Fortran
4877 returns @code{false}.
4879 @item @emph{C/C++}:
4880 @multitable @columnfractions .20 .80
4881 @item @emph{Prototype}: @tab @code{acc_on_device(acc_device_t devicetype);}
4882 @end multitable
4884 @item @emph{Fortran}:
4885 @multitable @columnfractions .20 .80
4886 @item @emph{Interface}: @tab @code{function acc_on_device(devicetype)}
4887 @item                   @tab @code{integer(acc_device_kind) devicetype}
4888 @item                   @tab @code{logical acc_on_device}
4889 @end multitable
4891 @item @emph{Reference}:
4892 @uref{https://www.openacc.org, OpenACC specification v2.6}, section
4893 3.2.17.
4894 @end table
4898 @node acc_malloc
4899 @section @code{acc_malloc} -- Allocate device memory.
4900 @table @asis
4901 @item @emph{Description}
4902 This function allocates @var{bytes} bytes of device memory. It returns
4903 the device address of the allocated memory.
4905 @item @emph{C/C++}:
4906 @multitable @columnfractions .20 .80
4907 @item @emph{Prototype}: @tab @code{d_void* acc_malloc(size_t bytes);}
4908 @end multitable
4910 @item @emph{Fortran}:
4911 @multitable @columnfractions .20 .80
4912 @item @emph{Interface}: @tab @code{type(c_ptr) function acc_malloc(bytes)}
4913 @item                   @tab @code{integer(c_size_t), value :: bytes}
4914 @end multitable
4916 @item @emph{Reference}:
4917 @uref{https://www.openacc.org, OpenACC specification v2.6}, section
4918 3.2.18.  @uref{https://www.openacc.org, openacc specification v3.3}, section
4919 3.2.16.
4920 @end table
4924 @node acc_free
4925 @section @code{acc_free} -- Free device memory.
4926 @table @asis
4927 @item @emph{Description}
4928 Free previously allocated device memory at the device address @code{data_dev}.
4930 @item @emph{C/C++}:
4931 @multitable @columnfractions .20 .80
4932 @item @emph{Prototype}: @tab @code{void acc_free(d_void *data_dev);}
4933 @end multitable
4935 @item @emph{Fortran}:
4936 @multitable @columnfractions .20 .80
4937 @item @emph{Interface}: @tab @code{subroutine acc_free(data_dev)}
4938 @item                   @tab @code{type(c_ptr), value :: data_dev}
4939 @end multitable
4941 @item @emph{Reference}:
4942 @uref{https://www.openacc.org, OpenACC specification v2.6}, section
4943 3.2.19.  @uref{https://www.openacc.org, openacc specification v3.3}, section
4944 3.2.17.
4945 @end table
4949 @node acc_copyin
4950 @section @code{acc_copyin} -- Allocate device memory and copy host memory to it.
4951 @table @asis
4952 @item @emph{Description}
4953 In C/C++, this function allocates @var{len} bytes of device memory
4954 and maps it to the specified host address in @var{a}. The device
4955 address of the newly allocated device memory is returned.
4957 In Fortran, two (2) forms are supported. In the first form, @var{a} specifies
4958 a contiguous array section. The second form @var{a} specifies a
4959 variable or array element and @var{len} specifies the length in bytes.
4961 @item @emph{C/C++}:
4962 @multitable @columnfractions .20 .80
4963 @item @emph{Prototype}: @tab @code{void *acc_copyin(h_void *a, size_t len);}
4964 @item @emph{Prototype}: @tab @code{void *acc_copyin_async(h_void *a, size_t len, int async);}
4965 @end multitable
4967 @item @emph{Fortran}:
4968 @multitable @columnfractions .20 .80
4969 @item @emph{Interface}: @tab @code{subroutine acc_copyin(a)}
4970 @item                   @tab @code{type, dimension(:[,:]...) :: a}
4971 @item @emph{Interface}: @tab @code{subroutine acc_copyin(a, len)}
4972 @item                   @tab @code{type, dimension(:[,:]...) :: a}
4973 @item                   @tab @code{integer len}
4974 @item @emph{Interface}: @tab @code{subroutine acc_copyin_async(a, async)}
4975 @item                   @tab @code{type, dimension(:[,:]...) :: a}
4976 @item                   @tab @code{integer(acc_handle_kind) :: async}
4977 @item @emph{Interface}: @tab @code{subroutine acc_copyin_async(a, len, async)}
4978 @item                   @tab @code{type, dimension(:[,:]...) :: a}
4979 @item                   @tab @code{integer len}
4980 @item                   @tab @code{integer(acc_handle_kind) :: async}
4981 @end multitable
4983 @item @emph{Reference}:
4984 @uref{https://www.openacc.org, OpenACC specification v2.6}, section
4985 3.2.20.
4986 @end table
4990 @node acc_present_or_copyin
4991 @section @code{acc_present_or_copyin} -- If the data is not present on the device, allocate device memory and copy from host memory.
4992 @table @asis
4993 @item @emph{Description}
4994 This function tests if the host data specified by @var{a} and of length
4995 @var{len} is present or not. If it is not present, device memory
4996 is allocated and the host memory copied. The device address of
4997 the newly allocated device memory is returned.
4999 In Fortran, two (2) forms are supported. In the first form, @var{a} specifies
5000 a contiguous array section. The second form @var{a} specifies a variable or
5001 array element and @var{len} specifies the length in bytes.
5003 Note that @code{acc_present_or_copyin} and @code{acc_pcopyin} exist for
5004 backward compatibility with OpenACC 2.0; use @ref{acc_copyin} instead.
5006 @item @emph{C/C++}:
5007 @multitable @columnfractions .20 .80
5008 @item @emph{Prototype}: @tab @code{void *acc_present_or_copyin(h_void *a, size_t len);}
5009 @item @emph{Prototype}: @tab @code{void *acc_pcopyin(h_void *a, size_t len);}
5010 @end multitable
5012 @item @emph{Fortran}:
5013 @multitable @columnfractions .20 .80
5014 @item @emph{Interface}: @tab @code{subroutine acc_present_or_copyin(a)}
5015 @item                   @tab @code{type, dimension(:[,:]...) :: a}
5016 @item @emph{Interface}: @tab @code{subroutine acc_present_or_copyin(a, len)}
5017 @item                   @tab @code{type, dimension(:[,:]...) :: a}
5018 @item                   @tab @code{integer len}
5019 @item @emph{Interface}: @tab @code{subroutine acc_pcopyin(a)}
5020 @item                   @tab @code{type, dimension(:[,:]...) :: a}
5021 @item @emph{Interface}: @tab @code{subroutine acc_pcopyin(a, len)}
5022 @item                   @tab @code{type, dimension(:[,:]...) :: a}
5023 @item                   @tab @code{integer len}
5024 @end multitable
5026 @item @emph{Reference}:
5027 @uref{https://www.openacc.org, OpenACC specification v2.6}, section
5028 3.2.20.
5029 @end table
5033 @node acc_create
5034 @section @code{acc_create} -- Allocate device memory and map it to host memory.
5035 @table @asis
5036 @item @emph{Description}
5037 This function allocates device memory and maps it to host memory specified
5038 by the host address @var{a} with a length of @var{len} bytes. In C/C++,
5039 the function returns the device address of the allocated device memory.
5041 In Fortran, two (2) forms are supported. In the first form, @var{a} specifies
5042 a contiguous array section. The second form @var{a} specifies a variable or
5043 array element and @var{len} specifies the length in bytes.
5045 @item @emph{C/C++}:
5046 @multitable @columnfractions .20 .80
5047 @item @emph{Prototype}: @tab @code{void *acc_create(h_void *a, size_t len);}
5048 @item @emph{Prototype}: @tab @code{void *acc_create_async(h_void *a, size_t len, int async);}
5049 @end multitable
5051 @item @emph{Fortran}:
5052 @multitable @columnfractions .20 .80
5053 @item @emph{Interface}: @tab @code{subroutine acc_create(a)}
5054 @item                   @tab @code{type, dimension(:[,:]...) :: a}
5055 @item @emph{Interface}: @tab @code{subroutine acc_create(a, len)}
5056 @item                   @tab @code{type, dimension(:[,:]...) :: a}
5057 @item                   @tab @code{integer len}
5058 @item @emph{Interface}: @tab @code{subroutine acc_create_async(a, async)}
5059 @item                   @tab @code{type, dimension(:[,:]...) :: a}
5060 @item                   @tab @code{integer(acc_handle_kind) :: async}
5061 @item @emph{Interface}: @tab @code{subroutine acc_create_async(a, len, async)}
5062 @item                   @tab @code{type, dimension(:[,:]...) :: a}
5063 @item                   @tab @code{integer len}
5064 @item                   @tab @code{integer(acc_handle_kind) :: async}
5065 @end multitable
5067 @item @emph{Reference}:
5068 @uref{https://www.openacc.org, OpenACC specification v2.6}, section
5069 3.2.21.
5070 @end table
5074 @node acc_present_or_create
5075 @section @code{acc_present_or_create} -- If the data is not present on the device, allocate device memory and map it to host memory.
5076 @table @asis
5077 @item @emph{Description}
5078 This function tests if the host data specified by @var{a} and of length
5079 @var{len} is present or not. If it is not present, device memory
5080 is allocated and mapped to host memory. In C/C++, the device address
5081 of the newly allocated device memory is returned.
5083 In Fortran, two (2) forms are supported. In the first form, @var{a} specifies
5084 a contiguous array section. The second form @var{a} specifies a variable or
5085 array element and @var{len} specifies the length in bytes.
5087 Note that @code{acc_present_or_create} and @code{acc_pcreate} exist for
5088 backward compatibility with OpenACC 2.0; use @ref{acc_create} instead.
5090 @item @emph{C/C++}:
5091 @multitable @columnfractions .20 .80
5092 @item @emph{Prototype}: @tab @code{void *acc_present_or_create(h_void *a, size_t len)}
5093 @item @emph{Prototype}: @tab @code{void *acc_pcreate(h_void *a, size_t len)}
5094 @end multitable
5096 @item @emph{Fortran}:
5097 @multitable @columnfractions .20 .80
5098 @item @emph{Interface}: @tab @code{subroutine acc_present_or_create(a)}
5099 @item                   @tab @code{type, dimension(:[,:]...) :: a}
5100 @item @emph{Interface}: @tab @code{subroutine acc_present_or_create(a, len)}
5101 @item                   @tab @code{type, dimension(:[,:]...) :: a}
5102 @item                   @tab @code{integer len}
5103 @item @emph{Interface}: @tab @code{subroutine acc_pcreate(a)}
5104 @item                   @tab @code{type, dimension(:[,:]...) :: a}
5105 @item @emph{Interface}: @tab @code{subroutine acc_pcreate(a, len)}
5106 @item                   @tab @code{type, dimension(:[,:]...) :: a}
5107 @item                   @tab @code{integer len}
5108 @end multitable
5110 @item @emph{Reference}:
5111 @uref{https://www.openacc.org, OpenACC specification v2.6}, section
5112 3.2.21.
5113 @end table
5117 @node acc_copyout
5118 @section @code{acc_copyout} -- Copy device memory to host memory.
5119 @table @asis
5120 @item @emph{Description}
5121 This function copies mapped device memory to host memory which is specified
5122 by host address @var{a} for a length @var{len} bytes in C/C++.
5124 In Fortran, two (2) forms are supported. In the first form, @var{a} specifies
5125 a contiguous array section. The second form @var{a} specifies a variable or
5126 array element and @var{len} specifies the length in bytes.
5128 @item @emph{C/C++}:
5129 @multitable @columnfractions .20 .80
5130 @item @emph{Prototype}: @tab @code{acc_copyout(h_void *a, size_t len);}
5131 @item @emph{Prototype}: @tab @code{acc_copyout_async(h_void *a, size_t len, int async);}
5132 @item @emph{Prototype}: @tab @code{acc_copyout_finalize(h_void *a, size_t len);}
5133 @item @emph{Prototype}: @tab @code{acc_copyout_finalize_async(h_void *a, size_t len, int async);}
5134 @end multitable
5136 @item @emph{Fortran}:
5137 @multitable @columnfractions .20 .80
5138 @item @emph{Interface}: @tab @code{subroutine acc_copyout(a)}
5139 @item                   @tab @code{type, dimension(:[,:]...) :: a}
5140 @item @emph{Interface}: @tab @code{subroutine acc_copyout(a, len)}
5141 @item                   @tab @code{type, dimension(:[,:]...) :: a}
5142 @item                   @tab @code{integer len}
5143 @item @emph{Interface}: @tab @code{subroutine acc_copyout_async(a, async)}
5144 @item                   @tab @code{type, dimension(:[,:]...) :: a}
5145 @item                   @tab @code{integer(acc_handle_kind) :: async}
5146 @item @emph{Interface}: @tab @code{subroutine acc_copyout_async(a, len, async)}
5147 @item                   @tab @code{type, dimension(:[,:]...) :: a}
5148 @item                   @tab @code{integer len}
5149 @item                   @tab @code{integer(acc_handle_kind) :: async}
5150 @item @emph{Interface}: @tab @code{subroutine acc_copyout_finalize(a)}
5151 @item                   @tab @code{type, dimension(:[,:]...) :: a}
5152 @item @emph{Interface}: @tab @code{subroutine acc_copyout_finalize(a, len)}
5153 @item                   @tab @code{type, dimension(:[,:]...) :: a}
5154 @item                   @tab @code{integer len}
5155 @item @emph{Interface}: @tab @code{subroutine acc_copyout_finalize_async(a, async)}
5156 @item                   @tab @code{type, dimension(:[,:]...) :: a}
5157 @item                   @tab @code{integer(acc_handle_kind) :: async}
5158 @item @emph{Interface}: @tab @code{subroutine acc_copyout_finalize_async(a, len, async)}
5159 @item                   @tab @code{type, dimension(:[,:]...) :: a}
5160 @item                   @tab @code{integer len}
5161 @item                   @tab @code{integer(acc_handle_kind) :: async}
5162 @end multitable
5164 @item @emph{Reference}:
5165 @uref{https://www.openacc.org, OpenACC specification v2.6}, section
5166 3.2.22.
5167 @end table
5171 @node acc_delete
5172 @section @code{acc_delete} -- Free device memory.
5173 @table @asis
5174 @item @emph{Description}
5175 This function frees previously allocated device memory specified by
5176 the device address @var{a} and the length of @var{len} bytes.
5178 In Fortran, two (2) forms are supported. In the first form, @var{a} specifies
5179 a contiguous array section. The second form @var{a} specifies a variable or
5180 array element and @var{len} specifies the length in bytes.
5182 @item @emph{C/C++}:
5183 @multitable @columnfractions .20 .80
5184 @item @emph{Prototype}: @tab @code{acc_delete(h_void *a, size_t len);}
5185 @item @emph{Prototype}: @tab @code{acc_delete_async(h_void *a, size_t len, int async);}
5186 @item @emph{Prototype}: @tab @code{acc_delete_finalize(h_void *a, size_t len);}
5187 @item @emph{Prototype}: @tab @code{acc_delete_finalize_async(h_void *a, size_t len, int async);}
5188 @end multitable
5190 @item @emph{Fortran}:
5191 @multitable @columnfractions .20 .80
5192 @item @emph{Interface}: @tab @code{subroutine acc_delete(a)}
5193 @item                   @tab @code{type, dimension(:[,:]...) :: a}
5194 @item @emph{Interface}: @tab @code{subroutine acc_delete(a, len)}
5195 @item                   @tab @code{type, dimension(:[,:]...) :: a}
5196 @item                   @tab @code{integer len}
5197 @item @emph{Interface}: @tab @code{subroutine acc_delete_async(a, async)}
5198 @item                   @tab @code{type, dimension(:[,:]...) :: a}
5199 @item                   @tab @code{integer(acc_handle_kind) :: async}
5200 @item @emph{Interface}: @tab @code{subroutine acc_delete_async(a, len, async)}
5201 @item                   @tab @code{type, dimension(:[,:]...) :: a}
5202 @item                   @tab @code{integer len}
5203 @item                   @tab @code{integer(acc_handle_kind) :: async}
5204 @item @emph{Interface}: @tab @code{subroutine acc_delete_finalize(a)}
5205 @item                   @tab @code{type, dimension(:[,:]...) :: a}
5206 @item @emph{Interface}: @tab @code{subroutine acc_delete_finalize(a, len)}
5207 @item                   @tab @code{type, dimension(:[,:]...) :: a}
5208 @item                   @tab @code{integer len}
5209 @item @emph{Interface}: @tab @code{subroutine acc_delete_async_finalize(a, async)}
5210 @item                   @tab @code{type, dimension(:[,:]...) :: a}
5211 @item                   @tab @code{integer(acc_handle_kind) :: async}
5212 @item @emph{Interface}: @tab @code{subroutine acc_delete_async_finalize(a, len, async)}
5213 @item                   @tab @code{type, dimension(:[,:]...) :: a}
5214 @item                   @tab @code{integer len}
5215 @item                   @tab @code{integer(acc_handle_kind) :: async}
5216 @end multitable
5218 @item @emph{Reference}:
5219 @uref{https://www.openacc.org, OpenACC specification v2.6}, section
5220 3.2.23.
5221 @end table
5225 @node acc_update_device
5226 @section @code{acc_update_device} -- Update device memory from mapped host memory.
5227 @table @asis
5228 @item @emph{Description}
5229 This function updates the device copy from the previously mapped host memory.
5230 The host memory is specified with the host address @var{a} and a length of
5231 @var{len} bytes.
5233 In Fortran, two (2) forms are supported. In the first form, @var{a} specifies
5234 a contiguous array section. The second form @var{a} specifies a variable or
5235 array element and @var{len} specifies the length in bytes.
5237 @item @emph{C/C++}:
5238 @multitable @columnfractions .20 .80
5239 @item @emph{Prototype}: @tab @code{acc_update_device(h_void *a, size_t len);}
5240 @item @emph{Prototype}: @tab @code{acc_update_device(h_void *a, size_t len, async);}
5241 @end multitable
5243 @item @emph{Fortran}:
5244 @multitable @columnfractions .20 .80
5245 @item @emph{Interface}: @tab @code{subroutine acc_update_device(a)}
5246 @item                   @tab @code{type, dimension(:[,:]...) :: a}
5247 @item @emph{Interface}: @tab @code{subroutine acc_update_device(a, len)}
5248 @item                   @tab @code{type, dimension(:[,:]...) :: a}
5249 @item                   @tab @code{integer len}
5250 @item @emph{Interface}: @tab @code{subroutine acc_update_device_async(a, async)}
5251 @item                   @tab @code{type, dimension(:[,:]...) :: a}
5252 @item                   @tab @code{integer(acc_handle_kind) :: async}
5253 @item @emph{Interface}: @tab @code{subroutine acc_update_device_async(a, len, async)}
5254 @item                   @tab @code{type, dimension(:[,:]...) :: a}
5255 @item                   @tab @code{integer len}
5256 @item                   @tab @code{integer(acc_handle_kind) :: async}
5257 @end multitable
5259 @item @emph{Reference}:
5260 @uref{https://www.openacc.org, OpenACC specification v2.6}, section
5261 3.2.24.
5262 @end table
5266 @node acc_update_self
5267 @section @code{acc_update_self} -- Update host memory from mapped device memory.
5268 @table @asis
5269 @item @emph{Description}
5270 This function updates the host copy from the previously mapped device memory.
5271 The host memory is specified with the host address @var{a} and a length of
5272 @var{len} bytes.
5274 In Fortran, two (2) forms are supported. In the first form, @var{a} specifies
5275 a contiguous array section. The second form @var{a} specifies a variable or
5276 array element and @var{len} specifies the length in bytes.
5278 @item @emph{C/C++}:
5279 @multitable @columnfractions .20 .80
5280 @item @emph{Prototype}: @tab @code{acc_update_self(h_void *a, size_t len);}
5281 @item @emph{Prototype}: @tab @code{acc_update_self_async(h_void *a, size_t len, int async);}
5282 @end multitable
5284 @item @emph{Fortran}:
5285 @multitable @columnfractions .20 .80
5286 @item @emph{Interface}: @tab @code{subroutine acc_update_self(a)}
5287 @item                   @tab @code{type, dimension(:[,:]...) :: a}
5288 @item @emph{Interface}: @tab @code{subroutine acc_update_self(a, len)}
5289 @item                   @tab @code{type, dimension(:[,:]...) :: a}
5290 @item                   @tab @code{integer len}
5291 @item @emph{Interface}: @tab @code{subroutine acc_update_self_async(a, async)}
5292 @item                   @tab @code{type, dimension(:[,:]...) :: a}
5293 @item                   @tab @code{integer(acc_handle_kind) :: async}
5294 @item @emph{Interface}: @tab @code{subroutine acc_update_self_async(a, len, async)}
5295 @item                   @tab @code{type, dimension(:[,:]...) :: a}
5296 @item                   @tab @code{integer len}
5297 @item                   @tab @code{integer(acc_handle_kind) :: async}
5298 @end multitable
5300 @item @emph{Reference}:
5301 @uref{https://www.openacc.org, OpenACC specification v2.6}, section
5302 3.2.25.
5303 @end table
5307 @node acc_map_data
5308 @section @code{acc_map_data} -- Map previously allocated device memory to host memory.
5309 @table @asis
5310 @item @emph{Description}
5311 This function maps previously allocated device and host memory. The device
5312 memory is specified with the device address @var{data_dev}. The host memory is
5313 specified with the host address @var{data_arg} and a length of @var{bytes}.
5315 @item @emph{C/C++}:
5316 @multitable @columnfractions .20 .80
5317 @item @emph{Prototype}: @tab @code{void acc_map_data(h_void *data_arg, d_void *data_dev, size_t bytes);}
5318 @end multitable
5320 @item @emph{Fortran}:
5321 @multitable @columnfractions .20 .80
5322 @item @emph{Interface}: @tab @code{subroutine acc_map_data(data_arg, data_dev, bytes)}
5323 @item                   @tab @code{type(*), dimension(*) :: data_arg}
5324 @item                   @tab @code{type(c_ptr), value :: data_dev}
5325 @item                   @tab @code{integer(c_size_t), value :: bytes}
5326 @end multitable
5328 @item @emph{Reference}:
5329 @uref{https://www.openacc.org, OpenACC specification v2.6}, section
5330 3.2.26.  @uref{https://www.openacc.org, OpenACC specification v3.3}, section
5331 3.2.21.
5332 @end table
5336 @node acc_unmap_data
5337 @section @code{acc_unmap_data} -- Unmap device memory from host memory.
5338 @table @asis
5339 @item @emph{Description}
5340 This function unmaps previously mapped device and host memory. The latter
5341 specified by @var{data_arg}.
5343 @item @emph{C/C++}:
5344 @multitable @columnfractions .20 .80
5345 @item @emph{Prototype}: @tab @code{void acc_unmap_data(h_void *data_arg);}
5346 @end multitable
5348 @item @emph{Fortran}:
5349 @multitable @columnfractions .20 .80
5350 @item @emph{Interface}: @tab @code{subroutine acc_unmap_data(data_arg)}
5351 @item                   @tab @code{type(*), dimension(*) :: data_arg}
5352 @end multitable
5354 @item @emph{Reference}:
5355 @uref{https://www.openacc.org, OpenACC specification v2.6}, section
5356 3.2.27. @uref{https://www.openacc.org, OpenACC specification v3.3}, section
5357 3.2.22.
5358 @end table
5362 @node acc_deviceptr
5363 @section @code{acc_deviceptr} -- Get device pointer associated with specific host address.
5364 @table @asis
5365 @item @emph{Description}
5366 This function returns the device address that has been mapped to the
5367 host address specified by @var{data_arg}.
5369 @item @emph{C/C++}:
5370 @multitable @columnfractions .20 .80
5371 @item @emph{Prototype}: @tab @code{void *acc_deviceptr(h_void *data_arg);}
5372 @end multitable
5374 @item @emph{Fortran}:
5375 @multitable @columnfractions .20 .80
5376 @item @emph{Interface}: @tab @code{type(c_ptr) function acc_deviceptr(data_arg)}
5377 @item                   @tab @code{type(*), dimension(*) :: data_arg}
5378 @end multitable
5380 @item @emph{Reference}:
5381 @uref{https://www.openacc.org, OpenACC specification v2.6}, section
5382 3.2.28.  @uref{https://www.openacc.org, OpenACC specification v3.3}, section
5383 3.2.23.
5384 @end table
5388 @node acc_hostptr
5389 @section @code{acc_hostptr} -- Get host pointer associated with specific device address.
5390 @table @asis
5391 @item @emph{Description}
5392 This function returns the host address that has been mapped to the
5393 device address specified by @var{data_dev}.
5395 @item @emph{C/C++}:
5396 @multitable @columnfractions .20 .80
5397 @item @emph{Prototype}: @tab @code{void *acc_hostptr(d_void *data_dev);}
5398 @end multitable
5400 @item @emph{Fortran}:
5401 @multitable @columnfractions .20 .80
5402 @item @emph{Interface}: @tab @code{type(c_ptr) function acc_hostptr(data_dev)}
5403 @item                   @tab @code{type(c_ptr), value :: data_dev}
5404 @end multitable
5406 @item @emph{Reference}:
5407 @uref{https://www.openacc.org, OpenACC specification v2.6}, section
5408 3.2.29.  @uref{https://www.openacc.org, OpenACC specification v3.3}, section
5409 3.2.24.
5410 @end table
5414 @node acc_is_present
5415 @section @code{acc_is_present} -- Indicate whether host variable / array is present on device.
5416 @table @asis
5417 @item @emph{Description}
5418 This function indicates whether the specified host address in @var{a} and a
5419 length of @var{len} bytes is present on the device. In C/C++, a non-zero
5420 value is returned to indicate the presence of the mapped memory on the
5421 device. A zero is returned to indicate the memory is not mapped on the
5422 device.
5424 In Fortran, two (2) forms are supported. In the first form, @var{a} specifies
5425 a contiguous array section. The second form @var{a} specifies a variable or
5426 array element and @var{len} specifies the length in bytes. If the host
5427 memory is mapped to device memory, then a @code{true} is returned. Otherwise,
5428 a @code{false} is return to indicate the mapped memory is not present.
5430 @item @emph{C/C++}:
5431 @multitable @columnfractions .20 .80
5432 @item @emph{Prototype}: @tab @code{int acc_is_present(h_void *a, size_t len);}
5433 @end multitable
5435 @item @emph{Fortran}:
5436 @multitable @columnfractions .20 .80
5437 @item @emph{Interface}: @tab @code{function acc_is_present(a)}
5438 @item                   @tab @code{type, dimension(:[,:]...) :: a}
5439 @item                   @tab @code{logical acc_is_present}
5440 @item @emph{Interface}: @tab @code{function acc_is_present(a, len)}
5441 @item                   @tab @code{type, dimension(:[,:]...) :: a}
5442 @item                   @tab @code{integer len}
5443 @item                   @tab @code{logical acc_is_present}
5444 @end multitable
5446 @item @emph{Reference}:
5447 @uref{https://www.openacc.org, OpenACC specification v2.6}, section
5448 3.2.30.
5449 @end table
5453 @node acc_memcpy_to_device
5454 @section @code{acc_memcpy_to_device} -- Copy host memory to device memory.
5455 @table @asis
5456 @item @emph{Description}
5457 This function copies host memory specified by host address of
5458 @var{data_host_src} to device memory specified by the device address
5459 @var{data_dev_dest} for a length of @var{bytes} bytes.
5461 @item @emph{C/C++}:
5462 @multitable @columnfractions .20 .80
5463 @item @emph{Prototype}: @tab @code{void acc_memcpy_to_device(d_void* data_dev_dest,}
5464 @item                   @tab @code{h_void* data_host_src, size_t bytes);}
5465 @item @emph{Prototype}: @tab @code{void acc_memcpy_to_device_async(d_void* data_dev_dest,}
5466 @item                   @tab @code{h_void* data_host_src, size_t bytes, int async_arg);}
5467 @end multitable
5469 @item @emph{Fortran}:
5470 @multitable @columnfractions .20 .80
5471 @item @emph{Interface}: @tab @code{subroutine acc_memcpy_to_device(data_dev_dest, &}
5472 @item                   @tab @code{data_host_src, bytes)}
5473 @item @emph{Interface}: @tab @code{subroutine acc_memcpy_to_device_async(data_dev_dest, &}
5474 @item                   @tab @code{data_host_src, bytes, async_arg)}
5475 @item                   @tab @code{type(c_ptr), value :: data_dev_dest}
5476 @item                   @tab @code{type(*), dimension(*) :: data_host_src}
5477 @item                   @tab @code{integer(c_size_t), value :: bytes}
5478 @item                   @tab @code{integer(acc_handle_kind), value :: async_arg}
5479 @end multitable
5481 @item @emph{Reference}:
5482 @uref{https://www.openacc.org, OpenACC specification v2.6}, section
5483 3.2.31  @uref{https://www.openacc.org, OpenACC specification v3.3}, section
5484 3.2.26.
5485 @end table
5489 @node acc_memcpy_from_device
5490 @section @code{acc_memcpy_from_device} -- Copy device memory to host memory.
5491 @table @asis
5492 @item @emph{Description}
5493 This function copies device memory specified by device address of
5494 @var{data_dev_src} to host memory specified by the host address
5495 @var{data_host_dest} for a length of @var{bytes} bytes.
5497 @item @emph{C/C++}:
5498 @multitable @columnfractions .20 .80
5499 @item @emph{Prototype}: @tab @code{void acc_memcpy_from_device(h_void* data_host_dest,}
5500 @item                   @tab @code{d_void* data_dev_src, size_t bytes);}
5501 @item @emph{Prototype}: @tab @code{void acc_memcpy_from_device_async(h_void* data_host_dest,}
5502 @item                   @tab @code{d_void* data_dev_src, size_t bytes, int async_arg);}
5503 @end multitable
5505 @item @emph{Fortran}:
5506 @multitable @columnfractions .20 .80
5507 @item @emph{Interface}: @tab @code{subroutine acc_memcpy_from_device(data_host_dest, &}
5508 @item                   @tab @code{data_dev_src, bytes)}
5509 @item @emph{Interface}: @tab @code{subroutine acc_memcpy_from_device_async(data_host_dest, &}
5510 @item                   @tab @code{data_dev_src, bytes, async_arg)}
5511 @item                   @tab @code{type(*), dimension(*) :: data_host_dest}
5512 @item                   @tab @code{type(c_ptr), value :: data_dev_src}
5513 @item                   @tab @code{integer(c_size_t), value :: bytes}
5514 @item                   @tab @code{integer(acc_handle_kind), value :: async_arg}
5515 @end multitable
5517 @item @emph{Reference}:
5518 @uref{https://www.openacc.org, OpenACC specification v2.6}, section
5519 3.2.32.  @uref{https://www.openacc.org, OpenACC specification v3.3}, section
5520 3.2.27.
5521 @end table
5525 @node acc_attach
5526 @section @code{acc_attach} -- Let device pointer point to device-pointer target.
5527 @table @asis
5528 @item @emph{Description}
5529 This function updates a pointer on the device from pointing to a host-pointer
5530 address to pointing to the corresponding device data.
5532 @item @emph{C/C++}:
5533 @multitable @columnfractions .20 .80
5534 @item @emph{Prototype}: @tab @code{void acc_attach(h_void **ptr_addr);}
5535 @item @emph{Prototype}: @tab @code{void acc_attach_async(h_void **ptr_addr, int async);}
5536 @end multitable
5538 @c @item @emph{Fortran}:
5539 @c @multitable @columnfractions .20 .80
5540 @c @item @emph{Interface}: @tab @code{subroutine acc_attach(ptr_addr)}
5541 @c @item @emph{Interface}: @tab @code{subroutine acc_attach_async(ptr_addr, async_arg)}
5542 @c @item                   @tab @code{type(*), dimension(..) :: ptr_addr}
5543 @c @item                   @tab @code{integer(acc_handle_kind), value :: async_arg}
5544 @c @end multitable
5546 @item @emph{Reference}:
5547 @uref{https://www.openacc.org, OpenACC specification v2.6}, section
5548 3.2.34.
5549 @c  @uref{https://www.openacc.org, OpenACC specification v3.3}, section
5550 @c 3.2.29.
5551 @end table
5555 @node acc_detach
5556 @section @code{acc_detach} -- Let device pointer point to host-pointer target.
5557 @table @asis
5558 @item @emph{Description}
5559 This function updates a pointer on the device from pointing to a device-pointer
5560 address to pointing to the corresponding host data.
5562 @item @emph{C/C++}:
5563 @multitable @columnfractions .20 .80
5564 @item @emph{Prototype}: @tab @code{void acc_detach(h_void **ptr_addr);}
5565 @item @emph{Prototype}: @tab @code{void acc_detach_async(h_void **ptr_addr, int async);}
5566 @item @emph{Prototype}: @tab @code{void acc_detach_finalize(h_void **ptr_addr);}
5567 @item @emph{Prototype}: @tab @code{void acc_detach_finalize_async(h_void **ptr_addr, int async);}
5568 @end multitable
5570 @c @item @emph{Fortran}:
5571 @c @multitable @columnfractions .20 .80
5572 @c @item @emph{Interface}: @tab @code{subroutine acc_detach(ptr_addr)}
5573 @c @item @emph{Interface}: @tab @code{subroutine acc_detach_async(ptr_addr, async_arg)}
5574 @c @item @emph{Interface}: @tab @code{subroutine acc_detach_finalize(ptr_addr)}
5575 @c @item @emph{Interface}: @tab @code{subroutine acc_detach_finalize_async(ptr_addr, async_arg)}
5576 @c @item                   @tab @code{type(*), dimension(..) :: ptr_addr}
5577 @c @item                   @tab @code{integer(acc_handle_kind), value :: async_arg}
5578 @c @end multitable
5580 @item @emph{Reference}:
5581 @uref{https://www.openacc.org, OpenACC specification v2.6}, section
5582 3.2.35.
5583 @c  @uref{https://www.openacc.org, OpenACC specification v3.3}, section
5584 @c 3.2.29.
5585 @end table
5589 @node acc_get_current_cuda_device
5590 @section @code{acc_get_current_cuda_device} -- Get CUDA device handle.
5591 @table @asis
5592 @item @emph{Description}
5593 This function returns the CUDA device handle. This handle is the same
5594 as used by the CUDA Runtime or Driver API's.
5596 @item @emph{C/C++}:
5597 @multitable @columnfractions .20 .80
5598 @item @emph{Prototype}: @tab @code{void *acc_get_current_cuda_device(void);}
5599 @end multitable
5601 @item @emph{Reference}:
5602 @uref{https://www.openacc.org, OpenACC specification v2.6}, section
5603 A.2.1.1.
5604 @end table
5608 @node acc_get_current_cuda_context
5609 @section @code{acc_get_current_cuda_context} -- Get CUDA context handle.
5610 @table @asis
5611 @item @emph{Description}
5612 This function returns the CUDA context handle. This handle is the same
5613 as used by the CUDA Runtime or Driver API's.
5615 @item @emph{C/C++}:
5616 @multitable @columnfractions .20 .80
5617 @item @emph{Prototype}: @tab @code{void *acc_get_current_cuda_context(void);}
5618 @end multitable
5620 @item @emph{Reference}:
5621 @uref{https://www.openacc.org, OpenACC specification v2.6}, section
5622 A.2.1.2.
5623 @end table
5627 @node acc_get_cuda_stream
5628 @section @code{acc_get_cuda_stream} -- Get CUDA stream handle.
5629 @table @asis
5630 @item @emph{Description}
5631 This function returns the CUDA stream handle for the queue @var{async}.
5632 This handle is the same as used by the CUDA Runtime or Driver API's.
5634 @item @emph{C/C++}:
5635 @multitable @columnfractions .20 .80
5636 @item @emph{Prototype}: @tab @code{void *acc_get_cuda_stream(int async);}
5637 @end multitable
5639 @item @emph{Reference}:
5640 @uref{https://www.openacc.org, OpenACC specification v2.6}, section
5641 A.2.1.3.
5642 @end table
5646 @node acc_set_cuda_stream
5647 @section @code{acc_set_cuda_stream} -- Set CUDA stream handle.
5648 @table @asis
5649 @item @emph{Description}
5650 This function associates the stream handle specified by @var{stream} with
5651 the queue @var{async}.
5653 This cannot be used to change the stream handle associated with
5654 @code{acc_async_sync}.
5656 The return value is not specified.
5658 @item @emph{C/C++}:
5659 @multitable @columnfractions .20 .80
5660 @item @emph{Prototype}: @tab @code{int acc_set_cuda_stream(int async, void *stream);}
5661 @end multitable
5663 @item @emph{Reference}:
5664 @uref{https://www.openacc.org, OpenACC specification v2.6}, section
5665 A.2.1.4.
5666 @end table
5670 @node acc_prof_register
5671 @section @code{acc_prof_register} -- Register callbacks.
5672 @table @asis
5673 @item @emph{Description}:
5674 This function registers callbacks.
5676 @item @emph{C/C++}:
5677 @multitable @columnfractions .20 .80
5678 @item @emph{Prototype}: @tab @code{void acc_prof_register (acc_event_t, acc_prof_callback, acc_register_t);}
5679 @end multitable
5681 @item @emph{See also}:
5682 @ref{OpenACC Profiling Interface}
5684 @item @emph{Reference}:
5685 @uref{https://www.openacc.org, OpenACC specification v2.6}, section
5686 5.3.
5687 @end table
5691 @node acc_prof_unregister
5692 @section @code{acc_prof_unregister} -- Unregister callbacks.
5693 @table @asis
5694 @item @emph{Description}:
5695 This function unregisters callbacks.
5697 @item @emph{C/C++}:
5698 @multitable @columnfractions .20 .80
5699 @item @emph{Prototype}: @tab @code{void acc_prof_unregister (acc_event_t, acc_prof_callback, acc_register_t);}
5700 @end multitable
5702 @item @emph{See also}:
5703 @ref{OpenACC Profiling Interface}
5705 @item @emph{Reference}:
5706 @uref{https://www.openacc.org, OpenACC specification v2.6}, section
5707 5.3.
5708 @end table
5712 @node acc_prof_lookup
5713 @section @code{acc_prof_lookup} -- Obtain inquiry functions.
5714 @table @asis
5715 @item @emph{Description}:
5716 Function to obtain inquiry functions.
5718 @item @emph{C/C++}:
5719 @multitable @columnfractions .20 .80
5720 @item @emph{Prototype}: @tab @code{acc_query_fn acc_prof_lookup (const char *);}
5721 @end multitable
5723 @item @emph{See also}:
5724 @ref{OpenACC Profiling Interface}
5726 @item @emph{Reference}:
5727 @uref{https://www.openacc.org, OpenACC specification v2.6}, section
5728 5.3.
5729 @end table
5733 @node acc_register_library
5734 @section @code{acc_register_library} -- Library registration.
5735 @table @asis
5736 @item @emph{Description}:
5737 Function for library registration.
5739 @item @emph{C/C++}:
5740 @multitable @columnfractions .20 .80
5741 @item @emph{Prototype}: @tab @code{void acc_register_library (acc_prof_reg, acc_prof_reg, acc_prof_lookup_func);}
5742 @end multitable
5744 @item @emph{See also}:
5745 @ref{OpenACC Profiling Interface}, @ref{ACC_PROFLIB}
5747 @item @emph{Reference}:
5748 @uref{https://www.openacc.org, OpenACC specification v2.6}, section
5749 5.3.
5750 @end table
5754 @c ---------------------------------------------------------------------
5755 @c OpenACC Environment Variables
5756 @c ---------------------------------------------------------------------
5758 @node OpenACC Environment Variables
5759 @chapter OpenACC Environment Variables
5761 The variables @env{ACC_DEVICE_TYPE} and @env{ACC_DEVICE_NUM}
5762 are defined by section 4 of the OpenACC specification in version 2.0.
5763 The variable @env{ACC_PROFLIB}
5764 is defined by section 4 of the OpenACC specification in version 2.6.
5766 @menu
5767 * ACC_DEVICE_TYPE::
5768 * ACC_DEVICE_NUM::
5769 * ACC_PROFLIB::
5770 @end menu
5774 @node ACC_DEVICE_TYPE
5775 @section @code{ACC_DEVICE_TYPE}
5776 @table @asis
5777 @item @emph{Description}:
5778 Control the default device type to use when executing compute regions.
5779 If unset, the code can be run on any device type, favoring a non-host
5780 device type.
5782 Supported values in GCC (if compiled in) are
5783 @itemize
5784 @item @code{host}
5785 @item @code{nvidia}
5786 @item @code{radeon}
5787 @end itemize
5788 @item @emph{Reference}:
5789 @uref{https://www.openacc.org, OpenACC specification v2.6}, section
5790 4.1.
5791 @end table
5795 @node ACC_DEVICE_NUM
5796 @section @code{ACC_DEVICE_NUM}
5797 @table @asis
5798 @item @emph{Description}:
5799 Control which device, identified by device number, is the default device.
5800 The value must be a nonnegative integer less than the number of devices.
5801 If unset, device number zero is used.
5802 @item @emph{Reference}:
5803 @uref{https://www.openacc.org, OpenACC specification v2.6}, section
5804 4.2.
5805 @end table
5809 @node ACC_PROFLIB
5810 @section @code{ACC_PROFLIB}
5811 @table @asis
5812 @item @emph{Description}:
5813 Semicolon-separated list of dynamic libraries that are loaded as profiling
5814 libraries.  Each library must provide at least the @code{acc_register_library}
5815 routine.  Each library file is found as described by the documentation of
5816 @code{dlopen} of your operating system.
5817 @item @emph{See also}:
5818 @ref{acc_register_library}, @ref{OpenACC Profiling Interface}
5820 @item @emph{Reference}:
5821 @uref{https://www.openacc.org, OpenACC specification v2.6}, section
5822 4.3.
5823 @end table
5827 @c ---------------------------------------------------------------------
5828 @c CUDA Streams Usage
5829 @c ---------------------------------------------------------------------
5831 @node CUDA Streams Usage
5832 @chapter CUDA Streams Usage
5834 This applies to the @code{nvptx} plugin only.
5836 The library provides elements that perform asynchronous movement of
5837 data and asynchronous operation of computing constructs.  This
5838 asynchronous functionality is implemented by making use of CUDA
5839 streams@footnote{See "Stream Management" in "CUDA Driver API",
5840 TRM-06703-001, Version 5.5, for additional information}.
5842 The primary means by that the asynchronous functionality is accessed
5843 is through the use of those OpenACC directives which make use of the
5844 @code{async} and @code{wait} clauses.  When the @code{async} clause is
5845 first used with a directive, it creates a CUDA stream.  If an
5846 @code{async-argument} is used with the @code{async} clause, then the
5847 stream is associated with the specified @code{async-argument}.
5849 Following the creation of an association between a CUDA stream and the
5850 @code{async-argument} of an @code{async} clause, both the @code{wait}
5851 clause and the @code{wait} directive can be used.  When either the
5852 clause or directive is used after stream creation, it creates a
5853 rendezvous point whereby execution waits until all operations
5854 associated with the @code{async-argument}, that is, stream, have
5855 completed.
5857 Normally, the management of the streams that are created as a result of
5858 using the @code{async} clause, is done without any intervention by the
5859 caller.  This implies the association between the @code{async-argument}
5860 and the CUDA stream is maintained for the lifetime of the program.
5861 However, this association can be changed through the use of the library
5862 function @code{acc_set_cuda_stream}.  When the function
5863 @code{acc_set_cuda_stream} is called, the CUDA stream that was
5864 originally associated with the @code{async} clause is destroyed.
5865 Caution should be taken when changing the association as subsequent
5866 references to the @code{async-argument} refer to a different
5867 CUDA stream.
5871 @c ---------------------------------------------------------------------
5872 @c OpenACC Library Interoperability
5873 @c ---------------------------------------------------------------------
5875 @node OpenACC Library Interoperability
5876 @chapter OpenACC Library Interoperability
5878 @section Introduction
5880 The OpenACC library uses the CUDA Driver API, and may interact with
5881 programs that use the Runtime library directly, or another library
5882 based on the Runtime library, e.g., CUBLAS@footnote{See section 2.26,
5883 "Interactions with the CUDA Driver API" in
5884 "CUDA Runtime API", Version 5.5, and section 2.27, "VDPAU
5885 Interoperability", in "CUDA Driver API", TRM-06703-001, Version 5.5,
5886 for additional information on library interoperability.}.
5887 This chapter describes the use cases and what changes are
5888 required in order to use both the OpenACC library and the CUBLAS and Runtime
5889 libraries within a program.
5891 @section First invocation: NVIDIA CUBLAS library API
5893 In this first use case (see below), a function in the CUBLAS library is called
5894 prior to any of the functions in the OpenACC library. More specifically, the
5895 function @code{cublasCreate()}.
5897 When invoked, the function initializes the library and allocates the
5898 hardware resources on the host and the device on behalf of the caller. Once
5899 the initialization and allocation has completed, a handle is returned to the
5900 caller. The OpenACC library also requires initialization and allocation of
5901 hardware resources. Since the CUBLAS library has already allocated the
5902 hardware resources for the device, all that is left to do is to initialize
5903 the OpenACC library and acquire the hardware resources on the host.
5905 Prior to calling the OpenACC function that initializes the library and
5906 allocate the host hardware resources, you need to acquire the device number
5907 that was allocated during the call to @code{cublasCreate()}. The invoking of the
5908 runtime library function @code{cudaGetDevice()} accomplishes this. Once
5909 acquired, the device number is passed along with the device type as
5910 parameters to the OpenACC library function @code{acc_set_device_num()}.
5912 Once the call to @code{acc_set_device_num()} has completed, the OpenACC
5913 library uses the  context that was created during the call to
5914 @code{cublasCreate()}. In other words, both libraries share the
5915 same context.
5917 @smallexample
5918     /* Create the handle */
5919     s = cublasCreate(&h);
5920     if (s != CUBLAS_STATUS_SUCCESS)
5921     @{
5922         fprintf(stderr, "cublasCreate failed %d\n", s);
5923         exit(EXIT_FAILURE);
5924     @}
5926     /* Get the device number */
5927     e = cudaGetDevice(&dev);
5928     if (e != cudaSuccess)
5929     @{
5930         fprintf(stderr, "cudaGetDevice failed %d\n", e);
5931         exit(EXIT_FAILURE);
5932     @}
5934     /* Initialize OpenACC library and use device 'dev' */
5935     acc_set_device_num(dev, acc_device_nvidia);
5937 @end smallexample
5938 @center Use Case 1 
5940 @section First invocation: OpenACC library API
5942 In this second use case (see below), a function in the OpenACC library is
5943 called prior to any of the functions in the CUBLAS library. More specifically,
5944 the function @code{acc_set_device_num()}.
5946 In the use case presented here, the function @code{acc_set_device_num()}
5947 is used to both initialize the OpenACC library and allocate the hardware
5948 resources on the host and the device. In the call to the function, the
5949 call parameters specify which device to use and what device
5950 type to use, i.e., @code{acc_device_nvidia}. It should be noted that this
5951 is but one method to initialize the OpenACC library and allocate the
5952 appropriate hardware resources. Other methods are available through the
5953 use of environment variables and these is discussed in the next section.
5955 Once the call to @code{acc_set_device_num()} has completed, other OpenACC
5956 functions can be called as seen with multiple calls being made to
5957 @code{acc_copyin()}. In addition, calls can be made to functions in the
5958 CUBLAS library. In the use case a call to @code{cublasCreate()} is made
5959 subsequent to the calls to @code{acc_copyin()}.
5960 As seen in the previous use case, a call to @code{cublasCreate()}
5961 initializes the CUBLAS library and allocates the hardware resources on the
5962 host and the device.  However, since the device has already been allocated,
5963 @code{cublasCreate()} only initializes the CUBLAS library and allocates
5964 the appropriate hardware resources on the host. The context that was created
5965 as part of the OpenACC initialization is shared with the CUBLAS library,
5966 similarly to the first use case.
5968 @smallexample
5969     dev = 0;
5971     acc_set_device_num(dev, acc_device_nvidia);
5973     /* Copy the first set to the device */
5974     d_X = acc_copyin(&h_X[0], N * sizeof (float));
5975     if (d_X == NULL)
5976     @{ 
5977         fprintf(stderr, "copyin error h_X\n");
5978         exit(EXIT_FAILURE);
5979     @}
5981     /* Copy the second set to the device */
5982     d_Y = acc_copyin(&h_Y1[0], N * sizeof (float));
5983     if (d_Y == NULL)
5984     @{ 
5985         fprintf(stderr, "copyin error h_Y1\n");
5986         exit(EXIT_FAILURE);
5987     @}
5989     /* Create the handle */
5990     s = cublasCreate(&h);
5991     if (s != CUBLAS_STATUS_SUCCESS)
5992     @{
5993         fprintf(stderr, "cublasCreate failed %d\n", s);
5994         exit(EXIT_FAILURE);
5995     @}
5997     /* Perform saxpy using CUBLAS library function */
5998     s = cublasSaxpy(h, N, &alpha, d_X, 1, d_Y, 1);
5999     if (s != CUBLAS_STATUS_SUCCESS)
6000     @{
6001         fprintf(stderr, "cublasSaxpy failed %d\n", s);
6002         exit(EXIT_FAILURE);
6003     @}
6005     /* Copy the results from the device */
6006     acc_memcpy_from_device(&h_Y1[0], d_Y, N * sizeof (float));
6008 @end smallexample
6009 @center Use Case 2
6011 @section OpenACC library and environment variables
6013 There are two environment variables associated with the OpenACC library
6014 that may be used to control the device type and device number:
6015 @env{ACC_DEVICE_TYPE} and @env{ACC_DEVICE_NUM}, respectively. These two
6016 environment variables can be used as an alternative to calling
6017 @code{acc_set_device_num()}. As seen in the second use case, the device
6018 type and device number were specified using @code{acc_set_device_num()}.
6019 If however, the aforementioned environment variables were set, then the
6020 call to @code{acc_set_device_num()} would not be required.
6023 The use of the environment variables is only relevant when an OpenACC function
6024 is called prior to a call to @code{cudaCreate()}. If @code{cudaCreate()}
6025 is called prior to a call to an OpenACC function, then you must call
6026 @code{acc_set_device_num()}@footnote{More complete information
6027 about @env{ACC_DEVICE_TYPE} and @env{ACC_DEVICE_NUM} can be found in
6028 sections 4.1 and 4.2 of the @uref{https://www.openacc.org, OpenACC}
6029 Application Programming Interface”, Version 2.6.}
6033 @c ---------------------------------------------------------------------
6034 @c OpenACC Profiling Interface
6035 @c ---------------------------------------------------------------------
6037 @node OpenACC Profiling Interface
6038 @chapter OpenACC Profiling Interface
6040 @section Implementation Status and Implementation-Defined Behavior
6042 We're implementing the OpenACC Profiling Interface as defined by the
6043 OpenACC 2.6 specification.  We're clarifying some aspects here as
6044 @emph{implementation-defined behavior}, while they're still under
6045 discussion within the OpenACC Technical Committee.
6047 This implementation is tuned to keep the performance impact as low as
6048 possible for the (very common) case that the Profiling Interface is
6049 not enabled.  This is relevant, as the Profiling Interface affects all
6050 the @emph{hot} code paths (in the target code, not in the offloaded
6051 code).  Users of the OpenACC Profiling Interface can be expected to
6052 understand that performance is impacted to some degree once the
6053 Profiling Interface is enabled: for example, because of the
6054 @emph{runtime} (libgomp) calling into a third-party @emph{library} for
6055 every event that has been registered.
6057 We're not yet accounting for the fact that @cite{OpenACC events may
6058 occur during event processing}.
6059 We just handle one case specially, as required by CUDA 9.0
6060 @command{nvprof}, that @code{acc_get_device_type}
6061 (@ref{acc_get_device_type})) may be called from
6062 @code{acc_ev_device_init_start}, @code{acc_ev_device_init_end}
6063 callbacks.
6065 We're not yet implementing initialization via a
6066 @code{acc_register_library} function that is either statically linked
6067 in, or dynamically via @env{LD_PRELOAD}.
6068 Initialization via @code{acc_register_library} functions dynamically
6069 loaded via the @env{ACC_PROFLIB} environment variable does work, as
6070 does directly calling @code{acc_prof_register},
6071 @code{acc_prof_unregister}, @code{acc_prof_lookup}.
6073 As currently there are no inquiry functions defined, calls to
6074 @code{acc_prof_lookup} always returns @code{NULL}.
6076 There aren't separate @emph{start}, @emph{stop} events defined for the
6077 event types @code{acc_ev_create}, @code{acc_ev_delete},
6078 @code{acc_ev_alloc}, @code{acc_ev_free}.  It's not clear if these
6079 should be triggered before or after the actual device-specific call is
6080 made.  We trigger them after.
6082 Remarks about data provided to callbacks:
6084 @table @asis
6086 @item @code{acc_prof_info.event_type}
6087 It's not clear if for @emph{nested} event callbacks (for example,
6088 @code{acc_ev_enqueue_launch_start} as part of a parent compute
6089 construct), this should be set for the nested event
6090 (@code{acc_ev_enqueue_launch_start}), or if the value of the parent
6091 construct should remain (@code{acc_ev_compute_construct_start}).  In
6092 this implementation, the value generally corresponds to the
6093 innermost nested event type.
6095 @item @code{acc_prof_info.device_type}
6096 @itemize
6098 @item
6099 For @code{acc_ev_compute_construct_start}, and in presence of an
6100 @code{if} clause with @emph{false} argument, this still refers to
6101 the offloading device type.
6102 It's not clear if that's the expected behavior.
6104 @item
6105 Complementary to the item before, for
6106 @code{acc_ev_compute_construct_end}, this is set to
6107 @code{acc_device_host} in presence of an @code{if} clause with
6108 @emph{false} argument.
6109 It's not clear if that's the expected behavior.
6111 @end itemize
6113 @item @code{acc_prof_info.thread_id}
6114 Always @code{-1}; not yet implemented.
6116 @item @code{acc_prof_info.async}
6117 @itemize
6119 @item
6120 Not yet implemented correctly for
6121 @code{acc_ev_compute_construct_start}.
6123 @item
6124 In a compute construct, for host-fallback
6125 execution/@code{acc_device_host} it always is
6126 @code{acc_async_sync}.
6127 It is unclear if that is the expected behavior.
6129 @item
6130 For @code{acc_ev_device_init_start} and @code{acc_ev_device_init_end},
6131 it will always be @code{acc_async_sync}.
6132 It is unclear if that is the expected behavior.
6134 @end itemize
6136 @item @code{acc_prof_info.async_queue}
6137 There is no @cite{limited number of asynchronous queues} in libgomp.
6138 This always has the same value as @code{acc_prof_info.async}.
6140 @item @code{acc_prof_info.src_file}
6141 Always @code{NULL}; not yet implemented.
6143 @item @code{acc_prof_info.func_name}
6144 Always @code{NULL}; not yet implemented.
6146 @item @code{acc_prof_info.line_no}
6147 Always @code{-1}; not yet implemented.
6149 @item @code{acc_prof_info.end_line_no}
6150 Always @code{-1}; not yet implemented.
6152 @item @code{acc_prof_info.func_line_no}
6153 Always @code{-1}; not yet implemented.
6155 @item @code{acc_prof_info.func_end_line_no}
6156 Always @code{-1}; not yet implemented.
6158 @item @code{acc_event_info.event_type}, @code{acc_event_info.*.event_type}
6159 Relating to @code{acc_prof_info.event_type} discussed above, in this
6160 implementation, this will always be the same value as
6161 @code{acc_prof_info.event_type}.
6163 @item @code{acc_event_info.*.parent_construct}
6164 @itemize
6166 @item
6167 Will be @code{acc_construct_parallel} for all OpenACC compute
6168 constructs as well as many OpenACC Runtime API calls; should be the
6169 one matching the actual construct, or
6170 @code{acc_construct_runtime_api}, respectively.
6172 @item
6173 Will be @code{acc_construct_enter_data} or
6174 @code{acc_construct_exit_data} when processing variable mappings
6175 specified in OpenACC @emph{declare} directives; should be
6176 @code{acc_construct_declare}.
6178 @item
6179 For implicit @code{acc_ev_device_init_start},
6180 @code{acc_ev_device_init_end}, and explicit as well as implicit
6181 @code{acc_ev_alloc}, @code{acc_ev_free},
6182 @code{acc_ev_enqueue_upload_start}, @code{acc_ev_enqueue_upload_end},
6183 @code{acc_ev_enqueue_download_start}, and
6184 @code{acc_ev_enqueue_download_end}, will be
6185 @code{acc_construct_parallel}; should reflect the real parent
6186 construct.
6188 @end itemize
6190 @item @code{acc_event_info.*.implicit}
6191 For @code{acc_ev_alloc}, @code{acc_ev_free},
6192 @code{acc_ev_enqueue_upload_start}, @code{acc_ev_enqueue_upload_end},
6193 @code{acc_ev_enqueue_download_start}, and
6194 @code{acc_ev_enqueue_download_end}, this currently will be @code{1}
6195 also for explicit usage.
6197 @item @code{acc_event_info.data_event.var_name}
6198 Always @code{NULL}; not yet implemented.
6200 @item @code{acc_event_info.data_event.host_ptr}
6201 For @code{acc_ev_alloc}, and @code{acc_ev_free}, this is always
6202 @code{NULL}.
6204 @item @code{typedef union acc_api_info}
6205 @dots{} as printed in @cite{5.2.3. Third Argument: API-Specific
6206 Information}.  This should obviously be @code{typedef @emph{struct}
6207 acc_api_info}.
6209 @item @code{acc_api_info.device_api}
6210 Possibly not yet implemented correctly for
6211 @code{acc_ev_compute_construct_start},
6212 @code{acc_ev_device_init_start}, @code{acc_ev_device_init_end}:
6213 will always be @code{acc_device_api_none} for these event types.
6214 For @code{acc_ev_enter_data_start}, it will be
6215 @code{acc_device_api_none} in some cases.
6217 @item @code{acc_api_info.device_type}
6218 Always the same as @code{acc_prof_info.device_type}.
6220 @item @code{acc_api_info.vendor}
6221 Always @code{-1}; not yet implemented.
6223 @item @code{acc_api_info.device_handle}
6224 Always @code{NULL}; not yet implemented.
6226 @item @code{acc_api_info.context_handle}
6227 Always @code{NULL}; not yet implemented.
6229 @item @code{acc_api_info.async_handle}
6230 Always @code{NULL}; not yet implemented.
6232 @end table
6234 Remarks about certain event types:
6236 @table @asis
6238 @item @code{acc_ev_device_init_start}, @code{acc_ev_device_init_end}
6239 @itemize
6241 @item
6242 @c See 'DEVICE_INIT_INSIDE_COMPUTE_CONSTRUCT' in
6243 @c 'libgomp.oacc-c-c++-common/acc_prof-kernels-1.c',
6244 @c 'libgomp.oacc-c-c++-common/acc_prof-parallel-1.c'.
6245 When a compute construct triggers implicit
6246 @code{acc_ev_device_init_start} and @code{acc_ev_device_init_end}
6247 events, they currently aren't @emph{nested within} the corresponding
6248 @code{acc_ev_compute_construct_start} and
6249 @code{acc_ev_compute_construct_end}, but they're currently observed
6250 @emph{before} @code{acc_ev_compute_construct_start}.
6251 It's not clear what to do: the standard asks us provide a lot of
6252 details to the @code{acc_ev_compute_construct_start} callback, without
6253 (implicitly) initializing a device before?
6255 @item
6256 Callbacks for these event types will not be invoked for calls to the
6257 @code{acc_set_device_type} and @code{acc_set_device_num} functions.
6258 It's not clear if they should be.
6260 @end itemize
6262 @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}
6263 @itemize
6265 @item
6266 Callbacks for these event types will also be invoked for OpenACC
6267 @emph{host_data} constructs.
6268 It's not clear if they should be.
6270 @item
6271 Callbacks for these event types will also be invoked when processing
6272 variable mappings specified in OpenACC @emph{declare} directives.
6273 It's not clear if they should be.
6275 @end itemize
6277 @end table
6279 Callbacks for the following event types will be invoked, but dispatch
6280 and information provided therein has not yet been thoroughly reviewed:
6282 @itemize
6283 @item @code{acc_ev_alloc}
6284 @item @code{acc_ev_free}
6285 @item @code{acc_ev_update_start}, @code{acc_ev_update_end}
6286 @item @code{acc_ev_enqueue_upload_start}, @code{acc_ev_enqueue_upload_end}
6287 @item @code{acc_ev_enqueue_download_start}, @code{acc_ev_enqueue_download_end}
6288 @end itemize
6290 During device initialization, and finalization, respectively,
6291 callbacks for the following event types will not yet be invoked:
6293 @itemize
6294 @item @code{acc_ev_alloc}
6295 @item @code{acc_ev_free}
6296 @end itemize
6298 Callbacks for the following event types have not yet been implemented,
6299 so currently won't be invoked:
6301 @itemize
6302 @item @code{acc_ev_device_shutdown_start}, @code{acc_ev_device_shutdown_end}
6303 @item @code{acc_ev_runtime_shutdown}
6304 @item @code{acc_ev_create}, @code{acc_ev_delete}
6305 @item @code{acc_ev_wait_start}, @code{acc_ev_wait_end}
6306 @end itemize
6308 For the following runtime library functions, not all expected
6309 callbacks will be invoked (mostly concerning implicit device
6310 initialization):
6312 @itemize
6313 @item @code{acc_get_num_devices}
6314 @item @code{acc_set_device_type}
6315 @item @code{acc_get_device_type}
6316 @item @code{acc_set_device_num}
6317 @item @code{acc_get_device_num}
6318 @item @code{acc_init}
6319 @item @code{acc_shutdown}
6320 @end itemize
6322 Aside from implicit device initialization, for the following runtime
6323 library functions, no callbacks will be invoked for shared-memory
6324 offloading devices (it's not clear if they should be):
6326 @itemize
6327 @item @code{acc_malloc}
6328 @item @code{acc_free}
6329 @item @code{acc_copyin}, @code{acc_present_or_copyin}, @code{acc_copyin_async}
6330 @item @code{acc_create}, @code{acc_present_or_create}, @code{acc_create_async}
6331 @item @code{acc_copyout}, @code{acc_copyout_async}, @code{acc_copyout_finalize}, @code{acc_copyout_finalize_async}
6332 @item @code{acc_delete}, @code{acc_delete_async}, @code{acc_delete_finalize}, @code{acc_delete_finalize_async}
6333 @item @code{acc_update_device}, @code{acc_update_device_async}
6334 @item @code{acc_update_self}, @code{acc_update_self_async}
6335 @item @code{acc_map_data}, @code{acc_unmap_data}
6336 @item @code{acc_memcpy_to_device}, @code{acc_memcpy_to_device_async}
6337 @item @code{acc_memcpy_from_device}, @code{acc_memcpy_from_device_async}
6338 @end itemize
6340 @c ---------------------------------------------------------------------
6341 @c OpenMP-Implementation Specifics
6342 @c ---------------------------------------------------------------------
6344 @node OpenMP-Implementation Specifics
6345 @chapter OpenMP-Implementation Specifics
6347 @menu
6348 * Implementation-defined ICV Initialization::
6349 * OpenMP Context Selectors::
6350 * Memory allocation::
6351 @end menu
6353 @node Implementation-defined ICV Initialization
6354 @section Implementation-defined ICV Initialization
6355 @cindex Implementation specific setting
6357 @multitable @columnfractions .30 .70
6358 @item @var{affinity-format-var} @tab See @ref{OMP_AFFINITY_FORMAT}.
6359 @item @var{def-allocator-var} @tab See @ref{OMP_ALLOCATOR}.
6360 @item @var{max-active-levels-var} @tab See @ref{OMP_MAX_ACTIVE_LEVELS}.
6361 @item @var{dyn-var} @tab See @ref{OMP_DYNAMIC}.
6362 @item @var{nthreads-var} @tab See @ref{OMP_NUM_THREADS}.
6363 @item @var{num-devices-var} @tab Number of non-host devices found
6364 by GCC's run-time library
6365 @item @var{num-procs-var} @tab The number of CPU cores on the
6366 initial device, except that affinity settings might lead to a
6367 smaller number.  On non-host devices, the value of the
6368 @var{nthreads-var} ICV.
6369 @item @var{place-partition-var} @tab See @ref{OMP_PLACES}.
6370 @item @var{run-sched-var} @tab See @ref{OMP_SCHEDULE}.
6371 @item @var{stacksize-var} @tab See @ref{OMP_STACKSIZE}.
6372 @item @var{thread-limit-var} @tab See @ref{OMP_TEAMS_THREAD_LIMIT}
6373 @item @var{wait-policy-var} @tab See @ref{OMP_WAIT_POLICY} and
6374 @ref{GOMP_SPINCOUNT}
6375 @end multitable
6377 @node OpenMP Context Selectors
6378 @section OpenMP Context Selectors
6380 @code{vendor} is always @code{gnu}. References are to the GCC manual.
6382 @c NOTE: Only the following selectors have been implemented. To add
6383 @c additional traits for target architecture, TARGET_OMP_DEVICE_KIND_ARCH_ISA
6384 @c has to be implemented; cf. also PR target/105640.
6385 @c For offload devices, add *additionally* gcc/config/*/t-omp-device.
6387 For the host compiler, @code{kind} always matches @code{host}; for the
6388 offloading architectures AMD GCN and Nvidia PTX, @code{kind} always matches
6389 @code{gpu}.  For the x86 family of computers, AMD GCN and Nvidia PTX
6390 the following traits are supported in addition; while OpenMP is supported
6391 on more architectures, GCC currently does not match any @code{arch} or
6392 @code{isa} traits for those.
6394 @multitable @columnfractions .65 .30
6395 @headitem @code{arch} @tab @code{isa}
6396 @item @code{x86}, @code{x86_64}, @code{i386}, @code{i486},
6397       @code{i586}, @code{i686}, @code{ia32}
6398       @tab See @code{-m...} flags in ``x86 Options'' (without @code{-m})
6399 @item @code{amdgcn}, @code{gcn}
6400       @tab See @code{-march=} in ``AMD GCN Options''
6401 @item @code{nvptx}, @code{nvptx64}
6402       @tab See @code{-march=} in ``Nvidia PTX Options''
6403 @end multitable
6405 @node Memory allocation
6406 @section Memory allocation
6408 The description below applies to:
6410 @itemize
6411 @item Explicit use of the OpenMP API routines, see
6412       @ref{Memory Management Routines}.
6413 @item The @code{allocate} clause, except when the @code{allocator} modifier is a
6414       constant expression with value @code{omp_default_mem_alloc} and no
6415       @code{align} modifier has been specified. (In that case, the normal
6416       @code{malloc} allocation is used.)
6417 @item Using the @code{allocate} directive for automatic/stack variables, except
6418       when the @code{allocator} clause is a constant expression with value
6419       @code{omp_default_mem_alloc} and no @code{align} clause has been
6420       specified. (In that case, the normal allocation is used: stack allocation
6421       and, sometimes for Fortran, also @code{malloc} [depending on flags such as
6422       @option{-fstack-arrays}].)
6423 @item Using the @code{allocate} directive for variable in static memory is
6424       currently not supported (compile time error).
6425 @item In Fortran, the @code{allocators} directive and the executable
6426       @code{allocate} directive for Fortran pointers and allocatables is
6427       supported, but requires that files containing those directives has to be
6428       compiled with @option{-fopenmp-allocators}.  Additionally, all files that
6429       might explicitly or implicitly deallocate memory allocated that way must
6430       also be compiled with that option.
6431 @end itemize
6433 For the available predefined allocators and, as applicable, their associated
6434 predefined memory spaces and for the available traits and their default values,
6435 see @ref{OMP_ALLOCATOR}.  Predefined allocators without an associated memory
6436 space use the @code{omp_default_mem_space} memory space.
6438 For the memory spaces, the following applies:
6439 @itemize
6440 @item @code{omp_default_mem_space} is supported
6441 @item @code{omp_const_mem_space} maps to @code{omp_default_mem_space}
6442 @item @code{omp_low_lat_mem_space} is only available on supported devices,
6443       and maps to @code{omp_default_mem_space} otherwise.
6444 @item @code{omp_large_cap_mem_space} maps to @code{omp_default_mem_space},
6445       unless the memkind library is available
6446 @item @code{omp_high_bw_mem_space} maps to @code{omp_default_mem_space},
6447       unless the memkind library is available
6448 @end itemize
6450 On Linux systems, where the @uref{https://github.com/memkind/memkind, memkind
6451 library} (@code{libmemkind.so.0}) is available at runtime, it is used when
6452 creating memory allocators requesting
6454 @itemize
6455 @item the memory space @code{omp_high_bw_mem_space}
6456 @item the memory space @code{omp_large_cap_mem_space}
6457 @item the @code{partition} trait @code{interleaved}; note that for
6458       @code{omp_large_cap_mem_space} the allocation will not be interleaved
6459 @end itemize
6461 On Linux systems, where the @uref{https://github.com/numactl/numactl, numa
6462 library} (@code{libnuma.so.1}) is available at runtime, it used when creating
6463 memory allocators requesting
6465 @itemize
6466 @item the @code{partition} trait @code{nearest}, except when both the
6467 libmemkind library is available and the memory space is either
6468 @code{omp_large_cap_mem_space} or @code{omp_high_bw_mem_space}
6469 @end itemize
6471 Note that the numa library will round up the allocation size to a multiple of
6472 the system page size; therefore, consider using it only with large data or
6473 by sharing allocations via the @code{pool_size} trait.  Furthermore, the Linux
6474 kernel does not guarantee that an allocation will always be on the nearest NUMA
6475 node nor that after reallocation the same node will be used.  Note additionally
6476 that, on Linux, the default setting of the memory placement policy is to use the
6477 current node; therefore, unless the memory placement policy has been overridden,
6478 the @code{partition} trait @code{environment} (the default) will be effectively
6479 a @code{nearest} allocation.
6481 Additional notes regarding the traits:
6482 @itemize
6483 @item The @code{pinned} trait is supported on Linux hosts, but is subject to
6484       the OS @code{ulimit}/@code{rlimit} locked memory settings.
6485 @item The default for the @code{pool_size} trait is no pool and for every
6486       (re)allocation the associated library routine is called, which might
6487       internally use a memory pool.
6488 @item For the @code{partition} trait, the partition part size will be the same
6489       as the requested size (i.e. @code{interleaved} or @code{blocked} has no
6490       effect), except for @code{interleaved} when the memkind library is
6491       available.  Furthermore, for @code{nearest} and unless the numa library
6492       is available, the memory might not be on the same NUMA node as thread
6493       that allocated the memory; on Linux, this is in particular the case when
6494       the memory placement policy is set to preferred.
6495 @item The @code{access} trait has no effect such that memory is always
6496       accessible by all threads.
6497 @item The @code{sync_hint} trait has no effect.
6498 @end itemize
6500 See also:
6501 @ref{Offload-Target Specifics}
6503 @c ---------------------------------------------------------------------
6504 @c Offload-Target Specifics
6505 @c ---------------------------------------------------------------------
6507 @node Offload-Target Specifics
6508 @chapter Offload-Target Specifics
6510 The following sections present notes on the offload-target specifics
6512 @menu
6513 * AMD Radeon::
6514 * nvptx::
6515 @end menu
6517 @node AMD Radeon
6518 @section AMD Radeon (GCN)
6520 On the hardware side, there is the hierarchy (fine to coarse):
6521 @itemize
6522 @item work item (thread)
6523 @item wavefront
6524 @item work group
6525 @item compute unit (CU)
6526 @end itemize
6528 All OpenMP and OpenACC levels are used, i.e.
6529 @itemize
6530 @item OpenMP's simd and OpenACC's vector map to work items (thread)
6531 @item OpenMP's threads (``parallel'') and OpenACC's workers map
6532       to wavefronts
6533 @item OpenMP's teams and OpenACC's gang use a threadpool with the
6534       size of the number of teams or gangs, respectively.
6535 @end itemize
6537 The used sizes are
6538 @itemize
6539 @item Number of teams is the specified @code{num_teams} (OpenMP) or
6540       @code{num_gangs} (OpenACC) or otherwise the number of CU. It is limited
6541       by two times the number of CU.
6542 @item Number of wavefronts is 4 for gfx900 and 16 otherwise;
6543       @code{num_threads} (OpenMP) and @code{num_workers} (OpenACC)
6544       overrides this if smaller.
6545 @item The wavefront has 102 scalars and 64 vectors
6546 @item Number of workitems is always 64
6547 @item The hardware permits maximally 40 workgroups/CU and
6548       16 wavefronts/workgroup up to a limit of 40 wavefronts in total per CU.
6549 @item 80 scalars registers and 24 vector registers in non-kernel functions
6550       (the chosen procedure-calling API).
6551 @item For the kernel itself: as many as register pressure demands (number of
6552       teams and number of threads, scaled down if registers are exhausted)
6553 @end itemize
6555 The implementation remark:
6556 @itemize
6557 @item I/O within OpenMP target regions and OpenACC compute regions is supported
6558       using the C library @code{printf} functions and the Fortran
6559       @code{print}/@code{write} statements.
6560 @item Reverse offload regions (i.e. @code{target} regions with
6561       @code{device(ancestor:1)}) are processed serially per @code{target} region
6562       such that the next reverse offload region is only executed after the previous
6563       one returned.
6564 @item OpenMP code that has a @code{requires} directive with
6565       @code{unified_shared_memory} is only supported if all AMD GPUs have the
6566       @code{HSA_AMD_SYSTEM_INFO_SVM_ACCESSIBLE_BY_DEFAULT} property; for
6567       discrete GPUs, this may require setting the @code{HSA_XNACK} environment
6568       variable to @samp{1}; for systems with both an APU and a discrete GPU that
6569       does not support XNACK, consider using @code{ROCR_VISIBLE_DEVICES} to
6570       enable only the APU.  If not supported, all AMD GPU devices are removed
6571       from the list of available devices (``host fallback'').
6572 @item The available stack size can be changed using the @code{GCN_STACK_SIZE}
6573       environment variable; the default is 32 kiB per thread.
6574 @item Low-latency memory (@code{omp_low_lat_mem_space}) is supported when the
6575       the @code{access} trait is set to @code{cgroup}.  The default pool size
6576       is automatically scaled to share the 64 kiB LDS memory between the number
6577       of teams configured to run on each compute-unit, but may be adjusted at
6578       runtime by setting environment variable
6579       @code{GOMP_GCN_LOWLAT_POOL=@var{bytes}}.
6580 @item @code{omp_low_lat_mem_alloc} cannot be used with true low-latency memory
6581       because the definition implies the @code{omp_atv_all} trait; main
6582       graphics memory is used instead.
6583 @item @code{omp_cgroup_mem_alloc}, @code{omp_pteam_mem_alloc}, and
6584       @code{omp_thread_mem_alloc}, all use low-latency memory as first
6585       preference, and fall back to main graphics memory when the low-latency
6586       pool is exhausted.
6587 @item The unique identifier (UID), used with OpenMP's API UID routines, is the
6588       value returned by the HSA runtime library for @code{HSA_AMD_AGENT_INFO_UUID}.
6589       For GPUs, it is currently @samp{GPU-} followed by 16 lower-case hex digits,
6590       yielding a string like @code{GPU-f914a2142fc3413a}.  The output matches
6591       the one used by @code{rocminfo}.
6592 @end itemize
6596 @node nvptx
6597 @section nvptx
6599 On the hardware side, there is the hierarchy (fine to coarse):
6600 @itemize
6601 @item thread
6602 @item warp
6603 @item thread block
6604 @item streaming multiprocessor
6605 @end itemize
6607 All OpenMP and OpenACC levels are used, i.e.
6608 @itemize
6609 @item OpenMP's simd and OpenACC's vector map to threads
6610 @item OpenMP's threads (``parallel'') and OpenACC's workers map to warps
6611 @item OpenMP's teams and OpenACC's gang use a threadpool with the
6612       size of the number of teams or gangs, respectively.
6613 @end itemize
6615 The used sizes are
6616 @itemize
6617 @item The @code{warp_size} is always 32
6618 @item CUDA kernel launched: @code{dim=@{#teams,1,1@}, blocks=@{#threads,warp_size,1@}}.
6619 @item The number of teams is limited by the number of blocks the device can
6620       host simultaneously.
6621 @end itemize
6623 Additional information can be obtained by setting the environment variable to
6624 @code{GOMP_DEBUG=1} (very verbose; grep for @code{kernel.*launch} for launch
6625 parameters).
6627 GCC generates generic PTX ISA code, which is just-in-time compiled by CUDA,
6628 which caches the JIT in the user's directory (see CUDA documentation; can be
6629 tuned by the environment variables @code{CUDA_CACHE_@{DISABLE,MAXSIZE,PATH@}}.
6631 Note: While PTX ISA is generic, the @code{-mptx=} and @code{-march=} commandline
6632 options still affect the used PTX ISA code and, thus, the requirements on
6633 CUDA version and hardware.
6635 The implementation remark:
6636 @itemize
6637 @item I/O within OpenMP target regions and OpenACC compute regions is supported
6638       using the C library @code{printf} functions.
6639       Additionally, the Fortran @code{print}/@code{write} statements are
6640       supported within OpenMP target regions, but not yet within OpenACC compute
6641       regions.  @c The latter needs 'GOMP_NVPTX_NATIVE_GPU_THREAD_STACK_SIZE'.
6642 @item Compilation OpenMP code that contains @code{requires reverse_offload}
6643       requires at least @code{-march=sm_35}, compiling for @code{-march=sm_30}
6644       is not supported.
6645 @item For code containing reverse offload (i.e. @code{target} regions with
6646       @code{device(ancestor:1)}), there is a slight performance penalty
6647       for @emph{all} target regions, consisting mostly of shutdown delay
6648       Per device, reverse offload regions are processed serially such that
6649       the next reverse offload region is only executed after the previous
6650       one returned.
6651 @item OpenMP code that has a @code{requires} directive with
6652       @code{unified_shared_memory} runs on nvptx devices if and only if
6653       all of those support the @code{pageableMemoryAccess} property;@footnote{
6654       @uref{https://docs.nvidia.com/cuda/cuda-c-programming-guide/index.html#um-requirements}}
6655       otherwise, all nvptx device are removed from the list of available
6656       devices (``host fallback'').
6657 @item The default per-warp stack size is 128 kiB; see also @code{-msoft-stack}
6658       in the GCC manual.
6659 @item The OpenMP routines @code{omp_target_memcpy_rect} and
6660       @code{omp_target_memcpy_rect_async} and the @code{target update}
6661       directive for non-contiguous list items will use the 2D and 3D
6662       memory-copy functions of the CUDA library.  Higher dimensions will
6663       call those functions in a loop and are therefore supported.
6664 @item Low-latency memory (@code{omp_low_lat_mem_space}) is supported when the
6665       the @code{access} trait is set to @code{cgroup}, the ISA is at least
6666       @code{sm_53}, and the PTX version is at least 4.1.  The default pool size
6667       is 8 kiB per team, but may be adjusted at runtime by setting environment
6668       variable @code{GOMP_NVPTX_LOWLAT_POOL=@var{bytes}}.  The maximum value is
6669       limited by the available hardware, and care should be taken that the
6670       selected pool size does not unduly limit the number of teams that can
6671       run simultaneously.
6672 @item @code{omp_low_lat_mem_alloc} cannot be used with true low-latency memory
6673       because the definition implies the @code{omp_atv_all} trait; main
6674       graphics memory is used instead.
6675 @item @code{omp_cgroup_mem_alloc}, @code{omp_pteam_mem_alloc}, and
6676       @code{omp_thread_mem_alloc}, all use low-latency memory as first
6677       preference, and fall back to main graphics memory when the low-latency
6678       pool is exhausted.
6679 @item The unique identifier (UID), used with OpenMP's API UID routines, consists
6680       of the @samp{GPU-} prefix followed by the 16-bytes UUID as returned by
6681       the CUDA runtime library.  This UUID is output in grouped lower-case
6682       hex digits; the grouping of those 32 digits is: 8 digits, hyphen,
6683       4 digits, hyphen, 4 digits, hyphen, 16 digits. This leads to a string
6684       like @code{GPU-a8081c9e-f03e-18eb-1827-bf5ba95afa5d}.  The output
6685       matches the format used by @code{nvidia-smi}.
6686 @end itemize
6689 @c ---------------------------------------------------------------------
6690 @c The libgomp ABI
6691 @c ---------------------------------------------------------------------
6693 @node The libgomp ABI
6694 @chapter The libgomp ABI
6696 The following sections present notes on the external ABI as 
6697 presented by libgomp.  Only maintainers should need them.
6699 @menu
6700 * Implementing MASTER construct::
6701 * Implementing CRITICAL construct::
6702 * Implementing ATOMIC construct::
6703 * Implementing FLUSH construct::
6704 * Implementing BARRIER construct::
6705 * Implementing THREADPRIVATE construct::
6706 * Implementing PRIVATE clause::
6707 * Implementing FIRSTPRIVATE LASTPRIVATE COPYIN and COPYPRIVATE clauses::
6708 * Implementing REDUCTION clause::
6709 * Implementing PARALLEL construct::
6710 * Implementing FOR construct::
6711 * Implementing ORDERED construct::
6712 * Implementing SECTIONS construct::
6713 * Implementing SINGLE construct::
6714 * Implementing OpenACC's PARALLEL construct::
6715 @end menu
6718 @node Implementing MASTER construct
6719 @section Implementing MASTER construct
6721 @smallexample
6722 if (omp_get_thread_num () == 0)
6723   block
6724 @end smallexample
6726 Alternately, we generate two copies of the parallel subfunction
6727 and only include this in the version run by the primary thread.
6728 Surely this is not worthwhile though...
6732 @node Implementing CRITICAL construct
6733 @section Implementing CRITICAL construct
6735 Without a specified name,
6737 @smallexample
6738   void GOMP_critical_start (void);
6739   void GOMP_critical_end (void);
6740 @end smallexample
6742 so that we don't get COPY relocations from libgomp to the main
6743 application.
6745 With a specified name, use omp_set_lock and omp_unset_lock with
6746 name being transformed into a variable declared like
6748 @smallexample
6749   omp_lock_t gomp_critical_user_<name> __attribute__((common))
6750 @end smallexample
6752 Ideally the ABI would specify that all zero is a valid unlocked
6753 state, and so we wouldn't need to initialize this at
6754 startup.
6758 @node Implementing ATOMIC construct
6759 @section Implementing ATOMIC construct
6761 The target should implement the @code{__sync} builtins.
6763 Failing that we could add
6765 @smallexample
6766   void GOMP_atomic_enter (void)
6767   void GOMP_atomic_exit (void)
6768 @end smallexample
6770 which reuses the regular lock code, but with yet another lock
6771 object private to the library.
6775 @node Implementing FLUSH construct
6776 @section Implementing FLUSH construct
6778 Expands to the @code{__sync_synchronize} builtin.
6782 @node Implementing BARRIER construct
6783 @section Implementing BARRIER construct
6785 @smallexample
6786   void GOMP_barrier (void)
6787 @end smallexample
6790 @node Implementing THREADPRIVATE construct
6791 @section Implementing THREADPRIVATE construct
6793 In _most_ cases we can map this directly to @code{__thread}.  Except
6794 that OMP allows constructors for C++ objects.  We can either
6795 refuse to support this (how often is it used?) or we can 
6796 implement something akin to .ctors.
6798 Even more ideally, this ctor feature is handled by extensions
6799 to the main pthreads library.  Failing that, we can have a set
6800 of entry points to register ctor functions to be called.
6804 @node Implementing PRIVATE clause
6805 @section Implementing PRIVATE clause
6807 In association with a PARALLEL, or within the lexical extent
6808 of a PARALLEL block, the variable becomes a local variable in
6809 the parallel subfunction.
6811 In association with FOR or SECTIONS blocks, create a new
6812 automatic variable within the current function.  This preserves
6813 the semantic of new variable creation.
6817 @node Implementing FIRSTPRIVATE LASTPRIVATE COPYIN and COPYPRIVATE clauses
6818 @section Implementing FIRSTPRIVATE LASTPRIVATE COPYIN and COPYPRIVATE clauses
6820 This seems simple enough for PARALLEL blocks.  Create a private 
6821 struct for communicating between the parent and subfunction.
6822 In the parent, copy in values for scalar and "small" structs;
6823 copy in addresses for others TREE_ADDRESSABLE types.  In the 
6824 subfunction, copy the value into the local variable.
6826 It is not clear what to do with bare FOR or SECTION blocks.
6827 The only thing I can figure is that we do something like:
6829 @smallexample
6830 #pragma omp for firstprivate(x) lastprivate(y)
6831 for (int i = 0; i < n; ++i)
6832   body;
6833 @end smallexample
6835 which becomes
6837 @smallexample
6839   int x = x, y;
6841   // for stuff
6843   if (i == n)
6844     y = y;
6846 @end smallexample
6848 where the "x=x" and "y=y" assignments actually have different
6849 uids for the two variables, i.e. not something you could write
6850 directly in C.  Presumably this only makes sense if the "outer"
6851 x and y are global variables.
6853 COPYPRIVATE would work the same way, except the structure 
6854 broadcast would have to happen via SINGLE machinery instead.
6858 @node Implementing REDUCTION clause
6859 @section Implementing REDUCTION clause
6861 The private struct mentioned in the previous section should have 
6862 a pointer to an array of the type of the variable, indexed by the 
6863 thread's @var{team_id}.  The thread stores its final value into the 
6864 array, and after the barrier, the primary thread iterates over the
6865 array to collect the values.
6868 @node Implementing PARALLEL construct
6869 @section Implementing PARALLEL construct
6871 @smallexample
6872   #pragma omp parallel
6873   @{
6874     body;
6875   @}
6876 @end smallexample
6878 becomes
6880 @smallexample
6881   void subfunction (void *data)
6882   @{
6883     use data;
6884     body;
6885   @}
6887   setup data;
6888   GOMP_parallel_start (subfunction, &data, num_threads);
6889   subfunction (&data);
6890   GOMP_parallel_end ();
6891 @end smallexample
6893 @smallexample
6894   void GOMP_parallel_start (void (*fn)(void *), void *data, unsigned num_threads)
6895 @end smallexample
6897 The @var{FN} argument is the subfunction to be run in parallel.
6899 The @var{DATA} argument is a pointer to a structure used to 
6900 communicate data in and out of the subfunction, as discussed
6901 above with respect to FIRSTPRIVATE et al.
6903 The @var{NUM_THREADS} argument is 1 if an IF clause is present
6904 and false, or the value of the NUM_THREADS clause, if
6905 present, or 0.
6907 The function needs to create the appropriate number of
6908 threads and/or launch them from the dock.  It needs to
6909 create the team structure and assign team ids.
6911 @smallexample
6912   void GOMP_parallel_end (void)
6913 @end smallexample
6915 Tears down the team and returns us to the previous @code{omp_in_parallel()} state.
6919 @node Implementing FOR construct
6920 @section Implementing FOR construct
6922 @smallexample
6923   #pragma omp parallel for
6924   for (i = lb; i <= ub; i++)
6925     body;
6926 @end smallexample
6928 becomes
6930 @smallexample
6931   void subfunction (void *data)
6932   @{
6933     long _s0, _e0;
6934     while (GOMP_loop_static_next (&_s0, &_e0))
6935     @{
6936       long _e1 = _e0, i;
6937       for (i = _s0; i < _e1; i++)
6938         body;
6939     @}
6940     GOMP_loop_end_nowait ();
6941   @}
6943   GOMP_parallel_loop_static (subfunction, NULL, 0, lb, ub+1, 1, 0);
6944   subfunction (NULL);
6945   GOMP_parallel_end ();
6946 @end smallexample
6948 @smallexample
6949   #pragma omp for schedule(runtime)
6950   for (i = 0; i < n; i++)
6951     body;
6952 @end smallexample
6954 becomes
6956 @smallexample
6957   @{
6958     long i, _s0, _e0;
6959     if (GOMP_loop_runtime_start (0, n, 1, &_s0, &_e0))
6960       do @{
6961         long _e1 = _e0;
6962         for (i = _s0, i < _e0; i++)
6963           body;
6964       @} while (GOMP_loop_runtime_next (&_s0, _&e0));
6965     GOMP_loop_end ();
6966   @}
6967 @end smallexample
6969 Note that while it looks like there is trickiness to propagating
6970 a non-constant STEP, there isn't really.  We're explicitly allowed
6971 to evaluate it as many times as we want, and any variables involved
6972 should automatically be handled as PRIVATE or SHARED like any other
6973 variables.  So the expression should remain evaluable in the 
6974 subfunction.  We can also pull it into a local variable if we like,
6975 but since its supposed to remain unchanged, we can also not if we like.
6977 If we have SCHEDULE(STATIC), and no ORDERED, then we ought to be
6978 able to get away with no work-sharing context at all, since we can
6979 simply perform the arithmetic directly in each thread to divide up
6980 the iterations.  Which would mean that we wouldn't need to call any
6981 of these routines.
6983 There are separate routines for handling loops with an ORDERED
6984 clause.  Bookkeeping for that is non-trivial...
6988 @node Implementing ORDERED construct
6989 @section Implementing ORDERED construct
6991 @smallexample
6992   void GOMP_ordered_start (void)
6993   void GOMP_ordered_end (void)
6994 @end smallexample
6998 @node Implementing SECTIONS construct
6999 @section Implementing SECTIONS construct
7001 A block as 
7003 @smallexample
7004   #pragma omp sections
7005   @{
7006     #pragma omp section
7007     stmt1;
7008     #pragma omp section
7009     stmt2;
7010     #pragma omp section
7011     stmt3;
7012   @}
7013 @end smallexample
7015 becomes
7017 @smallexample
7018   for (i = GOMP_sections_start (3); i != 0; i = GOMP_sections_next ())
7019     switch (i)
7020       @{
7021       case 1:
7022         stmt1;
7023         break;
7024       case 2:
7025         stmt2;
7026         break;
7027       case 3:
7028         stmt3;
7029         break;
7030       @}
7031   GOMP_barrier ();
7032 @end smallexample
7035 @node Implementing SINGLE construct
7036 @section Implementing SINGLE construct
7038 A block like 
7040 @smallexample
7041   #pragma omp single
7042   @{
7043     body;
7044   @}
7045 @end smallexample
7047 becomes
7049 @smallexample
7050   if (GOMP_single_start ())
7051     body;
7052   GOMP_barrier ();
7053 @end smallexample
7055 while 
7057 @smallexample
7058   #pragma omp single copyprivate(x)
7059     body;
7060 @end smallexample
7062 becomes
7064 @smallexample
7065   datap = GOMP_single_copy_start ();
7066   if (datap == NULL)
7067     @{
7068       body;
7069       data.x = x;
7070       GOMP_single_copy_end (&data);
7071     @}
7072   else
7073     x = datap->x;
7074   GOMP_barrier ();
7075 @end smallexample
7079 @node Implementing OpenACC's PARALLEL construct
7080 @section Implementing OpenACC's PARALLEL construct
7082 @smallexample
7083   void GOACC_parallel ()
7084 @end smallexample
7088 @c ---------------------------------------------------------------------
7089 @c Reporting Bugs
7090 @c ---------------------------------------------------------------------
7092 @node Reporting Bugs
7093 @chapter Reporting Bugs
7095 Bugs in the GNU Offloading and Multi Processing Runtime Library should
7096 be reported via @uref{https://gcc.gnu.org/bugzilla/, Bugzilla}.  Please add
7097 "openacc", or "openmp", or both to the keywords field in the bug
7098 report, as appropriate.
7102 @c ---------------------------------------------------------------------
7103 @c GNU General Public License
7104 @c ---------------------------------------------------------------------
7106 @include gpl_v3.texi
7110 @c ---------------------------------------------------------------------
7111 @c GNU Free Documentation License
7112 @c ---------------------------------------------------------------------
7114 @include fdl.texi
7118 @c ---------------------------------------------------------------------
7119 @c Funding Free Software
7120 @c ---------------------------------------------------------------------
7122 @include funding.texi
7124 @c ---------------------------------------------------------------------
7125 @c Index
7126 @c ---------------------------------------------------------------------
7128 @node Library Index
7129 @unnumbered Library Index
7131 @printindex cp
7133 @bye