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