1 \input texinfo @c -*-texinfo-*-
4 @setfilename libgomp.info
10 Copyright @copyright{} 2006-2022 Free Software Foundation, Inc.
12 Permission is granted to copy, distribute and/or modify this document
13 under the terms of the GNU Free Documentation License, Version 1.3 or
14 any later version published by the Free Software Foundation; with the
15 Invariant Sections being ``Funding Free Software'', the Front-Cover
16 texts being (a) (see below), and with the Back-Cover Texts being (b)
17 (see below). A copy of the license is included in the section entitled
18 ``GNU Free Documentation License''.
20 (a) The FSF's Front-Cover Text is:
24 (b) The FSF's Back-Cover Text is:
26 You have freedom to copy and modify this GNU Manual, like GNU
27 software. Copies published by the Free Software Foundation raise
28 funds for GNU development.
32 @dircategory GNU Libraries
34 * libgomp: (libgomp). GNU Offloading and Multi Processing Runtime Library.
37 This manual documents libgomp, the GNU Offloading and Multi Processing
38 Runtime library. This is the GNU implementation of the OpenMP and
39 OpenACC APIs for parallel and accelerator programming in C/C++ and
42 Published by the Free Software Foundation
43 51 Franklin Street, Fifth Floor
44 Boston, MA 02110-1301 USA
50 @setchapternewpage odd
53 @title GNU Offloading and Multi Processing Runtime Library
54 @subtitle The GNU OpenMP and OpenACC Implementation
56 @vskip 0pt plus 1filll
57 @comment For the @value{version-GCC} Version*
59 Published by the Free Software Foundation @*
60 51 Franklin Street, Fifth Floor@*
61 Boston, MA 02110-1301, USA@*
71 @node Top, Enabling OpenMP
75 This manual documents the usage of libgomp, the GNU Offloading and
76 Multi Processing Runtime Library. This includes the GNU
77 implementation of the @uref{https://www.openmp.org, OpenMP} Application
78 Programming Interface (API) for multi-platform shared-memory parallel
79 programming in C/C++ and Fortran, and the GNU implementation of the
80 @uref{https://www.openacc.org, OpenACC} Application Programming
81 Interface (API) for offloading of code to accelerator devices in C/C++
84 Originally, libgomp implemented the GNU OpenMP Runtime Library. Based
85 on this, support for OpenACC and offloading (both OpenACC and OpenMP
86 4's target construct) has been added later on, and the library's name
87 changed to GNU Offloading and Multi Processing Runtime Library.
92 @comment When you add a new menu item, please keep the right hand
93 @comment aligned to the same column. Do not use tabs. This provides
94 @comment better formatting.
97 * Enabling OpenMP:: How to enable OpenMP for your applications.
98 * OpenMP Implementation Status:: List of implemented features by OpenMP version
99 * OpenMP Runtime Library Routines: Runtime Library Routines.
100 The OpenMP runtime application programming
102 * OpenMP Environment Variables: Environment Variables.
103 Influencing OpenMP runtime behavior with
104 environment variables.
105 * Enabling OpenACC:: How to enable OpenACC for your
107 * OpenACC Runtime Library Routines:: The OpenACC runtime application
108 programming interface.
109 * OpenACC Environment Variables:: Influencing OpenACC runtime behavior with
110 environment variables.
111 * CUDA Streams Usage:: Notes on the implementation of
112 asynchronous operations.
113 * OpenACC Library Interoperability:: OpenACC library interoperability with the
114 NVIDIA CUBLAS library.
115 * OpenACC Profiling Interface::
116 * The libgomp ABI:: Notes on the external ABI presented by libgomp.
117 * Reporting Bugs:: How to report bugs in the GNU Offloading and
118 Multi Processing Runtime Library.
119 * Copying:: GNU general public license says
120 how you can copy and share libgomp.
121 * GNU Free Documentation License::
122 How you can copy and share this manual.
123 * Funding:: How to help assure continued work for free
125 * Library Index:: Index of this documentation.
129 @c ---------------------------------------------------------------------
131 @c ---------------------------------------------------------------------
133 @node Enabling OpenMP
134 @chapter Enabling OpenMP
136 To activate the OpenMP extensions for C/C++ and Fortran, the compile-time
137 flag @command{-fopenmp} must be specified. This enables the OpenMP directive
138 @code{#pragma omp} in C/C++ and @code{!$omp} directives in free form,
139 @code{c$omp}, @code{*$omp} and @code{!$omp} directives in fixed form,
140 @code{!$} conditional compilation sentinels in free form and @code{c$},
141 @code{*$} and @code{!$} sentinels in fixed form, for Fortran. The flag also
142 arranges for automatic linking of the OpenMP runtime library
143 (@ref{Runtime Library Routines}).
145 A complete description of all OpenMP directives may be found in the
146 @uref{https://www.openmp.org, OpenMP Application Program Interface} manuals.
147 See also @ref{OpenMP Implementation Status}.
150 @c ---------------------------------------------------------------------
151 @c OpenMP Implementation Status
152 @c ---------------------------------------------------------------------
154 @node OpenMP Implementation Status
155 @chapter OpenMP Implementation Status
158 * OpenMP 4.5:: Feature completion status to 4.5 specification
159 * OpenMP 5.0:: Feature completion status to 5.0 specification
160 * OpenMP 5.1:: Feature completion status to 5.1 specification
163 The @code{_OPENMP} preprocessor macro and Fortran's @code{openmp_version}
164 parameter, provided by @code{omp_lib.h} and the @code{omp_lib} module, have
165 the value @code{201511} (i.e. OpenMP 4.5).
170 The OpenMP 4.5 specification is fully supported.
175 @unnumberedsubsec New features listed in Appendix B of the OpenMP specification
176 @c This list is sorted as in OpenMP 5.1's B.3 not as in OpenMP 5.0's B.2
178 @multitable @columnfractions .60 .10 .25
179 @headitem Description @tab Status @tab Comments
180 @item Array shaping @tab N @tab
181 @item Array sections with non-unit strides in C and C++ @tab N @tab
182 @item Iterators @tab Y @tab
183 @item @code{metadirective} directive @tab N @tab
184 @item @code{declare variant} directive
185 @tab P @tab simd traits not handled correctly
186 @item @emph{target-offload-var} ICV and @code{OMP_TARGET_OFFLOAD}
187 env variable @tab Y @tab
188 @item Nested-parallel changes to @emph{max-active-levels-var} ICV @tab Y @tab
189 @item @code{requires} directive @tab P
190 @tab Only fulfillable requirement are @code{atomic_default_mem_order}
191 and @code{dynamic_allocators}
192 @item @code{teams} construct outside an enclosing target region @tab Y @tab
193 @item Non-rectangular loop nests @tab Y @tab
194 @item @code{!=} as relational-op in canonical loop form for C/C++ @tab Y @tab
195 @item @code{nonmonotonic} as default loop schedule modifier for worksharing-loop
196 constructs @tab Y @tab
197 @item Collapse of associated loops that are imperfectly nested loops @tab N @tab
198 @item Clauses @code{if}, @code{nontemporal} and @code{order(concurrent)} in
199 @code{simd} construct @tab Y @tab
200 @item @code{atomic} constructs in @code{simd} @tab Y @tab
201 @item @code{loop} construct @tab Y @tab
202 @item @code{order(concurrent)} clause @tab Y @tab
203 @item @code{scan} directive and @code{in_scan} modifier for the
204 @code{reduction} clause @tab Y @tab
205 @item @code{in_reduction} clause on @code{task} constructs @tab Y @tab
206 @item @code{in_reduction} clause on @code{target} constructs @tab P
207 @tab @code{nowait} only stub
208 @item @code{task_reduction} clause with @code{taskgroup} @tab Y @tab
209 @item @code{task} modifier to @code{reduction} clause @tab Y @tab
210 @item @code{affinity} clause to @code{task} construct @tab Y @tab Stub only
211 @item @code{detach} clause to @code{task} construct @tab Y @tab
212 @item @code{omp_fulfill_event} runtime routine @tab Y @tab
213 @item @code{reduction} and @code{in_reduction} clauses on @code{taskloop}
214 and @code{taskloop simd} constructs @tab Y @tab
215 @item @code{taskloop} construct cancelable by @code{cancel} construct
217 @item @code{mutexinoutset} @emph{dependence-type} for @code{depend} clause
219 @item Predefined memory spaces, memory allocators, allocator traits
220 @tab Y @tab Some are only stubs
221 @item Memory management routines @tab Y @tab
222 @item @code{allocate} directive @tab N @tab
223 @item @code{allocate} clause @tab P @tab initial support
224 @item @code{use_device_addr} clause on @code{target data} @tab Y @tab
225 @item @code{ancestor} modifier on @code{device} clause
226 @tab P @tab Reverse offload unsupported
227 @item Implicit declare target directive @tab Y @tab
228 @item Discontiguous array section with @code{target update} construct
230 @item C/C++'s lvalue expressions in @code{to}, @code{from}
231 and @code{map} clauses @tab N @tab
232 @item C/C++'s lvalue expressions in @code{depend} clauses @tab Y @tab
233 @item Nested @code{declare target} directive @tab Y @tab
234 @item Combined @code{master} constructs @tab Y @tab
235 @item @code{depend} clause on @code{taskwait} @tab Y @tab
236 @item Weak memory ordering clauses on @code{atomic} and @code{flush} construct
238 @item @code{hint} clause on the @code{atomic} construct @tab Y @tab Stub only
239 @item @code{depobj} construct and depend objects @tab Y @tab
240 @item Lock hints were renamed to synchronization hints @tab Y @tab
241 @item @code{conditional} modifier to @code{lastprivate} clause @tab Y @tab
242 @item Map-order clarifications @tab P @tab
243 @item @code{close} @emph{map-type-modifier} @tab Y @tab
244 @item Mapping C/C++ pointer variables and to assign the address of
245 device memory mapped by an array section @tab P @tab
246 @item Mapping of Fortran pointer and allocatable variables, including pointer
247 and allocatable components of variables
248 @tab P @tab Mapping of vars with allocatable components unsupported
249 @item @code{defaultmap} extensions @tab Y @tab
250 @item @code{declare mapper} directive @tab N @tab
251 @item @code{omp_get_supported_active_levels} routine @tab Y @tab
252 @item Runtime routines and environment variables to display runtime thread
253 affinity information @tab Y @tab
254 @item @code{omp_pause_resource} and @code{omp_pause_resource_all} runtime
256 @item @code{omp_get_device_num} runtime routine @tab Y @tab
257 @item OMPT interface @tab N @tab
258 @item OMPD interface @tab N @tab
261 @unnumberedsubsec Other new OpenMP 5.0 features
263 @multitable @columnfractions .60 .10 .25
264 @headitem Description @tab Status @tab Comments
265 @item Supporting C++'s range-based for loop @tab Y @tab
272 @unnumberedsubsec New features listed in Appendix B of the OpenMP specification
274 @multitable @columnfractions .60 .10 .25
275 @headitem Description @tab Status @tab Comments
276 @item OpenMP directive as C++ attribute specifiers @tab Y @tab
277 @item @code{omp_all_memory} reserved locator @tab N @tab
278 @item @emph{target_device trait} in OpenMP Context @tab N @tab
279 @item @code{target_device} selector set in context selectors @tab N @tab
280 @item C/C++'s @code{declare variant} directive: elision support of
281 preprocessed code @tab N @tab
282 @item @code{declare variant}: new clauses @code{adjust_args} and
283 @code{append_args} @tab N @tab
284 @item @code{dispatch} construct @tab N @tab
285 @item device-specific ICV settings the environment variables @tab N @tab
286 @item assume directive @tab N @tab
287 @item @code{nothing} directive @tab Y @tab
288 @item @code{error} directive @tab Y @tab
289 @item @code{masked} construct @tab Y @tab
290 @item @code{scope} directive @tab Y @tab
291 @item Loop transformation constructs @tab N @tab
292 @item @code{strict} modifier in the @code{grainsize} and @code{num_tasks}
293 clauses of the taskloop construct @tab Y @tab
294 @item @code{align} clause/modifier in @code{allocate} directive/clause
295 and @code{allocator} directive @tab P @tab C/C++ on clause only
296 @item @code{thread_limit} clause to @code{target} construct @tab Y @tab
297 @item @code{has_device_addr} clause to @code{target} construct @tab Y @tab
298 @item iterators in @code{target update} motion clauses and @code{map}
300 @item indirect calls to the device version of a procedure or function in
301 @code{target} regions @tab N @tab
302 @item @code{interop} directive @tab N @tab
303 @item @code{omp_interop_t} object support in runtime routines @tab N @tab
304 @item @code{nowait} clause in @code{taskwait} directive @tab N @tab
305 @item Extensions to the @code{atomic} directive @tab Y @tab
306 @item @code{seq_cst} clause on a @code{flush} construct @tab Y @tab
307 @item @code{inoutset} argument to the @code{depend} clause @tab N @tab
308 @item @code{private} and @code{firstprivate} argument to @code{default}
309 clause in C and C++ @tab Y @tab
310 @item @code{present} argument to @code{defaultmap} clause @tab N @tab
311 @item @code{omp_set_num_teams}, @code{omp_set_teams_thread_limit},
312 @code{omp_get_max_teams}, @code{omp_get_teams_thread_limit} runtime
314 @item @code{omp_target_is_accessible} runtime routine @tab Y @tab
315 @item @code{omp_target_memcpy_async} and @code{omp_target_memcpy_rect_async}
316 runtime routines @tab N @tab
317 @item @code{omp_get_mapped_ptr} runtime routine @tab Y @tab
318 @item @code{omp_calloc}, @code{omp_realloc}, @code{omp_aligned_alloc} and
319 @code{omp_aligned_calloc} runtime routines @tab Y @tab
320 @item @code{omp_alloctrait_key_t} enum: @code{omp_atv_serialized} added,
321 @code{omp_atv_default} changed @tab Y @tab
322 @item @code{omp_display_env} runtime routine @tab Y
323 @tab Not inside @code{target} regions
324 @item @code{ompt_scope_endpoint_t} enum: @code{ompt_scope_beginend} @tab N @tab
325 @item @code{ompt_sync_region_t} enum additions @tab N @tab
326 @item @code{ompt_state_t} enum: @code{ompt_state_wait_barrier_implementation}
327 and @code{ompt_state_wait_barrier_teams} @tab N @tab
328 @item @code{ompt_callback_target_data_op_emi_t},
329 @code{ompt_callback_target_emi_t}, @code{ompt_callback_target_map_emi_t}
330 and @code{ompt_callback_target_submit_emi_t} @tab N @tab
331 @item @code{ompt_callback_error_t} type @tab N @tab
332 @item @code{OMP_PLACES} syntax extensions @tab Y @tab
333 @item @code{OMP_NUM_TEAMS} and @code{OMP_TEAMS_THREAD_LIMIT} environment
334 variables @tab Y @tab
337 @unnumberedsubsec Other new OpenMP 5.1 features
339 @multitable @columnfractions .60 .10 .25
340 @headitem Description @tab Status @tab Comments
341 @item Support of strictly structured blocks in Fortran @tab Y @tab
342 @item Support of structured block sequences in C/C++ @tab Y @tab
343 @item @code{unconstrained} and @code{reproducible} modifiers on @code{order}
348 @c ---------------------------------------------------------------------
349 @c OpenMP Runtime Library Routines
350 @c ---------------------------------------------------------------------
352 @node Runtime Library Routines
353 @chapter OpenMP Runtime Library Routines
355 The runtime routines described here are defined by Section 3 of the OpenMP
356 specification in version 4.5. The routines are structured in following
360 Control threads, processors and the parallel environment. They have C
361 linkage, and do not throw exceptions.
363 * omp_get_active_level:: Number of active parallel regions
364 * omp_get_ancestor_thread_num:: Ancestor thread ID
365 * omp_get_cancellation:: Whether cancellation support is enabled
366 * omp_get_default_device:: Get the default device for target regions
367 * omp_get_device_num:: Get device that current thread is running on
368 * omp_get_dynamic:: Dynamic teams setting
369 * omp_get_initial_device:: Device number of host device
370 * omp_get_level:: Number of parallel regions
371 * omp_get_max_active_levels:: Current maximum number of active regions
372 * omp_get_max_task_priority:: Maximum task priority value that can be set
373 * omp_get_max_teams:: Maximum number of teams for teams region
374 * omp_get_max_threads:: Maximum number of threads of parallel region
375 * omp_get_nested:: Nested parallel regions
376 * omp_get_num_devices:: Number of target devices
377 * omp_get_num_procs:: Number of processors online
378 * omp_get_num_teams:: Number of teams
379 * omp_get_num_threads:: Size of the active team
380 * omp_get_proc_bind:: Whether theads may be moved between CPUs
381 * omp_get_schedule:: Obtain the runtime scheduling method
382 * omp_get_supported_active_levels:: Maximum number of active regions supported
383 * omp_get_team_num:: Get team number
384 * omp_get_team_size:: Number of threads in a team
385 * omp_get_teams_thread_limit:: Maximum number of threads imposed by teams
386 * omp_get_thread_limit:: Maximum number of threads
387 * omp_get_thread_num:: Current thread ID
388 * omp_in_parallel:: Whether a parallel region is active
389 * omp_in_final:: Whether in final or included task region
390 * omp_is_initial_device:: Whether executing on the host device
391 * omp_set_default_device:: Set the default device for target regions
392 * omp_set_dynamic:: Enable/disable dynamic teams
393 * omp_set_max_active_levels:: Limits the number of active parallel regions
394 * omp_set_nested:: Enable/disable nested parallel regions
395 * omp_set_num_teams:: Set upper teams limit for teams region
396 * omp_set_num_threads:: Set upper team size limit
397 * omp_set_schedule:: Set the runtime scheduling method
398 * omp_set_teams_thread_limit:: Set upper thread limit for teams construct
400 Initialize, set, test, unset and destroy simple and nested locks.
402 * omp_init_lock:: Initialize simple lock
403 * omp_set_lock:: Wait for and set simple lock
404 * omp_test_lock:: Test and set simple lock if available
405 * omp_unset_lock:: Unset simple lock
406 * omp_destroy_lock:: Destroy simple lock
407 * omp_init_nest_lock:: Initialize nested lock
408 * omp_set_nest_lock:: Wait for and set simple lock
409 * omp_test_nest_lock:: Test and set nested lock if available
410 * omp_unset_nest_lock:: Unset nested lock
411 * omp_destroy_nest_lock:: Destroy nested lock
413 Portable, thread-based, wall clock timer.
415 * omp_get_wtick:: Get timer precision.
416 * omp_get_wtime:: Elapsed wall clock time.
418 Support for event objects.
420 * omp_fulfill_event:: Fulfill and destroy an OpenMP event.
425 @node omp_get_active_level
426 @section @code{omp_get_active_level} -- Number of parallel regions
428 @item @emph{Description}:
429 This function returns the nesting level for the active parallel blocks,
430 which enclose the calling call.
433 @multitable @columnfractions .20 .80
434 @item @emph{Prototype}: @tab @code{int omp_get_active_level(void);}
437 @item @emph{Fortran}:
438 @multitable @columnfractions .20 .80
439 @item @emph{Interface}: @tab @code{integer function omp_get_active_level()}
442 @item @emph{See also}:
443 @ref{omp_get_level}, @ref{omp_get_max_active_levels}, @ref{omp_set_max_active_levels}
445 @item @emph{Reference}:
446 @uref{https://www.openmp.org, OpenMP specification v4.5}, Section 3.2.20.
451 @node omp_get_ancestor_thread_num
452 @section @code{omp_get_ancestor_thread_num} -- Ancestor thread ID
454 @item @emph{Description}:
455 This function returns the thread identification number for the given
456 nesting level of the current thread. For values of @var{level} outside
457 zero to @code{omp_get_level} -1 is returned; if @var{level} is
458 @code{omp_get_level} the result is identical to @code{omp_get_thread_num}.
461 @multitable @columnfractions .20 .80
462 @item @emph{Prototype}: @tab @code{int omp_get_ancestor_thread_num(int level);}
465 @item @emph{Fortran}:
466 @multitable @columnfractions .20 .80
467 @item @emph{Interface}: @tab @code{integer function omp_get_ancestor_thread_num(level)}
468 @item @tab @code{integer level}
471 @item @emph{See also}:
472 @ref{omp_get_level}, @ref{omp_get_thread_num}, @ref{omp_get_team_size}
474 @item @emph{Reference}:
475 @uref{https://www.openmp.org, OpenMP specification v4.5}, Section 3.2.18.
480 @node omp_get_cancellation
481 @section @code{omp_get_cancellation} -- Whether cancellation support is enabled
483 @item @emph{Description}:
484 This function returns @code{true} if cancellation is activated, @code{false}
485 otherwise. Here, @code{true} and @code{false} represent their language-specific
486 counterparts. Unless @env{OMP_CANCELLATION} is set true, cancellations are
490 @multitable @columnfractions .20 .80
491 @item @emph{Prototype}: @tab @code{int omp_get_cancellation(void);}
494 @item @emph{Fortran}:
495 @multitable @columnfractions .20 .80
496 @item @emph{Interface}: @tab @code{logical function omp_get_cancellation()}
499 @item @emph{See also}:
500 @ref{OMP_CANCELLATION}
502 @item @emph{Reference}:
503 @uref{https://www.openmp.org, OpenMP specification v4.5}, Section 3.2.9.
508 @node omp_get_default_device
509 @section @code{omp_get_default_device} -- Get the default device for target regions
511 @item @emph{Description}:
512 Get the default device for target regions without device clause.
515 @multitable @columnfractions .20 .80
516 @item @emph{Prototype}: @tab @code{int omp_get_default_device(void);}
519 @item @emph{Fortran}:
520 @multitable @columnfractions .20 .80
521 @item @emph{Interface}: @tab @code{integer function omp_get_default_device()}
524 @item @emph{See also}:
525 @ref{OMP_DEFAULT_DEVICE}, @ref{omp_set_default_device}
527 @item @emph{Reference}:
528 @uref{https://www.openmp.org, OpenMP specification v4.5}, Section 3.2.30.
533 @node omp_get_device_num
534 @section @code{omp_get_device_num} -- Return device number of current device
536 @item @emph{Description}:
537 This function returns a device number that represents the device that the
538 current thread is executing on. For OpenMP 5.0, this must be equal to the
539 value returned by the @code{omp_get_initial_device} function when called
543 @multitable @columnfractions .20 .80
544 @item @emph{Prototype}: @tab @code{int omp_get_device_num(void);}
547 @item @emph{Fortran}:
548 @multitable @columnfractions .20 .80
549 @item @emph{Interface}: @tab @code{integer function omp_get_device_num()}
552 @item @emph{See also}:
553 @ref{omp_get_initial_device}
555 @item @emph{Reference}:
556 @uref{https://www.openmp.org, OpenMP specification v5.0}, Section 3.2.37.
561 @node omp_get_dynamic
562 @section @code{omp_get_dynamic} -- Dynamic teams setting
564 @item @emph{Description}:
565 This function returns @code{true} if enabled, @code{false} otherwise.
566 Here, @code{true} and @code{false} represent their language-specific
569 The dynamic team setting may be initialized at startup by the
570 @env{OMP_DYNAMIC} environment variable or at runtime using
571 @code{omp_set_dynamic}. If undefined, dynamic adjustment is
575 @multitable @columnfractions .20 .80
576 @item @emph{Prototype}: @tab @code{int omp_get_dynamic(void);}
579 @item @emph{Fortran}:
580 @multitable @columnfractions .20 .80
581 @item @emph{Interface}: @tab @code{logical function omp_get_dynamic()}
584 @item @emph{See also}:
585 @ref{omp_set_dynamic}, @ref{OMP_DYNAMIC}
587 @item @emph{Reference}:
588 @uref{https://www.openmp.org, OpenMP specification v4.5}, Section 3.2.8.
593 @node omp_get_initial_device
594 @section @code{omp_get_initial_device} -- Return device number of initial device
596 @item @emph{Description}:
597 This function returns a device number that represents the host device.
598 For OpenMP 5.1, this must be equal to the value returned by the
599 @code{omp_get_num_devices} function.
602 @multitable @columnfractions .20 .80
603 @item @emph{Prototype}: @tab @code{int omp_get_initial_device(void);}
606 @item @emph{Fortran}:
607 @multitable @columnfractions .20 .80
608 @item @emph{Interface}: @tab @code{integer function omp_get_initial_device()}
611 @item @emph{See also}:
612 @ref{omp_get_num_devices}
614 @item @emph{Reference}:
615 @uref{https://www.openmp.org, OpenMP specification v4.5}, Section 3.2.35.
621 @section @code{omp_get_level} -- Obtain the current nesting level
623 @item @emph{Description}:
624 This function returns the nesting level for the parallel blocks,
625 which enclose the calling call.
628 @multitable @columnfractions .20 .80
629 @item @emph{Prototype}: @tab @code{int omp_get_level(void);}
632 @item @emph{Fortran}:
633 @multitable @columnfractions .20 .80
634 @item @emph{Interface}: @tab @code{integer function omp_level()}
637 @item @emph{See also}:
638 @ref{omp_get_active_level}
640 @item @emph{Reference}:
641 @uref{https://www.openmp.org, OpenMP specification v4.5}, Section 3.2.17.
646 @node omp_get_max_active_levels
647 @section @code{omp_get_max_active_levels} -- Current maximum number of active regions
649 @item @emph{Description}:
650 This function obtains the maximum allowed number of nested, active parallel regions.
653 @multitable @columnfractions .20 .80
654 @item @emph{Prototype}: @tab @code{int omp_get_max_active_levels(void);}
657 @item @emph{Fortran}:
658 @multitable @columnfractions .20 .80
659 @item @emph{Interface}: @tab @code{integer function omp_get_max_active_levels()}
662 @item @emph{See also}:
663 @ref{omp_set_max_active_levels}, @ref{omp_get_active_level}
665 @item @emph{Reference}:
666 @uref{https://www.openmp.org, OpenMP specification v4.5}, Section 3.2.16.
670 @node omp_get_max_task_priority
671 @section @code{omp_get_max_task_priority} -- Maximum priority value
672 that can be set for tasks.
674 @item @emph{Description}:
675 This function obtains the maximum allowed priority number for tasks.
678 @multitable @columnfractions .20 .80
679 @item @emph{Prototype}: @tab @code{int omp_get_max_task_priority(void);}
682 @item @emph{Fortran}:
683 @multitable @columnfractions .20 .80
684 @item @emph{Interface}: @tab @code{integer function omp_get_max_task_priority()}
687 @item @emph{Reference}:
688 @uref{https://www.openmp.org, OpenMP specification v4.5}, Section 3.2.29.
692 @node omp_get_max_teams
693 @section @code{omp_get_max_teams} -- Maximum number of teams of teams region
695 @item @emph{Description}:
696 Return the maximum number of teams used for the teams region
697 that does not use the clause @code{num_teams}.
700 @multitable @columnfractions .20 .80
701 @item @emph{Prototype}: @tab @code{int omp_get_max_teams(void);}
704 @item @emph{Fortran}:
705 @multitable @columnfractions .20 .80
706 @item @emph{Interface}: @tab @code{integer function omp_get_max_teams()}
709 @item @emph{See also}:
710 @ref{omp_set_num_teams}, @ref{omp_get_num_teams}
712 @item @emph{Reference}:
713 @uref{https://www.openmp.org, OpenMP specification v5.1}, Section 3.4.4.
718 @node omp_get_max_threads
719 @section @code{omp_get_max_threads} -- Maximum number of threads of parallel region
721 @item @emph{Description}:
722 Return the maximum number of threads used for the current parallel region
723 that does not use the clause @code{num_threads}.
726 @multitable @columnfractions .20 .80
727 @item @emph{Prototype}: @tab @code{int omp_get_max_threads(void);}
730 @item @emph{Fortran}:
731 @multitable @columnfractions .20 .80
732 @item @emph{Interface}: @tab @code{integer function omp_get_max_threads()}
735 @item @emph{See also}:
736 @ref{omp_set_num_threads}, @ref{omp_set_dynamic}, @ref{omp_get_thread_limit}
738 @item @emph{Reference}:
739 @uref{https://www.openmp.org, OpenMP specification v4.5}, Section 3.2.3.
745 @section @code{omp_get_nested} -- Nested parallel regions
747 @item @emph{Description}:
748 This function returns @code{true} if nested parallel regions are
749 enabled, @code{false} otherwise. Here, @code{true} and @code{false}
750 represent their language-specific counterparts.
752 The state of nested parallel regions at startup depends on several
753 environment variables. If @env{OMP_MAX_ACTIVE_LEVELS} is defined
754 and is set to greater than one, then nested parallel regions will be
755 enabled. If not defined, then the value of the @env{OMP_NESTED}
756 environment variable will be followed if defined. If neither are
757 defined, then if either @env{OMP_NUM_THREADS} or @env{OMP_PROC_BIND}
758 are defined with a list of more than one value, then nested parallel
759 regions are enabled. If none of these are defined, then nested parallel
760 regions are disabled by default.
762 Nested parallel regions can be enabled or disabled at runtime using
763 @code{omp_set_nested}, or by setting the maximum number of nested
764 regions with @code{omp_set_max_active_levels} to one to disable, or
768 @multitable @columnfractions .20 .80
769 @item @emph{Prototype}: @tab @code{int omp_get_nested(void);}
772 @item @emph{Fortran}:
773 @multitable @columnfractions .20 .80
774 @item @emph{Interface}: @tab @code{logical function omp_get_nested()}
777 @item @emph{See also}:
778 @ref{omp_set_max_active_levels}, @ref{omp_set_nested},
779 @ref{OMP_MAX_ACTIVE_LEVELS}, @ref{OMP_NESTED}
781 @item @emph{Reference}:
782 @uref{https://www.openmp.org, OpenMP specification v4.5}, Section 3.2.11.
787 @node omp_get_num_devices
788 @section @code{omp_get_num_devices} -- Number of target devices
790 @item @emph{Description}:
791 Returns the number of target devices.
794 @multitable @columnfractions .20 .80
795 @item @emph{Prototype}: @tab @code{int omp_get_num_devices(void);}
798 @item @emph{Fortran}:
799 @multitable @columnfractions .20 .80
800 @item @emph{Interface}: @tab @code{integer function omp_get_num_devices()}
803 @item @emph{Reference}:
804 @uref{https://www.openmp.org, OpenMP specification v4.5}, Section 3.2.31.
809 @node omp_get_num_procs
810 @section @code{omp_get_num_procs} -- Number of processors online
812 @item @emph{Description}:
813 Returns the number of processors online on that device.
816 @multitable @columnfractions .20 .80
817 @item @emph{Prototype}: @tab @code{int omp_get_num_procs(void);}
820 @item @emph{Fortran}:
821 @multitable @columnfractions .20 .80
822 @item @emph{Interface}: @tab @code{integer function omp_get_num_procs()}
825 @item @emph{Reference}:
826 @uref{https://www.openmp.org, OpenMP specification v4.5}, Section 3.2.5.
831 @node omp_get_num_teams
832 @section @code{omp_get_num_teams} -- Number of teams
834 @item @emph{Description}:
835 Returns the number of teams in the current team region.
838 @multitable @columnfractions .20 .80
839 @item @emph{Prototype}: @tab @code{int omp_get_num_teams(void);}
842 @item @emph{Fortran}:
843 @multitable @columnfractions .20 .80
844 @item @emph{Interface}: @tab @code{integer function omp_get_num_teams()}
847 @item @emph{Reference}:
848 @uref{https://www.openmp.org, OpenMP specification v4.5}, Section 3.2.32.
853 @node omp_get_num_threads
854 @section @code{omp_get_num_threads} -- Size of the active team
856 @item @emph{Description}:
857 Returns the number of threads in the current team. In a sequential section of
858 the program @code{omp_get_num_threads} returns 1.
860 The default team size may be initialized at startup by the
861 @env{OMP_NUM_THREADS} environment variable. At runtime, the size
862 of the current team may be set either by the @code{NUM_THREADS}
863 clause or by @code{omp_set_num_threads}. If none of the above were
864 used to define a specific value and @env{OMP_DYNAMIC} is disabled,
865 one thread per CPU online is used.
868 @multitable @columnfractions .20 .80
869 @item @emph{Prototype}: @tab @code{int omp_get_num_threads(void);}
872 @item @emph{Fortran}:
873 @multitable @columnfractions .20 .80
874 @item @emph{Interface}: @tab @code{integer function omp_get_num_threads()}
877 @item @emph{See also}:
878 @ref{omp_get_max_threads}, @ref{omp_set_num_threads}, @ref{OMP_NUM_THREADS}
880 @item @emph{Reference}:
881 @uref{https://www.openmp.org, OpenMP specification v4.5}, Section 3.2.2.
886 @node omp_get_proc_bind
887 @section @code{omp_get_proc_bind} -- Whether theads may be moved between CPUs
889 @item @emph{Description}:
890 This functions returns the currently active thread affinity policy, which is
891 set via @env{OMP_PROC_BIND}. Possible values are @code{omp_proc_bind_false},
892 @code{omp_proc_bind_true}, @code{omp_proc_bind_primary},
893 @code{omp_proc_bind_master}, @code{omp_proc_bind_close} and @code{omp_proc_bind_spread},
894 where @code{omp_proc_bind_master} is an alias for @code{omp_proc_bind_primary}.
897 @multitable @columnfractions .20 .80
898 @item @emph{Prototype}: @tab @code{omp_proc_bind_t omp_get_proc_bind(void);}
901 @item @emph{Fortran}:
902 @multitable @columnfractions .20 .80
903 @item @emph{Interface}: @tab @code{integer(kind=omp_proc_bind_kind) function omp_get_proc_bind()}
906 @item @emph{See also}:
907 @ref{OMP_PROC_BIND}, @ref{OMP_PLACES}, @ref{GOMP_CPU_AFFINITY},
909 @item @emph{Reference}:
910 @uref{https://www.openmp.org, OpenMP specification v4.5}, Section 3.2.22.
915 @node omp_get_schedule
916 @section @code{omp_get_schedule} -- Obtain the runtime scheduling method
918 @item @emph{Description}:
919 Obtain the runtime scheduling method. The @var{kind} argument will be
920 set to the value @code{omp_sched_static}, @code{omp_sched_dynamic},
921 @code{omp_sched_guided} or @code{omp_sched_auto}. The second argument,
922 @var{chunk_size}, is set to the chunk size.
925 @multitable @columnfractions .20 .80
926 @item @emph{Prototype}: @tab @code{void omp_get_schedule(omp_sched_t *kind, int *chunk_size);}
929 @item @emph{Fortran}:
930 @multitable @columnfractions .20 .80
931 @item @emph{Interface}: @tab @code{subroutine omp_get_schedule(kind, chunk_size)}
932 @item @tab @code{integer(kind=omp_sched_kind) kind}
933 @item @tab @code{integer chunk_size}
936 @item @emph{See also}:
937 @ref{omp_set_schedule}, @ref{OMP_SCHEDULE}
939 @item @emph{Reference}:
940 @uref{https://www.openmp.org, OpenMP specification v4.5}, Section 3.2.13.
944 @node omp_get_supported_active_levels
945 @section @code{omp_get_supported_active_levels} -- Maximum number of active regions supported
947 @item @emph{Description}:
948 This function returns the maximum number of nested, active parallel regions
949 supported by this implementation.
952 @multitable @columnfractions .20 .80
953 @item @emph{Prototype}: @tab @code{int omp_get_supported_active_levels(void);}
956 @item @emph{Fortran}:
957 @multitable @columnfractions .20 .80
958 @item @emph{Interface}: @tab @code{integer function omp_get_supported_active_levels()}
961 @item @emph{See also}:
962 @ref{omp_get_max_active_levels}, @ref{omp_set_max_active_levels}
964 @item @emph{Reference}:
965 @uref{https://www.openmp.org, OpenMP specification v5.0}, Section 3.2.15.
970 @node omp_get_team_num
971 @section @code{omp_get_team_num} -- Get team number
973 @item @emph{Description}:
974 Returns the team number of the calling thread.
977 @multitable @columnfractions .20 .80
978 @item @emph{Prototype}: @tab @code{int omp_get_team_num(void);}
981 @item @emph{Fortran}:
982 @multitable @columnfractions .20 .80
983 @item @emph{Interface}: @tab @code{integer function omp_get_team_num()}
986 @item @emph{Reference}:
987 @uref{https://www.openmp.org, OpenMP specification v4.5}, Section 3.2.33.
992 @node omp_get_team_size
993 @section @code{omp_get_team_size} -- Number of threads in a team
995 @item @emph{Description}:
996 This function returns the number of threads in a thread team to which
997 either the current thread or its ancestor belongs. For values of @var{level}
998 outside zero to @code{omp_get_level}, -1 is returned; if @var{level} is zero,
999 1 is returned, and for @code{omp_get_level}, the result is identical
1000 to @code{omp_get_num_threads}.
1003 @multitable @columnfractions .20 .80
1004 @item @emph{Prototype}: @tab @code{int omp_get_team_size(int level);}
1007 @item @emph{Fortran}:
1008 @multitable @columnfractions .20 .80
1009 @item @emph{Interface}: @tab @code{integer function omp_get_team_size(level)}
1010 @item @tab @code{integer level}
1013 @item @emph{See also}:
1014 @ref{omp_get_num_threads}, @ref{omp_get_level}, @ref{omp_get_ancestor_thread_num}
1016 @item @emph{Reference}:
1017 @uref{https://www.openmp.org, OpenMP specification v4.5}, Section 3.2.19.
1022 @node omp_get_teams_thread_limit
1023 @section @code{omp_get_teams_thread_limit} -- Maximum number of threads imposed by teams
1025 @item @emph{Description}:
1026 Return the maximum number of threads that will be able to participate in
1027 each team created by a teams construct.
1030 @multitable @columnfractions .20 .80
1031 @item @emph{Prototype}: @tab @code{int omp_get_teams_thread_limit(void);}
1034 @item @emph{Fortran}:
1035 @multitable @columnfractions .20 .80
1036 @item @emph{Interface}: @tab @code{integer function omp_get_teams_thread_limit()}
1039 @item @emph{See also}:
1040 @ref{omp_set_teams_thread_limit}, @ref{OMP_TEAMS_THREAD_LIMIT}
1042 @item @emph{Reference}:
1043 @uref{https://www.openmp.org, OpenMP specification v5.1}, Section 3.4.6.
1048 @node omp_get_thread_limit
1049 @section @code{omp_get_thread_limit} -- Maximum number of threads
1051 @item @emph{Description}:
1052 Return the maximum number of threads of the program.
1055 @multitable @columnfractions .20 .80
1056 @item @emph{Prototype}: @tab @code{int omp_get_thread_limit(void);}
1059 @item @emph{Fortran}:
1060 @multitable @columnfractions .20 .80
1061 @item @emph{Interface}: @tab @code{integer function omp_get_thread_limit()}
1064 @item @emph{See also}:
1065 @ref{omp_get_max_threads}, @ref{OMP_THREAD_LIMIT}
1067 @item @emph{Reference}:
1068 @uref{https://www.openmp.org, OpenMP specification v4.5}, Section 3.2.14.
1073 @node omp_get_thread_num
1074 @section @code{omp_get_thread_num} -- Current thread ID
1076 @item @emph{Description}:
1077 Returns a unique thread identification number within the current team.
1078 In a sequential parts of the program, @code{omp_get_thread_num}
1079 always returns 0. In parallel regions the return value varies
1080 from 0 to @code{omp_get_num_threads}-1 inclusive. The return
1081 value of the primary thread of a team is always 0.
1084 @multitable @columnfractions .20 .80
1085 @item @emph{Prototype}: @tab @code{int omp_get_thread_num(void);}
1088 @item @emph{Fortran}:
1089 @multitable @columnfractions .20 .80
1090 @item @emph{Interface}: @tab @code{integer function omp_get_thread_num()}
1093 @item @emph{See also}:
1094 @ref{omp_get_num_threads}, @ref{omp_get_ancestor_thread_num}
1096 @item @emph{Reference}:
1097 @uref{https://www.openmp.org, OpenMP specification v4.5}, Section 3.2.4.
1102 @node omp_in_parallel
1103 @section @code{omp_in_parallel} -- Whether a parallel region is active
1105 @item @emph{Description}:
1106 This function returns @code{true} if currently running in parallel,
1107 @code{false} otherwise. Here, @code{true} and @code{false} represent
1108 their language-specific counterparts.
1111 @multitable @columnfractions .20 .80
1112 @item @emph{Prototype}: @tab @code{int omp_in_parallel(void);}
1115 @item @emph{Fortran}:
1116 @multitable @columnfractions .20 .80
1117 @item @emph{Interface}: @tab @code{logical function omp_in_parallel()}
1120 @item @emph{Reference}:
1121 @uref{https://www.openmp.org, OpenMP specification v4.5}, Section 3.2.6.
1126 @section @code{omp_in_final} -- Whether in final or included task region
1128 @item @emph{Description}:
1129 This function returns @code{true} if currently running in a final
1130 or included task region, @code{false} otherwise. Here, @code{true}
1131 and @code{false} represent their language-specific counterparts.
1134 @multitable @columnfractions .20 .80
1135 @item @emph{Prototype}: @tab @code{int omp_in_final(void);}
1138 @item @emph{Fortran}:
1139 @multitable @columnfractions .20 .80
1140 @item @emph{Interface}: @tab @code{logical function omp_in_final()}
1143 @item @emph{Reference}:
1144 @uref{https://www.openmp.org, OpenMP specification v4.5}, Section 3.2.21.
1149 @node omp_is_initial_device
1150 @section @code{omp_is_initial_device} -- Whether executing on the host device
1152 @item @emph{Description}:
1153 This function returns @code{true} if currently running on the host device,
1154 @code{false} otherwise. Here, @code{true} and @code{false} represent
1155 their language-specific counterparts.
1158 @multitable @columnfractions .20 .80
1159 @item @emph{Prototype}: @tab @code{int omp_is_initial_device(void);}
1162 @item @emph{Fortran}:
1163 @multitable @columnfractions .20 .80
1164 @item @emph{Interface}: @tab @code{logical function omp_is_initial_device()}
1167 @item @emph{Reference}:
1168 @uref{https://www.openmp.org, OpenMP specification v4.5}, Section 3.2.34.
1173 @node omp_set_default_device
1174 @section @code{omp_set_default_device} -- Set the default device for target regions
1176 @item @emph{Description}:
1177 Set the default device for target regions without device clause. The argument
1178 shall be a nonnegative device number.
1181 @multitable @columnfractions .20 .80
1182 @item @emph{Prototype}: @tab @code{void omp_set_default_device(int device_num);}
1185 @item @emph{Fortran}:
1186 @multitable @columnfractions .20 .80
1187 @item @emph{Interface}: @tab @code{subroutine omp_set_default_device(device_num)}
1188 @item @tab @code{integer device_num}
1191 @item @emph{See also}:
1192 @ref{OMP_DEFAULT_DEVICE}, @ref{omp_get_default_device}
1194 @item @emph{Reference}:
1195 @uref{https://www.openmp.org, OpenMP specification v4.5}, Section 3.2.29.
1200 @node omp_set_dynamic
1201 @section @code{omp_set_dynamic} -- Enable/disable dynamic teams
1203 @item @emph{Description}:
1204 Enable or disable the dynamic adjustment of the number of threads
1205 within a team. The function takes the language-specific equivalent
1206 of @code{true} and @code{false}, where @code{true} enables dynamic
1207 adjustment of team sizes and @code{false} disables it.
1210 @multitable @columnfractions .20 .80
1211 @item @emph{Prototype}: @tab @code{void omp_set_dynamic(int dynamic_threads);}
1214 @item @emph{Fortran}:
1215 @multitable @columnfractions .20 .80
1216 @item @emph{Interface}: @tab @code{subroutine omp_set_dynamic(dynamic_threads)}
1217 @item @tab @code{logical, intent(in) :: dynamic_threads}
1220 @item @emph{See also}:
1221 @ref{OMP_DYNAMIC}, @ref{omp_get_dynamic}
1223 @item @emph{Reference}:
1224 @uref{https://www.openmp.org, OpenMP specification v4.5}, Section 3.2.7.
1229 @node omp_set_max_active_levels
1230 @section @code{omp_set_max_active_levels} -- Limits the number of active parallel regions
1232 @item @emph{Description}:
1233 This function limits the maximum allowed number of nested, active
1234 parallel regions. @var{max_levels} must be less or equal to
1235 the value returned by @code{omp_get_supported_active_levels}.
1238 @multitable @columnfractions .20 .80
1239 @item @emph{Prototype}: @tab @code{void omp_set_max_active_levels(int max_levels);}
1242 @item @emph{Fortran}:
1243 @multitable @columnfractions .20 .80
1244 @item @emph{Interface}: @tab @code{subroutine omp_set_max_active_levels(max_levels)}
1245 @item @tab @code{integer max_levels}
1248 @item @emph{See also}:
1249 @ref{omp_get_max_active_levels}, @ref{omp_get_active_level},
1250 @ref{omp_get_supported_active_levels}
1252 @item @emph{Reference}:
1253 @uref{https://www.openmp.org, OpenMP specification v4.5}, Section 3.2.15.
1258 @node omp_set_nested
1259 @section @code{omp_set_nested} -- Enable/disable nested parallel regions
1261 @item @emph{Description}:
1262 Enable or disable nested parallel regions, i.e., whether team members
1263 are allowed to create new teams. The function takes the language-specific
1264 equivalent of @code{true} and @code{false}, where @code{true} enables
1265 dynamic adjustment of team sizes and @code{false} disables it.
1267 Enabling nested parallel regions will also set the maximum number of
1268 active nested regions to the maximum supported. Disabling nested parallel
1269 regions will set the maximum number of active nested regions to one.
1272 @multitable @columnfractions .20 .80
1273 @item @emph{Prototype}: @tab @code{void omp_set_nested(int nested);}
1276 @item @emph{Fortran}:
1277 @multitable @columnfractions .20 .80
1278 @item @emph{Interface}: @tab @code{subroutine omp_set_nested(nested)}
1279 @item @tab @code{logical, intent(in) :: nested}
1282 @item @emph{See also}:
1283 @ref{omp_get_nested}, @ref{omp_set_max_active_levels},
1284 @ref{OMP_MAX_ACTIVE_LEVELS}, @ref{OMP_NESTED}
1286 @item @emph{Reference}:
1287 @uref{https://www.openmp.org, OpenMP specification v4.5}, Section 3.2.10.
1292 @node omp_set_num_teams
1293 @section @code{omp_set_num_teams} -- Set upper teams limit for teams construct
1295 @item @emph{Description}:
1296 Specifies the upper bound for number of teams created by the teams construct
1297 which does not specify a @code{num_teams} clause. The
1298 argument of @code{omp_set_num_teams} shall be a positive integer.
1301 @multitable @columnfractions .20 .80
1302 @item @emph{Prototype}: @tab @code{void omp_set_num_teams(int num_teams);}
1305 @item @emph{Fortran}:
1306 @multitable @columnfractions .20 .80
1307 @item @emph{Interface}: @tab @code{subroutine omp_set_num_teams(num_teams)}
1308 @item @tab @code{integer, intent(in) :: num_teams}
1311 @item @emph{See also}:
1312 @ref{OMP_NUM_TEAMS}, @ref{omp_get_num_teams}, @ref{omp_get_max_teams}
1314 @item @emph{Reference}:
1315 @uref{https://www.openmp.org, OpenMP specification v5.1}, Section 3.4.3.
1320 @node omp_set_num_threads
1321 @section @code{omp_set_num_threads} -- Set upper team size limit
1323 @item @emph{Description}:
1324 Specifies the number of threads used by default in subsequent parallel
1325 sections, if those do not specify a @code{num_threads} clause. The
1326 argument of @code{omp_set_num_threads} shall be a positive integer.
1329 @multitable @columnfractions .20 .80
1330 @item @emph{Prototype}: @tab @code{void omp_set_num_threads(int num_threads);}
1333 @item @emph{Fortran}:
1334 @multitable @columnfractions .20 .80
1335 @item @emph{Interface}: @tab @code{subroutine omp_set_num_threads(num_threads)}
1336 @item @tab @code{integer, intent(in) :: num_threads}
1339 @item @emph{See also}:
1340 @ref{OMP_NUM_THREADS}, @ref{omp_get_num_threads}, @ref{omp_get_max_threads}
1342 @item @emph{Reference}:
1343 @uref{https://www.openmp.org, OpenMP specification v4.5}, Section 3.2.1.
1348 @node omp_set_schedule
1349 @section @code{omp_set_schedule} -- Set the runtime scheduling method
1351 @item @emph{Description}:
1352 Sets the runtime scheduling method. The @var{kind} argument can have the
1353 value @code{omp_sched_static}, @code{omp_sched_dynamic},
1354 @code{omp_sched_guided} or @code{omp_sched_auto}. Except for
1355 @code{omp_sched_auto}, the chunk size is set to the value of
1356 @var{chunk_size} if positive, or to the default value if zero or negative.
1357 For @code{omp_sched_auto} the @var{chunk_size} argument is ignored.
1360 @multitable @columnfractions .20 .80
1361 @item @emph{Prototype}: @tab @code{void omp_set_schedule(omp_sched_t kind, int chunk_size);}
1364 @item @emph{Fortran}:
1365 @multitable @columnfractions .20 .80
1366 @item @emph{Interface}: @tab @code{subroutine omp_set_schedule(kind, chunk_size)}
1367 @item @tab @code{integer(kind=omp_sched_kind) kind}
1368 @item @tab @code{integer chunk_size}
1371 @item @emph{See also}:
1372 @ref{omp_get_schedule}
1375 @item @emph{Reference}:
1376 @uref{https://www.openmp.org, OpenMP specification v4.5}, Section 3.2.12.
1381 @node omp_set_teams_thread_limit
1382 @section @code{omp_set_teams_thread_limit} -- Set upper thread limit for teams construct
1384 @item @emph{Description}:
1385 Specifies the upper bound for number of threads that will be available
1386 for each team created by the teams construct which does not specify a
1387 @code{thread_limit} clause. The argument of
1388 @code{omp_set_teams_thread_limit} shall be a positive integer.
1391 @multitable @columnfractions .20 .80
1392 @item @emph{Prototype}: @tab @code{void omp_set_teams_thread_limit(int thread_limit);}
1395 @item @emph{Fortran}:
1396 @multitable @columnfractions .20 .80
1397 @item @emph{Interface}: @tab @code{subroutine omp_set_teams_thread_limit(thread_limit)}
1398 @item @tab @code{integer, intent(in) :: thread_limit}
1401 @item @emph{See also}:
1402 @ref{OMP_TEAMS_THREAD_LIMIT}, @ref{omp_get_teams_thread_limit}, @ref{omp_get_thread_limit}
1404 @item @emph{Reference}:
1405 @uref{https://www.openmp.org, OpenMP specification v5.1}, Section 3.4.5.
1411 @section @code{omp_init_lock} -- Initialize simple lock
1413 @item @emph{Description}:
1414 Initialize a simple lock. After initialization, the lock is in
1418 @multitable @columnfractions .20 .80
1419 @item @emph{Prototype}: @tab @code{void omp_init_lock(omp_lock_t *lock);}
1422 @item @emph{Fortran}:
1423 @multitable @columnfractions .20 .80
1424 @item @emph{Interface}: @tab @code{subroutine omp_init_lock(svar)}
1425 @item @tab @code{integer(omp_lock_kind), intent(out) :: svar}
1428 @item @emph{See also}:
1429 @ref{omp_destroy_lock}
1431 @item @emph{Reference}:
1432 @uref{https://www.openmp.org, OpenMP specification v4.5}, Section 3.3.1.
1438 @section @code{omp_set_lock} -- Wait for and set simple lock
1440 @item @emph{Description}:
1441 Before setting a simple lock, the lock variable must be initialized by
1442 @code{omp_init_lock}. The calling thread is blocked until the lock
1443 is available. If the lock is already held by the current thread,
1447 @multitable @columnfractions .20 .80
1448 @item @emph{Prototype}: @tab @code{void omp_set_lock(omp_lock_t *lock);}
1451 @item @emph{Fortran}:
1452 @multitable @columnfractions .20 .80
1453 @item @emph{Interface}: @tab @code{subroutine omp_set_lock(svar)}
1454 @item @tab @code{integer(omp_lock_kind), intent(inout) :: svar}
1457 @item @emph{See also}:
1458 @ref{omp_init_lock}, @ref{omp_test_lock}, @ref{omp_unset_lock}
1460 @item @emph{Reference}:
1461 @uref{https://www.openmp.org, OpenMP specification v4.5}, Section 3.3.4.
1467 @section @code{omp_test_lock} -- Test and set simple lock if available
1469 @item @emph{Description}:
1470 Before setting a simple lock, the lock variable must be initialized by
1471 @code{omp_init_lock}. Contrary to @code{omp_set_lock}, @code{omp_test_lock}
1472 does not block if the lock is not available. This function returns
1473 @code{true} upon success, @code{false} otherwise. Here, @code{true} and
1474 @code{false} represent their language-specific counterparts.
1477 @multitable @columnfractions .20 .80
1478 @item @emph{Prototype}: @tab @code{int omp_test_lock(omp_lock_t *lock);}
1481 @item @emph{Fortran}:
1482 @multitable @columnfractions .20 .80
1483 @item @emph{Interface}: @tab @code{logical function omp_test_lock(svar)}
1484 @item @tab @code{integer(omp_lock_kind), intent(inout) :: svar}
1487 @item @emph{See also}:
1488 @ref{omp_init_lock}, @ref{omp_set_lock}, @ref{omp_set_lock}
1490 @item @emph{Reference}:
1491 @uref{https://www.openmp.org, OpenMP specification v4.5}, Section 3.3.6.
1496 @node omp_unset_lock
1497 @section @code{omp_unset_lock} -- Unset simple lock
1499 @item @emph{Description}:
1500 A simple lock about to be unset must have been locked by @code{omp_set_lock}
1501 or @code{omp_test_lock} before. In addition, the lock must be held by the
1502 thread calling @code{omp_unset_lock}. Then, the lock becomes unlocked. If one
1503 or more threads attempted to set the lock before, one of them is chosen to,
1504 again, set the lock to itself.
1507 @multitable @columnfractions .20 .80
1508 @item @emph{Prototype}: @tab @code{void omp_unset_lock(omp_lock_t *lock);}
1511 @item @emph{Fortran}:
1512 @multitable @columnfractions .20 .80
1513 @item @emph{Interface}: @tab @code{subroutine omp_unset_lock(svar)}
1514 @item @tab @code{integer(omp_lock_kind), intent(inout) :: svar}
1517 @item @emph{See also}:
1518 @ref{omp_set_lock}, @ref{omp_test_lock}
1520 @item @emph{Reference}:
1521 @uref{https://www.openmp.org, OpenMP specification v4.5}, Section 3.3.5.
1526 @node omp_destroy_lock
1527 @section @code{omp_destroy_lock} -- Destroy simple lock
1529 @item @emph{Description}:
1530 Destroy a simple lock. In order to be destroyed, a simple lock must be
1531 in the unlocked state.
1534 @multitable @columnfractions .20 .80
1535 @item @emph{Prototype}: @tab @code{void omp_destroy_lock(omp_lock_t *lock);}
1538 @item @emph{Fortran}:
1539 @multitable @columnfractions .20 .80
1540 @item @emph{Interface}: @tab @code{subroutine omp_destroy_lock(svar)}
1541 @item @tab @code{integer(omp_lock_kind), intent(inout) :: svar}
1544 @item @emph{See also}:
1547 @item @emph{Reference}:
1548 @uref{https://www.openmp.org, OpenMP specification v4.5}, Section 3.3.3.
1553 @node omp_init_nest_lock
1554 @section @code{omp_init_nest_lock} -- Initialize nested lock
1556 @item @emph{Description}:
1557 Initialize a nested lock. After initialization, the lock is in
1558 an unlocked state and the nesting count is set to zero.
1561 @multitable @columnfractions .20 .80
1562 @item @emph{Prototype}: @tab @code{void omp_init_nest_lock(omp_nest_lock_t *lock);}
1565 @item @emph{Fortran}:
1566 @multitable @columnfractions .20 .80
1567 @item @emph{Interface}: @tab @code{subroutine omp_init_nest_lock(nvar)}
1568 @item @tab @code{integer(omp_nest_lock_kind), intent(out) :: nvar}
1571 @item @emph{See also}:
1572 @ref{omp_destroy_nest_lock}
1574 @item @emph{Reference}:
1575 @uref{https://www.openmp.org, OpenMP specification v4.5}, Section 3.3.1.
1579 @node omp_set_nest_lock
1580 @section @code{omp_set_nest_lock} -- Wait for and set nested lock
1582 @item @emph{Description}:
1583 Before setting a nested lock, the lock variable must be initialized by
1584 @code{omp_init_nest_lock}. The calling thread is blocked until the lock
1585 is available. If the lock is already held by the current thread, the
1586 nesting count for the lock is incremented.
1589 @multitable @columnfractions .20 .80
1590 @item @emph{Prototype}: @tab @code{void omp_set_nest_lock(omp_nest_lock_t *lock);}
1593 @item @emph{Fortran}:
1594 @multitable @columnfractions .20 .80
1595 @item @emph{Interface}: @tab @code{subroutine omp_set_nest_lock(nvar)}
1596 @item @tab @code{integer(omp_nest_lock_kind), intent(inout) :: nvar}
1599 @item @emph{See also}:
1600 @ref{omp_init_nest_lock}, @ref{omp_unset_nest_lock}
1602 @item @emph{Reference}:
1603 @uref{https://www.openmp.org, OpenMP specification v4.5}, Section 3.3.4.
1608 @node omp_test_nest_lock
1609 @section @code{omp_test_nest_lock} -- Test and set nested lock if available
1611 @item @emph{Description}:
1612 Before setting a nested lock, the lock variable must be initialized by
1613 @code{omp_init_nest_lock}. Contrary to @code{omp_set_nest_lock},
1614 @code{omp_test_nest_lock} does not block if the lock is not available.
1615 If the lock is already held by the current thread, the new nesting count
1616 is returned. Otherwise, the return value equals zero.
1619 @multitable @columnfractions .20 .80
1620 @item @emph{Prototype}: @tab @code{int omp_test_nest_lock(omp_nest_lock_t *lock);}
1623 @item @emph{Fortran}:
1624 @multitable @columnfractions .20 .80
1625 @item @emph{Interface}: @tab @code{logical function omp_test_nest_lock(nvar)}
1626 @item @tab @code{integer(omp_nest_lock_kind), intent(inout) :: nvar}
1630 @item @emph{See also}:
1631 @ref{omp_init_lock}, @ref{omp_set_lock}, @ref{omp_set_lock}
1633 @item @emph{Reference}:
1634 @uref{https://www.openmp.org, OpenMP specification v4.5}, Section 3.3.6.
1639 @node omp_unset_nest_lock
1640 @section @code{omp_unset_nest_lock} -- Unset nested lock
1642 @item @emph{Description}:
1643 A nested lock about to be unset must have been locked by @code{omp_set_nested_lock}
1644 or @code{omp_test_nested_lock} before. In addition, the lock must be held by the
1645 thread calling @code{omp_unset_nested_lock}. If the nesting count drops to zero, the
1646 lock becomes unlocked. If one ore more threads attempted to set the lock before,
1647 one of them is chosen to, again, set the lock to itself.
1650 @multitable @columnfractions .20 .80
1651 @item @emph{Prototype}: @tab @code{void omp_unset_nest_lock(omp_nest_lock_t *lock);}
1654 @item @emph{Fortran}:
1655 @multitable @columnfractions .20 .80
1656 @item @emph{Interface}: @tab @code{subroutine omp_unset_nest_lock(nvar)}
1657 @item @tab @code{integer(omp_nest_lock_kind), intent(inout) :: nvar}
1660 @item @emph{See also}:
1661 @ref{omp_set_nest_lock}
1663 @item @emph{Reference}:
1664 @uref{https://www.openmp.org, OpenMP specification v4.5}, Section 3.3.5.
1669 @node omp_destroy_nest_lock
1670 @section @code{omp_destroy_nest_lock} -- Destroy nested lock
1672 @item @emph{Description}:
1673 Destroy a nested lock. In order to be destroyed, a nested lock must be
1674 in the unlocked state and its nesting count must equal zero.
1677 @multitable @columnfractions .20 .80
1678 @item @emph{Prototype}: @tab @code{void omp_destroy_nest_lock(omp_nest_lock_t *);}
1681 @item @emph{Fortran}:
1682 @multitable @columnfractions .20 .80
1683 @item @emph{Interface}: @tab @code{subroutine omp_destroy_nest_lock(nvar)}
1684 @item @tab @code{integer(omp_nest_lock_kind), intent(inout) :: nvar}
1687 @item @emph{See also}:
1690 @item @emph{Reference}:
1691 @uref{https://www.openmp.org, OpenMP specification v4.5}, Section 3.3.3.
1697 @section @code{omp_get_wtick} -- Get timer precision
1699 @item @emph{Description}:
1700 Gets the timer precision, i.e., the number of seconds between two
1701 successive clock ticks.
1704 @multitable @columnfractions .20 .80
1705 @item @emph{Prototype}: @tab @code{double omp_get_wtick(void);}
1708 @item @emph{Fortran}:
1709 @multitable @columnfractions .20 .80
1710 @item @emph{Interface}: @tab @code{double precision function omp_get_wtick()}
1713 @item @emph{See also}:
1716 @item @emph{Reference}:
1717 @uref{https://www.openmp.org, OpenMP specification v4.5}, Section 3.4.2.
1723 @section @code{omp_get_wtime} -- Elapsed wall clock time
1725 @item @emph{Description}:
1726 Elapsed wall clock time in seconds. The time is measured per thread, no
1727 guarantee can be made that two distinct threads measure the same time.
1728 Time is measured from some "time in the past", which is an arbitrary time
1729 guaranteed not to change during the execution of the program.
1732 @multitable @columnfractions .20 .80
1733 @item @emph{Prototype}: @tab @code{double omp_get_wtime(void);}
1736 @item @emph{Fortran}:
1737 @multitable @columnfractions .20 .80
1738 @item @emph{Interface}: @tab @code{double precision function omp_get_wtime()}
1741 @item @emph{See also}:
1744 @item @emph{Reference}:
1745 @uref{https://www.openmp.org, OpenMP specification v4.5}, Section 3.4.1.
1750 @node omp_fulfill_event
1751 @section @code{omp_fulfill_event} -- Fulfill and destroy an OpenMP event
1753 @item @emph{Description}:
1754 Fulfill the event associated with the event handle argument. Currently, it
1755 is only used to fulfill events generated by detach clauses on task
1756 constructs - the effect of fulfilling the event is to allow the task to
1759 The result of calling @code{omp_fulfill_event} with an event handle other
1760 than that generated by a detach clause is undefined. Calling it with an
1761 event handle that has already been fulfilled is also undefined.
1764 @multitable @columnfractions .20 .80
1765 @item @emph{Prototype}: @tab @code{void omp_fulfill_event(omp_event_handle_t event);}
1768 @item @emph{Fortran}:
1769 @multitable @columnfractions .20 .80
1770 @item @emph{Interface}: @tab @code{subroutine omp_fulfill_event(event)}
1771 @item @tab @code{integer (kind=omp_event_handle_kind) :: event}
1774 @item @emph{Reference}:
1775 @uref{https://www.openmp.org, OpenMP specification v5.0}, Section 3.5.1.
1780 @c ---------------------------------------------------------------------
1781 @c OpenMP Environment Variables
1782 @c ---------------------------------------------------------------------
1784 @node Environment Variables
1785 @chapter OpenMP Environment Variables
1787 The environment variables which beginning with @env{OMP_} are defined by
1788 section 4 of the OpenMP specification in version 4.5, while those
1789 beginning with @env{GOMP_} are GNU extensions.
1792 * OMP_CANCELLATION:: Set whether cancellation is activated
1793 * OMP_DISPLAY_ENV:: Show OpenMP version and environment variables
1794 * OMP_DEFAULT_DEVICE:: Set the device used in target regions
1795 * OMP_DYNAMIC:: Dynamic adjustment of threads
1796 * OMP_MAX_ACTIVE_LEVELS:: Set the maximum number of nested parallel regions
1797 * OMP_MAX_TASK_PRIORITY:: Set the maximum task priority value
1798 * OMP_NESTED:: Nested parallel regions
1799 * OMP_NUM_TEAMS:: Specifies the number of teams to use by teams region
1800 * OMP_NUM_THREADS:: Specifies the number of threads to use
1801 * OMP_PROC_BIND:: Whether theads may be moved between CPUs
1802 * OMP_PLACES:: Specifies on which CPUs the theads should be placed
1803 * OMP_STACKSIZE:: Set default thread stack size
1804 * OMP_SCHEDULE:: How threads are scheduled
1805 * OMP_TARGET_OFFLOAD:: Controls offloading behaviour
1806 * OMP_TEAMS_THREAD_LIMIT:: Set the maximum number of threads imposed by teams
1807 * OMP_THREAD_LIMIT:: Set the maximum number of threads
1808 * OMP_WAIT_POLICY:: How waiting threads are handled
1809 * GOMP_CPU_AFFINITY:: Bind threads to specific CPUs
1810 * GOMP_DEBUG:: Enable debugging output
1811 * GOMP_STACKSIZE:: Set default thread stack size
1812 * GOMP_SPINCOUNT:: Set the busy-wait spin count
1813 * GOMP_RTEMS_THREAD_POOLS:: Set the RTEMS specific thread pools
1817 @node OMP_CANCELLATION
1818 @section @env{OMP_CANCELLATION} -- Set whether cancellation is activated
1819 @cindex Environment Variable
1821 @item @emph{Description}:
1822 If set to @code{TRUE}, the cancellation is activated. If set to @code{FALSE} or
1823 if unset, cancellation is disabled and the @code{cancel} construct is ignored.
1825 @item @emph{See also}:
1826 @ref{omp_get_cancellation}
1828 @item @emph{Reference}:
1829 @uref{https://www.openmp.org, OpenMP specification v4.5}, Section 4.11
1834 @node OMP_DISPLAY_ENV
1835 @section @env{OMP_DISPLAY_ENV} -- Show OpenMP version and environment variables
1836 @cindex Environment Variable
1838 @item @emph{Description}:
1839 If set to @code{TRUE}, the OpenMP version number and the values
1840 associated with the OpenMP environment variables are printed to @code{stderr}.
1841 If set to @code{VERBOSE}, it additionally shows the value of the environment
1842 variables which are GNU extensions. If undefined or set to @code{FALSE},
1843 this information will not be shown.
1846 @item @emph{Reference}:
1847 @uref{https://www.openmp.org, OpenMP specification v4.5}, Section 4.12
1852 @node OMP_DEFAULT_DEVICE
1853 @section @env{OMP_DEFAULT_DEVICE} -- Set the device used in target regions
1854 @cindex Environment Variable
1856 @item @emph{Description}:
1857 Set to choose the device which is used in a @code{target} region, unless the
1858 value is overridden by @code{omp_set_default_device} or by a @code{device}
1859 clause. The value shall be the nonnegative device number. If no device with
1860 the given device number exists, the code is executed on the host. If unset,
1861 device number 0 will be used.
1864 @item @emph{See also}:
1865 @ref{omp_get_default_device}, @ref{omp_set_default_device},
1867 @item @emph{Reference}:
1868 @uref{https://www.openmp.org, OpenMP specification v4.5}, Section 4.13
1874 @section @env{OMP_DYNAMIC} -- Dynamic adjustment of threads
1875 @cindex Environment Variable
1877 @item @emph{Description}:
1878 Enable or disable the dynamic adjustment of the number of threads
1879 within a team. The value of this environment variable shall be
1880 @code{TRUE} or @code{FALSE}. If undefined, dynamic adjustment is
1881 disabled by default.
1883 @item @emph{See also}:
1884 @ref{omp_set_dynamic}
1886 @item @emph{Reference}:
1887 @uref{https://www.openmp.org, OpenMP specification v4.5}, Section 4.3
1892 @node OMP_MAX_ACTIVE_LEVELS
1893 @section @env{OMP_MAX_ACTIVE_LEVELS} -- Set the maximum number of nested parallel regions
1894 @cindex Environment Variable
1896 @item @emph{Description}:
1897 Specifies the initial value for the maximum number of nested parallel
1898 regions. The value of this variable shall be a positive integer.
1899 If undefined, then if @env{OMP_NESTED} is defined and set to true, or
1900 if @env{OMP_NUM_THREADS} or @env{OMP_PROC_BIND} are defined and set to
1901 a list with more than one item, the maximum number of nested parallel
1902 regions will be initialized to the largest number supported, otherwise
1903 it will be set to one.
1905 @item @emph{See also}:
1906 @ref{omp_set_max_active_levels}, @ref{OMP_NESTED}
1908 @item @emph{Reference}:
1909 @uref{https://www.openmp.org, OpenMP specification v4.5}, Section 4.9
1914 @node OMP_MAX_TASK_PRIORITY
1915 @section @env{OMP_MAX_TASK_PRIORITY} -- Set the maximum priority
1916 number that can be set for a task.
1917 @cindex Environment Variable
1919 @item @emph{Description}:
1920 Specifies the initial value for the maximum priority value that can be
1921 set for a task. The value of this variable shall be a non-negative
1922 integer, and zero is allowed. If undefined, the default priority is
1925 @item @emph{See also}:
1926 @ref{omp_get_max_task_priority}
1928 @item @emph{Reference}:
1929 @uref{https://www.openmp.org, OpenMP specification v4.5}, Section 4.14
1935 @section @env{OMP_NESTED} -- Nested parallel regions
1936 @cindex Environment Variable
1937 @cindex Implementation specific setting
1939 @item @emph{Description}:
1940 Enable or disable nested parallel regions, i.e., whether team members
1941 are allowed to create new teams. The value of this environment variable
1942 shall be @code{TRUE} or @code{FALSE}. If set to @code{TRUE}, the number
1943 of maximum active nested regions supported will by default be set to the
1944 maximum supported, otherwise it will be set to one. If
1945 @env{OMP_MAX_ACTIVE_LEVELS} is defined, its setting will override this
1946 setting. If both are undefined, nested parallel regions are enabled if
1947 @env{OMP_NUM_THREADS} or @env{OMP_PROC_BINDS} are defined to a list with
1948 more than one item, otherwise they are disabled by default.
1950 @item @emph{See also}:
1951 @ref{omp_set_max_active_levels}, @ref{omp_set_nested}
1953 @item @emph{Reference}:
1954 @uref{https://www.openmp.org, OpenMP specification v4.5}, Section 4.6
1960 @section @env{OMP_NUM_TEAMS} -- Specifies the number of teams to use by teams region
1961 @cindex Environment Variable
1963 @item @emph{Description}:
1964 Specifies the upper bound for number of teams to use in teams regions
1965 without explicit @code{num_teams} clause. The value of this variable shall
1966 be a positive integer. If undefined it defaults to 0 which means
1967 implementation defined upper bound.
1969 @item @emph{See also}:
1970 @ref{omp_set_num_teams}
1972 @item @emph{Reference}:
1973 @uref{https://www.openmp.org, OpenMP specification v5.1}, Section 6.23
1978 @node OMP_NUM_THREADS
1979 @section @env{OMP_NUM_THREADS} -- Specifies the number of threads to use
1980 @cindex Environment Variable
1981 @cindex Implementation specific setting
1983 @item @emph{Description}:
1984 Specifies the default number of threads to use in parallel regions. The
1985 value of this variable shall be a comma-separated list of positive integers;
1986 the value specifies the number of threads to use for the corresponding nested
1987 level. Specifying more than one item in the list will automatically enable
1988 nesting by default. If undefined one thread per CPU is used.
1990 @item @emph{See also}:
1991 @ref{omp_set_num_threads}, @ref{OMP_NESTED}
1993 @item @emph{Reference}:
1994 @uref{https://www.openmp.org, OpenMP specification v4.5}, Section 4.2
2000 @section @env{OMP_PROC_BIND} -- Whether theads may be moved between CPUs
2001 @cindex Environment Variable
2003 @item @emph{Description}:
2004 Specifies whether threads may be moved between processors. If set to
2005 @code{TRUE}, OpenMP theads should not be moved; if set to @code{FALSE}
2006 they may be moved. Alternatively, a comma separated list with the
2007 values @code{PRIMARY}, @code{MASTER}, @code{CLOSE} and @code{SPREAD} can
2008 be used to specify the thread affinity policy for the corresponding nesting
2009 level. With @code{PRIMARY} and @code{MASTER} the worker threads are in the
2010 same place partition as the primary thread. With @code{CLOSE} those are
2011 kept close to the primary thread in contiguous place partitions. And
2012 with @code{SPREAD} a sparse distribution
2013 across the place partitions is used. Specifying more than one item in the
2014 list will automatically enable nesting by default.
2016 When undefined, @env{OMP_PROC_BIND} defaults to @code{TRUE} when
2017 @env{OMP_PLACES} or @env{GOMP_CPU_AFFINITY} is set and @code{FALSE} otherwise.
2019 @item @emph{See also}:
2020 @ref{omp_get_proc_bind}, @ref{GOMP_CPU_AFFINITY},
2021 @ref{OMP_NESTED}, @ref{OMP_PLACES}
2023 @item @emph{Reference}:
2024 @uref{https://www.openmp.org, OpenMP specification v4.5}, Section 4.4
2030 @section @env{OMP_PLACES} -- Specifies on which CPUs the theads should be placed
2031 @cindex Environment Variable
2033 @item @emph{Description}:
2034 The thread placement can be either specified using an abstract name or by an
2035 explicit list of the places. The abstract names @code{threads}, @code{cores},
2036 @code{sockets}, @code{ll_caches} and @code{numa_domains} can be optionally
2037 followed by a positive number in parentheses, which denotes the how many places
2038 shall be created. With @code{threads} each place corresponds to a single
2039 hardware thread; @code{cores} to a single core with the corresponding number of
2040 hardware threads; with @code{sockets} the place corresponds to a single
2041 socket; with @code{ll_caches} to a set of cores that shares the last level
2042 cache on the device; and @code{numa_domains} to a set of cores for which their
2043 closest memory on the device is the same memory and at a similar distance from
2044 the cores. The resulting placement can be shown by setting the
2045 @env{OMP_DISPLAY_ENV} environment variable.
2047 Alternatively, the placement can be specified explicitly as comma-separated
2048 list of places. A place is specified by set of nonnegative numbers in curly
2049 braces, denoting the hardware threads. The curly braces can be omitted
2050 when only a single number has been specified. The hardware threads
2051 belonging to a place can either be specified as comma-separated list of
2052 nonnegative thread numbers or using an interval. Multiple places can also be
2053 either specified by a comma-separated list of places or by an interval. To
2054 specify an interval, a colon followed by the count is placed after
2055 the hardware thread number or the place. Optionally, the length can be
2056 followed by a colon and the stride number -- otherwise a unit stride is
2057 assumed. Placing an exclamation mark (@code{!}) directly before a curly
2058 brace or numbers inside the curly braces (excluding intervals) will
2059 exclude those hardware threads.
2061 For instance, the following specifies the same places list:
2062 @code{"@{0,1,2@}, @{3,4,6@}, @{7,8,9@}, @{10,11,12@}"};
2063 @code{"@{0:3@}, @{3:3@}, @{7:3@}, @{10:3@}"}; and @code{"@{0:2@}:4:3"}.
2065 If @env{OMP_PLACES} and @env{GOMP_CPU_AFFINITY} are unset and
2066 @env{OMP_PROC_BIND} is either unset or @code{false}, threads may be moved
2067 between CPUs following no placement policy.
2069 @item @emph{See also}:
2070 @ref{OMP_PROC_BIND}, @ref{GOMP_CPU_AFFINITY}, @ref{omp_get_proc_bind},
2071 @ref{OMP_DISPLAY_ENV}
2073 @item @emph{Reference}:
2074 @uref{https://www.openmp.org, OpenMP specification v4.5}, Section 4.5
2080 @section @env{OMP_STACKSIZE} -- Set default thread stack size
2081 @cindex Environment Variable
2083 @item @emph{Description}:
2084 Set the default thread stack size in kilobytes, unless the number
2085 is suffixed by @code{B}, @code{K}, @code{M} or @code{G}, in which
2086 case the size is, respectively, in bytes, kilobytes, megabytes
2087 or gigabytes. This is different from @code{pthread_attr_setstacksize}
2088 which gets the number of bytes as an argument. If the stack size cannot
2089 be set due to system constraints, an error is reported and the initial
2090 stack size is left unchanged. If undefined, the stack size is system
2093 @item @emph{Reference}:
2094 @uref{https://www.openmp.org, OpenMP specification v4.5}, Section 4.7
2100 @section @env{OMP_SCHEDULE} -- How threads are scheduled
2101 @cindex Environment Variable
2102 @cindex Implementation specific setting
2104 @item @emph{Description}:
2105 Allows to specify @code{schedule type} and @code{chunk size}.
2106 The value of the variable shall have the form: @code{type[,chunk]} where
2107 @code{type} is one of @code{static}, @code{dynamic}, @code{guided} or @code{auto}
2108 The optional @code{chunk} size shall be a positive integer. If undefined,
2109 dynamic scheduling and a chunk size of 1 is used.
2111 @item @emph{See also}:
2112 @ref{omp_set_schedule}
2114 @item @emph{Reference}:
2115 @uref{https://www.openmp.org, OpenMP specification v4.5}, Sections 2.7.1.1 and 4.1
2120 @node OMP_TARGET_OFFLOAD
2121 @section @env{OMP_TARGET_OFFLOAD} -- Controls offloading behaviour
2122 @cindex Environment Variable
2123 @cindex Implementation specific setting
2125 @item @emph{Description}:
2126 Specifies the behaviour with regard to offloading code to a device. This
2127 variable can be set to one of three values - @code{MANDATORY}, @code{DISABLED}
2130 If set to @code{MANDATORY}, the program will terminate with an error if
2131 the offload device is not present or is not supported. If set to
2132 @code{DISABLED}, then offloading is disabled and all code will run on the
2133 host. If set to @code{DEFAULT}, the program will try offloading to the
2134 device first, then fall back to running code on the host if it cannot.
2136 If undefined, then the program will behave as if @code{DEFAULT} was set.
2138 @item @emph{Reference}:
2139 @uref{https://www.openmp.org, OpenMP specification v5.0}, Section 6.17
2144 @node OMP_TEAMS_THREAD_LIMIT
2145 @section @env{OMP_TEAMS_THREAD_LIMIT} -- Set the maximum number of threads imposed by teams
2146 @cindex Environment Variable
2148 @item @emph{Description}:
2149 Specifies an upper bound for the number of threads to use by each contention
2150 group created by a teams construct without explicit @code{thread_limit}
2151 clause. The value of this variable shall be a positive integer. If undefined,
2152 the value of 0 is used which stands for an implementation defined upper
2155 @item @emph{See also}:
2156 @ref{OMP_THREAD_LIMIT}, @ref{omp_set_teams_thread_limit}
2158 @item @emph{Reference}:
2159 @uref{https://www.openmp.org, OpenMP specification v5.1}, Section 6.24
2164 @node OMP_THREAD_LIMIT
2165 @section @env{OMP_THREAD_LIMIT} -- Set the maximum number of threads
2166 @cindex Environment Variable
2168 @item @emph{Description}:
2169 Specifies the number of threads to use for the whole program. The
2170 value of this variable shall be a positive integer. If undefined,
2171 the number of threads is not limited.
2173 @item @emph{See also}:
2174 @ref{OMP_NUM_THREADS}, @ref{omp_get_thread_limit}
2176 @item @emph{Reference}:
2177 @uref{https://www.openmp.org, OpenMP specification v4.5}, Section 4.10
2182 @node OMP_WAIT_POLICY
2183 @section @env{OMP_WAIT_POLICY} -- How waiting threads are handled
2184 @cindex Environment Variable
2186 @item @emph{Description}:
2187 Specifies whether waiting threads should be active or passive. If
2188 the value is @code{PASSIVE}, waiting threads should not consume CPU
2189 power while waiting; while the value is @code{ACTIVE} specifies that
2190 they should. If undefined, threads wait actively for a short time
2191 before waiting passively.
2193 @item @emph{See also}:
2194 @ref{GOMP_SPINCOUNT}
2196 @item @emph{Reference}:
2197 @uref{https://www.openmp.org, OpenMP specification v4.5}, Section 4.8
2202 @node GOMP_CPU_AFFINITY
2203 @section @env{GOMP_CPU_AFFINITY} -- Bind threads to specific CPUs
2204 @cindex Environment Variable
2206 @item @emph{Description}:
2207 Binds threads to specific CPUs. The variable should contain a space-separated
2208 or comma-separated list of CPUs. This list may contain different kinds of
2209 entries: either single CPU numbers in any order, a range of CPUs (M-N)
2210 or a range with some stride (M-N:S). CPU numbers are zero based. For example,
2211 @code{GOMP_CPU_AFFINITY="0 3 1-2 4-15:2"} will bind the initial thread
2212 to CPU 0, the second to CPU 3, the third to CPU 1, the fourth to
2213 CPU 2, the fifth to CPU 4, the sixth through tenth to CPUs 6, 8, 10, 12,
2214 and 14 respectively and then start assigning back from the beginning of
2215 the list. @code{GOMP_CPU_AFFINITY=0} binds all threads to CPU 0.
2217 There is no libgomp library routine to determine whether a CPU affinity
2218 specification is in effect. As a workaround, language-specific library
2219 functions, e.g., @code{getenv} in C or @code{GET_ENVIRONMENT_VARIABLE} in
2220 Fortran, may be used to query the setting of the @code{GOMP_CPU_AFFINITY}
2221 environment variable. A defined CPU affinity on startup cannot be changed
2222 or disabled during the runtime of the application.
2224 If both @env{GOMP_CPU_AFFINITY} and @env{OMP_PROC_BIND} are set,
2225 @env{OMP_PROC_BIND} has a higher precedence. If neither has been set and
2226 @env{OMP_PROC_BIND} is unset, or when @env{OMP_PROC_BIND} is set to
2227 @code{FALSE}, the host system will handle the assignment of threads to CPUs.
2229 @item @emph{See also}:
2230 @ref{OMP_PLACES}, @ref{OMP_PROC_BIND}
2236 @section @env{GOMP_DEBUG} -- Enable debugging output
2237 @cindex Environment Variable
2239 @item @emph{Description}:
2240 Enable debugging output. The variable should be set to @code{0}
2241 (disabled, also the default if not set), or @code{1} (enabled).
2243 If enabled, some debugging output will be printed during execution.
2244 This is currently not specified in more detail, and subject to change.
2249 @node GOMP_STACKSIZE
2250 @section @env{GOMP_STACKSIZE} -- Set default thread stack size
2251 @cindex Environment Variable
2252 @cindex Implementation specific setting
2254 @item @emph{Description}:
2255 Set the default thread stack size in kilobytes. This is different from
2256 @code{pthread_attr_setstacksize} which gets the number of bytes as an
2257 argument. If the stack size cannot be set due to system constraints, an
2258 error is reported and the initial stack size is left unchanged. If undefined,
2259 the stack size is system dependent.
2261 @item @emph{See also}:
2264 @item @emph{Reference}:
2265 @uref{https://gcc.gnu.org/ml/gcc-patches/2006-06/msg00493.html,
2266 GCC Patches Mailinglist},
2267 @uref{https://gcc.gnu.org/ml/gcc-patches/2006-06/msg00496.html,
2268 GCC Patches Mailinglist}
2273 @node GOMP_SPINCOUNT
2274 @section @env{GOMP_SPINCOUNT} -- Set the busy-wait spin count
2275 @cindex Environment Variable
2276 @cindex Implementation specific setting
2278 @item @emph{Description}:
2279 Determines how long a threads waits actively with consuming CPU power
2280 before waiting passively without consuming CPU power. The value may be
2281 either @code{INFINITE}, @code{INFINITY} to always wait actively or an
2282 integer which gives the number of spins of the busy-wait loop. The
2283 integer may optionally be followed by the following suffixes acting
2284 as multiplication factors: @code{k} (kilo, thousand), @code{M} (mega,
2285 million), @code{G} (giga, billion), or @code{T} (tera, trillion).
2286 If undefined, 0 is used when @env{OMP_WAIT_POLICY} is @code{PASSIVE},
2287 300,000 is used when @env{OMP_WAIT_POLICY} is undefined and
2288 30 billion is used when @env{OMP_WAIT_POLICY} is @code{ACTIVE}.
2289 If there are more OpenMP threads than available CPUs, 1000 and 100
2290 spins are used for @env{OMP_WAIT_POLICY} being @code{ACTIVE} or
2291 undefined, respectively; unless the @env{GOMP_SPINCOUNT} is lower
2292 or @env{OMP_WAIT_POLICY} is @code{PASSIVE}.
2294 @item @emph{See also}:
2295 @ref{OMP_WAIT_POLICY}
2300 @node GOMP_RTEMS_THREAD_POOLS
2301 @section @env{GOMP_RTEMS_THREAD_POOLS} -- Set the RTEMS specific thread pools
2302 @cindex Environment Variable
2303 @cindex Implementation specific setting
2305 @item @emph{Description}:
2306 This environment variable is only used on the RTEMS real-time operating system.
2307 It determines the scheduler instance specific thread pools. The format for
2308 @env{GOMP_RTEMS_THREAD_POOLS} is a list of optional
2309 @code{<thread-pool-count>[$<priority>]@@<scheduler-name>} configurations
2310 separated by @code{:} where:
2312 @item @code{<thread-pool-count>} is the thread pool count for this scheduler
2314 @item @code{$<priority>} is an optional priority for the worker threads of a
2315 thread pool according to @code{pthread_setschedparam}. In case a priority
2316 value is omitted, then a worker thread will inherit the priority of the OpenMP
2317 primary thread that created it. The priority of the worker thread is not
2318 changed after creation, even if a new OpenMP primary thread using the worker has
2319 a different priority.
2320 @item @code{@@<scheduler-name>} is the scheduler instance name according to the
2321 RTEMS application configuration.
2323 In case no thread pool configuration is specified for a scheduler instance,
2324 then each OpenMP primary thread of this scheduler instance will use its own
2325 dynamically allocated thread pool. To limit the worker thread count of the
2326 thread pools, each OpenMP primary thread must call @code{omp_set_num_threads}.
2327 @item @emph{Example}:
2328 Lets suppose we have three scheduler instances @code{IO}, @code{WRK0}, and
2329 @code{WRK1} with @env{GOMP_RTEMS_THREAD_POOLS} set to
2330 @code{"1@@WRK0:3$4@@WRK1"}. Then there are no thread pool restrictions for
2331 scheduler instance @code{IO}. In the scheduler instance @code{WRK0} there is
2332 one thread pool available. Since no priority is specified for this scheduler
2333 instance, the worker thread inherits the priority of the OpenMP primary thread
2334 that created it. In the scheduler instance @code{WRK1} there are three thread
2335 pools available and their worker threads run at priority four.
2340 @c ---------------------------------------------------------------------
2342 @c ---------------------------------------------------------------------
2344 @node Enabling OpenACC
2345 @chapter Enabling OpenACC
2347 To activate the OpenACC extensions for C/C++ and Fortran, the compile-time
2348 flag @option{-fopenacc} must be specified. This enables the OpenACC directive
2349 @code{#pragma acc} in C/C++ and @code{!$acc} directives in free form,
2350 @code{c$acc}, @code{*$acc} and @code{!$acc} directives in fixed form,
2351 @code{!$} conditional compilation sentinels in free form and @code{c$},
2352 @code{*$} and @code{!$} sentinels in fixed form, for Fortran. The flag also
2353 arranges for automatic linking of the OpenACC runtime library
2354 (@ref{OpenACC Runtime Library Routines}).
2356 See @uref{https://gcc.gnu.org/wiki/OpenACC} for more information.
2358 A complete description of all OpenACC directives accepted may be found in
2359 the @uref{https://www.openacc.org, OpenACC} Application Programming
2360 Interface manual, version 2.6.
2364 @c ---------------------------------------------------------------------
2365 @c OpenACC Runtime Library Routines
2366 @c ---------------------------------------------------------------------
2368 @node OpenACC Runtime Library Routines
2369 @chapter OpenACC Runtime Library Routines
2371 The runtime routines described here are defined by section 3 of the OpenACC
2372 specifications in version 2.6.
2373 They have C linkage, and do not throw exceptions.
2374 Generally, they are available only for the host, with the exception of
2375 @code{acc_on_device}, which is available for both the host and the
2376 acceleration device.
2379 * acc_get_num_devices:: Get number of devices for the given device
2381 * acc_set_device_type:: Set type of device accelerator to use.
2382 * acc_get_device_type:: Get type of device accelerator to be used.
2383 * acc_set_device_num:: Set device number to use.
2384 * acc_get_device_num:: Get device number to be used.
2385 * acc_get_property:: Get device property.
2386 * acc_async_test:: Tests for completion of a specific asynchronous
2388 * acc_async_test_all:: Tests for completion of all asynchronous
2390 * acc_wait:: Wait for completion of a specific asynchronous
2392 * acc_wait_all:: Waits for completion of all asynchronous
2394 * acc_wait_all_async:: Wait for completion of all asynchronous
2396 * acc_wait_async:: Wait for completion of asynchronous operations.
2397 * acc_init:: Initialize runtime for a specific device type.
2398 * acc_shutdown:: Shuts down the runtime for a specific device
2400 * acc_on_device:: Whether executing on a particular device
2401 * acc_malloc:: Allocate device memory.
2402 * acc_free:: Free device memory.
2403 * acc_copyin:: Allocate device memory and copy host memory to
2405 * acc_present_or_copyin:: If the data is not present on the device,
2406 allocate device memory and copy from host
2408 * acc_create:: Allocate device memory and map it to host
2410 * acc_present_or_create:: If the data is not present on the device,
2411 allocate device memory and map it to host
2413 * acc_copyout:: Copy device memory to host memory.
2414 * acc_delete:: Free device memory.
2415 * acc_update_device:: Update device memory from mapped host memory.
2416 * acc_update_self:: Update host memory from mapped device memory.
2417 * acc_map_data:: Map previously allocated device memory to host
2419 * acc_unmap_data:: Unmap device memory from host memory.
2420 * acc_deviceptr:: Get device pointer associated with specific
2422 * acc_hostptr:: Get host pointer associated with specific
2424 * acc_is_present:: Indicate whether host variable / array is
2426 * acc_memcpy_to_device:: Copy host memory to device memory.
2427 * acc_memcpy_from_device:: Copy device memory to host memory.
2428 * acc_attach:: Let device pointer point to device-pointer target.
2429 * acc_detach:: Let device pointer point to host-pointer target.
2431 API routines for target platforms.
2433 * acc_get_current_cuda_device:: Get CUDA device handle.
2434 * acc_get_current_cuda_context::Get CUDA context handle.
2435 * acc_get_cuda_stream:: Get CUDA stream handle.
2436 * acc_set_cuda_stream:: Set CUDA stream handle.
2438 API routines for the OpenACC Profiling Interface.
2440 * acc_prof_register:: Register callbacks.
2441 * acc_prof_unregister:: Unregister callbacks.
2442 * acc_prof_lookup:: Obtain inquiry functions.
2443 * acc_register_library:: Library registration.
2448 @node acc_get_num_devices
2449 @section @code{acc_get_num_devices} -- Get number of devices for given device type
2451 @item @emph{Description}
2452 This function returns a value indicating the number of devices available
2453 for the device type specified in @var{devicetype}.
2456 @multitable @columnfractions .20 .80
2457 @item @emph{Prototype}: @tab @code{int acc_get_num_devices(acc_device_t devicetype);}
2460 @item @emph{Fortran}:
2461 @multitable @columnfractions .20 .80
2462 @item @emph{Interface}: @tab @code{integer function acc_get_num_devices(devicetype)}
2463 @item @tab @code{integer(kind=acc_device_kind) devicetype}
2466 @item @emph{Reference}:
2467 @uref{https://www.openacc.org, OpenACC specification v2.6}, section
2473 @node acc_set_device_type
2474 @section @code{acc_set_device_type} -- Set type of device accelerator to use.
2476 @item @emph{Description}
2477 This function indicates to the runtime library which device type, specified
2478 in @var{devicetype}, to use when executing a parallel or kernels region.
2481 @multitable @columnfractions .20 .80
2482 @item @emph{Prototype}: @tab @code{acc_set_device_type(acc_device_t devicetype);}
2485 @item @emph{Fortran}:
2486 @multitable @columnfractions .20 .80
2487 @item @emph{Interface}: @tab @code{subroutine acc_set_device_type(devicetype)}
2488 @item @tab @code{integer(kind=acc_device_kind) devicetype}
2491 @item @emph{Reference}:
2492 @uref{https://www.openacc.org, OpenACC specification v2.6}, section
2498 @node acc_get_device_type
2499 @section @code{acc_get_device_type} -- Get type of device accelerator to be used.
2501 @item @emph{Description}
2502 This function returns what device type will be used when executing a
2503 parallel or kernels region.
2505 This function returns @code{acc_device_none} if
2506 @code{acc_get_device_type} is called from
2507 @code{acc_ev_device_init_start}, @code{acc_ev_device_init_end}
2508 callbacks of the OpenACC Profiling Interface (@ref{OpenACC Profiling
2509 Interface}), that is, if the device is currently being initialized.
2512 @multitable @columnfractions .20 .80
2513 @item @emph{Prototype}: @tab @code{acc_device_t acc_get_device_type(void);}
2516 @item @emph{Fortran}:
2517 @multitable @columnfractions .20 .80
2518 @item @emph{Interface}: @tab @code{function acc_get_device_type(void)}
2519 @item @tab @code{integer(kind=acc_device_kind) acc_get_device_type}
2522 @item @emph{Reference}:
2523 @uref{https://www.openacc.org, OpenACC specification v2.6}, section
2529 @node acc_set_device_num
2530 @section @code{acc_set_device_num} -- Set device number to use.
2532 @item @emph{Description}
2533 This function will indicate to the runtime which device number,
2534 specified by @var{devicenum}, associated with the specified device
2535 type @var{devicetype}.
2538 @multitable @columnfractions .20 .80
2539 @item @emph{Prototype}: @tab @code{acc_set_device_num(int devicenum, acc_device_t devicetype);}
2542 @item @emph{Fortran}:
2543 @multitable @columnfractions .20 .80
2544 @item @emph{Interface}: @tab @code{subroutine acc_set_device_num(devicenum, devicetype)}
2545 @item @tab @code{integer devicenum}
2546 @item @tab @code{integer(kind=acc_device_kind) devicetype}
2549 @item @emph{Reference}:
2550 @uref{https://www.openacc.org, OpenACC specification v2.6}, section
2556 @node acc_get_device_num
2557 @section @code{acc_get_device_num} -- Get device number to be used.
2559 @item @emph{Description}
2560 This function returns which device number associated with the specified device
2561 type @var{devicetype}, will be used when executing a parallel or kernels
2565 @multitable @columnfractions .20 .80
2566 @item @emph{Prototype}: @tab @code{int acc_get_device_num(acc_device_t devicetype);}
2569 @item @emph{Fortran}:
2570 @multitable @columnfractions .20 .80
2571 @item @emph{Interface}: @tab @code{function acc_get_device_num(devicetype)}
2572 @item @tab @code{integer(kind=acc_device_kind) devicetype}
2573 @item @tab @code{integer acc_get_device_num}
2576 @item @emph{Reference}:
2577 @uref{https://www.openacc.org, OpenACC specification v2.6}, section
2583 @node acc_get_property
2584 @section @code{acc_get_property} -- Get device property.
2585 @cindex acc_get_property
2586 @cindex acc_get_property_string
2588 @item @emph{Description}
2589 These routines return the value of the specified @var{property} for the
2590 device being queried according to @var{devicenum} and @var{devicetype}.
2591 Integer-valued and string-valued properties are returned by
2592 @code{acc_get_property} and @code{acc_get_property_string} respectively.
2593 The Fortran @code{acc_get_property_string} subroutine returns the string
2594 retrieved in its fourth argument while the remaining entry points are
2595 functions, which pass the return value as their result.
2597 Note for Fortran, only: the OpenACC technical committee corrected and, hence,
2598 modified the interface introduced in OpenACC 2.6. The kind-value parameter
2599 @code{acc_device_property} has been renamed to @code{acc_device_property_kind}
2600 for consistency and the return type of the @code{acc_get_property} function is
2601 now a @code{c_size_t} integer instead of a @code{acc_device_property} integer.
2602 The parameter @code{acc_device_property} will continue to be provided,
2603 but might be removed in a future version of GCC.
2606 @multitable @columnfractions .20 .80
2607 @item @emph{Prototype}: @tab @code{size_t acc_get_property(int devicenum, acc_device_t devicetype, acc_device_property_t property);}
2608 @item @emph{Prototype}: @tab @code{const char *acc_get_property_string(int devicenum, acc_device_t devicetype, acc_device_property_t property);}
2611 @item @emph{Fortran}:
2612 @multitable @columnfractions .20 .80
2613 @item @emph{Interface}: @tab @code{function acc_get_property(devicenum, devicetype, property)}
2614 @item @emph{Interface}: @tab @code{subroutine acc_get_property_string(devicenum, devicetype, property, string)}
2615 @item @tab @code{use ISO_C_Binding, only: c_size_t}
2616 @item @tab @code{integer devicenum}
2617 @item @tab @code{integer(kind=acc_device_kind) devicetype}
2618 @item @tab @code{integer(kind=acc_device_property_kind) property}
2619 @item @tab @code{integer(kind=c_size_t) acc_get_property}
2620 @item @tab @code{character(*) string}
2623 @item @emph{Reference}:
2624 @uref{https://www.openacc.org, OpenACC specification v2.6}, section
2630 @node acc_async_test
2631 @section @code{acc_async_test} -- Test for completion of a specific asynchronous operation.
2633 @item @emph{Description}
2634 This function tests for completion of the asynchronous operation specified
2635 in @var{arg}. In C/C++, a non-zero value will be returned to indicate
2636 the specified asynchronous operation has completed. While Fortran will return
2637 a @code{true}. If the asynchronous operation has not completed, C/C++ returns
2638 a zero and Fortran returns a @code{false}.
2641 @multitable @columnfractions .20 .80
2642 @item @emph{Prototype}: @tab @code{int acc_async_test(int arg);}
2645 @item @emph{Fortran}:
2646 @multitable @columnfractions .20 .80
2647 @item @emph{Interface}: @tab @code{function acc_async_test(arg)}
2648 @item @tab @code{integer(kind=acc_handle_kind) arg}
2649 @item @tab @code{logical acc_async_test}
2652 @item @emph{Reference}:
2653 @uref{https://www.openacc.org, OpenACC specification v2.6}, section
2659 @node acc_async_test_all
2660 @section @code{acc_async_test_all} -- Tests for completion of all asynchronous operations.
2662 @item @emph{Description}
2663 This function tests for completion of all asynchronous operations.
2664 In C/C++, a non-zero value will be returned to indicate all asynchronous
2665 operations have completed. While Fortran will return a @code{true}. If
2666 any asynchronous operation has not completed, C/C++ returns a zero and
2667 Fortran returns a @code{false}.
2670 @multitable @columnfractions .20 .80
2671 @item @emph{Prototype}: @tab @code{int acc_async_test_all(void);}
2674 @item @emph{Fortran}:
2675 @multitable @columnfractions .20 .80
2676 @item @emph{Interface}: @tab @code{function acc_async_test()}
2677 @item @tab @code{logical acc_get_device_num}
2680 @item @emph{Reference}:
2681 @uref{https://www.openacc.org, OpenACC specification v2.6}, section
2688 @section @code{acc_wait} -- Wait for completion of a specific asynchronous operation.
2690 @item @emph{Description}
2691 This function waits for completion of the asynchronous operation
2692 specified in @var{arg}.
2695 @multitable @columnfractions .20 .80
2696 @item @emph{Prototype}: @tab @code{acc_wait(arg);}
2697 @item @emph{Prototype (OpenACC 1.0 compatibility)}: @tab @code{acc_async_wait(arg);}
2700 @item @emph{Fortran}:
2701 @multitable @columnfractions .20 .80
2702 @item @emph{Interface}: @tab @code{subroutine acc_wait(arg)}
2703 @item @tab @code{integer(acc_handle_kind) arg}
2704 @item @emph{Interface (OpenACC 1.0 compatibility)}: @tab @code{subroutine acc_async_wait(arg)}
2705 @item @tab @code{integer(acc_handle_kind) arg}
2708 @item @emph{Reference}:
2709 @uref{https://www.openacc.org, OpenACC specification v2.6}, section
2716 @section @code{acc_wait_all} -- Waits for completion of all asynchronous operations.
2718 @item @emph{Description}
2719 This function waits for the completion of all asynchronous operations.
2722 @multitable @columnfractions .20 .80
2723 @item @emph{Prototype}: @tab @code{acc_wait_all(void);}
2724 @item @emph{Prototype (OpenACC 1.0 compatibility)}: @tab @code{acc_async_wait_all(void);}
2727 @item @emph{Fortran}:
2728 @multitable @columnfractions .20 .80
2729 @item @emph{Interface}: @tab @code{subroutine acc_wait_all()}
2730 @item @emph{Interface (OpenACC 1.0 compatibility)}: @tab @code{subroutine acc_async_wait_all()}
2733 @item @emph{Reference}:
2734 @uref{https://www.openacc.org, OpenACC specification v2.6}, section
2740 @node acc_wait_all_async
2741 @section @code{acc_wait_all_async} -- Wait for completion of all asynchronous operations.
2743 @item @emph{Description}
2744 This function enqueues a wait operation on the queue @var{async} for any
2745 and all asynchronous operations that have been previously enqueued on
2749 @multitable @columnfractions .20 .80
2750 @item @emph{Prototype}: @tab @code{acc_wait_all_async(int async);}
2753 @item @emph{Fortran}:
2754 @multitable @columnfractions .20 .80
2755 @item @emph{Interface}: @tab @code{subroutine acc_wait_all_async(async)}
2756 @item @tab @code{integer(acc_handle_kind) async}
2759 @item @emph{Reference}:
2760 @uref{https://www.openacc.org, OpenACC specification v2.6}, section
2766 @node acc_wait_async
2767 @section @code{acc_wait_async} -- Wait for completion of asynchronous operations.
2769 @item @emph{Description}
2770 This function enqueues a wait operation on queue @var{async} for any and all
2771 asynchronous operations enqueued on queue @var{arg}.
2774 @multitable @columnfractions .20 .80
2775 @item @emph{Prototype}: @tab @code{acc_wait_async(int arg, int async);}
2778 @item @emph{Fortran}:
2779 @multitable @columnfractions .20 .80
2780 @item @emph{Interface}: @tab @code{subroutine acc_wait_async(arg, async)}
2781 @item @tab @code{integer(acc_handle_kind) arg, async}
2784 @item @emph{Reference}:
2785 @uref{https://www.openacc.org, OpenACC specification v2.6}, section
2792 @section @code{acc_init} -- Initialize runtime for a specific device type.
2794 @item @emph{Description}
2795 This function initializes the runtime for the device type specified in
2799 @multitable @columnfractions .20 .80
2800 @item @emph{Prototype}: @tab @code{acc_init(acc_device_t devicetype);}
2803 @item @emph{Fortran}:
2804 @multitable @columnfractions .20 .80
2805 @item @emph{Interface}: @tab @code{subroutine acc_init(devicetype)}
2806 @item @tab @code{integer(acc_device_kind) devicetype}
2809 @item @emph{Reference}:
2810 @uref{https://www.openacc.org, OpenACC specification v2.6}, section
2817 @section @code{acc_shutdown} -- Shuts down the runtime for a specific device type.
2819 @item @emph{Description}
2820 This function shuts down the runtime for the device type specified in
2824 @multitable @columnfractions .20 .80
2825 @item @emph{Prototype}: @tab @code{acc_shutdown(acc_device_t devicetype);}
2828 @item @emph{Fortran}:
2829 @multitable @columnfractions .20 .80
2830 @item @emph{Interface}: @tab @code{subroutine acc_shutdown(devicetype)}
2831 @item @tab @code{integer(acc_device_kind) devicetype}
2834 @item @emph{Reference}:
2835 @uref{https://www.openacc.org, OpenACC specification v2.6}, section
2842 @section @code{acc_on_device} -- Whether executing on a particular device
2844 @item @emph{Description}:
2845 This function returns whether the program is executing on a particular
2846 device specified in @var{devicetype}. In C/C++ a non-zero value is
2847 returned to indicate the device is executing on the specified device type.
2848 In Fortran, @code{true} will be returned. If the program is not executing
2849 on the specified device type C/C++ will return a zero, while Fortran will
2850 return @code{false}.
2853 @multitable @columnfractions .20 .80
2854 @item @emph{Prototype}: @tab @code{acc_on_device(acc_device_t devicetype);}
2857 @item @emph{Fortran}:
2858 @multitable @columnfractions .20 .80
2859 @item @emph{Interface}: @tab @code{function acc_on_device(devicetype)}
2860 @item @tab @code{integer(acc_device_kind) devicetype}
2861 @item @tab @code{logical acc_on_device}
2865 @item @emph{Reference}:
2866 @uref{https://www.openacc.org, OpenACC specification v2.6}, section
2873 @section @code{acc_malloc} -- Allocate device memory.
2875 @item @emph{Description}
2876 This function allocates @var{len} bytes of device memory. It returns
2877 the device address of the allocated memory.
2880 @multitable @columnfractions .20 .80
2881 @item @emph{Prototype}: @tab @code{d_void* acc_malloc(size_t len);}
2884 @item @emph{Reference}:
2885 @uref{https://www.openacc.org, OpenACC specification v2.6}, section
2892 @section @code{acc_free} -- Free device memory.
2894 @item @emph{Description}
2895 Free previously allocated device memory at the device address @code{a}.
2898 @multitable @columnfractions .20 .80
2899 @item @emph{Prototype}: @tab @code{acc_free(d_void *a);}
2902 @item @emph{Reference}:
2903 @uref{https://www.openacc.org, OpenACC specification v2.6}, section
2910 @section @code{acc_copyin} -- Allocate device memory and copy host memory to it.
2912 @item @emph{Description}
2913 In C/C++, this function allocates @var{len} bytes of device memory
2914 and maps it to the specified host address in @var{a}. The device
2915 address of the newly allocated device memory is returned.
2917 In Fortran, two (2) forms are supported. In the first form, @var{a} specifies
2918 a contiguous array section. The second form @var{a} specifies a
2919 variable or array element and @var{len} specifies the length in bytes.
2922 @multitable @columnfractions .20 .80
2923 @item @emph{Prototype}: @tab @code{void *acc_copyin(h_void *a, size_t len);}
2924 @item @emph{Prototype}: @tab @code{void *acc_copyin_async(h_void *a, size_t len, int async);}
2927 @item @emph{Fortran}:
2928 @multitable @columnfractions .20 .80
2929 @item @emph{Interface}: @tab @code{subroutine acc_copyin(a)}
2930 @item @tab @code{type, dimension(:[,:]...) :: a}
2931 @item @emph{Interface}: @tab @code{subroutine acc_copyin(a, len)}
2932 @item @tab @code{type, dimension(:[,:]...) :: a}
2933 @item @tab @code{integer len}
2934 @item @emph{Interface}: @tab @code{subroutine acc_copyin_async(a, async)}
2935 @item @tab @code{type, dimension(:[,:]...) :: a}
2936 @item @tab @code{integer(acc_handle_kind) :: async}
2937 @item @emph{Interface}: @tab @code{subroutine acc_copyin_async(a, len, async)}
2938 @item @tab @code{type, dimension(:[,:]...) :: a}
2939 @item @tab @code{integer len}
2940 @item @tab @code{integer(acc_handle_kind) :: async}
2943 @item @emph{Reference}:
2944 @uref{https://www.openacc.org, OpenACC specification v2.6}, section
2950 @node acc_present_or_copyin
2951 @section @code{acc_present_or_copyin} -- If the data is not present on the device, allocate device memory and copy from host memory.
2953 @item @emph{Description}
2954 This function tests if the host data specified by @var{a} and of length
2955 @var{len} is present or not. If it is not present, then device memory
2956 will be allocated and the host memory copied. The device address of
2957 the newly allocated device memory is returned.
2959 In Fortran, two (2) forms are supported. In the first form, @var{a} specifies
2960 a contiguous array section. The second form @var{a} specifies a variable or
2961 array element and @var{len} specifies the length in bytes.
2963 Note that @code{acc_present_or_copyin} and @code{acc_pcopyin} exist for
2964 backward compatibility with OpenACC 2.0; use @ref{acc_copyin} instead.
2967 @multitable @columnfractions .20 .80
2968 @item @emph{Prototype}: @tab @code{void *acc_present_or_copyin(h_void *a, size_t len);}
2969 @item @emph{Prototype}: @tab @code{void *acc_pcopyin(h_void *a, size_t len);}
2972 @item @emph{Fortran}:
2973 @multitable @columnfractions .20 .80
2974 @item @emph{Interface}: @tab @code{subroutine acc_present_or_copyin(a)}
2975 @item @tab @code{type, dimension(:[,:]...) :: a}
2976 @item @emph{Interface}: @tab @code{subroutine acc_present_or_copyin(a, len)}
2977 @item @tab @code{type, dimension(:[,:]...) :: a}
2978 @item @tab @code{integer len}
2979 @item @emph{Interface}: @tab @code{subroutine acc_pcopyin(a)}
2980 @item @tab @code{type, dimension(:[,:]...) :: a}
2981 @item @emph{Interface}: @tab @code{subroutine acc_pcopyin(a, len)}
2982 @item @tab @code{type, dimension(:[,:]...) :: a}
2983 @item @tab @code{integer len}
2986 @item @emph{Reference}:
2987 @uref{https://www.openacc.org, OpenACC specification v2.6}, section
2994 @section @code{acc_create} -- Allocate device memory and map it to host memory.
2996 @item @emph{Description}
2997 This function allocates device memory and maps it to host memory specified
2998 by the host address @var{a} with a length of @var{len} bytes. In C/C++,
2999 the function returns the device address of the allocated device memory.
3001 In Fortran, two (2) forms are supported. In the first form, @var{a} specifies
3002 a contiguous array section. The second form @var{a} specifies a variable or
3003 array element and @var{len} specifies the length in bytes.
3006 @multitable @columnfractions .20 .80
3007 @item @emph{Prototype}: @tab @code{void *acc_create(h_void *a, size_t len);}
3008 @item @emph{Prototype}: @tab @code{void *acc_create_async(h_void *a, size_t len, int async);}
3011 @item @emph{Fortran}:
3012 @multitable @columnfractions .20 .80
3013 @item @emph{Interface}: @tab @code{subroutine acc_create(a)}
3014 @item @tab @code{type, dimension(:[,:]...) :: a}
3015 @item @emph{Interface}: @tab @code{subroutine acc_create(a, len)}
3016 @item @tab @code{type, dimension(:[,:]...) :: a}
3017 @item @tab @code{integer len}
3018 @item @emph{Interface}: @tab @code{subroutine acc_create_async(a, async)}
3019 @item @tab @code{type, dimension(:[,:]...) :: a}
3020 @item @tab @code{integer(acc_handle_kind) :: async}
3021 @item @emph{Interface}: @tab @code{subroutine acc_create_async(a, len, async)}
3022 @item @tab @code{type, dimension(:[,:]...) :: a}
3023 @item @tab @code{integer len}
3024 @item @tab @code{integer(acc_handle_kind) :: async}
3027 @item @emph{Reference}:
3028 @uref{https://www.openacc.org, OpenACC specification v2.6}, section
3034 @node acc_present_or_create
3035 @section @code{acc_present_or_create} -- If the data is not present on the device, allocate device memory and map it to host memory.
3037 @item @emph{Description}
3038 This function tests if the host data specified by @var{a} and of length
3039 @var{len} is present or not. If it is not present, then device memory
3040 will be allocated and mapped to host memory. In C/C++, the device address
3041 of the newly allocated device memory is returned.
3043 In Fortran, two (2) forms are supported. In the first form, @var{a} specifies
3044 a contiguous array section. The second form @var{a} specifies a variable or
3045 array element and @var{len} specifies the length in bytes.
3047 Note that @code{acc_present_or_create} and @code{acc_pcreate} exist for
3048 backward compatibility with OpenACC 2.0; use @ref{acc_create} instead.
3051 @multitable @columnfractions .20 .80
3052 @item @emph{Prototype}: @tab @code{void *acc_present_or_create(h_void *a, size_t len)}
3053 @item @emph{Prototype}: @tab @code{void *acc_pcreate(h_void *a, size_t len)}
3056 @item @emph{Fortran}:
3057 @multitable @columnfractions .20 .80
3058 @item @emph{Interface}: @tab @code{subroutine acc_present_or_create(a)}
3059 @item @tab @code{type, dimension(:[,:]...) :: a}
3060 @item @emph{Interface}: @tab @code{subroutine acc_present_or_create(a, len)}
3061 @item @tab @code{type, dimension(:[,:]...) :: a}
3062 @item @tab @code{integer len}
3063 @item @emph{Interface}: @tab @code{subroutine acc_pcreate(a)}
3064 @item @tab @code{type, dimension(:[,:]...) :: a}
3065 @item @emph{Interface}: @tab @code{subroutine acc_pcreate(a, len)}
3066 @item @tab @code{type, dimension(:[,:]...) :: a}
3067 @item @tab @code{integer len}
3070 @item @emph{Reference}:
3071 @uref{https://www.openacc.org, OpenACC specification v2.6}, section
3078 @section @code{acc_copyout} -- Copy device memory to host memory.
3080 @item @emph{Description}
3081 This function copies mapped device memory to host memory which is specified
3082 by host address @var{a} for a length @var{len} bytes in C/C++.
3084 In Fortran, two (2) forms are supported. In the first form, @var{a} specifies
3085 a contiguous array section. The second form @var{a} specifies a variable or
3086 array element and @var{len} specifies the length in bytes.
3089 @multitable @columnfractions .20 .80
3090 @item @emph{Prototype}: @tab @code{acc_copyout(h_void *a, size_t len);}
3091 @item @emph{Prototype}: @tab @code{acc_copyout_async(h_void *a, size_t len, int async);}
3092 @item @emph{Prototype}: @tab @code{acc_copyout_finalize(h_void *a, size_t len);}
3093 @item @emph{Prototype}: @tab @code{acc_copyout_finalize_async(h_void *a, size_t len, int async);}
3096 @item @emph{Fortran}:
3097 @multitable @columnfractions .20 .80
3098 @item @emph{Interface}: @tab @code{subroutine acc_copyout(a)}
3099 @item @tab @code{type, dimension(:[,:]...) :: a}
3100 @item @emph{Interface}: @tab @code{subroutine acc_copyout(a, len)}
3101 @item @tab @code{type, dimension(:[,:]...) :: a}
3102 @item @tab @code{integer len}
3103 @item @emph{Interface}: @tab @code{subroutine acc_copyout_async(a, async)}
3104 @item @tab @code{type, dimension(:[,:]...) :: a}
3105 @item @tab @code{integer(acc_handle_kind) :: async}
3106 @item @emph{Interface}: @tab @code{subroutine acc_copyout_async(a, len, async)}
3107 @item @tab @code{type, dimension(:[,:]...) :: a}
3108 @item @tab @code{integer len}
3109 @item @tab @code{integer(acc_handle_kind) :: async}
3110 @item @emph{Interface}: @tab @code{subroutine acc_copyout_finalize(a)}
3111 @item @tab @code{type, dimension(:[,:]...) :: a}
3112 @item @emph{Interface}: @tab @code{subroutine acc_copyout_finalize(a, len)}
3113 @item @tab @code{type, dimension(:[,:]...) :: a}
3114 @item @tab @code{integer len}
3115 @item @emph{Interface}: @tab @code{subroutine acc_copyout_finalize_async(a, async)}
3116 @item @tab @code{type, dimension(:[,:]...) :: a}
3117 @item @tab @code{integer(acc_handle_kind) :: async}
3118 @item @emph{Interface}: @tab @code{subroutine acc_copyout_finalize_async(a, len, async)}
3119 @item @tab @code{type, dimension(:[,:]...) :: a}
3120 @item @tab @code{integer len}
3121 @item @tab @code{integer(acc_handle_kind) :: async}
3124 @item @emph{Reference}:
3125 @uref{https://www.openacc.org, OpenACC specification v2.6}, section
3132 @section @code{acc_delete} -- Free device memory.
3134 @item @emph{Description}
3135 This function frees previously allocated device memory specified by
3136 the device address @var{a} and the length of @var{len} bytes.
3138 In Fortran, two (2) forms are supported. In the first form, @var{a} specifies
3139 a contiguous array section. The second form @var{a} specifies a variable or
3140 array element and @var{len} specifies the length in bytes.
3143 @multitable @columnfractions .20 .80
3144 @item @emph{Prototype}: @tab @code{acc_delete(h_void *a, size_t len);}
3145 @item @emph{Prototype}: @tab @code{acc_delete_async(h_void *a, size_t len, int async);}
3146 @item @emph{Prototype}: @tab @code{acc_delete_finalize(h_void *a, size_t len);}
3147 @item @emph{Prototype}: @tab @code{acc_delete_finalize_async(h_void *a, size_t len, int async);}
3150 @item @emph{Fortran}:
3151 @multitable @columnfractions .20 .80
3152 @item @emph{Interface}: @tab @code{subroutine acc_delete(a)}
3153 @item @tab @code{type, dimension(:[,:]...) :: a}
3154 @item @emph{Interface}: @tab @code{subroutine acc_delete(a, len)}
3155 @item @tab @code{type, dimension(:[,:]...) :: a}
3156 @item @tab @code{integer len}
3157 @item @emph{Interface}: @tab @code{subroutine acc_delete_async(a, async)}
3158 @item @tab @code{type, dimension(:[,:]...) :: a}
3159 @item @tab @code{integer(acc_handle_kind) :: async}
3160 @item @emph{Interface}: @tab @code{subroutine acc_delete_async(a, len, async)}
3161 @item @tab @code{type, dimension(:[,:]...) :: a}
3162 @item @tab @code{integer len}
3163 @item @tab @code{integer(acc_handle_kind) :: async}
3164 @item @emph{Interface}: @tab @code{subroutine acc_delete_finalize(a)}
3165 @item @tab @code{type, dimension(:[,:]...) :: a}
3166 @item @emph{Interface}: @tab @code{subroutine acc_delete_finalize(a, len)}
3167 @item @tab @code{type, dimension(:[,:]...) :: a}
3168 @item @tab @code{integer len}
3169 @item @emph{Interface}: @tab @code{subroutine acc_delete_async_finalize(a, async)}
3170 @item @tab @code{type, dimension(:[,:]...) :: a}
3171 @item @tab @code{integer(acc_handle_kind) :: async}
3172 @item @emph{Interface}: @tab @code{subroutine acc_delete_async_finalize(a, len, async)}
3173 @item @tab @code{type, dimension(:[,:]...) :: a}
3174 @item @tab @code{integer len}
3175 @item @tab @code{integer(acc_handle_kind) :: async}
3178 @item @emph{Reference}:
3179 @uref{https://www.openacc.org, OpenACC specification v2.6}, section
3185 @node acc_update_device
3186 @section @code{acc_update_device} -- Update device memory from mapped host memory.
3188 @item @emph{Description}
3189 This function updates the device copy from the previously mapped host memory.
3190 The host memory is specified with the host address @var{a} and a length of
3193 In Fortran, two (2) forms are supported. In the first form, @var{a} specifies
3194 a contiguous array section. The second form @var{a} specifies a variable or
3195 array element and @var{len} specifies the length in bytes.
3198 @multitable @columnfractions .20 .80
3199 @item @emph{Prototype}: @tab @code{acc_update_device(h_void *a, size_t len);}
3200 @item @emph{Prototype}: @tab @code{acc_update_device(h_void *a, size_t len, async);}
3203 @item @emph{Fortran}:
3204 @multitable @columnfractions .20 .80
3205 @item @emph{Interface}: @tab @code{subroutine acc_update_device(a)}
3206 @item @tab @code{type, dimension(:[,:]...) :: a}
3207 @item @emph{Interface}: @tab @code{subroutine acc_update_device(a, len)}
3208 @item @tab @code{type, dimension(:[,:]...) :: a}
3209 @item @tab @code{integer len}
3210 @item @emph{Interface}: @tab @code{subroutine acc_update_device_async(a, async)}
3211 @item @tab @code{type, dimension(:[,:]...) :: a}
3212 @item @tab @code{integer(acc_handle_kind) :: async}
3213 @item @emph{Interface}: @tab @code{subroutine acc_update_device_async(a, len, async)}
3214 @item @tab @code{type, dimension(:[,:]...) :: a}
3215 @item @tab @code{integer len}
3216 @item @tab @code{integer(acc_handle_kind) :: async}
3219 @item @emph{Reference}:
3220 @uref{https://www.openacc.org, OpenACC specification v2.6}, section
3226 @node acc_update_self
3227 @section @code{acc_update_self} -- Update host memory from mapped device memory.
3229 @item @emph{Description}
3230 This function updates the host copy from the previously mapped device memory.
3231 The host memory is specified with the host address @var{a} and a length of
3234 In Fortran, two (2) forms are supported. In the first form, @var{a} specifies
3235 a contiguous array section. The second form @var{a} specifies a variable or
3236 array element and @var{len} specifies the length in bytes.
3239 @multitable @columnfractions .20 .80
3240 @item @emph{Prototype}: @tab @code{acc_update_self(h_void *a, size_t len);}
3241 @item @emph{Prototype}: @tab @code{acc_update_self_async(h_void *a, size_t len, int async);}
3244 @item @emph{Fortran}:
3245 @multitable @columnfractions .20 .80
3246 @item @emph{Interface}: @tab @code{subroutine acc_update_self(a)}
3247 @item @tab @code{type, dimension(:[,:]...) :: a}
3248 @item @emph{Interface}: @tab @code{subroutine acc_update_self(a, len)}
3249 @item @tab @code{type, dimension(:[,:]...) :: a}
3250 @item @tab @code{integer len}
3251 @item @emph{Interface}: @tab @code{subroutine acc_update_self_async(a, async)}
3252 @item @tab @code{type, dimension(:[,:]...) :: a}
3253 @item @tab @code{integer(acc_handle_kind) :: async}
3254 @item @emph{Interface}: @tab @code{subroutine acc_update_self_async(a, len, async)}
3255 @item @tab @code{type, dimension(:[,:]...) :: a}
3256 @item @tab @code{integer len}
3257 @item @tab @code{integer(acc_handle_kind) :: async}
3260 @item @emph{Reference}:
3261 @uref{https://www.openacc.org, OpenACC specification v2.6}, section
3268 @section @code{acc_map_data} -- Map previously allocated device memory to host memory.
3270 @item @emph{Description}
3271 This function maps previously allocated device and host memory. The device
3272 memory is specified with the device address @var{d}. The host memory is
3273 specified with the host address @var{h} and a length of @var{len}.
3276 @multitable @columnfractions .20 .80
3277 @item @emph{Prototype}: @tab @code{acc_map_data(h_void *h, d_void *d, size_t len);}
3280 @item @emph{Reference}:
3281 @uref{https://www.openacc.org, OpenACC specification v2.6}, section
3287 @node acc_unmap_data
3288 @section @code{acc_unmap_data} -- Unmap device memory from host memory.
3290 @item @emph{Description}
3291 This function unmaps previously mapped device and host memory. The latter
3292 specified by @var{h}.
3295 @multitable @columnfractions .20 .80
3296 @item @emph{Prototype}: @tab @code{acc_unmap_data(h_void *h);}
3299 @item @emph{Reference}:
3300 @uref{https://www.openacc.org, OpenACC specification v2.6}, section
3307 @section @code{acc_deviceptr} -- Get device pointer associated with specific host address.
3309 @item @emph{Description}
3310 This function returns the device address that has been mapped to the
3311 host address specified by @var{h}.
3314 @multitable @columnfractions .20 .80
3315 @item @emph{Prototype}: @tab @code{void *acc_deviceptr(h_void *h);}
3318 @item @emph{Reference}:
3319 @uref{https://www.openacc.org, OpenACC specification v2.6}, section
3326 @section @code{acc_hostptr} -- Get host pointer associated with specific device address.
3328 @item @emph{Description}
3329 This function returns the host address that has been mapped to the
3330 device address specified by @var{d}.
3333 @multitable @columnfractions .20 .80
3334 @item @emph{Prototype}: @tab @code{void *acc_hostptr(d_void *d);}
3337 @item @emph{Reference}:
3338 @uref{https://www.openacc.org, OpenACC specification v2.6}, section
3344 @node acc_is_present
3345 @section @code{acc_is_present} -- Indicate whether host variable / array is present on device.
3347 @item @emph{Description}
3348 This function indicates whether the specified host address in @var{a} and a
3349 length of @var{len} bytes is present on the device. In C/C++, a non-zero
3350 value is returned to indicate the presence of the mapped memory on the
3351 device. A zero is returned to indicate the memory is not mapped on the
3354 In Fortran, two (2) forms are supported. In the first form, @var{a} specifies
3355 a contiguous array section. The second form @var{a} specifies a variable or
3356 array element and @var{len} specifies the length in bytes. If the host
3357 memory is mapped to device memory, then a @code{true} is returned. Otherwise,
3358 a @code{false} is return to indicate the mapped memory is not present.
3361 @multitable @columnfractions .20 .80
3362 @item @emph{Prototype}: @tab @code{int acc_is_present(h_void *a, size_t len);}
3365 @item @emph{Fortran}:
3366 @multitable @columnfractions .20 .80
3367 @item @emph{Interface}: @tab @code{function acc_is_present(a)}
3368 @item @tab @code{type, dimension(:[,:]...) :: a}
3369 @item @tab @code{logical acc_is_present}
3370 @item @emph{Interface}: @tab @code{function acc_is_present(a, len)}
3371 @item @tab @code{type, dimension(:[,:]...) :: a}
3372 @item @tab @code{integer len}
3373 @item @tab @code{logical acc_is_present}
3376 @item @emph{Reference}:
3377 @uref{https://www.openacc.org, OpenACC specification v2.6}, section
3383 @node acc_memcpy_to_device
3384 @section @code{acc_memcpy_to_device} -- Copy host memory to device memory.
3386 @item @emph{Description}
3387 This function copies host memory specified by host address of @var{src} to
3388 device memory specified by the device address @var{dest} for a length of
3392 @multitable @columnfractions .20 .80
3393 @item @emph{Prototype}: @tab @code{acc_memcpy_to_device(d_void *dest, h_void *src, size_t bytes);}
3396 @item @emph{Reference}:
3397 @uref{https://www.openacc.org, OpenACC specification v2.6}, section
3403 @node acc_memcpy_from_device
3404 @section @code{acc_memcpy_from_device} -- Copy device memory to host memory.
3406 @item @emph{Description}
3407 This function copies host memory specified by host address of @var{src} from
3408 device memory specified by the device address @var{dest} for a length of
3412 @multitable @columnfractions .20 .80
3413 @item @emph{Prototype}: @tab @code{acc_memcpy_from_device(d_void *dest, h_void *src, size_t bytes);}
3416 @item @emph{Reference}:
3417 @uref{https://www.openacc.org, OpenACC specification v2.6}, section
3424 @section @code{acc_attach} -- Let device pointer point to device-pointer target.
3426 @item @emph{Description}
3427 This function updates a pointer on the device from pointing to a host-pointer
3428 address to pointing to the corresponding device data.
3431 @multitable @columnfractions .20 .80
3432 @item @emph{Prototype}: @tab @code{acc_attach(h_void **ptr);}
3433 @item @emph{Prototype}: @tab @code{acc_attach_async(h_void **ptr, int async);}
3436 @item @emph{Reference}:
3437 @uref{https://www.openacc.org, OpenACC specification v2.6}, section
3444 @section @code{acc_detach} -- Let device pointer point to host-pointer target.
3446 @item @emph{Description}
3447 This function updates a pointer on the device from pointing to a device-pointer
3448 address to pointing to the corresponding host data.
3451 @multitable @columnfractions .20 .80
3452 @item @emph{Prototype}: @tab @code{acc_detach(h_void **ptr);}
3453 @item @emph{Prototype}: @tab @code{acc_detach_async(h_void **ptr, int async);}
3454 @item @emph{Prototype}: @tab @code{acc_detach_finalize(h_void **ptr);}
3455 @item @emph{Prototype}: @tab @code{acc_detach_finalize_async(h_void **ptr, int async);}
3458 @item @emph{Reference}:
3459 @uref{https://www.openacc.org, OpenACC specification v2.6}, section
3465 @node acc_get_current_cuda_device
3466 @section @code{acc_get_current_cuda_device} -- Get CUDA device handle.
3468 @item @emph{Description}
3469 This function returns the CUDA device handle. This handle is the same
3470 as used by the CUDA Runtime or Driver API's.
3473 @multitable @columnfractions .20 .80
3474 @item @emph{Prototype}: @tab @code{void *acc_get_current_cuda_device(void);}
3477 @item @emph{Reference}:
3478 @uref{https://www.openacc.org, OpenACC specification v2.6}, section
3484 @node acc_get_current_cuda_context
3485 @section @code{acc_get_current_cuda_context} -- Get CUDA context handle.
3487 @item @emph{Description}
3488 This function returns the CUDA context handle. This handle is the same
3489 as used by the CUDA Runtime or Driver API's.
3492 @multitable @columnfractions .20 .80
3493 @item @emph{Prototype}: @tab @code{void *acc_get_current_cuda_context(void);}
3496 @item @emph{Reference}:
3497 @uref{https://www.openacc.org, OpenACC specification v2.6}, section
3503 @node acc_get_cuda_stream
3504 @section @code{acc_get_cuda_stream} -- Get CUDA stream handle.
3506 @item @emph{Description}
3507 This function returns the CUDA stream handle for the queue @var{async}.
3508 This handle is the same as used by the CUDA Runtime or Driver API's.
3511 @multitable @columnfractions .20 .80
3512 @item @emph{Prototype}: @tab @code{void *acc_get_cuda_stream(int async);}
3515 @item @emph{Reference}:
3516 @uref{https://www.openacc.org, OpenACC specification v2.6}, section
3522 @node acc_set_cuda_stream
3523 @section @code{acc_set_cuda_stream} -- Set CUDA stream handle.
3525 @item @emph{Description}
3526 This function associates the stream handle specified by @var{stream} with
3527 the queue @var{async}.
3529 This cannot be used to change the stream handle associated with
3530 @code{acc_async_sync}.
3532 The return value is not specified.
3535 @multitable @columnfractions .20 .80
3536 @item @emph{Prototype}: @tab @code{int acc_set_cuda_stream(int async, void *stream);}
3539 @item @emph{Reference}:
3540 @uref{https://www.openacc.org, OpenACC specification v2.6}, section
3546 @node acc_prof_register
3547 @section @code{acc_prof_register} -- Register callbacks.
3549 @item @emph{Description}:
3550 This function registers callbacks.
3553 @multitable @columnfractions .20 .80
3554 @item @emph{Prototype}: @tab @code{void acc_prof_register (acc_event_t, acc_prof_callback, acc_register_t);}
3557 @item @emph{See also}:
3558 @ref{OpenACC Profiling Interface}
3560 @item @emph{Reference}:
3561 @uref{https://www.openacc.org, OpenACC specification v2.6}, section
3567 @node acc_prof_unregister
3568 @section @code{acc_prof_unregister} -- Unregister callbacks.
3570 @item @emph{Description}:
3571 This function unregisters callbacks.
3574 @multitable @columnfractions .20 .80
3575 @item @emph{Prototype}: @tab @code{void acc_prof_unregister (acc_event_t, acc_prof_callback, acc_register_t);}
3578 @item @emph{See also}:
3579 @ref{OpenACC Profiling Interface}
3581 @item @emph{Reference}:
3582 @uref{https://www.openacc.org, OpenACC specification v2.6}, section
3588 @node acc_prof_lookup
3589 @section @code{acc_prof_lookup} -- Obtain inquiry functions.
3591 @item @emph{Description}:
3592 Function to obtain inquiry functions.
3595 @multitable @columnfractions .20 .80
3596 @item @emph{Prototype}: @tab @code{acc_query_fn acc_prof_lookup (const char *);}
3599 @item @emph{See also}:
3600 @ref{OpenACC Profiling Interface}
3602 @item @emph{Reference}:
3603 @uref{https://www.openacc.org, OpenACC specification v2.6}, section
3609 @node acc_register_library
3610 @section @code{acc_register_library} -- Library registration.
3612 @item @emph{Description}:
3613 Function for library registration.
3616 @multitable @columnfractions .20 .80
3617 @item @emph{Prototype}: @tab @code{void acc_register_library (acc_prof_reg, acc_prof_reg, acc_prof_lookup_func);}
3620 @item @emph{See also}:
3621 @ref{OpenACC Profiling Interface}, @ref{ACC_PROFLIB}
3623 @item @emph{Reference}:
3624 @uref{https://www.openacc.org, OpenACC specification v2.6}, section
3630 @c ---------------------------------------------------------------------
3631 @c OpenACC Environment Variables
3632 @c ---------------------------------------------------------------------
3634 @node OpenACC Environment Variables
3635 @chapter OpenACC Environment Variables
3637 The variables @env{ACC_DEVICE_TYPE} and @env{ACC_DEVICE_NUM}
3638 are defined by section 4 of the OpenACC specification in version 2.0.
3639 The variable @env{ACC_PROFLIB}
3640 is defined by section 4 of the OpenACC specification in version 2.6.
3641 The variable @env{GCC_ACC_NOTIFY} is used for diagnostic purposes.
3652 @node ACC_DEVICE_TYPE
3653 @section @code{ACC_DEVICE_TYPE}
3655 @item @emph{Reference}:
3656 @uref{https://www.openacc.org, OpenACC specification v2.6}, section
3662 @node ACC_DEVICE_NUM
3663 @section @code{ACC_DEVICE_NUM}
3665 @item @emph{Reference}:
3666 @uref{https://www.openacc.org, OpenACC specification v2.6}, section
3673 @section @code{ACC_PROFLIB}
3675 @item @emph{See also}:
3676 @ref{acc_register_library}, @ref{OpenACC Profiling Interface}
3678 @item @emph{Reference}:
3679 @uref{https://www.openacc.org, OpenACC specification v2.6}, section
3685 @node GCC_ACC_NOTIFY
3686 @section @code{GCC_ACC_NOTIFY}
3688 @item @emph{Description}:
3689 Print debug information pertaining to the accelerator.
3694 @c ---------------------------------------------------------------------
3695 @c CUDA Streams Usage
3696 @c ---------------------------------------------------------------------
3698 @node CUDA Streams Usage
3699 @chapter CUDA Streams Usage
3701 This applies to the @code{nvptx} plugin only.
3703 The library provides elements that perform asynchronous movement of
3704 data and asynchronous operation of computing constructs. This
3705 asynchronous functionality is implemented by making use of CUDA
3706 streams@footnote{See "Stream Management" in "CUDA Driver API",
3707 TRM-06703-001, Version 5.5, for additional information}.
3709 The primary means by that the asynchronous functionality is accessed
3710 is through the use of those OpenACC directives which make use of the
3711 @code{async} and @code{wait} clauses. When the @code{async} clause is
3712 first used with a directive, it creates a CUDA stream. If an
3713 @code{async-argument} is used with the @code{async} clause, then the
3714 stream is associated with the specified @code{async-argument}.
3716 Following the creation of an association between a CUDA stream and the
3717 @code{async-argument} of an @code{async} clause, both the @code{wait}
3718 clause and the @code{wait} directive can be used. When either the
3719 clause or directive is used after stream creation, it creates a
3720 rendezvous point whereby execution waits until all operations
3721 associated with the @code{async-argument}, that is, stream, have
3724 Normally, the management of the streams that are created as a result of
3725 using the @code{async} clause, is done without any intervention by the
3726 caller. This implies the association between the @code{async-argument}
3727 and the CUDA stream will be maintained for the lifetime of the program.
3728 However, this association can be changed through the use of the library
3729 function @code{acc_set_cuda_stream}. When the function
3730 @code{acc_set_cuda_stream} is called, the CUDA stream that was
3731 originally associated with the @code{async} clause will be destroyed.
3732 Caution should be taken when changing the association as subsequent
3733 references to the @code{async-argument} refer to a different
3738 @c ---------------------------------------------------------------------
3739 @c OpenACC Library Interoperability
3740 @c ---------------------------------------------------------------------
3742 @node OpenACC Library Interoperability
3743 @chapter OpenACC Library Interoperability
3745 @section Introduction
3747 The OpenACC library uses the CUDA Driver API, and may interact with
3748 programs that use the Runtime library directly, or another library
3749 based on the Runtime library, e.g., CUBLAS@footnote{See section 2.26,
3750 "Interactions with the CUDA Driver API" in
3751 "CUDA Runtime API", Version 5.5, and section 2.27, "VDPAU
3752 Interoperability", in "CUDA Driver API", TRM-06703-001, Version 5.5,
3753 for additional information on library interoperability.}.
3754 This chapter describes the use cases and what changes are
3755 required in order to use both the OpenACC library and the CUBLAS and Runtime
3756 libraries within a program.
3758 @section First invocation: NVIDIA CUBLAS library API
3760 In this first use case (see below), a function in the CUBLAS library is called
3761 prior to any of the functions in the OpenACC library. More specifically, the
3762 function @code{cublasCreate()}.
3764 When invoked, the function initializes the library and allocates the
3765 hardware resources on the host and the device on behalf of the caller. Once
3766 the initialization and allocation has completed, a handle is returned to the
3767 caller. The OpenACC library also requires initialization and allocation of
3768 hardware resources. Since the CUBLAS library has already allocated the
3769 hardware resources for the device, all that is left to do is to initialize
3770 the OpenACC library and acquire the hardware resources on the host.
3772 Prior to calling the OpenACC function that initializes the library and
3773 allocate the host hardware resources, you need to acquire the device number
3774 that was allocated during the call to @code{cublasCreate()}. The invoking of the
3775 runtime library function @code{cudaGetDevice()} accomplishes this. Once
3776 acquired, the device number is passed along with the device type as
3777 parameters to the OpenACC library function @code{acc_set_device_num()}.
3779 Once the call to @code{acc_set_device_num()} has completed, the OpenACC
3780 library uses the context that was created during the call to
3781 @code{cublasCreate()}. In other words, both libraries will be sharing the
3785 /* Create the handle */
3786 s = cublasCreate(&h);
3787 if (s != CUBLAS_STATUS_SUCCESS)
3789 fprintf(stderr, "cublasCreate failed %d\n", s);
3793 /* Get the device number */
3794 e = cudaGetDevice(&dev);
3795 if (e != cudaSuccess)
3797 fprintf(stderr, "cudaGetDevice failed %d\n", e);
3801 /* Initialize OpenACC library and use device 'dev' */
3802 acc_set_device_num(dev, acc_device_nvidia);
3807 @section First invocation: OpenACC library API
3809 In this second use case (see below), a function in the OpenACC library is
3810 called prior to any of the functions in the CUBLAS library. More specificially,
3811 the function @code{acc_set_device_num()}.
3813 In the use case presented here, the function @code{acc_set_device_num()}
3814 is used to both initialize the OpenACC library and allocate the hardware
3815 resources on the host and the device. In the call to the function, the
3816 call parameters specify which device to use and what device
3817 type to use, i.e., @code{acc_device_nvidia}. It should be noted that this
3818 is but one method to initialize the OpenACC library and allocate the
3819 appropriate hardware resources. Other methods are available through the
3820 use of environment variables and these will be discussed in the next section.
3822 Once the call to @code{acc_set_device_num()} has completed, other OpenACC
3823 functions can be called as seen with multiple calls being made to
3824 @code{acc_copyin()}. In addition, calls can be made to functions in the
3825 CUBLAS library. In the use case a call to @code{cublasCreate()} is made
3826 subsequent to the calls to @code{acc_copyin()}.
3827 As seen in the previous use case, a call to @code{cublasCreate()}
3828 initializes the CUBLAS library and allocates the hardware resources on the
3829 host and the device. However, since the device has already been allocated,
3830 @code{cublasCreate()} will only initialize the CUBLAS library and allocate
3831 the appropriate hardware resources on the host. The context that was created
3832 as part of the OpenACC initialization is shared with the CUBLAS library,
3833 similarly to the first use case.
3838 acc_set_device_num(dev, acc_device_nvidia);
3840 /* Copy the first set to the device */
3841 d_X = acc_copyin(&h_X[0], N * sizeof (float));
3844 fprintf(stderr, "copyin error h_X\n");
3848 /* Copy the second set to the device */
3849 d_Y = acc_copyin(&h_Y1[0], N * sizeof (float));
3852 fprintf(stderr, "copyin error h_Y1\n");
3856 /* Create the handle */
3857 s = cublasCreate(&h);
3858 if (s != CUBLAS_STATUS_SUCCESS)
3860 fprintf(stderr, "cublasCreate failed %d\n", s);
3864 /* Perform saxpy using CUBLAS library function */
3865 s = cublasSaxpy(h, N, &alpha, d_X, 1, d_Y, 1);
3866 if (s != CUBLAS_STATUS_SUCCESS)
3868 fprintf(stderr, "cublasSaxpy failed %d\n", s);
3872 /* Copy the results from the device */
3873 acc_memcpy_from_device(&h_Y1[0], d_Y, N * sizeof (float));
3878 @section OpenACC library and environment variables
3880 There are two environment variables associated with the OpenACC library
3881 that may be used to control the device type and device number:
3882 @env{ACC_DEVICE_TYPE} and @env{ACC_DEVICE_NUM}, respectively. These two
3883 environment variables can be used as an alternative to calling
3884 @code{acc_set_device_num()}. As seen in the second use case, the device
3885 type and device number were specified using @code{acc_set_device_num()}.
3886 If however, the aforementioned environment variables were set, then the
3887 call to @code{acc_set_device_num()} would not be required.
3890 The use of the environment variables is only relevant when an OpenACC function
3891 is called prior to a call to @code{cudaCreate()}. If @code{cudaCreate()}
3892 is called prior to a call to an OpenACC function, then you must call
3893 @code{acc_set_device_num()}@footnote{More complete information
3894 about @env{ACC_DEVICE_TYPE} and @env{ACC_DEVICE_NUM} can be found in
3895 sections 4.1 and 4.2 of the @uref{https://www.openacc.org, OpenACC}
3896 Application Programming Interface”, Version 2.6.}
3900 @c ---------------------------------------------------------------------
3901 @c OpenACC Profiling Interface
3902 @c ---------------------------------------------------------------------
3904 @node OpenACC Profiling Interface
3905 @chapter OpenACC Profiling Interface
3907 @section Implementation Status and Implementation-Defined Behavior
3909 We're implementing the OpenACC Profiling Interface as defined by the
3910 OpenACC 2.6 specification. We're clarifying some aspects here as
3911 @emph{implementation-defined behavior}, while they're still under
3912 discussion within the OpenACC Technical Committee.
3914 This implementation is tuned to keep the performance impact as low as
3915 possible for the (very common) case that the Profiling Interface is
3916 not enabled. This is relevant, as the Profiling Interface affects all
3917 the @emph{hot} code paths (in the target code, not in the offloaded
3918 code). Users of the OpenACC Profiling Interface can be expected to
3919 understand that performance will be impacted to some degree once the
3920 Profiling Interface has gotten enabled: for example, because of the
3921 @emph{runtime} (libgomp) calling into a third-party @emph{library} for
3922 every event that has been registered.
3924 We're not yet accounting for the fact that @cite{OpenACC events may
3925 occur during event processing}.
3926 We just handle one case specially, as required by CUDA 9.0
3927 @command{nvprof}, that @code{acc_get_device_type}
3928 (@ref{acc_get_device_type})) may be called from
3929 @code{acc_ev_device_init_start}, @code{acc_ev_device_init_end}
3932 We're not yet implementing initialization via a
3933 @code{acc_register_library} function that is either statically linked
3934 in, or dynamically via @env{LD_PRELOAD}.
3935 Initialization via @code{acc_register_library} functions dynamically
3936 loaded via the @env{ACC_PROFLIB} environment variable does work, as
3937 does directly calling @code{acc_prof_register},
3938 @code{acc_prof_unregister}, @code{acc_prof_lookup}.
3940 As currently there are no inquiry functions defined, calls to
3941 @code{acc_prof_lookup} will always return @code{NULL}.
3943 There aren't separate @emph{start}, @emph{stop} events defined for the
3944 event types @code{acc_ev_create}, @code{acc_ev_delete},
3945 @code{acc_ev_alloc}, @code{acc_ev_free}. It's not clear if these
3946 should be triggered before or after the actual device-specific call is
3947 made. We trigger them after.
3949 Remarks about data provided to callbacks:
3953 @item @code{acc_prof_info.event_type}
3954 It's not clear if for @emph{nested} event callbacks (for example,
3955 @code{acc_ev_enqueue_launch_start} as part of a parent compute
3956 construct), this should be set for the nested event
3957 (@code{acc_ev_enqueue_launch_start}), or if the value of the parent
3958 construct should remain (@code{acc_ev_compute_construct_start}). In
3959 this implementation, the value will generally correspond to the
3960 innermost nested event type.
3962 @item @code{acc_prof_info.device_type}
3966 For @code{acc_ev_compute_construct_start}, and in presence of an
3967 @code{if} clause with @emph{false} argument, this will still refer to
3968 the offloading device type.
3969 It's not clear if that's the expected behavior.
3972 Complementary to the item before, for
3973 @code{acc_ev_compute_construct_end}, this is set to
3974 @code{acc_device_host} in presence of an @code{if} clause with
3975 @emph{false} argument.
3976 It's not clear if that's the expected behavior.
3980 @item @code{acc_prof_info.thread_id}
3981 Always @code{-1}; not yet implemented.
3983 @item @code{acc_prof_info.async}
3987 Not yet implemented correctly for
3988 @code{acc_ev_compute_construct_start}.
3991 In a compute construct, for host-fallback
3992 execution/@code{acc_device_host} it will always be
3993 @code{acc_async_sync}.
3994 It's not clear if that's the expected behavior.
3997 For @code{acc_ev_device_init_start} and @code{acc_ev_device_init_end},
3998 it will always be @code{acc_async_sync}.
3999 It's not clear if that's the expected behavior.
4003 @item @code{acc_prof_info.async_queue}
4004 There is no @cite{limited number of asynchronous queues} in libgomp.
4005 This will always have the same value as @code{acc_prof_info.async}.
4007 @item @code{acc_prof_info.src_file}
4008 Always @code{NULL}; not yet implemented.
4010 @item @code{acc_prof_info.func_name}
4011 Always @code{NULL}; not yet implemented.
4013 @item @code{acc_prof_info.line_no}
4014 Always @code{-1}; not yet implemented.
4016 @item @code{acc_prof_info.end_line_no}
4017 Always @code{-1}; not yet implemented.
4019 @item @code{acc_prof_info.func_line_no}
4020 Always @code{-1}; not yet implemented.
4022 @item @code{acc_prof_info.func_end_line_no}
4023 Always @code{-1}; not yet implemented.
4025 @item @code{acc_event_info.event_type}, @code{acc_event_info.*.event_type}
4026 Relating to @code{acc_prof_info.event_type} discussed above, in this
4027 implementation, this will always be the same value as
4028 @code{acc_prof_info.event_type}.
4030 @item @code{acc_event_info.*.parent_construct}
4034 Will be @code{acc_construct_parallel} for all OpenACC compute
4035 constructs as well as many OpenACC Runtime API calls; should be the
4036 one matching the actual construct, or
4037 @code{acc_construct_runtime_api}, respectively.
4040 Will be @code{acc_construct_enter_data} or
4041 @code{acc_construct_exit_data} when processing variable mappings
4042 specified in OpenACC @emph{declare} directives; should be
4043 @code{acc_construct_declare}.
4046 For implicit @code{acc_ev_device_init_start},
4047 @code{acc_ev_device_init_end}, and explicit as well as implicit
4048 @code{acc_ev_alloc}, @code{acc_ev_free},
4049 @code{acc_ev_enqueue_upload_start}, @code{acc_ev_enqueue_upload_end},
4050 @code{acc_ev_enqueue_download_start}, and
4051 @code{acc_ev_enqueue_download_end}, will be
4052 @code{acc_construct_parallel}; should reflect the real parent
4057 @item @code{acc_event_info.*.implicit}
4058 For @code{acc_ev_alloc}, @code{acc_ev_free},
4059 @code{acc_ev_enqueue_upload_start}, @code{acc_ev_enqueue_upload_end},
4060 @code{acc_ev_enqueue_download_start}, and
4061 @code{acc_ev_enqueue_download_end}, this currently will be @code{1}
4062 also for explicit usage.
4064 @item @code{acc_event_info.data_event.var_name}
4065 Always @code{NULL}; not yet implemented.
4067 @item @code{acc_event_info.data_event.host_ptr}
4068 For @code{acc_ev_alloc}, and @code{acc_ev_free}, this is always
4071 @item @code{typedef union acc_api_info}
4072 @dots{} as printed in @cite{5.2.3. Third Argument: API-Specific
4073 Information}. This should obviously be @code{typedef @emph{struct}
4076 @item @code{acc_api_info.device_api}
4077 Possibly not yet implemented correctly for
4078 @code{acc_ev_compute_construct_start},
4079 @code{acc_ev_device_init_start}, @code{acc_ev_device_init_end}:
4080 will always be @code{acc_device_api_none} for these event types.
4081 For @code{acc_ev_enter_data_start}, it will be
4082 @code{acc_device_api_none} in some cases.
4084 @item @code{acc_api_info.device_type}
4085 Always the same as @code{acc_prof_info.device_type}.
4087 @item @code{acc_api_info.vendor}
4088 Always @code{-1}; not yet implemented.
4090 @item @code{acc_api_info.device_handle}
4091 Always @code{NULL}; not yet implemented.
4093 @item @code{acc_api_info.context_handle}
4094 Always @code{NULL}; not yet implemented.
4096 @item @code{acc_api_info.async_handle}
4097 Always @code{NULL}; not yet implemented.
4101 Remarks about certain event types:
4105 @item @code{acc_ev_device_init_start}, @code{acc_ev_device_init_end}
4109 @c See 'DEVICE_INIT_INSIDE_COMPUTE_CONSTRUCT' in
4110 @c 'libgomp.oacc-c-c++-common/acc_prof-kernels-1.c',
4111 @c 'libgomp.oacc-c-c++-common/acc_prof-parallel-1.c'.
4112 When a compute construct triggers implicit
4113 @code{acc_ev_device_init_start} and @code{acc_ev_device_init_end}
4114 events, they currently aren't @emph{nested within} the corresponding
4115 @code{acc_ev_compute_construct_start} and
4116 @code{acc_ev_compute_construct_end}, but they're currently observed
4117 @emph{before} @code{acc_ev_compute_construct_start}.
4118 It's not clear what to do: the standard asks us provide a lot of
4119 details to the @code{acc_ev_compute_construct_start} callback, without
4120 (implicitly) initializing a device before?
4123 Callbacks for these event types will not be invoked for calls to the
4124 @code{acc_set_device_type} and @code{acc_set_device_num} functions.
4125 It's not clear if they should be.
4129 @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}
4133 Callbacks for these event types will also be invoked for OpenACC
4134 @emph{host_data} constructs.
4135 It's not clear if they should be.
4138 Callbacks for these event types will also be invoked when processing
4139 variable mappings specified in OpenACC @emph{declare} directives.
4140 It's not clear if they should be.
4146 Callbacks for the following event types will be invoked, but dispatch
4147 and information provided therein has not yet been thoroughly reviewed:
4150 @item @code{acc_ev_alloc}
4151 @item @code{acc_ev_free}
4152 @item @code{acc_ev_update_start}, @code{acc_ev_update_end}
4153 @item @code{acc_ev_enqueue_upload_start}, @code{acc_ev_enqueue_upload_end}
4154 @item @code{acc_ev_enqueue_download_start}, @code{acc_ev_enqueue_download_end}
4157 During device initialization, and finalization, respectively,
4158 callbacks for the following event types will not yet be invoked:
4161 @item @code{acc_ev_alloc}
4162 @item @code{acc_ev_free}
4165 Callbacks for the following event types have not yet been implemented,
4166 so currently won't be invoked:
4169 @item @code{acc_ev_device_shutdown_start}, @code{acc_ev_device_shutdown_end}
4170 @item @code{acc_ev_runtime_shutdown}
4171 @item @code{acc_ev_create}, @code{acc_ev_delete}
4172 @item @code{acc_ev_wait_start}, @code{acc_ev_wait_end}
4175 For the following runtime library functions, not all expected
4176 callbacks will be invoked (mostly concerning implicit device
4180 @item @code{acc_get_num_devices}
4181 @item @code{acc_set_device_type}
4182 @item @code{acc_get_device_type}
4183 @item @code{acc_set_device_num}
4184 @item @code{acc_get_device_num}
4185 @item @code{acc_init}
4186 @item @code{acc_shutdown}
4189 Aside from implicit device initialization, for the following runtime
4190 library functions, no callbacks will be invoked for shared-memory
4191 offloading devices (it's not clear if they should be):
4194 @item @code{acc_malloc}
4195 @item @code{acc_free}
4196 @item @code{acc_copyin}, @code{acc_present_or_copyin}, @code{acc_copyin_async}
4197 @item @code{acc_create}, @code{acc_present_or_create}, @code{acc_create_async}
4198 @item @code{acc_copyout}, @code{acc_copyout_async}, @code{acc_copyout_finalize}, @code{acc_copyout_finalize_async}
4199 @item @code{acc_delete}, @code{acc_delete_async}, @code{acc_delete_finalize}, @code{acc_delete_finalize_async}
4200 @item @code{acc_update_device}, @code{acc_update_device_async}
4201 @item @code{acc_update_self}, @code{acc_update_self_async}
4202 @item @code{acc_map_data}, @code{acc_unmap_data}
4203 @item @code{acc_memcpy_to_device}, @code{acc_memcpy_to_device_async}
4204 @item @code{acc_memcpy_from_device}, @code{acc_memcpy_from_device_async}
4209 @c ---------------------------------------------------------------------
4211 @c ---------------------------------------------------------------------
4213 @node The libgomp ABI
4214 @chapter The libgomp ABI
4216 The following sections present notes on the external ABI as
4217 presented by libgomp. Only maintainers should need them.
4220 * Implementing MASTER construct::
4221 * Implementing CRITICAL construct::
4222 * Implementing ATOMIC construct::
4223 * Implementing FLUSH construct::
4224 * Implementing BARRIER construct::
4225 * Implementing THREADPRIVATE construct::
4226 * Implementing PRIVATE clause::
4227 * Implementing FIRSTPRIVATE LASTPRIVATE COPYIN and COPYPRIVATE clauses::
4228 * Implementing REDUCTION clause::
4229 * Implementing PARALLEL construct::
4230 * Implementing FOR construct::
4231 * Implementing ORDERED construct::
4232 * Implementing SECTIONS construct::
4233 * Implementing SINGLE construct::
4234 * Implementing OpenACC's PARALLEL construct::
4238 @node Implementing MASTER construct
4239 @section Implementing MASTER construct
4242 if (omp_get_thread_num () == 0)
4246 Alternately, we generate two copies of the parallel subfunction
4247 and only include this in the version run by the primary thread.
4248 Surely this is not worthwhile though...
4252 @node Implementing CRITICAL construct
4253 @section Implementing CRITICAL construct
4255 Without a specified name,
4258 void GOMP_critical_start (void);
4259 void GOMP_critical_end (void);
4262 so that we don't get COPY relocations from libgomp to the main
4265 With a specified name, use omp_set_lock and omp_unset_lock with
4266 name being transformed into a variable declared like
4269 omp_lock_t gomp_critical_user_<name> __attribute__((common))
4272 Ideally the ABI would specify that all zero is a valid unlocked
4273 state, and so we wouldn't need to initialize this at
4278 @node Implementing ATOMIC construct
4279 @section Implementing ATOMIC construct
4281 The target should implement the @code{__sync} builtins.
4283 Failing that we could add
4286 void GOMP_atomic_enter (void)
4287 void GOMP_atomic_exit (void)
4290 which reuses the regular lock code, but with yet another lock
4291 object private to the library.
4295 @node Implementing FLUSH construct
4296 @section Implementing FLUSH construct
4298 Expands to the @code{__sync_synchronize} builtin.
4302 @node Implementing BARRIER construct
4303 @section Implementing BARRIER construct
4306 void GOMP_barrier (void)
4310 @node Implementing THREADPRIVATE construct
4311 @section Implementing THREADPRIVATE construct
4313 In _most_ cases we can map this directly to @code{__thread}. Except
4314 that OMP allows constructors for C++ objects. We can either
4315 refuse to support this (how often is it used?) or we can
4316 implement something akin to .ctors.
4318 Even more ideally, this ctor feature is handled by extensions
4319 to the main pthreads library. Failing that, we can have a set
4320 of entry points to register ctor functions to be called.
4324 @node Implementing PRIVATE clause
4325 @section Implementing PRIVATE clause
4327 In association with a PARALLEL, or within the lexical extent
4328 of a PARALLEL block, the variable becomes a local variable in
4329 the parallel subfunction.
4331 In association with FOR or SECTIONS blocks, create a new
4332 automatic variable within the current function. This preserves
4333 the semantic of new variable creation.
4337 @node Implementing FIRSTPRIVATE LASTPRIVATE COPYIN and COPYPRIVATE clauses
4338 @section Implementing FIRSTPRIVATE LASTPRIVATE COPYIN and COPYPRIVATE clauses
4340 This seems simple enough for PARALLEL blocks. Create a private
4341 struct for communicating between the parent and subfunction.
4342 In the parent, copy in values for scalar and "small" structs;
4343 copy in addresses for others TREE_ADDRESSABLE types. In the
4344 subfunction, copy the value into the local variable.
4346 It is not clear what to do with bare FOR or SECTION blocks.
4347 The only thing I can figure is that we do something like:
4350 #pragma omp for firstprivate(x) lastprivate(y)
4351 for (int i = 0; i < n; ++i)
4368 where the "x=x" and "y=y" assignments actually have different
4369 uids for the two variables, i.e. not something you could write
4370 directly in C. Presumably this only makes sense if the "outer"
4371 x and y are global variables.
4373 COPYPRIVATE would work the same way, except the structure
4374 broadcast would have to happen via SINGLE machinery instead.
4378 @node Implementing REDUCTION clause
4379 @section Implementing REDUCTION clause
4381 The private struct mentioned in the previous section should have
4382 a pointer to an array of the type of the variable, indexed by the
4383 thread's @var{team_id}. The thread stores its final value into the
4384 array, and after the barrier, the primary thread iterates over the
4385 array to collect the values.
4388 @node Implementing PARALLEL construct
4389 @section Implementing PARALLEL construct
4392 #pragma omp parallel
4401 void subfunction (void *data)
4408 GOMP_parallel_start (subfunction, &data, num_threads);
4409 subfunction (&data);
4410 GOMP_parallel_end ();
4414 void GOMP_parallel_start (void (*fn)(void *), void *data, unsigned num_threads)
4417 The @var{FN} argument is the subfunction to be run in parallel.
4419 The @var{DATA} argument is a pointer to a structure used to
4420 communicate data in and out of the subfunction, as discussed
4421 above with respect to FIRSTPRIVATE et al.
4423 The @var{NUM_THREADS} argument is 1 if an IF clause is present
4424 and false, or the value of the NUM_THREADS clause, if
4427 The function needs to create the appropriate number of
4428 threads and/or launch them from the dock. It needs to
4429 create the team structure and assign team ids.
4432 void GOMP_parallel_end (void)
4435 Tears down the team and returns us to the previous @code{omp_in_parallel()} state.
4439 @node Implementing FOR construct
4440 @section Implementing FOR construct
4443 #pragma omp parallel for
4444 for (i = lb; i <= ub; i++)
4451 void subfunction (void *data)
4454 while (GOMP_loop_static_next (&_s0, &_e0))
4457 for (i = _s0; i < _e1; i++)
4460 GOMP_loop_end_nowait ();
4463 GOMP_parallel_loop_static (subfunction, NULL, 0, lb, ub+1, 1, 0);
4465 GOMP_parallel_end ();
4469 #pragma omp for schedule(runtime)
4470 for (i = 0; i < n; i++)
4479 if (GOMP_loop_runtime_start (0, n, 1, &_s0, &_e0))
4482 for (i = _s0, i < _e0; i++)
4484 @} while (GOMP_loop_runtime_next (&_s0, _&e0));
4489 Note that while it looks like there is trickiness to propagating
4490 a non-constant STEP, there isn't really. We're explicitly allowed
4491 to evaluate it as many times as we want, and any variables involved
4492 should automatically be handled as PRIVATE or SHARED like any other
4493 variables. So the expression should remain evaluable in the
4494 subfunction. We can also pull it into a local variable if we like,
4495 but since its supposed to remain unchanged, we can also not if we like.
4497 If we have SCHEDULE(STATIC), and no ORDERED, then we ought to be
4498 able to get away with no work-sharing context at all, since we can
4499 simply perform the arithmetic directly in each thread to divide up
4500 the iterations. Which would mean that we wouldn't need to call any
4503 There are separate routines for handling loops with an ORDERED
4504 clause. Bookkeeping for that is non-trivial...
4508 @node Implementing ORDERED construct
4509 @section Implementing ORDERED construct
4512 void GOMP_ordered_start (void)
4513 void GOMP_ordered_end (void)
4518 @node Implementing SECTIONS construct
4519 @section Implementing SECTIONS construct
4524 #pragma omp sections
4538 for (i = GOMP_sections_start (3); i != 0; i = GOMP_sections_next ())
4555 @node Implementing SINGLE construct
4556 @section Implementing SINGLE construct
4570 if (GOMP_single_start ())
4578 #pragma omp single copyprivate(x)
4585 datap = GOMP_single_copy_start ();
4590 GOMP_single_copy_end (&data);
4599 @node Implementing OpenACC's PARALLEL construct
4600 @section Implementing OpenACC's PARALLEL construct
4603 void GOACC_parallel ()
4608 @c ---------------------------------------------------------------------
4610 @c ---------------------------------------------------------------------
4612 @node Reporting Bugs
4613 @chapter Reporting Bugs
4615 Bugs in the GNU Offloading and Multi Processing Runtime Library should
4616 be reported via @uref{https://gcc.gnu.org/bugzilla/, Bugzilla}. Please add
4617 "openacc", or "openmp", or both to the keywords field in the bug
4618 report, as appropriate.
4622 @c ---------------------------------------------------------------------
4623 @c GNU General Public License
4624 @c ---------------------------------------------------------------------
4626 @include gpl_v3.texi
4630 @c ---------------------------------------------------------------------
4631 @c GNU Free Documentation License
4632 @c ---------------------------------------------------------------------
4638 @c ---------------------------------------------------------------------
4639 @c Funding Free Software
4640 @c ---------------------------------------------------------------------
4642 @include funding.texi
4644 @c ---------------------------------------------------------------------
4646 @c ---------------------------------------------------------------------
4649 @unnumbered Library Index