]> git.ipfire.org Git - thirdparty/gcc.git/blame_incremental - libgomp/libgomp.texi
c++: uninitialized TARGET_EXPR and constexpr [PR120684]
[thirdparty/gcc.git] / libgomp / libgomp.texi
... / ...
CommitLineData
1\input texinfo @c -*-texinfo-*-
2
3@c %**start of header
4@setfilename libgomp.info
5@settitle GNU libgomp
6@c %**end of header
7
8
9@copying
10Copyright @copyright{} 2006-2025 Free Software Foundation, Inc.
11
12Permission is granted to copy, distribute and/or modify this document
13under the terms of the GNU Free Documentation License, Version 1.3 or
14any later version published by the Free Software Foundation; with the
15Invariant Sections being ``Funding Free Software'', the Front-Cover
16texts 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''.
19
20(a) The FSF's Front-Cover Text is:
21
22 A GNU Manual
23
24(b) The FSF's Back-Cover Text is:
25
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
30
31@ifinfo
32@dircategory GNU Libraries
33@direntry
34* libgomp: (libgomp). GNU Offloading and Multi Processing Runtime Library.
35@end direntry
36
37This manual documents libgomp, the GNU Offloading and Multi Processing
38Runtime library. This is the GNU implementation of the OpenMP and
39OpenACC APIs for parallel and accelerator programming in C/C++ and
40Fortran.
41
42Published by the Free Software Foundation
4351 Franklin Street, Fifth Floor
44Boston, MA 02110-1301 USA
45
46@insertcopying
47@end ifinfo
48
49
50@setchapternewpage odd
51
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
59Published by the Free Software Foundation @*
6051 Franklin Street, Fifth Floor@*
61Boston, MA 02110-1301, USA@*
62@sp 1
63@insertcopying
64@end titlepage
65
66@summarycontents
67@contents
68@page
69
70
71@node Top, Enabling OpenMP
72@top Introduction
73@cindex Introduction
74
75This manual documents the usage of libgomp, the GNU Offloading and
76Multi Processing Runtime Library. This includes the GNU
77implementation of the @uref{https://www.openmp.org, OpenMP} Application
78Programming Interface (API) for multi-platform shared-memory parallel
79programming in C/C++ and Fortran, and the GNU implementation of the
80@uref{https://www.openacc.org, OpenACC} Application Programming
81Interface (API) for offloading of code to accelerator devices in C/C++
82and Fortran.
83
84Originally, libgomp implemented the GNU OpenMP Runtime Library. Based
85on this, support for OpenACC and offloading (both OpenACC and OpenMP
864's target construct) has been added later on, and the library's name
87changed to GNU Offloading and Multi Processing Runtime Library.
88
89
90
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
130
131
132@c ---------------------------------------------------------------------
133@c Enabling OpenMP
134@c ---------------------------------------------------------------------
135
136@node Enabling OpenMP
137@chapter Enabling OpenMP
138
139To activate the OpenMP extensions for C/C++ and Fortran, the compile-time
140flag @option{-fopenmp} must be specified. For C and C++, this enables
141the 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
144free 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
147the @code{c$}, @code{*$} and @code{!$} conditional compilation sentinels.
148The flag also arranges for automatic linking of the OpenMP runtime library
149(@ref{Runtime Library Routines}).
150
151The @option{-fopenmp-simd} flag can be used to enable a subset of
152OpenMP directives that do not require the linking of either the
153OpenMP runtime library or the POSIX threads library.
154
155A complete description of all OpenMP directives may be found in the
156@uref{https://www.openmp.org, OpenMP Application Program Interface} manuals.
157See also @ref{OpenMP Implementation Status}.
158
159
160@c ---------------------------------------------------------------------
161@c OpenMP Implementation Status
162@c ---------------------------------------------------------------------
163
164@node OpenMP Implementation Status
165@chapter OpenMP Implementation Status
166
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 6.0:: Feature completion status to 6.0 specification
173@end menu
174
175The @code{_OPENMP} preprocessor macro and Fortran's @code{openmp_version}
176parameter, provided by @code{omp_lib.h} and the @code{omp_lib} module, have
177the value @code{201511} (i.e. OpenMP 4.5).
178
179@node OpenMP 4.5
180@section OpenMP 4.5
181
182The OpenMP 4.5 specification is fully supported.
183
184@node OpenMP 5.0
185@section OpenMP 5.0
186
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
189
190@multitable @columnfractions .60 .10 .25
191@headitem Description @tab Status @tab Comments
192@item Array shaping @tab N @tab
193@item Array sections with non-unit strides in C and C++ @tab N @tab
194@item Iterators @tab Y @tab
195@item @code{metadirective} directive @tab Y @tab
196@item @code{declare variant} directive @tab Y @tab
197@item @var{target-offload-var} ICV and @code{OMP_TARGET_OFFLOAD}
198 env variable @tab Y @tab
199@item Nested-parallel changes to @var{max-active-levels-var} ICV @tab Y @tab
200@item @code{requires} directive @tab Y
201 @tab See also @ref{Offload-Target Specifics}
202@item @code{teams} construct outside an enclosing target region @tab Y @tab
203@item Non-rectangular loop nests @tab P
204 @tab Full support for C/C++, partial for Fortran
205 (@uref{https://gcc.gnu.org/PR110735,PR110735})
206@item @code{!=} as relational-op in canonical loop form for C/C++ @tab Y @tab
207@item @code{nonmonotonic} as default loop schedule modifier for worksharing-loop
208 constructs @tab Y @tab
209@item Collapse of associated loops that are imperfectly nested loops @tab Y @tab
210@item Clauses @code{if}, @code{nontemporal} and @code{order(concurrent)} in
211 @code{simd} construct @tab Y @tab
212@item @code{atomic} constructs in @code{simd} @tab Y @tab
213@item @code{loop} construct @tab Y @tab
214@item @code{order(concurrent)} clause @tab Y @tab
215@item @code{scan} directive and @code{in_scan} modifier for the
216 @code{reduction} clause @tab Y @tab
217@item @code{in_reduction} clause on @code{task} constructs @tab Y @tab
218@item @code{in_reduction} clause on @code{target} constructs @tab P
219 @tab @code{nowait} only stub
220@item @code{task_reduction} clause with @code{taskgroup} @tab Y @tab
221@item @code{task} modifier to @code{reduction} clause @tab Y @tab
222@item @code{affinity} clause to @code{task} construct @tab Y @tab Stub only
223@item @code{detach} clause to @code{task} construct @tab Y @tab
224@item @code{omp_fulfill_event} runtime routine @tab Y @tab
225@item @code{reduction} and @code{in_reduction} clauses on @code{taskloop}
226 and @code{taskloop simd} constructs @tab Y @tab
227@item @code{taskloop} construct cancelable by @code{cancel} construct
228 @tab Y @tab
229@item @code{mutexinoutset} @emph{dependence-type} for @code{depend} clause
230 @tab Y @tab
231@item Predefined memory spaces, memory allocators, allocator traits
232 @tab Y @tab See also @ref{Memory allocation}
233@item Memory management routines @tab Y @tab
234@item @code{allocate} directive @tab P
235 @tab C++ unsupported; see also @ref{Memory allocation}
236@item @code{allocate} clause @tab P @tab Clause has no effect on @code{target}
237 (@uref{https://gcc.gnu.org/PR113436,PR113436})
238@item @code{use_device_addr} clause on @code{target data} @tab Y @tab
239@item @code{ancestor} modifier on @code{device} clause @tab Y @tab
240@item Implicit declare target directive @tab Y @tab
241@item Discontiguous array section with @code{target update} construct
242 @tab N @tab
243@item C/C++'s lvalue expressions in @code{to}, @code{from}
244 and @code{map} clauses @tab Y @tab
245@item C/C++'s lvalue expressions in @code{depend} clauses @tab Y @tab
246@item Nested @code{declare target} directive @tab Y @tab
247@item Combined @code{master} constructs @tab Y @tab
248@item @code{depend} clause on @code{taskwait} @tab Y @tab
249@item Weak memory ordering clauses on @code{atomic} and @code{flush} construct
250 @tab Y @tab
251@item @code{hint} clause on the @code{atomic} construct @tab Y @tab Stub only
252@item @code{depobj} construct and depend objects @tab Y @tab
253@item Lock hints were renamed to synchronization hints @tab Y @tab
254@item @code{conditional} modifier to @code{lastprivate} clause @tab Y @tab
255@item Map-order clarifications @tab P @tab
256@item @code{close} @emph{map-type-modifier} @tab Y @tab
257@item Mapping C/C++ pointer variables and to assign the address of
258 device memory mapped by an array section @tab P @tab
259@item Mapping of Fortran pointer and allocatable variables, including pointer
260 and allocatable components of variables
261 @tab Y @tab
262@item @code{defaultmap} extensions @tab Y @tab
263@item @code{declare mapper} directive @tab N @tab
264@item @code{omp_get_supported_active_levels} routine @tab Y @tab
265@item Runtime routines and environment variables to display runtime thread
266 affinity information @tab Y @tab
267@item @code{omp_pause_resource} and @code{omp_pause_resource_all} runtime
268 routines @tab Y @tab
269@item @code{omp_get_device_num} runtime routine @tab Y @tab
270@item OMPT interface @tab N @tab
271@item OMPD interface @tab N @tab
272@end multitable
273
274@unnumberedsubsec Other new OpenMP 5.0 features
275
276@multitable @columnfractions .60 .10 .25
277@headitem Description @tab Status @tab Comments
278@item Supporting C++'s range-based for loop @tab Y @tab
279@end multitable
280
281
282@node OpenMP 5.1
283@section OpenMP 5.1
284
285@unnumberedsubsec New features listed in Appendix B of the OpenMP specification
286
287@multitable @columnfractions .60 .10 .25
288@headitem Description @tab Status @tab Comments
289@item OpenMP directive as C++ attribute specifiers @tab Y @tab
290@item @code{omp_all_memory} reserved locator @tab Y @tab
291@item @emph{target_device trait} in OpenMP Context @tab Y
292@item @code{target_device} selector set in context selectors @tab Y @tab
293@item C/C++'s @code{declare variant} directive: elision support of
294 preprocessed code @tab N @tab
295@item @code{declare variant}: new clauses @code{adjust_args} and
296 @code{append_args} @tab Y @tab
297@item @code{dispatch} construct @tab Y @tab
298@item device-specific ICV settings with environment variables @tab Y @tab
299@item @code{assume} and @code{assumes} directives @tab Y @tab
300@item @code{nothing} directive @tab Y @tab
301@item @code{error} directive @tab Y @tab
302@item @code{masked} construct @tab Y @tab
303@item @code{scope} directive @tab Y @tab
304@item Loop transformation constructs @tab Y @tab
305@item @code{strict} modifier in the @code{grainsize} and @code{num_tasks}
306 clauses of the @code{taskloop} construct @tab Y @tab
307@item @code{align} clause in @code{allocate} directive @tab P
308 @tab Only C and Fortran
309@item @code{align} modifier in @code{allocate} clause @tab Y @tab
310@item @code{thread_limit} clause to @code{target} construct @tab Y @tab
311@item @code{has_device_addr} clause to @code{target} construct @tab Y @tab
312@item Iterators in @code{target update} motion clauses and @code{map}
313 clauses @tab N @tab
314@item Indirect calls to the device version of a procedure or function in
315 @code{target} regions @tab Y @tab
316@item @code{interop} directive @tab Y @tab Cf. @ref{Offload-Target Specifics}
317@item @code{omp_interop_t} object support in runtime routines @tab Y @tab
318@item @code{nowait} clause in @code{taskwait} directive @tab Y @tab
319@item Extensions to the @code{atomic} directive @tab Y @tab
320@item @code{seq_cst} clause on a @code{flush} construct @tab Y @tab
321@item @code{inoutset} argument to the @code{depend} clause @tab Y @tab
322@item @code{private} and @code{firstprivate} argument to @code{default}
323 clause in C and C++ @tab Y @tab
324@item @code{present} argument to @code{defaultmap} clause @tab Y @tab
325@item @code{omp_set_num_teams}, @code{omp_set_teams_thread_limit},
326 @code{omp_get_max_teams}, @code{omp_get_teams_thread_limit} runtime
327 routines @tab Y @tab
328@item @code{omp_target_is_accessible} runtime routine @tab Y @tab
329@item @code{omp_target_memcpy_async} and @code{omp_target_memcpy_rect_async}
330 runtime routines @tab Y @tab
331@item @code{omp_get_mapped_ptr} runtime routine @tab Y @tab
332@item @code{omp_calloc}, @code{omp_realloc}, @code{omp_aligned_alloc} and
333 @code{omp_aligned_calloc} runtime routines @tab Y @tab
334@item @code{omp_alloctrait_key_t} enum: @code{omp_atv_serialized} added,
335 @code{omp_atv_default} changed @tab Y @tab
336@item @code{omp_display_env} runtime routine @tab Y @tab
337@item @code{ompt_scope_endpoint_t} enum: @code{ompt_scope_beginend} @tab N @tab
338@item @code{ompt_sync_region_t} enum additions @tab N @tab
339@item @code{ompt_state_t} enum: @code{ompt_state_wait_barrier_implementation}
340 and @code{ompt_state_wait_barrier_teams} @tab N @tab
341@item @code{ompt_callback_target_data_op_emi_t},
342 @code{ompt_callback_target_emi_t}, @code{ompt_callback_target_map_emi_t}
343 and @code{ompt_callback_target_submit_emi_t} @tab N @tab
344@item @code{ompt_callback_error_t} type @tab N @tab
345@item @code{OMP_PLACES} syntax extensions @tab Y @tab
346@item @code{OMP_NUM_TEAMS} and @code{OMP_TEAMS_THREAD_LIMIT} environment
347 variables @tab Y @tab
348@end multitable
349
350@unnumberedsubsec Other new OpenMP 5.1 features
351
352@multitable @columnfractions .60 .10 .25
353@headitem Description @tab Status @tab Comments
354@item Support of strictly structured blocks in Fortran @tab Y @tab
355@item Support of structured block sequences in C/C++ @tab Y @tab
356@item @code{unconstrained} and @code{reproducible} modifiers on @code{order}
357 clause @tab Y @tab
358@item Support @code{begin/end declare target} syntax in C/C++ @tab Y @tab
359@item Pointer predetermined firstprivate getting initialized
360to address of matching mapped list item per 5.1, Sect. 2.21.7.2 @tab N @tab
361@item For Fortran, diagnose placing declarative before/between @code{USE},
362 @code{IMPORT}, and @code{IMPLICIT} as invalid @tab N @tab
363@item Optional comma between directive and clause in the @code{#pragma} form @tab Y @tab
364@item @code{indirect} clause in @code{declare target} @tab Y @tab
365@item @code{device_type(nohost)}/@code{device_type(host)} for variables @tab N @tab
366@item @code{present} modifier to the @code{map}, @code{to} and @code{from}
367 clauses @tab Y @tab
368@item Changed interaction between @code{declare target} and OpenMP context
369 @tab Y @tab
370@item Dynamic selector support in @code{metadirective} @tab Y @tab
371@item Dynamic selector support in @code{declare variant} @tab P
372 @tab Fortran rejects non-constant expressions in dynamic selectors;
373 C/C++ reject expressions using argument variables.
374 (@uref{https://gcc.gnu.org/PR113904,PR113904})
375@end multitable
376
377
378@node OpenMP 5.2
379@section OpenMP 5.2
380
381@unnumberedsubsec New features listed in Appendix B of the OpenMP specification
382
383@multitable @columnfractions .60 .10 .25
384@headitem Description @tab Status @tab Comments
385@item @code{omp_in_explicit_task} routine and @var{explicit-task-var} ICV
386 @tab Y @tab
387@item @code{omp}/@code{ompx}/@code{omx} sentinels and @code{omp_}/@code{ompx_}
388 namespaces @tab N/A
389 @tab warning for @code{ompx/omx} sentinels@footnote{The @code{ompx}
390 sentinel as C/C++ pragma and C++ attributes are warned for with
391 @code{-Wunknown-pragmas} (implied by @code{-Wall}) and @code{-Wattributes}
392 (enabled by default), respectively; for Fortran free-source code, there is
393 a warning enabled by default and, for fixed-source code, the @code{omx}
394 sentinel is warned for with @code{-Wsurprising} (enabled by
395 @code{-Wall}). Unknown clauses are always rejected with an error.}
396@item Clauses on @code{end} directive can be on directive @tab Y @tab
397@item @code{destroy} clause with destroy-var argument on @code{depobj}
398 @tab Y @tab
399@item Deprecation of no-argument @code{destroy} clause on @code{depobj}
400 @tab N/A @tab undeprecated in OpenMP 6
401@item @code{linear} clause syntax changes and @code{step} modifier @tab Y @tab
402@item Deprecation of minus operator for reductions @tab N @tab
403@item Deprecation of separating @code{map} modifiers without comma @tab N @tab
404@item @code{declare mapper} with iterator and @code{present} modifiers
405 @tab N @tab
406@item If a matching mapped list item is not found in the data environment, the
407 pointer retains its original value @tab Y @tab
408@item New @code{enter} clause as alias for @code{to} on declare target directive
409 @tab Y @tab
410@item Deprecation of @code{to} clause on declare target directive @tab N @tab
411@item Extended list of directives permitted in Fortran pure procedures
412 @tab Y @tab
413@item New @code{allocators} directive for Fortran @tab Y @tab
414@item Deprecation of @code{allocate} directive for Fortran
415 allocatables/pointers @tab N @tab
416@item Optional paired @code{end} directive with @code{dispatch} @tab Y @tab
417@item New @code{memspace} and @code{traits} modifiers for @code{uses_allocators}
418 @tab N @tab
419@item Deprecation of traits array following the allocator_handle expression in
420 @code{uses_allocators} @tab N @tab
421@item New @code{otherwise} clause as alias for @code{default} on metadirectives
422 @tab Y @tab
423@item Deprecation of @code{default} clause on metadirectives @tab N
424 @tab Both @code{otherwise} and @code{default} are accepted
425 without diagnostics.
426@item Deprecation of delimited form of @code{declare target} @tab N @tab
427@item Reproducible semantics changed for @code{order(concurrent)} @tab N @tab
428@item @code{allocate} and @code{firstprivate} clauses on @code{scope}
429 @tab Y @tab
430@item @code{ompt_callback_work} @tab N @tab
431@item Default map-type for the @code{map} clause in @code{target enter/exit data}
432 @tab Y @tab
433@item New @code{doacross} clause as alias for @code{depend} with
434 @code{source}/@code{sink} modifier @tab Y @tab
435@item Deprecation of @code{depend} with @code{source}/@code{sink} modifier
436 @tab N @tab
437@item @code{omp_cur_iteration} keyword @tab Y @tab
438@end multitable
439
440@unnumberedsubsec Other new OpenMP 5.2 features
441
442@multitable @columnfractions .60 .10 .25
443@headitem Description @tab Status @tab Comments
444@item For Fortran, optional comma between directive and clause @tab N @tab
445@item Conforming device numbers and @code{omp_initial_device} and
446 @code{omp_invalid_device} enum/PARAMETER @tab Y @tab
447@item Initial value of @var{default-device-var} ICV with
448 @code{OMP_TARGET_OFFLOAD=mandatory} @tab Y @tab
449@item @code{all} as @emph{implicit-behavior} for @code{defaultmap} @tab Y @tab
450@item @emph{interop_types} in any position of the modifier list for the @code{init} clause
451 of the @code{interop} construct @tab Y @tab
452@item Invoke virtual member functions of C++ objects created on the host device
453 on other devices @tab N @tab
454@item @code{mapper} as map-type modifier in @code{declare mapper} @tab N @tab
455@end multitable
456
457
458@node OpenMP 6.0
459@section OpenMP 6.0
460
461@unnumberedsubsec New features listed in Appendix B of the OpenMP specification
462@multitable @columnfractions .60 .10 .25
463@item Features deprecated in versions 5.0, 5.1 and 5.2 were removed
464 @tab N/A @tab Backward compatibility
465@item Full support for C23 was added @tab P @tab
466@item Full support for C++23 was added @tab P @tab
467@item Full support for Fortran 2023 was added @tab P @tab
468@item @code{_ALL} suffix to the device-scope environment variables
469 @tab P @tab Host device number wrongly accepted
470@item @code{num_threads} clause now accepts a list @tab N @tab
471@item Abstract names added for @code{OMP_NUM_THREADS},
472 @code{OMP_THREAD_LIMIT} and @code{OMP_TEAMS_THREAD_LIMIT}
473 @tab N @tab
474@item Supporting increments with abstract names in @code{OMP_PLACES} @tab N @tab
475@item Extension of @code{OMP_DEFAULT_DEVICE} and new
476 @code{OMP_AVAILABLE_DEVICES} environment vars @tab N @tab
477@item New @code{uid} trait for target devices and for
478 @code{OMP_AVAILABLE_DEVICES} and @code{OMP_DEFAULT_DEVICE} @tab N @tab
479@item New @code{OMP_THREADS_RESERVE} environment variable @tab N @tab
480@item The @code{decl} attribute was added to the C++ attribute syntax
481 @tab Y @tab
482@item The OpenMP directive syntax was extended to include C23 attribute
483 specifiers @tab Y @tab
484@item Support for pure directives in Fortran's @code{do concurrent} @tab N @tab
485@item All inarguable clauses take now an optional Boolean argument @tab N @tab
486@item The @code{adjust_args} clause was extended to specify the argument by position
487 and supports variadic arguments @tab N @tab
488@item For Fortran, @emph{locator list} can be also function reference with
489 data pointer result @tab N @tab
490@item Concept of @emph{assumed-size arrays} in C and C++
491 @tab N @tab
492@item @emph{directive-name-modifier} accepted in all clauses @tab N @tab
493@item Extension of @code{interop} operation of @code{append_args}, allowing
494 all modifiers of the @code{init} clause @tab Y @tab
495@item New argument-free version of @code{depobj} with repeatable clauses and
496 the @code{init} clause @tab N @tab
497@item Undeprecate omitting the argument to the @code{depend} clause of
498 the argument version of the @code{depend} construct @tab Y @tab
499@item For Fortran, atomic with BLOCK construct and, for C/C++, with
500 unlimited curly braces supported @tab N @tab
501@item For Fortran, atomic with pointer comparison @tab N @tab
502@item For Fortran, atomic with enum and enumeration types @tab N @tab
503@item For Fortran, atomic compare with storing the comparison result
504 @tab N @tab
505@item Canonical loop sequences and new @code{looprange} clause @tab N @tab
506@item For Fortran, handling polymorphic types in data-sharing-attribute
507 clauses @tab P @tab @code{private} not supported
508@item For Fortran, rejecting polymorphic types in data-mapping clauses
509 @tab N @tab not diagnosed (and mostly unsupported)
510@item New @code{taskgraph} construct including @code{saved} modifier and
511 @code{replayable} clause @tab N @tab
512@item @code{default} clause on the @code{target} directive and accepting
513 variable categories @tab N @tab
514@item Semantic change regarding the reference count update with
515 @code{use_device_ptr} and @code{use_device_addr} @tab N @tab
516@item Support for inductions @tab N @tab
517@item Reduction over private variables with @code{reduction} clause
518 @tab N @tab
519@item Implicit reduction identifiers of C++ classes
520 @tab N @tab
521@item New @code{init_complete} clause to the @code{scan} directive
522 @tab N @tab
523@item @code{ref} modifier to the @code{map} clause @tab N @tab
524@item New @code{storage} map-type modifier; context-dependent @code{alloc} and
525 @code{release} are aliases @tab N @tab
526@item Change of the @emph{map-type} property from @emph{ultimate} to
527 @emph{default} @tab N @tab
528@item @code{self} modifier to @code{map} and @code{self} as
529 @code{defaultmap} argument @tab N @tab
530@item Mapping of @emph{assumed-size arrays} in C, C++ and Fortran
531 @tab N @tab
532@item @code{delete} as delete-modifier not as map type @tab N @tab
533@item For Fortran, the @code{automap} modifier to the @code{enter} clause
534 of @code{declare_target} @tab N @tab
535@item @code{groupprivate} directive @tab N @tab
536@item @code{local} clause to @code{declare_target} directive @tab N @tab
537@item @code{part_size} allocator trait for @code{interleaved} allocator
538 partitions @tab N @tab
539@item @code{pin_device}, @code{preferred_device} and @code{target_access}
540 allocator traits
541 @tab N @tab
542@item @code{access} allocator trait changes @tab N @tab
543@item New @code{partitioner} value to @code{partition} allocator trait
544 @tab N @tab
545@item Semicolon-separated list to @code{uses_allocators} @tab N @tab
546@item New @code{need_device_addr} modifier to @code{adjust_args} clause @tab N @tab
547@item @code{interop} clause to @code{dispatch} @tab Y @tab
548@item Scope requirement changes for @code{declare_target} @tab N @tab
549@item @code{message} and @code{severity} clauses to @code{parallel} directive
550 @tab N @tab
551@item @code{self_maps} clause to @code{requires} directive @tab Y @tab
552@item @code{no_openmp_constructs} assumptions clause @tab N @tab
553@item Restriction for @code{ordered} regarding loop-transforming directives
554 @tab N @tab
555@item @code{apply} clause to loop-transforming constructs @tab N @tab
556@item Non-constant values in the @code{sizes} clause @tab N @tab
557@item @code{fuse} loop-transformation construct @tab N @tab
558@item @code{interchange} loop-transformation construct @tab N @tab
559@item @code{reverse} loop-transformation construct @tab N @tab
560@item @code{split} loop-transformation construct @tab N @tab
561@item @code{stripe} loop-transformation construct @tab N @tab
562@item @code{tile} permitting association of grid and inter-tile loops @tab N @tab
563@item @code{strict} modifier keyword to @code{num_threads} @tab N @tab
564@item @code{safesync} clause to the @code{parallel} construct @tab N @tab
565@item @code{omp_curr_progress_width} identifier @tab N @tab
566@item @code{omp_get_max_progress_width} runtime routine @tab N @tab
567@item Lifted restrictions on @code{order(concurrent)} and, hence, the
568 @code{loop} construct @tab N @tab
569@item @code{atomic} permitted in a construct with @code{order(concurrent)}
570 @tab N @tab
571@item Lifted restrictions on not-strictly-nested regions with
572 @code{order(concurrent)} @tab N @tab
573@item @code{workdistribute} directive for Fortran @tab N @tab
574@item Fortran @code{DO CONCURRENT} as associated loop in a @code{loop} construct
575 @tab N @tab
576@item New @code{task_iteration} directive inside @code{taskloop} @tab N @tab
577@item @code{threadset} clause in task-generating constructs @tab N @tab
578@item New @code{priority} clause to @code{target}, @code{target_enter_data},
579 @code{target_data}, @code{target_exit_data} and @code{target_update}
580 @tab N @tab
581@item New @code{device_type} clause to the @code{target} directive
582 @tab N @tab
583@item @code{target_data} as composite construct @tab N @tab
584@item @code{nowait} clause with reverse-offload @code{target} directives
585 @tab N @tab
586@item Extended @emph{prefer-type} modifier to @code{init} clause @tab Y @tab
587@item Boolean argument to @code{nowait} and @code{nogroup} may be non constant
588 @tab N @tab
589@item @code{memscope} clause to @code{atomic} and @code{flush} @tab N @tab
590@item New @code{transparent} clause for multi-generational task-dependence graphs
591 @tab N @tab
592@item The @code{cancel} construct now completes tasks with unfulfilled events
593 @tab N @tab
594@item @code{omp_fulfill_event} routine was restricted regarding fulfillment of
595 event variables @tab N @tab
596@item Added rule for compound-directive names, permitting many more combinations
597 @tab N @tab
598@item @code{omp_is_free_agent} and @code{omp_ancestor_is_free_agent} routines
599 @tab N @tab
600@item @code{omp_get_device_from_uid} and @code{omp_get_uid_from_device} routines
601 @tab Y @tab
602@item @code{omp_get_device_num_teams}, @code{omp_set_device_num_teams},
603 @code{omp_get_device_teams_thread_limit}, and
604 @code{omp_set_device_teams_thread_limit} routines @tab N @tab
605@item @code{omp_target_memset} and @code{omp_target_memset_async} routines
606 @tab Y @tab
607@item Fortran version of the interop runtime routines @tab Y @tab
608@item Routines for obtaining memory spaces/allocators for shared/device memory
609 @tab N @tab
610@item @code{omp_get_memspace_num_resources} routine @tab N @tab
611@item @code{omp_get_memspace_pagesize} routine @tab N @tab
612@item @code{omp_get_submemspace} routine @tab N @tab
613@item @code{omp_init_mempartitioner}, @code{omp_destroy_mempartitioner},
614 @code{omp_init_mempartition}, @code{omp_destroy_mempartition},
615 @code{omp_mempartition_set_part}, @code{omp_mempartition_get_user_data}
616 routines @tab N @tab
617@item Deprecation of the @code{target_data_op}, @code{target},
618 @code{target_map} and @code{target_submit} callbacks and as values that
619 @code{set_callback} must return @tab N @tab
620@item @code{ompt_target_data_transfer} and @code{ompt_target_data_transfer_async}
621 values in @code{ompt_target_data_op_t} enum @tab N @tab
622@item The values @code{ompt_target_data_transfer_to_device},
623 @code{ompt_target_data_transfer_from_device},
624 @code{ompt_target_data_transfer_to_device_async} and
625 @code{ompt_target_data_transfer_from_device_async} of the @code{target_data_op}
626 OMPT type were deprecated @tab N @tab
627@item @code{ompt_get_buffer_limits} OMPT routine @tab N @tab
628@end multitable
629
630@unnumberedsubsec Deprecated features, unless listed above
631@multitable @columnfractions .60 .10 .25
632@item Deprecation of omitting the optional white space to separate adjacent
633 keywords in the directive-name in Fortran (fixed and free source form)
634 @tab N @tab
635@item Deprecation of the combiner expression in the @code{declare_reduction}
636 argument @tab N @tab
637@item Deprecation of the Fortran include file @code{omp_lib.h}
638 @tab N @tab
639@end multitable
640
641@unnumberedsubsec Other new OpenMP 6.0 features
642@multitable @columnfractions .60 .10 .25
643@item Multi-word directives now use underscore by default @tab N @tab
644@item Relaxed Fortran restrictions to the @code{aligned} clause @tab N @tab
645@item Mapping lambda captures @tab N @tab
646@item New @code{omp_pause_stop_tool} constant for omp_pause_resource @tab N @tab
647@item In Fortran (fixed and free source form), spaces between directive names are mandatory
648 @tab N @tab
649@item Update of the map-type decay for mapping and @code{declare_mapper}
650 @tab N @tab
651@end multitable
652
653
654
655@c ---------------------------------------------------------------------
656@c OpenMP Runtime Library Routines
657@c ---------------------------------------------------------------------
658
659@node Runtime Library Routines
660@chapter OpenMP Runtime Library Routines
661
662The runtime routines described here are defined by Section 18 of the OpenMP
663specification in version 5.2.
664
665@menu
666* Thread Team Routines::
667* Thread Affinity Routines::
668* Teams Region Routines::
669* Tasking Routines::
670* Resource Relinquishing Routines::
671* Device Information Routines::
672* Device Memory Routines::
673* Lock Routines::
674* Timing Routines::
675* Event Routine::
676* Interoperability Routines::
677* Memory Management Routines::
678@c * Tool Control Routine::
679* Environment Display Routine::
680@end menu
681
682
683
684@node Thread Team Routines
685@section Thread Team Routines
686
687Routines controlling threads in the current contention group.
688They have C linkage and do not throw exceptions.
689
690@menu
691* omp_set_num_threads:: Set upper team size limit
692* omp_get_num_threads:: Size of the active team
693* omp_get_max_threads:: Maximum number of threads of parallel region
694* omp_get_thread_num:: Current thread ID
695* omp_in_parallel:: Whether a parallel region is active
696* omp_set_dynamic:: Enable/disable dynamic teams
697* omp_get_dynamic:: Dynamic teams setting
698* omp_get_cancellation:: Whether cancellation support is enabled
699* omp_set_nested:: Enable/disable nested parallel regions
700* omp_get_nested:: Nested parallel regions
701* omp_set_schedule:: Set the runtime scheduling method
702* omp_get_schedule:: Obtain the runtime scheduling method
703* omp_get_teams_thread_limit:: Maximum number of threads imposed by teams
704* omp_get_supported_active_levels:: Maximum number of active regions supported
705* omp_set_max_active_levels:: Limits the number of active parallel regions
706* omp_get_max_active_levels:: Current maximum number of active regions
707* omp_get_level:: Number of parallel regions
708* omp_get_ancestor_thread_num:: Ancestor thread ID
709* omp_get_team_size:: Number of threads in a team
710* omp_get_active_level:: Number of active parallel regions
711@end menu
712
713
714
715@node omp_set_num_threads
716@subsection @code{omp_set_num_threads} -- Set upper team size limit
717@table @asis
718@item @emph{Description}:
719Specifies the number of threads used by default in subsequent parallel
720sections, if those do not specify a @code{num_threads} clause. The
721argument of @code{omp_set_num_threads} shall be a positive integer.
722
723@item @emph{C/C++}:
724@multitable @columnfractions .20 .80
725@item @emph{Prototype}: @tab @code{void omp_set_num_threads(int num_threads);}
726@end multitable
727
728@item @emph{Fortran}:
729@multitable @columnfractions .20 .80
730@item @emph{Interface}: @tab @code{subroutine omp_set_num_threads(num_threads)}
731@item @tab @code{integer, intent(in) :: num_threads}
732@end multitable
733
734@item @emph{See also}:
735@ref{OMP_NUM_THREADS}, @ref{omp_get_num_threads}, @ref{omp_get_max_threads}
736
737@item @emph{Reference}:
738@uref{https://www.openmp.org, OpenMP specification v4.5}, Section 3.2.1.
739@end table
740
741
742
743@node omp_get_num_threads
744@subsection @code{omp_get_num_threads} -- Size of the active team
745@table @asis
746@item @emph{Description}:
747Returns the number of threads in the current team. In a sequential section of
748the program @code{omp_get_num_threads} returns 1.
749
750The default team size may be initialized at startup by the
751@env{OMP_NUM_THREADS} environment variable. At runtime, the size
752of the current team may be set either by the @code{NUM_THREADS}
753clause or by @code{omp_set_num_threads}. If none of the above were
754used to define a specific value and @env{OMP_DYNAMIC} is disabled,
755one thread per CPU online is used.
756
757@item @emph{C/C++}:
758@multitable @columnfractions .20 .80
759@item @emph{Prototype}: @tab @code{int omp_get_num_threads(void);}
760@end multitable
761
762@item @emph{Fortran}:
763@multitable @columnfractions .20 .80
764@item @emph{Interface}: @tab @code{integer function omp_get_num_threads()}
765@end multitable
766
767@item @emph{See also}:
768@ref{omp_get_max_threads}, @ref{omp_set_num_threads}, @ref{OMP_NUM_THREADS}
769
770@item @emph{Reference}:
771@uref{https://www.openmp.org, OpenMP specification v4.5}, Section 3.2.2.
772@end table
773
774
775
776@node omp_get_max_threads
777@subsection @code{omp_get_max_threads} -- Maximum number of threads of parallel region
778@table @asis
779@item @emph{Description}:
780Return the maximum number of threads used for the current parallel region
781that does not use the clause @code{num_threads}.
782
783@item @emph{C/C++}:
784@multitable @columnfractions .20 .80
785@item @emph{Prototype}: @tab @code{int omp_get_max_threads(void);}
786@end multitable
787
788@item @emph{Fortran}:
789@multitable @columnfractions .20 .80
790@item @emph{Interface}: @tab @code{integer function omp_get_max_threads()}
791@end multitable
792
793@item @emph{See also}:
794@ref{omp_set_num_threads}, @ref{omp_set_dynamic}, @ref{omp_get_thread_limit}
795
796@item @emph{Reference}:
797@uref{https://www.openmp.org, OpenMP specification v4.5}, Section 3.2.3.
798@end table
799
800
801
802@node omp_get_thread_num
803@subsection @code{omp_get_thread_num} -- Current thread ID
804@table @asis
805@item @emph{Description}:
806Returns a unique thread identification number within the current team.
807In a sequential parts of the program, @code{omp_get_thread_num}
808always returns 0. In parallel regions the return value varies
809from 0 to @code{omp_get_num_threads}-1 inclusive. The return
810value of the primary thread of a team is always 0.
811
812@item @emph{C/C++}:
813@multitable @columnfractions .20 .80
814@item @emph{Prototype}: @tab @code{int omp_get_thread_num(void);}
815@end multitable
816
817@item @emph{Fortran}:
818@multitable @columnfractions .20 .80
819@item @emph{Interface}: @tab @code{integer function omp_get_thread_num()}
820@end multitable
821
822@item @emph{See also}:
823@ref{omp_get_num_threads}, @ref{omp_get_ancestor_thread_num}
824
825@item @emph{Reference}:
826@uref{https://www.openmp.org, OpenMP specification v4.5}, Section 3.2.4.
827@end table
828
829
830
831@node omp_in_parallel
832@subsection @code{omp_in_parallel} -- Whether a parallel region is active
833@table @asis
834@item @emph{Description}:
835This function returns @code{true} if currently running in parallel,
836@code{false} otherwise. Here, @code{true} and @code{false} represent
837their language-specific counterparts.
838
839@item @emph{C/C++}:
840@multitable @columnfractions .20 .80
841@item @emph{Prototype}: @tab @code{int omp_in_parallel(void);}
842@end multitable
843
844@item @emph{Fortran}:
845@multitable @columnfractions .20 .80
846@item @emph{Interface}: @tab @code{logical function omp_in_parallel()}
847@end multitable
848
849@item @emph{Reference}:
850@uref{https://www.openmp.org, OpenMP specification v4.5}, Section 3.2.6.
851@end table
852
853
854@node omp_set_dynamic
855@subsection @code{omp_set_dynamic} -- Enable/disable dynamic teams
856@table @asis
857@item @emph{Description}:
858Enable or disable the dynamic adjustment of the number of threads
859within a team. The function takes the language-specific equivalent
860of @code{true} and @code{false}, where @code{true} enables dynamic
861adjustment of team sizes and @code{false} disables it.
862
863@item @emph{C/C++}:
864@multitable @columnfractions .20 .80
865@item @emph{Prototype}: @tab @code{void omp_set_dynamic(int dynamic_threads);}
866@end multitable
867
868@item @emph{Fortran}:
869@multitable @columnfractions .20 .80
870@item @emph{Interface}: @tab @code{subroutine omp_set_dynamic(dynamic_threads)}
871@item @tab @code{logical, intent(in) :: dynamic_threads}
872@end multitable
873
874@item @emph{See also}:
875@ref{OMP_DYNAMIC}, @ref{omp_get_dynamic}
876
877@item @emph{Reference}:
878@uref{https://www.openmp.org, OpenMP specification v4.5}, Section 3.2.7.
879@end table
880
881
882
883@node omp_get_dynamic
884@subsection @code{omp_get_dynamic} -- Dynamic teams setting
885@table @asis
886@item @emph{Description}:
887This function returns @code{true} if enabled, @code{false} otherwise.
888Here, @code{true} and @code{false} represent their language-specific
889counterparts.
890
891The dynamic team setting may be initialized at startup by the
892@env{OMP_DYNAMIC} environment variable or at runtime using
893@code{omp_set_dynamic}. If undefined, dynamic adjustment is
894disabled by default.
895
896@item @emph{C/C++}:
897@multitable @columnfractions .20 .80
898@item @emph{Prototype}: @tab @code{int omp_get_dynamic(void);}
899@end multitable
900
901@item @emph{Fortran}:
902@multitable @columnfractions .20 .80
903@item @emph{Interface}: @tab @code{logical function omp_get_dynamic()}
904@end multitable
905
906@item @emph{See also}:
907@ref{omp_set_dynamic}, @ref{OMP_DYNAMIC}
908
909@item @emph{Reference}:
910@uref{https://www.openmp.org, OpenMP specification v4.5}, Section 3.2.8.
911@end table
912
913
914
915@node omp_get_cancellation
916@subsection @code{omp_get_cancellation} -- Whether cancellation support is enabled
917@table @asis
918@item @emph{Description}:
919This function returns @code{true} if cancellation is activated, @code{false}
920otherwise. Here, @code{true} and @code{false} represent their language-specific
921counterparts. Unless @env{OMP_CANCELLATION} is set true, cancellations are
922deactivated.
923
924@item @emph{C/C++}:
925@multitable @columnfractions .20 .80
926@item @emph{Prototype}: @tab @code{int omp_get_cancellation(void);}
927@end multitable
928
929@item @emph{Fortran}:
930@multitable @columnfractions .20 .80
931@item @emph{Interface}: @tab @code{logical function omp_get_cancellation()}
932@end multitable
933
934@item @emph{See also}:
935@ref{OMP_CANCELLATION}
936
937@item @emph{Reference}:
938@uref{https://www.openmp.org, OpenMP specification v4.5}, Section 3.2.9.
939@end table
940
941
942
943@node omp_set_nested
944@subsection @code{omp_set_nested} -- Enable/disable nested parallel regions
945@table @asis
946@item @emph{Description}:
947Enable or disable nested parallel regions, i.e., whether team members
948are allowed to create new teams. The function takes the language-specific
949equivalent of @code{true} and @code{false}, where @code{true} enables
950dynamic adjustment of team sizes and @code{false} disables it.
951
952Enabling nested parallel regions also sets the maximum number of
953active nested regions to the maximum supported. Disabling nested parallel
954regions sets the maximum number of active nested regions to one.
955
956Note that the @code{omp_set_nested} API routine was deprecated
957in the OpenMP specification 5.0 in favor of @code{omp_set_max_active_levels}.
958
959@item @emph{C/C++}:
960@multitable @columnfractions .20 .80
961@item @emph{Prototype}: @tab @code{void omp_set_nested(int nested);}
962@end multitable
963
964@item @emph{Fortran}:
965@multitable @columnfractions .20 .80
966@item @emph{Interface}: @tab @code{subroutine omp_set_nested(nested)}
967@item @tab @code{logical, intent(in) :: nested}
968@end multitable
969
970@item @emph{See also}:
971@ref{omp_get_nested}, @ref{omp_set_max_active_levels},
972@ref{OMP_MAX_ACTIVE_LEVELS}, @ref{OMP_NESTED}
973
974@item @emph{Reference}:
975@uref{https://www.openmp.org, OpenMP specification v4.5}, Section 3.2.10.
976@end table
977
978
979
980@node omp_get_nested
981@subsection @code{omp_get_nested} -- Nested parallel regions
982@table @asis
983@item @emph{Description}:
984This function returns @code{true} if nested parallel regions are
985enabled, @code{false} otherwise. Here, @code{true} and @code{false}
986represent their language-specific counterparts.
987
988The state of nested parallel regions at startup depends on several
989environment variables. If @env{OMP_MAX_ACTIVE_LEVELS} is defined
990and is set to greater than one, then nested parallel regions will be
991enabled. If not defined, then the value of the @env{OMP_NESTED}
992environment variable will be followed if defined. If neither are
993defined, then if either @env{OMP_NUM_THREADS} or @env{OMP_PROC_BIND}
994are defined with a list of more than one value, then nested parallel
995regions are enabled. If none of these are defined, then nested parallel
996regions are disabled by default.
997
998Nested parallel regions can be enabled or disabled at runtime using
999@code{omp_set_nested}, or by setting the maximum number of nested
1000regions with @code{omp_set_max_active_levels} to one to disable, or
1001above one to enable.
1002
1003Note that the @code{omp_get_nested} API routine was deprecated
1004in the OpenMP specification 5.0 in favor of @code{omp_get_max_active_levels}.
1005
1006@item @emph{C/C++}:
1007@multitable @columnfractions .20 .80
1008@item @emph{Prototype}: @tab @code{int omp_get_nested(void);}
1009@end multitable
1010
1011@item @emph{Fortran}:
1012@multitable @columnfractions .20 .80
1013@item @emph{Interface}: @tab @code{logical function omp_get_nested()}
1014@end multitable
1015
1016@item @emph{See also}:
1017@ref{omp_get_max_active_levels}, @ref{omp_set_nested},
1018@ref{OMP_MAX_ACTIVE_LEVELS}, @ref{OMP_NESTED}
1019
1020@item @emph{Reference}:
1021@uref{https://www.openmp.org, OpenMP specification v4.5}, Section 3.2.11.
1022@end table
1023
1024
1025
1026@node omp_set_schedule
1027@subsection @code{omp_set_schedule} -- Set the runtime scheduling method
1028@table @asis
1029@item @emph{Description}:
1030Sets the runtime scheduling method. The @var{kind} argument can have the
1031value @code{omp_sched_static}, @code{omp_sched_dynamic},
1032@code{omp_sched_guided} or @code{omp_sched_auto}. Except for
1033@code{omp_sched_auto}, the chunk size is set to the value of
1034@var{chunk_size} if positive, or to the default value if zero or negative.
1035For @code{omp_sched_auto} the @var{chunk_size} argument is ignored.
1036
1037@item @emph{C/C++}
1038@multitable @columnfractions .20 .80
1039@item @emph{Prototype}: @tab @code{void omp_set_schedule(omp_sched_t kind, int chunk_size);}
1040@end multitable
1041
1042@item @emph{Fortran}:
1043@multitable @columnfractions .20 .80
1044@item @emph{Interface}: @tab @code{subroutine omp_set_schedule(kind, chunk_size)}
1045@item @tab @code{integer(kind=omp_sched_kind) kind}
1046@item @tab @code{integer chunk_size}
1047@end multitable
1048
1049@item @emph{See also}:
1050@ref{omp_get_schedule}
1051@ref{OMP_SCHEDULE}
1052
1053@item @emph{Reference}:
1054@uref{https://www.openmp.org, OpenMP specification v4.5}, Section 3.2.12.
1055@end table
1056
1057
1058
1059@node omp_get_schedule
1060@subsection @code{omp_get_schedule} -- Obtain the runtime scheduling method
1061@table @asis
1062@item @emph{Description}:
1063Obtain the runtime scheduling method. The @var{kind} argument is set to
1064@code{omp_sched_static}, @code{omp_sched_dynamic},
1065@code{omp_sched_guided} or @code{omp_sched_auto}. The second argument,
1066@var{chunk_size}, is set to the chunk size.
1067
1068@item @emph{C/C++}
1069@multitable @columnfractions .20 .80
1070@item @emph{Prototype}: @tab @code{void omp_get_schedule(omp_sched_t *kind, int *chunk_size);}
1071@end multitable
1072
1073@item @emph{Fortran}:
1074@multitable @columnfractions .20 .80
1075@item @emph{Interface}: @tab @code{subroutine omp_get_schedule(kind, chunk_size)}
1076@item @tab @code{integer(kind=omp_sched_kind) kind}
1077@item @tab @code{integer chunk_size}
1078@end multitable
1079
1080@item @emph{See also}:
1081@ref{omp_set_schedule}, @ref{OMP_SCHEDULE}
1082
1083@item @emph{Reference}:
1084@uref{https://www.openmp.org, OpenMP specification v4.5}, Section 3.2.13.
1085@end table
1086
1087
1088@node omp_get_teams_thread_limit
1089@subsection @code{omp_get_teams_thread_limit} -- Maximum number of threads imposed by teams
1090@table @asis
1091@item @emph{Description}:
1092Return the maximum number of threads that are able to participate in
1093each team created by a teams construct.
1094
1095@item @emph{C/C++}:
1096@multitable @columnfractions .20 .80
1097@item @emph{Prototype}: @tab @code{int omp_get_teams_thread_limit(void);}
1098@end multitable
1099
1100@item @emph{Fortran}:
1101@multitable @columnfractions .20 .80
1102@item @emph{Interface}: @tab @code{integer function omp_get_teams_thread_limit()}
1103@end multitable
1104
1105@item @emph{See also}:
1106@ref{omp_set_teams_thread_limit}, @ref{OMP_TEAMS_THREAD_LIMIT}
1107
1108@item @emph{Reference}:
1109@uref{https://www.openmp.org, OpenMP specification v5.1}, Section 3.4.6.
1110@end table
1111
1112
1113
1114@node omp_get_supported_active_levels
1115@subsection @code{omp_get_supported_active_levels} -- Maximum number of active regions supported
1116@table @asis
1117@item @emph{Description}:
1118This function returns the maximum number of nested, active parallel regions
1119supported by this implementation.
1120
1121@item @emph{C/C++}
1122@multitable @columnfractions .20 .80
1123@item @emph{Prototype}: @tab @code{int omp_get_supported_active_levels(void);}
1124@end multitable
1125
1126@item @emph{Fortran}:
1127@multitable @columnfractions .20 .80
1128@item @emph{Interface}: @tab @code{integer function omp_get_supported_active_levels()}
1129@end multitable
1130
1131@item @emph{See also}:
1132@ref{omp_get_max_active_levels}, @ref{omp_set_max_active_levels}
1133
1134@item @emph{Reference}:
1135@uref{https://www.openmp.org, OpenMP specification v5.0}, Section 3.2.15.
1136@end table
1137
1138
1139
1140@node omp_set_max_active_levels
1141@subsection @code{omp_set_max_active_levels} -- Limits the number of active parallel regions
1142@table @asis
1143@item @emph{Description}:
1144This function limits the maximum allowed number of nested, active
1145parallel regions. @var{max_levels} must be less or equal to
1146the value returned by @code{omp_get_supported_active_levels}.
1147
1148@item @emph{C/C++}
1149@multitable @columnfractions .20 .80
1150@item @emph{Prototype}: @tab @code{void omp_set_max_active_levels(int max_levels);}
1151@end multitable
1152
1153@item @emph{Fortran}:
1154@multitable @columnfractions .20 .80
1155@item @emph{Interface}: @tab @code{subroutine omp_set_max_active_levels(max_levels)}
1156@item @tab @code{integer max_levels}
1157@end multitable
1158
1159@item @emph{See also}:
1160@ref{omp_get_max_active_levels}, @ref{omp_get_active_level},
1161@ref{omp_get_supported_active_levels}
1162
1163@item @emph{Reference}:
1164@uref{https://www.openmp.org, OpenMP specification v4.5}, Section 3.2.15.
1165@end table
1166
1167
1168
1169@node omp_get_max_active_levels
1170@subsection @code{omp_get_max_active_levels} -- Current maximum number of active regions
1171@table @asis
1172@item @emph{Description}:
1173This function obtains the maximum allowed number of nested, active parallel regions.
1174
1175@item @emph{C/C++}
1176@multitable @columnfractions .20 .80
1177@item @emph{Prototype}: @tab @code{int omp_get_max_active_levels(void);}
1178@end multitable
1179
1180@item @emph{Fortran}:
1181@multitable @columnfractions .20 .80
1182@item @emph{Interface}: @tab @code{integer function omp_get_max_active_levels()}
1183@end multitable
1184
1185@item @emph{See also}:
1186@ref{omp_set_max_active_levels}, @ref{omp_get_active_level}
1187
1188@item @emph{Reference}:
1189@uref{https://www.openmp.org, OpenMP specification v4.5}, Section 3.2.16.
1190@end table
1191
1192
1193@node omp_get_level
1194@subsection @code{omp_get_level} -- Obtain the current nesting level
1195@table @asis
1196@item @emph{Description}:
1197This function returns the nesting level for the parallel blocks,
1198which enclose the calling call.
1199
1200@item @emph{C/C++}
1201@multitable @columnfractions .20 .80
1202@item @emph{Prototype}: @tab @code{int omp_get_level(void);}
1203@end multitable
1204
1205@item @emph{Fortran}:
1206@multitable @columnfractions .20 .80
1207@item @emph{Interface}: @tab @code{integer function omp_level()}
1208@end multitable
1209
1210@item @emph{See also}:
1211@ref{omp_get_active_level}
1212
1213@item @emph{Reference}:
1214@uref{https://www.openmp.org, OpenMP specification v4.5}, Section 3.2.17.
1215@end table
1216
1217
1218
1219@node omp_get_ancestor_thread_num
1220@subsection @code{omp_get_ancestor_thread_num} -- Ancestor thread ID
1221@table @asis
1222@item @emph{Description}:
1223This function returns the thread identification number for the given
1224nesting level of the current thread. For values of @var{level} outside
1225zero to @code{omp_get_level} -1 is returned; if @var{level} is
1226@code{omp_get_level} the result is identical to @code{omp_get_thread_num}.
1227
1228@item @emph{C/C++}
1229@multitable @columnfractions .20 .80
1230@item @emph{Prototype}: @tab @code{int omp_get_ancestor_thread_num(int level);}
1231@end multitable
1232
1233@item @emph{Fortran}:
1234@multitable @columnfractions .20 .80
1235@item @emph{Interface}: @tab @code{integer function omp_get_ancestor_thread_num(level)}
1236@item @tab @code{integer level}
1237@end multitable
1238
1239@item @emph{See also}:
1240@ref{omp_get_level}, @ref{omp_get_thread_num}, @ref{omp_get_team_size}
1241
1242@item @emph{Reference}:
1243@uref{https://www.openmp.org, OpenMP specification v4.5}, Section 3.2.18.
1244@end table
1245
1246
1247
1248@node omp_get_team_size
1249@subsection @code{omp_get_team_size} -- Number of threads in a team
1250@table @asis
1251@item @emph{Description}:
1252This function returns the number of threads in a thread team to which
1253either the current thread or its ancestor belongs. For values of @var{level}
1254outside zero to @code{omp_get_level}, -1 is returned; if @var{level} is zero,
12551 is returned, and for @code{omp_get_level}, the result is identical
1256to @code{omp_get_num_threads}.
1257
1258@item @emph{C/C++}:
1259@multitable @columnfractions .20 .80
1260@item @emph{Prototype}: @tab @code{int omp_get_team_size(int level);}
1261@end multitable
1262
1263@item @emph{Fortran}:
1264@multitable @columnfractions .20 .80
1265@item @emph{Interface}: @tab @code{integer function omp_get_team_size(level)}
1266@item @tab @code{integer level}
1267@end multitable
1268
1269@item @emph{See also}:
1270@ref{omp_get_num_threads}, @ref{omp_get_level}, @ref{omp_get_ancestor_thread_num}
1271
1272@item @emph{Reference}:
1273@uref{https://www.openmp.org, OpenMP specification v4.5}, Section 3.2.19.
1274@end table
1275
1276
1277
1278@node omp_get_active_level
1279@subsection @code{omp_get_active_level} -- Number of parallel regions
1280@table @asis
1281@item @emph{Description}:
1282This function returns the nesting level for the active parallel blocks,
1283which enclose the calling call.
1284
1285@item @emph{C/C++}
1286@multitable @columnfractions .20 .80
1287@item @emph{Prototype}: @tab @code{int omp_get_active_level(void);}
1288@end multitable
1289
1290@item @emph{Fortran}:
1291@multitable @columnfractions .20 .80
1292@item @emph{Interface}: @tab @code{integer function omp_get_active_level()}
1293@end multitable
1294
1295@item @emph{See also}:
1296@ref{omp_get_level}, @ref{omp_get_max_active_levels}, @ref{omp_set_max_active_levels}
1297
1298@item @emph{Reference}:
1299@uref{https://www.openmp.org, OpenMP specification v4.5}, Section 3.2.20.
1300@end table
1301
1302
1303
1304@node Thread Affinity Routines
1305@section Thread Affinity Routines
1306
1307Routines controlling and accessing thread-affinity policies.
1308They have C linkage and do not throw exceptions.
1309
1310@menu
1311* omp_get_proc_bind:: Whether threads may be moved between CPUs
1312@c * omp_get_num_places:: Get the number of places available
1313@c * omp_get_place_num_procs:: Get the number of processes associated with a place
1314@c * omp_get_place_proc_ids:: Get number of processes associated with a place
1315@c * omp_get_place_num:: Get place number of the associated task
1316@c * omp_get_partition_num_places:: Get number of places of innermost task
1317@c * omp_get_partition_place_nums:: <fixme>
1318@c * omp_set_affinity_format:: <fixme>
1319@c * omp_get_affinity_format:: <fixme>
1320@c * omp_display_affinity:: <fixme>
1321@c * omp_capture_affinity:: <fixme>
1322@end menu
1323
1324
1325
1326@node omp_get_proc_bind
1327@subsection @code{omp_get_proc_bind} -- Whether threads may be moved between CPUs
1328@table @asis
1329@item @emph{Description}:
1330This functions returns the currently active thread affinity policy, which is
1331set via @env{OMP_PROC_BIND}. Possible values are @code{omp_proc_bind_false},
1332@code{omp_proc_bind_true}, @code{omp_proc_bind_primary},
1333@code{omp_proc_bind_master}, @code{omp_proc_bind_close} and @code{omp_proc_bind_spread},
1334where @code{omp_proc_bind_master} is an alias for @code{omp_proc_bind_primary}.
1335
1336@item @emph{C/C++}:
1337@multitable @columnfractions .20 .80
1338@item @emph{Prototype}: @tab @code{omp_proc_bind_t omp_get_proc_bind(void);}
1339@end multitable
1340
1341@item @emph{Fortran}:
1342@multitable @columnfractions .20 .80
1343@item @emph{Interface}: @tab @code{integer(kind=omp_proc_bind_kind) function omp_get_proc_bind()}
1344@end multitable
1345
1346@item @emph{See also}:
1347@ref{OMP_PROC_BIND}, @ref{OMP_PLACES}, @ref{GOMP_CPU_AFFINITY},
1348
1349@item @emph{Reference}:
1350@uref{https://www.openmp.org, OpenMP specification v4.5}, Section 3.2.22.
1351@end table
1352
1353
1354
1355@node Teams Region Routines
1356@section Teams Region Routines
1357
1358Routines controlling the league of teams that are executed in a @code{teams}
1359region. They have C linkage and do not throw exceptions.
1360
1361@menu
1362* omp_get_num_teams:: Number of teams
1363* omp_get_team_num:: Get team number
1364* omp_set_num_teams:: Set upper teams limit for teams region
1365* omp_get_max_teams:: Maximum number of teams for teams region
1366* omp_set_teams_thread_limit:: Set upper thread limit for teams construct
1367* omp_get_thread_limit:: Maximum number of threads
1368@end menu
1369
1370
1371
1372@node omp_get_num_teams
1373@subsection @code{omp_get_num_teams} -- Number of teams
1374@table @asis
1375@item @emph{Description}:
1376Returns the number of teams in the current team region.
1377
1378@item @emph{C/C++}:
1379@multitable @columnfractions .20 .80
1380@item @emph{Prototype}: @tab @code{int omp_get_num_teams(void);}
1381@end multitable
1382
1383@item @emph{Fortran}:
1384@multitable @columnfractions .20 .80
1385@item @emph{Interface}: @tab @code{integer function omp_get_num_teams()}
1386@end multitable
1387
1388@item @emph{Reference}:
1389@uref{https://www.openmp.org, OpenMP specification v4.5}, Section 3.2.32.
1390@end table
1391
1392
1393
1394@node omp_get_team_num
1395@subsection @code{omp_get_team_num} -- Get team number
1396@table @asis
1397@item @emph{Description}:
1398Returns the team number of the calling thread.
1399
1400@item @emph{C/C++}:
1401@multitable @columnfractions .20 .80
1402@item @emph{Prototype}: @tab @code{int omp_get_team_num(void);}
1403@end multitable
1404
1405@item @emph{Fortran}:
1406@multitable @columnfractions .20 .80
1407@item @emph{Interface}: @tab @code{integer function omp_get_team_num()}
1408@end multitable
1409
1410@item @emph{Reference}:
1411@uref{https://www.openmp.org, OpenMP specification v4.5}, Section 3.2.33.
1412@end table
1413
1414
1415
1416@node omp_set_num_teams
1417@subsection @code{omp_set_num_teams} -- Set upper teams limit for teams construct
1418@table @asis
1419@item @emph{Description}:
1420Specifies the upper bound for number of teams created by the teams construct
1421which does not specify a @code{num_teams} clause. The
1422argument of @code{omp_set_num_teams} shall be a positive integer.
1423
1424@item @emph{C/C++}:
1425@multitable @columnfractions .20 .80
1426@item @emph{Prototype}: @tab @code{void omp_set_num_teams(int num_teams);}
1427@end multitable
1428
1429@item @emph{Fortran}:
1430@multitable @columnfractions .20 .80
1431@item @emph{Interface}: @tab @code{subroutine omp_set_num_teams(num_teams)}
1432@item @tab @code{integer, intent(in) :: num_teams}
1433@end multitable
1434
1435@item @emph{See also}:
1436@ref{OMP_NUM_TEAMS}, @ref{omp_get_num_teams}, @ref{omp_get_max_teams}
1437
1438@item @emph{Reference}:
1439@uref{https://www.openmp.org, OpenMP specification v5.1}, Section 3.4.3.
1440@end table
1441
1442
1443
1444@node omp_get_max_teams
1445@subsection @code{omp_get_max_teams} -- Maximum number of teams of teams region
1446@table @asis
1447@item @emph{Description}:
1448Return the maximum number of teams used for the teams region
1449that does not use the clause @code{num_teams}.
1450
1451@item @emph{C/C++}:
1452@multitable @columnfractions .20 .80
1453@item @emph{Prototype}: @tab @code{int omp_get_max_teams(void);}
1454@end multitable
1455
1456@item @emph{Fortran}:
1457@multitable @columnfractions .20 .80
1458@item @emph{Interface}: @tab @code{integer function omp_get_max_teams()}
1459@end multitable
1460
1461@item @emph{See also}:
1462@ref{omp_set_num_teams}, @ref{omp_get_num_teams}
1463
1464@item @emph{Reference}:
1465@uref{https://www.openmp.org, OpenMP specification v5.1}, Section 3.4.4.
1466@end table
1467
1468
1469
1470@node omp_set_teams_thread_limit
1471@subsection @code{omp_set_teams_thread_limit} -- Set upper thread limit for teams construct
1472@table @asis
1473@item @emph{Description}:
1474Specifies the upper bound for number of threads that are available
1475for each team created by the teams construct which does not specify a
1476@code{thread_limit} clause. The argument of
1477@code{omp_set_teams_thread_limit} shall be a positive integer.
1478
1479@item @emph{C/C++}:
1480@multitable @columnfractions .20 .80
1481@item @emph{Prototype}: @tab @code{void omp_set_teams_thread_limit(int thread_limit);}
1482@end multitable
1483
1484@item @emph{Fortran}:
1485@multitable @columnfractions .20 .80
1486@item @emph{Interface}: @tab @code{subroutine omp_set_teams_thread_limit(thread_limit)}
1487@item @tab @code{integer, intent(in) :: thread_limit}
1488@end multitable
1489
1490@item @emph{See also}:
1491@ref{OMP_TEAMS_THREAD_LIMIT}, @ref{omp_get_teams_thread_limit}, @ref{omp_get_thread_limit}
1492
1493@item @emph{Reference}:
1494@uref{https://www.openmp.org, OpenMP specification v5.1}, Section 3.4.5.
1495@end table
1496
1497
1498
1499@node omp_get_thread_limit
1500@subsection @code{omp_get_thread_limit} -- Maximum number of threads
1501@table @asis
1502@item @emph{Description}:
1503Return the maximum number of threads of the program.
1504
1505@item @emph{C/C++}:
1506@multitable @columnfractions .20 .80
1507@item @emph{Prototype}: @tab @code{int omp_get_thread_limit(void);}
1508@end multitable
1509
1510@item @emph{Fortran}:
1511@multitable @columnfractions .20 .80
1512@item @emph{Interface}: @tab @code{integer function omp_get_thread_limit()}
1513@end multitable
1514
1515@item @emph{See also}:
1516@ref{omp_get_max_threads}, @ref{OMP_THREAD_LIMIT}
1517
1518@item @emph{Reference}:
1519@uref{https://www.openmp.org, OpenMP specification v4.5}, Section 3.2.14.
1520@end table
1521
1522
1523
1524@node Tasking Routines
1525@section Tasking Routines
1526
1527Routines relating to explicit tasks.
1528They have C linkage and do not throw exceptions.
1529
1530@menu
1531* omp_get_max_task_priority:: Maximum task priority value that can be set
1532* omp_in_explicit_task:: Whether a given task is an explicit task
1533* omp_in_final:: Whether in final or included task region
1534@c * omp_is_free_agent:: <fixme>/TR12
1535@c * omp_ancestor_is_free_agent:: <fixme>/TR12
1536@end menu
1537
1538
1539
1540@node omp_get_max_task_priority
1541@subsection @code{omp_get_max_task_priority} -- Maximum priority value
1542that can be set for tasks.
1543@table @asis
1544@item @emph{Description}:
1545This function obtains the maximum allowed priority number for tasks.
1546
1547@item @emph{C/C++}
1548@multitable @columnfractions .20 .80
1549@item @emph{Prototype}: @tab @code{int omp_get_max_task_priority(void);}
1550@end multitable
1551
1552@item @emph{Fortran}:
1553@multitable @columnfractions .20 .80
1554@item @emph{Interface}: @tab @code{integer function omp_get_max_task_priority()}
1555@end multitable
1556
1557@item @emph{Reference}:
1558@uref{https://www.openmp.org, OpenMP specification v4.5}, Section 3.2.29.
1559@end table
1560
1561
1562
1563@node omp_in_explicit_task
1564@subsection @code{omp_in_explicit_task} -- Whether a given task is an explicit task
1565@table @asis
1566@item @emph{Description}:
1567The function returns the @var{explicit-task-var} ICV; it returns true when the
1568encountering task was generated by a task-generating construct such as
1569@code{target}, @code{task} or @code{taskloop}. Otherwise, the encountering task
1570is in an implicit task region such as generated by the implicit or explicit
1571@code{parallel} region and @code{omp_in_explicit_task} returns false.
1572
1573@item @emph{C/C++}
1574@multitable @columnfractions .20 .80
1575@item @emph{Prototype}: @tab @code{int omp_in_explicit_task(void);}
1576@end multitable
1577
1578@item @emph{Fortran}:
1579@multitable @columnfractions .20 .80
1580@item @emph{Interface}: @tab @code{logical function omp_in_explicit_task()}
1581@end multitable
1582
1583@item @emph{Reference}:
1584@uref{https://www.openmp.org, OpenMP specification v5.2}, Section 18.5.2.
1585@end table
1586
1587
1588
1589@node omp_in_final
1590@subsection @code{omp_in_final} -- Whether in final or included task region
1591@table @asis
1592@item @emph{Description}:
1593This function returns @code{true} if currently running in a final
1594or included task region, @code{false} otherwise. Here, @code{true}
1595and @code{false} represent their language-specific counterparts.
1596
1597@item @emph{C/C++}:
1598@multitable @columnfractions .20 .80
1599@item @emph{Prototype}: @tab @code{int omp_in_final(void);}
1600@end multitable
1601
1602@item @emph{Fortran}:
1603@multitable @columnfractions .20 .80
1604@item @emph{Interface}: @tab @code{logical function omp_in_final()}
1605@end multitable
1606
1607@item @emph{Reference}:
1608@uref{https://www.openmp.org, OpenMP specification v4.5}, Section 3.2.21.
1609@end table
1610
1611
1612
1613@node Resource Relinquishing Routines
1614@section Resource Relinquishing Routines
1615
1616Routines releasing resources used by the OpenMP runtime.
1617They have C linkage and do not throw exceptions.
1618
1619@menu
1620* omp_pause_resource:: Release OpenMP resources on a device
1621* omp_pause_resource_all:: Release OpenMP resources on all devices
1622@end menu
1623
1624
1625
1626@node omp_pause_resource
1627@subsection @code{omp_pause_resource} -- Release OpenMP resources on a device
1628@table @asis
1629@item @emph{Description}:
1630Free resources used by the OpenMP program and the runtime library on and for the
1631device specified by @var{device_num}; on success, zero is returned and non-zero
1632otherwise.
1633
1634The value of @var{device_num} must be a conforming device number. The routine
1635may not be called from within any explicit region and all explicit threads that
1636do not bind to the implicit parallel region have finalized execution.
1637
1638@item @emph{C/C++}:
1639@multitable @columnfractions .20 .80
1640@item @emph{Prototype}: @tab @code{int omp_pause_resource(omp_pause_resource_t kind, int device_num);}
1641@end multitable
1642
1643@item @emph{Fortran}:
1644@multitable @columnfractions .20 .80
1645@item @emph{Interface}: @tab @code{integer function omp_pause_resource(kind, device_num)}
1646@item @tab @code{integer (kind=omp_pause_resource_kind) kind}
1647@item @tab @code{integer device_num}
1648@end multitable
1649
1650@item @emph{Reference}:
1651@uref{https://www.openmp.org, OpenMP specification v5.0}, Section 3.2.43.
1652@end table
1653
1654
1655
1656@node omp_pause_resource_all
1657@subsection @code{omp_pause_resource_all} -- Release OpenMP resources on all devices
1658@table @asis
1659@item @emph{Description}:
1660Free resources used by the OpenMP program and the runtime library on all devices,
1661including the host. On success, zero is returned and non-zero otherwise.
1662
1663The routine may not be called from within any explicit region and all explicit
1664threads that do not bind to the implicit parallel region have finalized execution.
1665
1666@item @emph{C/C++}:
1667@multitable @columnfractions .20 .80
1668@item @emph{Prototype}: @tab @code{int omp_pause_resource(omp_pause_resource_t kind);}
1669@end multitable
1670
1671@item @emph{Fortran}:
1672@multitable @columnfractions .20 .80
1673@item @emph{Interface}: @tab @code{integer function omp_pause_resource(kind)}
1674@item @tab @code{integer (kind=omp_pause_resource_kind) kind}
1675@end multitable
1676
1677@item @emph{See also}:
1678@ref{omp_pause_resource}
1679
1680@item @emph{Reference}:
1681@uref{https://www.openmp.org, OpenMP specification v5.0}, Section 3.2.44.
1682@end table
1683
1684
1685
1686@node Device Information Routines
1687@section Device Information Routines
1688
1689Routines related to devices available to an OpenMP program.
1690They have C linkage and do not throw exceptions.
1691
1692@menu
1693* omp_get_num_procs:: Number of processors online
1694@c * omp_get_max_progress_width:: <fixme>/TR11
1695* omp_set_default_device:: Set the default device for target regions
1696* omp_get_default_device:: Get the default device for target regions
1697* omp_get_num_devices:: Number of target devices
1698* omp_get_device_num:: Get device that current thread is running on
1699* omp_get_device_from_uid:: Obtain the device number to a unique id
1700* omp_get_uid_from_device:: Obtain the unique id of a device
1701* omp_is_initial_device:: Whether executing on the host device
1702* omp_get_initial_device:: Device number of host device
1703@c * omp_get_device_num_teams:: <fixme>/TR13
1704@c * omp_set_device_num_teams:: <fixme>/TR13
1705@c * omp_get_device_teams_thread_limit:: <fixme>/TR13
1706@c * omp_set_device_teams_thread_limit:: <fixme>/TR13
1707@end menu
1708
1709
1710
1711@node omp_get_num_procs
1712@subsection @code{omp_get_num_procs} -- Number of processors online
1713@table @asis
1714@item @emph{Description}:
1715Returns the number of processors online on that device.
1716
1717@item @emph{C/C++}:
1718@multitable @columnfractions .20 .80
1719@item @emph{Prototype}: @tab @code{int omp_get_num_procs(void);}
1720@end multitable
1721
1722@item @emph{Fortran}:
1723@multitable @columnfractions .20 .80
1724@item @emph{Interface}: @tab @code{integer function omp_get_num_procs()}
1725@end multitable
1726
1727@item @emph{Reference}:
1728@uref{https://www.openmp.org, OpenMP specification v4.5}, Section 3.2.5.
1729@end table
1730
1731
1732
1733@node omp_set_default_device
1734@subsection @code{omp_set_default_device} -- Set the default device for target regions
1735@table @asis
1736@item @emph{Description}:
1737Get the value of the @emph{default-device-var} ICV, which is used
1738for target regions without a device clause. The argument
1739shall be a nonnegative device number, @code{omp_initial_device},
1740or @code{omp_invalid_device}.
1741
1742The effect of running this routine in a @code{target} region is unspecified.
1743
1744@item @emph{C/C++}:
1745@multitable @columnfractions .20 .80
1746@item @emph{Prototype}: @tab @code{void omp_set_default_device(int device_num);}
1747@end multitable
1748
1749@item @emph{Fortran}:
1750@multitable @columnfractions .20 .80
1751@item @emph{Interface}: @tab @code{subroutine omp_set_default_device(device_num)}
1752@item @tab @code{integer device_num}
1753@end multitable
1754
1755@item @emph{See also}:
1756@ref{OMP_DEFAULT_DEVICE}, @ref{omp_get_default_device}
1757
1758@item @emph{Reference}:
1759@uref{https://www.openmp.org, OpenMP specification v4.5}, Section 3.2.29.
1760@end table
1761
1762
1763
1764@node omp_get_default_device
1765@subsection @code{omp_get_default_device} -- Get the default device for target regions
1766@table @asis
1767@item @emph{Description}:
1768Get the value of the @emph{default-device-var} ICV, which is used
1769for target regions without a device clause. The value is either a
1770nonnegative device number, @code{omp_initial_device} or
1771@code{omp_invalid_device}. Note that for the host, the ICV can have two values:
1772either the value of the named constant @code{omp_initial_device} or the value
1773returned by the @code{omp_get_num_devices} routine.
1774
1775The effect of running this routine in a @code{target} region is unspecified.
1776
1777@item @emph{C/C++}:
1778@multitable @columnfractions .20 .80
1779@item @emph{Prototype}: @tab @code{int omp_get_default_device(void);}
1780@end multitable
1781
1782@item @emph{Fortran}:
1783@multitable @columnfractions .20 .80
1784@item @emph{Interface}: @tab @code{integer function omp_get_default_device()}
1785@end multitable
1786
1787@item @emph{See also}:
1788@ref{OMP_DEFAULT_DEVICE}, @ref{omp_set_default_device},
1789@ref{omp_get_initial_device}
1790
1791@item @emph{Reference}:
1792@uref{https://www.openmp.org, OpenMP specification v4.5}, Section 3.2.30.
1793@end table
1794
1795
1796
1797@node omp_get_num_devices
1798@subsection @code{omp_get_num_devices} -- Number of target devices
1799@table @asis
1800@item @emph{Description}:
1801Returns the number of available non-host devices.
1802
1803The effect of running this routine in a @code{target} region is unspecified.
1804
1805Note that in GCC the function is marked pure, i.e. as returning always the
1806same number. When GCC was not configured to support offloading, it is replaced
1807by zero; compile with @option{-fno-builtin-omp_get_num_devices} if a run-time
1808function is desired.
1809
1810@item @emph{C/C++}:
1811@multitable @columnfractions .20 .80
1812@item @emph{Prototype}: @tab @code{int omp_get_num_devices(void);}
1813@end multitable
1814
1815@item @emph{Fortran}:
1816@multitable @columnfractions .20 .80
1817@item @emph{Interface}: @tab @code{integer function omp_get_num_devices()}
1818@end multitable
1819
1820@item @emph{See also}:
1821@ref{omp_get_initial_device}
1822
1823@item @emph{Reference}:
1824@uref{https://www.openmp.org, OpenMP specification v4.5}, Section 3.2.31.
1825@end table
1826
1827
1828
1829@node omp_get_device_num
1830@subsection @code{omp_get_device_num} -- Return device number of current device
1831@table @asis
1832@item @emph{Description}:
1833This function returns a device number that represents the device that the
1834current thread is executing on. When called on the host, it returns
1835the same value as returned by the @code{omp_get_initial_device} function
1836as required since OpenMP 5.0.
1837
1838@item @emph{C/C++}
1839@multitable @columnfractions .20 .80
1840@item @emph{Prototype}: @tab @code{int omp_get_device_num(void);}
1841@end multitable
1842
1843@item @emph{Fortran}:
1844@multitable @columnfractions .20 .80
1845@item @emph{Interface}: @tab @code{integer function omp_get_device_num()}
1846@end multitable
1847
1848@item @emph{See also}:
1849@ref{omp_get_initial_device}
1850
1851@item @emph{Reference}:
1852@uref{https://www.openmp.org, OpenMP specification v5.0}, Section 3.2.37.
1853@end table
1854
1855
1856
1857@node omp_get_device_from_uid
1858@subsection @code{omp_get_device_from_uid} -- Obtain the device number to a unique id
1859@table @asis
1860@item @emph{Description}:
1861This function returns the device number associated with the passed
1862unique-identifier (UID) string. If no device with this UID is available, the value
1863@code{omp_invalid_device} is returned. The effect of running this routine in a
1864@code{target} region is unspecified.
1865
1866GCC treats the UID string case sensitive; for the initial device, GCC currently
1867only accepts the value @code{OMP_INITIAL_DEVICE} and returns for it the value
1868of @code{omp_initial_device}.
1869
1870@item @emph{C/C++}:
1871@multitable @columnfractions .20 .80
1872@item @emph{Prototype}: @tab @code{int omp_get_device_from_uid(const char *uid);}
1873@end multitable
1874
1875@item @emph{Fortran}:
1876@multitable @columnfractions .20 .80
1877@item @emph{Interface}: @tab @code{integer function omp_get_device_from_uid(uid)}
1878@item @tab @code{character(len=*), intent(in) :: uid}
1879@end multitable
1880
1881@item @emph{See also}:
1882@ref{omp_get_uid_from_device}, @ref{Offload-Target Specifics}
1883
1884@item @emph{Reference}:
1885@uref{https://www.openmp.org, OpenMP specification v6.0}, Section 24.7
1886@end table
1887
1888
1889
1890@node omp_get_uid_from_device
1891@subsection @code{omp_get_uid_from_device} -- Obtain the unique id of a device
1892@table @asis
1893@item @emph{Description}:
1894This function returns a pointer to a string that represents a unique identifier
1895(UID) for the device specified by @var{device_num}. It returns a @code{NULL} (C/C++)
1896or a disassociated pointer (Fortran) for @code{omp_invalid_device}. The effect of
1897running this routine in a @code{target} region is unspecified.
1898
1899GCC currently returns for initial device the value @code{OMP_INITIAL_DEVICE}.
1900
1901@item @emph{C/C++}:
1902@multitable @columnfractions .20 .80
1903@item @emph{Prototype}: @tab @code{const char *omp_get_uid_from_device(int device_num);}
1904@end multitable
1905
1906@item @emph{Fortran}:
1907@multitable @columnfractions .20 .80
1908@item @emph{Interface}: @tab @code{character(:) function omp_get_uid_from_device(device_num)}
1909@item @emph{Interface}: @tab @code{pointer :: omp_get_uid_from_device}
1910@item @tab @code{integer, intent(in) :: device_num}
1911@end multitable
1912
1913@item @emph{See also}:
1914@ref{omp_get_uid_from_device}, @ref{Offload-Target Specifics}
1915
1916@item @emph{Reference}:
1917@uref{https://www.openmp.org, OpenMP specification v6.0}, Section 24.8
1918@end table
1919
1920
1921
1922@node omp_is_initial_device
1923@subsection @code{omp_is_initial_device} -- Whether executing on the host device
1924@table @asis
1925@item @emph{Description}:
1926This function returns @code{true} if currently running on the host device,
1927@code{false} otherwise. Here, @code{true} and @code{false} represent
1928their language-specific counterparts.
1929
1930Note that in GCC this function call is already folded to a constant in the
1931compiler; compile with @option{-fno-builtin-omp_is_initial_device} if a
1932run-time function is desired.
1933
1934@item @emph{C/C++}:
1935@multitable @columnfractions .20 .80
1936@item @emph{Prototype}: @tab @code{int omp_is_initial_device(void);}
1937@end multitable
1938
1939@item @emph{Fortran}:
1940@multitable @columnfractions .20 .80
1941@item @emph{Interface}: @tab @code{logical function omp_is_initial_device()}
1942@end multitable
1943
1944@item @emph{Reference}:
1945@uref{https://www.openmp.org, OpenMP specification v4.5}, Section 3.2.34.
1946@end table
1947
1948
1949
1950@node omp_get_initial_device
1951@subsection @code{omp_get_initial_device} -- Return device number of initial device
1952@table @asis
1953@item @emph{Description}:
1954This function returns a device number that represents the host device.
1955Since OpenMP 5.1, this is equal to the value returned by the
1956@code{omp_get_num_devices} function; since OpenMP 6.0 it may also return
1957the value of @code{omp_initial_device}.
1958
1959The effect of running this routine in a @code{target} region is unspecified.
1960
1961Note that GCC inlines this function unless you compile with
1962@option{-fno-builtin-omp_get_initial_device}. If GCC was not configured to
1963support offloading, it expands to constant zero; in non-host code it expands
1964to @code{omp_initial_device}; and otherwise it is replaced with a call to
1965@code{omp_get_num_devices}.
1966
1967@item @emph{C/C++}
1968@multitable @columnfractions .20 .80
1969@item @emph{Prototype}: @tab @code{int omp_get_initial_device(void);}
1970@end multitable
1971
1972@item @emph{Fortran}:
1973@multitable @columnfractions .20 .80
1974@item @emph{Interface}: @tab @code{integer function omp_get_initial_device()}
1975@end multitable
1976
1977@item @emph{See also}:
1978@ref{omp_get_num_devices}
1979
1980@item @emph{Reference}:
1981@uref{https://www.openmp.org, OpenMP specification v4.5}, Section 3.2.35.
1982@end table
1983
1984
1985
1986@node Device Memory Routines
1987@section Device Memory Routines
1988
1989Routines related to memory allocation and managing corresponding
1990pointers on devices. They have C linkage and do not throw exceptions.
1991
1992@menu
1993* omp_target_alloc:: Allocate device memory
1994* omp_target_free:: Free device memory
1995* omp_target_is_present:: Check whether storage is mapped
1996* omp_target_is_accessible:: Check whether memory is device accessible
1997* omp_target_memcpy:: Copy data between devices
1998* omp_target_memcpy_async:: Copy data between devices asynchronously
1999* omp_target_memcpy_rect:: Copy a subvolume of data between devices
2000* omp_target_memcpy_rect_async:: Copy a subvolume of data between devices asynchronously
2001* omp_target_memset:: Set bytes in device memory
2002* omp_target_memset_async:: Set bytes in device memory asynchronously
2003* omp_target_associate_ptr:: Associate a device pointer with a host pointer
2004* omp_target_disassociate_ptr:: Remove device--host pointer association
2005* omp_get_mapped_ptr:: Return device pointer to a host pointer
2006@end menu
2007
2008
2009
2010@node omp_target_alloc
2011@subsection @code{omp_target_alloc} -- Allocate device memory
2012@table @asis
2013@item @emph{Description}:
2014This routine allocates @var{size} bytes of memory in the device environment
2015associated with the device number @var{device_num}. If successful, a device
2016pointer is returned, otherwise a null pointer.
2017
2018In GCC, when the device is the host or the device shares memory with the host,
2019the memory is allocated on the host; in that case, when @var{size} is zero,
2020either NULL or a unique pointer value that can later be successfully passed to
2021@code{omp_target_free} is returned. When the allocation is not performed on
2022the host, a null pointer is returned when @var{size} is zero; in that case,
2023additionally a diagnostic might be printed to standard error (stderr).
2024
2025Running this routine in a @code{target} region except on the initial device
2026is not supported.
2027
2028@item @emph{C/C++}
2029@multitable @columnfractions .20 .80
2030@item @emph{Prototype}: @tab @code{void *omp_target_alloc(size_t size, int device_num)}
2031@end multitable
2032
2033@item @emph{Fortran}:
2034@multitable @columnfractions .20 .80
2035@item @emph{Interface}: @tab @code{type(c_ptr) function omp_target_alloc(size, device_num) bind(C)}
2036@item @tab @code{use, intrinsic :: iso_c_binding, only: c_ptr, c_int, c_size_t}
2037@item @tab @code{integer(c_size_t), value :: size}
2038@item @tab @code{integer(c_int), value :: device_num}
2039@end multitable
2040
2041@item @emph{See also}:
2042@ref{omp_target_free}, @ref{omp_target_associate_ptr}
2043
2044@item @emph{Reference}:
2045@uref{https://www.openmp.org, OpenMP specification v5.1}, Section 3.8.1
2046@end table
2047
2048
2049
2050@node omp_target_free
2051@subsection @code{omp_target_free} -- Free device memory
2052@table @asis
2053@item @emph{Description}:
2054This routine frees memory allocated by the @code{omp_target_alloc} routine.
2055The @var{device_ptr} argument must be either a null pointer or a device pointer
2056returned by @code{omp_target_alloc} for the specified @code{device_num}. The
2057device number @var{device_num} must be a conforming device number.
2058
2059Running this routine in a @code{target} region except on the initial device
2060is not supported.
2061
2062@item @emph{C/C++}
2063@multitable @columnfractions .20 .80
2064@item @emph{Prototype}: @tab @code{void omp_target_free(void *device_ptr, int device_num)}
2065@end multitable
2066
2067@item @emph{Fortran}:
2068@multitable @columnfractions .20 .80
2069@item @emph{Interface}: @tab @code{subroutine omp_target_free(device_ptr, device_num) bind(C)}
2070@item @tab @code{use, intrinsic :: iso_c_binding, only: c_ptr, c_int}
2071@item @tab @code{type(c_ptr), value :: device_ptr}
2072@item @tab @code{integer(c_int), value :: device_num}
2073@end multitable
2074
2075@item @emph{See also}:
2076@ref{omp_target_alloc}, @ref{omp_target_disassociate_ptr}
2077
2078@item @emph{Reference}:
2079@uref{https://www.openmp.org, OpenMP specification v5.1}, Section 3.8.2
2080@end table
2081
2082
2083
2084@node omp_target_is_present
2085@subsection @code{omp_target_is_present} -- Check whether storage is mapped
2086@table @asis
2087@item @emph{Description}:
2088This routine tests whether storage, identified by the host pointer @var{ptr}
2089is mapped to the device specified by @var{device_num}. If so, it returns
2090a nonzero value and otherwise zero.
2091
2092In GCC, this includes self mapping such that @code{omp_target_is_present}
2093returns @emph{true} when @var{device_num} specifies the host or when the host
2094and the device share memory. If @var{ptr} is a null pointer, @var{true} is
2095returned and if @var{device_num} is an invalid device number, @var{false} is
2096returned.
2097
2098If those conditions do not apply, @emph{true} is returned if the association has
2099been established by an explicit or implicit @code{map} clause, the
2100@code{declare target} directive or a call to the @code{omp_target_associate_ptr}
2101routine.
2102
2103Running this routine in a @code{target} region except on the initial device
2104is not supported.
2105
2106@item @emph{C/C++}
2107@multitable @columnfractions .20 .80
2108@item @emph{Prototype}: @tab @code{int omp_target_is_present(const void *ptr,}
2109@item @tab @code{ int device_num)}
2110@end multitable
2111
2112@item @emph{Fortran}:
2113@multitable @columnfractions .20 .80
2114@item @emph{Interface}: @tab @code{integer(c_int) function omp_target_is_present(ptr, &}
2115@item @tab @code{ device_num) bind(C)}
2116@item @tab @code{use, intrinsic :: iso_c_binding, only: c_ptr, c_int}
2117@item @tab @code{type(c_ptr), value :: ptr}
2118@item @tab @code{integer(c_int), value :: device_num}
2119@end multitable
2120
2121@item @emph{See also}:
2122@ref{omp_target_associate_ptr}
2123
2124@item @emph{Reference}:
2125@uref{https://www.openmp.org, OpenMP specification v5.1}, Section 3.8.3
2126@end table
2127
2128
2129
2130@node omp_target_is_accessible
2131@subsection @code{omp_target_is_accessible} -- Check whether memory is device accessible
2132@table @asis
2133@item @emph{Description}:
2134This routine tests whether memory, starting at the address given by @var{ptr}
2135and extending @var{size} bytes, is accessibly on the device specified by
2136@var{device_num}. If so, it returns a nonzero value and otherwise zero.
2137
2138The address given by @var{ptr} is interpreted to be in the address space of
2139the device and @var{size} must be positive.
2140
2141Note that GCC's current implementation assumes that @var{ptr} is a valid host
2142pointer. Therefore, all addresses given by @var{ptr} are assumed to be
2143accessible on the initial device. And, to err on the safe side, this memory
2144is only available on a non-host device that can access all host memory
2145([uniform] shared memory access).
2146
2147Running this routine in a @code{target} region except on the initial device
2148is not supported.
2149
2150@item @emph{C/C++}
2151@multitable @columnfractions .20 .80
2152@item @emph{Prototype}: @tab @code{int omp_target_is_accessible(const void *ptr,}
2153@item @tab @code{ size_t size,}
2154@item @tab @code{ int device_num)}
2155@end multitable
2156
2157@item @emph{Fortran}:
2158@multitable @columnfractions .20 .80
2159@item @emph{Interface}: @tab @code{integer(c_int) function omp_target_is_accessible(ptr, &}
2160@item @tab @code{ size, device_num) bind(C)}
2161@item @tab @code{use, intrinsic :: iso_c_binding, only: c_ptr, c_size_t, c_int}
2162@item @tab @code{type(c_ptr), value :: ptr}
2163@item @tab @code{integer(c_size_t), value :: size}
2164@item @tab @code{integer(c_int), value :: device_num}
2165@end multitable
2166
2167@item @emph{See also}:
2168@ref{omp_target_associate_ptr}
2169
2170@item @emph{Reference}:
2171@uref{https://www.openmp.org, OpenMP specification v5.1}, Section 3.8.4
2172@end table
2173
2174
2175
2176@node omp_target_memcpy
2177@subsection @code{omp_target_memcpy} -- Copy data between devices
2178@table @asis
2179@item @emph{Description}:
2180This routine copies @var{length} of bytes of data from the device
2181identified by device number @var{src_device_num} to device @var{dst_device_num}.
2182The data is copied from the source device from the address provided by
2183@var{src}, shifted by the offset of @var{src_offset} bytes, to the destination
2184device's @var{dst} address shifted by @var{dst_offset}. The routine returns
2185zero on success and non-zero otherwise.
2186
2187Running this routine in a @code{target} region except on the initial device
2188is not supported.
2189
2190@item @emph{C/C++}
2191@multitable @columnfractions .20 .80
2192@item @emph{Prototype}: @tab @code{int omp_target_memcpy(void *dst,}
2193@item @tab @code{ const void *src,}
2194@item @tab @code{ size_t length,}
2195@item @tab @code{ size_t dst_offset,}
2196@item @tab @code{ size_t src_offset,}
2197@item @tab @code{ int dst_device_num,}
2198@item @tab @code{ int src_device_num)}
2199@end multitable
2200
2201@item @emph{Fortran}:
2202@multitable @columnfractions .20 .80
2203@item @emph{Interface}: @tab @code{integer(c_int) function omp_target_memcpy( &}
2204@item @tab @code{ dst, src, length, dst_offset, src_offset, &}
2205@item @tab @code{ dst_device_num, src_device_num) bind(C)}
2206@item @tab @code{use, intrinsic :: iso_c_binding, only: c_ptr, c_size_t, c_int}
2207@item @tab @code{type(c_ptr), value :: dst, src}
2208@item @tab @code{integer(c_size_t), value :: length, dst_offset, src_offset}
2209@item @tab @code{integer(c_int), value :: dst_device_num, src_device_num}
2210@end multitable
2211
2212@item @emph{See also}:
2213@ref{omp_target_memcpy_async}, @ref{omp_target_memcpy_rect}
2214
2215@item @emph{Reference}:
2216@uref{https://www.openmp.org, OpenMP specification v5.1}, Section 3.8.5
2217@end table
2218
2219
2220
2221@node omp_target_memcpy_async
2222@subsection @code{omp_target_memcpy_async} -- Copy data between devices asynchronously
2223@table @asis
2224@item @emph{Description}:
2225This routine copies asynchronously @var{length} of bytes of data from the
2226device identified by device number @var{src_device_num} to device
2227@var{dst_device_num}. The data is copied from the source device from the
2228address provided by @var{src}, shifted by the offset of @var{src_offset} bytes,
2229to the destination device's @var{dst} address shifted by @var{dst_offset}.
2230Task dependence is expressed by passing an array of depend objects to
2231@var{depobj_list}, where the number of array elements is passed as
2232@var{depobj_count}; if the count is zero, the @var{depobj_list} argument is
2233ignored. In C++ and Fortran, the @var{depobj_list} argument can also be
2234omitted in that case. The routine returns zero if the copying process has
2235successfully been started and non-zero otherwise.
2236
2237Running this routine in a @code{target} region except on the initial device
2238is not supported.
2239
2240@item @emph{C/C++}
2241@multitable @columnfractions .20 .80
2242@item @emph{Prototype}: @tab @code{int omp_target_memcpy_async(void *dst,}
2243@item @tab @code{ const void *src,}
2244@item @tab @code{ size_t length,}
2245@item @tab @code{ size_t dst_offset,}
2246@item @tab @code{ size_t src_offset,}
2247@item @tab @code{ int dst_device_num,}
2248@item @tab @code{ int src_device_num,}
2249@item @tab @code{ int depobj_count,}
2250@item @tab @code{ omp_depend_t *depobj_list)}
2251@end multitable
2252
2253@item @emph{Fortran}:
2254@multitable @columnfractions .20 .80
2255@item @emph{Interface}: @tab @code{integer(c_int) function omp_target_memcpy_async( &}
2256@item @tab @code{ dst, src, length, dst_offset, src_offset, &}
2257@item @tab @code{ dst_device_num, src_device_num, &}
2258@item @tab @code{ depobj_count, depobj_list) bind(C)}
2259@item @tab @code{use, intrinsic :: iso_c_binding, only: c_ptr, c_size_t, c_int}
2260@item @tab @code{type(c_ptr), value :: dst, src}
2261@item @tab @code{integer(c_size_t), value :: length, dst_offset, src_offset}
2262@item @tab @code{integer(c_int), value :: dst_device_num, src_device_num, depobj_count}
2263@item @tab @code{integer(omp_depend_kind), optional :: depobj_list(*)}
2264@end multitable
2265
2266@item @emph{See also}:
2267@ref{omp_target_memcpy}, @ref{omp_target_memcpy_rect_async}
2268
2269@item @emph{Reference}:
2270@uref{https://www.openmp.org, OpenMP specification v5.1}, Section 3.8.7
2271@end table
2272
2273
2274
2275@node omp_target_memcpy_rect
2276@subsection @code{omp_target_memcpy_rect} -- Copy a subvolume of data between devices
2277@table @asis
2278@item @emph{Description}:
2279This routine copies a subvolume of data from the device identified by
2280device number @var{src_device_num} to device @var{dst_device_num}.
2281The array has @var{num_dims} dimensions and each array element has a size of
2282@var{element_size} bytes. The @var{volume} array specifies how many elements
2283per dimension are copied. The full sizes of the destination and source arrays
2284are given by the @var{dst_dimensions} and @var{src_dimensions} arguments,
2285respectively. The offset per dimension to the first element to be copied is
2286given by the @var{dst_offset} and @var{src_offset} arguments. The routine
2287returns zero on success and non-zero otherwise.
2288
2289The OpenMP specification only requires that @var{num_dims} up to three is
2290supported. In order to find implementation-specific maximally supported number
2291of dimensions, the routine returns this value when invoked with a null pointer
2292to both the @var{dst} and @var{src} arguments. As GCC supports arbitrary
2293dimensions, it returns @code{INT_MAX}.
2294
2295The device-number arguments must be conforming device numbers, the @var{src} and
2296@var{dst} must be either both null pointers or all of the following must be
2297fulfilled: @var{element_size} and @var{num_dims} must be positive and the
2298@var{volume}, offset and dimension arrays must have at least @var{num_dims}
2299dimensions.
2300
2301Running this routine in a @code{target} region is not supported except on
2302the initial device.
2303
2304@item @emph{C/C++}
2305@multitable @columnfractions .20 .80
2306@item @emph{Prototype}: @tab @code{int omp_target_memcpy_rect(void *dst,}
2307@item @tab @code{ const void *src,}
2308@item @tab @code{ size_t element_size,}
2309@item @tab @code{ int num_dims,}
2310@item @tab @code{ const size_t *volume,}
2311@item @tab @code{ const size_t *dst_offset,}
2312@item @tab @code{ const size_t *src_offset,}
2313@item @tab @code{ const size_t *dst_dimensions,}
2314@item @tab @code{ const size_t *src_dimensions,}
2315@item @tab @code{ int dst_device_num,}
2316@item @tab @code{ int src_device_num)}
2317@end multitable
2318
2319@item @emph{Fortran}:
2320@multitable @columnfractions .20 .80
2321@item @emph{Interface}: @tab @code{integer(c_int) function omp_target_memcpy_rect( &}
2322@item @tab @code{ dst, src, element_size, num_dims, volume, &}
2323@item @tab @code{ dst_offset, src_offset, dst_dimensions, &}
2324@item @tab @code{ src_dimensions, dst_device_num, src_device_num) bind(C)}
2325@item @tab @code{use, intrinsic :: iso_c_binding, only: c_ptr, c_size_t, c_int}
2326@item @tab @code{type(c_ptr), value :: dst, src}
2327@item @tab @code{integer(c_size_t), value :: element_size, dst_offset, src_offset}
2328@item @tab @code{integer(c_size_t), value :: volume, dst_dimensions, src_dimensions}
2329@item @tab @code{integer(c_int), value :: num_dims, dst_device_num, src_device_num}
2330@end multitable
2331
2332@item @emph{See also}:
2333@ref{omp_target_memcpy_rect_async}, @ref{omp_target_memcpy}, @ref{Offload-Target Specifics}
2334
2335@item @emph{Reference}:
2336@uref{https://www.openmp.org, OpenMP specification v5.1}, Section 3.8.6
2337@end table
2338
2339
2340
2341@node omp_target_memcpy_rect_async
2342@subsection @code{omp_target_memcpy_rect_async} -- Copy a subvolume of data between devices asynchronously
2343@table @asis
2344@item @emph{Description}:
2345This routine copies asynchronously a subvolume of data from the device
2346identified by device number @var{src_device_num} to device @var{dst_device_num}.
2347The array has @var{num_dims} dimensions and each array element has a size of
2348@var{element_size} bytes. The @var{volume} array specifies how many elements
2349per dimension are copied. The full sizes of the destination and source arrays
2350are given by the @var{dst_dimensions} and @var{src_dimensions} arguments,
2351respectively. The offset per dimension to the first element to be copied is
2352given by the @var{dst_offset} and @var{src_offset} arguments. Task dependence
2353is expressed by passing an array of depend objects to @var{depobj_list}, where
2354the number of array elements is passed as @var{depobj_count}; if the count is
2355zero, the @var{depobj_list} argument is ignored. In C++ and Fortran, the
2356@var{depobj_list} argument can also be omitted in that case. The routine
2357returns zero on success and non-zero otherwise.
2358
2359The OpenMP specification only requires that @var{num_dims} up to three is
2360supported. In order to find implementation-specific maximally supported number
2361of dimensions, the routine returns this value when invoked with a null pointer
2362to both the @var{dst} and @var{src} arguments. As GCC supports arbitrary
2363dimensions, it returns @code{INT_MAX}.
2364
2365The device-number arguments must be conforming device numbers, the @var{src} and
2366@var{dst} must be either both null pointers or all of the following must be
2367fulfilled: @var{element_size} and @var{num_dims} must be positive and the
2368@var{volume}, offset and dimension arrays must have at least @var{num_dims}
2369dimensions.
2370
2371Running this routine in a @code{target} region is not supported except on
2372the initial device.
2373
2374@item @emph{C/C++}
2375@multitable @columnfractions .20 .80
2376@item @emph{Prototype}: @tab @code{int omp_target_memcpy_rect_async(void *dst,}
2377@item @tab @code{ const void *src,}
2378@item @tab @code{ size_t element_size,}
2379@item @tab @code{ int num_dims,}
2380@item @tab @code{ const size_t *volume,}
2381@item @tab @code{ const size_t *dst_offset,}
2382@item @tab @code{ const size_t *src_offset,}
2383@item @tab @code{ const size_t *dst_dimensions,}
2384@item @tab @code{ const size_t *src_dimensions,}
2385@item @tab @code{ int dst_device_num,}
2386@item @tab @code{ int src_device_num,}
2387@item @tab @code{ int depobj_count,}
2388@item @tab @code{ omp_depend_t *depobj_list)}
2389@end multitable
2390
2391@item @emph{Fortran}:
2392@multitable @columnfractions .20 .80
2393@item @emph{Interface}: @tab @code{integer(c_int) function omp_target_memcpy_rect_async( &}
2394@item @tab @code{ dst, src, element_size, num_dims, volume, &}
2395@item @tab @code{ dst_offset, src_offset, dst_dimensions, &}
2396@item @tab @code{ src_dimensions, dst_device_num, src_device_num, &}
2397@item @tab @code{ depobj_count, depobj_list) bind(C)}
2398@item @tab @code{use, intrinsic :: iso_c_binding, only: c_ptr, c_size_t, c_int}
2399@item @tab @code{type(c_ptr), value :: dst, src}
2400@item @tab @code{integer(c_size_t), value :: element_size, dst_offset, src_offset}
2401@item @tab @code{integer(c_size_t), value :: volume, dst_dimensions, src_dimensions}
2402@item @tab @code{integer(c_int), value :: num_dims, dst_device_num, src_device_num}
2403@item @tab @code{integer(c_int), value :: depobj_count}
2404@item @tab @code{integer(omp_depend_kind), optional :: depobj_list(*)}
2405@end multitable
2406
2407@item @emph{See also}:
2408@ref{omp_target_memcpy_rect}, @ref{omp_target_memcpy_async}, @ref{Offload-Target Specifics}
2409
2410@item @emph{Reference}:
2411@uref{https://www.openmp.org, OpenMP specification v5.1}, Section 3.8.8
2412@end table
2413
2414
2415@node omp_target_memset
2416@subsection @code{omp_target_memset} -- Set bytes in device memory
2417@table @asis
2418@item @emph{Description}:
2419This routine fills memory on the device identified by device number
2420@var{device_num}. Starting from the device address @var{ptr}, the first
2421@var{count} bytes are set to the value @var{val}, converted to
2422@code{unsigned char}. If @var{count} is zero, the routine has no effect;
2423if @var{ptr} is @code{NULL}, the behavior is unspecified. The function
2424returns @var{ptr}.
2425
2426The @var{device_num} must be a conforming device number and @var{ptr} must be
2427a valid device pointer for that device. Running this routine in a
2428@code{target} region except on the initial device is not supported.
2429
2430@item @emph{C/C++}
2431@multitable @columnfractions .20 .80
2432@item @emph{Prototype}: @tab @code{void *omp_target_memcpy(void *ptr,}
2433@item @tab @code{ int val,}
2434@item @tab @code{ size_t count,}
2435@item @tab @code{ int device_num)}
2436@end multitable
2437
2438@item @emph{Fortran}:
2439@multitable @columnfractions .20 .80
2440@item @emph{Interface}: @tab @code{type(c_ptr) function omp_target_memset( &}
2441@item @tab @code{ ptr, val, count, device_num) bind(C)}
2442@item @tab @code{use, intrinsic :: iso_c_binding, only: c_ptr, c_size_t, c_int}
2443@item @tab @code{type(c_ptr), value :: ptr}
2444@item @tab @code{integer(c_size_t), value :: count}
2445@item @tab @code{integer(c_int), value :: val, device_num}
2446@end multitable
2447
2448@item @emph{See also}:
2449@ref{omp_target_memset_async}
2450
2451@item @emph{Reference}:
2452@uref{https://www.openmp.org, OpenMP specification v6.0}, Section 25.8.1
2453@end table
2454
2455
2456
2457@node omp_target_memset_async
2458@subsection @code{omp_target_memset} -- Set bytes in device memory asynchronously
2459@table @asis
2460@item @emph{Description}:
2461This routine fills memory on the device identified by device number
2462@var{device_num}. Starting from the device address @var{ptr}, the first
2463@var{count} bytes are set to the value @var{val}, converted to
2464@code{unsigned char}. If @var{count} is zero, the routine has no effect;
2465if @var{ptr} is @code{NULL}, the behavior is unspecified. Task dependence
2466is expressed by passing an array of depend objects to @var{depobj_list}, where
2467the number of array elements is passed as @var{depobj_count}; if the count is
2468zero, the @var{depobj_list} argument is ignored. In C++ and Fortran, the
2469@var{depobj_list} argument can also be omitted in that case. The function
2470returns @var{ptr}.
2471
2472The @var{device_num} must be a conforming device number and @var{ptr} must be
2473a valid device pointer for that device. Running this routine in a
2474@code{target} region except on the initial device is not supported.
2475
2476@item @emph{C/C++}
2477@multitable @columnfractions .20 .80
2478@item @emph{Prototype}: @tab @code{void *omp_target_memcpy_async(void *ptr,}
2479@item @tab @code{ int val,}
2480@item @tab @code{ size_t count,}
2481@item @tab @code{ int device_num,}
2482@item @tab @code{ int depobj_count,}
2483@item @tab @code{ omp_depend_t *depobj_list)}
2484@end multitable
2485
2486@item @emph{Fortran}:
2487@multitable @columnfractions .20 .80
2488@item @emph{Interface}: @tab @code{type(c_ptr) function omp_target_memset_async( &}
2489@item @tab @code{ ptr, val, count, device_num, &}
2490@item @tab @code{ depobj_count, depobj_list) bind(C)}
2491@item @tab @code{use, intrinsic :: iso_c_binding, only: c_ptr, c_size_t, c_int}
2492@item @tab @code{type(c_ptr), value :: ptr}
2493@item @tab @code{integer(c_size_t), value :: count}
2494@item @tab @code{integer(c_int), value :: val, device_num, depobj_count}
2495@item @tab @code{integer(omp_depend_kind), optional :: depobj_list(*)}
2496@end multitable
2497
2498
2499@item @emph{See also}:
2500@ref{omp_target_memset}
2501
2502@item @emph{Reference}:
2503@uref{https://www.openmp.org, OpenMP specification v6.0}, Section 25.8.2
2504@end table
2505
2506
2507
2508@node omp_target_associate_ptr
2509@subsection @code{omp_target_associate_ptr} -- Associate a device pointer with a host pointer
2510@table @asis
2511@item @emph{Description}:
2512This routine associates storage on the host with storage on a device identified
2513by @var{device_num}. The device pointer is usually obtained by calling
2514@code{omp_target_alloc} or by other means (but not by using the @code{map}
2515clauses or the @code{declare target} directive). The host pointer should point
2516to memory that has a storage size of at least @var{size}.
2517
2518The @var{device_offset} parameter specifies the offset into @var{device_ptr}
2519that is used as the base address for the device side of the mapping; the
2520storage size should be at least @var{device_offset} plus @var{size}.
2521
2522After the association, the host pointer can be used in a @code{map} clause and
2523in the @code{to} and @code{from} clauses of the @code{target update} directive
2524to transfer data between the associated pointers. The reference count of such
2525associated storage is infinite. The association can be removed by calling
2526@code{omp_target_disassociate_ptr} which should be done before the lifetime
2527of either storage ends.
2528
2529The routine returns nonzero (@code{EINVAL}) when the @var{device_num} invalid,
2530for when the initial device or the associated device shares memory with the
2531host. @code{omp_target_associate_ptr} returns zero if @var{host_ptr} points
2532into already associated storage that is fully inside of a previously associated
2533memory. Otherwise, if the association was successful zero is returned; if none
2534of the cases above apply, nonzero (@code{EINVAL}) is returned.
2535
2536The @code{omp_target_is_present} routine can be used to test whether
2537associated storage for a device pointer exists.
2538
2539Running this routine in a @code{target} region except on the initial device
2540is not supported.
2541
2542@item @emph{C/C++}
2543@multitable @columnfractions .20 .80
2544@item @emph{Prototype}: @tab @code{int omp_target_associate_ptr(const void *host_ptr,}
2545@item @tab @code{ const void *device_ptr,}
2546@item @tab @code{ size_t size,}
2547@item @tab @code{ size_t device_offset,}
2548@item @tab @code{ int device_num)}
2549@end multitable
2550
2551@item @emph{Fortran}:
2552@multitable @columnfractions .20 .80
2553@item @emph{Interface}: @tab @code{integer(c_int) function omp_target_associate_ptr(host_ptr, &}
2554@item @tab @code{ device_ptr, size, device_offset, device_num) bind(C)}
2555@item @tab @code{use, intrinsic :: iso_c_binding, only: c_ptr, c_int, c_size_t}
2556@item @tab @code{type(c_ptr), value :: host_ptr, device_ptr}
2557@item @tab @code{integer(c_size_t), value :: size, device_offset}
2558@item @tab @code{integer(c_int), value :: device_num}
2559@end multitable
2560
2561@item @emph{See also}:
2562@ref{omp_target_disassociate_ptr}, @ref{omp_target_is_present},
2563@ref{omp_target_alloc}
2564
2565@item @emph{Reference}:
2566@uref{https://www.openmp.org, OpenMP specification v5.1}, Section 3.8.9
2567@end table
2568
2569
2570
2571@node omp_target_disassociate_ptr
2572@subsection @code{omp_target_disassociate_ptr} -- Remove device--host pointer association
2573@table @asis
2574@item @emph{Description}:
2575This routine removes the storage association established by calling
2576@code{omp_target_associate_ptr} and sets the reference count to zero,
2577even if @code{omp_target_associate_ptr} was invoked multiple times for
2578for host pointer @code{ptr}. If applicable, the device memory needs
2579to be freed by the user.
2580
2581If an associated device storage location for the @var{device_num} was
2582found and has infinite reference count, the association is removed and
2583zero is returned. In all other cases, nonzero (@code{EINVAL}) is returned
2584and no other action is taken.
2585
2586Note that passing a host pointer where the association to the device pointer
2587was established with the @code{declare target} directive yields undefined
2588behavior.
2589
2590Running this routine in a @code{target} region except on the initial device
2591is not supported.
2592
2593@item @emph{C/C++}
2594@multitable @columnfractions .20 .80
2595@item @emph{Prototype}: @tab @code{int omp_target_disassociate_ptr(const void *ptr,}
2596@item @tab @code{ int device_num)}
2597@end multitable
2598
2599@item @emph{Fortran}:
2600@multitable @columnfractions .20 .80
2601@item @emph{Interface}: @tab @code{integer(c_int) function omp_target_disassociate_ptr(ptr, &}
2602@item @tab @code{ device_num) bind(C)}
2603@item @tab @code{use, intrinsic :: iso_c_binding, only: c_ptr, c_int}
2604@item @tab @code{type(c_ptr), value :: ptr}
2605@item @tab @code{integer(c_int), value :: device_num}
2606@end multitable
2607
2608@item @emph{See also}:
2609@ref{omp_target_associate_ptr}
2610
2611@item @emph{Reference}:
2612@uref{https://www.openmp.org, OpenMP specification v5.1}, Section 3.8.10
2613@end table
2614
2615
2616
2617@node omp_get_mapped_ptr
2618@subsection @code{omp_get_mapped_ptr} -- Return device pointer to a host pointer
2619@table @asis
2620@item @emph{Description}:
2621If the device number is refers to the initial device or to a device with
2622memory accessible from the host (shared memory), the @code{omp_get_mapped_ptr}
2623routines returns the value of the passed @var{ptr}. Otherwise, if associated
2624storage to the passed host pointer @var{ptr} exists on device associated with
2625@var{device_num}, it returns that pointer. In all other cases and in cases of
2626an error, a null pointer is returned.
2627
2628The association of storage location is established either via an explicit or
2629implicit @code{map} clause, the @code{declare target} directive or the
2630@code{omp_target_associate_ptr} routine.
2631
2632Running this routine in a @code{target} region except on the initial device
2633is not supported.
2634
2635@item @emph{C/C++}
2636@multitable @columnfractions .20 .80
2637@item @emph{Prototype}: @tab @code{void *omp_get_mapped_ptr(const void *ptr, int device_num);}
2638@end multitable
2639
2640@item @emph{Fortran}:
2641@multitable @columnfractions .20 .80
2642@item @emph{Interface}: @tab @code{type(c_ptr) function omp_get_mapped_ptr(ptr, device_num) bind(C)}
2643@item @tab @code{use, intrinsic :: iso_c_binding, only: c_ptr, c_int}
2644@item @tab @code{type(c_ptr), value :: ptr}
2645@item @tab @code{integer(c_int), value :: device_num}
2646@end multitable
2647
2648@item @emph{See also}:
2649@ref{omp_target_associate_ptr}
2650
2651@item @emph{Reference}:
2652@uref{https://www.openmp.org, OpenMP specification v5.1}, Section 3.8.11
2653@end table
2654
2655
2656
2657@node Lock Routines
2658@section Lock Routines
2659
2660Initialize, set, test, unset and destroy simple and nested locks.
2661The routines have C linkage and do not throw exceptions.
2662
2663@menu
2664* omp_init_lock:: Initialize simple lock
2665* omp_init_nest_lock:: Initialize nested lock
2666@c PR libgomp/109452
2667@c * omp_init_lock_with_hint:: Initialize simple lock with sync hint
2668@c * omp_init_nest_lock_with_hint:: Initialize nested lock with sync hint
2669* omp_destroy_lock:: Destroy simple lock
2670* omp_destroy_nest_lock:: Destroy nested lock
2671* omp_set_lock:: Wait for and set simple lock
2672* omp_set_nest_lock:: Wait for and set simple lock
2673* omp_unset_lock:: Unset simple lock
2674* omp_unset_nest_lock:: Unset nested lock
2675* omp_test_lock:: Test and set simple lock if available
2676* omp_test_nest_lock:: Test and set nested lock if available
2677@end menu
2678
2679
2680
2681@node omp_init_lock
2682@subsection @code{omp_init_lock} -- Initialize simple lock
2683@table @asis
2684@item @emph{Description}:
2685Initialize a simple lock. After initialization, the lock is in
2686an unlocked state.
2687
2688@item @emph{C/C++}:
2689@multitable @columnfractions .20 .80
2690@item @emph{Prototype}: @tab @code{void omp_init_lock(omp_lock_t *lock);}
2691@end multitable
2692
2693@item @emph{Fortran}:
2694@multitable @columnfractions .20 .80
2695@item @emph{Interface}: @tab @code{subroutine omp_init_lock(svar)}
2696@item @tab @code{integer(omp_lock_kind), intent(out) :: svar}
2697@end multitable
2698
2699@item @emph{See also}:
2700@ref{omp_destroy_lock}
2701
2702@item @emph{Reference}:
2703@uref{https://www.openmp.org, OpenMP specification v4.5}, Section 3.3.1.
2704@end table
2705
2706
2707
2708@node omp_init_nest_lock
2709@subsection @code{omp_init_nest_lock} -- Initialize nested lock
2710@table @asis
2711@item @emph{Description}:
2712Initialize a nested lock. After initialization, the lock is in
2713an unlocked state and the nesting count is set to zero.
2714
2715@item @emph{C/C++}:
2716@multitable @columnfractions .20 .80
2717@item @emph{Prototype}: @tab @code{void omp_init_nest_lock(omp_nest_lock_t *lock);}
2718@end multitable
2719
2720@item @emph{Fortran}:
2721@multitable @columnfractions .20 .80
2722@item @emph{Interface}: @tab @code{subroutine omp_init_nest_lock(nvar)}
2723@item @tab @code{integer(omp_nest_lock_kind), intent(out) :: nvar}
2724@end multitable
2725
2726@item @emph{See also}:
2727@ref{omp_destroy_nest_lock}
2728
2729@item @emph{Reference}:
2730@uref{https://www.openmp.org, OpenMP specification v4.5}, Section 3.3.1.
2731@end table
2732
2733
2734
2735@node omp_destroy_lock
2736@subsection @code{omp_destroy_lock} -- Destroy simple lock
2737@table @asis
2738@item @emph{Description}:
2739Destroy a simple lock. In order to be destroyed, a simple lock must be
2740in the unlocked state.
2741
2742@item @emph{C/C++}:
2743@multitable @columnfractions .20 .80
2744@item @emph{Prototype}: @tab @code{void omp_destroy_lock(omp_lock_t *lock);}
2745@end multitable
2746
2747@item @emph{Fortran}:
2748@multitable @columnfractions .20 .80
2749@item @emph{Interface}: @tab @code{subroutine omp_destroy_lock(svar)}
2750@item @tab @code{integer(omp_lock_kind), intent(inout) :: svar}
2751@end multitable
2752
2753@item @emph{See also}:
2754@ref{omp_init_lock}
2755
2756@item @emph{Reference}:
2757@uref{https://www.openmp.org, OpenMP specification v4.5}, Section 3.3.3.
2758@end table
2759
2760
2761
2762@node omp_destroy_nest_lock
2763@subsection @code{omp_destroy_nest_lock} -- Destroy nested lock
2764@table @asis
2765@item @emph{Description}:
2766Destroy a nested lock. In order to be destroyed, a nested lock must be
2767in the unlocked state and its nesting count must equal zero.
2768
2769@item @emph{C/C++}:
2770@multitable @columnfractions .20 .80
2771@item @emph{Prototype}: @tab @code{void omp_destroy_nest_lock(omp_nest_lock_t *);}
2772@end multitable
2773
2774@item @emph{Fortran}:
2775@multitable @columnfractions .20 .80
2776@item @emph{Interface}: @tab @code{subroutine omp_destroy_nest_lock(nvar)}
2777@item @tab @code{integer(omp_nest_lock_kind), intent(inout) :: nvar}
2778@end multitable
2779
2780@item @emph{See also}:
2781@ref{omp_init_lock}
2782
2783@item @emph{Reference}:
2784@uref{https://www.openmp.org, OpenMP specification v4.5}, Section 3.3.3.
2785@end table
2786
2787
2788
2789@node omp_set_lock
2790@subsection @code{omp_set_lock} -- Wait for and set simple lock
2791@table @asis
2792@item @emph{Description}:
2793Before setting a simple lock, the lock variable must be initialized by
2794@code{omp_init_lock}. The calling thread is blocked until the lock
2795is available. If the lock is already held by the current thread,
2796a deadlock occurs.
2797
2798@item @emph{C/C++}:
2799@multitable @columnfractions .20 .80
2800@item @emph{Prototype}: @tab @code{void omp_set_lock(omp_lock_t *lock);}
2801@end multitable
2802
2803@item @emph{Fortran}:
2804@multitable @columnfractions .20 .80
2805@item @emph{Interface}: @tab @code{subroutine omp_set_lock(svar)}
2806@item @tab @code{integer(omp_lock_kind), intent(inout) :: svar}
2807@end multitable
2808
2809@item @emph{See also}:
2810@ref{omp_init_lock}, @ref{omp_test_lock}, @ref{omp_unset_lock}
2811
2812@item @emph{Reference}:
2813@uref{https://www.openmp.org, OpenMP specification v4.5}, Section 3.3.4.
2814@end table
2815
2816
2817
2818@node omp_set_nest_lock
2819@subsection @code{omp_set_nest_lock} -- Wait for and set nested lock
2820@table @asis
2821@item @emph{Description}:
2822Before setting a nested lock, the lock variable must be initialized by
2823@code{omp_init_nest_lock}. The calling thread is blocked until the lock
2824is available. If the lock is already held by the current thread, the
2825nesting count for the lock is incremented.
2826
2827@item @emph{C/C++}:
2828@multitable @columnfractions .20 .80
2829@item @emph{Prototype}: @tab @code{void omp_set_nest_lock(omp_nest_lock_t *lock);}
2830@end multitable
2831
2832@item @emph{Fortran}:
2833@multitable @columnfractions .20 .80
2834@item @emph{Interface}: @tab @code{subroutine omp_set_nest_lock(nvar)}
2835@item @tab @code{integer(omp_nest_lock_kind), intent(inout) :: nvar}
2836@end multitable
2837
2838@item @emph{See also}:
2839@ref{omp_init_nest_lock}, @ref{omp_unset_nest_lock}
2840
2841@item @emph{Reference}:
2842@uref{https://www.openmp.org, OpenMP specification v4.5}, Section 3.3.4.
2843@end table
2844
2845
2846
2847@node omp_unset_lock
2848@subsection @code{omp_unset_lock} -- Unset simple lock
2849@table @asis
2850@item @emph{Description}:
2851A simple lock about to be unset must have been locked by @code{omp_set_lock}
2852or @code{omp_test_lock} before. In addition, the lock must be held by the
2853thread calling @code{omp_unset_lock}. Then, the lock becomes unlocked. If one
2854or more threads attempted to set the lock before, one of them is chosen to,
2855again, set the lock to itself.
2856
2857@item @emph{C/C++}:
2858@multitable @columnfractions .20 .80
2859@item @emph{Prototype}: @tab @code{void omp_unset_lock(omp_lock_t *lock);}
2860@end multitable
2861
2862@item @emph{Fortran}:
2863@multitable @columnfractions .20 .80
2864@item @emph{Interface}: @tab @code{subroutine omp_unset_lock(svar)}
2865@item @tab @code{integer(omp_lock_kind), intent(inout) :: svar}
2866@end multitable
2867
2868@item @emph{See also}:
2869@ref{omp_set_lock}, @ref{omp_test_lock}
2870
2871@item @emph{Reference}:
2872@uref{https://www.openmp.org, OpenMP specification v4.5}, Section 3.3.5.
2873@end table
2874
2875
2876
2877@node omp_unset_nest_lock
2878@subsection @code{omp_unset_nest_lock} -- Unset nested lock
2879@table @asis
2880@item @emph{Description}:
2881A nested lock about to be unset must have been locked by @code{omp_set_nested_lock}
2882or @code{omp_test_nested_lock} before. In addition, the lock must be held by the
2883thread calling @code{omp_unset_nested_lock}. If the nesting count drops to zero, the
2884lock becomes unlocked. If one ore more threads attempted to set the lock before,
2885one of them is chosen to, again, set the lock to itself.
2886
2887@item @emph{C/C++}:
2888@multitable @columnfractions .20 .80
2889@item @emph{Prototype}: @tab @code{void omp_unset_nest_lock(omp_nest_lock_t *lock);}
2890@end multitable
2891
2892@item @emph{Fortran}:
2893@multitable @columnfractions .20 .80
2894@item @emph{Interface}: @tab @code{subroutine omp_unset_nest_lock(nvar)}
2895@item @tab @code{integer(omp_nest_lock_kind), intent(inout) :: nvar}
2896@end multitable
2897
2898@item @emph{See also}:
2899@ref{omp_set_nest_lock}
2900
2901@item @emph{Reference}:
2902@uref{https://www.openmp.org, OpenMP specification v4.5}, Section 3.3.5.
2903@end table
2904
2905
2906
2907@node omp_test_lock
2908@subsection @code{omp_test_lock} -- Test and set simple lock if available
2909@table @asis
2910@item @emph{Description}:
2911Before setting a simple lock, the lock variable must be initialized by
2912@code{omp_init_lock}. Contrary to @code{omp_set_lock}, @code{omp_test_lock}
2913does not block if the lock is not available. This function returns
2914@code{true} upon success, @code{false} otherwise. Here, @code{true} and
2915@code{false} represent their language-specific counterparts.
2916
2917@item @emph{C/C++}:
2918@multitable @columnfractions .20 .80
2919@item @emph{Prototype}: @tab @code{int omp_test_lock(omp_lock_t *lock);}
2920@end multitable
2921
2922@item @emph{Fortran}:
2923@multitable @columnfractions .20 .80
2924@item @emph{Interface}: @tab @code{logical function omp_test_lock(svar)}
2925@item @tab @code{integer(omp_lock_kind), intent(inout) :: svar}
2926@end multitable
2927
2928@item @emph{See also}:
2929@ref{omp_init_lock}, @ref{omp_set_lock}, @ref{omp_set_lock}
2930
2931@item @emph{Reference}:
2932@uref{https://www.openmp.org, OpenMP specification v4.5}, Section 3.3.6.
2933@end table
2934
2935
2936
2937@node omp_test_nest_lock
2938@subsection @code{omp_test_nest_lock} -- Test and set nested lock if available
2939@table @asis
2940@item @emph{Description}:
2941Before setting a nested lock, the lock variable must be initialized by
2942@code{omp_init_nest_lock}. Contrary to @code{omp_set_nest_lock},
2943@code{omp_test_nest_lock} does not block if the lock is not available.
2944If the lock is already held by the current thread, the new nesting count
2945is returned. Otherwise, the return value equals zero.
2946
2947@item @emph{C/C++}:
2948@multitable @columnfractions .20 .80
2949@item @emph{Prototype}: @tab @code{int omp_test_nest_lock(omp_nest_lock_t *lock);}
2950@end multitable
2951
2952@item @emph{Fortran}:
2953@multitable @columnfractions .20 .80
2954@item @emph{Interface}: @tab @code{logical function omp_test_nest_lock(nvar)}
2955@item @tab @code{integer(omp_nest_lock_kind), intent(inout) :: nvar}
2956@end multitable
2957
2958
2959@item @emph{See also}:
2960@ref{omp_init_lock}, @ref{omp_set_lock}, @ref{omp_set_lock}
2961
2962@item @emph{Reference}:
2963@uref{https://www.openmp.org, OpenMP specification v4.5}, Section 3.3.6.
2964@end table
2965
2966
2967
2968@node Timing Routines
2969@section Timing Routines
2970
2971Portable, thread-based, wall clock timer.
2972The routines have C linkage and do not throw exceptions.
2973
2974@menu
2975* omp_get_wtick:: Get timer precision.
2976* omp_get_wtime:: Elapsed wall clock time.
2977@end menu
2978
2979
2980
2981@node omp_get_wtick
2982@subsection @code{omp_get_wtick} -- Get timer precision
2983@table @asis
2984@item @emph{Description}:
2985Gets the timer precision, i.e., the number of seconds between two
2986successive clock ticks.
2987
2988@item @emph{C/C++}:
2989@multitable @columnfractions .20 .80
2990@item @emph{Prototype}: @tab @code{double omp_get_wtick(void);}
2991@end multitable
2992
2993@item @emph{Fortran}:
2994@multitable @columnfractions .20 .80
2995@item @emph{Interface}: @tab @code{double precision function omp_get_wtick()}
2996@end multitable
2997
2998@item @emph{See also}:
2999@ref{omp_get_wtime}
3000
3001@item @emph{Reference}:
3002@uref{https://www.openmp.org, OpenMP specification v4.5}, Section 3.4.2.
3003@end table
3004
3005
3006
3007@node omp_get_wtime
3008@subsection @code{omp_get_wtime} -- Elapsed wall clock time
3009@table @asis
3010@item @emph{Description}:
3011Elapsed wall clock time in seconds. The time is measured per thread, no
3012guarantee can be made that two distinct threads measure the same time.
3013Time is measured from some "time in the past", which is an arbitrary time
3014guaranteed not to change during the execution of the program.
3015
3016@item @emph{C/C++}:
3017@multitable @columnfractions .20 .80
3018@item @emph{Prototype}: @tab @code{double omp_get_wtime(void);}
3019@end multitable
3020
3021@item @emph{Fortran}:
3022@multitable @columnfractions .20 .80
3023@item @emph{Interface}: @tab @code{double precision function omp_get_wtime()}
3024@end multitable
3025
3026@item @emph{See also}:
3027@ref{omp_get_wtick}
3028
3029@item @emph{Reference}:
3030@uref{https://www.openmp.org, OpenMP specification v4.5}, Section 3.4.1.
3031@end table
3032
3033
3034
3035@node Event Routine
3036@section Event Routine
3037
3038Support for event objects.
3039The routine has C linkage and do not throw exceptions.
3040
3041@menu
3042* omp_fulfill_event:: Fulfill and destroy an OpenMP event.
3043@end menu
3044
3045
3046
3047@node omp_fulfill_event
3048@subsection @code{omp_fulfill_event} -- Fulfill and destroy an OpenMP event
3049@table @asis
3050@item @emph{Description}:
3051Fulfill the event associated with the event handle argument. Currently, it
3052is only used to fulfill events generated by detach clauses on task
3053constructs - the effect of fulfilling the event is to allow the task to
3054complete.
3055
3056The result of calling @code{omp_fulfill_event} with an event handle other
3057than that generated by a detach clause is undefined. Calling it with an
3058event handle that has already been fulfilled is also undefined.
3059
3060@item @emph{C/C++}:
3061@multitable @columnfractions .20 .80
3062@item @emph{Prototype}: @tab @code{void omp_fulfill_event(omp_event_handle_t event);}
3063@end multitable
3064
3065@item @emph{Fortran}:
3066@multitable @columnfractions .20 .80
3067@item @emph{Interface}: @tab @code{subroutine omp_fulfill_event(event)}
3068@item @tab @code{integer (kind=omp_event_handle_kind) :: event}
3069@end multitable
3070
3071@item @emph{Reference}:
3072@uref{https://www.openmp.org, OpenMP specification v5.0}, Section 3.5.1.
3073@end table
3074
3075
3076
3077@node Interoperability Routines
3078@section Interoperability Routines
3079
3080Routines to obtain properties from an object of OpenMP interop type.
3081They have C linkage and do not throw exceptions.
3082
3083@menu
3084* omp_get_num_interop_properties:: Get the number of implementation-specific properties
3085* omp_get_interop_int:: Obtain integer-valued interoperability property
3086* omp_get_interop_ptr:: Obtain pointer-valued interoperability property
3087* omp_get_interop_str:: Obtain string-valued interoperability property
3088* omp_get_interop_name:: Obtain the name of an interop_property value as string
3089* omp_get_interop_type_desc:: Obtain type and description to an interop_property
3090* omp_get_interop_rc_desc:: Obtain error string to an interop_rc error code
3091@end menu
3092
3093
3094
3095@node omp_get_num_interop_properties
3096@subsection @code{omp_get_num_interop_properties} -- Get the number of implementation-specific properties
3097@table @asis
3098@item @emph{Description}:
3099The @code{omp_get_num_interop_properties} function returns the number of
3100implementation-defined interoperability properties available for the passed
3101@var{interop}, extending the OpenMP-defined properties. The available OpenMP
3102interop_property-type values range from @code{omp_ipr_first} to the value
3103returned by @code{omp_get_num_interop_properties} minus one.
3104
3105No implementation-defined properties are currently defined in GCC.
3106
3107@c Implementation remark: In GCC, the Fortran interface differs from the one shown
3108@c below: the function has C binding, @var{interop} is passed by value and an
3109@c integer of @code{c_int} kind is returned, which permits use of the same ABI as
3110@c the C function. This does not affect the usage of the function when GCC's
3111@c @code{omp_lib} module or @code{omp_lib.h} header is used.
3112
3113@item @emph{C/C++}:
3114@multitable @columnfractions .20 .80
3115@item @emph{Prototype}: @tab @code{int omp_get_num_interop_properties(const omp_interop_t interop)}
3116@end multitable
3117
3118@item @emph{Fortran}:
3119@multitable @columnfractions .20 .80
3120@item @emph{Interface}: @tab @code{integer function omp_get_num_interop_properties(interop)}
3121@item @tab @code{integer(omp_interop_kind), intent(in) :: interop}
3122@end multitable
3123
3124@item @emph{See also}:
3125@ref{omp_get_interop_name}, @ref{omp_get_interop_type_desc}
3126
3127@item @emph{Reference}:
3128@uref{https://www.openmp.org, OpenMP specification v5.1}, Section 3.12.1,
3129@uref{https://www.openmp.org, OpenMP specification v6.0}, Section 26.1
3130@end table
3131
3132
3133
3134@node omp_get_interop_int
3135@subsection @code{omp_get_interop_int} -- Obtain integer-valued interoperability property
3136@table @asis
3137@item @emph{Description}:
3138The @code{omp_get_interop_int} function returns the integer value associated
3139with the @var{property_id} interoperability property of the passed @var{interop}
3140object. The @var{ret_code} argument is optional, i.e. it can be omitted in C++
3141and Fortran or used with @code{NULL} as argument in C and C++. If successful,
3142@var{ret_code} (if present) is set to @code{omp_irc_success}.
3143
3144In GCC, the effect of running this routine in a @code{target} region that is not
3145the initial device is unspecified.
3146
3147GCC implements the OpenMP 6.0 version of this function for C and C++, which is not
3148compatible with its type signature in previous versions of the OpenMP specification.
3149In older versions, the type @code{int*} was used for the @var{ret_code} argument
3150in place of a pointer to the enumerated type @code{omp_interop_rc_t}.
3151
3152@c Implementation remark: In GCC, the Fortran interface differs from the one shown
3153@c below: the function has C binding and @var{interop} and @var{property_id} are
3154@c passed by value, which permits use of the same ABI as the C function. This does
3155@c not affect the usage of the function when GCC's @code{omp_lib} module or
3156@c @code{omp_lib.h} header is used.
3157
3158@item @emph{C/C++}:
3159@multitable @columnfractions .20 .80
3160@item @emph{Prototype}: @tab @code{omp_intptr_t omp_get_interop_int(const omp_interop_t interop,
3161 omp_interop_property_t property_id, omp_interop_rc_t *ret_code)}
3162@end multitable
3163
3164@item @emph{Fortran}:
3165@multitable @columnfractions .20 .80
3166@item @emph{Interface}: @tab @code{integer(c_intptr_t) function omp_get_interop_int(interop,
3167 property_id, ret_code)}
3168@item @tab @code{use, intrinsic :: iso_c_binding, only : c_intptr_t}
3169@item @tab @code{integer(omp_interop_kind), intent(in) :: interop}
3170@item @tab @code{integer(omp_interop_property_kind) property_id}
3171@item @tab @code{integer(omp_interop_rc_kind), optional, intent(out) :: ret_code}
3172@end multitable
3173
3174@item @emph{See also}:
3175@ref{omp_get_interop_ptr}, @ref{omp_get_interop_str}, @ref{omp_get_interop_rc_desc},
3176@ref{Offload-Target Specifics}
3177
3178@item @emph{Reference}:
3179@uref{https://www.openmp.org, OpenMP specification v5.1}, Section 3.12.2,
3180@uref{https://www.openmp.org, OpenMP specification v6.0}, Section 26.2
3181@end table
3182
3183
3184
3185@node omp_get_interop_ptr
3186@subsection @code{omp_get_interop_ptr} -- Obtain pointer-valued interoperability property
3187@table @asis
3188@item @emph{Description}:
3189The @code{omp_get_interop_int} function returns the pointer value associated with
3190the @var{property_id} interoperability property of the passed @var{interop}
3191object. The @var{ret_code} argument is optional, i.e. it can be omitted in C++
3192and Fortran or used with @code{NULL} as argument in C and C++. If successful,
3193@var{ret_code} (if present) is set to @code{omp_irc_success}.
3194
3195In GCC, the effect of running this routine in a @code{target} region that is not
3196the initial device is unspecified.
3197
3198GCC implements the OpenMP 6.0 version of this function for C and C++, which is not
3199compatible with its type signature in previous versions of the OpenMP specification.
3200In older versions, the type @code{int*} was used for the @var{ret_code} argument
3201in place of a pointer to the enumerated type @code{omp_interop_rc_t}.
3202
3203@c Implementation remark: In GCC, the Fortran interface differs from the one shown
3204@c below: the function has C binding and @var{interop} and @var{property_id} are
3205@c passed by value, which permits use of the same ABI as the C function. This does
3206@c not affect the usage of the function when GCC's @code{omp_lib} module or
3207@c @code{omp_lib.h} header is used.
3208
3209@item @emph{C/C++}:
3210@multitable @columnfractions .20 .80
3211@item @emph{Prototype}: @tab @code{void *omp_get_interop_ptr(const omp_interop_t interop,
3212 omp_interop_property_t property_id, omp_interop_rc_t *ret_code)}
3213@end multitable
3214
3215@item @emph{Fortran}:
3216@multitable @columnfractions .20 .80
3217@item @emph{Interface}: @tab @code{type(c_ptr) function omp_get_interop_int(interop,
3218 property_id, ret_code)}
3219@item @tab @code{use, intrinsic :: iso_c_binding, only : c_ptr}
3220@item @tab @code{integer(omp_interop_kind), intent(in) :: interop}
3221@item @tab @code{integer(omp_interop_property_kind) property_id}
3222@item @tab @code{integer(omp_interop_rc_kind), optional, intent(out) :: ret_code}
3223@end multitable
3224
3225@item @emph{See also}:
3226@ref{omp_get_interop_int}, @ref{omp_get_interop_str}, @ref{omp_get_interop_rc_desc},
3227@ref{Offload-Target Specifics}
3228
3229@item @emph{Reference}:
3230@uref{https://www.openmp.org, OpenMP specification v5.1}, Section 3.12.3,
3231@uref{https://www.openmp.org, OpenMP specification v6.0}, Section 26.3
3232@end table
3233
3234
3235
3236@node omp_get_interop_str
3237@subsection @code{omp_get_interop_str} -- Obtain string-valued interoperability property
3238@table @asis
3239@item @emph{Description}:
3240The @code{omp_get_interop_str} function returns the string value associated with
3241the @var{property_id} interoperability property of the passed @var{interop}
3242object. The @var{ret_code} argument is optional, i.e. it can be omitted in C++
3243and Fortran or used with @code{NULL} as argument in C and C++. If successful,
3244@var{ret_code} (if present) is set to @code{omp_irc_success}.
3245
3246In GCC, the effect of running this routine in a @code{target} region that is not
3247the initial device is unspecified.
3248
3249GCC implements the OpenMP 6.0 version of this function for C and C++, which is not
3250compatible with its type signature in previous versions of the OpenMP specification.
3251In older versions, the type @code{int*} was used for the @var{ret_code} argument
3252in place of a pointer to the enumerated type @code{omp_interop_rc_t}.
3253
3254@c Implementation remark: In GCC, the Fortran interface differs from the one shown
3255@c below: @var{interop} and @var{property_id} are passed by value. This does not
3256@c affect the usage of the function when GCC's @code{omp_lib} module or
3257@c @code{omp_lib.h} header is used.
3258
3259@item @emph{C/C++}:
3260@multitable @columnfractions .20 .80
3261@item @emph{Prototype}: @tab @code{const char *omp_get_interop_str(const omp_interop_t interop,
3262 omp_interop_property_t property_id, omp_interop_rc_t *ret_code)}
3263@end multitable
3264
3265@item @emph{Fortran}:
3266@multitable @columnfractions .20 .80
3267@item @emph{Interface}: @tab @code{character(:) function omp_get_interop_str(interop,
3268 property_id, ret_code)}
3269@item @tab @code{pointer :: omp_get_interop_str}
3270@item @tab @code{integer(omp_interop_kind), intent(in) :: interop}
3271@item @tab @code{integer(omp_interop_property_kind) property_id}
3272@item @tab @code{integer(omp_interop_rc_kind), optional, intent(out) :: ret_code}
3273@end multitable
3274
3275@item @emph{See also}:
3276@ref{omp_get_interop_int}, @ref{omp_get_interop_ptr}, @ref{omp_get_interop_rc_desc},
3277@ref{Offload-Target Specifics}
3278
3279@item @emph{Reference}:
3280@uref{https://www.openmp.org, OpenMP specification v5.1}, Section 3.12.4,
3281@uref{https://www.openmp.org, OpenMP specification v6.0}, Section 26.4
3282@end table
3283
3284
3285
3286@node omp_get_interop_name
3287@subsection @code{omp_get_interop_name} -- Obtain the name of an @code{interop_property} value as string
3288@table @asis
3289@item @emph{Description}:
3290The @code{omp_get_interop_name} function returns the name of the property
3291itself as string; for the properties specified by the OpenMP specification,
3292the name matches the name of the named constant with the @samp{omp_ipr_}
3293prefix removed.
3294
3295@c Implementation remark: In GCC, the Fortran interface differs from the one shown
3296@c below: @var{interop} and @var{property_id} are passed by value. This does not
3297@c affect the usage of the function when GCC's @code{omp_lib} module or
3298@c @code{omp_lib.h} header is used.
3299
3300@item @emph{C/C++}:
3301@multitable @columnfractions .20 .80
3302@item @emph{Prototype}: @tab @code{const char *omp_get_interop_name(const omp_interop_t interop,
3303 omp_interop_property_t property_id)}
3304@end multitable
3305
3306@item @emph{Fortran}:
3307@multitable @columnfractions .20 .80
3308@item @emph{Interface}: @tab @code{character(:) function omp_get_interop_name(interop,
3309 property_id)}
3310@item @tab @code{pointer :: omp_get_interop_name}
3311@item @tab @code{integer(omp_interop_kind), intent(in) :: interop}
3312@item @tab @code{integer(omp_interop_property_kind) property_id}
3313@end multitable
3314
3315@item @emph{See also}:
3316@ref{omp_get_num_interop_properties}, @ref{omp_get_interop_type_desc}
3317
3318@item @emph{Reference}:
3319@uref{https://www.openmp.org, OpenMP specification v5.1}, Section 3.12.5,
3320@uref{https://www.openmp.org, OpenMP specification v6.0}, Section 26.5
3321@end table
3322
3323
3324
3325@node omp_get_interop_type_desc
3326@subsection @code{omp_get_interop_type_desc} -- Obtain type and description to an @code{interop_property}
3327@table @asis
3328@item @emph{Description}:
3329The @code{omp_get_interop_type_desc} function returns a string that describes in
3330human-readable form the data type associated with the @var{property_id}
3331interoperability property of the passed @var{interop} object.
3332
3333In GCC, this function returns the name of the C/C++ data type for this property
3334or @samp{N/A} if this property is not available for the given foreign runtime.
3335If @var{interop} is @code{omp_interop_none} or for invalid property values,
3336a null pointer is returned. The effect of running this routine in a
3337@code{target} region that is not the initial device is unspecified.
3338
3339@c Implementation remark: In GCC, the Fortran interface differs from the one shown
3340@c below: @var{interop} and @var{property_id} are passed by value. This does not
3341@c affect the usage of the function when GCC's @code{omp_lib} module or
3342@c @code{omp_lib.h} header is used.
3343
3344@item @emph{C/C++}:
3345@multitable @columnfractions .20 .80
3346@item @emph{Prototype}: @tab @code{const char *omp_get_interop_type_desc(const omp_interop_t interop,
3347 omp_interop_property_t property_id)}
3348@end multitable
3349
3350@item @emph{Fortran}:
3351@multitable @columnfractions .20 .80
3352@item @emph{Interface}: @tab @code{character(:) function omp_get_interop_type_desc(interop,
3353 property_id)}
3354@item @tab @code{pointer :: omp_get_interop_type_desc}
3355@item @tab @code{integer(omp_interop_kind), intent(in) :: interop}
3356@item @tab @code{integer(omp_interop_property_kind) property_id}
3357@end multitable
3358
3359@item @emph{See also}:
3360@ref{omp_get_num_interop_properties}, @ref{omp_get_interop_name},
3361@ref{Offload-Target Specifics}
3362
3363@item @emph{Reference}:
3364@uref{https://www.openmp.org, OpenMP specification v5.1}, Section 3.12.6,
3365@uref{https://www.openmp.org, OpenMP specification v6.0}, Section 26.6
3366@end table
3367
3368
3369
3370@node omp_get_interop_rc_desc
3371@subsection @code{omp_get_interop_rc_desc} -- Obtain error string to an @code{interop_rc} error code
3372@table @asis
3373@item @emph{Description}:
3374The @code{omp_get_interop_rc_desc} function returns a string value describing
3375the @var{ret_code} in human-readable form.
3376
3377The behavior is unspecified if value of @var{ret_code} was not set by an
3378interoperability routine invoked for @var{interop}.
3379
3380GCC implements the OpenMP 6.0 version of this function for C and C++, which is not
3381compatible with its type signature in previous versions of the OpenMP specification.
3382In older versions, the type @code{int} was used for the @var{ret_code} argument
3383in place of the enumerated type @code{omp_interop_rc_t}.
3384
3385@item @emph{C/C++}:
3386@multitable @columnfractions .20 .80
3387@item @emph{Prototype}: @tab @code{const char *omp_get_interop_rc_desc(const omp_interop_t interop,
3388 omp_interop_rc_t ret_code)}
3389@end multitable
3390
3391@item @emph{Fortran}:
3392@multitable @columnfractions .20 .80
3393@item @emph{Interface}: @tab @code{character(:) function omp_get_interop_rc_desc(interop,
3394 property_id, ret_code)}
3395@item @tab @code{pointer :: omp_get_interop_rc_desc}
3396@item @tab @code{integer(omp_interop_kind), intent(in) :: interop}
3397@item @tab @code{integer (omp_interop_rc_kind) ret_code}
3398@end multitable
3399
3400@item @emph{Reference}:
3401@uref{https://www.openmp.org, OpenMP specification v5.1}, Section 3.12.7,
3402@uref{https://www.openmp.org, OpenMP specification v6.0}, Section 26.7
3403@end table
3404
3405
3406
3407@node Memory Management Routines
3408@section Memory Management Routines
3409
3410Routines to manage and allocate memory on the current device.
3411They have C linkage and do not throw exceptions.
3412
3413@menu
3414@c * omp_get_devices_memspace:: <fixme>/TR13
3415@c * omp_get_device_memspace:: <fixme>/TR13
3416@c * omp_get_devices_and_host_memspace:: <fixme>/TR13
3417@c * omp_get_device_and_host_memspace:: <fixme>/TR13
3418@c * omp_get_devices_all_memspace:: <fixme>/TR13
3419@c * omp_get_memspace_num_resources:: <fixme>/TR11
3420@c * omp_get_memspace_pagesize:: <fixme>/TR13
3421@c * omp_get_submemspace:: <fixme>/TR11
3422@c * omp_init_mempartitioner:: <fixme>/TR13
3423@c * omp_destroy_mempartitioner:: <fixme>/TR13
3424@c * omp_init_mempartition:: <fixme>/TR13
3425@c * omp_destroy_mempartition:: <fixme>/TR13
3426@c * omp_mempartition_set_part:: <fixme>/TR13
3427@c * omp_mempartition_get_user_data:: <fixme>/TR13
3428* omp_init_allocator:: Create an allocator
3429* omp_destroy_allocator:: Destroy an allocator
3430@c * omp_get_devices_allocator:: <fixme>/TR13
3431@c * omp_get_device_allocator:: <fixme>/TR13
3432@c * omp_get_devices_and_host_allocator:: <fixme>/TR13
3433@c * omp_get_device_and_host_allocator:: <fixme>/TR13
3434@c * omp_get_devices_all_allocator:: <fixme>/TR13
3435* omp_set_default_allocator:: Set the default allocator
3436* omp_get_default_allocator:: Get the default allocator
3437* omp_alloc:: Memory allocation with an allocator
3438* omp_aligned_alloc:: Memory allocation with an allocator and alignment
3439* omp_free:: Freeing memory allocated with OpenMP routines
3440* omp_calloc:: Allocate nullified memory with an allocator
3441* omp_aligned_calloc:: Allocate nullified aligned memory with an allocator
3442* omp_realloc:: Reallocate memory allocated with OpenMP routines
3443@end menu
3444
3445
3446
3447@node omp_init_allocator
3448@subsection @code{omp_init_allocator} -- Create an allocator
3449@table @asis
3450@item @emph{Description}:
3451Create an allocator that uses the specified memory space and has the specified
3452traits; if an allocator that fulfills the requirements cannot be created,
3453@code{omp_null_allocator} is returned.
3454
3455The predefined memory spaces and available traits can be found at
3456@ref{Memory allocation}, where the trait names have to be prefixed by
3457@code{omp_atk_} (e.g. @code{omp_atk_pinned}) and the named trait values by
3458@code{omp_atv_} (e.g. @code{omp_atv_true}); additionally, @code{omp_atv_default}
3459may be used as trait value to specify that the default value should be used.
3460
3461@item @emph{C/C++}:
3462@multitable @columnfractions .20 .80
3463@item @emph{Prototype}: @tab @code{omp_allocator_handle_t omp_init_allocator(}
3464@item @tab @code{ omp_memspace_handle_t memspace,}
3465@item @tab @code{ int ntraits,}
3466@item @tab @code{ const omp_alloctrait_t traits[]);}
3467@end multitable
3468
3469@item @emph{Fortran}:
3470@multitable @columnfractions .20 .80
3471@item @emph{Interface}: @tab @code{function omp_init_allocator(memspace, ntraits, traits)}
3472@item @tab @code{integer (omp_allocator_handle_kind) :: omp_init_allocator}
3473@item @tab @code{integer (omp_memspace_handle_kind), intent(in) :: memspace}
3474@item @tab @code{integer, intent(in) :: ntraits}
3475@item @tab @code{type (omp_alloctrait), intent(in) :: traits(*)}
3476@end multitable
3477
3478@item @emph{See also}:
3479@ref{Memory allocation}, @ref{OMP_ALLOCATOR}, @ref{omp_destroy_allocator}
3480
3481@item @emph{Reference}:
3482@uref{https://www.openmp.org, OpenMP specification v5.0}, Section 3.7.2
3483@end table
3484
3485
3486
3487@node omp_destroy_allocator
3488@subsection @code{omp_destroy_allocator} -- Destroy an allocator
3489@table @asis
3490@item @emph{Description}:
3491Releases all resources used by a memory allocator, which must not represent
3492a predefined memory allocator. Accessing memory after its allocator has been
3493destroyed has unspecified behavior. Passing @code{omp_null_allocator} to the
3494routine is permitted but has no effect.
3495
3496
3497@item @emph{C/C++}:
3498@multitable @columnfractions .20 .80
3499@item @emph{Prototype}: @tab @code{void omp_destroy_allocator (omp_allocator_handle_t allocator);}
3500@end multitable
3501
3502@item @emph{Fortran}:
3503@multitable @columnfractions .20 .80
3504@item @emph{Interface}: @tab @code{subroutine omp_destroy_allocator(allocator)}
3505@item @tab @code{integer (omp_allocator_handle_kind), intent(in) :: allocator}
3506@end multitable
3507
3508@item @emph{See also}:
3509@ref{omp_init_allocator}
3510
3511@item @emph{Reference}:
3512@uref{https://www.openmp.org, OpenMP specification v5.0}, Section 3.7.3
3513@end table
3514
3515
3516
3517@node omp_set_default_allocator
3518@subsection @code{omp_set_default_allocator} -- Set the default allocator
3519@table @asis
3520@item @emph{Description}:
3521Sets the default allocator that is used when no allocator has been specified
3522in the @code{allocate} or @code{allocator} clause or if an OpenMP memory
3523routine is invoked with the @code{omp_null_allocator} allocator.
3524
3525@item @emph{C/C++}:
3526@multitable @columnfractions .20 .80
3527@item @emph{Prototype}: @tab @code{void omp_set_default_allocator(omp_allocator_handle_t allocator);}
3528@end multitable
3529
3530@item @emph{Fortran}:
3531@multitable @columnfractions .20 .80
3532@item @emph{Interface}: @tab @code{subroutine omp_set_default_allocator(allocator)}
3533@item @tab @code{integer (omp_allocator_handle_kind), intent(in) :: allocator}
3534@end multitable
3535
3536@item @emph{See also}:
3537@ref{omp_get_default_allocator}, @ref{omp_init_allocator}, @ref{OMP_ALLOCATOR},
3538@ref{Memory allocation}
3539
3540@item @emph{Reference}:
3541@uref{https://www.openmp.org, OpenMP specification v5.0}, Section 3.7.4
3542@end table
3543
3544
3545
3546@node omp_get_default_allocator
3547@subsection @code{omp_get_default_allocator} -- Get the default allocator
3548@table @asis
3549@item @emph{Description}:
3550The routine returns the default allocator that is used when no allocator has
3551been specified in the @code{allocate} or @code{allocator} clause or if an
3552OpenMP memory routine is invoked with the @code{omp_null_allocator} allocator.
3553
3554@item @emph{C/C++}:
3555@multitable @columnfractions .20 .80
3556@item @emph{Prototype}: @tab @code{omp_allocator_handle_t omp_get_default_allocator();}
3557@end multitable
3558
3559@item @emph{Fortran}:
3560@multitable @columnfractions .20 .80
3561@item @emph{Interface}: @tab @code{function omp_get_default_allocator()}
3562@item @tab @code{integer (omp_allocator_handle_kind) :: omp_get_default_allocator}
3563@end multitable
3564
3565@item @emph{See also}:
3566@ref{omp_set_default_allocator}, @ref{OMP_ALLOCATOR}
3567
3568@item @emph{Reference}:
3569@uref{https://www.openmp.org, OpenMP specification v5.0}, Section 3.7.5
3570@end table
3571
3572
3573
3574@node omp_alloc
3575@subsection @code{omp_alloc} -- Memory allocation with an allocator
3576@table @asis
3577@item @emph{Description}:
3578Allocate memory with the specified allocator, which can either be a predefined
3579allocator, an allocator handle or @code{omp_null_allocator}. If the allocators
3580is @code{omp_null_allocator}, the allocator specified by the
3581@var{def-allocator-var} ICV is used. @var{size} must be a nonnegative number
3582denoting the number of bytes to be allocated; if @var{size} is zero,
3583@code{omp_alloc} will return a null pointer. If successful, a pointer to the
3584allocated memory is returned, otherwise the @code{fallback} trait of the
3585allocator determines the behavior. The content of the allocated memory is
3586unspecified.
3587
3588In @code{target} regions, either the @code{dynamic_allocators} clause must
3589appear on a @code{requires} directive in the same compilation unit -- or the
3590@var{allocator} argument may only be a constant expression with the value of
3591one of the predefined allocators and may not be @code{omp_null_allocator}.
3592
3593Memory allocated by @code{omp_alloc} must be freed using @code{omp_free}.
3594
3595@item @emph{C}:
3596@multitable @columnfractions .20 .80
3597@item @emph{Prototype}: @tab @code{void* omp_alloc(size_t size,}
3598@item @tab @code{ omp_allocator_handle_t allocator)}
3599@end multitable
3600
3601@item @emph{C++}:
3602@multitable @columnfractions .20 .80
3603@item @emph{Prototype}: @tab @code{void* omp_alloc(size_t size,}
3604@item @tab @code{ omp_allocator_handle_t allocator=omp_null_allocator)}
3605@end multitable
3606
3607@item @emph{Fortran}:
3608@multitable @columnfractions .20 .80
3609@item @emph{Interface}: @tab @code{type(c_ptr) function omp_alloc(size, allocator) bind(C)}
3610@item @tab @code{use, intrinsic :: iso_c_binding, only : c_ptr, c_size_t}
3611@item @tab @code{integer (c_size_t), value :: size}
3612@item @tab @code{integer (omp_allocator_handle_kind), value :: allocator}
3613@end multitable
3614
3615@item @emph{See also}:
3616@ref{OMP_ALLOCATOR}, @ref{Memory allocation}, @ref{omp_set_default_allocator},
3617@ref{omp_free}, @ref{omp_init_allocator}
3618
3619@item @emph{Reference}:
3620@uref{https://www.openmp.org, OpenMP specification v5.0}, Section 3.7.6
3621@end table
3622
3623
3624
3625@node omp_aligned_alloc
3626@subsection @code{omp_aligned_alloc} -- Memory allocation with an allocator and alignment
3627@table @asis
3628@item @emph{Description}:
3629Allocate memory with the specified allocator, which can either be a predefined
3630allocator, an allocator handle or @code{omp_null_allocator}. If the allocators
3631is @code{omp_null_allocator}, the allocator specified by the
3632@var{def-allocator-var} ICV is used. @var{alignment} must be a positive power
3633of two and @var{size} must be a nonnegative number that is a multiple of the
3634alignment and denotes the number of bytes to be allocated; if @var{size} is
3635zero, @code{omp_aligned_alloc} will return a null pointer. The alignment will
3636be at least the maximal value required by @code{alignment} trait of the
3637allocator and the value of the passed @var{alignment} argument. If successful,
3638a pointer to the allocated memory is returned, otherwise the @code{fallback}
3639trait of the allocator determines the behavior. The content of the allocated
3640memory is unspecified.
3641
3642In @code{target} regions, either the @code{dynamic_allocators} clause must
3643appear on a @code{requires} directive in the same compilation unit -- or the
3644@var{allocator} argument may only be a constant expression with the value of
3645one of the predefined allocators and may not be @code{omp_null_allocator}.
3646
3647Memory allocated by @code{omp_aligned_alloc} must be freed using
3648@code{omp_free}.
3649
3650@item @emph{C}:
3651@multitable @columnfractions .20 .80
3652@item @emph{Prototype}: @tab @code{void* omp_aligned_alloc(size_t alignment,}
3653@item @tab @code{ size_t size,}
3654@item @tab @code{ omp_allocator_handle_t allocator)}
3655@end multitable
3656
3657@item @emph{C++}:
3658@multitable @columnfractions .20 .80
3659@item @emph{Prototype}: @tab @code{void* omp_aligned_alloc(size_t alignment,}
3660@item @tab @code{ size_t size,}
3661@item @tab @code{ omp_allocator_handle_t allocator=omp_null_allocator)}
3662@end multitable
3663
3664@item @emph{Fortran}:
3665@multitable @columnfractions .20 .80
3666@item @emph{Interface}: @tab @code{type(c_ptr) function omp_aligned_alloc(alignment, size, allocator) bind(C)}
3667@item @tab @code{use, intrinsic :: iso_c_binding, only : c_ptr, c_size_t}
3668@item @tab @code{integer (c_size_t), value :: alignment, size}
3669@item @tab @code{integer (omp_allocator_handle_kind), value :: allocator}
3670@end multitable
3671
3672@item @emph{See also}:
3673@ref{OMP_ALLOCATOR}, @ref{Memory allocation}, @ref{omp_set_default_allocator},
3674@ref{omp_free}, @ref{omp_init_allocator}
3675
3676@item @emph{Reference}:
3677@uref{https://www.openmp.org, OpenMP specification v5.1}, Section 3.13.6
3678@end table
3679
3680
3681
3682@node omp_free
3683@subsection @code{omp_free} -- Freeing memory allocated with OpenMP routines
3684@table @asis
3685@item @emph{Description}:
3686The @code{omp_free} routine deallocates memory previously allocated by an
3687OpenMP memory-management routine. The @var{ptr} argument must point to such
3688memory or be a null pointer; if it is a null pointer, no operation is
3689performed. If specified, the @var{allocator} argument must be either the
3690memory allocator that was used for the allocation or @code{omp_null_allocator};
3691if it is @code{omp_null_allocator}, the implementation will determine the value
3692automatically.
3693
3694Calling @code{omp_free} invokes undefined behavior if the memory
3695was already deallocated or when the used allocator has already been destroyed.
3696
3697@item @emph{C}:
3698@multitable @columnfractions .20 .80
3699@item @emph{Prototype}: @tab @code{void omp_free(void *ptr,}
3700@item @tab @code{ omp_allocator_handle_t allocator)}
3701@end multitable
3702
3703@item @emph{C++}:
3704@multitable @columnfractions .20 .80
3705@item @emph{Prototype}: @tab @code{void omp_free(void *ptr,}
3706@item @tab @code{ omp_allocator_handle_t allocator=omp_null_allocator)}
3707@end multitable
3708
3709@item @emph{Fortran}:
3710@multitable @columnfractions .20 .80
3711@item @emph{Interface}: @tab @code{subroutine omp_free(ptr, allocator) bind(C)}
3712@item @tab @code{use, intrinsic :: iso_c_binding, only : c_ptr}
3713@item @tab @code{type (c_ptr), value :: ptr}
3714@item @tab @code{integer (omp_allocator_handle_kind), value :: allocator}
3715@end multitable
3716
3717@item @emph{See also}:
3718@ref{omp_alloc}, @ref{omp_aligned_alloc}, @ref{omp_calloc},
3719@ref{omp_aligned_calloc}, @ref{omp_realloc}
3720
3721@item @emph{Reference}:
3722@uref{https://www.openmp.org, OpenMP specification v5.0}, Section 3.7.7
3723@end table
3724
3725
3726
3727@node omp_calloc
3728@subsection @code{omp_calloc} -- Allocate nullified memory with an allocator
3729@table @asis
3730@item @emph{Description}:
3731Allocate zero-initialized memory with the specified allocator, which can either
3732be a predefined allocator, an allocator handle or @code{omp_null_allocator}. If
3733the allocators is @code{omp_null_allocator}, the allocator specified by the
3734@var{def-allocator-var} ICV is used. The to-be allocated memory is for an
3735array with @var{nmemb} elements, each having a size of @var{size} bytes. Both
3736@var{nmemb} and @var{size} must be nonnegative numbers; if either of them is
3737zero, @code{omp_calloc} will return a null pointer. If successful, a pointer to
3738the zero-initialized allocated memory is returned, otherwise the @code{fallback}
3739trait of the allocator determines the behavior.
3740
3741In @code{target} regions, either the @code{dynamic_allocators} clause must
3742appear on a @code{requires} directive in the same compilation unit -- or the
3743@var{allocator} argument may only be a constant expression with the value of
3744one of the predefined allocators and may not be @code{omp_null_allocator}.
3745
3746Memory allocated by @code{omp_calloc} must be freed using @code{omp_free}.
3747
3748@item @emph{C}:
3749@multitable @columnfractions .20 .80
3750@item @emph{Prototype}: @tab @code{void* omp_calloc(size_t nmemb, size_t size,}
3751@item @tab @code{ omp_allocator_handle_t allocator)}
3752@end multitable
3753
3754@item @emph{C++}:
3755@multitable @columnfractions .20 .80
3756@item @emph{Prototype}: @tab @code{void* omp_calloc(size_t nmemb, size_t size,}
3757@item @tab @code{ omp_allocator_handle_t allocator=omp_null_allocator)}
3758@end multitable
3759
3760@item @emph{Fortran}:
3761@multitable @columnfractions .20 .80
3762@item @emph{Interface}: @tab @code{type(c_ptr) function omp_calloc(nmemb, size, allocator) bind(C)}
3763@item @tab @code{use, intrinsic :: iso_c_binding, only : c_ptr, c_size_t}
3764@item @tab @code{integer (c_size_t), value :: nmemb, size}
3765@item @tab @code{integer (omp_allocator_handle_kind), value :: allocator}
3766@end multitable
3767
3768@item @emph{See also}:
3769@ref{OMP_ALLOCATOR}, @ref{Memory allocation}, @ref{omp_set_default_allocator},
3770@ref{omp_free}, @ref{omp_init_allocator}
3771
3772@item @emph{Reference}:
3773@uref{https://www.openmp.org, OpenMP specification v5.1}, Section 3.13.8
3774@end table
3775
3776
3777
3778@node omp_aligned_calloc
3779@subsection @code{omp_aligned_calloc} -- Allocate aligned nullified memory with an allocator
3780@table @asis
3781@item @emph{Description}:
3782Allocate zero-initialized memory with the specified allocator, which can either
3783be a predefined allocator, an allocator handle or @code{omp_null_allocator}. If
3784the allocators is @code{omp_null_allocator}, the allocator specified by the
3785@var{def-allocator-var} ICV is used. The to-be allocated memory is for an
3786array with @var{nmemb} elements, each having a size of @var{size} bytes. Both
3787@var{nmemb} and @var{size} must be nonnegative numbers; if either of them is
3788zero, @code{omp_aligned_calloc} will return a null pointer. @var{alignment}
3789must be a positive power of two and @var{size} must be a multiple of the
3790alignment; the alignment will be at least the maximal value required by
3791@code{alignment} trait of the allocator and the value of the passed
3792@var{alignment} argument. If successful, a pointer to the zero-initialized
3793allocated memory is returned, otherwise the @code{fallback} trait of the
3794allocator determines the behavior.
3795
3796In @code{target} regions, either the @code{dynamic_allocators} clause must
3797appear on a @code{requires} directive in the same compilation unit -- or the
3798@var{allocator} argument may only be a constant expression with the value of
3799one of the predefined allocators and may not be @code{omp_null_allocator}.
3800
3801Memory allocated by @code{omp_aligned_calloc} must be freed using
3802@code{omp_free}.
3803
3804@item @emph{C}:
3805@multitable @columnfractions .20 .80
3806@item @emph{Prototype}: @tab @code{void* omp_aligned_calloc(size_t nmemb, size_t size,}
3807@item @tab @code{ omp_allocator_handle_t allocator)}
3808@end multitable
3809
3810@item @emph{C++}:
3811@multitable @columnfractions .20 .80
3812@item @emph{Prototype}: @tab @code{void* omp_aligned_calloc(size_t nmemb, size_t size,}
3813@item @tab @code{ omp_allocator_handle_t allocator=omp_null_allocator)}
3814@end multitable
3815
3816@item @emph{Fortran}:
3817@multitable @columnfractions .20 .80
3818@item @emph{Interface}: @tab @code{type(c_ptr) function omp_aligned_calloc(nmemb, size, allocator) bind(C)}
3819@item @tab @code{use, intrinsic :: iso_c_binding, only : c_ptr, c_size_t}
3820@item @tab @code{integer (c_size_t), value :: nmemb, size}
3821@item @tab @code{integer (omp_allocator_handle_kind), value :: allocator}
3822@end multitable
3823
3824@item @emph{See also}:
3825@ref{OMP_ALLOCATOR}, @ref{Memory allocation}, @ref{omp_set_default_allocator},
3826@ref{omp_free}, @ref{omp_init_allocator}
3827
3828@item @emph{Reference}:
3829@uref{https://www.openmp.org, OpenMP specification v5.1}, Section 3.13.8
3830@end table
3831
3832
3833
3834@node omp_realloc
3835@subsection @code{omp_realloc} -- Reallocate memory allocated with OpenMP routines
3836@table @asis
3837@item @emph{Description}:
3838The @code{omp_realloc} routine deallocates memory to which @var{ptr} points to
3839and allocates new memory with the specified @var{allocator} argument; the
3840new memory will have the content of the old memory up to the minimum of the
3841old size and the new @var{size}, otherwise the content of the returned memory
3842is unspecified. If the new allocator is the same as the old one, the routine
3843tries to resize the existing memory allocation, returning the same address as
3844@var{ptr} if successful. @var{ptr} must point to memory allocated by an OpenMP
3845memory-management routine.
3846
3847The @var{allocator} and @var{free_allocator} arguments must be a predefined
3848allocator, an allocator handle or @code{omp_null_allocator}. If
3849@var{free_allocator} is @code{omp_null_allocator}, the implementation
3850automatically determines the allocator used for the allocation of @var{ptr}.
3851If @var{allocator} is @code{omp_null_allocator} and @var{ptr} is not a
3852null pointer, the same allocator as @code{free_allocator} is used and
3853when @var{ptr} is a null pointer the allocator specified by the
3854@var{def-allocator-var} ICV is used.
3855
3856The @var{size} must be a nonnegative number denoting the number of bytes to be
3857allocated; if @var{size} is zero, @code{omp_realloc} will return free the
3858memory and return a null pointer. When @var{size} is nonzero: if successful,
3859a pointer to the allocated memory is returned, otherwise the @code{fallback}
3860trait of the allocator determines the behavior.
3861
3862In @code{target} regions, either the @code{dynamic_allocators} clause must
3863appear on a @code{requires} directive in the same compilation unit -- or the
3864@var{free_allocator} and @var{allocator} arguments may only be a constant
3865expression with the value of one of the predefined allocators and may not be
3866@code{omp_null_allocator}.
3867
3868Memory allocated by @code{omp_realloc} must be freed using @code{omp_free}.
3869Calling @code{omp_free} invokes undefined behavior if the memory
3870was already deallocated or when the used allocator has already been destroyed.
3871
3872@item @emph{C}:
3873@multitable @columnfractions .20 .80
3874@item @emph{Prototype}: @tab @code{void* omp_realloc(void *ptr, size_t size,}
3875@item @tab @code{ omp_allocator_handle_t allocator,}
3876@item @tab @code{ omp_allocator_handle_t free_allocator)}
3877@end multitable
3878
3879@item @emph{C++}:
3880@multitable @columnfractions .20 .80
3881@item @emph{Prototype}: @tab @code{void* omp_realloc(void *ptr, size_t size,}
3882@item @tab @code{ omp_allocator_handle_t allocator=omp_null_allocator,}
3883@item @tab @code{ omp_allocator_handle_t free_allocator=omp_null_allocator)}
3884@end multitable
3885
3886@item @emph{Fortran}:
3887@multitable @columnfractions .20 .80
3888@item @emph{Interface}: @tab @code{type(c_ptr) function omp_realloc(ptr, size, allocator, free_allocator) bind(C)}
3889@item @tab @code{use, intrinsic :: iso_c_binding, only : c_ptr, c_size_t}
3890@item @tab @code{type(C_ptr), value :: ptr}
3891@item @tab @code{integer (c_size_t), value :: size}
3892@item @tab @code{integer (omp_allocator_handle_kind), value :: allocator, free_allocator}
3893@end multitable
3894
3895@item @emph{See also}:
3896@ref{OMP_ALLOCATOR}, @ref{Memory allocation}, @ref{omp_set_default_allocator},
3897@ref{omp_free}, @ref{omp_init_allocator}
3898
3899@item @emph{Reference}:
3900@uref{https://www.openmp.org, OpenMP specification v5.0}, Section 3.7.9
3901@end table
3902
3903
3904
3905@c @node Tool Control Routine
3906@c @section Tool Control Routine
3907@c
3908@c FIXME
3909
3910@node Environment Display Routine
3911@section Environment Display Routine
3912
3913Routine to display the OpenMP version number and the initial value of ICVs.
3914It has C linkage and does not throw exceptions.
3915
3916@menu
3917* omp_display_env:: print the initial ICV values
3918@end menu
3919
3920@node omp_display_env
3921@subsection @code{omp_display_env} -- print the initial ICV values
3922@table @asis
3923@item @emph{Description}:
3924Each time this routine is invoked, the OpenMP version number and initial value
3925of internal control variables (ICVs) is printed on @code{stderr}. The displayed
3926values are those at startup after evaluating the environment variables; later
3927calls to API routines or clauses used in enclosing constructs do not affect
3928the output.
3929
3930If the @var{verbose} argument is @code{false}, only the OpenMP version and
3931standard OpenMP ICVs are shown; if it is @code{true}, additionally, the
3932GCC-specific ICVs are shown.
3933
3934The output consists of multiple lines and starts with
3935@samp{OPENMP DISPLAY ENVIRONMENT BEGIN} followed by the name-value lines and
3936ends with @samp{OPENMP DISPLAY ENVIRONMENT END}. The @var{name} is followed by
3937an equal sign and the @var{value} is enclosed in single quotes.
3938
3939The first line has as @var{name} either @samp{_OPENMP} or @samp{openmp_version}
3940and shows as value the supported OpenMP version number (4-digit year, 2-digit
3941month) of the implementation, matching the value of the @code{_OPENMP} macro
3942and, in Fortran, the named constant @code{openmp_version}.
3943
3944In each of the succeeding lines, the @var{name} matches the environment-variable
3945name of an ICV and shows its value. Those line are might be prefixed by pair of
3946brackets and a space, where the brackets enclose a comma-separated list of
3947devices to which the ICV-value combination applies to; the value can either be a
3948numeric device number or an abstract name denoting all devices (@code{all}), the
3949initial host device (@code{host}) or all devices but the host (@code{device}).
3950Note that the same ICV might be printed multiple times for multiple devices,
3951even if all have the same value.
3952
3953The effect when invoked from within a @code{target} region is unspecified.
3954
3955@item @emph{C/C++}:
3956@multitable @columnfractions .20 .80
3957@item @emph{Prototype}: @tab @code{void omp_display_env(int verbose)}
3958@end multitable
3959
3960@item @emph{Fortran}:
3961@multitable @columnfractions .20 .80
3962@item @emph{Interface}: @tab @code{subroutine omp_display_env(verbose)}
3963@item @tab @code{logical, intent(in) :: verbose}
3964@end multitable
3965
3966@item @emph{Example}:
3967Note that the GCC-specific ICVs, such as the shown @code{GOMP_SPINCOUNT},
3968are only printed when @var{verbose} set to @code{true}.
3969
3970@smallexample
3971OPENMP DISPLAY ENVIRONMENT BEGIN
3972 _OPENMP = '201511'
3973 [host] OMP_DYNAMIC = 'FALSE'
3974 [host] OMP_NESTED = 'FALSE'
3975 [all] OMP_CANCELLATION = 'FALSE'
3976 ...
3977 [host] GOMP_SPINCOUNT = '300000'
3978OPENMP DISPLAY ENVIRONMENT END
3979@end smallexample
3980
3981
3982@item @emph{See also}:
3983@ref{OMP_DISPLAY_ENV}, @ref{Environment Variables},
3984@ref{Implementation-defined ICV Initialization}
3985
3986@item @emph{Reference}:
3987@uref{https://www.openmp.org, OpenMP specification v5.1}, Section 3.15
3988@end table
3989
3990
3991@c ---------------------------------------------------------------------
3992@c OpenMP Environment Variables
3993@c ---------------------------------------------------------------------
3994
3995@node Environment Variables
3996@chapter OpenMP Environment Variables
3997
3998The environment variables which beginning with @env{OMP_} are defined by
3999section 4 of the OpenMP specification in version 4.5 or in a later version
4000of the specification, while those beginning with @env{GOMP_} are GNU extensions.
4001Most @env{OMP_} environment variables have an associated internal control
4002variable (ICV).
4003
4004For any OpenMP environment variable that sets an ICV and is neither
4005@code{OMP_DEFAULT_DEVICE} nor has global ICV scope, associated
4006device-specific environment variables exist. For them, the environment
4007variable without suffix affects the host. The suffix @code{_DEV_} followed
4008by a non-negative device number less that the number of available devices sets
4009the ICV for the corresponding device. The suffix @code{_DEV} sets the ICV
4010of all non-host devices for which a device-specific corresponding environment
4011variable has not been set while the @code{_ALL} suffix sets the ICV of all
4012host and non-host devices for which a more specific corresponding environment
4013variable is not set.
4014
4015@menu
4016* OMP_ALLOCATOR:: Set the default allocator
4017* OMP_AFFINITY_FORMAT:: Set the format string used for affinity display
4018* OMP_CANCELLATION:: Set whether cancellation is activated
4019* OMP_DISPLAY_AFFINITY:: Display thread affinity information
4020* OMP_DISPLAY_ENV:: Show OpenMP version and environment variables
4021* OMP_DEFAULT_DEVICE:: Set the device used in target regions
4022* OMP_DYNAMIC:: Dynamic adjustment of threads
4023* OMP_MAX_ACTIVE_LEVELS:: Set the maximum number of nested parallel regions
4024* OMP_MAX_TASK_PRIORITY:: Set the maximum task priority value
4025* OMP_NESTED:: Nested parallel regions
4026* OMP_NUM_TEAMS:: Specifies the number of teams to use by teams region
4027* OMP_NUM_THREADS:: Specifies the number of threads to use
4028* OMP_PROC_BIND:: Whether threads may be moved between CPUs
4029* OMP_PLACES:: Specifies on which CPUs the threads should be placed
4030* OMP_STACKSIZE:: Set default thread stack size
4031* OMP_SCHEDULE:: How threads are scheduled
4032* OMP_TARGET_OFFLOAD:: Controls offloading behavior
4033* OMP_TEAMS_THREAD_LIMIT:: Set the maximum number of threads imposed by teams
4034* OMP_THREAD_LIMIT:: Set the maximum number of threads
4035* OMP_WAIT_POLICY:: How waiting threads are handled
4036* GOMP_CPU_AFFINITY:: Bind threads to specific CPUs
4037* GOMP_DEBUG:: Enable debugging output
4038* GOMP_STACKSIZE:: Set default thread stack size
4039* GOMP_SPINCOUNT:: Set the busy-wait spin count
4040* GOMP_RTEMS_THREAD_POOLS:: Set the RTEMS specific thread pools
4041@end menu
4042
4043
4044@node OMP_ALLOCATOR
4045@section @env{OMP_ALLOCATOR} -- Set the default allocator
4046@cindex Environment Variable
4047@table @asis
4048@item @emph{ICV:} @var{def-allocator-var}
4049@item @emph{Scope:} data environment
4050@item @emph{Description}:
4051Sets the default allocator that is used when no allocator has been specified
4052in the @code{allocate} or @code{allocator} clause or if an OpenMP memory
4053routine is invoked with the @code{omp_null_allocator} allocator.
4054If unset, @code{omp_default_mem_alloc} is used.
4055
4056The value can either be a predefined allocator or a predefined memory space
4057or a predefined memory space followed by a colon and a comma-separated list
4058of memory trait and value pairs, separated by @code{=}.
4059
4060See @ref{Memory allocation} for a list of supported prefedined allocators,
4061memory spaces, and traits.
4062
4063Note: The corresponding device environment variables are currently not
4064supported. Therefore, the non-host @var{def-allocator-var} ICVs are always
4065initialized to @code{omp_default_mem_alloc}. However, on all devices,
4066the @code{omp_set_default_allocator} API routine can be used to change
4067value.
4068
4069Examples:
4070@smallexample
4071OMP_ALLOCATOR=omp_high_bw_mem_alloc
4072OMP_ALLOCATOR=omp_large_cap_mem_space
4073OMP_ALLOCATOR=omp_low_lat_mem_space:pinned=true,partition=nearest
4074@end smallexample
4075
4076@item @emph{See also}:
4077@ref{Memory allocation}, @ref{omp_get_default_allocator},
4078@ref{omp_set_default_allocator}, @ref{Offload-Target Specifics}
4079
4080@item @emph{Reference}:
4081@uref{https://www.openmp.org, OpenMP specification v5.0}, Section 6.21
4082@end table
4083
4084
4085
4086@node OMP_AFFINITY_FORMAT
4087@section @env{OMP_AFFINITY_FORMAT} -- Set the format string used for affinity display
4088@cindex Environment Variable
4089@table @asis
4090@item @emph{ICV:} @var{affinity-format-var}
4091@item @emph{Scope:} device
4092@item @emph{Description}:
4093Sets the format string used when displaying OpenMP thread affinity information.
4094Special values are output using @code{%} followed by an optional size
4095specification and then either the single-character field type or its long
4096name enclosed in curly braces; using @code{%%} displays a literal percent.
4097The size specification consists of an optional @code{0.} or @code{.} followed
4098by a positive integer, specifying the minimal width of the output. With
4099@code{0.} and numerical values, the output is padded with zeros on the left;
4100with @code{.}, the output is padded by spaces on the left; otherwise, the
4101output is padded by spaces on the right. If unset, the value is
4102``@code{level %L thread %i affinity %A}''.
4103
4104Supported field types are:
4105
4106@multitable @columnfractions .10 .25 .60
4107@item t @tab team_num @tab value returned by @code{omp_get_team_num}
4108@item T @tab num_teams @tab value returned by @code{omp_get_num_teams}
4109@item L @tab nesting_level @tab value returned by @code{omp_get_level}
4110@item n @tab thread_num @tab value returned by @code{omp_get_thread_num}
4111@item N @tab num_threads @tab value returned by @code{omp_get_num_threads}
4112@item a @tab ancestor_tnum
4113 @tab value returned by
4114 @code{omp_get_ancestor_thread_num(omp_get_level()-1)}
4115@item H @tab host @tab name of the host that executes the thread
4116@item P @tab process_id @tab process identifier
4117@item i @tab native_thread_id @tab native thread identifier
4118@item A @tab thread_affinity
4119 @tab comma separated list of integer values or ranges, representing the
4120 processors on which a process might execute, subject to affinity
4121 mechanisms
4122@end multitable
4123
4124For instance, after setting
4125
4126@smallexample
4127OMP_AFFINITY_FORMAT="%0.2a!%n!%.4L!%N;%.2t;%0.2T;%@{team_num@};%@{num_teams@};%A"
4128@end smallexample
4129
4130with either @code{OMP_DISPLAY_AFFINITY} being set or when calling
4131@code{omp_display_affinity} with @code{NULL} or an empty string, the program
4132might display the following:
4133
4134@smallexample
413500!0! 1!4; 0;01;0;1;0-11
413600!3! 1!4; 0;01;0;1;0-11
413700!2! 1!4; 0;01;0;1;0-11
413800!1! 1!4; 0;01;0;1;0-11
4139@end smallexample
4140
4141@item @emph{See also}:
4142@ref{OMP_DISPLAY_AFFINITY}
4143
4144@item @emph{Reference}:
4145@uref{https://www.openmp.org, OpenMP specification v5.0}, Section 6.14
4146@end table
4147
4148
4149
4150@node OMP_CANCELLATION
4151@section @env{OMP_CANCELLATION} -- Set whether cancellation is activated
4152@cindex Environment Variable
4153@table @asis
4154@item @emph{ICV:} @var{cancel-var}
4155@item @emph{Scope:} global
4156@item @emph{Description}:
4157If set to @code{TRUE}, the cancellation is activated. If set to @code{FALSE} or
4158if unset, cancellation is disabled and the @code{cancel} construct is ignored.
4159
4160@item @emph{See also}:
4161@ref{omp_get_cancellation}
4162
4163@item @emph{Reference}:
4164@uref{https://www.openmp.org, OpenMP specification v4.5}, Section 4.11
4165@end table
4166
4167
4168
4169@node OMP_DISPLAY_AFFINITY
4170@section @env{OMP_DISPLAY_AFFINITY} -- Display thread affinity information
4171@cindex Environment Variable
4172@table @asis
4173@item @emph{ICV:} @var{display-affinity-var}
4174@item @emph{Scope:} global
4175@item @emph{Description}:
4176If set to @code{FALSE} or if unset, affinity displaying is disabled.
4177If set to @code{TRUE}, the runtime displays affinity information about
4178OpenMP threads in a parallel region upon entering the region and every time
4179any change occurs.
4180
4181@item @emph{See also}:
4182@ref{OMP_AFFINITY_FORMAT}
4183
4184@item @emph{Reference}:
4185@uref{https://www.openmp.org, OpenMP specification v5.0}, Section 6.13
4186@end table
4187
4188
4189
4190
4191@node OMP_DISPLAY_ENV
4192@section @env{OMP_DISPLAY_ENV} -- Show OpenMP version and environment variables
4193@cindex Environment Variable
4194@table @asis
4195@item @emph{ICV:} none
4196@item @emph{Scope:} not applicable
4197@item @emph{Description}:
4198If set to @code{TRUE}, the runtime displays the same information to
4199@code{stderr} as shown by the @code{omp_display_env} routine invoked with
4200@var{verbose} argument set to @code{false}. If set to @code{VERBOSE}, the same
4201information is shown as invoking the routine with @var{verbose} set to
4202@code{true}. If unset or set to @code{FALSE}, this information is not shown.
4203The result for any other value is unspecified.
4204
4205@item @emph{See also}:
4206@ref{omp_display_env}
4207
4208@item @emph{Reference}:
4209@uref{https://www.openmp.org, OpenMP specification v4.5}, Section 4.12
4210@end table
4211
4212
4213
4214@node OMP_DEFAULT_DEVICE
4215@section @env{OMP_DEFAULT_DEVICE} -- Set the device used in target regions
4216@cindex Environment Variable
4217@table @asis
4218@item @emph{ICV:} @var{default-device-var}
4219@item @emph{Scope:} data environment
4220@item @emph{Description}:
4221Set to choose the device which is used in a @code{target} region, unless the
4222value is overridden by @code{omp_set_default_device} or by a @code{device}
4223clause. The value shall be the nonnegative device number. If no device with
4224the given device number exists, the code is executed on the host. If unset,
4225@env{OMP_TARGET_OFFLOAD} is @code{mandatory} and no non-host devices are
4226available, it is set to @code{omp_invalid_device}. Otherwise, if unset,
4227device number 0 is used.
4228
4229
4230@item @emph{See also}:
4231@ref{omp_get_default_device}, @ref{omp_set_default_device},
4232@ref{OMP_TARGET_OFFLOAD}
4233
4234@item @emph{Reference}:
4235@uref{https://www.openmp.org, OpenMP specification v5.2}, Section 21.2.7
4236@end table
4237
4238
4239
4240@node OMP_DYNAMIC
4241@section @env{OMP_DYNAMIC} -- Dynamic adjustment of threads
4242@cindex Environment Variable
4243@table @asis
4244@item @emph{ICV:} @var{dyn-var}
4245@item @emph{Scope:} global
4246@item @emph{Description}:
4247Enable or disable the dynamic adjustment of the number of threads
4248within a team. The value of this environment variable shall be
4249@code{TRUE} or @code{FALSE}. If undefined, dynamic adjustment is
4250disabled by default.
4251
4252@item @emph{See also}:
4253@ref{omp_set_dynamic}
4254
4255@item @emph{Reference}:
4256@uref{https://www.openmp.org, OpenMP specification v4.5}, Section 4.3
4257@end table
4258
4259
4260
4261@node OMP_MAX_ACTIVE_LEVELS
4262@section @env{OMP_MAX_ACTIVE_LEVELS} -- Set the maximum number of nested parallel regions
4263@cindex Environment Variable
4264@table @asis
4265@item @emph{ICV:} @var{max-active-levels-var}
4266@item @emph{Scope:} data environment
4267@item @emph{Description}:
4268Specifies the initial value for the maximum number of nested parallel
4269regions. The value of this variable shall be a positive integer.
4270If undefined, then if @env{OMP_NESTED} is defined and set to true, or
4271if @env{OMP_NUM_THREADS} or @env{OMP_PROC_BIND} are defined and set to
4272a list with more than one item, the maximum number of nested parallel
4273regions is initialized to the largest number supported, otherwise
4274it is set to one.
4275
4276@item @emph{See also}:
4277@ref{omp_set_max_active_levels}, @ref{OMP_NESTED}, @ref{OMP_PROC_BIND},
4278@ref{OMP_NUM_THREADS}
4279
4280
4281@item @emph{Reference}:
4282@uref{https://www.openmp.org, OpenMP specification v4.5}, Section 4.9
4283@end table
4284
4285
4286
4287@node OMP_MAX_TASK_PRIORITY
4288@section @env{OMP_MAX_TASK_PRIORITY} -- Set the maximum priority
4289number that can be set for a task.
4290@cindex Environment Variable
4291@table @asis
4292@item @emph{ICV:} @var{max-task-priority-var}
4293@item @emph{Scope:} global
4294@item @emph{Description}:
4295Specifies the initial value for the maximum priority value that can be
4296set for a task. The value of this variable shall be a non-negative
4297integer, and zero is allowed. If undefined, the default priority is
42980.
4299
4300@item @emph{See also}:
4301@ref{omp_get_max_task_priority}
4302
4303@item @emph{Reference}:
4304@uref{https://www.openmp.org, OpenMP specification v4.5}, Section 4.14
4305@end table
4306
4307
4308
4309@node OMP_NESTED
4310@section @env{OMP_NESTED} -- Nested parallel regions
4311@cindex Environment Variable
4312@cindex Implementation specific setting
4313@table @asis
4314@item @emph{ICV:} @var{max-active-levels-var}
4315@item @emph{Scope:} data environment
4316@item @emph{Description}:
4317Enable or disable nested parallel regions, i.e., whether team members
4318are allowed to create new teams. The value of this environment variable
4319shall be @code{TRUE} or @code{FALSE}. If set to @code{TRUE}, the number
4320of maximum active nested regions supported is by default set to the
4321maximum supported, otherwise it is set to one. If
4322@env{OMP_MAX_ACTIVE_LEVELS} is defined, its setting overrides this
4323setting. If both are undefined, nested parallel regions are enabled if
4324@env{OMP_NUM_THREADS} or @env{OMP_PROC_BINDS} are defined to a list with
4325more than one item, otherwise they are disabled by default.
4326
4327Note that the @code{OMP_NESTED} environment variable was deprecated in
4328the OpenMP specification 5.0 in favor of @code{OMP_MAX_ACTIVE_LEVELS}.
4329
4330@item @emph{See also}:
4331@ref{omp_set_max_active_levels}, @ref{omp_set_nested},
4332@ref{OMP_MAX_ACTIVE_LEVELS}
4333
4334@item @emph{Reference}:
4335@uref{https://www.openmp.org, OpenMP specification v4.5}, Section 4.6
4336@end table
4337
4338
4339
4340@node OMP_NUM_TEAMS
4341@section @env{OMP_NUM_TEAMS} -- Specifies the number of teams to use by teams region
4342@cindex Environment Variable
4343@table @asis
4344@item @emph{ICV:} @var{nteams-var}
4345@item @emph{Scope:} device
4346@item @emph{Description}:
4347Specifies the upper bound for number of teams to use in teams regions
4348without explicit @code{num_teams} clause. The value of this variable shall
4349be a positive integer. If undefined it defaults to 0 which means
4350implementation defined upper bound.
4351
4352@item @emph{See also}:
4353@ref{omp_set_num_teams}
4354
4355@item @emph{Reference}:
4356@uref{https://www.openmp.org, OpenMP specification v5.1}, Section 6.23
4357@end table
4358
4359
4360
4361@node OMP_NUM_THREADS
4362@section @env{OMP_NUM_THREADS} -- Specifies the number of threads to use
4363@cindex Environment Variable
4364@cindex Implementation specific setting
4365@table @asis
4366@item @emph{ICV:} @var{nthreads-var}
4367@item @emph{Scope:} data environment
4368@item @emph{Description}:
4369Specifies the default number of threads to use in parallel regions. The
4370value of this variable shall be a comma-separated list of positive integers;
4371the value specifies the number of threads to use for the corresponding nested
4372level. Specifying more than one item in the list automatically enables
4373nesting by default. If undefined one thread per CPU is used.
4374
4375When a list with more than value is specified, it also affects the
4376@var{max-active-levels-var} ICV as described in @ref{OMP_MAX_ACTIVE_LEVELS}.
4377
4378@item @emph{See also}:
4379@ref{omp_set_num_threads}, @ref{OMP_MAX_ACTIVE_LEVELS}
4380
4381@item @emph{Reference}:
4382@uref{https://www.openmp.org, OpenMP specification v4.5}, Section 4.2
4383@end table
4384
4385
4386
4387@node OMP_PROC_BIND
4388@section @env{OMP_PROC_BIND} -- Whether threads may be moved between CPUs
4389@cindex Environment Variable
4390@table @asis
4391@item @emph{ICV:} @var{bind-var}
4392@item @emph{Scope:} data environment
4393@item @emph{Description}:
4394Specifies whether threads may be moved between processors. If set to
4395@code{TRUE}, OpenMP threads should not be moved; if set to @code{FALSE}
4396they may be moved. Alternatively, a comma separated list with the
4397values @code{PRIMARY}, @code{MASTER}, @code{CLOSE} and @code{SPREAD} can
4398be used to specify the thread affinity policy for the corresponding nesting
4399level. With @code{PRIMARY} and @code{MASTER} the worker threads are in the
4400same place partition as the primary thread. With @code{CLOSE} those are
4401kept close to the primary thread in contiguous place partitions. And
4402with @code{SPREAD} a sparse distribution
4403across the place partitions is used. Specifying more than one item in the
4404list automatically enables nesting by default.
4405
4406When a list is specified, it also affects the @var{max-active-levels-var} ICV
4407as described in @ref{OMP_MAX_ACTIVE_LEVELS}.
4408
4409When undefined, @env{OMP_PROC_BIND} defaults to @code{TRUE} when
4410@env{OMP_PLACES} or @env{GOMP_CPU_AFFINITY} is set and @code{FALSE} otherwise.
4411
4412@item @emph{See also}:
4413@ref{omp_get_proc_bind}, @ref{GOMP_CPU_AFFINITY}, @ref{OMP_PLACES},
4414@ref{OMP_MAX_ACTIVE_LEVELS}
4415
4416@item @emph{Reference}:
4417@uref{https://www.openmp.org, OpenMP specification v4.5}, Section 4.4
4418@end table
4419
4420
4421
4422@node OMP_PLACES
4423@section @env{OMP_PLACES} -- Specifies on which CPUs the threads should be placed
4424@cindex Environment Variable
4425@table @asis
4426@item @emph{ICV:} @var{place-partition-var}
4427@item @emph{Scope:} implicit tasks
4428@item @emph{Description}:
4429The thread placement can be either specified using an abstract name or by an
4430explicit list of the places. The abstract names @code{threads}, @code{cores},
4431@code{sockets}, @code{ll_caches} and @code{numa_domains} can be optionally
4432followed by a positive number in parentheses, which denotes the how many places
4433shall be created. With @code{threads} each place corresponds to a single
4434hardware thread; @code{cores} to a single core with the corresponding number of
4435hardware threads; with @code{sockets} the place corresponds to a single
4436socket; with @code{ll_caches} to a set of cores that shares the last level
4437cache on the device; and @code{numa_domains} to a set of cores for which their
4438closest memory on the device is the same memory and at a similar distance from
4439the cores. The resulting placement can be shown by setting the
4440@env{OMP_DISPLAY_ENV} environment variable.
4441
4442Alternatively, the placement can be specified explicitly as comma-separated
4443list of places. A place is specified by set of nonnegative numbers in curly
4444braces, denoting the hardware threads. The curly braces can be omitted
4445when only a single number has been specified. The hardware threads
4446belonging to a place can either be specified as comma-separated list of
4447nonnegative thread numbers or using an interval. Multiple places can also be
4448either specified by a comma-separated list of places or by an interval. To
4449specify an interval, a colon followed by the count is placed after
4450the hardware thread number or the place. Optionally, the length can be
4451followed by a colon and the stride number -- otherwise a unit stride is
4452assumed. Placing an exclamation mark (@code{!}) directly before a curly
4453brace or numbers inside the curly braces (excluding intervals)
4454excludes those hardware threads.
4455
4456For instance, the following specifies the same places list:
4457@code{"@{0,1,2@}, @{3,4,6@}, @{7,8,9@}, @{10,11,12@}"};
4458@code{"@{0:3@}, @{3:3@}, @{7:3@}, @{10:3@}"}; and @code{"@{0:2@}:4:3"}.
4459
4460If @env{OMP_PLACES} and @env{GOMP_CPU_AFFINITY} are unset and
4461@env{OMP_PROC_BIND} is either unset or @code{false}, threads may be moved
4462between CPUs following no placement policy.
4463
4464@item @emph{See also}:
4465@ref{OMP_PROC_BIND}, @ref{GOMP_CPU_AFFINITY}, @ref{omp_get_proc_bind},
4466@ref{OMP_DISPLAY_ENV}
4467
4468@item @emph{Reference}:
4469@uref{https://www.openmp.org, OpenMP specification v4.5}, Section 4.5
4470@end table
4471
4472
4473
4474@node OMP_STACKSIZE
4475@section @env{OMP_STACKSIZE} -- Set default thread stack size
4476@cindex Environment Variable
4477@table @asis
4478@item @emph{ICV:} @var{stacksize-var}
4479@item @emph{Scope:} device
4480@item @emph{Description}:
4481Set the default thread stack size in kilobytes, unless the number
4482is suffixed by @code{B}, @code{K}, @code{M} or @code{G}, in which
4483case the size is, respectively, in bytes, kilobytes, megabytes
4484or gigabytes. This is different from @code{pthread_attr_setstacksize}
4485which gets the number of bytes as an argument. If the stack size cannot
4486be set due to system constraints, an error is reported and the initial
4487stack size is left unchanged. If undefined, the stack size is system
4488dependent.
4489
4490@item @emph{See also}:
4491@ref{GOMP_STACKSIZE}
4492
4493@item @emph{Reference}:
4494@uref{https://www.openmp.org, OpenMP specification v4.5}, Section 4.7
4495@end table
4496
4497
4498
4499@node OMP_SCHEDULE
4500@section @env{OMP_SCHEDULE} -- How threads are scheduled
4501@cindex Environment Variable
4502@cindex Implementation specific setting
4503@table @asis
4504@item @emph{ICV:} @var{run-sched-var}
4505@item @emph{Scope:} data environment
4506@item @emph{Description}:
4507Allows to specify @code{schedule type} and @code{chunk size}.
4508The value of the variable shall have the form: @code{type[,chunk]} where
4509@code{type} is one of @code{static}, @code{dynamic}, @code{guided} or @code{auto}
4510The optional @code{chunk} size shall be a positive integer. If undefined,
4511dynamic scheduling and a chunk size of 1 is used.
4512
4513@item @emph{See also}:
4514@ref{omp_set_schedule}
4515
4516@item @emph{Reference}:
4517@uref{https://www.openmp.org, OpenMP specification v4.5}, Sections 2.7.1.1 and 4.1
4518@end table
4519
4520
4521
4522@node OMP_TARGET_OFFLOAD
4523@section @env{OMP_TARGET_OFFLOAD} -- Controls offloading behavior
4524@cindex Environment Variable
4525@cindex Implementation specific setting
4526@table @asis
4527@item @emph{ICV:} @var{target-offload-var}
4528@item @emph{Scope:} global
4529@item @emph{Description}:
4530Specifies the behavior with regard to offloading code to a device. This
4531variable can be set to one of three values - @code{MANDATORY}, @code{DISABLED}
4532or @code{DEFAULT}.
4533
4534If set to @code{MANDATORY}, the program terminates with an error if
4535any device construct or device memory routine uses a device that is unavailable
4536or not supported by the implementation, or uses a non-conforming device number.
4537If set to @code{DISABLED}, then offloading is disabled and all code runs on
4538the host. If set to @code{DEFAULT}, the program tries offloading to the
4539device first, then falls back to running code on the host if it cannot.
4540
4541If undefined, then the program behaves as if @code{DEFAULT} was set.
4542
4543Note: Even with @code{MANDATORY}, no run-time termination is performed when
4544the device number in a @code{device} clause or argument to a device memory
4545routine is for host, which includes using the device number in the
4546@var{default-device-var} ICV. However, the initial value of
4547the @var{default-device-var} ICV is affected by @code{MANDATORY}.
4548
4549@item @emph{See also}:
4550@ref{OMP_DEFAULT_DEVICE}
4551
4552@item @emph{Reference}:
4553@uref{https://www.openmp.org, OpenMP specification v5.2}, Section 21.2.8
4554@end table
4555
4556
4557
4558@node OMP_TEAMS_THREAD_LIMIT
4559@section @env{OMP_TEAMS_THREAD_LIMIT} -- Set the maximum number of threads imposed by teams
4560@cindex Environment Variable
4561@table @asis
4562@item @emph{ICV:} @var{teams-thread-limit-var}
4563@item @emph{Scope:} device
4564@item @emph{Description}:
4565Specifies an upper bound for the number of threads to use by each contention
4566group created by a teams construct without explicit @code{thread_limit}
4567clause. The value of this variable shall be a positive integer. If undefined,
4568the value of 0 is used which stands for an implementation defined upper
4569limit.
4570
4571@item @emph{See also}:
4572@ref{OMP_THREAD_LIMIT}, @ref{omp_set_teams_thread_limit}
4573
4574@item @emph{Reference}:
4575@uref{https://www.openmp.org, OpenMP specification v5.1}, Section 6.24
4576@end table
4577
4578
4579
4580@node OMP_THREAD_LIMIT
4581@section @env{OMP_THREAD_LIMIT} -- Set the maximum number of threads
4582@cindex Environment Variable
4583@table @asis
4584@item @emph{ICV:} @var{thread-limit-var}
4585@item @emph{Scope:} data environment
4586@item @emph{Description}:
4587Specifies the number of threads to use for the whole program. The
4588value of this variable shall be a positive integer. If undefined,
4589the number of threads is not limited.
4590
4591@item @emph{See also}:
4592@ref{OMP_NUM_THREADS}, @ref{omp_get_thread_limit}
4593
4594@item @emph{Reference}:
4595@uref{https://www.openmp.org, OpenMP specification v4.5}, Section 4.10
4596@end table
4597
4598
4599
4600@node OMP_WAIT_POLICY
4601@section @env{OMP_WAIT_POLICY} -- How waiting threads are handled
4602@cindex Environment Variable
4603@table @asis
4604@item @emph{Description}:
4605Specifies whether waiting threads should be active or passive. If
4606the value is @code{PASSIVE}, waiting threads should not consume CPU
4607power while waiting; while the value is @code{ACTIVE} specifies that
4608they should. If undefined, threads wait actively for a short time
4609before waiting passively.
4610
4611@item @emph{See also}:
4612@ref{GOMP_SPINCOUNT}
4613
4614@item @emph{Reference}:
4615@uref{https://www.openmp.org, OpenMP specification v4.5}, Section 4.8
4616@end table
4617
4618
4619
4620@node GOMP_CPU_AFFINITY
4621@section @env{GOMP_CPU_AFFINITY} -- Bind threads to specific CPUs
4622@cindex Environment Variable
4623@table @asis
4624@item @emph{Description}:
4625Binds threads to specific CPUs. The variable should contain a space-separated
4626or comma-separated list of CPUs. This list may contain different kinds of
4627entries: either single CPU numbers in any order, a range of CPUs (M-N)
4628or a range with some stride (M-N:S). CPU numbers are zero based. For example,
4629@code{GOMP_CPU_AFFINITY="0 3 1-2 4-15:2"} binds the initial thread
4630to CPU 0, the second to CPU 3, the third to CPU 1, the fourth to
4631CPU 2, the fifth to CPU 4, the sixth through tenth to CPUs 6, 8, 10, 12,
4632and 14 respectively and then starts assigning back from the beginning of
4633the list. @code{GOMP_CPU_AFFINITY=0} binds all threads to CPU 0.
4634
4635There is no libgomp library routine to determine whether a CPU affinity
4636specification is in effect. As a workaround, language-specific library
4637functions, e.g., @code{getenv} in C or @code{GET_ENVIRONMENT_VARIABLE} in
4638Fortran, may be used to query the setting of the @code{GOMP_CPU_AFFINITY}
4639environment variable. A defined CPU affinity on startup cannot be changed
4640or disabled during the runtime of the application.
4641
4642If both @env{GOMP_CPU_AFFINITY} and @env{OMP_PROC_BIND} are set,
4643@env{OMP_PROC_BIND} has a higher precedence. If neither has been set and
4644@env{OMP_PROC_BIND} is unset, or when @env{OMP_PROC_BIND} is set to
4645@code{FALSE}, the host system handles the assignment of threads to CPUs.
4646
4647@item @emph{See also}:
4648@ref{OMP_PLACES}, @ref{OMP_PROC_BIND}
4649@end table
4650
4651
4652
4653@node GOMP_DEBUG
4654@section @env{GOMP_DEBUG} -- Enable debugging output
4655@cindex Environment Variable
4656@table @asis
4657@item @emph{Description}:
4658Enable debugging output. The variable should be set to @code{0}
4659(disabled, also the default if not set), or @code{1} (enabled).
4660
4661If enabled, some debugging output is printed during execution.
4662This is currently not specified in more detail, and subject to change.
4663@end table
4664
4665
4666
4667@node GOMP_STACKSIZE
4668@section @env{GOMP_STACKSIZE} -- Set default thread stack size
4669@cindex Environment Variable
4670@cindex Implementation specific setting
4671@table @asis
4672@item @emph{Description}:
4673Set the default thread stack size in kilobytes. This is different from
4674@code{pthread_attr_setstacksize} which gets the number of bytes as an
4675argument. If the stack size cannot be set due to system constraints, an
4676error is reported and the initial stack size is left unchanged. If undefined,
4677the stack size is system dependent.
4678
4679@item @emph{See also}:
4680@ref{OMP_STACKSIZE}
4681
4682@item @emph{Reference}:
4683@uref{https://gcc.gnu.org/ml/gcc-patches/2006-06/msg00493.html,
4684GCC Patches Mailinglist},
4685@uref{https://gcc.gnu.org/ml/gcc-patches/2006-06/msg00496.html,
4686GCC Patches Mailinglist}
4687@end table
4688
4689
4690
4691@node GOMP_SPINCOUNT
4692@section @env{GOMP_SPINCOUNT} -- Set the busy-wait spin count
4693@cindex Environment Variable
4694@cindex Implementation specific setting
4695@table @asis
4696@item @emph{Description}:
4697Determines how long a threads waits actively with consuming CPU power
4698before waiting passively without consuming CPU power. The value may be
4699either @code{INFINITE}, @code{INFINITY} to always wait actively or an
4700integer which gives the number of spins of the busy-wait loop. The
4701integer may optionally be followed by the following suffixes acting
4702as multiplication factors: @code{k} (kilo, thousand), @code{M} (mega,
4703million), @code{G} (giga, billion), or @code{T} (tera, trillion).
4704If undefined, 0 is used when @env{OMP_WAIT_POLICY} is @code{PASSIVE},
4705300,000 is used when @env{OMP_WAIT_POLICY} is undefined and
470630 billion is used when @env{OMP_WAIT_POLICY} is @code{ACTIVE}.
4707If there are more OpenMP threads than available CPUs, 1000 and 100
4708spins are used for @env{OMP_WAIT_POLICY} being @code{ACTIVE} or
4709undefined, respectively; unless the @env{GOMP_SPINCOUNT} is lower
4710or @env{OMP_WAIT_POLICY} is @code{PASSIVE}.
4711
4712@item @emph{See also}:
4713@ref{OMP_WAIT_POLICY}
4714@end table
4715
4716
4717
4718@node GOMP_RTEMS_THREAD_POOLS
4719@section @env{GOMP_RTEMS_THREAD_POOLS} -- Set the RTEMS specific thread pools
4720@cindex Environment Variable
4721@cindex Implementation specific setting
4722@table @asis
4723@item @emph{Description}:
4724This environment variable is only used on the RTEMS real-time operating system.
4725It determines the scheduler instance specific thread pools. The format for
4726@env{GOMP_RTEMS_THREAD_POOLS} is a list of optional
4727@code{<thread-pool-count>[$<priority>]@@<scheduler-name>} configurations
4728separated by @code{:} where:
4729@itemize @bullet
4730@item @code{<thread-pool-count>} is the thread pool count for this scheduler
4731instance.
4732@item @code{$<priority>} is an optional priority for the worker threads of a
4733thread pool according to @code{pthread_setschedparam}. In case a priority
4734value is omitted, then a worker thread inherits the priority of the OpenMP
4735primary thread that created it. The priority of the worker thread is not
4736changed after creation, even if a new OpenMP primary thread using the worker has
4737a different priority.
4738@item @code{@@<scheduler-name>} is the scheduler instance name according to the
4739RTEMS application configuration.
4740@end itemize
4741In case no thread pool configuration is specified for a scheduler instance,
4742then each OpenMP primary thread of this scheduler instance uses its own
4743dynamically allocated thread pool. To limit the worker thread count of the
4744thread pools, each OpenMP primary thread must call @code{omp_set_num_threads}.
4745@item @emph{Example}:
4746Lets suppose we have three scheduler instances @code{IO}, @code{WRK0}, and
4747@code{WRK1} with @env{GOMP_RTEMS_THREAD_POOLS} set to
4748@code{"1@@WRK0:3$4@@WRK1"}. Then there are no thread pool restrictions for
4749scheduler instance @code{IO}. In the scheduler instance @code{WRK0} there is
4750one thread pool available. Since no priority is specified for this scheduler
4751instance, the worker thread inherits the priority of the OpenMP primary thread
4752that created it. In the scheduler instance @code{WRK1} there are three thread
4753pools available and their worker threads run at priority four.
4754@end table
4755
4756
4757
4758@c ---------------------------------------------------------------------
4759@c Enabling OpenACC
4760@c ---------------------------------------------------------------------
4761
4762@node Enabling OpenACC
4763@chapter Enabling OpenACC
4764
4765To activate the OpenACC extensions for C/C++ and Fortran, the compile-time
4766flag @option{-fopenacc} must be specified. This enables the OpenACC directive
4767@samp{#pragma acc} in C/C++ and, in Fortran, the @samp{!$acc} sentinel in free
4768source form and the @samp{c$acc}, @samp{*$acc} and @samp{!$acc} sentinels in
4769fixed source form. The flag also arranges for automatic linking of the OpenACC
4770runtime library (@ref{OpenACC Runtime Library Routines}).
4771
4772See @uref{https://gcc.gnu.org/wiki/OpenACC} for more information.
4773
4774A complete description of all OpenACC directives accepted may be found in
4775the @uref{https://www.openacc.org, OpenACC} Application Programming
4776Interface manual, version 2.6.
4777
4778
4779
4780@c ---------------------------------------------------------------------
4781@c OpenACC Runtime Library Routines
4782@c ---------------------------------------------------------------------
4783
4784@node OpenACC Runtime Library Routines
4785@chapter OpenACC Runtime Library Routines
4786
4787The runtime routines described here are defined by section 3 of the OpenACC
4788specifications in version 2.6.
4789They have C linkage, and do not throw exceptions.
4790Generally, they are available only for the host, with the exception of
4791@code{acc_on_device}, which is available for both the host and the
4792acceleration device.
4793
4794@menu
4795* acc_get_num_devices:: Get number of devices for the given device
4796 type.
4797* acc_set_device_type:: Set type of device accelerator to use.
4798* acc_get_device_type:: Get type of device accelerator to be used.
4799* acc_set_device_num:: Set device number to use.
4800* acc_get_device_num:: Get device number to be used.
4801* acc_get_property:: Get device property.
4802* acc_async_test:: Tests for completion of a specific asynchronous
4803 operation.
4804* acc_async_test_all:: Tests for completion of all asynchronous
4805 operations.
4806* acc_wait:: Wait for completion of a specific asynchronous
4807 operation.
4808* acc_wait_all:: Waits for completion of all asynchronous
4809 operations.
4810* acc_wait_all_async:: Wait for completion of all asynchronous
4811 operations.
4812* acc_wait_async:: Wait for completion of asynchronous operations.
4813* acc_init:: Initialize runtime for a specific device type.
4814* acc_shutdown:: Shuts down the runtime for a specific device
4815 type.
4816* acc_on_device:: Whether executing on a particular device
4817* acc_malloc:: Allocate device memory.
4818* acc_free:: Free device memory.
4819* acc_copyin:: Allocate device memory and copy host memory to
4820 it.
4821* acc_present_or_copyin:: If the data is not present on the device,
4822 allocate device memory and copy from host
4823 memory.
4824* acc_create:: Allocate device memory and map it to host
4825 memory.
4826* acc_present_or_create:: If the data is not present on the device,
4827 allocate device memory and map it to host
4828 memory.
4829* acc_copyout:: Copy device memory to host memory.
4830* acc_delete:: Free device memory.
4831* acc_update_device:: Update device memory from mapped host memory.
4832* acc_update_self:: Update host memory from mapped device memory.
4833* acc_map_data:: Map previously allocated device memory to host
4834 memory.
4835* acc_unmap_data:: Unmap device memory from host memory.
4836* acc_deviceptr:: Get device pointer associated with specific
4837 host address.
4838* acc_hostptr:: Get host pointer associated with specific
4839 device address.
4840* acc_is_present:: Indicate whether host variable / array is
4841 present on device.
4842* acc_memcpy_to_device:: Copy host memory to device memory.
4843* acc_memcpy_from_device:: Copy device memory to host memory.
4844* acc_memcpy_device:: Copy memory within a device.
4845* acc_attach:: Let device pointer point to device-pointer target.
4846* acc_detach:: Let device pointer point to host-pointer target.
4847
4848API routines for target platforms.
4849
4850* acc_get_current_cuda_device:: Get CUDA device handle.
4851* acc_get_current_cuda_context::Get CUDA context handle.
4852* acc_get_cuda_stream:: Get CUDA stream handle.
4853* acc_set_cuda_stream:: Set CUDA stream handle.
4854
4855API routines for the OpenACC Profiling Interface.
4856
4857* acc_prof_register:: Register callbacks.
4858* acc_prof_unregister:: Unregister callbacks.
4859* acc_prof_lookup:: Obtain inquiry functions.
4860* acc_register_library:: Library registration.
4861@end menu
4862
4863
4864
4865@node acc_get_num_devices
4866@section @code{acc_get_num_devices} -- Get number of devices for given device type
4867@table @asis
4868@item @emph{Description}
4869This function returns a value indicating the number of devices available
4870for the device type specified in @var{devicetype}.
4871
4872@item @emph{C/C++}:
4873@multitable @columnfractions .20 .80
4874@item @emph{Prototype}: @tab @code{int acc_get_num_devices(acc_device_t devicetype);}
4875@end multitable
4876
4877@item @emph{Fortran}:
4878@multitable @columnfractions .20 .80
4879@item @emph{Interface}: @tab @code{integer function acc_get_num_devices(devicetype)}
4880@item @tab @code{integer(kind=acc_device_kind) devicetype}
4881@end multitable
4882
4883@item @emph{Reference}:
4884@uref{https://www.openacc.org, OpenACC specification v2.6}, section
48853.2.1.
4886@end table
4887
4888
4889
4890@node acc_set_device_type
4891@section @code{acc_set_device_type} -- Set type of device accelerator to use.
4892@table @asis
4893@item @emph{Description}
4894This function indicates to the runtime library which device type, specified
4895in @var{devicetype}, to use when executing a parallel or kernels region.
4896
4897@item @emph{C/C++}:
4898@multitable @columnfractions .20 .80
4899@item @emph{Prototype}: @tab @code{acc_set_device_type(acc_device_t devicetype);}
4900@end multitable
4901
4902@item @emph{Fortran}:
4903@multitable @columnfractions .20 .80
4904@item @emph{Interface}: @tab @code{subroutine acc_set_device_type(devicetype)}
4905@item @tab @code{integer(kind=acc_device_kind) devicetype}
4906@end multitable
4907
4908@item @emph{Reference}:
4909@uref{https://www.openacc.org, OpenACC specification v2.6}, section
49103.2.2.
4911@end table
4912
4913
4914
4915@node acc_get_device_type
4916@section @code{acc_get_device_type} -- Get type of device accelerator to be used.
4917@table @asis
4918@item @emph{Description}
4919This function returns what device type will be used when executing a
4920parallel or kernels region.
4921
4922This function returns @code{acc_device_none} if
4923@code{acc_get_device_type} is called from
4924@code{acc_ev_device_init_start}, @code{acc_ev_device_init_end}
4925callbacks of the OpenACC Profiling Interface (@ref{OpenACC Profiling
4926Interface}), that is, if the device is currently being initialized.
4927
4928@item @emph{C/C++}:
4929@multitable @columnfractions .20 .80
4930@item @emph{Prototype}: @tab @code{acc_device_t acc_get_device_type(void);}
4931@end multitable
4932
4933@item @emph{Fortran}:
4934@multitable @columnfractions .20 .80
4935@item @emph{Interface}: @tab @code{function acc_get_device_type(void)}
4936@item @tab @code{integer(kind=acc_device_kind) acc_get_device_type}
4937@end multitable
4938
4939@item @emph{Reference}:
4940@uref{https://www.openacc.org, OpenACC specification v2.6}, section
49413.2.3.
4942@end table
4943
4944
4945
4946@node acc_set_device_num
4947@section @code{acc_set_device_num} -- Set device number to use.
4948@table @asis
4949@item @emph{Description}
4950This function will indicate to the runtime which device number,
4951specified by @var{devicenum}, associated with the specified device
4952type @var{devicetype}.
4953
4954@item @emph{C/C++}:
4955@multitable @columnfractions .20 .80
4956@item @emph{Prototype}: @tab @code{acc_set_device_num(int devicenum, acc_device_t devicetype);}
4957@end multitable
4958
4959@item @emph{Fortran}:
4960@multitable @columnfractions .20 .80
4961@item @emph{Interface}: @tab @code{subroutine acc_set_device_num(devicenum, devicetype)}
4962@item @tab @code{integer devicenum}
4963@item @tab @code{integer(kind=acc_device_kind) devicetype}
4964@end multitable
4965
4966@item @emph{Reference}:
4967@uref{https://www.openacc.org, OpenACC specification v2.6}, section
49683.2.4.
4969@end table
4970
4971
4972
4973@node acc_get_device_num
4974@section @code{acc_get_device_num} -- Get device number to be used.
4975@table @asis
4976@item @emph{Description}
4977This function returns which device number associated with the specified device
4978type @var{devicetype}, will be used when executing a parallel or kernels
4979region.
4980
4981@item @emph{C/C++}:
4982@multitable @columnfractions .20 .80
4983@item @emph{Prototype}: @tab @code{int acc_get_device_num(acc_device_t devicetype);}
4984@end multitable
4985
4986@item @emph{Fortran}:
4987@multitable @columnfractions .20 .80
4988@item @emph{Interface}: @tab @code{function acc_get_device_num(devicetype)}
4989@item @tab @code{integer(kind=acc_device_kind) devicetype}
4990@item @tab @code{integer acc_get_device_num}
4991@end multitable
4992
4993@item @emph{Reference}:
4994@uref{https://www.openacc.org, OpenACC specification v2.6}, section
49953.2.5.
4996@end table
4997
4998
4999
5000@node acc_get_property
5001@section @code{acc_get_property} -- Get device property.
5002@cindex acc_get_property
5003@cindex acc_get_property_string
5004@table @asis
5005@item @emph{Description}
5006These routines return the value of the specified @var{property} for the
5007device being queried according to @var{devicenum} and @var{devicetype}.
5008Integer-valued and string-valued properties are returned by
5009@code{acc_get_property} and @code{acc_get_property_string} respectively.
5010The Fortran @code{acc_get_property_string} subroutine returns the string
5011retrieved in its fourth argument while the remaining entry points are
5012functions, which pass the return value as their result.
5013
5014Note for Fortran, only: the OpenACC technical committee corrected and, hence,
5015modified the interface introduced in OpenACC 2.6. The kind-value parameter
5016@code{acc_device_property} has been renamed to @code{acc_device_property_kind}
5017for consistency and the return type of the @code{acc_get_property} function is
5018now a @code{c_size_t} integer instead of a @code{acc_device_property} integer.
5019The parameter @code{acc_device_property} is still provided,
5020but might be removed in a future version of GCC.
5021
5022@item @emph{C/C++}:
5023@multitable @columnfractions .20 .80
5024@item @emph{Prototype}: @tab @code{size_t acc_get_property(int devicenum, acc_device_t devicetype, acc_device_property_t property);}
5025@item @emph{Prototype}: @tab @code{const char *acc_get_property_string(int devicenum, acc_device_t devicetype, acc_device_property_t property);}
5026@end multitable
5027
5028@item @emph{Fortran}:
5029@multitable @columnfractions .20 .80
5030@item @emph{Interface}: @tab @code{function acc_get_property(devicenum, devicetype, property)}
5031@item @emph{Interface}: @tab @code{subroutine acc_get_property_string(devicenum, devicetype, property, string)}
5032@item @tab @code{use ISO_C_Binding, only: c_size_t}
5033@item @tab @code{integer devicenum}
5034@item @tab @code{integer(kind=acc_device_kind) devicetype}
5035@item @tab @code{integer(kind=acc_device_property_kind) property}
5036@item @tab @code{integer(kind=c_size_t) acc_get_property}
5037@item @tab @code{character(*) string}
5038@end multitable
5039
5040@item @emph{Reference}:
5041@uref{https://www.openacc.org, OpenACC specification v2.6}, section
50423.2.6.
5043@end table
5044
5045
5046
5047@node acc_async_test
5048@section @code{acc_async_test} -- Test for completion of a specific asynchronous operation.
5049@table @asis
5050@item @emph{Description}
5051This function tests for completion of the asynchronous operation specified
5052in @var{arg}. In C/C++, a non-zero value is returned to indicate
5053the specified asynchronous operation has completed while Fortran returns
5054@code{true}. If the asynchronous operation has not completed, C/C++ returns
5055zero and Fortran returns @code{false}.
5056
5057@item @emph{C/C++}:
5058@multitable @columnfractions .20 .80
5059@item @emph{Prototype}: @tab @code{int acc_async_test(int arg);}
5060@end multitable
5061
5062@item @emph{Fortran}:
5063@multitable @columnfractions .20 .80
5064@item @emph{Interface}: @tab @code{function acc_async_test(arg)}
5065@item @tab @code{integer(kind=acc_handle_kind) arg}
5066@item @tab @code{logical acc_async_test}
5067@end multitable
5068
5069@item @emph{Reference}:
5070@uref{https://www.openacc.org, OpenACC specification v2.6}, section
50713.2.9.
5072@end table
5073
5074
5075
5076@node acc_async_test_all
5077@section @code{acc_async_test_all} -- Tests for completion of all asynchronous operations.
5078@table @asis
5079@item @emph{Description}
5080This function tests for completion of all asynchronous operations.
5081In C/C++, a non-zero value is returned to indicate all asynchronous
5082operations have completed while Fortran returns @code{true}. If
5083any asynchronous operation has not completed, C/C++ returns zero and
5084Fortran returns @code{false}.
5085
5086@item @emph{C/C++}:
5087@multitable @columnfractions .20 .80
5088@item @emph{Prototype}: @tab @code{int acc_async_test_all(void);}
5089@end multitable
5090
5091@item @emph{Fortran}:
5092@multitable @columnfractions .20 .80
5093@item @emph{Interface}: @tab @code{function acc_async_test()}
5094@item @tab @code{logical acc_get_device_num}
5095@end multitable
5096
5097@item @emph{Reference}:
5098@uref{https://www.openacc.org, OpenACC specification v2.6}, section
50993.2.10.
5100@end table
5101
5102
5103
5104@node acc_wait
5105@section @code{acc_wait} -- Wait for completion of a specific asynchronous operation.
5106@table @asis
5107@item @emph{Description}
5108This function waits for completion of the asynchronous operation
5109specified in @var{arg}.
5110
5111@item @emph{C/C++}:
5112@multitable @columnfractions .20 .80
5113@item @emph{Prototype}: @tab @code{acc_wait(arg);}
5114@item @emph{Prototype (OpenACC 1.0 compatibility)}: @tab @code{acc_async_wait(arg);}
5115@end multitable
5116
5117@item @emph{Fortran}:
5118@multitable @columnfractions .20 .80
5119@item @emph{Interface}: @tab @code{subroutine acc_wait(arg)}
5120@item @tab @code{integer(acc_handle_kind) arg}
5121@item @emph{Interface (OpenACC 1.0 compatibility)}: @tab @code{subroutine acc_async_wait(arg)}
5122@item @tab @code{integer(acc_handle_kind) arg}
5123@end multitable
5124
5125@item @emph{Reference}:
5126@uref{https://www.openacc.org, OpenACC specification v2.6}, section
51273.2.11.
5128@end table
5129
5130
5131
5132@node acc_wait_all
5133@section @code{acc_wait_all} -- Waits for completion of all asynchronous operations.
5134@table @asis
5135@item @emph{Description}
5136This function waits for the completion of all asynchronous operations.
5137
5138@item @emph{C/C++}:
5139@multitable @columnfractions .20 .80
5140@item @emph{Prototype}: @tab @code{acc_wait_all(void);}
5141@item @emph{Prototype (OpenACC 1.0 compatibility)}: @tab @code{acc_async_wait_all(void);}
5142@end multitable
5143
5144@item @emph{Fortran}:
5145@multitable @columnfractions .20 .80
5146@item @emph{Interface}: @tab @code{subroutine acc_wait_all()}
5147@item @emph{Interface (OpenACC 1.0 compatibility)}: @tab @code{subroutine acc_async_wait_all()}
5148@end multitable
5149
5150@item @emph{Reference}:
5151@uref{https://www.openacc.org, OpenACC specification v2.6}, section
51523.2.13.
5153@end table
5154
5155
5156
5157@node acc_wait_all_async
5158@section @code{acc_wait_all_async} -- Wait for completion of all asynchronous operations.
5159@table @asis
5160@item @emph{Description}
5161This function enqueues a wait operation on the queue @var{async} for any
5162and all asynchronous operations that have been previously enqueued on
5163any queue.
5164
5165@item @emph{C/C++}:
5166@multitable @columnfractions .20 .80
5167@item @emph{Prototype}: @tab @code{acc_wait_all_async(int async);}
5168@end multitable
5169
5170@item @emph{Fortran}:
5171@multitable @columnfractions .20 .80
5172@item @emph{Interface}: @tab @code{subroutine acc_wait_all_async(async)}
5173@item @tab @code{integer(acc_handle_kind) async}
5174@end multitable
5175
5176@item @emph{Reference}:
5177@uref{https://www.openacc.org, OpenACC specification v2.6}, section
51783.2.14.
5179@end table
5180
5181
5182
5183@node acc_wait_async
5184@section @code{acc_wait_async} -- Wait for completion of asynchronous operations.
5185@table @asis
5186@item @emph{Description}
5187This function enqueues a wait operation on queue @var{async} for any and all
5188asynchronous operations enqueued on queue @var{arg}.
5189
5190@item @emph{C/C++}:
5191@multitable @columnfractions .20 .80
5192@item @emph{Prototype}: @tab @code{acc_wait_async(int arg, int async);}
5193@end multitable
5194
5195@item @emph{Fortran}:
5196@multitable @columnfractions .20 .80
5197@item @emph{Interface}: @tab @code{subroutine acc_wait_async(arg, async)}
5198@item @tab @code{integer(acc_handle_kind) arg, async}
5199@end multitable
5200
5201@item @emph{Reference}:
5202@uref{https://www.openacc.org, OpenACC specification v2.6}, section
52033.2.12.
5204@end table
5205
5206
5207
5208@node acc_init
5209@section @code{acc_init} -- Initialize runtime for a specific device type.
5210@table @asis
5211@item @emph{Description}
5212This function initializes the runtime for the device type specified in
5213@var{devicetype}.
5214
5215@item @emph{C/C++}:
5216@multitable @columnfractions .20 .80
5217@item @emph{Prototype}: @tab @code{acc_init(acc_device_t devicetype);}
5218@end multitable
5219
5220@item @emph{Fortran}:
5221@multitable @columnfractions .20 .80
5222@item @emph{Interface}: @tab @code{subroutine acc_init(devicetype)}
5223@item @tab @code{integer(acc_device_kind) devicetype}
5224@end multitable
5225
5226@item @emph{Reference}:
5227@uref{https://www.openacc.org, OpenACC specification v2.6}, section
52283.2.7.
5229@end table
5230
5231
5232
5233@node acc_shutdown
5234@section @code{acc_shutdown} -- Shuts down the runtime for a specific device type.
5235@table @asis
5236@item @emph{Description}
5237This function shuts down the runtime for the device type specified in
5238@var{devicetype}.
5239
5240@item @emph{C/C++}:
5241@multitable @columnfractions .20 .80
5242@item @emph{Prototype}: @tab @code{acc_shutdown(acc_device_t devicetype);}
5243@end multitable
5244
5245@item @emph{Fortran}:
5246@multitable @columnfractions .20 .80
5247@item @emph{Interface}: @tab @code{subroutine acc_shutdown(devicetype)}
5248@item @tab @code{integer(acc_device_kind) devicetype}
5249@end multitable
5250
5251@item @emph{Reference}:
5252@uref{https://www.openacc.org, OpenACC specification v2.6}, section
52533.2.8.
5254@end table
5255
5256
5257
5258@node acc_on_device
5259@section @code{acc_on_device} -- Whether executing on a particular device
5260@table @asis
5261@item @emph{Description}:
5262This function returns whether the program is executing on a particular
5263device specified in @var{devicetype}. In C/C++ a non-zero value is
5264returned to indicate the device is executing on the specified device type.
5265In Fortran, @code{true} is returned. If the program is not executing
5266on the specified device type C/C++ returns zero, while Fortran
5267returns @code{false}.
5268
5269Note that in GCC, depending on @var{devicetype}, the function call might
5270be folded to a constant in the compiler; compile with
5271@option{-fno-builtin-acc_on_device} if a run-time function is desired.
5272
5273@item @emph{C/C++}:
5274@multitable @columnfractions .20 .80
5275@item @emph{Prototype}: @tab @code{acc_on_device(acc_device_t devicetype);}
5276@end multitable
5277
5278@item @emph{Fortran}:
5279@multitable @columnfractions .20 .80
5280@item @emph{Interface}: @tab @code{function acc_on_device(devicetype)}
5281@item @tab @code{integer(acc_device_kind) devicetype}
5282@item @tab @code{logical acc_on_device}
5283@end multitable
5284
5285@item @emph{Reference}:
5286@uref{https://www.openacc.org, OpenACC specification v2.6}, section
52873.2.17.
5288@end table
5289
5290
5291
5292@node acc_malloc
5293@section @code{acc_malloc} -- Allocate device memory.
5294@table @asis
5295@item @emph{Description}
5296This function allocates @var{bytes} bytes of device memory. It returns
5297the device address of the allocated memory.
5298
5299@item @emph{C/C++}:
5300@multitable @columnfractions .20 .80
5301@item @emph{Prototype}: @tab @code{d_void* acc_malloc(size_t bytes);}
5302@end multitable
5303
5304@item @emph{Fortran}:
5305@multitable @columnfractions .20 .80
5306@item @emph{Interface}: @tab @code{type(c_ptr) function acc_malloc(bytes)}
5307@item @tab @code{integer(c_size_t), value :: bytes}
5308@end multitable
5309
5310@item @emph{Reference}:
5311@uref{https://www.openacc.org, OpenACC specification v2.6}, section
53123.2.18. @uref{https://www.openacc.org, openacc specification v3.3}, section
53133.2.16.
5314@end table
5315
5316
5317
5318@node acc_free
5319@section @code{acc_free} -- Free device memory.
5320@table @asis
5321@item @emph{Description}
5322Free previously allocated device memory at the device address @code{data_dev}.
5323
5324@item @emph{C/C++}:
5325@multitable @columnfractions .20 .80
5326@item @emph{Prototype}: @tab @code{void acc_free(d_void *data_dev);}
5327@end multitable
5328
5329@item @emph{Fortran}:
5330@multitable @columnfractions .20 .80
5331@item @emph{Interface}: @tab @code{subroutine acc_free(data_dev)}
5332@item @tab @code{type(c_ptr), value :: data_dev}
5333@end multitable
5334
5335@item @emph{Reference}:
5336@uref{https://www.openacc.org, OpenACC specification v2.6}, section
53373.2.19. @uref{https://www.openacc.org, openacc specification v3.3}, section
53383.2.17.
5339@end table
5340
5341
5342
5343@node acc_copyin
5344@section @code{acc_copyin} -- Allocate device memory and copy host memory to it.
5345@table @asis
5346@item @emph{Description}
5347In C/C++, this function allocates @var{len} bytes of device memory
5348and maps it to the specified host address in @var{a}. The device
5349address of the newly allocated device memory is returned.
5350
5351In Fortran, two (2) forms are supported. In the first form, @var{a} specifies
5352a contiguous array section. The second form @var{a} specifies a
5353variable or array element and @var{len} specifies the length in bytes.
5354
5355@item @emph{C/C++}:
5356@multitable @columnfractions .20 .80
5357@item @emph{Prototype}: @tab @code{void *acc_copyin(h_void *a, size_t len);}
5358@item @emph{Prototype}: @tab @code{void *acc_copyin_async(h_void *a, size_t len, int async);}
5359@end multitable
5360
5361@item @emph{Fortran}:
5362@multitable @columnfractions .20 .80
5363@item @emph{Interface}: @tab @code{subroutine acc_copyin(a)}
5364@item @tab @code{type, dimension(:[,:]...) :: a}
5365@item @emph{Interface}: @tab @code{subroutine acc_copyin(a, len)}
5366@item @tab @code{type, dimension(:[,:]...) :: a}
5367@item @tab @code{integer len}
5368@item @emph{Interface}: @tab @code{subroutine acc_copyin_async(a, async)}
5369@item @tab @code{type, dimension(:[,:]...) :: a}
5370@item @tab @code{integer(acc_handle_kind) :: async}
5371@item @emph{Interface}: @tab @code{subroutine acc_copyin_async(a, len, async)}
5372@item @tab @code{type, dimension(:[,:]...) :: a}
5373@item @tab @code{integer len}
5374@item @tab @code{integer(acc_handle_kind) :: async}
5375@end multitable
5376
5377@item @emph{Reference}:
5378@uref{https://www.openacc.org, OpenACC specification v2.6}, section
53793.2.20.
5380@end table
5381
5382
5383
5384@node acc_present_or_copyin
5385@section @code{acc_present_or_copyin} -- If the data is not present on the device, allocate device memory and copy from host memory.
5386@table @asis
5387@item @emph{Description}
5388This function tests if the host data specified by @var{a} and of length
5389@var{len} is present or not. If it is not present, device memory
5390is allocated and the host memory copied. The device address of
5391the newly allocated device memory is returned.
5392
5393In Fortran, two (2) forms are supported. In the first form, @var{a} specifies
5394a contiguous array section. The second form @var{a} specifies a variable or
5395array element and @var{len} specifies the length in bytes.
5396
5397Note that @code{acc_present_or_copyin} and @code{acc_pcopyin} exist for
5398backward compatibility with OpenACC 2.0; use @ref{acc_copyin} instead.
5399
5400@item @emph{C/C++}:
5401@multitable @columnfractions .20 .80
5402@item @emph{Prototype}: @tab @code{void *acc_present_or_copyin(h_void *a, size_t len);}
5403@item @emph{Prototype}: @tab @code{void *acc_pcopyin(h_void *a, size_t len);}
5404@end multitable
5405
5406@item @emph{Fortran}:
5407@multitable @columnfractions .20 .80
5408@item @emph{Interface}: @tab @code{subroutine acc_present_or_copyin(a)}
5409@item @tab @code{type, dimension(:[,:]...) :: a}
5410@item @emph{Interface}: @tab @code{subroutine acc_present_or_copyin(a, len)}
5411@item @tab @code{type, dimension(:[,:]...) :: a}
5412@item @tab @code{integer len}
5413@item @emph{Interface}: @tab @code{subroutine acc_pcopyin(a)}
5414@item @tab @code{type, dimension(:[,:]...) :: a}
5415@item @emph{Interface}: @tab @code{subroutine acc_pcopyin(a, len)}
5416@item @tab @code{type, dimension(:[,:]...) :: a}
5417@item @tab @code{integer len}
5418@end multitable
5419
5420@item @emph{Reference}:
5421@uref{https://www.openacc.org, OpenACC specification v2.6}, section
54223.2.20.
5423@end table
5424
5425
5426
5427@node acc_create
5428@section @code{acc_create} -- Allocate device memory and map it to host memory.
5429@table @asis
5430@item @emph{Description}
5431This function allocates device memory and maps it to host memory specified
5432by the host address @var{a} with a length of @var{len} bytes. In C/C++,
5433the function returns the device address of the allocated device memory.
5434
5435In Fortran, two (2) forms are supported. In the first form, @var{a} specifies
5436a contiguous array section. The second form @var{a} specifies a variable or
5437array element and @var{len} specifies the length in bytes.
5438
5439@item @emph{C/C++}:
5440@multitable @columnfractions .20 .80
5441@item @emph{Prototype}: @tab @code{void *acc_create(h_void *a, size_t len);}
5442@item @emph{Prototype}: @tab @code{void *acc_create_async(h_void *a, size_t len, int async);}
5443@end multitable
5444
5445@item @emph{Fortran}:
5446@multitable @columnfractions .20 .80
5447@item @emph{Interface}: @tab @code{subroutine acc_create(a)}
5448@item @tab @code{type, dimension(:[,:]...) :: a}
5449@item @emph{Interface}: @tab @code{subroutine acc_create(a, len)}
5450@item @tab @code{type, dimension(:[,:]...) :: a}
5451@item @tab @code{integer len}
5452@item @emph{Interface}: @tab @code{subroutine acc_create_async(a, async)}
5453@item @tab @code{type, dimension(:[,:]...) :: a}
5454@item @tab @code{integer(acc_handle_kind) :: async}
5455@item @emph{Interface}: @tab @code{subroutine acc_create_async(a, len, async)}
5456@item @tab @code{type, dimension(:[,:]...) :: a}
5457@item @tab @code{integer len}
5458@item @tab @code{integer(acc_handle_kind) :: async}
5459@end multitable
5460
5461@item @emph{Reference}:
5462@uref{https://www.openacc.org, OpenACC specification v2.6}, section
54633.2.21.
5464@end table
5465
5466
5467
5468@node acc_present_or_create
5469@section @code{acc_present_or_create} -- If the data is not present on the device, allocate device memory and map it to host memory.
5470@table @asis
5471@item @emph{Description}
5472This function tests if the host data specified by @var{a} and of length
5473@var{len} is present or not. If it is not present, device memory
5474is allocated and mapped to host memory. In C/C++, the device address
5475of the newly allocated device memory is returned.
5476
5477In Fortran, two (2) forms are supported. In the first form, @var{a} specifies
5478a contiguous array section. The second form @var{a} specifies a variable or
5479array element and @var{len} specifies the length in bytes.
5480
5481Note that @code{acc_present_or_create} and @code{acc_pcreate} exist for
5482backward compatibility with OpenACC 2.0; use @ref{acc_create} instead.
5483
5484@item @emph{C/C++}:
5485@multitable @columnfractions .20 .80
5486@item @emph{Prototype}: @tab @code{void *acc_present_or_create(h_void *a, size_t len)}
5487@item @emph{Prototype}: @tab @code{void *acc_pcreate(h_void *a, size_t len)}
5488@end multitable
5489
5490@item @emph{Fortran}:
5491@multitable @columnfractions .20 .80
5492@item @emph{Interface}: @tab @code{subroutine acc_present_or_create(a)}
5493@item @tab @code{type, dimension(:[,:]...) :: a}
5494@item @emph{Interface}: @tab @code{subroutine acc_present_or_create(a, len)}
5495@item @tab @code{type, dimension(:[,:]...) :: a}
5496@item @tab @code{integer len}
5497@item @emph{Interface}: @tab @code{subroutine acc_pcreate(a)}
5498@item @tab @code{type, dimension(:[,:]...) :: a}
5499@item @emph{Interface}: @tab @code{subroutine acc_pcreate(a, len)}
5500@item @tab @code{type, dimension(:[,:]...) :: a}
5501@item @tab @code{integer len}
5502@end multitable
5503
5504@item @emph{Reference}:
5505@uref{https://www.openacc.org, OpenACC specification v2.6}, section
55063.2.21.
5507@end table
5508
5509
5510
5511@node acc_copyout
5512@section @code{acc_copyout} -- Copy device memory to host memory.
5513@table @asis
5514@item @emph{Description}
5515This function copies mapped device memory to host memory which is specified
5516by host address @var{a} for a length @var{len} bytes in C/C++.
5517
5518In Fortran, two (2) forms are supported. In the first form, @var{a} specifies
5519a contiguous array section. The second form @var{a} specifies a variable or
5520array element and @var{len} specifies the length in bytes.
5521
5522@item @emph{C/C++}:
5523@multitable @columnfractions .20 .80
5524@item @emph{Prototype}: @tab @code{acc_copyout(h_void *a, size_t len);}
5525@item @emph{Prototype}: @tab @code{acc_copyout_async(h_void *a, size_t len, int async);}
5526@item @emph{Prototype}: @tab @code{acc_copyout_finalize(h_void *a, size_t len);}
5527@item @emph{Prototype}: @tab @code{acc_copyout_finalize_async(h_void *a, size_t len, int async);}
5528@end multitable
5529
5530@item @emph{Fortran}:
5531@multitable @columnfractions .20 .80
5532@item @emph{Interface}: @tab @code{subroutine acc_copyout(a)}
5533@item @tab @code{type, dimension(:[,:]...) :: a}
5534@item @emph{Interface}: @tab @code{subroutine acc_copyout(a, len)}
5535@item @tab @code{type, dimension(:[,:]...) :: a}
5536@item @tab @code{integer len}
5537@item @emph{Interface}: @tab @code{subroutine acc_copyout_async(a, async)}
5538@item @tab @code{type, dimension(:[,:]...) :: a}
5539@item @tab @code{integer(acc_handle_kind) :: async}
5540@item @emph{Interface}: @tab @code{subroutine acc_copyout_async(a, len, async)}
5541@item @tab @code{type, dimension(:[,:]...) :: a}
5542@item @tab @code{integer len}
5543@item @tab @code{integer(acc_handle_kind) :: async}
5544@item @emph{Interface}: @tab @code{subroutine acc_copyout_finalize(a)}
5545@item @tab @code{type, dimension(:[,:]...) :: a}
5546@item @emph{Interface}: @tab @code{subroutine acc_copyout_finalize(a, len)}
5547@item @tab @code{type, dimension(:[,:]...) :: a}
5548@item @tab @code{integer len}
5549@item @emph{Interface}: @tab @code{subroutine acc_copyout_finalize_async(a, async)}
5550@item @tab @code{type, dimension(:[,:]...) :: a}
5551@item @tab @code{integer(acc_handle_kind) :: async}
5552@item @emph{Interface}: @tab @code{subroutine acc_copyout_finalize_async(a, len, async)}
5553@item @tab @code{type, dimension(:[,:]...) :: a}
5554@item @tab @code{integer len}
5555@item @tab @code{integer(acc_handle_kind) :: async}
5556@end multitable
5557
5558@item @emph{Reference}:
5559@uref{https://www.openacc.org, OpenACC specification v2.6}, section
55603.2.22.
5561@end table
5562
5563
5564
5565@node acc_delete
5566@section @code{acc_delete} -- Free device memory.
5567@table @asis
5568@item @emph{Description}
5569This function frees previously allocated device memory specified by
5570the device address @var{a} and the length of @var{len} bytes.
5571
5572In Fortran, two (2) forms are supported. In the first form, @var{a} specifies
5573a contiguous array section. The second form @var{a} specifies a variable or
5574array element and @var{len} specifies the length in bytes.
5575
5576@item @emph{C/C++}:
5577@multitable @columnfractions .20 .80
5578@item @emph{Prototype}: @tab @code{acc_delete(h_void *a, size_t len);}
5579@item @emph{Prototype}: @tab @code{acc_delete_async(h_void *a, size_t len, int async);}
5580@item @emph{Prototype}: @tab @code{acc_delete_finalize(h_void *a, size_t len);}
5581@item @emph{Prototype}: @tab @code{acc_delete_finalize_async(h_void *a, size_t len, int async);}
5582@end multitable
5583
5584@item @emph{Fortran}:
5585@multitable @columnfractions .20 .80
5586@item @emph{Interface}: @tab @code{subroutine acc_delete(a)}
5587@item @tab @code{type, dimension(:[,:]...) :: a}
5588@item @emph{Interface}: @tab @code{subroutine acc_delete(a, len)}
5589@item @tab @code{type, dimension(:[,:]...) :: a}
5590@item @tab @code{integer len}
5591@item @emph{Interface}: @tab @code{subroutine acc_delete_async(a, async)}
5592@item @tab @code{type, dimension(:[,:]...) :: a}
5593@item @tab @code{integer(acc_handle_kind) :: async}
5594@item @emph{Interface}: @tab @code{subroutine acc_delete_async(a, len, async)}
5595@item @tab @code{type, dimension(:[,:]...) :: a}
5596@item @tab @code{integer len}
5597@item @tab @code{integer(acc_handle_kind) :: async}
5598@item @emph{Interface}: @tab @code{subroutine acc_delete_finalize(a)}
5599@item @tab @code{type, dimension(:[,:]...) :: a}
5600@item @emph{Interface}: @tab @code{subroutine acc_delete_finalize(a, len)}
5601@item @tab @code{type, dimension(:[,:]...) :: a}
5602@item @tab @code{integer len}
5603@item @emph{Interface}: @tab @code{subroutine acc_delete_async_finalize(a, async)}
5604@item @tab @code{type, dimension(:[,:]...) :: a}
5605@item @tab @code{integer(acc_handle_kind) :: async}
5606@item @emph{Interface}: @tab @code{subroutine acc_delete_async_finalize(a, len, async)}
5607@item @tab @code{type, dimension(:[,:]...) :: a}
5608@item @tab @code{integer len}
5609@item @tab @code{integer(acc_handle_kind) :: async}
5610@end multitable
5611
5612@item @emph{Reference}:
5613@uref{https://www.openacc.org, OpenACC specification v2.6}, section
56143.2.23.
5615@end table
5616
5617
5618
5619@node acc_update_device
5620@section @code{acc_update_device} -- Update device memory from mapped host memory.
5621@table @asis
5622@item @emph{Description}
5623This function updates the device copy from the previously mapped host memory.
5624The host memory is specified with the host address @var{a} and a length of
5625@var{len} bytes.
5626
5627In Fortran, two (2) forms are supported. In the first form, @var{a} specifies
5628a contiguous array section. The second form @var{a} specifies a variable or
5629array element and @var{len} specifies the length in bytes.
5630
5631@item @emph{C/C++}:
5632@multitable @columnfractions .20 .80
5633@item @emph{Prototype}: @tab @code{acc_update_device(h_void *a, size_t len);}
5634@item @emph{Prototype}: @tab @code{acc_update_device(h_void *a, size_t len, async);}
5635@end multitable
5636
5637@item @emph{Fortran}:
5638@multitable @columnfractions .20 .80
5639@item @emph{Interface}: @tab @code{subroutine acc_update_device(a)}
5640@item @tab @code{type, dimension(:[,:]...) :: a}
5641@item @emph{Interface}: @tab @code{subroutine acc_update_device(a, len)}
5642@item @tab @code{type, dimension(:[,:]...) :: a}
5643@item @tab @code{integer len}
5644@item @emph{Interface}: @tab @code{subroutine acc_update_device_async(a, async)}
5645@item @tab @code{type, dimension(:[,:]...) :: a}
5646@item @tab @code{integer(acc_handle_kind) :: async}
5647@item @emph{Interface}: @tab @code{subroutine acc_update_device_async(a, len, async)}
5648@item @tab @code{type, dimension(:[,:]...) :: a}
5649@item @tab @code{integer len}
5650@item @tab @code{integer(acc_handle_kind) :: async}
5651@end multitable
5652
5653@item @emph{Reference}:
5654@uref{https://www.openacc.org, OpenACC specification v2.6}, section
56553.2.24.
5656@end table
5657
5658
5659
5660@node acc_update_self
5661@section @code{acc_update_self} -- Update host memory from mapped device memory.
5662@table @asis
5663@item @emph{Description}
5664This function updates the host copy from the previously mapped device memory.
5665The host memory is specified with the host address @var{a} and a length of
5666@var{len} bytes.
5667
5668In Fortran, two (2) forms are supported. In the first form, @var{a} specifies
5669a contiguous array section. The second form @var{a} specifies a variable or
5670array element and @var{len} specifies the length in bytes.
5671
5672@item @emph{C/C++}:
5673@multitable @columnfractions .20 .80
5674@item @emph{Prototype}: @tab @code{acc_update_self(h_void *a, size_t len);}
5675@item @emph{Prototype}: @tab @code{acc_update_self_async(h_void *a, size_t len, int async);}
5676@end multitable
5677
5678@item @emph{Fortran}:
5679@multitable @columnfractions .20 .80
5680@item @emph{Interface}: @tab @code{subroutine acc_update_self(a)}
5681@item @tab @code{type, dimension(:[,:]...) :: a}
5682@item @emph{Interface}: @tab @code{subroutine acc_update_self(a, len)}
5683@item @tab @code{type, dimension(:[,:]...) :: a}
5684@item @tab @code{integer len}
5685@item @emph{Interface}: @tab @code{subroutine acc_update_self_async(a, async)}
5686@item @tab @code{type, dimension(:[,:]...) :: a}
5687@item @tab @code{integer(acc_handle_kind) :: async}
5688@item @emph{Interface}: @tab @code{subroutine acc_update_self_async(a, len, async)}
5689@item @tab @code{type, dimension(:[,:]...) :: a}
5690@item @tab @code{integer len}
5691@item @tab @code{integer(acc_handle_kind) :: async}
5692@end multitable
5693
5694@item @emph{Reference}:
5695@uref{https://www.openacc.org, OpenACC specification v2.6}, section
56963.2.25.
5697@end table
5698
5699
5700
5701@node acc_map_data
5702@section @code{acc_map_data} -- Map previously allocated device memory to host memory.
5703@table @asis
5704@item @emph{Description}
5705This function maps previously allocated device and host memory. The device
5706memory is specified with the device address @var{data_dev}. The host memory is
5707specified with the host address @var{data_arg} and a length of @var{bytes}.
5708
5709@item @emph{C/C++}:
5710@multitable @columnfractions .20 .80
5711@item @emph{Prototype}: @tab @code{void acc_map_data(h_void *data_arg, d_void *data_dev, size_t bytes);}
5712@end multitable
5713
5714@item @emph{Fortran}:
5715@multitable @columnfractions .20 .80
5716@item @emph{Interface}: @tab @code{subroutine acc_map_data(data_arg, data_dev, bytes)}
5717@item @tab @code{type(*), dimension(*) :: data_arg}
5718@item @tab @code{type(c_ptr), value :: data_dev}
5719@item @tab @code{integer(c_size_t), value :: bytes}
5720@end multitable
5721
5722@item @emph{Reference}:
5723@uref{https://www.openacc.org, OpenACC specification v2.6}, section
57243.2.26. @uref{https://www.openacc.org, OpenACC specification v3.3}, section
57253.2.21.
5726@end table
5727
5728
5729
5730@node acc_unmap_data
5731@section @code{acc_unmap_data} -- Unmap device memory from host memory.
5732@table @asis
5733@item @emph{Description}
5734This function unmaps previously mapped device and host memory. The latter
5735specified by @var{data_arg}.
5736
5737@item @emph{C/C++}:
5738@multitable @columnfractions .20 .80
5739@item @emph{Prototype}: @tab @code{void acc_unmap_data(h_void *data_arg);}
5740@end multitable
5741
5742@item @emph{Fortran}:
5743@multitable @columnfractions .20 .80
5744@item @emph{Interface}: @tab @code{subroutine acc_unmap_data(data_arg)}
5745@item @tab @code{type(*), dimension(*) :: data_arg}
5746@end multitable
5747
5748@item @emph{Reference}:
5749@uref{https://www.openacc.org, OpenACC specification v2.6}, section
57503.2.27. @uref{https://www.openacc.org, OpenACC specification v3.3}, section
57513.2.22.
5752@end table
5753
5754
5755
5756@node acc_deviceptr
5757@section @code{acc_deviceptr} -- Get device pointer associated with specific host address.
5758@table @asis
5759@item @emph{Description}
5760This function returns the device address that has been mapped to the
5761host address specified by @var{data_arg}.
5762
5763@item @emph{C/C++}:
5764@multitable @columnfractions .20 .80
5765@item @emph{Prototype}: @tab @code{void *acc_deviceptr(h_void *data_arg);}
5766@end multitable
5767
5768@item @emph{Fortran}:
5769@multitable @columnfractions .20 .80
5770@item @emph{Interface}: @tab @code{type(c_ptr) function acc_deviceptr(data_arg)}
5771@item @tab @code{type(*), dimension(*) :: data_arg}
5772@end multitable
5773
5774@item @emph{Reference}:
5775@uref{https://www.openacc.org, OpenACC specification v2.6}, section
57763.2.28. @uref{https://www.openacc.org, OpenACC specification v3.3}, section
57773.2.23.
5778@end table
5779
5780
5781
5782@node acc_hostptr
5783@section @code{acc_hostptr} -- Get host pointer associated with specific device address.
5784@table @asis
5785@item @emph{Description}
5786This function returns the host address that has been mapped to the
5787device address specified by @var{data_dev}.
5788
5789@item @emph{C/C++}:
5790@multitable @columnfractions .20 .80
5791@item @emph{Prototype}: @tab @code{void *acc_hostptr(d_void *data_dev);}
5792@end multitable
5793
5794@item @emph{Fortran}:
5795@multitable @columnfractions .20 .80
5796@item @emph{Interface}: @tab @code{type(c_ptr) function acc_hostptr(data_dev)}
5797@item @tab @code{type(c_ptr), value :: data_dev}
5798@end multitable
5799
5800@item @emph{Reference}:
5801@uref{https://www.openacc.org, OpenACC specification v2.6}, section
58023.2.29. @uref{https://www.openacc.org, OpenACC specification v3.3}, section
58033.2.24.
5804@end table
5805
5806
5807
5808@node acc_is_present
5809@section @code{acc_is_present} -- Indicate whether host variable / array is present on device.
5810@table @asis
5811@item @emph{Description}
5812This function indicates whether the specified host address in @var{a} and a
5813length of @var{len} bytes is present on the device. In C/C++, a non-zero
5814value is returned to indicate the presence of the mapped memory on the
5815device. A zero is returned to indicate the memory is not mapped on the
5816device.
5817
5818In Fortran, two (2) forms are supported. In the first form, @var{a} specifies
5819a contiguous array section. The second form @var{a} specifies a variable or
5820array element and @var{len} specifies the length in bytes. If the host
5821memory is mapped to device memory, then a @code{true} is returned. Otherwise,
5822a @code{false} is return to indicate the mapped memory is not present.
5823
5824@item @emph{C/C++}:
5825@multitable @columnfractions .20 .80
5826@item @emph{Prototype}: @tab @code{int acc_is_present(h_void *a, size_t len);}
5827@end multitable
5828
5829@item @emph{Fortran}:
5830@multitable @columnfractions .20 .80
5831@item @emph{Interface}: @tab @code{function acc_is_present(a)}
5832@item @tab @code{type, dimension(:[,:]...) :: a}
5833@item @tab @code{logical acc_is_present}
5834@item @emph{Interface}: @tab @code{function acc_is_present(a, len)}
5835@item @tab @code{type, dimension(:[,:]...) :: a}
5836@item @tab @code{integer len}
5837@item @tab @code{logical acc_is_present}
5838@end multitable
5839
5840@item @emph{Reference}:
5841@uref{https://www.openacc.org, OpenACC specification v2.6}, section
58423.2.30.
5843@end table
5844
5845
5846
5847@node acc_memcpy_to_device
5848@section @code{acc_memcpy_to_device} -- Copy host memory to device memory.
5849@table @asis
5850@item @emph{Description}
5851This function copies host memory specified by host address of
5852@var{data_host_src} to device memory specified by the device address
5853@var{data_dev_dest} for a length of @var{bytes} bytes.
5854
5855@item @emph{C/C++}:
5856@multitable @columnfractions .20 .80
5857@item @emph{Prototype}: @tab @code{void acc_memcpy_to_device(d_void* data_dev_dest,}
5858@item @tab @code{h_void* data_host_src, size_t bytes);}
5859@item @emph{Prototype}: @tab @code{void acc_memcpy_to_device_async(d_void* data_dev_dest,}
5860@item @tab @code{h_void* data_host_src, size_t bytes, int async_arg);}
5861@end multitable
5862
5863@item @emph{Fortran}:
5864@multitable @columnfractions .20 .80
5865@item @emph{Interface}: @tab @code{subroutine acc_memcpy_to_device(data_dev_dest, &}
5866@item @tab @code{data_host_src, bytes)}
5867@item @emph{Interface}: @tab @code{subroutine acc_memcpy_to_device_async(data_dev_dest, &}
5868@item @tab @code{data_host_src, bytes, async_arg)}
5869@item @tab @code{type(c_ptr), value :: data_dev_dest}
5870@item @tab @code{type(*), dimension(*) :: data_host_src}
5871@item @tab @code{integer(c_size_t), value :: bytes}
5872@item @tab @code{integer(acc_handle_kind), value :: async_arg}
5873@end multitable
5874
5875@item @emph{Reference}:
5876@uref{https://www.openacc.org, OpenACC specification v2.6}, section
58773.2.31 @uref{https://www.openacc.org, OpenACC specification v3.3}, section
58783.2.26.
5879@end table
5880
5881
5882
5883@node acc_memcpy_from_device
5884@section @code{acc_memcpy_from_device} -- Copy device memory to host memory.
5885@table @asis
5886@item @emph{Description}
5887This function copies device memory specified by device address of
5888@var{data_dev_src} to host memory specified by the host address
5889@var{data_host_dest} for a length of @var{bytes} bytes.
5890
5891@item @emph{C/C++}:
5892@multitable @columnfractions .20 .80
5893@item @emph{Prototype}: @tab @code{void acc_memcpy_from_device(h_void* data_host_dest,}
5894@item @tab @code{d_void* data_dev_src, size_t bytes);}
5895@item @emph{Prototype}: @tab @code{void acc_memcpy_from_device_async(h_void* data_host_dest,}
5896@item @tab @code{d_void* data_dev_src, size_t bytes, int async_arg);}
5897@end multitable
5898
5899@item @emph{Fortran}:
5900@multitable @columnfractions .20 .80
5901@item @emph{Interface}: @tab @code{subroutine acc_memcpy_from_device(data_host_dest, &}
5902@item @tab @code{data_dev_src, bytes)}
5903@item @emph{Interface}: @tab @code{subroutine acc_memcpy_from_device_async(data_host_dest, &}
5904@item @tab @code{data_dev_src, bytes, async_arg)}
5905@item @tab @code{type(*), dimension(*) :: data_host_dest}
5906@item @tab @code{type(c_ptr), value :: data_dev_src}
5907@item @tab @code{integer(c_size_t), value :: bytes}
5908@item @tab @code{integer(acc_handle_kind), value :: async_arg}
5909@end multitable
5910
5911@item @emph{Reference}:
5912@uref{https://www.openacc.org, OpenACC specification v2.6}, section
59133.2.32. @uref{https://www.openacc.org, OpenACC specification v3.3}, section
59143.2.27.
5915@end table
5916
5917
5918
5919@node acc_memcpy_device
5920@section @code{acc_memcpy_device} -- Copy memory within a device.
5921@table @asis
5922@item @emph{Description}
5923This function copies device memory from one memory location to another
5924on the current device. It copies @var{bytes} bytes of data from the device
5925address, specified by @var{data_dev_src}, to the device address
5926@var{data_dev_dest}. The @code{_async} version performs the transfer
5927asynchronously using the queue associated with @var{async_arg}.
5928
5929@item @emph{C/C++}:
5930@multitable @columnfractions .20 .80
5931@item @emph{Prototype}: @tab @code{void acc_memcpy_device(d_void* data_dev_dest,}
5932@item @tab @code{d_void* data_dev_src, size_t bytes);}
5933@item @emph{Prototype}: @tab @code{void acc_memcpy_device_async(d_void* data_dev_dest,}
5934@item @tab @code{d_void* data_dev_src, size_t bytes, int async_arg);}
5935@end multitable
5936
5937@item @emph{Fortran}:
5938@multitable @columnfractions .20 .80
5939@item @emph{Interface}: @tab @code{subroutine acc_memcpy_device(data_dev_dest, &}
5940@item @tab @code{data_dev_src, bytes)}
5941@item @emph{Interface}: @tab @code{subroutine acc_memcpy_device_async(data_dev_dest, &}
5942@item @tab @code{data_dev_src, bytes, async_arg)}
5943@item @tab @code{type(c_ptr), value :: data_dev_dest}
5944@item @tab @code{type(c_ptr), value :: data_dev_src}
5945@item @tab @code{integer(c_size_t), value :: bytes}
5946@item @tab @code{integer(acc_handle_kind), value :: async_arg}
5947@end multitable
5948
5949@item @emph{Reference}:
5950@uref{https://www.openacc.org, OpenACC specification v2.6}, section
59513.2.33. @uref{https://www.openacc.org, OpenACC specification v3.3}, section
59523.2.28.
5953@end table
5954
5955
5956
5957@node acc_attach
5958@section @code{acc_attach} -- Let device pointer point to device-pointer target.
5959@table @asis
5960@item @emph{Description}
5961This function updates a pointer on the device from pointing to a host-pointer
5962address to pointing to the corresponding device data.
5963
5964@item @emph{C/C++}:
5965@multitable @columnfractions .20 .80
5966@item @emph{Prototype}: @tab @code{void acc_attach(h_void **ptr_addr);}
5967@item @emph{Prototype}: @tab @code{void acc_attach_async(h_void **ptr_addr, int async);}
5968@end multitable
5969
5970@item @emph{Fortran}:
5971@multitable @columnfractions .20 .80
5972@item @emph{Interface}: @tab @code{subroutine acc_attach(ptr_addr)}
5973@item @emph{Interface}: @tab @code{subroutine acc_attach_async(ptr_addr, async_arg)}
5974@item @tab @code{type(*), dimension(..) :: ptr_addr}
5975@item @tab @code{integer(acc_handle_kind), value :: async_arg}
5976@end multitable
5977
5978@item @emph{Reference}:
5979@uref{https://www.openacc.org, OpenACC specification v2.6}, section
59803.2.34.
5981 @uref{https://www.openacc.org, OpenACC specification v3.3}, section
59823.2.29.
5983@end table
5984
5985
5986
5987@node acc_detach
5988@section @code{acc_detach} -- Let device pointer point to host-pointer target.
5989@table @asis
5990@item @emph{Description}
5991This function updates a pointer on the device from pointing to a device-pointer
5992address to pointing to the corresponding host data.
5993
5994@item @emph{C/C++}:
5995@multitable @columnfractions .20 .80
5996@item @emph{Prototype}: @tab @code{void acc_detach(h_void **ptr_addr);}
5997@item @emph{Prototype}: @tab @code{void acc_detach_async(h_void **ptr_addr, int async);}
5998@item @emph{Prototype}: @tab @code{void acc_detach_finalize(h_void **ptr_addr);}
5999@item @emph{Prototype}: @tab @code{void acc_detach_finalize_async(h_void **ptr_addr, int async);}
6000@end multitable
6001
6002@item @emph{Fortran}:
6003@multitable @columnfractions .20 .80
6004@item @emph{Interface}: @tab @code{subroutine acc_detach(ptr_addr)}
6005@item @emph{Interface}: @tab @code{subroutine acc_detach_async(ptr_addr, async_arg)}
6006@item @emph{Interface}: @tab @code{subroutine acc_detach_finalize(ptr_addr)}
6007@item @emph{Interface}: @tab @code{subroutine acc_detach_finalize_async(ptr_addr, async_arg)}
6008@item @tab @code{type(*), dimension(..) :: ptr_addr}
6009@item @tab @code{integer(acc_handle_kind), value :: async_arg}
6010@end multitable
6011
6012@item @emph{Reference}:
6013@uref{https://www.openacc.org, OpenACC specification v2.6}, section
60143.2.35.
6015@uref{https://www.openacc.org, OpenACC specification v3.3}, section
60163.2.29.
6017@end table
6018
6019
6020
6021@node acc_get_current_cuda_device
6022@section @code{acc_get_current_cuda_device} -- Get CUDA device handle.
6023@table @asis
6024@item @emph{Description}
6025This function returns the CUDA device handle. This handle is the same
6026as used by the CUDA Runtime or Driver API's.
6027
6028@item @emph{C/C++}:
6029@multitable @columnfractions .20 .80
6030@item @emph{Prototype}: @tab @code{void *acc_get_current_cuda_device(void);}
6031@end multitable
6032
6033@item @emph{Reference}:
6034@uref{https://www.openacc.org, OpenACC specification v2.6}, section
6035A.2.1.1.
6036@end table
6037
6038
6039
6040@node acc_get_current_cuda_context
6041@section @code{acc_get_current_cuda_context} -- Get CUDA context handle.
6042@table @asis
6043@item @emph{Description}
6044This function returns the CUDA context handle. This handle is the same
6045as used by the CUDA Runtime or Driver API's.
6046
6047@item @emph{C/C++}:
6048@multitable @columnfractions .20 .80
6049@item @emph{Prototype}: @tab @code{void *acc_get_current_cuda_context(void);}
6050@end multitable
6051
6052@item @emph{Reference}:
6053@uref{https://www.openacc.org, OpenACC specification v2.6}, section
6054A.2.1.2.
6055@end table
6056
6057
6058
6059@node acc_get_cuda_stream
6060@section @code{acc_get_cuda_stream} -- Get CUDA stream handle.
6061@table @asis
6062@item @emph{Description}
6063This function returns the CUDA stream handle for the queue @var{async}.
6064This handle is the same as used by the CUDA Runtime or Driver API's.
6065
6066@item @emph{C/C++}:
6067@multitable @columnfractions .20 .80
6068@item @emph{Prototype}: @tab @code{void *acc_get_cuda_stream(int async);}
6069@end multitable
6070
6071@item @emph{Reference}:
6072@uref{https://www.openacc.org, OpenACC specification v2.6}, section
6073A.2.1.3.
6074@end table
6075
6076
6077
6078@node acc_set_cuda_stream
6079@section @code{acc_set_cuda_stream} -- Set CUDA stream handle.
6080@table @asis
6081@item @emph{Description}
6082This function associates the stream handle specified by @var{stream} with
6083the queue @var{async}.
6084
6085This cannot be used to change the stream handle associated with
6086@code{acc_async_sync}.
6087
6088The return value is not specified.
6089
6090@item @emph{C/C++}:
6091@multitable @columnfractions .20 .80
6092@item @emph{Prototype}: @tab @code{int acc_set_cuda_stream(int async, void *stream);}
6093@end multitable
6094
6095@item @emph{Reference}:
6096@uref{https://www.openacc.org, OpenACC specification v2.6}, section
6097A.2.1.4.
6098@end table
6099
6100
6101
6102@node acc_prof_register
6103@section @code{acc_prof_register} -- Register callbacks.
6104@table @asis
6105@item @emph{Description}:
6106This function registers callbacks.
6107
6108@item @emph{C/C++}:
6109@multitable @columnfractions .20 .80
6110@item @emph{Prototype}: @tab @code{void acc_prof_register (acc_event_t, acc_prof_callback, acc_register_t);}
6111@end multitable
6112
6113@item @emph{See also}:
6114@ref{OpenACC Profiling Interface}
6115
6116@item @emph{Reference}:
6117@uref{https://www.openacc.org, OpenACC specification v2.6}, section
61185.3.
6119@end table
6120
6121
6122
6123@node acc_prof_unregister
6124@section @code{acc_prof_unregister} -- Unregister callbacks.
6125@table @asis
6126@item @emph{Description}:
6127This function unregisters callbacks.
6128
6129@item @emph{C/C++}:
6130@multitable @columnfractions .20 .80
6131@item @emph{Prototype}: @tab @code{void acc_prof_unregister (acc_event_t, acc_prof_callback, acc_register_t);}
6132@end multitable
6133
6134@item @emph{See also}:
6135@ref{OpenACC Profiling Interface}
6136
6137@item @emph{Reference}:
6138@uref{https://www.openacc.org, OpenACC specification v2.6}, section
61395.3.
6140@end table
6141
6142
6143
6144@node acc_prof_lookup
6145@section @code{acc_prof_lookup} -- Obtain inquiry functions.
6146@table @asis
6147@item @emph{Description}:
6148Function to obtain inquiry functions.
6149
6150@item @emph{C/C++}:
6151@multitable @columnfractions .20 .80
6152@item @emph{Prototype}: @tab @code{acc_query_fn acc_prof_lookup (const char *);}
6153@end multitable
6154
6155@item @emph{See also}:
6156@ref{OpenACC Profiling Interface}
6157
6158@item @emph{Reference}:
6159@uref{https://www.openacc.org, OpenACC specification v2.6}, section
61605.3.
6161@end table
6162
6163
6164
6165@node acc_register_library
6166@section @code{acc_register_library} -- Library registration.
6167@table @asis
6168@item @emph{Description}:
6169Function for library registration.
6170
6171@item @emph{C/C++}:
6172@multitable @columnfractions .20 .80
6173@item @emph{Prototype}: @tab @code{void acc_register_library (acc_prof_reg, acc_prof_reg, acc_prof_lookup_func);}
6174@end multitable
6175
6176@item @emph{See also}:
6177@ref{OpenACC Profiling Interface}, @ref{ACC_PROFLIB}
6178
6179@item @emph{Reference}:
6180@uref{https://www.openacc.org, OpenACC specification v2.6}, section
61815.3.
6182@end table
6183
6184
6185
6186@c ---------------------------------------------------------------------
6187@c OpenACC Environment Variables
6188@c ---------------------------------------------------------------------
6189
6190@node OpenACC Environment Variables
6191@chapter OpenACC Environment Variables
6192
6193The variables @env{ACC_DEVICE_TYPE} and @env{ACC_DEVICE_NUM}
6194are defined by section 4 of the OpenACC specification in version 2.0.
6195The variable @env{ACC_PROFLIB}
6196is defined by section 4 of the OpenACC specification in version 2.6.
6197
6198@menu
6199* ACC_DEVICE_TYPE::
6200* ACC_DEVICE_NUM::
6201* ACC_PROFLIB::
6202@end menu
6203
6204
6205
6206@node ACC_DEVICE_TYPE
6207@section @code{ACC_DEVICE_TYPE}
6208@table @asis
6209@item @emph{Description}:
6210Control the default device type to use when executing compute regions.
6211If unset, the code can be run on any device type, favoring a non-host
6212device type.
6213
6214Supported values in GCC (if compiled in) are
6215@itemize
6216@item @code{host}
6217@item @code{nvidia}
6218@item @code{radeon}
6219@end itemize
6220@item @emph{Reference}:
6221@uref{https://www.openacc.org, OpenACC specification v2.6}, section
62224.1.
6223@end table
6224
6225
6226
6227@node ACC_DEVICE_NUM
6228@section @code{ACC_DEVICE_NUM}
6229@table @asis
6230@item @emph{Description}:
6231Control which device, identified by device number, is the default device.
6232The value must be a nonnegative integer less than the number of devices.
6233If unset, device number zero is used.
6234@item @emph{Reference}:
6235@uref{https://www.openacc.org, OpenACC specification v2.6}, section
62364.2.
6237@end table
6238
6239
6240
6241@node ACC_PROFLIB
6242@section @code{ACC_PROFLIB}
6243@table @asis
6244@item @emph{Description}:
6245Semicolon-separated list of dynamic libraries that are loaded as profiling
6246libraries. Each library must provide at least the @code{acc_register_library}
6247routine. Each library file is found as described by the documentation of
6248@code{dlopen} of your operating system.
6249@item @emph{See also}:
6250@ref{acc_register_library}, @ref{OpenACC Profiling Interface}
6251
6252@item @emph{Reference}:
6253@uref{https://www.openacc.org, OpenACC specification v2.6}, section
62544.3.
6255@end table
6256
6257
6258
6259@c ---------------------------------------------------------------------
6260@c CUDA Streams Usage
6261@c ---------------------------------------------------------------------
6262
6263@node CUDA Streams Usage
6264@chapter CUDA Streams Usage
6265
6266This applies to the @code{nvptx} plugin only.
6267
6268The library provides elements that perform asynchronous movement of
6269data and asynchronous operation of computing constructs. This
6270asynchronous functionality is implemented by making use of CUDA
6271streams@footnote{See "Stream Management" in "CUDA Driver API",
6272TRM-06703-001, Version 5.5, for additional information}.
6273
6274The primary means by that the asynchronous functionality is accessed
6275is through the use of those OpenACC directives which make use of the
6276@code{async} and @code{wait} clauses. When the @code{async} clause is
6277first used with a directive, it creates a CUDA stream. If an
6278@code{async-argument} is used with the @code{async} clause, then the
6279stream is associated with the specified @code{async-argument}.
6280
6281Following the creation of an association between a CUDA stream and the
6282@code{async-argument} of an @code{async} clause, both the @code{wait}
6283clause and the @code{wait} directive can be used. When either the
6284clause or directive is used after stream creation, it creates a
6285rendezvous point whereby execution waits until all operations
6286associated with the @code{async-argument}, that is, stream, have
6287completed.
6288
6289Normally, the management of the streams that are created as a result of
6290using the @code{async} clause, is done without any intervention by the
6291caller. This implies the association between the @code{async-argument}
6292and the CUDA stream is maintained for the lifetime of the program.
6293However, this association can be changed through the use of the library
6294function @code{acc_set_cuda_stream}. When the function
6295@code{acc_set_cuda_stream} is called, the CUDA stream that was
6296originally associated with the @code{async} clause is destroyed.
6297Caution should be taken when changing the association as subsequent
6298references to the @code{async-argument} refer to a different
6299CUDA stream.
6300
6301
6302
6303@c ---------------------------------------------------------------------
6304@c OpenACC Library Interoperability
6305@c ---------------------------------------------------------------------
6306
6307@node OpenACC Library Interoperability
6308@chapter OpenACC Library Interoperability
6309
6310@section Introduction
6311
6312The OpenACC library uses the CUDA Driver API, and may interact with
6313programs that use the Runtime library directly, or another library
6314based on the Runtime library, e.g., CUBLAS@footnote{See section 2.26,
6315"Interactions with the CUDA Driver API" in
6316"CUDA Runtime API", Version 5.5, and section 2.27, "VDPAU
6317Interoperability", in "CUDA Driver API", TRM-06703-001, Version 5.5,
6318for additional information on library interoperability.}.
6319This chapter describes the use cases and what changes are
6320required in order to use both the OpenACC library and the CUBLAS and Runtime
6321libraries within a program.
6322
6323@section First invocation: NVIDIA CUBLAS library API
6324
6325In this first use case (see below), a function in the CUBLAS library is called
6326prior to any of the functions in the OpenACC library. More specifically, the
6327function @code{cublasCreate()}.
6328
6329When invoked, the function initializes the library and allocates the
6330hardware resources on the host and the device on behalf of the caller. Once
6331the initialization and allocation has completed, a handle is returned to the
6332caller. The OpenACC library also requires initialization and allocation of
6333hardware resources. Since the CUBLAS library has already allocated the
6334hardware resources for the device, all that is left to do is to initialize
6335the OpenACC library and acquire the hardware resources on the host.
6336
6337Prior to calling the OpenACC function that initializes the library and
6338allocate the host hardware resources, you need to acquire the device number
6339that was allocated during the call to @code{cublasCreate()}. The invoking of the
6340runtime library function @code{cudaGetDevice()} accomplishes this. Once
6341acquired, the device number is passed along with the device type as
6342parameters to the OpenACC library function @code{acc_set_device_num()}.
6343
6344Once the call to @code{acc_set_device_num()} has completed, the OpenACC
6345library uses the context that was created during the call to
6346@code{cublasCreate()}. In other words, both libraries share the
6347same context.
6348
6349@smallexample
6350 /* Create the handle */
6351 s = cublasCreate(&h);
6352 if (s != CUBLAS_STATUS_SUCCESS)
6353 @{
6354 fprintf(stderr, "cublasCreate failed %d\n", s);
6355 exit(EXIT_FAILURE);
6356 @}
6357
6358 /* Get the device number */
6359 e = cudaGetDevice(&dev);
6360 if (e != cudaSuccess)
6361 @{
6362 fprintf(stderr, "cudaGetDevice failed %d\n", e);
6363 exit(EXIT_FAILURE);
6364 @}
6365
6366 /* Initialize OpenACC library and use device 'dev' */
6367 acc_set_device_num(dev, acc_device_nvidia);
6368
6369@end smallexample
6370@center Use Case 1
6371
6372@section First invocation: OpenACC library API
6373
6374In this second use case (see below), a function in the OpenACC library is
6375called prior to any of the functions in the CUBLAS library. More specifically,
6376the function @code{acc_set_device_num()}.
6377
6378In the use case presented here, the function @code{acc_set_device_num()}
6379is used to both initialize the OpenACC library and allocate the hardware
6380resources on the host and the device. In the call to the function, the
6381call parameters specify which device to use and what device
6382type to use, i.e., @code{acc_device_nvidia}. It should be noted that this
6383is but one method to initialize the OpenACC library and allocate the
6384appropriate hardware resources. Other methods are available through the
6385use of environment variables and these is discussed in the next section.
6386
6387Once the call to @code{acc_set_device_num()} has completed, other OpenACC
6388functions can be called as seen with multiple calls being made to
6389@code{acc_copyin()}. In addition, calls can be made to functions in the
6390CUBLAS library. In the use case a call to @code{cublasCreate()} is made
6391subsequent to the calls to @code{acc_copyin()}.
6392As seen in the previous use case, a call to @code{cublasCreate()}
6393initializes the CUBLAS library and allocates the hardware resources on the
6394host and the device. However, since the device has already been allocated,
6395@code{cublasCreate()} only initializes the CUBLAS library and allocates
6396the appropriate hardware resources on the host. The context that was created
6397as part of the OpenACC initialization is shared with the CUBLAS library,
6398similarly to the first use case.
6399
6400@smallexample
6401 dev = 0;
6402
6403 acc_set_device_num(dev, acc_device_nvidia);
6404
6405 /* Copy the first set to the device */
6406 d_X = acc_copyin(&h_X[0], N * sizeof (float));
6407 if (d_X == NULL)
6408 @{
6409 fprintf(stderr, "copyin error h_X\n");
6410 exit(EXIT_FAILURE);
6411 @}
6412
6413 /* Copy the second set to the device */
6414 d_Y = acc_copyin(&h_Y1[0], N * sizeof (float));
6415 if (d_Y == NULL)
6416 @{
6417 fprintf(stderr, "copyin error h_Y1\n");
6418 exit(EXIT_FAILURE);
6419 @}
6420
6421 /* Create the handle */
6422 s = cublasCreate(&h);
6423 if (s != CUBLAS_STATUS_SUCCESS)
6424 @{
6425 fprintf(stderr, "cublasCreate failed %d\n", s);
6426 exit(EXIT_FAILURE);
6427 @}
6428
6429 /* Perform saxpy using CUBLAS library function */
6430 s = cublasSaxpy(h, N, &alpha, d_X, 1, d_Y, 1);
6431 if (s != CUBLAS_STATUS_SUCCESS)
6432 @{
6433 fprintf(stderr, "cublasSaxpy failed %d\n", s);
6434 exit(EXIT_FAILURE);
6435 @}
6436
6437 /* Copy the results from the device */
6438 acc_memcpy_from_device(&h_Y1[0], d_Y, N * sizeof (float));
6439
6440@end smallexample
6441@center Use Case 2
6442
6443@section OpenACC library and environment variables
6444
6445There are two environment variables associated with the OpenACC library
6446that may be used to control the device type and device number:
6447@env{ACC_DEVICE_TYPE} and @env{ACC_DEVICE_NUM}, respectively. These two
6448environment variables can be used as an alternative to calling
6449@code{acc_set_device_num()}. As seen in the second use case, the device
6450type and device number were specified using @code{acc_set_device_num()}.
6451If however, the aforementioned environment variables were set, then the
6452call to @code{acc_set_device_num()} would not be required.
6453
6454
6455The use of the environment variables is only relevant when an OpenACC function
6456is called prior to a call to @code{cudaCreate()}. If @code{cudaCreate()}
6457is called prior to a call to an OpenACC function, then you must call
6458@code{acc_set_device_num()}@footnote{More complete information
6459about @env{ACC_DEVICE_TYPE} and @env{ACC_DEVICE_NUM} can be found in
6460sections 4.1 and 4.2 of the @uref{https://www.openacc.org, OpenACC}
6461Application Programming Interface”, Version 2.6.}
6462
6463
6464
6465@c ---------------------------------------------------------------------
6466@c OpenACC Profiling Interface
6467@c ---------------------------------------------------------------------
6468
6469@node OpenACC Profiling Interface
6470@chapter OpenACC Profiling Interface
6471
6472@section Implementation Status and Implementation-Defined Behavior
6473
6474We're implementing the OpenACC Profiling Interface as defined by the
6475OpenACC 2.6 specification. We're clarifying some aspects here as
6476@emph{implementation-defined behavior}, while they're still under
6477discussion within the OpenACC Technical Committee.
6478
6479This implementation is tuned to keep the performance impact as low as
6480possible for the (very common) case that the Profiling Interface is
6481not enabled. This is relevant, as the Profiling Interface affects all
6482the @emph{hot} code paths (in the target code, not in the offloaded
6483code). Users of the OpenACC Profiling Interface can be expected to
6484understand that performance is impacted to some degree once the
6485Profiling Interface is enabled: for example, because of the
6486@emph{runtime} (libgomp) calling into a third-party @emph{library} for
6487every event that has been registered.
6488
6489We're not yet accounting for the fact that @cite{OpenACC events may
6490occur during event processing}.
6491We just handle one case specially, as required by CUDA 9.0
6492@command{nvprof}, that @code{acc_get_device_type}
6493(@ref{acc_get_device_type})) may be called from
6494@code{acc_ev_device_init_start}, @code{acc_ev_device_init_end}
6495callbacks.
6496
6497We're not yet implementing initialization via a
6498@code{acc_register_library} function that is either statically linked
6499in, or dynamically via @env{LD_PRELOAD}.
6500Initialization via @code{acc_register_library} functions dynamically
6501loaded via the @env{ACC_PROFLIB} environment variable does work, as
6502does directly calling @code{acc_prof_register},
6503@code{acc_prof_unregister}, @code{acc_prof_lookup}.
6504
6505As currently there are no inquiry functions defined, calls to
6506@code{acc_prof_lookup} always returns @code{NULL}.
6507
6508There aren't separate @emph{start}, @emph{stop} events defined for the
6509event types @code{acc_ev_create}, @code{acc_ev_delete},
6510@code{acc_ev_alloc}, @code{acc_ev_free}. It's not clear if these
6511should be triggered before or after the actual device-specific call is
6512made. We trigger them after.
6513
6514Remarks about data provided to callbacks:
6515
6516@table @asis
6517
6518@item @code{acc_prof_info.event_type}
6519It's not clear if for @emph{nested} event callbacks (for example,
6520@code{acc_ev_enqueue_launch_start} as part of a parent compute
6521construct), this should be set for the nested event
6522(@code{acc_ev_enqueue_launch_start}), or if the value of the parent
6523construct should remain (@code{acc_ev_compute_construct_start}). In
6524this implementation, the value generally corresponds to the
6525innermost nested event type.
6526
6527@item @code{acc_prof_info.device_type}
6528@itemize
6529
6530@item
6531For @code{acc_ev_compute_construct_start}, and in presence of an
6532@code{if} clause with @emph{false} argument, this still refers to
6533the offloading device type.
6534It's not clear if that's the expected behavior.
6535
6536@item
6537Complementary to the item before, for
6538@code{acc_ev_compute_construct_end}, this is set to
6539@code{acc_device_host} in presence of an @code{if} clause with
6540@emph{false} argument.
6541It's not clear if that's the expected behavior.
6542
6543@end itemize
6544
6545@item @code{acc_prof_info.thread_id}
6546Always @code{-1}; not yet implemented.
6547
6548@item @code{acc_prof_info.async}
6549@itemize
6550
6551@item
6552Not yet implemented correctly for
6553@code{acc_ev_compute_construct_start}.
6554
6555@item
6556In a compute construct, for host-fallback
6557execution/@code{acc_device_host} it always is
6558@code{acc_async_sync}.
6559It is unclear if that is the expected behavior.
6560
6561@item
6562For @code{acc_ev_device_init_start} and @code{acc_ev_device_init_end},
6563it will always be @code{acc_async_sync}.
6564It is unclear if that is the expected behavior.
6565
6566@end itemize
6567
6568@item @code{acc_prof_info.async_queue}
6569There is no @cite{limited number of asynchronous queues} in libgomp.
6570This always has the same value as @code{acc_prof_info.async}.
6571
6572@item @code{acc_prof_info.src_file}
6573Always @code{NULL}; not yet implemented.
6574
6575@item @code{acc_prof_info.func_name}
6576Always @code{NULL}; not yet implemented.
6577
6578@item @code{acc_prof_info.line_no}
6579Always @code{-1}; not yet implemented.
6580
6581@item @code{acc_prof_info.end_line_no}
6582Always @code{-1}; not yet implemented.
6583
6584@item @code{acc_prof_info.func_line_no}
6585Always @code{-1}; not yet implemented.
6586
6587@item @code{acc_prof_info.func_end_line_no}
6588Always @code{-1}; not yet implemented.
6589
6590@item @code{acc_event_info.event_type}, @code{acc_event_info.*.event_type}
6591Relating to @code{acc_prof_info.event_type} discussed above, in this
6592implementation, this will always be the same value as
6593@code{acc_prof_info.event_type}.
6594
6595@item @code{acc_event_info.*.parent_construct}
6596@itemize
6597
6598@item
6599Will be @code{acc_construct_parallel} for all OpenACC compute
6600constructs as well as many OpenACC Runtime API calls; should be the
6601one matching the actual construct, or
6602@code{acc_construct_runtime_api}, respectively.
6603
6604@item
6605Will be @code{acc_construct_enter_data} or
6606@code{acc_construct_exit_data} when processing variable mappings
6607specified in OpenACC @emph{declare} directives; should be
6608@code{acc_construct_declare}.
6609
6610@item
6611For implicit @code{acc_ev_device_init_start},
6612@code{acc_ev_device_init_end}, and explicit as well as implicit
6613@code{acc_ev_alloc}, @code{acc_ev_free},
6614@code{acc_ev_enqueue_upload_start}, @code{acc_ev_enqueue_upload_end},
6615@code{acc_ev_enqueue_download_start}, and
6616@code{acc_ev_enqueue_download_end}, will be
6617@code{acc_construct_parallel}; should reflect the real parent
6618construct.
6619
6620@end itemize
6621
6622@item @code{acc_event_info.*.implicit}
6623For @code{acc_ev_alloc}, @code{acc_ev_free},
6624@code{acc_ev_enqueue_upload_start}, @code{acc_ev_enqueue_upload_end},
6625@code{acc_ev_enqueue_download_start}, and
6626@code{acc_ev_enqueue_download_end}, this currently will be @code{1}
6627also for explicit usage.
6628
6629@item @code{acc_event_info.data_event.var_name}
6630Always @code{NULL}; not yet implemented.
6631
6632@item @code{acc_event_info.data_event.host_ptr}
6633For @code{acc_ev_alloc}, and @code{acc_ev_free}, this is always
6634@code{NULL}.
6635
6636@item @code{typedef union acc_api_info}
6637@dots{} as printed in @cite{5.2.3. Third Argument: API-Specific
6638Information}. This should obviously be @code{typedef @emph{struct}
6639acc_api_info}.
6640
6641@item @code{acc_api_info.device_api}
6642Possibly not yet implemented correctly for
6643@code{acc_ev_compute_construct_start},
6644@code{acc_ev_device_init_start}, @code{acc_ev_device_init_end}:
6645will always be @code{acc_device_api_none} for these event types.
6646For @code{acc_ev_enter_data_start}, it will be
6647@code{acc_device_api_none} in some cases.
6648
6649@item @code{acc_api_info.device_type}
6650Always the same as @code{acc_prof_info.device_type}.
6651
6652@item @code{acc_api_info.vendor}
6653Always @code{-1}; not yet implemented.
6654
6655@item @code{acc_api_info.device_handle}
6656Always @code{NULL}; not yet implemented.
6657
6658@item @code{acc_api_info.context_handle}
6659Always @code{NULL}; not yet implemented.
6660
6661@item @code{acc_api_info.async_handle}
6662Always @code{NULL}; not yet implemented.
6663
6664@end table
6665
6666Remarks about certain event types:
6667
6668@table @asis
6669
6670@item @code{acc_ev_device_init_start}, @code{acc_ev_device_init_end}
6671@itemize
6672
6673@item
6674@c See 'DEVICE_INIT_INSIDE_COMPUTE_CONSTRUCT' in
6675@c 'libgomp.oacc-c-c++-common/acc_prof-kernels-1.c',
6676@c 'libgomp.oacc-c-c++-common/acc_prof-parallel-1.c'.
6677When a compute construct triggers implicit
6678@code{acc_ev_device_init_start} and @code{acc_ev_device_init_end}
6679events, they currently aren't @emph{nested within} the corresponding
6680@code{acc_ev_compute_construct_start} and
6681@code{acc_ev_compute_construct_end}, but they're currently observed
6682@emph{before} @code{acc_ev_compute_construct_start}.
6683It's not clear what to do: the standard asks us provide a lot of
6684details to the @code{acc_ev_compute_construct_start} callback, without
6685(implicitly) initializing a device before?
6686
6687@item
6688Callbacks for these event types will not be invoked for calls to the
6689@code{acc_set_device_type} and @code{acc_set_device_num} functions.
6690It's not clear if they should be.
6691
6692@end itemize
6693
6694@item @code{acc_ev_enter_data_start}, @code{acc_ev_enter_data_end}, @code{acc_ev_exit_data_start}, @code{acc_ev_exit_data_end}
6695@itemize
6696
6697@item
6698Callbacks for these event types will also be invoked for OpenACC
6699@emph{host_data} constructs.
6700It's not clear if they should be.
6701
6702@item
6703Callbacks for these event types will also be invoked when processing
6704variable mappings specified in OpenACC @emph{declare} directives.
6705It's not clear if they should be.
6706
6707@end itemize
6708
6709@end table
6710
6711Callbacks for the following event types will be invoked, but dispatch
6712and information provided therein has not yet been thoroughly reviewed:
6713
6714@itemize
6715@item @code{acc_ev_alloc}
6716@item @code{acc_ev_free}
6717@item @code{acc_ev_update_start}, @code{acc_ev_update_end}
6718@item @code{acc_ev_enqueue_upload_start}, @code{acc_ev_enqueue_upload_end}
6719@item @code{acc_ev_enqueue_download_start}, @code{acc_ev_enqueue_download_end}
6720@end itemize
6721
6722During device initialization, and finalization, respectively,
6723callbacks for the following event types will not yet be invoked:
6724
6725@itemize
6726@item @code{acc_ev_alloc}
6727@item @code{acc_ev_free}
6728@end itemize
6729
6730Callbacks for the following event types have not yet been implemented,
6731so currently won't be invoked:
6732
6733@itemize
6734@item @code{acc_ev_device_shutdown_start}, @code{acc_ev_device_shutdown_end}
6735@item @code{acc_ev_runtime_shutdown}
6736@item @code{acc_ev_create}, @code{acc_ev_delete}
6737@item @code{acc_ev_wait_start}, @code{acc_ev_wait_end}
6738@end itemize
6739
6740For the following runtime library functions, not all expected
6741callbacks will be invoked (mostly concerning implicit device
6742initialization):
6743
6744@itemize
6745@item @code{acc_get_num_devices}
6746@item @code{acc_set_device_type}
6747@item @code{acc_get_device_type}
6748@item @code{acc_set_device_num}
6749@item @code{acc_get_device_num}
6750@item @code{acc_init}
6751@item @code{acc_shutdown}
6752@end itemize
6753
6754Aside from implicit device initialization, for the following runtime
6755library functions, no callbacks will be invoked for shared-memory
6756offloading devices (it's not clear if they should be):
6757
6758@itemize
6759@item @code{acc_malloc}
6760@item @code{acc_free}
6761@item @code{acc_copyin}, @code{acc_present_or_copyin}, @code{acc_copyin_async}
6762@item @code{acc_create}, @code{acc_present_or_create}, @code{acc_create_async}
6763@item @code{acc_copyout}, @code{acc_copyout_async}, @code{acc_copyout_finalize}, @code{acc_copyout_finalize_async}
6764@item @code{acc_delete}, @code{acc_delete_async}, @code{acc_delete_finalize}, @code{acc_delete_finalize_async}
6765@item @code{acc_update_device}, @code{acc_update_device_async}
6766@item @code{acc_update_self}, @code{acc_update_self_async}
6767@item @code{acc_map_data}, @code{acc_unmap_data}
6768@item @code{acc_memcpy_to_device}, @code{acc_memcpy_to_device_async}
6769@item @code{acc_memcpy_from_device}, @code{acc_memcpy_from_device_async}
6770@end itemize
6771
6772@c ---------------------------------------------------------------------
6773@c OpenMP-Implementation Specifics
6774@c ---------------------------------------------------------------------
6775
6776@node OpenMP-Implementation Specifics
6777@chapter OpenMP-Implementation Specifics
6778
6779@menu
6780* Implementation-defined ICV Initialization::
6781* OpenMP Context Selectors::
6782* Memory allocation::
6783@end menu
6784
6785@node Implementation-defined ICV Initialization
6786@section Implementation-defined ICV Initialization
6787@cindex Implementation specific setting
6788
6789@multitable @columnfractions .30 .70
6790@item @var{affinity-format-var} @tab See @ref{OMP_AFFINITY_FORMAT}.
6791@item @var{def-allocator-var} @tab See @ref{OMP_ALLOCATOR}.
6792@item @var{max-active-levels-var} @tab See @ref{OMP_MAX_ACTIVE_LEVELS}.
6793@item @var{dyn-var} @tab See @ref{OMP_DYNAMIC}.
6794@item @var{nthreads-var} @tab See @ref{OMP_NUM_THREADS}.
6795@item @var{num-devices-var} @tab Number of non-host devices found
6796by GCC's run-time library
6797@item @var{num-procs-var} @tab The number of CPU cores on the
6798initial device, except that affinity settings might lead to a
6799smaller number. On non-host devices, the value of the
6800@var{nthreads-var} ICV.
6801@item @var{place-partition-var} @tab See @ref{OMP_PLACES}.
6802@item @var{run-sched-var} @tab See @ref{OMP_SCHEDULE}.
6803@item @var{stacksize-var} @tab See @ref{OMP_STACKSIZE}.
6804@item @var{thread-limit-var} @tab See @ref{OMP_TEAMS_THREAD_LIMIT}
6805@item @var{wait-policy-var} @tab See @ref{OMP_WAIT_POLICY} and
6806@ref{GOMP_SPINCOUNT}
6807@end multitable
6808
6809@node OpenMP Context Selectors
6810@section OpenMP Context Selectors
6811
6812@code{vendor} is always @code{gnu}. References are to the GCC manual.
6813
6814@c NOTE: Only the following selectors have been implemented. To add
6815@c additional traits for target architecture, TARGET_OMP_DEVICE_KIND_ARCH_ISA
6816@c has to be implemented; cf. also PR target/105640.
6817@c For offload devices, add *additionally* gcc/config/*/t-omp-device.
6818
6819For the host compiler, @code{kind} always matches @code{host}, @code{cpu}
6820and @code{any}; for the offloading architectures AMD GCN and Nvidia PTX,
6821@code{kind} always matches @code{nohost}, @code{gpu} and @code{any}.
6822For the x86 family of computers, AMD GCN and Nvidia PTX
6823the following traits are supported in addition; while OpenMP is supported
6824on more architectures, GCC currently does not match any @code{arch} or
6825@code{isa} traits for those.
6826
6827@multitable @columnfractions .65 .30
6828@headitem @code{arch} @tab @code{isa}
6829@item @code{x86}, @code{x86_64}, @code{i386}, @code{i486},
6830 @code{i586}, @code{i686}, @code{ia32}
6831 @tab See @code{-m...} flags in ``x86 Options'' (without @code{-m})
6832@item @code{amdgcn}, @code{gcn}
6833 @tab See @code{-march=} in ``AMD GCN Options''
6834@item @code{nvptx}, @code{nvptx64}
6835 @tab See @code{-march=} in ``Nvidia PTX Options''
6836@end multitable
6837
6838
6839@node Memory allocation
6840@section Memory allocation
6841
6842The description below applies to:
6843
6844@itemize
6845@item Explicit use of the OpenMP API routines, see
6846 @ref{Memory Management Routines}.
6847@item The @code{allocate} clause, except when the @code{allocator} modifier is a
6848 constant expression with value @code{omp_default_mem_alloc} and no
6849 @code{align} modifier has been specified. (In that case, the normal
6850 @code{malloc} allocation is used.)
6851@item The @code{allocate} directive for variables in static memory; while
6852 the alignment is honored, the normal static memory is used.
6853@item Using the @code{allocate} directive for automatic/stack variables, except
6854 when the @code{allocator} clause is a constant expression with value
6855 @code{omp_default_mem_alloc} and no @code{align} clause has been
6856 specified. (In that case, the normal allocation is used: stack allocation
6857 and, sometimes for Fortran, also @code{malloc} [depending on flags such as
6858 @option{-fstack-arrays}].)
6859@item In Fortran, the @code{allocators} directive and the executable
6860 @code{allocate} directive for Fortran pointers and allocatables is
6861 supported, but requires that files containing those directives has to be
6862 compiled with @option{-fopenmp-allocators}. Additionally, all files that
6863 might explicitly or implicitly deallocate memory allocated that way must
6864 also be compiled with that option.
6865@item The used alignment is the maximum of the value the @code{align} clause
6866 and the alignment of the type after honoring, if present, the
6867 @code{aligned} (@code{GNU::aligned}) attribute and C's @code{_Alignas}
6868 and C++'s @code{alignas}. However, the @code{align} clause of the
6869 @code{allocate} directive has no effect on the value of C's
6870 @code{_Alignof} and C++'s @code{alignof}.
6871@end itemize
6872
6873GCC supports the following predefined allocators and predefined memory spaces:
6874
6875@multitable @columnfractions .45 .45
6876@headitem Predefined allocators @tab Associated predefined memory spaces
6877@item omp_default_mem_alloc @tab omp_default_mem_space
6878@item omp_large_cap_mem_alloc @tab omp_large_cap_mem_space
6879@item omp_const_mem_alloc @tab omp_const_mem_space
6880@item omp_high_bw_mem_alloc @tab omp_high_bw_mem_space
6881@item omp_low_lat_mem_alloc @tab omp_low_lat_mem_space
6882@item omp_cgroup_mem_alloc @tab omp_low_lat_mem_space (implementation defined)
6883@item omp_pteam_mem_alloc @tab omp_low_lat_mem_space (implementation defined)
6884@item omp_thread_mem_alloc @tab omp_low_lat_mem_space (implementation defined)
6885@item ompx_gnu_pinned_mem_alloc @tab omp_default_mem_space (GNU extension)
6886@end multitable
6887
6888Each predefined allocator, including @code{omp_null_allocator}, has a corresponding
6889allocator class template that meet the C++ allocator completeness requirements.
6890These are located in the @code{omp::allocator} namespace, and the
6891@code{ompx::allocator} namespace for gnu extensions. This allows the
6892allocator-aware C++ standard library containers to use OpenMP allocation routines;
6893for instance:
6894
6895@smallexample
6896std::vector<int, omp::allocator::cgroup_mem<int>> vec;
6897@end smallexample
6898
6899The following allocator templates are supported:
6900
6901@multitable @columnfractions .45 .45
6902@headitem Predefined allocators @tab Associated allocator template
6903@item omp_null_allocator @tab omp::allocator::null_allocator
6904@item omp_default_mem_alloc @tab omp::allocator::default_mem
6905@item omp_large_cap_mem_alloc @tab omp::allocator::large_cap_mem
6906@item omp_const_mem_alloc @tab omp::allocator::const_mem
6907@item omp_high_bw_mem_alloc @tab omp::allocator::high_bw_mem
6908@item omp_low_lat_mem_alloc @tab omp::allocator::low_lat_mem
6909@item omp_cgroup_mem_alloc @tab omp::allocator::cgroup_mem
6910@item omp_pteam_mem_alloc @tab omp::allocator::pteam_mem
6911@item omp_thread_mem_alloc @tab omp::allocator::thread_mem
6912@item ompx_gnu_pinned_mem_alloc @tab ompx::allocator::gnu_pinned_mem
6913@end multitable
6914
6915The following traits are available when constructing a new allocator;
6916if a trait is not specified or with the value @code{default}, the
6917specified default value is used for that trait. The predefined
6918allocators use the default values of each trait, except that the
6919@code{omp_cgroup_mem_alloc}, @code{omp_pteam_mem_alloc}, and
6920@code{omp_thread_mem_alloc} allocators have the @code{access} trait
6921set to @code{cgroup}, @code{pteam}, and @code{thread}, respectively.
6922For each trait, a named constant prefixed by @code{omp_atk_} exists;
6923for each non-numeric value, a named constant prefixed by @code{omp_atv_}
6924exists.
6925
6926@multitable @columnfractions .25 .40 .25
6927@headitem Trait @tab Allowed values @tab Default value
6928@item @code{sync_hint} @tab @code{contended}, @code{uncontended},
6929 @code{serialized}, @code{private}
6930 @tab @code{contended}
6931@item @code{alignment} @tab Positive integer being a power of two
6932 @tab 1 byte
6933@item @code{access} @tab @code{all}, @code{cgroup},
6934 @code{pteam}, @code{thread}
6935 @tab @code{all}
6936@item @code{pool_size} @tab Positive integer (bytes)
6937 @tab See below.
6938@item @code{fallback} @tab @code{default_mem_fb}, @code{null_fb},
6939 @code{abort_fb}, @code{allocator_fb}
6940 @tab See below
6941@item @code{fb_data} @tab @emph{allocator handle}
6942 @tab (none)
6943@item @code{pinned} @tab @code{true}, @code{false}
6944 @tab See below
6945@item @code{partition} @tab @code{environment}, @code{nearest},
6946 @code{blocked}, @code{interleaved}
6947 @tab @code{environment}
6948@end multitable
6949
6950For the @code{fallback} trait, the default value is @code{null_fb} for the
6951@code{omp_default_mem_alloc} allocator and any allocator that is associated
6952with device memory; for all other allocators, it is @code{default_mem_fb}
6953by default.
6954
6955For the @code{pinned} trait, the default value is @code{true} for
6956predefined allocator @code{ompx_gnu_pinned_mem_alloc} (a GNU extension), and
6957@code{false} for all others.
6958
6959The following description applies to the initial device (the host) and largely
6960also to non-host devices; for the latter, also see @ref{Offload-Target Specifics}.
6961
6962For the memory spaces, the following applies:
6963@itemize
6964@item @code{omp_default_mem_space} is supported
6965@item @code{omp_const_mem_space} maps to @code{omp_default_mem_space}
6966@item @code{omp_low_lat_mem_space} is only available on supported devices,
6967 and maps to @code{omp_default_mem_space} otherwise.
6968@item @code{omp_large_cap_mem_space} maps to @code{omp_default_mem_space},
6969 unless the memkind library is available
6970@item @code{omp_high_bw_mem_space} maps to @code{omp_default_mem_space},
6971 unless the memkind library is available
6972@end itemize
6973
6974On Linux systems, where the @uref{https://github.com/memkind/memkind, memkind
6975library} (@code{libmemkind.so.0}) is available at runtime and the respective
6976memkind kind is supported, it is used when creating memory allocators requesting
6977
6978@itemize
6979@item the @code{partition} trait @code{interleaved} except when the memory space
6980 is @code{omp_large_cap_mem_space} (uses @code{MEMKIND_HBW_INTERLEAVE})
6981@item the memory space is @code{omp_high_bw_mem_space} (uses
6982 @code{MEMKIND_HBW_PREFERRED})
6983@item the memory space is @code{omp_large_cap_mem_space} (uses
6984 @code{MEMKIND_DAX_KMEM_ALL} or, if not available, @code{MEMKIND_DAX_KMEM})
6985@end itemize
6986
6987On Linux systems, where the @uref{https://github.com/numactl/numactl, numa
6988library} (@code{libnuma.so.1}) is available at runtime, it used when creating
6989memory allocators requesting
6990
6991@itemize
6992@item the @code{partition} trait @code{nearest}, except when both the
6993libmemkind library is available and the memory space is either
6994@code{omp_large_cap_mem_space} or @code{omp_high_bw_mem_space}
6995@end itemize
6996
6997Note that the numa library will round up the allocation size to a multiple of
6998the system page size; therefore, consider using it only with large data or
6999by sharing allocations via the @code{pool_size} trait. Furthermore, the Linux
7000kernel does not guarantee that an allocation will always be on the nearest NUMA
7001node nor that after reallocation the same node will be used. Note additionally
7002that, on Linux, the default setting of the memory placement policy is to use the
7003current node; therefore, unless the memory placement policy has been overridden,
7004the @code{partition} trait @code{environment} (the default) will be effectively
7005a @code{nearest} allocation.
7006
7007Additional notes regarding the traits:
7008@itemize
7009@item The @code{pinned} trait is supported on Linux hosts, but is subject to
7010 the OS @code{ulimit}/@code{rlimit} locked memory settings. It currently
7011 uses @code{mmap} and is therefore optimized for few allocations, including
7012 large data. If the conditions for numa or memkind allocations are
7013 fulfilled, those allocators are used instead.
7014@item The default for the @code{pool_size} trait is no pool and for every
7015 (re)allocation the associated library routine is called, which might
7016 internally use a memory pool. Currently, the same applies when a
7017 @code{pool_size} has been specified, except that once allocations exceed
7018 the the pool size, the action of the @code{fallback} trait applies.
7019@item For the @code{partition} trait, the partition part size will be the same
7020 as the requested size (i.e. @code{interleaved} or @code{blocked} has no
7021 effect), except for @code{interleaved} when the memkind library is
7022 available. Furthermore, for @code{nearest} and unless the numa library
7023 is available, the memory might not be on the same NUMA node as thread
7024 that allocated the memory; on Linux, this is in particular the case when
7025 the memory placement policy is set to preferred.
7026@item The @code{access} trait has no effect such that memory is always
7027 accessible by all threads. (Except on supported no-host devices.)
7028@item The @code{sync_hint} trait has no effect.
7029@end itemize
7030
7031See also:
7032@ref{Offload-Target Specifics}
7033
7034
7035
7036@c ---------------------------------------------------------------------
7037@c Offload-Target Specifics
7038@c ---------------------------------------------------------------------
7039
7040@node Offload-Target Specifics
7041@chapter Offload-Target Specifics
7042
7043The following sections present notes on the offload-target specifics
7044
7045@menu
7046* AMD Radeon::
7047* nvptx::
7048@end menu
7049
7050@node AMD Radeon
7051@section AMD Radeon (GCN)
7052
7053@menu
7054* Foreign-runtime support for AMD GPUs::
7055@end menu
7056
7057On the hardware side, there is the hierarchy (fine to coarse):
7058@itemize
7059@item work item (thread)
7060@item wavefront
7061@item work group
7062@item compute unit (CU)
7063@end itemize
7064
7065All OpenMP and OpenACC levels are used, i.e.
7066@itemize
7067@item OpenMP's simd and OpenACC's vector map to work items (thread)
7068@item OpenMP's threads (``parallel'') and OpenACC's workers map
7069 to wavefronts
7070@item OpenMP's teams and OpenACC's gang use a threadpool with the
7071 size of the number of teams or gangs, respectively.
7072@end itemize
7073
7074The used sizes are
7075@itemize
7076@item Number of teams is the specified @code{num_teams} (OpenMP) or
7077 @code{num_gangs} (OpenACC) or otherwise the number of CU. It is limited
7078 by two times the number of CU.
7079@item Number of wavefronts is 4 for gfx900 and 16 otherwise;
7080 @code{num_threads} (OpenMP) and @code{num_workers} (OpenACC)
7081 overrides this if smaller.
7082@item The wavefront has 102 scalars and 64 vectors
7083@item Number of workitems is always 64
7084@item The hardware permits maximally 40 workgroups/CU and
7085 16 wavefronts/workgroup up to a limit of 40 wavefronts in total per CU.
7086@item 80 scalars registers and 24 vector registers in non-kernel functions
7087 (the chosen procedure-calling API).
7088@item For the kernel itself: as many as register pressure demands (number of
7089 teams and number of threads, scaled down if registers are exhausted)
7090@end itemize
7091
7092The implementation remark:
7093@itemize
7094@item I/O within OpenMP target regions and OpenACC compute regions is supported
7095 using the C library @code{printf} functions and the Fortran
7096 @code{print}/@code{write} statements.
7097@item Reverse offload regions (i.e. @code{target} regions with
7098 @code{device(ancestor:1)}) are processed serially per @code{target} region
7099 such that the next reverse offload region is only executed after the previous
7100 one returned.
7101@item OpenMP code that has a @code{requires} directive with @code{self_maps} or
7102 @code{unified_shared_memory} is only supported if all AMD GPUs have the
7103 @code{HSA_AMD_SYSTEM_INFO_SVM_ACCESSIBLE_BY_DEFAULT} property; for
7104 discrete GPUs, this may require setting the @code{HSA_XNACK} environment
7105 variable to @samp{1}; for systems with both an APU and a discrete GPU that
7106 does not support XNACK, consider using @code{ROCR_VISIBLE_DEVICES} to
7107 enable only the APU. If not supported, all AMD GPU devices are removed
7108 from the list of available devices (``host fallback'').
7109@item The available stack size can be changed using the @code{GCN_STACK_SIZE}
7110 environment variable; the default is 32 kiB per thread.
7111@item Low-latency memory (@code{omp_low_lat_mem_space}) is supported when the
7112 the @code{access} trait is set to @code{cgroup}. The default pool size
7113 is automatically scaled to share the 64 kiB LDS memory between the number
7114 of teams configured to run on each compute-unit, but may be adjusted at
7115 runtime by setting environment variable
7116 @code{GOMP_GCN_LOWLAT_POOL=@var{bytes}}.
7117@item @code{omp_low_lat_mem_alloc} cannot be used with true low-latency memory
7118 because the definition implies the @code{omp_atv_all} trait; main
7119 graphics memory is used instead.
7120@item @code{omp_cgroup_mem_alloc}, @code{omp_pteam_mem_alloc}, and
7121 @code{omp_thread_mem_alloc}, all use low-latency memory as first
7122 preference, and fall back to main graphics memory when the low-latency
7123 pool is exhausted.
7124@item The OpenMP routines @code{omp_target_memcpy_rect} and
7125 @code{omp_target_memcpy_rect_async} and the @code{target update}
7126 directive for non-contiguous list items use the 3D memory-copy function
7127 of the HSA library. Higher dimensions call this functions in a loop and
7128 are therefore supported.
7129@item The unique identifier (UID), used with OpenMP's API UID routines, is the
7130 value returned by the HSA runtime library for @code{HSA_AMD_AGENT_INFO_UUID}.
7131 For GPUs, it is currently @samp{GPU-} followed by 16 lower-case hex digits,
7132 yielding a string like @code{GPU-f914a2142fc3413a}. The output matches
7133 the one used by @code{rocminfo}.
7134@end itemize
7135
7136
7137@node Foreign-runtime support for AMD GPUs
7138@subsection OpenMP @code{interop} -- Foreign-Runtime Support for AMD GPUs
7139
7140On AMD GPUs, the foreign runtimes are HIP (C++ Heterogeneous-Compute Interface
7141for Portability) and HSA (Heterogeneous System Architecture),
7142where HIP is the default. The interop object is created using OpenMP's
7143@code{interop} directive or, implicitly, when invoking a @code{declare variant}
7144procedure that has the @code{append_args} clause. In either case, the
7145@code{prefer_type} modifier determines whether HIP or HSA is used.
7146
7147When specifying the @code{targetsync} modifier: For HIP, a stream is
7148created using @code{hipStreamCreate}. For HSA, a queue is created of type
7149@code{HSA_QUEUE_TYPE_MULTI} with a queue size of 64.
7150
7151Invoke the @ref{Interoperability Routines} on an interop object to obtain
7152the following properties. For properties with integral (int), pointer (ptr),
7153or string (str) data type, call @code{omp_get_interop_int},
7154@code{omp_get_interop_ptr}, or @code{omp_get_interop_str}, respectively.
7155Note that @code{device_num} is the OpenMP device number
7156while @code{device} is the HIP device number or HSA device handle.
7157
7158When using HIP with C and C++, the @code{__HIP_PLATFORM_AMD__} preprocessor
7159macro must be defined before including the HIP header files.
7160
7161For the API routine call, add the prefix @code{omp_ipr_} to the property name;
7162for instance:
7163@smallexample
7164omp_interop_rc_t ret;
7165int device_num = omp_get_interop_int (my_interop_obj, omp_ipr_device_num, &ret);
7166@end smallexample
7167
7168@noindent
7169Available properties for an HIP interop object:
7170
7171@multitable @columnfractions .20 .35 .20 .20
7172@headitem Property @tab C data type @tab API routine @tab value (if constant)
7173@item @code{fr_id} @tab @code{omp_interop_fr_t} @tab int @tab @code{omp_fr_hip}
7174@item @code{fr_name} @tab @code{const char *} @tab str @tab @code{"hip"}
7175@item @code{vendor} @tab @code{int} @tab int @tab @code{1}
7176@item @code{vendor_name} @tab @code{const char *} @tab str @tab @code{"amd"}
7177@item @code{device_num} @tab @code{int} @tab int @tab
7178@item @code{platform} @tab N/A @tab @tab
7179@item @code{device} @tab @code{hipDevice_t} @tab int @tab
7180@item @code{device_context} @tab @code{hipCtx_t} @tab ptr @tab
7181@item @code{targetsync} @tab @code{hipStream_t} @tab ptr @tab
7182@end multitable
7183
7184@noindent
7185Available properties for an HSA interop object:
7186
7187@multitable @columnfractions .20 .35 .20 .20
7188@headitem Property @tab C data type @tab API routine @tab value (if constant)
7189@item @code{fr_id} @tab @code{omp_interop_fr_t} @tab int @tab @code{omp_fr_hsa}
7190@item @code{fr_name} @tab @code{const char *} @tab str @tab @code{"hsa"}
7191@item @code{vendor} @tab @code{int} @tab int @tab @code{1}
7192@item @code{vendor_name} @tab @code{const char *} @tab str @tab @code{"amd"}
7193@item @code{device_num} @tab @code{int} @tab int @tab
7194@item @code{platform} @tab N/A @tab @tab
7195@item @code{device} @tab @code{hsa_agent *} @tab ptr @tab
7196@item @code{device_context} @tab N/A @tab @tab
7197@item @code{targetsync} @tab @code{hsa_queue *} @tab ptr @tab
7198@end multitable
7199
7200
7201
7202@node nvptx
7203@section nvptx
7204
7205@menu
7206* Foreign-runtime support for Nvidia GPUs::
7207@end menu
7208
7209On the hardware side, there is the hierarchy (fine to coarse):
7210@itemize
7211@item thread
7212@item warp
7213@item thread block
7214@item streaming multiprocessor
7215@end itemize
7216
7217All OpenMP and OpenACC levels are used, i.e.
7218@itemize
7219@item OpenMP's simd and OpenACC's vector map to threads
7220@item OpenMP's threads (``parallel'') and OpenACC's workers map to warps
7221@item OpenMP's teams and OpenACC's gang use a threadpool with the
7222 size of the number of teams or gangs, respectively.
7223@end itemize
7224
7225The used sizes are
7226@itemize
7227@item The @code{warp_size} is always 32
7228@item CUDA kernel launched: @code{dim=@{#teams,1,1@}, blocks=@{#threads,warp_size,1@}}.
7229@item The number of teams is limited by the number of blocks the device can
7230 host simultaneously.
7231@end itemize
7232
7233Additional information can be obtained by setting the environment variable to
7234@code{GOMP_DEBUG=1} (very verbose; grep for @code{kernel.*launch} for launch
7235parameters).
7236
7237GCC generates generic PTX ISA code, which is just-in-time compiled by CUDA,
7238which caches the JIT in the user's directory (see CUDA documentation; can be
7239tuned by the environment variables @code{CUDA_CACHE_@{DISABLE,MAXSIZE,PATH@}}.
7240
7241Note: While PTX ISA is generic, the @code{-mptx=} and @code{-march=} commandline
7242options still affect the used PTX ISA code and, thus, the requirements on
7243CUDA version and hardware.
7244
7245The implementation remark:
7246@itemize
7247@item I/O within OpenMP target regions and OpenACC compute regions is supported
7248 using the C library @code{printf} functions.
7249 Additionally, the Fortran @code{print}/@code{write} statements are
7250 supported within OpenMP target regions, but not yet within OpenACC compute
7251 regions. @c The latter needs 'GOMP_NVPTX_NATIVE_GPU_THREAD_STACK_SIZE'.
7252@item Compilation OpenMP code that contains @code{requires reverse_offload}
7253 requires at least @code{-march=sm_35}, compiling for @code{-march=sm_30}
7254 is not supported.
7255@item For code containing reverse offload (i.e. @code{target} regions with
7256 @code{device(ancestor:1)}), there is a slight performance penalty
7257 for @emph{all} target regions, consisting mostly of shutdown delay
7258 Per device, reverse offload regions are processed serially such that
7259 the next reverse offload region is only executed after the previous
7260 one returned.
7261@item OpenMP code that has a @code{requires} directive with @code{self_maps} or
7262 @code{unified_shared_memory} runs on nvptx devices if and only if
7263 all of those support the @code{pageableMemoryAccess} property;@footnote{
7264 @uref{https://docs.nvidia.com/cuda/cuda-c-programming-guide/index.html#um-requirements}}
7265 otherwise, all nvptx device are removed from the list of available
7266 devices (``host fallback'').
7267@item The default per-warp stack size is 128 kiB; see also @code{-msoft-stack}
7268 in the GCC manual.
7269@item Low-latency memory (@code{omp_low_lat_mem_space}) is supported when the
7270 the @code{access} trait is set to @code{cgroup}, and libgomp has
7271 been built for PTX ISA version 4.1 or higher (such as in GCC's
7272 default configuration). @c -mptx=4.1
7273 The default pool size
7274 is 8 kiB per team, but may be adjusted at runtime by setting environment
7275 variable @code{GOMP_NVPTX_LOWLAT_POOL=@var{bytes}}. The maximum value is
7276 limited by the available hardware, and care should be taken that the
7277 selected pool size does not unduly limit the number of teams that can
7278 run simultaneously.
7279@item @code{omp_low_lat_mem_alloc} cannot be used with true low-latency memory
7280 because the definition implies the @code{omp_atv_all} trait; main
7281 graphics memory is used instead.
7282@item @code{omp_cgroup_mem_alloc}, @code{omp_pteam_mem_alloc}, and
7283 @code{omp_thread_mem_alloc}, all use low-latency memory as first
7284 preference, and fall back to main graphics memory when the low-latency
7285 pool is exhausted.
7286@item The OpenMP routines @code{omp_target_memcpy_rect} and
7287 @code{omp_target_memcpy_rect_async} and the @code{target update}
7288 directive for non-contiguous list items use the 2D and 3D memory-copy
7289 functions of the CUDA library. Higher dimensions call those functions
7290 in a loop and are therefore supported.
7291@item The unique identifier (UID), used with OpenMP's API UID routines, consists
7292 of the @samp{GPU-} prefix followed by the 16-bytes UUID as returned by
7293 the CUDA runtime library. This UUID is output in grouped lower-case
7294 hex digits; the grouping of those 32 digits is: 8 digits, hyphen,
7295 4 digits, hyphen, 4 digits, hyphen, 16 digits. This leads to a string
7296 like @code{GPU-a8081c9e-f03e-18eb-1827-bf5ba95afa5d}. The output
7297 matches the format used by @code{nvidia-smi}.
7298@end itemize
7299
7300
7301@node Foreign-runtime support for Nvidia GPUs
7302@subsection OpenMP @code{interop} -- Foreign-Runtime Support for Nvidia GPUs
7303
7304On Nvidia GPUs, the foreign runtimes APIs are the CUDA runtime API, the CUDA
7305driver API, and HIP, the C++ Heterogeneous-Compute Interface for Portability
7306that is---on CUDA-based systems---a very thin layer on top of the CUDA API. By
7307default, CUDA is used. The interop object is created using OpenMP's
7308@code{interop} directive or, implicitly, when invoking a @code{declare variant}
7309procedure that has the @code{append_args} clause. In either case, the
7310@code{prefer_type} modifier determines whether CUDA, CUDA driver, or HSA is
7311used.
7312
7313When specifying the @code{targetsync} modifier, a CUDA stream is created using
7314the @code{CU_STREAM_DEFAULT} flag.
7315
7316Invoke the @ref{Interoperability Routines} on an interop object to obtain
7317the following properties. For properties with integral (int), pointer (ptr),
7318or string (str) data type, call @code{omp_get_interop_int},
7319@code{omp_get_interop_ptr}, or @code{omp_get_interop_str}, respectively.
7320Note that @code{device_num} is the OpenMP device number while @code{device}
7321is the CUDA, CUDA Driver, or HIP device number.
7322
7323When using HIP with C and C++, the @code{__HIP_PLATFORM_NVIDIA__} preprocessor
7324macro must be defined before including the HIP header files.
7325
7326For the API routine call, add the prefix @code{omp_ipr_} to the property name;
7327for instance:
7328@smallexample
7329omp_interop_rc_t ret;
7330int device_num = omp_get_interop_int (my_interop_obj, omp_ipr_device_num, &ret);
7331@end smallexample
7332
7333@noindent
7334Available properties for a CUDA runtime API interop object:
7335
7336@multitable @columnfractions .20 .35 .20 .20
7337@headitem Property @tab C data type @tab API routine @tab value (if constant)
7338@item @code{fr_id} @tab @code{omp_interop_fr_t} @tab int @tab @code{omp_fr_cuda}
7339@item @code{fr_name} @tab @code{const char *} @tab str @tab @code{"cuda"}
7340@item @code{vendor} @tab @code{int} @tab int @tab @code{11}
7341@item @code{vendor_name} @tab @code{const char *} @tab str @tab @code{"nvidia"}
7342@item @code{device_num} @tab @code{int} @tab int @tab
7343@item @code{platform} @tab N/A @tab @tab
7344@item @code{device} @tab @code{int} @tab int @tab
7345@item @code{device_context} @tab N/A @tab @tab
7346@item @code{targetsync} @tab @code{cudaStream_t} @tab ptr @tab
7347@end multitable
7348
7349@noindent
7350Available properties for a CUDA driver API interop object:
7351
7352@multitable @columnfractions .20 .35 .20 .20
7353@headitem Property @tab C data type @tab API routine @tab value (if constant)
7354@item @code{fr_id} @tab @code{omp_interop_fr_t} @tab int @tab @code{omp_fr_cuda_driver}
7355@item @code{fr_name} @tab @code{const char *} @tab str @tab @code{"cuda_driver"}
7356@item @code{vendor} @tab @code{int} @tab int @tab @code{11}
7357@item @code{vendor_name} @tab @code{const char *} @tab str @tab @code{"nvidia"}
7358@item @code{device_num} @tab @code{int} @tab int @tab
7359@item @code{platform} @tab N/A @tab @tab
7360@item @code{device} @tab @code{CUdevice} @tab int @tab
7361@item @code{device_context} @tab @code{CUcontext} @tab ptr @tab
7362@item @code{targetsync} @tab @code{CUstream} @tab ptr @tab
7363@end multitable
7364
7365@noindent
7366Available properties for an HIP interop object:
7367
7368@multitable @columnfractions .20 .35 .20 .20
7369@headitem Property @tab C data type @tab API routine @tab value (if constant)
7370@item @code{fr_id} @tab @code{omp_interop_fr_t} @tab int @tab @code{omp_fr_hip}
7371@item @code{fr_name} @tab @code{const char *} @tab str @tab @code{"hip"}
7372@item @code{vendor} @tab @code{int} @tab int @tab @code{11}
7373@item @code{vendor_name} @tab @code{const char *} @tab str @tab @code{"nvidia"}
7374@item @code{device_num} @tab @code{int} @tab int @tab
7375@item @code{platform} @tab N/A @tab @tab
7376@item @code{device} @tab @code{hipDevice_t} @tab int @tab
7377@item @code{device_context} @tab @code{hipCtx_t} @tab ptr @tab
7378@item @code{targetsync} @tab @code{hipStream_t} @tab ptr @tab
7379@end multitable
7380
7381
7382
7383@c ---------------------------------------------------------------------
7384@c The libgomp ABI
7385@c ---------------------------------------------------------------------
7386
7387@node The libgomp ABI
7388@chapter The libgomp ABI
7389
7390The following sections present notes on the external ABI as
7391presented by libgomp. Only maintainers should need them.
7392
7393@menu
7394* Implementing MASTER construct::
7395* Implementing CRITICAL construct::
7396* Implementing ATOMIC construct::
7397* Implementing FLUSH construct::
7398* Implementing BARRIER construct::
7399* Implementing THREADPRIVATE construct::
7400* Implementing PRIVATE clause::
7401* Implementing FIRSTPRIVATE LASTPRIVATE COPYIN and COPYPRIVATE clauses::
7402* Implementing REDUCTION clause::
7403* Implementing PARALLEL construct::
7404* Implementing FOR construct::
7405* Implementing ORDERED construct::
7406* Implementing SECTIONS construct::
7407* Implementing SINGLE construct::
7408* Implementing OpenACC's PARALLEL construct::
7409@end menu
7410
7411
7412@node Implementing MASTER construct
7413@section Implementing MASTER construct
7414
7415@smallexample
7416if (omp_get_thread_num () == 0)
7417 block
7418@end smallexample
7419
7420Alternately, we generate two copies of the parallel subfunction
7421and only include this in the version run by the primary thread.
7422Surely this is not worthwhile though...
7423
7424
7425
7426@node Implementing CRITICAL construct
7427@section Implementing CRITICAL construct
7428
7429Without a specified name,
7430
7431@smallexample
7432 void GOMP_critical_start (void);
7433 void GOMP_critical_end (void);
7434@end smallexample
7435
7436so that we don't get COPY relocations from libgomp to the main
7437application.
7438
7439With a specified name, use omp_set_lock and omp_unset_lock with
7440name being transformed into a variable declared like
7441
7442@smallexample
7443 omp_lock_t gomp_critical_user_<name> __attribute__((common))
7444@end smallexample
7445
7446Ideally the ABI would specify that all zero is a valid unlocked
7447state, and so we wouldn't need to initialize this at
7448startup.
7449
7450
7451
7452@node Implementing ATOMIC construct
7453@section Implementing ATOMIC construct
7454
7455The target should implement the @code{__sync} builtins.
7456
7457Failing that we could add
7458
7459@smallexample
7460 void GOMP_atomic_enter (void)
7461 void GOMP_atomic_exit (void)
7462@end smallexample
7463
7464which reuses the regular lock code, but with yet another lock
7465object private to the library.
7466
7467
7468
7469@node Implementing FLUSH construct
7470@section Implementing FLUSH construct
7471
7472Expands to the @code{__sync_synchronize} builtin.
7473
7474
7475
7476@node Implementing BARRIER construct
7477@section Implementing BARRIER construct
7478
7479@smallexample
7480 void GOMP_barrier (void)
7481@end smallexample
7482
7483
7484@node Implementing THREADPRIVATE construct
7485@section Implementing THREADPRIVATE construct
7486
7487In _most_ cases we can map this directly to @code{__thread}. Except
7488that OMP allows constructors for C++ objects. We can either
7489refuse to support this (how often is it used?) or we can
7490implement something akin to .ctors.
7491
7492Even more ideally, this ctor feature is handled by extensions
7493to the main pthreads library. Failing that, we can have a set
7494of entry points to register ctor functions to be called.
7495
7496
7497
7498@node Implementing PRIVATE clause
7499@section Implementing PRIVATE clause
7500
7501In association with a PARALLEL, or within the lexical extent
7502of a PARALLEL block, the variable becomes a local variable in
7503the parallel subfunction.
7504
7505In association with FOR or SECTIONS blocks, create a new
7506automatic variable within the current function. This preserves
7507the semantic of new variable creation.
7508
7509
7510
7511@node Implementing FIRSTPRIVATE LASTPRIVATE COPYIN and COPYPRIVATE clauses
7512@section Implementing FIRSTPRIVATE LASTPRIVATE COPYIN and COPYPRIVATE clauses
7513
7514This seems simple enough for PARALLEL blocks. Create a private
7515struct for communicating between the parent and subfunction.
7516In the parent, copy in values for scalar and "small" structs;
7517copy in addresses for others TREE_ADDRESSABLE types. In the
7518subfunction, copy the value into the local variable.
7519
7520It is not clear what to do with bare FOR or SECTION blocks.
7521The only thing I can figure is that we do something like:
7522
7523@smallexample
7524#pragma omp for firstprivate(x) lastprivate(y)
7525for (int i = 0; i < n; ++i)
7526 body;
7527@end smallexample
7528
7529which becomes
7530
7531@smallexample
7532@{
7533 int x = x, y;
7534
7535 // for stuff
7536
7537 if (i == n)
7538 y = y;
7539@}
7540@end smallexample
7541
7542where the "x=x" and "y=y" assignments actually have different
7543uids for the two variables, i.e. not something you could write
7544directly in C. Presumably this only makes sense if the "outer"
7545x and y are global variables.
7546
7547COPYPRIVATE would work the same way, except the structure
7548broadcast would have to happen via SINGLE machinery instead.
7549
7550
7551
7552@node Implementing REDUCTION clause
7553@section Implementing REDUCTION clause
7554
7555The private struct mentioned in the previous section should have
7556a pointer to an array of the type of the variable, indexed by the
7557thread's @var{team_id}. The thread stores its final value into the
7558array, and after the barrier, the primary thread iterates over the
7559array to collect the values.
7560
7561
7562@node Implementing PARALLEL construct
7563@section Implementing PARALLEL construct
7564
7565@smallexample
7566 #pragma omp parallel
7567 @{
7568 body;
7569 @}
7570@end smallexample
7571
7572becomes
7573
7574@smallexample
7575 void subfunction (void *data)
7576 @{
7577 use data;
7578 body;
7579 @}
7580
7581 setup data;
7582 GOMP_parallel_start (subfunction, &data, num_threads);
7583 subfunction (&data);
7584 GOMP_parallel_end ();
7585@end smallexample
7586
7587@smallexample
7588 void GOMP_parallel_start (void (*fn)(void *), void *data, unsigned num_threads)
7589@end smallexample
7590
7591The @var{FN} argument is the subfunction to be run in parallel.
7592
7593The @var{DATA} argument is a pointer to a structure used to
7594communicate data in and out of the subfunction, as discussed
7595above with respect to FIRSTPRIVATE et al.
7596
7597The @var{NUM_THREADS} argument is 1 if an IF clause is present
7598and false, or the value of the NUM_THREADS clause, if
7599present, or 0.
7600
7601The function needs to create the appropriate number of
7602threads and/or launch them from the dock. It needs to
7603create the team structure and assign team ids.
7604
7605@smallexample
7606 void GOMP_parallel_end (void)
7607@end smallexample
7608
7609Tears down the team and returns us to the previous @code{omp_in_parallel()} state.
7610
7611
7612
7613@node Implementing FOR construct
7614@section Implementing FOR construct
7615
7616@smallexample
7617 #pragma omp parallel for
7618 for (i = lb; i <= ub; i++)
7619 body;
7620@end smallexample
7621
7622becomes
7623
7624@smallexample
7625 void subfunction (void *data)
7626 @{
7627 long _s0, _e0;
7628 while (GOMP_loop_static_next (&_s0, &_e0))
7629 @{
7630 long _e1 = _e0, i;
7631 for (i = _s0; i < _e1; i++)
7632 body;
7633 @}
7634 GOMP_loop_end_nowait ();
7635 @}
7636
7637 GOMP_parallel_loop_static (subfunction, NULL, 0, lb, ub+1, 1, 0);
7638 subfunction (NULL);
7639 GOMP_parallel_end ();
7640@end smallexample
7641
7642@smallexample
7643 #pragma omp for schedule(runtime)
7644 for (i = 0; i < n; i++)
7645 body;
7646@end smallexample
7647
7648becomes
7649
7650@smallexample
7651 @{
7652 long i, _s0, _e0;
7653 if (GOMP_loop_runtime_start (0, n, 1, &_s0, &_e0))
7654 do @{
7655 long _e1 = _e0;
7656 for (i = _s0, i < _e0; i++)
7657 body;
7658 @} while (GOMP_loop_runtime_next (&_s0, _&e0));
7659 GOMP_loop_end ();
7660 @}
7661@end smallexample
7662
7663Note that while it looks like there is trickiness to propagating
7664a non-constant STEP, there isn't really. We're explicitly allowed
7665to evaluate it as many times as we want, and any variables involved
7666should automatically be handled as PRIVATE or SHARED like any other
7667variables. So the expression should remain evaluable in the
7668subfunction. We can also pull it into a local variable if we like,
7669but since its supposed to remain unchanged, we can also not if we like.
7670
7671If we have SCHEDULE(STATIC), and no ORDERED, then we ought to be
7672able to get away with no work-sharing context at all, since we can
7673simply perform the arithmetic directly in each thread to divide up
7674the iterations. Which would mean that we wouldn't need to call any
7675of these routines.
7676
7677There are separate routines for handling loops with an ORDERED
7678clause. Bookkeeping for that is non-trivial...
7679
7680
7681
7682@node Implementing ORDERED construct
7683@section Implementing ORDERED construct
7684
7685@smallexample
7686 void GOMP_ordered_start (void)
7687 void GOMP_ordered_end (void)
7688@end smallexample
7689
7690
7691
7692@node Implementing SECTIONS construct
7693@section Implementing SECTIONS construct
7694
7695A block as
7696
7697@smallexample
7698 #pragma omp sections
7699 @{
7700 #pragma omp section
7701 stmt1;
7702 #pragma omp section
7703 stmt2;
7704 #pragma omp section
7705 stmt3;
7706 @}
7707@end smallexample
7708
7709becomes
7710
7711@smallexample
7712 for (i = GOMP_sections_start (3); i != 0; i = GOMP_sections_next ())
7713 switch (i)
7714 @{
7715 case 1:
7716 stmt1;
7717 break;
7718 case 2:
7719 stmt2;
7720 break;
7721 case 3:
7722 stmt3;
7723 break;
7724 @}
7725 GOMP_barrier ();
7726@end smallexample
7727
7728
7729@node Implementing SINGLE construct
7730@section Implementing SINGLE construct
7731
7732A block like
7733
7734@smallexample
7735 #pragma omp single
7736 @{
7737 body;
7738 @}
7739@end smallexample
7740
7741becomes
7742
7743@smallexample
7744 if (GOMP_single_start ())
7745 body;
7746 GOMP_barrier ();
7747@end smallexample
7748
7749while
7750
7751@smallexample
7752 #pragma omp single copyprivate(x)
7753 body;
7754@end smallexample
7755
7756becomes
7757
7758@smallexample
7759 datap = GOMP_single_copy_start ();
7760 if (datap == NULL)
7761 @{
7762 body;
7763 data.x = x;
7764 GOMP_single_copy_end (&data);
7765 @}
7766 else
7767 x = datap->x;
7768 GOMP_barrier ();
7769@end smallexample
7770
7771
7772
7773@node Implementing OpenACC's PARALLEL construct
7774@section Implementing OpenACC's PARALLEL construct
7775
7776@smallexample
7777 void GOACC_parallel ()
7778@end smallexample
7779
7780
7781
7782@c ---------------------------------------------------------------------
7783@c Reporting Bugs
7784@c ---------------------------------------------------------------------
7785
7786@node Reporting Bugs
7787@chapter Reporting Bugs
7788
7789Bugs in the GNU Offloading and Multi Processing Runtime Library should
7790be reported via @uref{https://gcc.gnu.org/bugzilla/, Bugzilla}. Please add
7791"openacc", or "openmp", or both to the keywords field in the bug
7792report, as appropriate.
7793
7794
7795
7796@c ---------------------------------------------------------------------
7797@c GNU General Public License
7798@c ---------------------------------------------------------------------
7799
7800@include gpl_v3.texi
7801
7802
7803
7804@c ---------------------------------------------------------------------
7805@c GNU Free Documentation License
7806@c ---------------------------------------------------------------------
7807
7808@include fdl.texi
7809
7810
7811
7812@c ---------------------------------------------------------------------
7813@c Funding Free Software
7814@c ---------------------------------------------------------------------
7815
7816@include funding.texi
7817
7818@c ---------------------------------------------------------------------
7819@c Index
7820@c ---------------------------------------------------------------------
7821
7822@node Library Index
7823@unnumbered Library Index
7824
7825@printindex cp
7826
7827@bye