[Ada] Small cleanup in System.Exceptions
[official-gcc.git] / libgomp / libgomp.texi
blob2c1f1b5968b1dbd8143423828a50d2b2d73b1500
1 \input texinfo @c -*-texinfo-*-
3 @c %**start of header
4 @setfilename libgomp.info
5 @settitle GNU libgomp
6 @c %**end of header
9 @copying
10 Copyright @copyright{} 2006-2021 Free Software Foundation, Inc.
12 Permission is granted to copy, distribute and/or modify this document
13 under the terms of the GNU Free Documentation License, Version 1.3 or
14 any later version published by the Free Software Foundation; with the
15 Invariant Sections being ``Funding Free Software'', the Front-Cover
16 texts being (a) (see below), and with the Back-Cover Texts being (b)
17 (see below).  A copy of the license is included in the section entitled
18 ``GNU Free Documentation License''.
20 (a) The FSF's Front-Cover Text is:
22      A GNU Manual
24 (b) The FSF's Back-Cover Text is:
26      You have freedom to copy and modify this GNU Manual, like GNU
27      software.  Copies published by the Free Software Foundation raise
28      funds for GNU development.
29 @end copying
31 @ifinfo
32 @dircategory GNU Libraries
33 @direntry
34 * libgomp: (libgomp).          GNU Offloading and Multi Processing Runtime Library.
35 @end direntry
37 This manual documents libgomp, the GNU Offloading and Multi Processing
38 Runtime library.  This is the GNU implementation of the OpenMP and
39 OpenACC APIs for parallel and accelerator programming in C/C++ and
40 Fortran.
42 Published by the Free Software Foundation
43 51 Franklin Street, Fifth Floor
44 Boston, MA 02110-1301 USA
46 @insertcopying
47 @end ifinfo
50 @setchapternewpage odd
52 @titlepage
53 @title GNU Offloading and Multi Processing Runtime Library
54 @subtitle The GNU OpenMP and OpenACC Implementation
55 @page
56 @vskip 0pt plus 1filll
57 @comment For the @value{version-GCC} Version*
58 @sp 1
59 Published by the Free Software Foundation @*
60 51 Franklin Street, Fifth Floor@*
61 Boston, MA 02110-1301, USA@*
62 @sp 1
63 @insertcopying
64 @end titlepage
66 @summarycontents
67 @contents
68 @page
71 @node Top, Enabling OpenMP
72 @top Introduction
73 @cindex Introduction
75 This manual documents the usage of libgomp, the GNU Offloading and
76 Multi Processing Runtime Library.  This includes the GNU
77 implementation of the @uref{https://www.openmp.org, OpenMP} Application
78 Programming Interface (API) for multi-platform shared-memory parallel
79 programming in C/C++ and Fortran, and the GNU implementation of the
80 @uref{https://www.openacc.org, OpenACC} Application Programming
81 Interface (API) for offloading of code to accelerator devices in C/C++
82 and Fortran.
84 Originally, libgomp implemented the GNU OpenMP Runtime Library.  Based
85 on this, support for OpenACC and offloading (both OpenACC and OpenMP
86 4's target construct) has been added later on, and the library's name
87 changed to GNU Offloading and Multi Processing Runtime Library.
91 @comment
92 @comment  When you add a new menu item, please keep the right hand
93 @comment  aligned to the same column.  Do not use tabs.  This provides
94 @comment  better formatting.
95 @comment
96 @menu
97 * Enabling OpenMP::            How to enable OpenMP for your applications.
98 * OpenMP Runtime Library Routines: Runtime Library Routines.
99                                The OpenMP runtime application programming
100                                interface.
101 * OpenMP Environment Variables: Environment Variables.
102                                Influencing OpenMP runtime behavior with
103                                environment variables.
104 * Enabling OpenACC::           How to enable OpenACC for your
105                                applications.
106 * OpenACC Runtime Library Routines:: The OpenACC runtime application
107                                programming interface.
108 * OpenACC Environment Variables:: Influencing OpenACC runtime behavior with
109                                environment variables.
110 * CUDA Streams Usage::         Notes on the implementation of
111                                asynchronous operations.
112 * OpenACC Library Interoperability:: OpenACC library interoperability with the
113                                NVIDIA CUBLAS library.
114 * OpenACC Profiling Interface::
115 * The libgomp ABI::            Notes on the external ABI presented by libgomp.
116 * Reporting Bugs::             How to report bugs in the GNU Offloading and
117                                Multi Processing Runtime Library.
118 * Copying::                    GNU general public license says
119                                how you can copy and share libgomp.
120 * GNU Free Documentation License::
121                                How you can copy and share this manual.
122 * Funding::                    How to help assure continued work for free 
123                                software.
124 * Library Index::              Index of this documentation.
125 @end menu
128 @c ---------------------------------------------------------------------
129 @c Enabling OpenMP
130 @c ---------------------------------------------------------------------
132 @node Enabling OpenMP
133 @chapter Enabling OpenMP
135 To activate the OpenMP extensions for C/C++ and Fortran, the compile-time 
136 flag @command{-fopenmp} must be specified.  This enables the OpenMP directive
137 @code{#pragma omp} in C/C++ and @code{!$omp} directives in free form, 
138 @code{c$omp}, @code{*$omp} and @code{!$omp} directives in fixed form, 
139 @code{!$} conditional compilation sentinels in free form and @code{c$},
140 @code{*$} and @code{!$} sentinels in fixed form, for Fortran.  The flag also
141 arranges for automatic linking of the OpenMP runtime library 
142 (@ref{Runtime Library Routines}).
144 A complete description of all OpenMP directives accepted may be found in 
145 the @uref{https://www.openmp.org, OpenMP Application Program Interface} manual,
146 version 4.5.
149 @c ---------------------------------------------------------------------
150 @c OpenMP Runtime Library Routines
151 @c ---------------------------------------------------------------------
153 @node Runtime Library Routines
154 @chapter OpenMP Runtime Library Routines
156 The runtime routines described here are defined by Section 3 of the OpenMP
157 specification in version 4.5.  The routines are structured in following
158 three parts:
160 @menu
161 Control threads, processors and the parallel environment.  They have C
162 linkage, and do not throw exceptions.
164 * omp_get_active_level::        Number of active parallel regions
165 * omp_get_ancestor_thread_num:: Ancestor thread ID
166 * omp_get_cancellation::        Whether cancellation support is enabled
167 * omp_get_default_device::      Get the default device for target regions
168 * omp_get_dynamic::             Dynamic teams setting
169 * omp_get_initial_device::      Device number of host device
170 * omp_get_level::               Number of parallel regions
171 * omp_get_max_active_levels::   Current maximum number of active regions
172 * omp_get_max_task_priority::   Maximum task priority value that can be set
173 * omp_get_max_threads::         Maximum number of threads of parallel region
174 * omp_get_nested::              Nested parallel regions
175 * omp_get_num_devices::         Number of target devices
176 * omp_get_num_procs::           Number of processors online
177 * omp_get_num_teams::           Number of teams
178 * omp_get_num_threads::         Size of the active team
179 * omp_get_proc_bind::           Whether theads may be moved between CPUs
180 * omp_get_schedule::            Obtain the runtime scheduling method
181 * omp_get_supported_active_levels:: Maximum number of active regions supported
182 * omp_get_team_num::            Get team number
183 * omp_get_team_size::           Number of threads in a team
184 * omp_get_thread_limit::        Maximum number of threads
185 * omp_get_thread_num::          Current thread ID
186 * omp_in_parallel::             Whether a parallel region is active
187 * omp_in_final::                Whether in final or included task region
188 * omp_is_initial_device::       Whether executing on the host device
189 * omp_set_default_device::      Set the default device for target regions
190 * omp_set_dynamic::             Enable/disable dynamic teams
191 * omp_set_max_active_levels::   Limits the number of active parallel regions
192 * omp_set_nested::              Enable/disable nested parallel regions
193 * omp_set_num_threads::         Set upper team size limit
194 * omp_set_schedule::            Set the runtime scheduling method
196 Initialize, set, test, unset and destroy simple and nested locks.
198 * omp_init_lock::            Initialize simple lock
199 * omp_set_lock::             Wait for and set simple lock
200 * omp_test_lock::            Test and set simple lock if available
201 * omp_unset_lock::           Unset simple lock
202 * omp_destroy_lock::         Destroy simple lock
203 * omp_init_nest_lock::       Initialize nested lock
204 * omp_set_nest_lock::        Wait for and set simple lock
205 * omp_test_nest_lock::       Test and set nested lock if available
206 * omp_unset_nest_lock::      Unset nested lock
207 * omp_destroy_nest_lock::    Destroy nested lock
209 Portable, thread-based, wall clock timer.
211 * omp_get_wtick::            Get timer precision.
212 * omp_get_wtime::            Elapsed wall clock time.
214 Support for event objects.
216 * omp_fulfill_event::        Fulfill and destroy an OpenMP event.
217 @end menu
221 @node omp_get_active_level
222 @section @code{omp_get_active_level} -- Number of parallel regions
223 @table @asis
224 @item @emph{Description}:
225 This function returns the nesting level for the active parallel blocks,
226 which enclose the calling call.
228 @item @emph{C/C++}
229 @multitable @columnfractions .20 .80
230 @item @emph{Prototype}: @tab @code{int omp_get_active_level(void);}
231 @end multitable
233 @item @emph{Fortran}:
234 @multitable @columnfractions .20 .80
235 @item @emph{Interface}: @tab @code{integer function omp_get_active_level()}
236 @end multitable
238 @item @emph{See also}:
239 @ref{omp_get_level}, @ref{omp_get_max_active_levels}, @ref{omp_set_max_active_levels}
241 @item @emph{Reference}:
242 @uref{https://www.openmp.org, OpenMP specification v4.5}, Section 3.2.20.
243 @end table
247 @node omp_get_ancestor_thread_num
248 @section @code{omp_get_ancestor_thread_num} -- Ancestor thread ID
249 @table @asis
250 @item @emph{Description}:
251 This function returns the thread identification number for the given
252 nesting level of the current thread.  For values of @var{level} outside
253 zero to @code{omp_get_level} -1 is returned; if @var{level} is
254 @code{omp_get_level} the result is identical to @code{omp_get_thread_num}.
256 @item @emph{C/C++}
257 @multitable @columnfractions .20 .80
258 @item @emph{Prototype}: @tab @code{int omp_get_ancestor_thread_num(int level);}
259 @end multitable
261 @item @emph{Fortran}:
262 @multitable @columnfractions .20 .80
263 @item @emph{Interface}: @tab @code{integer function omp_get_ancestor_thread_num(level)}
264 @item                   @tab @code{integer level}
265 @end multitable
267 @item @emph{See also}:
268 @ref{omp_get_level}, @ref{omp_get_thread_num}, @ref{omp_get_team_size}
270 @item @emph{Reference}:
271 @uref{https://www.openmp.org, OpenMP specification v4.5}, Section 3.2.18.
272 @end table
276 @node omp_get_cancellation
277 @section @code{omp_get_cancellation} -- Whether cancellation support is enabled
278 @table @asis
279 @item @emph{Description}:
280 This function returns @code{true} if cancellation is activated, @code{false}
281 otherwise.  Here, @code{true} and @code{false} represent their language-specific
282 counterparts.  Unless @env{OMP_CANCELLATION} is set true, cancellations are
283 deactivated.
285 @item @emph{C/C++}:
286 @multitable @columnfractions .20 .80
287 @item @emph{Prototype}: @tab @code{int omp_get_cancellation(void);}
288 @end multitable
290 @item @emph{Fortran}:
291 @multitable @columnfractions .20 .80
292 @item @emph{Interface}: @tab @code{logical function omp_get_cancellation()}
293 @end multitable
295 @item @emph{See also}:
296 @ref{OMP_CANCELLATION}
298 @item @emph{Reference}:
299 @uref{https://www.openmp.org, OpenMP specification v4.5}, Section 3.2.9.
300 @end table
304 @node omp_get_default_device
305 @section @code{omp_get_default_device} -- Get the default device for target regions
306 @table @asis
307 @item @emph{Description}:
308 Get the default device for target regions without device clause.
310 @item @emph{C/C++}:
311 @multitable @columnfractions .20 .80
312 @item @emph{Prototype}: @tab @code{int omp_get_default_device(void);}
313 @end multitable
315 @item @emph{Fortran}:
316 @multitable @columnfractions .20 .80
317 @item @emph{Interface}: @tab @code{integer function omp_get_default_device()}
318 @end multitable
320 @item @emph{See also}:
321 @ref{OMP_DEFAULT_DEVICE}, @ref{omp_set_default_device}
323 @item @emph{Reference}:
324 @uref{https://www.openmp.org, OpenMP specification v4.5}, Section 3.2.30.
325 @end table
329 @node omp_get_dynamic
330 @section @code{omp_get_dynamic} -- Dynamic teams setting
331 @table @asis
332 @item @emph{Description}:
333 This function returns @code{true} if enabled, @code{false} otherwise. 
334 Here, @code{true} and @code{false} represent their language-specific 
335 counterparts.
337 The dynamic team setting may be initialized at startup by the 
338 @env{OMP_DYNAMIC} environment variable or at runtime using
339 @code{omp_set_dynamic}.  If undefined, dynamic adjustment is
340 disabled by default.
342 @item @emph{C/C++}:
343 @multitable @columnfractions .20 .80
344 @item @emph{Prototype}: @tab @code{int omp_get_dynamic(void);}
345 @end multitable
347 @item @emph{Fortran}:
348 @multitable @columnfractions .20 .80
349 @item @emph{Interface}: @tab @code{logical function omp_get_dynamic()}
350 @end multitable
352 @item @emph{See also}:
353 @ref{omp_set_dynamic}, @ref{OMP_DYNAMIC}
355 @item @emph{Reference}:
356 @uref{https://www.openmp.org, OpenMP specification v4.5}, Section 3.2.8.
357 @end table
361 @node omp_get_initial_device
362 @section @code{omp_get_initial_device} -- Return device number of initial device
363 @table @asis
364 @item @emph{Description}:
365 This function returns a device number that represents the host device.
366 For OpenMP 5.1, this must be equal to the value returned by the
367 @code{omp_get_num_devices} function.
369 @item @emph{C/C++}
370 @multitable @columnfractions .20 .80
371 @item @emph{Prototype}: @tab @code{int omp_get_initial_device(void);}
372 @end multitable
374 @item @emph{Fortran}:
375 @multitable @columnfractions .20 .80
376 @item @emph{Interface}: @tab @code{integer function omp_get_initial_device()}
377 @end multitable
379 @item @emph{See also}:
380 @ref{omp_get_num_devices}
382 @item @emph{Reference}:
383 @uref{https://www.openmp.org, OpenMP specification v4.5}, Section 3.2.35.
384 @end table
388 @node omp_get_level
389 @section @code{omp_get_level} -- Obtain the current nesting level
390 @table @asis
391 @item @emph{Description}:
392 This function returns the nesting level for the parallel blocks,
393 which enclose the calling call.
395 @item @emph{C/C++}
396 @multitable @columnfractions .20 .80
397 @item @emph{Prototype}: @tab @code{int omp_get_level(void);}
398 @end multitable
400 @item @emph{Fortran}:
401 @multitable @columnfractions .20 .80
402 @item @emph{Interface}: @tab @code{integer function omp_level()}
403 @end multitable
405 @item @emph{See also}:
406 @ref{omp_get_active_level}
408 @item @emph{Reference}:
409 @uref{https://www.openmp.org, OpenMP specification v4.5}, Section 3.2.17.
410 @end table
414 @node omp_get_max_active_levels
415 @section @code{omp_get_max_active_levels} -- Current maximum number of active regions
416 @table @asis
417 @item @emph{Description}:
418 This function obtains the maximum allowed number of nested, active parallel regions.
420 @item @emph{C/C++}
421 @multitable @columnfractions .20 .80
422 @item @emph{Prototype}: @tab @code{int omp_get_max_active_levels(void);}
423 @end multitable
425 @item @emph{Fortran}:
426 @multitable @columnfractions .20 .80
427 @item @emph{Interface}: @tab @code{integer function omp_get_max_active_levels()}
428 @end multitable
430 @item @emph{See also}:
431 @ref{omp_set_max_active_levels}, @ref{omp_get_active_level}
433 @item @emph{Reference}:
434 @uref{https://www.openmp.org, OpenMP specification v4.5}, Section 3.2.16.
435 @end table
438 @node omp_get_max_task_priority
439 @section @code{omp_get_max_task_priority} -- Maximum priority value
440 that can be set for tasks.
441 @table @asis
442 @item @emph{Description}:
443 This function obtains the maximum allowed priority number for tasks.
445 @item @emph{C/C++}
446 @multitable @columnfractions .20 .80
447 @item @emph{Prototype}: @tab @code{int omp_get_max_task_priority(void);}
448 @end multitable
450 @item @emph{Fortran}:
451 @multitable @columnfractions .20 .80
452 @item @emph{Interface}: @tab @code{integer function omp_get_max_task_priority()}
453 @end multitable
455 @item @emph{Reference}:
456 @uref{https://www.openmp.org, OpenMP specification v4.5}, Section 3.2.29.
457 @end table
460 @node omp_get_max_threads
461 @section @code{omp_get_max_threads} -- Maximum number of threads of parallel region
462 @table @asis
463 @item @emph{Description}:
464 Return the maximum number of threads used for the current parallel region
465 that does not use the clause @code{num_threads}.
467 @item @emph{C/C++}:
468 @multitable @columnfractions .20 .80
469 @item @emph{Prototype}: @tab @code{int omp_get_max_threads(void);}
470 @end multitable
472 @item @emph{Fortran}:
473 @multitable @columnfractions .20 .80
474 @item @emph{Interface}: @tab @code{integer function omp_get_max_threads()}
475 @end multitable
477 @item @emph{See also}:
478 @ref{omp_set_num_threads}, @ref{omp_set_dynamic}, @ref{omp_get_thread_limit}
480 @item @emph{Reference}:
481 @uref{https://www.openmp.org, OpenMP specification v4.5}, Section 3.2.3.
482 @end table
486 @node omp_get_nested
487 @section @code{omp_get_nested} -- Nested parallel regions
488 @table @asis
489 @item @emph{Description}:
490 This function returns @code{true} if nested parallel regions are
491 enabled, @code{false} otherwise.  Here, @code{true} and @code{false}
492 represent their language-specific counterparts.
494 The state of nested parallel regions at startup depends on several
495 environment variables.  If @env{OMP_MAX_ACTIVE_LEVELS} is defined
496 and is set to greater than one, then nested parallel regions will be
497 enabled.  If not defined, then the value of the @env{OMP_NESTED}
498 environment variable will be followed if defined.  If neither are
499 defined, then if either @env{OMP_NUM_THREADS} or @env{OMP_PROC_BIND}
500 are defined with a list of more than one value, then nested parallel
501 regions are enabled.  If none of these are defined, then nested parallel
502 regions are disabled by default.
504 Nested parallel regions can be enabled or disabled at runtime using
505 @code{omp_set_nested}, or by setting the maximum number of nested
506 regions with @code{omp_set_max_active_levels} to one to disable, or
507 above one to enable.
509 @item @emph{C/C++}:
510 @multitable @columnfractions .20 .80
511 @item @emph{Prototype}: @tab @code{int omp_get_nested(void);}
512 @end multitable
514 @item @emph{Fortran}:
515 @multitable @columnfractions .20 .80
516 @item @emph{Interface}: @tab @code{logical function omp_get_nested()}
517 @end multitable
519 @item @emph{See also}:
520 @ref{omp_set_max_active_levels}, @ref{omp_set_nested},
521 @ref{OMP_MAX_ACTIVE_LEVELS}, @ref{OMP_NESTED}
523 @item @emph{Reference}:
524 @uref{https://www.openmp.org, OpenMP specification v4.5}, Section 3.2.11.
525 @end table
529 @node omp_get_num_devices
530 @section @code{omp_get_num_devices} -- Number of target devices
531 @table @asis
532 @item @emph{Description}:
533 Returns the number of target devices.
535 @item @emph{C/C++}:
536 @multitable @columnfractions .20 .80
537 @item @emph{Prototype}: @tab @code{int omp_get_num_devices(void);}
538 @end multitable
540 @item @emph{Fortran}:
541 @multitable @columnfractions .20 .80
542 @item @emph{Interface}: @tab @code{integer function omp_get_num_devices()}
543 @end multitable
545 @item @emph{Reference}:
546 @uref{https://www.openmp.org, OpenMP specification v4.5}, Section 3.2.31.
547 @end table
551 @node omp_get_num_procs
552 @section @code{omp_get_num_procs} -- Number of processors online
553 @table @asis
554 @item @emph{Description}:
555 Returns the number of processors online on that device.
557 @item @emph{C/C++}:
558 @multitable @columnfractions .20 .80
559 @item @emph{Prototype}: @tab @code{int omp_get_num_procs(void);}
560 @end multitable
562 @item @emph{Fortran}:
563 @multitable @columnfractions .20 .80
564 @item @emph{Interface}: @tab @code{integer function omp_get_num_procs()}
565 @end multitable
567 @item @emph{Reference}:
568 @uref{https://www.openmp.org, OpenMP specification v4.5}, Section 3.2.5.
569 @end table
573 @node omp_get_num_teams
574 @section @code{omp_get_num_teams} -- Number of teams
575 @table @asis
576 @item @emph{Description}:
577 Returns the number of teams in the current team region.
579 @item @emph{C/C++}:
580 @multitable @columnfractions .20 .80
581 @item @emph{Prototype}: @tab @code{int omp_get_num_teams(void);}
582 @end multitable
584 @item @emph{Fortran}:
585 @multitable @columnfractions .20 .80
586 @item @emph{Interface}: @tab @code{integer function omp_get_num_teams()}
587 @end multitable
589 @item @emph{Reference}:
590 @uref{https://www.openmp.org, OpenMP specification v4.5}, Section 3.2.32.
591 @end table
595 @node omp_get_num_threads
596 @section @code{omp_get_num_threads} -- Size of the active team
597 @table @asis
598 @item @emph{Description}:
599 Returns the number of threads in the current team.  In a sequential section of
600 the program @code{omp_get_num_threads} returns 1.
602 The default team size may be initialized at startup by the 
603 @env{OMP_NUM_THREADS} environment variable.  At runtime, the size
604 of the current team may be set either by the @code{NUM_THREADS}
605 clause or by @code{omp_set_num_threads}.  If none of the above were
606 used to define a specific value and @env{OMP_DYNAMIC} is disabled,
607 one thread per CPU online is used.
609 @item @emph{C/C++}:
610 @multitable @columnfractions .20 .80
611 @item @emph{Prototype}: @tab @code{int omp_get_num_threads(void);}
612 @end multitable
614 @item @emph{Fortran}:
615 @multitable @columnfractions .20 .80
616 @item @emph{Interface}: @tab @code{integer function omp_get_num_threads()}
617 @end multitable
619 @item @emph{See also}:
620 @ref{omp_get_max_threads}, @ref{omp_set_num_threads}, @ref{OMP_NUM_THREADS}
622 @item @emph{Reference}:
623 @uref{https://www.openmp.org, OpenMP specification v4.5}, Section 3.2.2.
624 @end table
628 @node omp_get_proc_bind
629 @section @code{omp_get_proc_bind} -- Whether theads may be moved between CPUs
630 @table @asis
631 @item @emph{Description}:
632 This functions returns the currently active thread affinity policy, which is
633 set via @env{OMP_PROC_BIND}.  Possible values are @code{omp_proc_bind_false},
634 @code{omp_proc_bind_true}, @code{omp_proc_bind_master},
635 @code{omp_proc_bind_close} and @code{omp_proc_bind_spread}.
637 @item @emph{C/C++}:
638 @multitable @columnfractions .20 .80
639 @item @emph{Prototype}: @tab @code{omp_proc_bind_t omp_get_proc_bind(void);}
640 @end multitable
642 @item @emph{Fortran}:
643 @multitable @columnfractions .20 .80
644 @item @emph{Interface}: @tab @code{integer(kind=omp_proc_bind_kind) function omp_get_proc_bind()}
645 @end multitable
647 @item @emph{See also}:
648 @ref{OMP_PROC_BIND}, @ref{OMP_PLACES}, @ref{GOMP_CPU_AFFINITY},
650 @item @emph{Reference}:
651 @uref{https://www.openmp.org, OpenMP specification v4.5}, Section 3.2.22.
652 @end table
656 @node omp_get_schedule
657 @section @code{omp_get_schedule} -- Obtain the runtime scheduling method
658 @table @asis
659 @item @emph{Description}:
660 Obtain the runtime scheduling method.  The @var{kind} argument will be
661 set to the value @code{omp_sched_static}, @code{omp_sched_dynamic},
662 @code{omp_sched_guided} or @code{omp_sched_auto}.  The second argument,
663 @var{chunk_size}, is set to the chunk size.
665 @item @emph{C/C++}
666 @multitable @columnfractions .20 .80
667 @item @emph{Prototype}: @tab @code{void omp_get_schedule(omp_sched_t *kind, int *chunk_size);}
668 @end multitable
670 @item @emph{Fortran}:
671 @multitable @columnfractions .20 .80
672 @item @emph{Interface}: @tab @code{subroutine omp_get_schedule(kind, chunk_size)}
673 @item                   @tab @code{integer(kind=omp_sched_kind) kind}
674 @item                   @tab @code{integer chunk_size}
675 @end multitable
677 @item @emph{See also}:
678 @ref{omp_set_schedule}, @ref{OMP_SCHEDULE}
680 @item @emph{Reference}:
681 @uref{https://www.openmp.org, OpenMP specification v4.5}, Section 3.2.13.
682 @end table
685 @node omp_get_supported_active_levels
686 @section @code{omp_get_supported_active_levels} -- Maximum number of active regions supported
687 @table @asis
688 @item @emph{Description}:
689 This function returns the maximum number of nested, active parallel regions
690 supported by this implementation.
692 @item @emph{C/C++}
693 @multitable @columnfractions .20 .80
694 @item @emph{Prototype}: @tab @code{int omp_get_supported_active_levels(void);}
695 @end multitable
697 @item @emph{Fortran}:
698 @multitable @columnfractions .20 .80
699 @item @emph{Interface}: @tab @code{integer function omp_get_supported_active_levels()}
700 @end multitable
702 @item @emph{See also}:
703 @ref{omp_get_max_active_levels}, @ref{omp_set_max_active_levels}
705 @item @emph{Reference}:
706 @uref{https://www.openmp.org, OpenMP specification v5.0}, Section 3.2.15.
707 @end table
711 @node omp_get_team_num
712 @section @code{omp_get_team_num} -- Get team number
713 @table @asis
714 @item @emph{Description}:
715 Returns the team number of the calling thread.
717 @item @emph{C/C++}:
718 @multitable @columnfractions .20 .80
719 @item @emph{Prototype}: @tab @code{int omp_get_team_num(void);}
720 @end multitable
722 @item @emph{Fortran}:
723 @multitable @columnfractions .20 .80
724 @item @emph{Interface}: @tab @code{integer function omp_get_team_num()}
725 @end multitable
727 @item @emph{Reference}:
728 @uref{https://www.openmp.org, OpenMP specification v4.5}, Section 3.2.33.
729 @end table
733 @node omp_get_team_size
734 @section @code{omp_get_team_size} -- Number of threads in a team
735 @table @asis
736 @item @emph{Description}:
737 This function returns the number of threads in a thread team to which
738 either the current thread or its ancestor belongs.  For values of @var{level}
739 outside zero to @code{omp_get_level}, -1 is returned; if @var{level} is zero,
740 1 is returned, and for @code{omp_get_level}, the result is identical
741 to @code{omp_get_num_threads}.
743 @item @emph{C/C++}:
744 @multitable @columnfractions .20 .80
745 @item @emph{Prototype}: @tab @code{int omp_get_team_size(int level);}
746 @end multitable
748 @item @emph{Fortran}:
749 @multitable @columnfractions .20 .80
750 @item @emph{Interface}: @tab @code{integer function omp_get_team_size(level)}
751 @item                   @tab @code{integer level}
752 @end multitable
754 @item @emph{See also}:
755 @ref{omp_get_num_threads}, @ref{omp_get_level}, @ref{omp_get_ancestor_thread_num}
757 @item @emph{Reference}:
758 @uref{https://www.openmp.org, OpenMP specification v4.5}, Section 3.2.19.
759 @end table
763 @node omp_get_thread_limit
764 @section @code{omp_get_thread_limit} -- Maximum number of threads
765 @table @asis
766 @item @emph{Description}:
767 Return the maximum number of threads of the program.
769 @item @emph{C/C++}:
770 @multitable @columnfractions .20 .80
771 @item @emph{Prototype}: @tab @code{int omp_get_thread_limit(void);}
772 @end multitable
774 @item @emph{Fortran}:
775 @multitable @columnfractions .20 .80
776 @item @emph{Interface}: @tab @code{integer function omp_get_thread_limit()}
777 @end multitable
779 @item @emph{See also}:
780 @ref{omp_get_max_threads}, @ref{OMP_THREAD_LIMIT}
782 @item @emph{Reference}:
783 @uref{https://www.openmp.org, OpenMP specification v4.5}, Section 3.2.14.
784 @end table
788 @node omp_get_thread_num
789 @section @code{omp_get_thread_num} -- Current thread ID
790 @table @asis
791 @item @emph{Description}:
792 Returns a unique thread identification number within the current team.
793 In a sequential parts of the program, @code{omp_get_thread_num}
794 always returns 0.  In parallel regions the return value varies
795 from 0 to @code{omp_get_num_threads}-1 inclusive.  The return
796 value of the master thread of a team is always 0.
798 @item @emph{C/C++}:
799 @multitable @columnfractions .20 .80
800 @item @emph{Prototype}: @tab @code{int omp_get_thread_num(void);}
801 @end multitable
803 @item @emph{Fortran}:
804 @multitable @columnfractions .20 .80
805 @item @emph{Interface}: @tab @code{integer function omp_get_thread_num()}
806 @end multitable
808 @item @emph{See also}:
809 @ref{omp_get_num_threads}, @ref{omp_get_ancestor_thread_num}
811 @item @emph{Reference}:
812 @uref{https://www.openmp.org, OpenMP specification v4.5}, Section 3.2.4.
813 @end table
817 @node omp_in_parallel
818 @section @code{omp_in_parallel} -- Whether a parallel region is active
819 @table @asis
820 @item @emph{Description}:
821 This function returns @code{true} if currently running in parallel,
822 @code{false} otherwise.  Here, @code{true} and @code{false} represent
823 their language-specific counterparts.
825 @item @emph{C/C++}:
826 @multitable @columnfractions .20 .80
827 @item @emph{Prototype}: @tab @code{int omp_in_parallel(void);}
828 @end multitable
830 @item @emph{Fortran}:
831 @multitable @columnfractions .20 .80
832 @item @emph{Interface}: @tab @code{logical function omp_in_parallel()}
833 @end multitable
835 @item @emph{Reference}:
836 @uref{https://www.openmp.org, OpenMP specification v4.5}, Section 3.2.6.
837 @end table
840 @node omp_in_final
841 @section @code{omp_in_final} -- Whether in final or included task region
842 @table @asis
843 @item @emph{Description}:
844 This function returns @code{true} if currently running in a final
845 or included task region, @code{false} otherwise.  Here, @code{true}
846 and @code{false} represent their language-specific counterparts.
848 @item @emph{C/C++}:
849 @multitable @columnfractions .20 .80
850 @item @emph{Prototype}: @tab @code{int omp_in_final(void);}
851 @end multitable
853 @item @emph{Fortran}:
854 @multitable @columnfractions .20 .80
855 @item @emph{Interface}: @tab @code{logical function omp_in_final()}
856 @end multitable
858 @item @emph{Reference}:
859 @uref{https://www.openmp.org, OpenMP specification v4.5}, Section 3.2.21.
860 @end table
864 @node omp_is_initial_device
865 @section @code{omp_is_initial_device} -- Whether executing on the host device
866 @table @asis
867 @item @emph{Description}:
868 This function returns @code{true} if currently running on the host device,
869 @code{false} otherwise.  Here, @code{true} and @code{false} represent
870 their language-specific counterparts.
872 @item @emph{C/C++}:
873 @multitable @columnfractions .20 .80
874 @item @emph{Prototype}: @tab @code{int omp_is_initial_device(void);}
875 @end multitable
877 @item @emph{Fortran}:
878 @multitable @columnfractions .20 .80
879 @item @emph{Interface}: @tab @code{logical function omp_is_initial_device()}
880 @end multitable
882 @item @emph{Reference}:
883 @uref{https://www.openmp.org, OpenMP specification v4.5}, Section 3.2.34.
884 @end table
888 @node omp_set_default_device
889 @section @code{omp_set_default_device} -- Set the default device for target regions
890 @table @asis
891 @item @emph{Description}:
892 Set the default device for target regions without device clause.  The argument
893 shall be a nonnegative device number.
895 @item @emph{C/C++}:
896 @multitable @columnfractions .20 .80
897 @item @emph{Prototype}: @tab @code{void omp_set_default_device(int device_num);}
898 @end multitable
900 @item @emph{Fortran}:
901 @multitable @columnfractions .20 .80
902 @item @emph{Interface}: @tab @code{subroutine omp_set_default_device(device_num)}
903 @item                   @tab @code{integer device_num}
904 @end multitable
906 @item @emph{See also}:
907 @ref{OMP_DEFAULT_DEVICE}, @ref{omp_get_default_device}
909 @item @emph{Reference}:
910 @uref{https://www.openmp.org, OpenMP specification v4.5}, Section 3.2.29.
911 @end table
915 @node omp_set_dynamic
916 @section @code{omp_set_dynamic} -- Enable/disable dynamic teams
917 @table @asis
918 @item @emph{Description}:
919 Enable or disable the dynamic adjustment of the number of threads 
920 within a team.  The function takes the language-specific equivalent
921 of @code{true} and @code{false}, where @code{true} enables dynamic 
922 adjustment of team sizes and @code{false} disables it.
924 @item @emph{C/C++}:
925 @multitable @columnfractions .20 .80
926 @item @emph{Prototype}: @tab @code{void omp_set_dynamic(int dynamic_threads);}
927 @end multitable
929 @item @emph{Fortran}:
930 @multitable @columnfractions .20 .80
931 @item @emph{Interface}: @tab @code{subroutine omp_set_dynamic(dynamic_threads)}
932 @item                   @tab @code{logical, intent(in) :: dynamic_threads}
933 @end multitable
935 @item @emph{See also}:
936 @ref{OMP_DYNAMIC}, @ref{omp_get_dynamic}
938 @item @emph{Reference}:
939 @uref{https://www.openmp.org, OpenMP specification v4.5}, Section 3.2.7.
940 @end table
944 @node omp_set_max_active_levels
945 @section @code{omp_set_max_active_levels} -- Limits the number of active parallel regions
946 @table @asis
947 @item @emph{Description}:
948 This function limits the maximum allowed number of nested, active
949 parallel regions.  @var{max_levels} must be less or equal to
950 the value returned by @code{omp_get_supported_active_levels}.
952 @item @emph{C/C++}
953 @multitable @columnfractions .20 .80
954 @item @emph{Prototype}: @tab @code{void omp_set_max_active_levels(int max_levels);}
955 @end multitable
957 @item @emph{Fortran}:
958 @multitable @columnfractions .20 .80
959 @item @emph{Interface}: @tab @code{subroutine omp_set_max_active_levels(max_levels)}
960 @item                   @tab @code{integer max_levels}
961 @end multitable
963 @item @emph{See also}:
964 @ref{omp_get_max_active_levels}, @ref{omp_get_active_level},
965 @ref{omp_get_supported_active_levels}
967 @item @emph{Reference}:
968 @uref{https://www.openmp.org, OpenMP specification v4.5}, Section 3.2.15.
969 @end table
973 @node omp_set_nested
974 @section @code{omp_set_nested} -- Enable/disable nested parallel regions
975 @table @asis
976 @item @emph{Description}:
977 Enable or disable nested parallel regions, i.e., whether team members
978 are allowed to create new teams.  The function takes the language-specific
979 equivalent of @code{true} and @code{false}, where @code{true} enables 
980 dynamic adjustment of team sizes and @code{false} disables it.
982 Enabling nested parallel regions will also set the maximum number of
983 active nested regions to the maximum supported.  Disabling nested parallel
984 regions will set the maximum number of active nested regions to one.
986 @item @emph{C/C++}:
987 @multitable @columnfractions .20 .80
988 @item @emph{Prototype}: @tab @code{void omp_set_nested(int nested);}
989 @end multitable
991 @item @emph{Fortran}:
992 @multitable @columnfractions .20 .80
993 @item @emph{Interface}: @tab @code{subroutine omp_set_nested(nested)}
994 @item                   @tab @code{logical, intent(in) :: nested}
995 @end multitable
997 @item @emph{See also}:
998 @ref{omp_get_nested}, @ref{omp_set_max_active_levels},
999 @ref{OMP_MAX_ACTIVE_LEVELS}, @ref{OMP_NESTED}
1001 @item @emph{Reference}:
1002 @uref{https://www.openmp.org, OpenMP specification v4.5}, Section 3.2.10.
1003 @end table
1007 @node omp_set_num_threads
1008 @section @code{omp_set_num_threads} -- Set upper team size limit
1009 @table @asis
1010 @item @emph{Description}:
1011 Specifies the number of threads used by default in subsequent parallel 
1012 sections, if those do not specify a @code{num_threads} clause.  The
1013 argument of @code{omp_set_num_threads} shall be a positive integer.
1015 @item @emph{C/C++}:
1016 @multitable @columnfractions .20 .80
1017 @item @emph{Prototype}: @tab @code{void omp_set_num_threads(int num_threads);}
1018 @end multitable
1020 @item @emph{Fortran}:
1021 @multitable @columnfractions .20 .80
1022 @item @emph{Interface}: @tab @code{subroutine omp_set_num_threads(num_threads)}
1023 @item                   @tab @code{integer, intent(in) :: num_threads}
1024 @end multitable
1026 @item @emph{See also}:
1027 @ref{OMP_NUM_THREADS}, @ref{omp_get_num_threads}, @ref{omp_get_max_threads}
1029 @item @emph{Reference}:
1030 @uref{https://www.openmp.org, OpenMP specification v4.5}, Section 3.2.1.
1031 @end table
1035 @node omp_set_schedule
1036 @section @code{omp_set_schedule} -- Set the runtime scheduling method
1037 @table @asis
1038 @item @emph{Description}:
1039 Sets the runtime scheduling method.  The @var{kind} argument can have the
1040 value @code{omp_sched_static}, @code{omp_sched_dynamic},
1041 @code{omp_sched_guided} or @code{omp_sched_auto}.  Except for
1042 @code{omp_sched_auto}, the chunk size is set to the value of
1043 @var{chunk_size} if positive, or to the default value if zero or negative.
1044 For @code{omp_sched_auto} the @var{chunk_size} argument is ignored.
1046 @item @emph{C/C++}
1047 @multitable @columnfractions .20 .80
1048 @item @emph{Prototype}: @tab @code{void omp_set_schedule(omp_sched_t kind, int chunk_size);}
1049 @end multitable
1051 @item @emph{Fortran}:
1052 @multitable @columnfractions .20 .80
1053 @item @emph{Interface}: @tab @code{subroutine omp_set_schedule(kind, chunk_size)}
1054 @item                   @tab @code{integer(kind=omp_sched_kind) kind}
1055 @item                   @tab @code{integer chunk_size}
1056 @end multitable
1058 @item @emph{See also}:
1059 @ref{omp_get_schedule}
1060 @ref{OMP_SCHEDULE}
1062 @item @emph{Reference}:
1063 @uref{https://www.openmp.org, OpenMP specification v4.5}, Section 3.2.12.
1064 @end table
1068 @node omp_init_lock
1069 @section @code{omp_init_lock} -- Initialize simple lock
1070 @table @asis
1071 @item @emph{Description}:
1072 Initialize a simple lock.  After initialization, the lock is in
1073 an unlocked state.
1075 @item @emph{C/C++}:
1076 @multitable @columnfractions .20 .80
1077 @item @emph{Prototype}: @tab @code{void omp_init_lock(omp_lock_t *lock);}
1078 @end multitable
1080 @item @emph{Fortran}:
1081 @multitable @columnfractions .20 .80
1082 @item @emph{Interface}: @tab @code{subroutine omp_init_lock(svar)}
1083 @item                   @tab @code{integer(omp_lock_kind), intent(out) :: svar}
1084 @end multitable
1086 @item @emph{See also}:
1087 @ref{omp_destroy_lock}
1089 @item @emph{Reference}: 
1090 @uref{https://www.openmp.org, OpenMP specification v4.5}, Section 3.3.1.
1091 @end table
1095 @node omp_set_lock
1096 @section @code{omp_set_lock} -- Wait for and set simple lock
1097 @table @asis
1098 @item @emph{Description}:
1099 Before setting a simple lock, the lock variable must be initialized by 
1100 @code{omp_init_lock}.  The calling thread is blocked until the lock 
1101 is available.  If the lock is already held by the current thread, 
1102 a deadlock occurs.
1104 @item @emph{C/C++}:
1105 @multitable @columnfractions .20 .80
1106 @item @emph{Prototype}: @tab @code{void omp_set_lock(omp_lock_t *lock);}
1107 @end multitable
1109 @item @emph{Fortran}:
1110 @multitable @columnfractions .20 .80
1111 @item @emph{Interface}: @tab @code{subroutine omp_set_lock(svar)}
1112 @item                   @tab @code{integer(omp_lock_kind), intent(inout) :: svar}
1113 @end multitable
1115 @item @emph{See also}:
1116 @ref{omp_init_lock}, @ref{omp_test_lock}, @ref{omp_unset_lock}
1118 @item @emph{Reference}: 
1119 @uref{https://www.openmp.org, OpenMP specification v4.5}, Section 3.3.4.
1120 @end table
1124 @node omp_test_lock
1125 @section @code{omp_test_lock} -- Test and set simple lock if available
1126 @table @asis
1127 @item @emph{Description}:
1128 Before setting a simple lock, the lock variable must be initialized by 
1129 @code{omp_init_lock}.  Contrary to @code{omp_set_lock}, @code{omp_test_lock} 
1130 does not block if the lock is not available.  This function returns
1131 @code{true} upon success, @code{false} otherwise.  Here, @code{true} and
1132 @code{false} represent their language-specific counterparts.
1134 @item @emph{C/C++}:
1135 @multitable @columnfractions .20 .80
1136 @item @emph{Prototype}: @tab @code{int omp_test_lock(omp_lock_t *lock);}
1137 @end multitable
1139 @item @emph{Fortran}:
1140 @multitable @columnfractions .20 .80
1141 @item @emph{Interface}: @tab @code{logical function omp_test_lock(svar)}
1142 @item                   @tab @code{integer(omp_lock_kind), intent(inout) :: svar}
1143 @end multitable
1145 @item @emph{See also}:
1146 @ref{omp_init_lock}, @ref{omp_set_lock}, @ref{omp_set_lock}
1148 @item @emph{Reference}: 
1149 @uref{https://www.openmp.org, OpenMP specification v4.5}, Section 3.3.6.
1150 @end table
1154 @node omp_unset_lock
1155 @section @code{omp_unset_lock} -- Unset simple lock
1156 @table @asis
1157 @item @emph{Description}:
1158 A simple lock about to be unset must have been locked by @code{omp_set_lock}
1159 or @code{omp_test_lock} before.  In addition, the lock must be held by the
1160 thread calling @code{omp_unset_lock}.  Then, the lock becomes unlocked.  If one
1161 or more threads attempted to set the lock before, one of them is chosen to,
1162 again, set the lock to itself.
1164 @item @emph{C/C++}:
1165 @multitable @columnfractions .20 .80
1166 @item @emph{Prototype}: @tab @code{void omp_unset_lock(omp_lock_t *lock);}
1167 @end multitable
1169 @item @emph{Fortran}:
1170 @multitable @columnfractions .20 .80
1171 @item @emph{Interface}: @tab @code{subroutine omp_unset_lock(svar)}
1172 @item                   @tab @code{integer(omp_lock_kind), intent(inout) :: svar}
1173 @end multitable
1175 @item @emph{See also}:
1176 @ref{omp_set_lock}, @ref{omp_test_lock}
1178 @item @emph{Reference}: 
1179 @uref{https://www.openmp.org, OpenMP specification v4.5}, Section 3.3.5.
1180 @end table
1184 @node omp_destroy_lock
1185 @section @code{omp_destroy_lock} -- Destroy simple lock
1186 @table @asis
1187 @item @emph{Description}:
1188 Destroy a simple lock.  In order to be destroyed, a simple lock must be
1189 in the unlocked state. 
1191 @item @emph{C/C++}:
1192 @multitable @columnfractions .20 .80
1193 @item @emph{Prototype}: @tab @code{void omp_destroy_lock(omp_lock_t *lock);}
1194 @end multitable
1196 @item @emph{Fortran}:
1197 @multitable @columnfractions .20 .80
1198 @item @emph{Interface}: @tab @code{subroutine omp_destroy_lock(svar)}
1199 @item                   @tab @code{integer(omp_lock_kind), intent(inout) :: svar}
1200 @end multitable
1202 @item @emph{See also}:
1203 @ref{omp_init_lock}
1205 @item @emph{Reference}: 
1206 @uref{https://www.openmp.org, OpenMP specification v4.5}, Section 3.3.3.
1207 @end table
1211 @node omp_init_nest_lock
1212 @section @code{omp_init_nest_lock} -- Initialize nested lock
1213 @table @asis
1214 @item @emph{Description}:
1215 Initialize a nested lock.  After initialization, the lock is in
1216 an unlocked state and the nesting count is set to zero.
1218 @item @emph{C/C++}:
1219 @multitable @columnfractions .20 .80
1220 @item @emph{Prototype}: @tab @code{void omp_init_nest_lock(omp_nest_lock_t *lock);}
1221 @end multitable
1223 @item @emph{Fortran}:
1224 @multitable @columnfractions .20 .80
1225 @item @emph{Interface}: @tab @code{subroutine omp_init_nest_lock(nvar)}
1226 @item                   @tab @code{integer(omp_nest_lock_kind), intent(out) :: nvar}
1227 @end multitable
1229 @item @emph{See also}:
1230 @ref{omp_destroy_nest_lock}
1232 @item @emph{Reference}:
1233 @uref{https://www.openmp.org, OpenMP specification v4.5}, Section 3.3.1.
1234 @end table
1237 @node omp_set_nest_lock
1238 @section @code{omp_set_nest_lock} -- Wait for and set nested lock
1239 @table @asis
1240 @item @emph{Description}:
1241 Before setting a nested lock, the lock variable must be initialized by 
1242 @code{omp_init_nest_lock}.  The calling thread is blocked until the lock
1243 is available.  If the lock is already held by the current thread, the
1244 nesting count for the lock is incremented.
1246 @item @emph{C/C++}:
1247 @multitable @columnfractions .20 .80
1248 @item @emph{Prototype}: @tab @code{void omp_set_nest_lock(omp_nest_lock_t *lock);}
1249 @end multitable
1251 @item @emph{Fortran}:
1252 @multitable @columnfractions .20 .80
1253 @item @emph{Interface}: @tab @code{subroutine omp_set_nest_lock(nvar)}
1254 @item                   @tab @code{integer(omp_nest_lock_kind), intent(inout) :: nvar}
1255 @end multitable
1257 @item @emph{See also}:
1258 @ref{omp_init_nest_lock}, @ref{omp_unset_nest_lock}
1260 @item @emph{Reference}: 
1261 @uref{https://www.openmp.org, OpenMP specification v4.5}, Section 3.3.4.
1262 @end table
1266 @node omp_test_nest_lock
1267 @section @code{omp_test_nest_lock} -- Test and set nested lock if available
1268 @table @asis
1269 @item @emph{Description}:
1270 Before setting a nested lock, the lock variable must be initialized by 
1271 @code{omp_init_nest_lock}.  Contrary to @code{omp_set_nest_lock},
1272 @code{omp_test_nest_lock} does not block if the lock is not available. 
1273 If the lock is already held by the current thread, the new nesting count 
1274 is returned.  Otherwise, the return value equals zero.
1276 @item @emph{C/C++}:
1277 @multitable @columnfractions .20 .80
1278 @item @emph{Prototype}: @tab @code{int omp_test_nest_lock(omp_nest_lock_t *lock);}
1279 @end multitable
1281 @item @emph{Fortran}:
1282 @multitable @columnfractions .20 .80
1283 @item @emph{Interface}: @tab @code{logical function omp_test_nest_lock(nvar)}
1284 @item                   @tab @code{integer(omp_nest_lock_kind), intent(inout) :: nvar}
1285 @end multitable
1288 @item @emph{See also}:
1289 @ref{omp_init_lock}, @ref{omp_set_lock}, @ref{omp_set_lock}
1291 @item @emph{Reference}: 
1292 @uref{https://www.openmp.org, OpenMP specification v4.5}, Section 3.3.6.
1293 @end table
1297 @node omp_unset_nest_lock
1298 @section @code{omp_unset_nest_lock} -- Unset nested lock
1299 @table @asis
1300 @item @emph{Description}:
1301 A nested lock about to be unset must have been locked by @code{omp_set_nested_lock}
1302 or @code{omp_test_nested_lock} before.  In addition, the lock must be held by the
1303 thread calling @code{omp_unset_nested_lock}.  If the nesting count drops to zero, the
1304 lock becomes unlocked.  If one ore more threads attempted to set the lock before,
1305 one of them is chosen to, again, set the lock to itself.
1307 @item @emph{C/C++}:
1308 @multitable @columnfractions .20 .80
1309 @item @emph{Prototype}: @tab @code{void omp_unset_nest_lock(omp_nest_lock_t *lock);}
1310 @end multitable
1312 @item @emph{Fortran}:
1313 @multitable @columnfractions .20 .80
1314 @item @emph{Interface}: @tab @code{subroutine omp_unset_nest_lock(nvar)}
1315 @item                   @tab @code{integer(omp_nest_lock_kind), intent(inout) :: nvar}
1316 @end multitable
1318 @item @emph{See also}:
1319 @ref{omp_set_nest_lock}
1321 @item @emph{Reference}: 
1322 @uref{https://www.openmp.org, OpenMP specification v4.5}, Section 3.3.5.
1323 @end table
1327 @node omp_destroy_nest_lock
1328 @section @code{omp_destroy_nest_lock} -- Destroy nested lock
1329 @table @asis
1330 @item @emph{Description}:
1331 Destroy a nested lock.  In order to be destroyed, a nested lock must be
1332 in the unlocked state and its nesting count must equal zero.
1334 @item @emph{C/C++}:
1335 @multitable @columnfractions .20 .80
1336 @item @emph{Prototype}: @tab @code{void omp_destroy_nest_lock(omp_nest_lock_t *);}
1337 @end multitable
1339 @item @emph{Fortran}:
1340 @multitable @columnfractions .20 .80
1341 @item @emph{Interface}: @tab @code{subroutine omp_destroy_nest_lock(nvar)}
1342 @item                   @tab @code{integer(omp_nest_lock_kind), intent(inout) :: nvar}
1343 @end multitable
1345 @item @emph{See also}:
1346 @ref{omp_init_lock}
1348 @item @emph{Reference}: 
1349 @uref{https://www.openmp.org, OpenMP specification v4.5}, Section 3.3.3.
1350 @end table
1354 @node omp_get_wtick
1355 @section @code{omp_get_wtick} -- Get timer precision
1356 @table @asis
1357 @item @emph{Description}:
1358 Gets the timer precision, i.e., the number of seconds between two 
1359 successive clock ticks.
1361 @item @emph{C/C++}:
1362 @multitable @columnfractions .20 .80
1363 @item @emph{Prototype}: @tab @code{double omp_get_wtick(void);}
1364 @end multitable
1366 @item @emph{Fortran}:
1367 @multitable @columnfractions .20 .80
1368 @item @emph{Interface}: @tab @code{double precision function omp_get_wtick()}
1369 @end multitable
1371 @item @emph{See also}:
1372 @ref{omp_get_wtime}
1374 @item @emph{Reference}: 
1375 @uref{https://www.openmp.org, OpenMP specification v4.5}, Section 3.4.2.
1376 @end table
1380 @node omp_get_wtime
1381 @section @code{omp_get_wtime} -- Elapsed wall clock time
1382 @table @asis
1383 @item @emph{Description}:
1384 Elapsed wall clock time in seconds.  The time is measured per thread, no
1385 guarantee can be made that two distinct threads measure the same time.
1386 Time is measured from some "time in the past", which is an arbitrary time
1387 guaranteed not to change during the execution of the program.
1389 @item @emph{C/C++}:
1390 @multitable @columnfractions .20 .80
1391 @item @emph{Prototype}: @tab @code{double omp_get_wtime(void);}
1392 @end multitable
1394 @item @emph{Fortran}:
1395 @multitable @columnfractions .20 .80
1396 @item @emph{Interface}: @tab @code{double precision function omp_get_wtime()}
1397 @end multitable
1399 @item @emph{See also}:
1400 @ref{omp_get_wtick}
1402 @item @emph{Reference}: 
1403 @uref{https://www.openmp.org, OpenMP specification v4.5}, Section 3.4.1.
1404 @end table
1408 @node omp_fulfill_event
1409 @section @code{omp_fulfill_event} -- Fulfill and destroy an OpenMP event
1410 @table @asis
1411 @item @emph{Description}:
1412 Fulfill the event associated with the event handle argument.  Currently, it
1413 is only used to fulfill events generated by detach clauses on task
1414 constructs - the effect of fulfilling the event is to allow the task to
1415 complete.
1417 The result of calling @code{omp_fulfill_event} with an event handle other
1418 than that generated by a detach clause is undefined.  Calling it with an
1419 event handle that has already been fulfilled is also undefined.
1421 @item @emph{C/C++}:
1422 @multitable @columnfractions .20 .80
1423 @item @emph{Prototype}: @tab @code{void omp_fulfill_event(omp_event_handle_t event);}
1424 @end multitable
1426 @item @emph{Fortran}:
1427 @multitable @columnfractions .20 .80
1428 @item @emph{Interface}: @tab @code{subroutine omp_fulfill_event(event)}
1429 @item                   @tab @code{integer (kind=omp_event_handle_kind) :: event}
1430 @end multitable
1432 @item @emph{Reference}:
1433 @uref{https://www.openmp.org, OpenMP specification v5.0}, Section 3.5.1.
1434 @end table
1438 @c ---------------------------------------------------------------------
1439 @c OpenMP Environment Variables
1440 @c ---------------------------------------------------------------------
1442 @node Environment Variables
1443 @chapter OpenMP Environment Variables
1445 The environment variables which beginning with @env{OMP_} are defined by
1446 section 4 of the OpenMP specification in version 4.5, while those
1447 beginning with @env{GOMP_} are GNU extensions.
1449 @menu
1450 * OMP_CANCELLATION::        Set whether cancellation is activated
1451 * OMP_DISPLAY_ENV::         Show OpenMP version and environment variables
1452 * OMP_DEFAULT_DEVICE::      Set the device used in target regions
1453 * OMP_DYNAMIC::             Dynamic adjustment of threads
1454 * OMP_MAX_ACTIVE_LEVELS::   Set the maximum number of nested parallel regions
1455 * OMP_MAX_TASK_PRIORITY::   Set the maximum task priority value
1456 * OMP_NESTED::              Nested parallel regions
1457 * OMP_NUM_THREADS::         Specifies the number of threads to use
1458 * OMP_PROC_BIND::           Whether theads may be moved between CPUs
1459 * OMP_PLACES::              Specifies on which CPUs the theads should be placed
1460 * OMP_STACKSIZE::           Set default thread stack size
1461 * OMP_SCHEDULE::            How threads are scheduled
1462 * OMP_TARGET_OFFLOAD::      Controls offloading behaviour
1463 * OMP_THREAD_LIMIT::        Set the maximum number of threads
1464 * OMP_WAIT_POLICY::         How waiting threads are handled
1465 * GOMP_CPU_AFFINITY::       Bind threads to specific CPUs
1466 * GOMP_DEBUG::              Enable debugging output
1467 * GOMP_STACKSIZE::          Set default thread stack size
1468 * GOMP_SPINCOUNT::          Set the busy-wait spin count
1469 * GOMP_RTEMS_THREAD_POOLS:: Set the RTEMS specific thread pools
1470 @end menu
1473 @node OMP_CANCELLATION
1474 @section @env{OMP_CANCELLATION} -- Set whether cancellation is activated
1475 @cindex Environment Variable
1476 @table @asis
1477 @item @emph{Description}:
1478 If set to @code{TRUE}, the cancellation is activated.  If set to @code{FALSE} or
1479 if unset, cancellation is disabled and the @code{cancel} construct is ignored.
1481 @item @emph{See also}:
1482 @ref{omp_get_cancellation}
1484 @item @emph{Reference}:
1485 @uref{https://www.openmp.org, OpenMP specification v4.5}, Section 4.11
1486 @end table
1490 @node OMP_DISPLAY_ENV
1491 @section @env{OMP_DISPLAY_ENV} -- Show OpenMP version and environment variables
1492 @cindex Environment Variable
1493 @table @asis
1494 @item @emph{Description}:
1495 If set to @code{TRUE}, the OpenMP version number and the values
1496 associated with the OpenMP environment variables are printed to @code{stderr}.
1497 If set to @code{VERBOSE}, it additionally shows the value of the environment
1498 variables which are GNU extensions.  If undefined or set to @code{FALSE},
1499 this information will not be shown.
1502 @item @emph{Reference}:
1503 @uref{https://www.openmp.org, OpenMP specification v4.5}, Section 4.12
1504 @end table
1508 @node OMP_DEFAULT_DEVICE
1509 @section @env{OMP_DEFAULT_DEVICE} -- Set the device used in target regions
1510 @cindex Environment Variable
1511 @table @asis
1512 @item @emph{Description}:
1513 Set to choose the device which is used in a @code{target} region, unless the
1514 value is overridden by @code{omp_set_default_device} or by a @code{device}
1515 clause.  The value shall be the nonnegative device number. If no device with
1516 the given device number exists, the code is executed on the host.  If unset,
1517 device number 0 will be used.
1520 @item @emph{See also}:
1521 @ref{omp_get_default_device}, @ref{omp_set_default_device},
1523 @item @emph{Reference}:
1524 @uref{https://www.openmp.org, OpenMP specification v4.5}, Section 4.13
1525 @end table
1529 @node OMP_DYNAMIC
1530 @section @env{OMP_DYNAMIC} -- Dynamic adjustment of threads
1531 @cindex Environment Variable
1532 @table @asis
1533 @item @emph{Description}:
1534 Enable or disable the dynamic adjustment of the number of threads 
1535 within a team.  The value of this environment variable shall be 
1536 @code{TRUE} or @code{FALSE}.  If undefined, dynamic adjustment is
1537 disabled by default.
1539 @item @emph{See also}:
1540 @ref{omp_set_dynamic}
1542 @item @emph{Reference}: 
1543 @uref{https://www.openmp.org, OpenMP specification v4.5}, Section 4.3
1544 @end table
1548 @node OMP_MAX_ACTIVE_LEVELS
1549 @section @env{OMP_MAX_ACTIVE_LEVELS} -- Set the maximum number of nested parallel regions
1550 @cindex Environment Variable
1551 @table @asis
1552 @item @emph{Description}:
1553 Specifies the initial value for the maximum number of nested parallel
1554 regions.  The value of this variable shall be a positive integer.
1555 If undefined, then if @env{OMP_NESTED} is defined and set to true, or
1556 if @env{OMP_NUM_THREADS} or @env{OMP_PROC_BIND} are defined and set to
1557 a list with more than one item, the maximum number of nested parallel
1558 regions will be initialized to the largest number supported, otherwise
1559 it will be set to one.
1561 @item @emph{See also}:
1562 @ref{omp_set_max_active_levels}, @ref{OMP_NESTED}
1564 @item @emph{Reference}: 
1565 @uref{https://www.openmp.org, OpenMP specification v4.5}, Section 4.9
1566 @end table
1570 @node OMP_MAX_TASK_PRIORITY
1571 @section @env{OMP_MAX_TASK_PRIORITY} -- Set the maximum priority
1572 number that can be set for a task.
1573 @cindex Environment Variable
1574 @table @asis
1575 @item @emph{Description}:
1576 Specifies the initial value for the maximum priority value that can be
1577 set for a task.  The value of this variable shall be a non-negative
1578 integer, and zero is allowed.  If undefined, the default priority is
1581 @item @emph{See also}:
1582 @ref{omp_get_max_task_priority}
1584 @item @emph{Reference}: 
1585 @uref{https://www.openmp.org, OpenMP specification v4.5}, Section 4.14
1586 @end table
1590 @node OMP_NESTED
1591 @section @env{OMP_NESTED} -- Nested parallel regions
1592 @cindex Environment Variable
1593 @cindex Implementation specific setting
1594 @table @asis
1595 @item @emph{Description}:
1596 Enable or disable nested parallel regions, i.e., whether team members
1597 are allowed to create new teams.  The value of this environment variable 
1598 shall be @code{TRUE} or @code{FALSE}.  If set to @code{TRUE}, the number
1599 of maximum active nested regions supported will by default be set to the
1600 maximum supported, otherwise it will be set to one.  If
1601 @env{OMP_MAX_ACTIVE_LEVELS} is defined, its setting will override this
1602 setting.  If both are undefined, nested parallel regions are enabled if
1603 @env{OMP_NUM_THREADS} or @env{OMP_PROC_BINDS} are defined to a list with
1604 more than one item, otherwise they are disabled by default.
1606 @item @emph{See also}:
1607 @ref{omp_set_max_active_levels}, @ref{omp_set_nested}
1609 @item @emph{Reference}: 
1610 @uref{https://www.openmp.org, OpenMP specification v4.5}, Section 4.6
1611 @end table
1615 @node OMP_NUM_THREADS
1616 @section @env{OMP_NUM_THREADS} -- Specifies the number of threads to use
1617 @cindex Environment Variable
1618 @cindex Implementation specific setting
1619 @table @asis
1620 @item @emph{Description}:
1621 Specifies the default number of threads to use in parallel regions.  The 
1622 value of this variable shall be a comma-separated list of positive integers;
1623 the value specifies the number of threads to use for the corresponding nested
1624 level.  Specifying more than one item in the list will automatically enable
1625 nesting by default.  If undefined one thread per CPU is used.
1627 @item @emph{See also}:
1628 @ref{omp_set_num_threads}, @ref{OMP_NESTED}
1630 @item @emph{Reference}: 
1631 @uref{https://www.openmp.org, OpenMP specification v4.5}, Section 4.2
1632 @end table
1636 @node OMP_PROC_BIND
1637 @section @env{OMP_PROC_BIND} -- Whether theads may be moved between CPUs
1638 @cindex Environment Variable
1639 @table @asis
1640 @item @emph{Description}:
1641 Specifies whether threads may be moved between processors.  If set to
1642 @code{TRUE}, OpenMP theads should not be moved; if set to @code{FALSE}
1643 they may be moved.  Alternatively, a comma separated list with the
1644 values @code{MASTER}, @code{CLOSE} and @code{SPREAD} can be used to specify
1645 the thread affinity policy for the corresponding nesting level.  With
1646 @code{MASTER} the worker threads are in the same place partition as the
1647 master thread.  With @code{CLOSE} those are kept close to the master thread
1648 in contiguous place partitions.  And with @code{SPREAD} a sparse distribution
1649 across the place partitions is used.  Specifying more than one item in the
1650 list will automatically enable nesting by default.
1652 When undefined, @env{OMP_PROC_BIND} defaults to @code{TRUE} when
1653 @env{OMP_PLACES} or @env{GOMP_CPU_AFFINITY} is set and @code{FALSE} otherwise.
1655 @item @emph{See also}:
1656 @ref{omp_get_proc_bind}, @ref{GOMP_CPU_AFFINITY},
1657 @ref{OMP_NESTED}, @ref{OMP_PLACES}
1659 @item @emph{Reference}:
1660 @uref{https://www.openmp.org, OpenMP specification v4.5}, Section 4.4
1661 @end table
1665 @node OMP_PLACES
1666 @section @env{OMP_PLACES} -- Specifies on which CPUs the theads should be placed
1667 @cindex Environment Variable
1668 @table @asis
1669 @item @emph{Description}:
1670 The thread placement can be either specified using an abstract name or by an
1671 explicit list of the places.  The abstract names @code{threads}, @code{cores}
1672 and @code{sockets} can be optionally followed by a positive number in
1673 parentheses, which denotes the how many places shall be created.  With
1674 @code{threads} each place corresponds to a single hardware thread; @code{cores}
1675 to a single core with the corresponding number of hardware threads; and with
1676 @code{sockets} the place corresponds to a single socket.  The resulting
1677 placement can be shown by setting the @env{OMP_DISPLAY_ENV} environment
1678 variable.
1680 Alternatively, the placement can be specified explicitly as comma-separated
1681 list of places.  A place is specified by set of nonnegative numbers in curly
1682 braces, denoting the denoting the hardware threads.  The hardware threads
1683 belonging to a place can either be specified as comma-separated list of
1684 nonnegative thread numbers or using an interval.  Multiple places can also be
1685 either specified by a comma-separated list of places or by an interval.  To
1686 specify an interval, a colon followed by the count is placed after after
1687 the hardware thread number or the place.  Optionally, the length can be
1688 followed by a colon and the stride number -- otherwise a unit stride is
1689 assumed.  For instance, the following specifies the same places list:
1690 @code{"@{0,1,2@}, @{3,4,6@}, @{7,8,9@}, @{10,11,12@}"};
1691 @code{"@{0:3@}, @{3:3@}, @{7:3@}, @{10:3@}"}; and @code{"@{0:2@}:4:3"}.
1693 If @env{OMP_PLACES} and @env{GOMP_CPU_AFFINITY} are unset and
1694 @env{OMP_PROC_BIND} is either unset or @code{false}, threads may be moved
1695 between CPUs following no placement policy.
1697 @item @emph{See also}:
1698 @ref{OMP_PROC_BIND}, @ref{GOMP_CPU_AFFINITY}, @ref{omp_get_proc_bind},
1699 @ref{OMP_DISPLAY_ENV}
1701 @item @emph{Reference}:
1702 @uref{https://www.openmp.org, OpenMP specification v4.5}, Section 4.5
1703 @end table
1707 @node OMP_STACKSIZE
1708 @section @env{OMP_STACKSIZE} -- Set default thread stack size
1709 @cindex Environment Variable
1710 @table @asis
1711 @item @emph{Description}:
1712 Set the default thread stack size in kilobytes, unless the number
1713 is suffixed by @code{B}, @code{K}, @code{M} or @code{G}, in which
1714 case the size is, respectively, in bytes, kilobytes, megabytes
1715 or gigabytes.  This is different from @code{pthread_attr_setstacksize}
1716 which gets the number of bytes as an argument.  If the stack size cannot
1717 be set due to system constraints, an error is reported and the initial
1718 stack size is left unchanged.  If undefined, the stack size is system
1719 dependent.
1721 @item @emph{Reference}: 
1722 @uref{https://www.openmp.org, OpenMP specification v4.5}, Section 4.7
1723 @end table
1727 @node OMP_SCHEDULE
1728 @section @env{OMP_SCHEDULE} -- How threads are scheduled
1729 @cindex Environment Variable
1730 @cindex Implementation specific setting
1731 @table @asis
1732 @item @emph{Description}:
1733 Allows to specify @code{schedule type} and @code{chunk size}. 
1734 The value of the variable shall have the form: @code{type[,chunk]} where
1735 @code{type} is one of @code{static}, @code{dynamic}, @code{guided} or @code{auto}
1736 The optional @code{chunk} size shall be a positive integer.  If undefined,
1737 dynamic scheduling and a chunk size of 1 is used.
1739 @item @emph{See also}:
1740 @ref{omp_set_schedule}
1742 @item @emph{Reference}: 
1743 @uref{https://www.openmp.org, OpenMP specification v4.5}, Sections 2.7.1.1 and 4.1
1744 @end table
1748 @node OMP_TARGET_OFFLOAD
1749 @section @env{OMP_TARGET_OFFLOAD} -- Controls offloading behaviour
1750 @cindex Environment Variable
1751 @cindex Implementation specific setting
1752 @table @asis
1753 @item @emph{Description}:
1754 Specifies the behaviour with regard to offloading code to a device.  This
1755 variable can be set to one of three values - @code{MANDATORY}, @code{DISABLED}
1756 or @code{DEFAULT}.
1758 If set to @code{MANDATORY}, the program will terminate with an error if
1759 the offload device is not present or is not supported.  If set to
1760 @code{DISABLED}, then offloading is disabled and all code will run on the
1761 host. If set to @code{DEFAULT}, the program will try offloading to the
1762 device first, then fall back to running code on the host if it cannot.
1764 If undefined, then the program will behave as if @code{DEFAULT} was set.
1766 @item @emph{Reference}:
1767 @uref{https://www.openmp.org, OpenMP specification v5.0}, Section 6.17
1768 @end table
1772 @node OMP_THREAD_LIMIT
1773 @section @env{OMP_THREAD_LIMIT} -- Set the maximum number of threads
1774 @cindex Environment Variable
1775 @table @asis
1776 @item @emph{Description}:
1777 Specifies the number of threads to use for the whole program.  The
1778 value of this variable shall be a positive integer.  If undefined,
1779 the number of threads is not limited.
1781 @item @emph{See also}:
1782 @ref{OMP_NUM_THREADS}, @ref{omp_get_thread_limit}
1784 @item @emph{Reference}: 
1785 @uref{https://www.openmp.org, OpenMP specification v4.5}, Section 4.10
1786 @end table
1790 @node OMP_WAIT_POLICY
1791 @section @env{OMP_WAIT_POLICY} -- How waiting threads are handled
1792 @cindex Environment Variable
1793 @table @asis
1794 @item @emph{Description}:
1795 Specifies whether waiting threads should be active or passive.  If
1796 the value is @code{PASSIVE}, waiting threads should not consume CPU
1797 power while waiting; while the value is @code{ACTIVE} specifies that
1798 they should.  If undefined, threads wait actively for a short time
1799 before waiting passively.
1801 @item @emph{See also}:
1802 @ref{GOMP_SPINCOUNT}
1804 @item @emph{Reference}: 
1805 @uref{https://www.openmp.org, OpenMP specification v4.5}, Section 4.8
1806 @end table
1810 @node GOMP_CPU_AFFINITY
1811 @section @env{GOMP_CPU_AFFINITY} -- Bind threads to specific CPUs
1812 @cindex Environment Variable
1813 @table @asis
1814 @item @emph{Description}:
1815 Binds threads to specific CPUs.  The variable should contain a space-separated
1816 or comma-separated list of CPUs.  This list may contain different kinds of 
1817 entries: either single CPU numbers in any order, a range of CPUs (M-N) 
1818 or a range with some stride (M-N:S).  CPU numbers are zero based.  For example,
1819 @code{GOMP_CPU_AFFINITY="0 3 1-2 4-15:2"} will bind the initial thread
1820 to CPU 0, the second to CPU 3, the third to CPU 1, the fourth to 
1821 CPU 2, the fifth to CPU 4, the sixth through tenth to CPUs 6, 8, 10, 12,
1822 and 14 respectively and then start assigning back from the beginning of
1823 the list.  @code{GOMP_CPU_AFFINITY=0} binds all threads to CPU 0.
1825 There is no libgomp library routine to determine whether a CPU affinity
1826 specification is in effect.  As a workaround, language-specific library 
1827 functions, e.g., @code{getenv} in C or @code{GET_ENVIRONMENT_VARIABLE} in 
1828 Fortran, may be used to query the setting of the @code{GOMP_CPU_AFFINITY} 
1829 environment variable.  A defined CPU affinity on startup cannot be changed 
1830 or disabled during the runtime of the application.
1832 If both @env{GOMP_CPU_AFFINITY} and @env{OMP_PROC_BIND} are set,
1833 @env{OMP_PROC_BIND} has a higher precedence.  If neither has been set and
1834 @env{OMP_PROC_BIND} is unset, or when @env{OMP_PROC_BIND} is set to
1835 @code{FALSE}, the host system will handle the assignment of threads to CPUs.
1837 @item @emph{See also}:
1838 @ref{OMP_PLACES}, @ref{OMP_PROC_BIND}
1839 @end table
1843 @node GOMP_DEBUG
1844 @section @env{GOMP_DEBUG} -- Enable debugging output
1845 @cindex Environment Variable
1846 @table @asis
1847 @item @emph{Description}:
1848 Enable debugging output.  The variable should be set to @code{0}
1849 (disabled, also the default if not set), or @code{1} (enabled).
1851 If enabled, some debugging output will be printed during execution.
1852 This is currently not specified in more detail, and subject to change.
1853 @end table
1857 @node GOMP_STACKSIZE
1858 @section @env{GOMP_STACKSIZE} -- Set default thread stack size
1859 @cindex Environment Variable
1860 @cindex Implementation specific setting
1861 @table @asis
1862 @item @emph{Description}:
1863 Set the default thread stack size in kilobytes.  This is different from
1864 @code{pthread_attr_setstacksize} which gets the number of bytes as an 
1865 argument.  If the stack size cannot be set due to system constraints, an 
1866 error is reported and the initial stack size is left unchanged.  If undefined,
1867 the stack size is system dependent.
1869 @item @emph{See also}:
1870 @ref{OMP_STACKSIZE}
1872 @item @emph{Reference}: 
1873 @uref{https://gcc.gnu.org/ml/gcc-patches/2006-06/msg00493.html,
1874 GCC Patches Mailinglist}, 
1875 @uref{https://gcc.gnu.org/ml/gcc-patches/2006-06/msg00496.html,
1876 GCC Patches Mailinglist}
1877 @end table
1881 @node GOMP_SPINCOUNT
1882 @section @env{GOMP_SPINCOUNT} -- Set the busy-wait spin count
1883 @cindex Environment Variable
1884 @cindex Implementation specific setting
1885 @table @asis
1886 @item @emph{Description}:
1887 Determines how long a threads waits actively with consuming CPU power
1888 before waiting passively without consuming CPU power.  The value may be
1889 either @code{INFINITE}, @code{INFINITY} to always wait actively or an
1890 integer which gives the number of spins of the busy-wait loop.  The
1891 integer may optionally be followed by the following suffixes acting
1892 as multiplication factors: @code{k} (kilo, thousand), @code{M} (mega,
1893 million), @code{G} (giga, billion), or @code{T} (tera, trillion).
1894 If undefined, 0 is used when @env{OMP_WAIT_POLICY} is @code{PASSIVE},
1895 300,000 is used when @env{OMP_WAIT_POLICY} is undefined and
1896 30 billion is used when @env{OMP_WAIT_POLICY} is @code{ACTIVE}.
1897 If there are more OpenMP threads than available CPUs, 1000 and 100
1898 spins are used for @env{OMP_WAIT_POLICY} being @code{ACTIVE} or
1899 undefined, respectively; unless the @env{GOMP_SPINCOUNT} is lower
1900 or @env{OMP_WAIT_POLICY} is @code{PASSIVE}.
1902 @item @emph{See also}:
1903 @ref{OMP_WAIT_POLICY}
1904 @end table
1908 @node GOMP_RTEMS_THREAD_POOLS
1909 @section @env{GOMP_RTEMS_THREAD_POOLS} -- Set the RTEMS specific thread pools
1910 @cindex Environment Variable
1911 @cindex Implementation specific setting
1912 @table @asis
1913 @item @emph{Description}:
1914 This environment variable is only used on the RTEMS real-time operating system.
1915 It determines the scheduler instance specific thread pools.  The format for
1916 @env{GOMP_RTEMS_THREAD_POOLS} is a list of optional
1917 @code{<thread-pool-count>[$<priority>]@@<scheduler-name>} configurations
1918 separated by @code{:} where:
1919 @itemize @bullet
1920 @item @code{<thread-pool-count>} is the thread pool count for this scheduler
1921 instance.
1922 @item @code{$<priority>} is an optional priority for the worker threads of a
1923 thread pool according to @code{pthread_setschedparam}.  In case a priority
1924 value is omitted, then a worker thread will inherit the priority of the OpenMP
1925 master thread that created it.  The priority of the worker thread is not
1926 changed after creation, even if a new OpenMP master thread using the worker has
1927 a different priority.
1928 @item @code{@@<scheduler-name>} is the scheduler instance name according to the
1929 RTEMS application configuration.
1930 @end itemize
1931 In case no thread pool configuration is specified for a scheduler instance,
1932 then each OpenMP master thread of this scheduler instance will use its own
1933 dynamically allocated thread pool.  To limit the worker thread count of the
1934 thread pools, each OpenMP master thread must call @code{omp_set_num_threads}.
1935 @item @emph{Example}:
1936 Lets suppose we have three scheduler instances @code{IO}, @code{WRK0}, and
1937 @code{WRK1} with @env{GOMP_RTEMS_THREAD_POOLS} set to
1938 @code{"1@@WRK0:3$4@@WRK1"}.  Then there are no thread pool restrictions for
1939 scheduler instance @code{IO}.  In the scheduler instance @code{WRK0} there is
1940 one thread pool available.  Since no priority is specified for this scheduler
1941 instance, the worker thread inherits the priority of the OpenMP master thread
1942 that created it.  In the scheduler instance @code{WRK1} there are three thread
1943 pools available and their worker threads run at priority four.
1944 @end table
1948 @c ---------------------------------------------------------------------
1949 @c Enabling OpenACC
1950 @c ---------------------------------------------------------------------
1952 @node Enabling OpenACC
1953 @chapter Enabling OpenACC
1955 To activate the OpenACC extensions for C/C++ and Fortran, the compile-time 
1956 flag @option{-fopenacc} must be specified.  This enables the OpenACC directive
1957 @code{#pragma acc} in C/C++ and @code{!$acc} directives in free form,
1958 @code{c$acc}, @code{*$acc} and @code{!$acc} directives in fixed form,
1959 @code{!$} conditional compilation sentinels in free form and @code{c$},
1960 @code{*$} and @code{!$} sentinels in fixed form, for Fortran.  The flag also
1961 arranges for automatic linking of the OpenACC runtime library 
1962 (@ref{OpenACC Runtime Library Routines}).
1964 See @uref{https://gcc.gnu.org/wiki/OpenACC} for more information.
1966 A complete description of all OpenACC directives accepted may be found in 
1967 the @uref{https://www.openacc.org, OpenACC} Application Programming
1968 Interface manual, version 2.6.
1972 @c ---------------------------------------------------------------------
1973 @c OpenACC Runtime Library Routines
1974 @c ---------------------------------------------------------------------
1976 @node OpenACC Runtime Library Routines
1977 @chapter OpenACC Runtime Library Routines
1979 The runtime routines described here are defined by section 3 of the OpenACC
1980 specifications in version 2.6.
1981 They have C linkage, and do not throw exceptions.
1982 Generally, they are available only for the host, with the exception of
1983 @code{acc_on_device}, which is available for both the host and the
1984 acceleration device.
1986 @menu
1987 * acc_get_num_devices::         Get number of devices for the given device
1988                                 type.
1989 * acc_set_device_type::         Set type of device accelerator to use.
1990 * acc_get_device_type::         Get type of device accelerator to be used.
1991 * acc_set_device_num::          Set device number to use.
1992 * acc_get_device_num::          Get device number to be used.
1993 * acc_get_property::            Get device property.
1994 * acc_async_test::              Tests for completion of a specific asynchronous
1995                                 operation.
1996 * acc_async_test_all::          Tests for completion of all asynchronous
1997                                 operations.
1998 * acc_wait::                    Wait for completion of a specific asynchronous
1999                                 operation.
2000 * acc_wait_all::                Waits for completion of all asynchronous
2001                                 operations.
2002 * acc_wait_all_async::          Wait for completion of all asynchronous
2003                                 operations.
2004 * acc_wait_async::              Wait for completion of asynchronous operations.
2005 * acc_init::                    Initialize runtime for a specific device type.
2006 * acc_shutdown::                Shuts down the runtime for a specific device
2007                                 type.
2008 * acc_on_device::               Whether executing on a particular device
2009 * acc_malloc::                  Allocate device memory.
2010 * acc_free::                    Free device memory.
2011 * acc_copyin::                  Allocate device memory and copy host memory to
2012                                 it.
2013 * acc_present_or_copyin::       If the data is not present on the device,
2014                                 allocate device memory and copy from host
2015                                 memory.
2016 * acc_create::                  Allocate device memory and map it to host
2017                                 memory.
2018 * acc_present_or_create::       If the data is not present on the device,
2019                                 allocate device memory and map it to host
2020                                 memory.
2021 * acc_copyout::                 Copy device memory to host memory.
2022 * acc_delete::                  Free device memory.
2023 * acc_update_device::           Update device memory from mapped host memory.
2024 * acc_update_self::             Update host memory from mapped device memory.
2025 * acc_map_data::                Map previously allocated device memory to host
2026                                 memory.
2027 * acc_unmap_data::              Unmap device memory from host memory.
2028 * acc_deviceptr::               Get device pointer associated with specific
2029                                 host address.
2030 * acc_hostptr::                 Get host pointer associated with specific
2031                                 device address.
2032 * acc_is_present::              Indicate whether host variable / array is
2033                                 present on device.
2034 * acc_memcpy_to_device::        Copy host memory to device memory.
2035 * acc_memcpy_from_device::      Copy device memory to host memory.
2036 * acc_attach::                  Let device pointer point to device-pointer target.
2037 * acc_detach::                  Let device pointer point to host-pointer target.
2039 API routines for target platforms.
2041 * acc_get_current_cuda_device:: Get CUDA device handle.
2042 * acc_get_current_cuda_context::Get CUDA context handle.
2043 * acc_get_cuda_stream::         Get CUDA stream handle.
2044 * acc_set_cuda_stream::         Set CUDA stream handle.
2046 API routines for the OpenACC Profiling Interface.
2048 * acc_prof_register::           Register callbacks.
2049 * acc_prof_unregister::         Unregister callbacks.
2050 * acc_prof_lookup::             Obtain inquiry functions.
2051 * acc_register_library::        Library registration.
2052 @end menu
2056 @node acc_get_num_devices
2057 @section @code{acc_get_num_devices} -- Get number of devices for given device type
2058 @table @asis
2059 @item @emph{Description}
2060 This function returns a value indicating the number of devices available
2061 for the device type specified in @var{devicetype}. 
2063 @item @emph{C/C++}:
2064 @multitable @columnfractions .20 .80
2065 @item @emph{Prototype}: @tab @code{int acc_get_num_devices(acc_device_t devicetype);}
2066 @end multitable
2068 @item @emph{Fortran}:
2069 @multitable @columnfractions .20 .80
2070 @item @emph{Interface}: @tab @code{integer function acc_get_num_devices(devicetype)}
2071 @item                  @tab @code{integer(kind=acc_device_kind) devicetype}
2072 @end multitable
2074 @item @emph{Reference}:
2075 @uref{https://www.openacc.org, OpenACC specification v2.6}, section
2076 3.2.1.
2077 @end table
2081 @node acc_set_device_type
2082 @section @code{acc_set_device_type} -- Set type of device accelerator to use.
2083 @table @asis
2084 @item @emph{Description}
2085 This function indicates to the runtime library which device type, specified
2086 in @var{devicetype}, to use when executing a parallel or kernels region. 
2088 @item @emph{C/C++}:
2089 @multitable @columnfractions .20 .80
2090 @item @emph{Prototype}: @tab @code{acc_set_device_type(acc_device_t devicetype);}
2091 @end multitable
2093 @item @emph{Fortran}:
2094 @multitable @columnfractions .20 .80
2095 @item @emph{Interface}: @tab @code{subroutine acc_set_device_type(devicetype)}
2096 @item                   @tab @code{integer(kind=acc_device_kind) devicetype}
2097 @end multitable
2099 @item @emph{Reference}:
2100 @uref{https://www.openacc.org, OpenACC specification v2.6}, section
2101 3.2.2.
2102 @end table
2106 @node acc_get_device_type
2107 @section @code{acc_get_device_type} -- Get type of device accelerator to be used.
2108 @table @asis
2109 @item @emph{Description}
2110 This function returns what device type will be used when executing a
2111 parallel or kernels region.
2113 This function returns @code{acc_device_none} if
2114 @code{acc_get_device_type} is called from
2115 @code{acc_ev_device_init_start}, @code{acc_ev_device_init_end}
2116 callbacks of the OpenACC Profiling Interface (@ref{OpenACC Profiling
2117 Interface}), that is, if the device is currently being initialized.
2119 @item @emph{C/C++}:
2120 @multitable @columnfractions .20 .80
2121 @item @emph{Prototype}: @tab @code{acc_device_t acc_get_device_type(void);}
2122 @end multitable
2124 @item @emph{Fortran}:
2125 @multitable @columnfractions .20 .80
2126 @item @emph{Interface}: @tab @code{function acc_get_device_type(void)}
2127 @item                  @tab @code{integer(kind=acc_device_kind) acc_get_device_type}
2128 @end multitable
2130 @item @emph{Reference}:
2131 @uref{https://www.openacc.org, OpenACC specification v2.6}, section
2132 3.2.3.
2133 @end table
2137 @node acc_set_device_num
2138 @section @code{acc_set_device_num} -- Set device number to use.
2139 @table @asis
2140 @item @emph{Description}
2141 This function will indicate to the runtime which device number,
2142 specified by @var{devicenum}, associated with the specified device
2143 type @var{devicetype}.
2145 @item @emph{C/C++}:
2146 @multitable @columnfractions .20 .80
2147 @item @emph{Prototype}: @tab @code{acc_set_device_num(int devicenum, acc_device_t devicetype);}
2148 @end multitable
2150 @item @emph{Fortran}:
2151 @multitable @columnfractions .20 .80
2152 @item @emph{Interface}: @tab @code{subroutine acc_set_device_num(devicenum, devicetype)}
2153 @item                   @tab @code{integer devicenum}
2154 @item                   @tab @code{integer(kind=acc_device_kind) devicetype}
2155 @end multitable
2157 @item @emph{Reference}:
2158 @uref{https://www.openacc.org, OpenACC specification v2.6}, section
2159 3.2.4.
2160 @end table
2164 @node acc_get_device_num
2165 @section @code{acc_get_device_num} -- Get device number to be used.
2166 @table @asis
2167 @item @emph{Description}
2168 This function returns which device number associated with the specified device
2169 type @var{devicetype}, will be used when executing a parallel or kernels
2170 region.
2172 @item @emph{C/C++}:
2173 @multitable @columnfractions .20 .80
2174 @item @emph{Prototype}: @tab @code{int acc_get_device_num(acc_device_t devicetype);}
2175 @end multitable
2177 @item @emph{Fortran}:
2178 @multitable @columnfractions .20 .80
2179 @item @emph{Interface}: @tab @code{function acc_get_device_num(devicetype)}
2180 @item                   @tab @code{integer(kind=acc_device_kind) devicetype}
2181 @item                   @tab @code{integer acc_get_device_num}
2182 @end multitable
2184 @item @emph{Reference}:
2185 @uref{https://www.openacc.org, OpenACC specification v2.6}, section
2186 3.2.5.
2187 @end table
2191 @node acc_get_property
2192 @section @code{acc_get_property} -- Get device property.
2193 @cindex acc_get_property
2194 @cindex acc_get_property_string
2195 @table @asis
2196 @item @emph{Description}
2197 These routines return the value of the specified @var{property} for the
2198 device being queried according to @var{devicenum} and @var{devicetype}.
2199 Integer-valued and string-valued properties are returned by
2200 @code{acc_get_property} and @code{acc_get_property_string} respectively.
2201 The Fortran @code{acc_get_property_string} subroutine returns the string
2202 retrieved in its fourth argument while the remaining entry points are
2203 functions, which pass the return value as their result.
2205 Note for Fortran, only: the OpenACC technical committee corrected and, hence,
2206 modified the interface introduced in OpenACC 2.6.  The kind-value parameter
2207 @code{acc_device_property} has been renamed to @code{acc_device_property_kind}
2208 for consistency and the return type of the @code{acc_get_property} function is
2209 now a @code{c_size_t} integer instead of a @code{acc_device_property} integer.
2210 The parameter @code{acc_device_property} will continue to be provided,
2211 but might be removed in a future version of GCC.
2213 @item @emph{C/C++}:
2214 @multitable @columnfractions .20 .80
2215 @item @emph{Prototype}: @tab @code{size_t acc_get_property(int devicenum, acc_device_t devicetype, acc_device_property_t property);}
2216 @item @emph{Prototype}: @tab @code{const char *acc_get_property_string(int devicenum, acc_device_t devicetype, acc_device_property_t property);}
2217 @end multitable
2219 @item @emph{Fortran}:
2220 @multitable @columnfractions .20 .80
2221 @item @emph{Interface}: @tab @code{function acc_get_property(devicenum, devicetype, property)}
2222 @item @emph{Interface}: @tab @code{subroutine acc_get_property_string(devicenum, devicetype, property, string)}
2223 @item                   @tab @code{use ISO_C_Binding, only: c_size_t}
2224 @item                   @tab @code{integer devicenum}
2225 @item                   @tab @code{integer(kind=acc_device_kind) devicetype}
2226 @item                   @tab @code{integer(kind=acc_device_property_kind) property}
2227 @item                   @tab @code{integer(kind=c_size_t) acc_get_property}
2228 @item                   @tab @code{character(*) string}
2229 @end multitable
2231 @item @emph{Reference}:
2232 @uref{https://www.openacc.org, OpenACC specification v2.6}, section
2233 3.2.6.
2234 @end table
2238 @node acc_async_test
2239 @section @code{acc_async_test} -- Test for completion of a specific asynchronous operation.
2240 @table @asis
2241 @item @emph{Description}
2242 This function tests for completion of the asynchronous operation specified
2243 in @var{arg}. In C/C++, a non-zero value will be returned to indicate
2244 the specified asynchronous operation has completed. While Fortran will return
2245 a @code{true}. If the asynchronous operation has not completed, C/C++ returns
2246 a zero and Fortran returns a @code{false}.
2248 @item @emph{C/C++}:
2249 @multitable @columnfractions .20 .80
2250 @item @emph{Prototype}: @tab @code{int acc_async_test(int arg);}
2251 @end multitable
2253 @item @emph{Fortran}:
2254 @multitable @columnfractions .20 .80
2255 @item @emph{Interface}: @tab @code{function acc_async_test(arg)}
2256 @item                   @tab @code{integer(kind=acc_handle_kind) arg}
2257 @item                   @tab @code{logical acc_async_test}
2258 @end multitable
2260 @item @emph{Reference}:
2261 @uref{https://www.openacc.org, OpenACC specification v2.6}, section
2262 3.2.9.
2263 @end table
2267 @node acc_async_test_all
2268 @section @code{acc_async_test_all} -- Tests for completion of all asynchronous operations.
2269 @table @asis
2270 @item @emph{Description}
2271 This function tests for completion of all asynchronous operations.
2272 In C/C++, a non-zero value will be returned to indicate all asynchronous
2273 operations have completed. While Fortran will return a @code{true}. If
2274 any asynchronous operation has not completed, C/C++ returns a zero and
2275 Fortran returns a @code{false}.
2277 @item @emph{C/C++}:
2278 @multitable @columnfractions .20 .80
2279 @item @emph{Prototype}: @tab @code{int acc_async_test_all(void);}
2280 @end multitable
2282 @item @emph{Fortran}:
2283 @multitable @columnfractions .20 .80
2284 @item @emph{Interface}: @tab @code{function acc_async_test()}
2285 @item                   @tab @code{logical acc_get_device_num}
2286 @end multitable
2288 @item @emph{Reference}:
2289 @uref{https://www.openacc.org, OpenACC specification v2.6}, section
2290 3.2.10.
2291 @end table
2295 @node acc_wait
2296 @section @code{acc_wait} -- Wait for completion of a specific asynchronous operation.
2297 @table @asis
2298 @item @emph{Description}
2299 This function waits for completion of the asynchronous operation
2300 specified in @var{arg}.
2302 @item @emph{C/C++}:
2303 @multitable @columnfractions .20 .80
2304 @item @emph{Prototype}: @tab @code{acc_wait(arg);}
2305 @item @emph{Prototype (OpenACC 1.0 compatibility)}: @tab @code{acc_async_wait(arg);}
2306 @end multitable
2308 @item @emph{Fortran}:
2309 @multitable @columnfractions .20 .80
2310 @item @emph{Interface}: @tab @code{subroutine acc_wait(arg)}
2311 @item                   @tab @code{integer(acc_handle_kind) arg}
2312 @item @emph{Interface (OpenACC 1.0 compatibility)}: @tab @code{subroutine acc_async_wait(arg)}
2313 @item                                               @tab @code{integer(acc_handle_kind) arg}
2314 @end multitable
2316 @item @emph{Reference}:
2317 @uref{https://www.openacc.org, OpenACC specification v2.6}, section
2318 3.2.11.
2319 @end table
2323 @node acc_wait_all
2324 @section @code{acc_wait_all} -- Waits for completion of all asynchronous operations.
2325 @table @asis
2326 @item @emph{Description}
2327 This function waits for the completion of all asynchronous operations.
2329 @item @emph{C/C++}:
2330 @multitable @columnfractions .20 .80
2331 @item @emph{Prototype}: @tab @code{acc_wait_all(void);}
2332 @item @emph{Prototype (OpenACC 1.0 compatibility)}: @tab @code{acc_async_wait_all(void);}
2333 @end multitable
2335 @item @emph{Fortran}:
2336 @multitable @columnfractions .20 .80
2337 @item @emph{Interface}: @tab @code{subroutine acc_wait_all()}
2338 @item @emph{Interface (OpenACC 1.0 compatibility)}: @tab @code{subroutine acc_async_wait_all()}
2339 @end multitable
2341 @item @emph{Reference}:
2342 @uref{https://www.openacc.org, OpenACC specification v2.6}, section
2343 3.2.13.
2344 @end table
2348 @node acc_wait_all_async
2349 @section @code{acc_wait_all_async} -- Wait for completion of all asynchronous operations.
2350 @table @asis
2351 @item @emph{Description}
2352 This function enqueues a wait operation on the queue @var{async} for any
2353 and all asynchronous operations that have been previously enqueued on
2354 any queue.
2356 @item @emph{C/C++}:
2357 @multitable @columnfractions .20 .80
2358 @item @emph{Prototype}: @tab @code{acc_wait_all_async(int async);}
2359 @end multitable
2361 @item @emph{Fortran}:
2362 @multitable @columnfractions .20 .80
2363 @item @emph{Interface}: @tab @code{subroutine acc_wait_all_async(async)}
2364 @item                   @tab @code{integer(acc_handle_kind) async}
2365 @end multitable
2367 @item @emph{Reference}:
2368 @uref{https://www.openacc.org, OpenACC specification v2.6}, section
2369 3.2.14.
2370 @end table
2374 @node acc_wait_async
2375 @section @code{acc_wait_async} -- Wait for completion of asynchronous operations.
2376 @table @asis
2377 @item @emph{Description}
2378 This function enqueues a wait operation on queue @var{async} for any and all
2379 asynchronous operations enqueued on queue @var{arg}.
2381 @item @emph{C/C++}:
2382 @multitable @columnfractions .20 .80
2383 @item @emph{Prototype}: @tab @code{acc_wait_async(int arg, int async);}
2384 @end multitable
2386 @item @emph{Fortran}:
2387 @multitable @columnfractions .20 .80
2388 @item @emph{Interface}: @tab @code{subroutine acc_wait_async(arg, async)}
2389 @item                   @tab @code{integer(acc_handle_kind) arg, async}
2390 @end multitable
2392 @item @emph{Reference}:
2393 @uref{https://www.openacc.org, OpenACC specification v2.6}, section
2394 3.2.12.
2395 @end table
2399 @node acc_init
2400 @section @code{acc_init} -- Initialize runtime for a specific device type.
2401 @table @asis
2402 @item @emph{Description}
2403 This function initializes the runtime for the device type specified in
2404 @var{devicetype}.
2406 @item @emph{C/C++}:
2407 @multitable @columnfractions .20 .80
2408 @item @emph{Prototype}: @tab @code{acc_init(acc_device_t devicetype);}
2409 @end multitable
2411 @item @emph{Fortran}:
2412 @multitable @columnfractions .20 .80
2413 @item @emph{Interface}: @tab @code{subroutine acc_init(devicetype)}
2414 @item                   @tab @code{integer(acc_device_kind) devicetype}
2415 @end multitable
2417 @item @emph{Reference}:
2418 @uref{https://www.openacc.org, OpenACC specification v2.6}, section
2419 3.2.7.
2420 @end table
2424 @node acc_shutdown
2425 @section @code{acc_shutdown} -- Shuts down the runtime for a specific device type.
2426 @table @asis
2427 @item @emph{Description}
2428 This function shuts down the runtime for the device type specified in
2429 @var{devicetype}.
2431 @item @emph{C/C++}:
2432 @multitable @columnfractions .20 .80
2433 @item @emph{Prototype}: @tab @code{acc_shutdown(acc_device_t devicetype);}
2434 @end multitable
2436 @item @emph{Fortran}:
2437 @multitable @columnfractions .20 .80
2438 @item @emph{Interface}: @tab @code{subroutine acc_shutdown(devicetype)}
2439 @item                   @tab @code{integer(acc_device_kind) devicetype}
2440 @end multitable
2442 @item @emph{Reference}:
2443 @uref{https://www.openacc.org, OpenACC specification v2.6}, section
2444 3.2.8.
2445 @end table
2449 @node acc_on_device
2450 @section @code{acc_on_device} -- Whether executing on a particular device
2451 @table @asis
2452 @item @emph{Description}:
2453 This function returns whether the program is executing on a particular
2454 device specified in @var{devicetype}. In C/C++ a non-zero value is
2455 returned to indicate the device is executing on the specified device type.
2456 In Fortran, @code{true} will be returned. If the program is not executing
2457 on the specified device type C/C++ will return a zero, while Fortran will
2458 return @code{false}.
2460 @item @emph{C/C++}:
2461 @multitable @columnfractions .20 .80
2462 @item @emph{Prototype}: @tab @code{acc_on_device(acc_device_t devicetype);}
2463 @end multitable
2465 @item @emph{Fortran}:
2466 @multitable @columnfractions .20 .80
2467 @item @emph{Interface}: @tab @code{function acc_on_device(devicetype)}
2468 @item                   @tab @code{integer(acc_device_kind) devicetype}
2469 @item                   @tab @code{logical acc_on_device}
2470 @end multitable
2473 @item @emph{Reference}:
2474 @uref{https://www.openacc.org, OpenACC specification v2.6}, section
2475 3.2.17.
2476 @end table
2480 @node acc_malloc
2481 @section @code{acc_malloc} -- Allocate device memory.
2482 @table @asis
2483 @item @emph{Description}
2484 This function allocates @var{len} bytes of device memory. It returns
2485 the device address of the allocated memory.
2487 @item @emph{C/C++}:
2488 @multitable @columnfractions .20 .80
2489 @item @emph{Prototype}: @tab @code{d_void* acc_malloc(size_t len);}
2490 @end multitable
2492 @item @emph{Reference}:
2493 @uref{https://www.openacc.org, OpenACC specification v2.6}, section
2494 3.2.18.
2495 @end table
2499 @node acc_free
2500 @section @code{acc_free} -- Free device memory.
2501 @table @asis
2502 @item @emph{Description}
2503 Free previously allocated device memory at the device address @code{a}.
2505 @item @emph{C/C++}:
2506 @multitable @columnfractions .20 .80
2507 @item @emph{Prototype}: @tab @code{acc_free(d_void *a);}
2508 @end multitable
2510 @item @emph{Reference}:
2511 @uref{https://www.openacc.org, OpenACC specification v2.6}, section
2512 3.2.19.
2513 @end table
2517 @node acc_copyin
2518 @section @code{acc_copyin} -- Allocate device memory and copy host memory to it.
2519 @table @asis
2520 @item @emph{Description}
2521 In C/C++, this function allocates @var{len} bytes of device memory
2522 and maps it to the specified host address in @var{a}. The device
2523 address of the newly allocated device memory is returned.
2525 In Fortran, two (2) forms are supported. In the first form, @var{a} specifies
2526 a contiguous array section. The second form @var{a} specifies a
2527 variable or array element and @var{len} specifies the length in bytes.
2529 @item @emph{C/C++}:
2530 @multitable @columnfractions .20 .80
2531 @item @emph{Prototype}: @tab @code{void *acc_copyin(h_void *a, size_t len);}
2532 @item @emph{Prototype}: @tab @code{void *acc_copyin_async(h_void *a, size_t len, int async);}
2533 @end multitable
2535 @item @emph{Fortran}:
2536 @multitable @columnfractions .20 .80
2537 @item @emph{Interface}: @tab @code{subroutine acc_copyin(a)}
2538 @item                   @tab @code{type, dimension(:[,:]...) :: a}
2539 @item @emph{Interface}: @tab @code{subroutine acc_copyin(a, len)}
2540 @item                   @tab @code{type, dimension(:[,:]...) :: a}
2541 @item                   @tab @code{integer len}
2542 @item @emph{Interface}: @tab @code{subroutine acc_copyin_async(a, async)}
2543 @item                   @tab @code{type, dimension(:[,:]...) :: a}
2544 @item                   @tab @code{integer(acc_handle_kind) :: async}
2545 @item @emph{Interface}: @tab @code{subroutine acc_copyin_async(a, len, async)}
2546 @item                   @tab @code{type, dimension(:[,:]...) :: a}
2547 @item                   @tab @code{integer len}
2548 @item                   @tab @code{integer(acc_handle_kind) :: async}
2549 @end multitable
2551 @item @emph{Reference}:
2552 @uref{https://www.openacc.org, OpenACC specification v2.6}, section
2553 3.2.20.
2554 @end table
2558 @node acc_present_or_copyin
2559 @section @code{acc_present_or_copyin} -- If the data is not present on the device, allocate device memory and copy from host memory.
2560 @table @asis
2561 @item @emph{Description}
2562 This function tests if the host data specified by @var{a} and of length
2563 @var{len} is present or not. If it is not present, then device memory
2564 will be allocated and the host memory copied. The device address of
2565 the newly allocated device memory is returned.
2567 In Fortran, two (2) forms are supported. In the first form, @var{a} specifies
2568 a contiguous array section. The second form @var{a} specifies a variable or
2569 array element and @var{len} specifies the length in bytes.
2571 Note that @code{acc_present_or_copyin} and @code{acc_pcopyin} exist for
2572 backward compatibility with OpenACC 2.0; use @ref{acc_copyin} instead.
2574 @item @emph{C/C++}:
2575 @multitable @columnfractions .20 .80
2576 @item @emph{Prototype}: @tab @code{void *acc_present_or_copyin(h_void *a, size_t len);}
2577 @item @emph{Prototype}: @tab @code{void *acc_pcopyin(h_void *a, size_t len);}
2578 @end multitable
2580 @item @emph{Fortran}:
2581 @multitable @columnfractions .20 .80
2582 @item @emph{Interface}: @tab @code{subroutine acc_present_or_copyin(a)}
2583 @item                   @tab @code{type, dimension(:[,:]...) :: a}
2584 @item @emph{Interface}: @tab @code{subroutine acc_present_or_copyin(a, len)}
2585 @item                   @tab @code{type, dimension(:[,:]...) :: a}
2586 @item                   @tab @code{integer len}
2587 @item @emph{Interface}: @tab @code{subroutine acc_pcopyin(a)}
2588 @item                   @tab @code{type, dimension(:[,:]...) :: a}
2589 @item @emph{Interface}: @tab @code{subroutine acc_pcopyin(a, len)}
2590 @item                   @tab @code{type, dimension(:[,:]...) :: a}
2591 @item                   @tab @code{integer len}
2592 @end multitable
2594 @item @emph{Reference}:
2595 @uref{https://www.openacc.org, OpenACC specification v2.6}, section
2596 3.2.20.
2597 @end table
2601 @node acc_create
2602 @section @code{acc_create} -- Allocate device memory and map it to host memory.
2603 @table @asis
2604 @item @emph{Description}
2605 This function allocates device memory and maps it to host memory specified
2606 by the host address @var{a} with a length of @var{len} bytes. In C/C++,
2607 the function returns the device address of the allocated device memory.
2609 In Fortran, two (2) forms are supported. In the first form, @var{a} specifies
2610 a contiguous array section. The second form @var{a} specifies a variable or
2611 array element and @var{len} specifies the length in bytes.
2613 @item @emph{C/C++}:
2614 @multitable @columnfractions .20 .80
2615 @item @emph{Prototype}: @tab @code{void *acc_create(h_void *a, size_t len);}
2616 @item @emph{Prototype}: @tab @code{void *acc_create_async(h_void *a, size_t len, int async);}
2617 @end multitable
2619 @item @emph{Fortran}:
2620 @multitable @columnfractions .20 .80
2621 @item @emph{Interface}: @tab @code{subroutine acc_create(a)}
2622 @item                   @tab @code{type, dimension(:[,:]...) :: a}
2623 @item @emph{Interface}: @tab @code{subroutine acc_create(a, len)}
2624 @item                   @tab @code{type, dimension(:[,:]...) :: a}
2625 @item                   @tab @code{integer len}
2626 @item @emph{Interface}: @tab @code{subroutine acc_create_async(a, async)}
2627 @item                   @tab @code{type, dimension(:[,:]...) :: a}
2628 @item                   @tab @code{integer(acc_handle_kind) :: async}
2629 @item @emph{Interface}: @tab @code{subroutine acc_create_async(a, len, async)}
2630 @item                   @tab @code{type, dimension(:[,:]...) :: a}
2631 @item                   @tab @code{integer len}
2632 @item                   @tab @code{integer(acc_handle_kind) :: async}
2633 @end multitable
2635 @item @emph{Reference}:
2636 @uref{https://www.openacc.org, OpenACC specification v2.6}, section
2637 3.2.21.
2638 @end table
2642 @node acc_present_or_create
2643 @section @code{acc_present_or_create} -- If the data is not present on the device, allocate device memory and map it to host memory.
2644 @table @asis
2645 @item @emph{Description}
2646 This function tests if the host data specified by @var{a} and of length
2647 @var{len} is present or not. If it is not present, then device memory
2648 will be allocated and mapped to host memory. In C/C++, the device address
2649 of the newly allocated device memory is returned.
2651 In Fortran, two (2) forms are supported. In the first form, @var{a} specifies
2652 a contiguous array section. The second form @var{a} specifies a variable or
2653 array element and @var{len} specifies the length in bytes.
2655 Note that @code{acc_present_or_create} and @code{acc_pcreate} exist for
2656 backward compatibility with OpenACC 2.0; use @ref{acc_create} instead.
2658 @item @emph{C/C++}:
2659 @multitable @columnfractions .20 .80
2660 @item @emph{Prototype}: @tab @code{void *acc_present_or_create(h_void *a, size_t len)}
2661 @item @emph{Prototype}: @tab @code{void *acc_pcreate(h_void *a, size_t len)}
2662 @end multitable
2664 @item @emph{Fortran}:
2665 @multitable @columnfractions .20 .80
2666 @item @emph{Interface}: @tab @code{subroutine acc_present_or_create(a)}
2667 @item                   @tab @code{type, dimension(:[,:]...) :: a}
2668 @item @emph{Interface}: @tab @code{subroutine acc_present_or_create(a, len)}
2669 @item                   @tab @code{type, dimension(:[,:]...) :: a}
2670 @item                   @tab @code{integer len}
2671 @item @emph{Interface}: @tab @code{subroutine acc_pcreate(a)}
2672 @item                   @tab @code{type, dimension(:[,:]...) :: a}
2673 @item @emph{Interface}: @tab @code{subroutine acc_pcreate(a, len)}
2674 @item                   @tab @code{type, dimension(:[,:]...) :: a}
2675 @item                   @tab @code{integer len}
2676 @end multitable
2678 @item @emph{Reference}:
2679 @uref{https://www.openacc.org, OpenACC specification v2.6}, section
2680 3.2.21.
2681 @end table
2685 @node acc_copyout
2686 @section @code{acc_copyout} -- Copy device memory to host memory.
2687 @table @asis
2688 @item @emph{Description}
2689 This function copies mapped device memory to host memory which is specified
2690 by host address @var{a} for a length @var{len} bytes in C/C++.
2692 In Fortran, two (2) forms are supported. In the first form, @var{a} specifies
2693 a contiguous array section. The second form @var{a} specifies a variable or
2694 array element and @var{len} specifies the length in bytes.
2696 @item @emph{C/C++}:
2697 @multitable @columnfractions .20 .80
2698 @item @emph{Prototype}: @tab @code{acc_copyout(h_void *a, size_t len);}
2699 @item @emph{Prototype}: @tab @code{acc_copyout_async(h_void *a, size_t len, int async);}
2700 @item @emph{Prototype}: @tab @code{acc_copyout_finalize(h_void *a, size_t len);}
2701 @item @emph{Prototype}: @tab @code{acc_copyout_finalize_async(h_void *a, size_t len, int async);}
2702 @end multitable
2704 @item @emph{Fortran}:
2705 @multitable @columnfractions .20 .80
2706 @item @emph{Interface}: @tab @code{subroutine acc_copyout(a)}
2707 @item                   @tab @code{type, dimension(:[,:]...) :: a}
2708 @item @emph{Interface}: @tab @code{subroutine acc_copyout(a, len)}
2709 @item                   @tab @code{type, dimension(:[,:]...) :: a}
2710 @item                   @tab @code{integer len}
2711 @item @emph{Interface}: @tab @code{subroutine acc_copyout_async(a, async)}
2712 @item                   @tab @code{type, dimension(:[,:]...) :: a}
2713 @item                   @tab @code{integer(acc_handle_kind) :: async}
2714 @item @emph{Interface}: @tab @code{subroutine acc_copyout_async(a, len, async)}
2715 @item                   @tab @code{type, dimension(:[,:]...) :: a}
2716 @item                   @tab @code{integer len}
2717 @item                   @tab @code{integer(acc_handle_kind) :: async}
2718 @item @emph{Interface}: @tab @code{subroutine acc_copyout_finalize(a)}
2719 @item                   @tab @code{type, dimension(:[,:]...) :: a}
2720 @item @emph{Interface}: @tab @code{subroutine acc_copyout_finalize(a, len)}
2721 @item                   @tab @code{type, dimension(:[,:]...) :: a}
2722 @item                   @tab @code{integer len}
2723 @item @emph{Interface}: @tab @code{subroutine acc_copyout_finalize_async(a, async)}
2724 @item                   @tab @code{type, dimension(:[,:]...) :: a}
2725 @item                   @tab @code{integer(acc_handle_kind) :: async}
2726 @item @emph{Interface}: @tab @code{subroutine acc_copyout_finalize_async(a, len, async)}
2727 @item                   @tab @code{type, dimension(:[,:]...) :: a}
2728 @item                   @tab @code{integer len}
2729 @item                   @tab @code{integer(acc_handle_kind) :: async}
2730 @end multitable
2732 @item @emph{Reference}:
2733 @uref{https://www.openacc.org, OpenACC specification v2.6}, section
2734 3.2.22.
2735 @end table
2739 @node acc_delete
2740 @section @code{acc_delete} -- Free device memory.
2741 @table @asis
2742 @item @emph{Description}
2743 This function frees previously allocated device memory specified by
2744 the device address @var{a} and the length of @var{len} bytes.
2746 In Fortran, two (2) forms are supported. In the first form, @var{a} specifies
2747 a contiguous array section. The second form @var{a} specifies a variable or
2748 array element and @var{len} specifies the length in bytes.
2750 @item @emph{C/C++}:
2751 @multitable @columnfractions .20 .80
2752 @item @emph{Prototype}: @tab @code{acc_delete(h_void *a, size_t len);}
2753 @item @emph{Prototype}: @tab @code{acc_delete_async(h_void *a, size_t len, int async);}
2754 @item @emph{Prototype}: @tab @code{acc_delete_finalize(h_void *a, size_t len);}
2755 @item @emph{Prototype}: @tab @code{acc_delete_finalize_async(h_void *a, size_t len, int async);}
2756 @end multitable
2758 @item @emph{Fortran}:
2759 @multitable @columnfractions .20 .80
2760 @item @emph{Interface}: @tab @code{subroutine acc_delete(a)}
2761 @item                   @tab @code{type, dimension(:[,:]...) :: a}
2762 @item @emph{Interface}: @tab @code{subroutine acc_delete(a, len)}
2763 @item                   @tab @code{type, dimension(:[,:]...) :: a}
2764 @item                   @tab @code{integer len}
2765 @item @emph{Interface}: @tab @code{subroutine acc_delete_async(a, async)}
2766 @item                   @tab @code{type, dimension(:[,:]...) :: a}
2767 @item                   @tab @code{integer(acc_handle_kind) :: async}
2768 @item @emph{Interface}: @tab @code{subroutine acc_delete_async(a, len, async)}
2769 @item                   @tab @code{type, dimension(:[,:]...) :: a}
2770 @item                   @tab @code{integer len}
2771 @item                   @tab @code{integer(acc_handle_kind) :: async}
2772 @item @emph{Interface}: @tab @code{subroutine acc_delete_finalize(a)}
2773 @item                   @tab @code{type, dimension(:[,:]...) :: a}
2774 @item @emph{Interface}: @tab @code{subroutine acc_delete_finalize(a, len)}
2775 @item                   @tab @code{type, dimension(:[,:]...) :: a}
2776 @item                   @tab @code{integer len}
2777 @item @emph{Interface}: @tab @code{subroutine acc_delete_async_finalize(a, async)}
2778 @item                   @tab @code{type, dimension(:[,:]...) :: a}
2779 @item                   @tab @code{integer(acc_handle_kind) :: async}
2780 @item @emph{Interface}: @tab @code{subroutine acc_delete_async_finalize(a, len, async)}
2781 @item                   @tab @code{type, dimension(:[,:]...) :: a}
2782 @item                   @tab @code{integer len}
2783 @item                   @tab @code{integer(acc_handle_kind) :: async}
2784 @end multitable
2786 @item @emph{Reference}:
2787 @uref{https://www.openacc.org, OpenACC specification v2.6}, section
2788 3.2.23.
2789 @end table
2793 @node acc_update_device
2794 @section @code{acc_update_device} -- Update device memory from mapped host memory.
2795 @table @asis
2796 @item @emph{Description}
2797 This function updates the device copy from the previously mapped host memory.
2798 The host memory is specified with the host address @var{a} and a length of
2799 @var{len} bytes.
2801 In Fortran, two (2) forms are supported. In the first form, @var{a} specifies
2802 a contiguous array section. The second form @var{a} specifies a variable or
2803 array element and @var{len} specifies the length in bytes.
2805 @item @emph{C/C++}:
2806 @multitable @columnfractions .20 .80
2807 @item @emph{Prototype}: @tab @code{acc_update_device(h_void *a, size_t len);}
2808 @item @emph{Prototype}: @tab @code{acc_update_device(h_void *a, size_t len, async);}
2809 @end multitable
2811 @item @emph{Fortran}:
2812 @multitable @columnfractions .20 .80
2813 @item @emph{Interface}: @tab @code{subroutine acc_update_device(a)}
2814 @item                   @tab @code{type, dimension(:[,:]...) :: a}
2815 @item @emph{Interface}: @tab @code{subroutine acc_update_device(a, len)}
2816 @item                   @tab @code{type, dimension(:[,:]...) :: a}
2817 @item                   @tab @code{integer len}
2818 @item @emph{Interface}: @tab @code{subroutine acc_update_device_async(a, async)}
2819 @item                   @tab @code{type, dimension(:[,:]...) :: a}
2820 @item                   @tab @code{integer(acc_handle_kind) :: async}
2821 @item @emph{Interface}: @tab @code{subroutine acc_update_device_async(a, len, async)}
2822 @item                   @tab @code{type, dimension(:[,:]...) :: a}
2823 @item                   @tab @code{integer len}
2824 @item                   @tab @code{integer(acc_handle_kind) :: async}
2825 @end multitable
2827 @item @emph{Reference}:
2828 @uref{https://www.openacc.org, OpenACC specification v2.6}, section
2829 3.2.24.
2830 @end table
2834 @node acc_update_self
2835 @section @code{acc_update_self} -- Update host memory from mapped device memory.
2836 @table @asis
2837 @item @emph{Description}
2838 This function updates the host copy from the previously mapped device memory.
2839 The host memory is specified with the host address @var{a} and a length of
2840 @var{len} bytes.
2842 In Fortran, two (2) forms are supported. In the first form, @var{a} specifies
2843 a contiguous array section. The second form @var{a} specifies a variable or
2844 array element and @var{len} specifies the length in bytes.
2846 @item @emph{C/C++}:
2847 @multitable @columnfractions .20 .80
2848 @item @emph{Prototype}: @tab @code{acc_update_self(h_void *a, size_t len);}
2849 @item @emph{Prototype}: @tab @code{acc_update_self_async(h_void *a, size_t len, int async);}
2850 @end multitable
2852 @item @emph{Fortran}:
2853 @multitable @columnfractions .20 .80
2854 @item @emph{Interface}: @tab @code{subroutine acc_update_self(a)}
2855 @item                   @tab @code{type, dimension(:[,:]...) :: a}
2856 @item @emph{Interface}: @tab @code{subroutine acc_update_self(a, len)}
2857 @item                   @tab @code{type, dimension(:[,:]...) :: a}
2858 @item                   @tab @code{integer len}
2859 @item @emph{Interface}: @tab @code{subroutine acc_update_self_async(a, async)}
2860 @item                   @tab @code{type, dimension(:[,:]...) :: a}
2861 @item                   @tab @code{integer(acc_handle_kind) :: async}
2862 @item @emph{Interface}: @tab @code{subroutine acc_update_self_async(a, len, async)}
2863 @item                   @tab @code{type, dimension(:[,:]...) :: a}
2864 @item                   @tab @code{integer len}
2865 @item                   @tab @code{integer(acc_handle_kind) :: async}
2866 @end multitable
2868 @item @emph{Reference}:
2869 @uref{https://www.openacc.org, OpenACC specification v2.6}, section
2870 3.2.25.
2871 @end table
2875 @node acc_map_data
2876 @section @code{acc_map_data} -- Map previously allocated device memory to host memory.
2877 @table @asis
2878 @item @emph{Description}
2879 This function maps previously allocated device and host memory. The device
2880 memory is specified with the device address @var{d}. The host memory is
2881 specified with the host address @var{h} and a length of @var{len}.
2883 @item @emph{C/C++}:
2884 @multitable @columnfractions .20 .80
2885 @item @emph{Prototype}: @tab @code{acc_map_data(h_void *h, d_void *d, size_t len);}
2886 @end multitable
2888 @item @emph{Reference}:
2889 @uref{https://www.openacc.org, OpenACC specification v2.6}, section
2890 3.2.26.
2891 @end table
2895 @node acc_unmap_data
2896 @section @code{acc_unmap_data} -- Unmap device memory from host memory.
2897 @table @asis
2898 @item @emph{Description}
2899 This function unmaps previously mapped device and host memory. The latter
2900 specified by @var{h}.
2902 @item @emph{C/C++}:
2903 @multitable @columnfractions .20 .80
2904 @item @emph{Prototype}: @tab @code{acc_unmap_data(h_void *h);}
2905 @end multitable
2907 @item @emph{Reference}:
2908 @uref{https://www.openacc.org, OpenACC specification v2.6}, section
2909 3.2.27.
2910 @end table
2914 @node acc_deviceptr
2915 @section @code{acc_deviceptr} -- Get device pointer associated with specific host address.
2916 @table @asis
2917 @item @emph{Description}
2918 This function returns the device address that has been mapped to the
2919 host address specified by @var{h}.
2921 @item @emph{C/C++}:
2922 @multitable @columnfractions .20 .80
2923 @item @emph{Prototype}: @tab @code{void *acc_deviceptr(h_void *h);}
2924 @end multitable
2926 @item @emph{Reference}:
2927 @uref{https://www.openacc.org, OpenACC specification v2.6}, section
2928 3.2.28.
2929 @end table
2933 @node acc_hostptr
2934 @section @code{acc_hostptr} -- Get host pointer associated with specific device address.
2935 @table @asis
2936 @item @emph{Description}
2937 This function returns the host address that has been mapped to the
2938 device address specified by @var{d}.
2940 @item @emph{C/C++}:
2941 @multitable @columnfractions .20 .80
2942 @item @emph{Prototype}: @tab @code{void *acc_hostptr(d_void *d);}
2943 @end multitable
2945 @item @emph{Reference}:
2946 @uref{https://www.openacc.org, OpenACC specification v2.6}, section
2947 3.2.29.
2948 @end table
2952 @node acc_is_present
2953 @section @code{acc_is_present} -- Indicate whether host variable / array is present on device.
2954 @table @asis
2955 @item @emph{Description}
2956 This function indicates whether the specified host address in @var{a} and a
2957 length of @var{len} bytes is present on the device. In C/C++, a non-zero
2958 value is returned to indicate the presence of the mapped memory on the
2959 device. A zero is returned to indicate the memory is not mapped on the
2960 device.
2962 In Fortran, two (2) forms are supported. In the first form, @var{a} specifies
2963 a contiguous array section. The second form @var{a} specifies a variable or
2964 array element and @var{len} specifies the length in bytes. If the host
2965 memory is mapped to device memory, then a @code{true} is returned. Otherwise,
2966 a @code{false} is return to indicate the mapped memory is not present.
2968 @item @emph{C/C++}:
2969 @multitable @columnfractions .20 .80
2970 @item @emph{Prototype}: @tab @code{int acc_is_present(h_void *a, size_t len);}
2971 @end multitable
2973 @item @emph{Fortran}:
2974 @multitable @columnfractions .20 .80
2975 @item @emph{Interface}: @tab @code{function acc_is_present(a)}
2976 @item                   @tab @code{type, dimension(:[,:]...) :: a}
2977 @item                   @tab @code{logical acc_is_present}
2978 @item @emph{Interface}: @tab @code{function acc_is_present(a, len)}
2979 @item                   @tab @code{type, dimension(:[,:]...) :: a}
2980 @item                   @tab @code{integer len}
2981 @item                   @tab @code{logical acc_is_present}
2982 @end multitable
2984 @item @emph{Reference}:
2985 @uref{https://www.openacc.org, OpenACC specification v2.6}, section
2986 3.2.30.
2987 @end table
2991 @node acc_memcpy_to_device
2992 @section @code{acc_memcpy_to_device} -- Copy host memory to device memory.
2993 @table @asis
2994 @item @emph{Description}
2995 This function copies host memory specified by host address of @var{src} to
2996 device memory specified by the device address @var{dest} for a length of
2997 @var{bytes} bytes.
2999 @item @emph{C/C++}:
3000 @multitable @columnfractions .20 .80
3001 @item @emph{Prototype}: @tab @code{acc_memcpy_to_device(d_void *dest, h_void *src, size_t bytes);}
3002 @end multitable
3004 @item @emph{Reference}:
3005 @uref{https://www.openacc.org, OpenACC specification v2.6}, section
3006 3.2.31.
3007 @end table
3011 @node acc_memcpy_from_device
3012 @section @code{acc_memcpy_from_device} -- Copy device memory to host memory.
3013 @table @asis
3014 @item @emph{Description}
3015 This function copies host memory specified by host address of @var{src} from
3016 device memory specified by the device address @var{dest} for a length of
3017 @var{bytes} bytes.
3019 @item @emph{C/C++}:
3020 @multitable @columnfractions .20 .80
3021 @item @emph{Prototype}: @tab @code{acc_memcpy_from_device(d_void *dest, h_void *src, size_t bytes);}
3022 @end multitable
3024 @item @emph{Reference}:
3025 @uref{https://www.openacc.org, OpenACC specification v2.6}, section
3026 3.2.32.
3027 @end table
3031 @node acc_attach
3032 @section @code{acc_attach} -- Let device pointer point to device-pointer target.
3033 @table @asis
3034 @item @emph{Description}
3035 This function updates a pointer on the device from pointing to a host-pointer
3036 address to pointing to the corresponding device data.
3038 @item @emph{C/C++}:
3039 @multitable @columnfractions .20 .80
3040 @item @emph{Prototype}: @tab @code{acc_attach(h_void **ptr);}
3041 @item @emph{Prototype}: @tab @code{acc_attach_async(h_void **ptr, int async);}
3042 @end multitable
3044 @item @emph{Reference}:
3045 @uref{https://www.openacc.org, OpenACC specification v2.6}, section
3046 3.2.34.
3047 @end table
3051 @node acc_detach
3052 @section @code{acc_detach} -- Let device pointer point to host-pointer target.
3053 @table @asis
3054 @item @emph{Description}
3055 This function updates a pointer on the device from pointing to a device-pointer
3056 address to pointing to the corresponding host data.
3058 @item @emph{C/C++}:
3059 @multitable @columnfractions .20 .80
3060 @item @emph{Prototype}: @tab @code{acc_detach(h_void **ptr);}
3061 @item @emph{Prototype}: @tab @code{acc_detach_async(h_void **ptr, int async);}
3062 @item @emph{Prototype}: @tab @code{acc_detach_finalize(h_void **ptr);}
3063 @item @emph{Prototype}: @tab @code{acc_detach_finalize_async(h_void **ptr, int async);}
3064 @end multitable
3066 @item @emph{Reference}:
3067 @uref{https://www.openacc.org, OpenACC specification v2.6}, section
3068 3.2.35.
3069 @end table
3073 @node acc_get_current_cuda_device
3074 @section @code{acc_get_current_cuda_device} -- Get CUDA device handle.
3075 @table @asis
3076 @item @emph{Description}
3077 This function returns the CUDA device handle. This handle is the same
3078 as used by the CUDA Runtime or Driver API's.
3080 @item @emph{C/C++}:
3081 @multitable @columnfractions .20 .80
3082 @item @emph{Prototype}: @tab @code{void *acc_get_current_cuda_device(void);}
3083 @end multitable
3085 @item @emph{Reference}:
3086 @uref{https://www.openacc.org, OpenACC specification v2.6}, section
3087 A.2.1.1.
3088 @end table
3092 @node acc_get_current_cuda_context
3093 @section @code{acc_get_current_cuda_context} -- Get CUDA context handle.
3094 @table @asis
3095 @item @emph{Description}
3096 This function returns the CUDA context handle. This handle is the same
3097 as used by the CUDA Runtime or Driver API's.
3099 @item @emph{C/C++}:
3100 @multitable @columnfractions .20 .80
3101 @item @emph{Prototype}: @tab @code{void *acc_get_current_cuda_context(void);}
3102 @end multitable
3104 @item @emph{Reference}:
3105 @uref{https://www.openacc.org, OpenACC specification v2.6}, section
3106 A.2.1.2.
3107 @end table
3111 @node acc_get_cuda_stream
3112 @section @code{acc_get_cuda_stream} -- Get CUDA stream handle.
3113 @table @asis
3114 @item @emph{Description}
3115 This function returns the CUDA stream handle for the queue @var{async}.
3116 This handle is the same as used by the CUDA Runtime or Driver API's.
3118 @item @emph{C/C++}:
3119 @multitable @columnfractions .20 .80
3120 @item @emph{Prototype}: @tab @code{void *acc_get_cuda_stream(int async);}
3121 @end multitable
3123 @item @emph{Reference}:
3124 @uref{https://www.openacc.org, OpenACC specification v2.6}, section
3125 A.2.1.3.
3126 @end table
3130 @node acc_set_cuda_stream
3131 @section @code{acc_set_cuda_stream} -- Set CUDA stream handle.
3132 @table @asis
3133 @item @emph{Description}
3134 This function associates the stream handle specified by @var{stream} with
3135 the queue @var{async}.
3137 This cannot be used to change the stream handle associated with
3138 @code{acc_async_sync}.
3140 The return value is not specified.
3142 @item @emph{C/C++}:
3143 @multitable @columnfractions .20 .80
3144 @item @emph{Prototype}: @tab @code{int acc_set_cuda_stream(int async, void *stream);}
3145 @end multitable
3147 @item @emph{Reference}:
3148 @uref{https://www.openacc.org, OpenACC specification v2.6}, section
3149 A.2.1.4.
3150 @end table
3154 @node acc_prof_register
3155 @section @code{acc_prof_register} -- Register callbacks.
3156 @table @asis
3157 @item @emph{Description}:
3158 This function registers callbacks.
3160 @item @emph{C/C++}:
3161 @multitable @columnfractions .20 .80
3162 @item @emph{Prototype}: @tab @code{void acc_prof_register (acc_event_t, acc_prof_callback, acc_register_t);}
3163 @end multitable
3165 @item @emph{See also}:
3166 @ref{OpenACC Profiling Interface}
3168 @item @emph{Reference}:
3169 @uref{https://www.openacc.org, OpenACC specification v2.6}, section
3170 5.3.
3171 @end table
3175 @node acc_prof_unregister
3176 @section @code{acc_prof_unregister} -- Unregister callbacks.
3177 @table @asis
3178 @item @emph{Description}:
3179 This function unregisters callbacks.
3181 @item @emph{C/C++}:
3182 @multitable @columnfractions .20 .80
3183 @item @emph{Prototype}: @tab @code{void acc_prof_unregister (acc_event_t, acc_prof_callback, acc_register_t);}
3184 @end multitable
3186 @item @emph{See also}:
3187 @ref{OpenACC Profiling Interface}
3189 @item @emph{Reference}:
3190 @uref{https://www.openacc.org, OpenACC specification v2.6}, section
3191 5.3.
3192 @end table
3196 @node acc_prof_lookup
3197 @section @code{acc_prof_lookup} -- Obtain inquiry functions.
3198 @table @asis
3199 @item @emph{Description}:
3200 Function to obtain inquiry functions.
3202 @item @emph{C/C++}:
3203 @multitable @columnfractions .20 .80
3204 @item @emph{Prototype}: @tab @code{acc_query_fn acc_prof_lookup (const char *);}
3205 @end multitable
3207 @item @emph{See also}:
3208 @ref{OpenACC Profiling Interface}
3210 @item @emph{Reference}:
3211 @uref{https://www.openacc.org, OpenACC specification v2.6}, section
3212 5.3.
3213 @end table
3217 @node acc_register_library
3218 @section @code{acc_register_library} -- Library registration.
3219 @table @asis
3220 @item @emph{Description}:
3221 Function for library registration.
3223 @item @emph{C/C++}:
3224 @multitable @columnfractions .20 .80
3225 @item @emph{Prototype}: @tab @code{void acc_register_library (acc_prof_reg, acc_prof_reg, acc_prof_lookup_func);}
3226 @end multitable
3228 @item @emph{See also}:
3229 @ref{OpenACC Profiling Interface}, @ref{ACC_PROFLIB}
3231 @item @emph{Reference}:
3232 @uref{https://www.openacc.org, OpenACC specification v2.6}, section
3233 5.3.
3234 @end table
3238 @c ---------------------------------------------------------------------
3239 @c OpenACC Environment Variables
3240 @c ---------------------------------------------------------------------
3242 @node OpenACC Environment Variables
3243 @chapter OpenACC Environment Variables
3245 The variables @env{ACC_DEVICE_TYPE} and @env{ACC_DEVICE_NUM}
3246 are defined by section 4 of the OpenACC specification in version 2.0.
3247 The variable @env{ACC_PROFLIB}
3248 is defined by section 4 of the OpenACC specification in version 2.6.
3249 The variable @env{GCC_ACC_NOTIFY} is used for diagnostic purposes.
3251 @menu
3252 * ACC_DEVICE_TYPE::
3253 * ACC_DEVICE_NUM::
3254 * ACC_PROFLIB::
3255 * GCC_ACC_NOTIFY::
3256 @end menu
3260 @node ACC_DEVICE_TYPE
3261 @section @code{ACC_DEVICE_TYPE}
3262 @table @asis
3263 @item @emph{Reference}:
3264 @uref{https://www.openacc.org, OpenACC specification v2.6}, section
3265 4.1.
3266 @end table
3270 @node ACC_DEVICE_NUM
3271 @section @code{ACC_DEVICE_NUM}
3272 @table @asis
3273 @item @emph{Reference}:
3274 @uref{https://www.openacc.org, OpenACC specification v2.6}, section
3275 4.2.
3276 @end table
3280 @node ACC_PROFLIB
3281 @section @code{ACC_PROFLIB}
3282 @table @asis
3283 @item @emph{See also}:
3284 @ref{acc_register_library}, @ref{OpenACC Profiling Interface}
3286 @item @emph{Reference}:
3287 @uref{https://www.openacc.org, OpenACC specification v2.6}, section
3288 4.3.
3289 @end table
3293 @node GCC_ACC_NOTIFY
3294 @section @code{GCC_ACC_NOTIFY}
3295 @table @asis
3296 @item @emph{Description}:
3297 Print debug information pertaining to the accelerator.
3298 @end table
3302 @c ---------------------------------------------------------------------
3303 @c CUDA Streams Usage
3304 @c ---------------------------------------------------------------------
3306 @node CUDA Streams Usage
3307 @chapter CUDA Streams Usage
3309 This applies to the @code{nvptx} plugin only.
3311 The library provides elements that perform asynchronous movement of
3312 data and asynchronous operation of computing constructs.  This
3313 asynchronous functionality is implemented by making use of CUDA
3314 streams@footnote{See "Stream Management" in "CUDA Driver API",
3315 TRM-06703-001, Version 5.5, for additional information}.
3317 The primary means by that the asynchronous functionality is accessed
3318 is through the use of those OpenACC directives which make use of the
3319 @code{async} and @code{wait} clauses.  When the @code{async} clause is
3320 first used with a directive, it creates a CUDA stream.  If an
3321 @code{async-argument} is used with the @code{async} clause, then the
3322 stream is associated with the specified @code{async-argument}.
3324 Following the creation of an association between a CUDA stream and the
3325 @code{async-argument} of an @code{async} clause, both the @code{wait}
3326 clause and the @code{wait} directive can be used.  When either the
3327 clause or directive is used after stream creation, it creates a
3328 rendezvous point whereby execution waits until all operations
3329 associated with the @code{async-argument}, that is, stream, have
3330 completed.
3332 Normally, the management of the streams that are created as a result of
3333 using the @code{async} clause, is done without any intervention by the
3334 caller.  This implies the association between the @code{async-argument}
3335 and the CUDA stream will be maintained for the lifetime of the program.
3336 However, this association can be changed through the use of the library
3337 function @code{acc_set_cuda_stream}.  When the function
3338 @code{acc_set_cuda_stream} is called, the CUDA stream that was
3339 originally associated with the @code{async} clause will be destroyed.
3340 Caution should be taken when changing the association as subsequent
3341 references to the @code{async-argument} refer to a different
3342 CUDA stream.
3346 @c ---------------------------------------------------------------------
3347 @c OpenACC Library Interoperability
3348 @c ---------------------------------------------------------------------
3350 @node OpenACC Library Interoperability
3351 @chapter OpenACC Library Interoperability
3353 @section Introduction
3355 The OpenACC library uses the CUDA Driver API, and may interact with
3356 programs that use the Runtime library directly, or another library
3357 based on the Runtime library, e.g., CUBLAS@footnote{See section 2.26,
3358 "Interactions with the CUDA Driver API" in
3359 "CUDA Runtime API", Version 5.5, and section 2.27, "VDPAU
3360 Interoperability", in "CUDA Driver API", TRM-06703-001, Version 5.5,
3361 for additional information on library interoperability.}.
3362 This chapter describes the use cases and what changes are
3363 required in order to use both the OpenACC library and the CUBLAS and Runtime
3364 libraries within a program.
3366 @section First invocation: NVIDIA CUBLAS library API
3368 In this first use case (see below), a function in the CUBLAS library is called
3369 prior to any of the functions in the OpenACC library. More specifically, the
3370 function @code{cublasCreate()}.
3372 When invoked, the function initializes the library and allocates the
3373 hardware resources on the host and the device on behalf of the caller. Once
3374 the initialization and allocation has completed, a handle is returned to the
3375 caller. The OpenACC library also requires initialization and allocation of
3376 hardware resources. Since the CUBLAS library has already allocated the
3377 hardware resources for the device, all that is left to do is to initialize
3378 the OpenACC library and acquire the hardware resources on the host.
3380 Prior to calling the OpenACC function that initializes the library and
3381 allocate the host hardware resources, you need to acquire the device number
3382 that was allocated during the call to @code{cublasCreate()}. The invoking of the
3383 runtime library function @code{cudaGetDevice()} accomplishes this. Once
3384 acquired, the device number is passed along with the device type as
3385 parameters to the OpenACC library function @code{acc_set_device_num()}.
3387 Once the call to @code{acc_set_device_num()} has completed, the OpenACC
3388 library uses the  context that was created during the call to
3389 @code{cublasCreate()}. In other words, both libraries will be sharing the
3390 same context.
3392 @smallexample
3393     /* Create the handle */
3394     s = cublasCreate(&h);
3395     if (s != CUBLAS_STATUS_SUCCESS)
3396     @{
3397         fprintf(stderr, "cublasCreate failed %d\n", s);
3398         exit(EXIT_FAILURE);
3399     @}
3401     /* Get the device number */
3402     e = cudaGetDevice(&dev);
3403     if (e != cudaSuccess)
3404     @{
3405         fprintf(stderr, "cudaGetDevice failed %d\n", e);
3406         exit(EXIT_FAILURE);
3407     @}
3409     /* Initialize OpenACC library and use device 'dev' */
3410     acc_set_device_num(dev, acc_device_nvidia);
3412 @end smallexample
3413 @center Use Case 1 
3415 @section First invocation: OpenACC library API
3417 In this second use case (see below), a function in the OpenACC library is
3418 called prior to any of the functions in the CUBLAS library. More specificially,
3419 the function @code{acc_set_device_num()}.
3421 In the use case presented here, the function @code{acc_set_device_num()}
3422 is used to both initialize the OpenACC library and allocate the hardware
3423 resources on the host and the device. In the call to the function, the
3424 call parameters specify which device to use and what device
3425 type to use, i.e., @code{acc_device_nvidia}. It should be noted that this
3426 is but one method to initialize the OpenACC library and allocate the
3427 appropriate hardware resources. Other methods are available through the
3428 use of environment variables and these will be discussed in the next section.
3430 Once the call to @code{acc_set_device_num()} has completed, other OpenACC
3431 functions can be called as seen with multiple calls being made to
3432 @code{acc_copyin()}. In addition, calls can be made to functions in the
3433 CUBLAS library. In the use case a call to @code{cublasCreate()} is made
3434 subsequent to the calls to @code{acc_copyin()}.
3435 As seen in the previous use case, a call to @code{cublasCreate()}
3436 initializes the CUBLAS library and allocates the hardware resources on the
3437 host and the device.  However, since the device has already been allocated,
3438 @code{cublasCreate()} will only initialize the CUBLAS library and allocate
3439 the appropriate hardware resources on the host. The context that was created
3440 as part of the OpenACC initialization is shared with the CUBLAS library,
3441 similarly to the first use case.
3443 @smallexample
3444     dev = 0;
3446     acc_set_device_num(dev, acc_device_nvidia);
3448     /* Copy the first set to the device */
3449     d_X = acc_copyin(&h_X[0], N * sizeof (float));
3450     if (d_X == NULL)
3451     @{ 
3452         fprintf(stderr, "copyin error h_X\n");
3453         exit(EXIT_FAILURE);
3454     @}
3456     /* Copy the second set to the device */
3457     d_Y = acc_copyin(&h_Y1[0], N * sizeof (float));
3458     if (d_Y == NULL)
3459     @{ 
3460         fprintf(stderr, "copyin error h_Y1\n");
3461         exit(EXIT_FAILURE);
3462     @}
3464     /* Create the handle */
3465     s = cublasCreate(&h);
3466     if (s != CUBLAS_STATUS_SUCCESS)
3467     @{
3468         fprintf(stderr, "cublasCreate failed %d\n", s);
3469         exit(EXIT_FAILURE);
3470     @}
3472     /* Perform saxpy using CUBLAS library function */
3473     s = cublasSaxpy(h, N, &alpha, d_X, 1, d_Y, 1);
3474     if (s != CUBLAS_STATUS_SUCCESS)
3475     @{
3476         fprintf(stderr, "cublasSaxpy failed %d\n", s);
3477         exit(EXIT_FAILURE);
3478     @}
3480     /* Copy the results from the device */
3481     acc_memcpy_from_device(&h_Y1[0], d_Y, N * sizeof (float));
3483 @end smallexample
3484 @center Use Case 2
3486 @section OpenACC library and environment variables
3488 There are two environment variables associated with the OpenACC library
3489 that may be used to control the device type and device number:
3490 @env{ACC_DEVICE_TYPE} and @env{ACC_DEVICE_NUM}, respectively. These two
3491 environment variables can be used as an alternative to calling
3492 @code{acc_set_device_num()}. As seen in the second use case, the device
3493 type and device number were specified using @code{acc_set_device_num()}.
3494 If however, the aforementioned environment variables were set, then the
3495 call to @code{acc_set_device_num()} would not be required.
3498 The use of the environment variables is only relevant when an OpenACC function
3499 is called prior to a call to @code{cudaCreate()}. If @code{cudaCreate()}
3500 is called prior to a call to an OpenACC function, then you must call
3501 @code{acc_set_device_num()}@footnote{More complete information
3502 about @env{ACC_DEVICE_TYPE} and @env{ACC_DEVICE_NUM} can be found in
3503 sections 4.1 and 4.2 of the @uref{https://www.openacc.org, OpenACC}
3504 Application Programming Interface”, Version 2.6.}
3508 @c ---------------------------------------------------------------------
3509 @c OpenACC Profiling Interface
3510 @c ---------------------------------------------------------------------
3512 @node OpenACC Profiling Interface
3513 @chapter OpenACC Profiling Interface
3515 @section Implementation Status and Implementation-Defined Behavior
3517 We're implementing the OpenACC Profiling Interface as defined by the
3518 OpenACC 2.6 specification.  We're clarifying some aspects here as
3519 @emph{implementation-defined behavior}, while they're still under
3520 discussion within the OpenACC Technical Committee.
3522 This implementation is tuned to keep the performance impact as low as
3523 possible for the (very common) case that the Profiling Interface is
3524 not enabled.  This is relevant, as the Profiling Interface affects all
3525 the @emph{hot} code paths (in the target code, not in the offloaded
3526 code).  Users of the OpenACC Profiling Interface can be expected to
3527 understand that performance will be impacted to some degree once the
3528 Profiling Interface has gotten enabled: for example, because of the
3529 @emph{runtime} (libgomp) calling into a third-party @emph{library} for
3530 every event that has been registered.
3532 We're not yet accounting for the fact that @cite{OpenACC events may
3533 occur during event processing}.
3534 We just handle one case specially, as required by CUDA 9.0
3535 @command{nvprof}, that @code{acc_get_device_type}
3536 (@ref{acc_get_device_type})) may be called from
3537 @code{acc_ev_device_init_start}, @code{acc_ev_device_init_end}
3538 callbacks.
3540 We're not yet implementing initialization via a
3541 @code{acc_register_library} function that is either statically linked
3542 in, or dynamically via @env{LD_PRELOAD}.
3543 Initialization via @code{acc_register_library} functions dynamically
3544 loaded via the @env{ACC_PROFLIB} environment variable does work, as
3545 does directly calling @code{acc_prof_register},
3546 @code{acc_prof_unregister}, @code{acc_prof_lookup}.
3548 As currently there are no inquiry functions defined, calls to
3549 @code{acc_prof_lookup} will always return @code{NULL}.
3551 There aren't separate @emph{start}, @emph{stop} events defined for the
3552 event types @code{acc_ev_create}, @code{acc_ev_delete},
3553 @code{acc_ev_alloc}, @code{acc_ev_free}.  It's not clear if these
3554 should be triggered before or after the actual device-specific call is
3555 made.  We trigger them after.
3557 Remarks about data provided to callbacks:
3559 @table @asis
3561 @item @code{acc_prof_info.event_type}
3562 It's not clear if for @emph{nested} event callbacks (for example,
3563 @code{acc_ev_enqueue_launch_start} as part of a parent compute
3564 construct), this should be set for the nested event
3565 (@code{acc_ev_enqueue_launch_start}), or if the value of the parent
3566 construct should remain (@code{acc_ev_compute_construct_start}).  In
3567 this implementation, the value will generally correspond to the
3568 innermost nested event type.
3570 @item @code{acc_prof_info.device_type}
3571 @itemize
3573 @item
3574 For @code{acc_ev_compute_construct_start}, and in presence of an
3575 @code{if} clause with @emph{false} argument, this will still refer to
3576 the offloading device type.
3577 It's not clear if that's the expected behavior.
3579 @item
3580 Complementary to the item before, for
3581 @code{acc_ev_compute_construct_end}, this is set to
3582 @code{acc_device_host} in presence of an @code{if} clause with
3583 @emph{false} argument.
3584 It's not clear if that's the expected behavior.
3586 @end itemize
3588 @item @code{acc_prof_info.thread_id}
3589 Always @code{-1}; not yet implemented.
3591 @item @code{acc_prof_info.async}
3592 @itemize
3594 @item
3595 Not yet implemented correctly for
3596 @code{acc_ev_compute_construct_start}.
3598 @item
3599 In a compute construct, for host-fallback
3600 execution/@code{acc_device_host} it will always be
3601 @code{acc_async_sync}.
3602 It's not clear if that's the expected behavior.
3604 @item
3605 For @code{acc_ev_device_init_start} and @code{acc_ev_device_init_end},
3606 it will always be @code{acc_async_sync}.
3607 It's not clear if that's the expected behavior.
3609 @end itemize
3611 @item @code{acc_prof_info.async_queue}
3612 There is no @cite{limited number of asynchronous queues} in libgomp.
3613 This will always have the same value as @code{acc_prof_info.async}.
3615 @item @code{acc_prof_info.src_file}
3616 Always @code{NULL}; not yet implemented.
3618 @item @code{acc_prof_info.func_name}
3619 Always @code{NULL}; not yet implemented.
3621 @item @code{acc_prof_info.line_no}
3622 Always @code{-1}; not yet implemented.
3624 @item @code{acc_prof_info.end_line_no}
3625 Always @code{-1}; not yet implemented.
3627 @item @code{acc_prof_info.func_line_no}
3628 Always @code{-1}; not yet implemented.
3630 @item @code{acc_prof_info.func_end_line_no}
3631 Always @code{-1}; not yet implemented.
3633 @item @code{acc_event_info.event_type}, @code{acc_event_info.*.event_type}
3634 Relating to @code{acc_prof_info.event_type} discussed above, in this
3635 implementation, this will always be the same value as
3636 @code{acc_prof_info.event_type}.
3638 @item @code{acc_event_info.*.parent_construct}
3639 @itemize
3641 @item
3642 Will be @code{acc_construct_parallel} for all OpenACC compute
3643 constructs as well as many OpenACC Runtime API calls; should be the
3644 one matching the actual construct, or
3645 @code{acc_construct_runtime_api}, respectively.
3647 @item
3648 Will be @code{acc_construct_enter_data} or
3649 @code{acc_construct_exit_data} when processing variable mappings
3650 specified in OpenACC @emph{declare} directives; should be
3651 @code{acc_construct_declare}.
3653 @item
3654 For implicit @code{acc_ev_device_init_start},
3655 @code{acc_ev_device_init_end}, and explicit as well as implicit
3656 @code{acc_ev_alloc}, @code{acc_ev_free},
3657 @code{acc_ev_enqueue_upload_start}, @code{acc_ev_enqueue_upload_end},
3658 @code{acc_ev_enqueue_download_start}, and
3659 @code{acc_ev_enqueue_download_end}, will be
3660 @code{acc_construct_parallel}; should reflect the real parent
3661 construct.
3663 @end itemize
3665 @item @code{acc_event_info.*.implicit}
3666 For @code{acc_ev_alloc}, @code{acc_ev_free},
3667 @code{acc_ev_enqueue_upload_start}, @code{acc_ev_enqueue_upload_end},
3668 @code{acc_ev_enqueue_download_start}, and
3669 @code{acc_ev_enqueue_download_end}, this currently will be @code{1}
3670 also for explicit usage.
3672 @item @code{acc_event_info.data_event.var_name}
3673 Always @code{NULL}; not yet implemented.
3675 @item @code{acc_event_info.data_event.host_ptr}
3676 For @code{acc_ev_alloc}, and @code{acc_ev_free}, this is always
3677 @code{NULL}.
3679 @item @code{typedef union acc_api_info}
3680 @dots{} as printed in @cite{5.2.3. Third Argument: API-Specific
3681 Information}.  This should obviously be @code{typedef @emph{struct}
3682 acc_api_info}.
3684 @item @code{acc_api_info.device_api}
3685 Possibly not yet implemented correctly for
3686 @code{acc_ev_compute_construct_start},
3687 @code{acc_ev_device_init_start}, @code{acc_ev_device_init_end}:
3688 will always be @code{acc_device_api_none} for these event types.
3689 For @code{acc_ev_enter_data_start}, it will be
3690 @code{acc_device_api_none} in some cases.
3692 @item @code{acc_api_info.device_type}
3693 Always the same as @code{acc_prof_info.device_type}.
3695 @item @code{acc_api_info.vendor}
3696 Always @code{-1}; not yet implemented.
3698 @item @code{acc_api_info.device_handle}
3699 Always @code{NULL}; not yet implemented.
3701 @item @code{acc_api_info.context_handle}
3702 Always @code{NULL}; not yet implemented.
3704 @item @code{acc_api_info.async_handle}
3705 Always @code{NULL}; not yet implemented.
3707 @end table
3709 Remarks about certain event types:
3711 @table @asis
3713 @item @code{acc_ev_device_init_start}, @code{acc_ev_device_init_end}
3714 @itemize
3716 @item
3717 @c See 'DEVICE_INIT_INSIDE_COMPUTE_CONSTRUCT' in
3718 @c 'libgomp.oacc-c-c++-common/acc_prof-kernels-1.c',
3719 @c 'libgomp.oacc-c-c++-common/acc_prof-parallel-1.c'.
3720 Whan a compute construct triggers implicit
3721 @code{acc_ev_device_init_start} and @code{acc_ev_device_init_end}
3722 events, they currently aren't @emph{nested within} the corresponding
3723 @code{acc_ev_compute_construct_start} and
3724 @code{acc_ev_compute_construct_end}, but they're currently observed
3725 @emph{before} @code{acc_ev_compute_construct_start}.
3726 It's not clear what to do: the standard asks us provide a lot of
3727 details to the @code{acc_ev_compute_construct_start} callback, without
3728 (implicitly) initializing a device before?
3730 @item
3731 Callbacks for these event types will not be invoked for calls to the
3732 @code{acc_set_device_type} and @code{acc_set_device_num} functions.
3733 It's not clear if they should be.
3735 @end itemize
3737 @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}
3738 @itemize
3740 @item
3741 Callbacks for these event types will also be invoked for OpenACC
3742 @emph{host_data} constructs.
3743 It's not clear if they should be.
3745 @item
3746 Callbacks for these event types will also be invoked when processing
3747 variable mappings specified in OpenACC @emph{declare} directives.
3748 It's not clear if they should be.
3750 @end itemize
3752 @end table
3754 Callbacks for the following event types will be invoked, but dispatch
3755 and information provided therein has not yet been thoroughly reviewed:
3757 @itemize
3758 @item @code{acc_ev_alloc}
3759 @item @code{acc_ev_free}
3760 @item @code{acc_ev_update_start}, @code{acc_ev_update_end}
3761 @item @code{acc_ev_enqueue_upload_start}, @code{acc_ev_enqueue_upload_end}
3762 @item @code{acc_ev_enqueue_download_start}, @code{acc_ev_enqueue_download_end}
3763 @end itemize
3765 During device initialization, and finalization, respectively,
3766 callbacks for the following event types will not yet be invoked:
3768 @itemize
3769 @item @code{acc_ev_alloc}
3770 @item @code{acc_ev_free}
3771 @end itemize
3773 Callbacks for the following event types have not yet been implemented,
3774 so currently won't be invoked:
3776 @itemize
3777 @item @code{acc_ev_device_shutdown_start}, @code{acc_ev_device_shutdown_end}
3778 @item @code{acc_ev_runtime_shutdown}
3779 @item @code{acc_ev_create}, @code{acc_ev_delete}
3780 @item @code{acc_ev_wait_start}, @code{acc_ev_wait_end}
3781 @end itemize
3783 For the following runtime library functions, not all expected
3784 callbacks will be invoked (mostly concerning implicit device
3785 initialization):
3787 @itemize
3788 @item @code{acc_get_num_devices}
3789 @item @code{acc_set_device_type}
3790 @item @code{acc_get_device_type}
3791 @item @code{acc_set_device_num}
3792 @item @code{acc_get_device_num}
3793 @item @code{acc_init}
3794 @item @code{acc_shutdown}
3795 @end itemize
3797 Aside from implicit device initialization, for the following runtime
3798 library functions, no callbacks will be invoked for shared-memory
3799 offloading devices (it's not clear if they should be):
3801 @itemize
3802 @item @code{acc_malloc}
3803 @item @code{acc_free}
3804 @item @code{acc_copyin}, @code{acc_present_or_copyin}, @code{acc_copyin_async}
3805 @item @code{acc_create}, @code{acc_present_or_create}, @code{acc_create_async}
3806 @item @code{acc_copyout}, @code{acc_copyout_async}, @code{acc_copyout_finalize}, @code{acc_copyout_finalize_async}
3807 @item @code{acc_delete}, @code{acc_delete_async}, @code{acc_delete_finalize}, @code{acc_delete_finalize_async}
3808 @item @code{acc_update_device}, @code{acc_update_device_async}
3809 @item @code{acc_update_self}, @code{acc_update_self_async}
3810 @item @code{acc_map_data}, @code{acc_unmap_data}
3811 @item @code{acc_memcpy_to_device}, @code{acc_memcpy_to_device_async}
3812 @item @code{acc_memcpy_from_device}, @code{acc_memcpy_from_device_async}
3813 @end itemize
3817 @c ---------------------------------------------------------------------
3818 @c The libgomp ABI
3819 @c ---------------------------------------------------------------------
3821 @node The libgomp ABI
3822 @chapter The libgomp ABI
3824 The following sections present notes on the external ABI as 
3825 presented by libgomp.  Only maintainers should need them.
3827 @menu
3828 * Implementing MASTER construct::
3829 * Implementing CRITICAL construct::
3830 * Implementing ATOMIC construct::
3831 * Implementing FLUSH construct::
3832 * Implementing BARRIER construct::
3833 * Implementing THREADPRIVATE construct::
3834 * Implementing PRIVATE clause::
3835 * Implementing FIRSTPRIVATE LASTPRIVATE COPYIN and COPYPRIVATE clauses::
3836 * Implementing REDUCTION clause::
3837 * Implementing PARALLEL construct::
3838 * Implementing FOR construct::
3839 * Implementing ORDERED construct::
3840 * Implementing SECTIONS construct::
3841 * Implementing SINGLE construct::
3842 * Implementing OpenACC's PARALLEL construct::
3843 @end menu
3846 @node Implementing MASTER construct
3847 @section Implementing MASTER construct
3849 @smallexample
3850 if (omp_get_thread_num () == 0)
3851   block
3852 @end smallexample
3854 Alternately, we generate two copies of the parallel subfunction
3855 and only include this in the version run by the master thread.
3856 Surely this is not worthwhile though...
3860 @node Implementing CRITICAL construct
3861 @section Implementing CRITICAL construct
3863 Without a specified name,
3865 @smallexample
3866   void GOMP_critical_start (void);
3867   void GOMP_critical_end (void);
3868 @end smallexample
3870 so that we don't get COPY relocations from libgomp to the main
3871 application.
3873 With a specified name, use omp_set_lock and omp_unset_lock with
3874 name being transformed into a variable declared like
3876 @smallexample
3877   omp_lock_t gomp_critical_user_<name> __attribute__((common))
3878 @end smallexample
3880 Ideally the ABI would specify that all zero is a valid unlocked
3881 state, and so we wouldn't need to initialize this at
3882 startup.
3886 @node Implementing ATOMIC construct
3887 @section Implementing ATOMIC construct
3889 The target should implement the @code{__sync} builtins.
3891 Failing that we could add
3893 @smallexample
3894   void GOMP_atomic_enter (void)
3895   void GOMP_atomic_exit (void)
3896 @end smallexample
3898 which reuses the regular lock code, but with yet another lock
3899 object private to the library.
3903 @node Implementing FLUSH construct
3904 @section Implementing FLUSH construct
3906 Expands to the @code{__sync_synchronize} builtin.
3910 @node Implementing BARRIER construct
3911 @section Implementing BARRIER construct
3913 @smallexample
3914   void GOMP_barrier (void)
3915 @end smallexample
3918 @node Implementing THREADPRIVATE construct
3919 @section Implementing THREADPRIVATE construct
3921 In _most_ cases we can map this directly to @code{__thread}.  Except
3922 that OMP allows constructors for C++ objects.  We can either
3923 refuse to support this (how often is it used?) or we can 
3924 implement something akin to .ctors.
3926 Even more ideally, this ctor feature is handled by extensions
3927 to the main pthreads library.  Failing that, we can have a set
3928 of entry points to register ctor functions to be called.
3932 @node Implementing PRIVATE clause
3933 @section Implementing PRIVATE clause
3935 In association with a PARALLEL, or within the lexical extent
3936 of a PARALLEL block, the variable becomes a local variable in
3937 the parallel subfunction.
3939 In association with FOR or SECTIONS blocks, create a new
3940 automatic variable within the current function.  This preserves
3941 the semantic of new variable creation.
3945 @node Implementing FIRSTPRIVATE LASTPRIVATE COPYIN and COPYPRIVATE clauses
3946 @section Implementing FIRSTPRIVATE LASTPRIVATE COPYIN and COPYPRIVATE clauses
3948 This seems simple enough for PARALLEL blocks.  Create a private 
3949 struct for communicating between the parent and subfunction.
3950 In the parent, copy in values for scalar and "small" structs;
3951 copy in addresses for others TREE_ADDRESSABLE types.  In the 
3952 subfunction, copy the value into the local variable.
3954 It is not clear what to do with bare FOR or SECTION blocks.
3955 The only thing I can figure is that we do something like:
3957 @smallexample
3958 #pragma omp for firstprivate(x) lastprivate(y)
3959 for (int i = 0; i < n; ++i)
3960   body;
3961 @end smallexample
3963 which becomes
3965 @smallexample
3967   int x = x, y;
3969   // for stuff
3971   if (i == n)
3972     y = y;
3974 @end smallexample
3976 where the "x=x" and "y=y" assignments actually have different
3977 uids for the two variables, i.e. not something you could write
3978 directly in C.  Presumably this only makes sense if the "outer"
3979 x and y are global variables.
3981 COPYPRIVATE would work the same way, except the structure 
3982 broadcast would have to happen via SINGLE machinery instead.
3986 @node Implementing REDUCTION clause
3987 @section Implementing REDUCTION clause
3989 The private struct mentioned in the previous section should have 
3990 a pointer to an array of the type of the variable, indexed by the 
3991 thread's @var{team_id}.  The thread stores its final value into the 
3992 array, and after the barrier, the master thread iterates over the
3993 array to collect the values.
3996 @node Implementing PARALLEL construct
3997 @section Implementing PARALLEL construct
3999 @smallexample
4000   #pragma omp parallel
4001   @{
4002     body;
4003   @}
4004 @end smallexample
4006 becomes
4008 @smallexample
4009   void subfunction (void *data)
4010   @{
4011     use data;
4012     body;
4013   @}
4015   setup data;
4016   GOMP_parallel_start (subfunction, &data, num_threads);
4017   subfunction (&data);
4018   GOMP_parallel_end ();
4019 @end smallexample
4021 @smallexample
4022   void GOMP_parallel_start (void (*fn)(void *), void *data, unsigned num_threads)
4023 @end smallexample
4025 The @var{FN} argument is the subfunction to be run in parallel.
4027 The @var{DATA} argument is a pointer to a structure used to 
4028 communicate data in and out of the subfunction, as discussed
4029 above with respect to FIRSTPRIVATE et al.
4031 The @var{NUM_THREADS} argument is 1 if an IF clause is present
4032 and false, or the value of the NUM_THREADS clause, if
4033 present, or 0.
4035 The function needs to create the appropriate number of
4036 threads and/or launch them from the dock.  It needs to
4037 create the team structure and assign team ids.
4039 @smallexample
4040   void GOMP_parallel_end (void)
4041 @end smallexample
4043 Tears down the team and returns us to the previous @code{omp_in_parallel()} state.
4047 @node Implementing FOR construct
4048 @section Implementing FOR construct
4050 @smallexample
4051   #pragma omp parallel for
4052   for (i = lb; i <= ub; i++)
4053     body;
4054 @end smallexample
4056 becomes
4058 @smallexample
4059   void subfunction (void *data)
4060   @{
4061     long _s0, _e0;
4062     while (GOMP_loop_static_next (&_s0, &_e0))
4063     @{
4064       long _e1 = _e0, i;
4065       for (i = _s0; i < _e1; i++)
4066         body;
4067     @}
4068     GOMP_loop_end_nowait ();
4069   @}
4071   GOMP_parallel_loop_static (subfunction, NULL, 0, lb, ub+1, 1, 0);
4072   subfunction (NULL);
4073   GOMP_parallel_end ();
4074 @end smallexample
4076 @smallexample
4077   #pragma omp for schedule(runtime)
4078   for (i = 0; i < n; i++)
4079     body;
4080 @end smallexample
4082 becomes
4084 @smallexample
4085   @{
4086     long i, _s0, _e0;
4087     if (GOMP_loop_runtime_start (0, n, 1, &_s0, &_e0))
4088       do @{
4089         long _e1 = _e0;
4090         for (i = _s0, i < _e0; i++)
4091           body;
4092       @} while (GOMP_loop_runtime_next (&_s0, _&e0));
4093     GOMP_loop_end ();
4094   @}
4095 @end smallexample
4097 Note that while it looks like there is trickiness to propagating
4098 a non-constant STEP, there isn't really.  We're explicitly allowed
4099 to evaluate it as many times as we want, and any variables involved
4100 should automatically be handled as PRIVATE or SHARED like any other
4101 variables.  So the expression should remain evaluable in the 
4102 subfunction.  We can also pull it into a local variable if we like,
4103 but since its supposed to remain unchanged, we can also not if we like.
4105 If we have SCHEDULE(STATIC), and no ORDERED, then we ought to be
4106 able to get away with no work-sharing context at all, since we can
4107 simply perform the arithmetic directly in each thread to divide up
4108 the iterations.  Which would mean that we wouldn't need to call any
4109 of these routines.
4111 There are separate routines for handling loops with an ORDERED
4112 clause.  Bookkeeping for that is non-trivial...
4116 @node Implementing ORDERED construct
4117 @section Implementing ORDERED construct
4119 @smallexample
4120   void GOMP_ordered_start (void)
4121   void GOMP_ordered_end (void)
4122 @end smallexample
4126 @node Implementing SECTIONS construct
4127 @section Implementing SECTIONS construct
4129 A block as 
4131 @smallexample
4132   #pragma omp sections
4133   @{
4134     #pragma omp section
4135     stmt1;
4136     #pragma omp section
4137     stmt2;
4138     #pragma omp section
4139     stmt3;
4140   @}
4141 @end smallexample
4143 becomes
4145 @smallexample
4146   for (i = GOMP_sections_start (3); i != 0; i = GOMP_sections_next ())
4147     switch (i)
4148       @{
4149       case 1:
4150         stmt1;
4151         break;
4152       case 2:
4153         stmt2;
4154         break;
4155       case 3:
4156         stmt3;
4157         break;
4158       @}
4159   GOMP_barrier ();
4160 @end smallexample
4163 @node Implementing SINGLE construct
4164 @section Implementing SINGLE construct
4166 A block like 
4168 @smallexample
4169   #pragma omp single
4170   @{
4171     body;
4172   @}
4173 @end smallexample
4175 becomes
4177 @smallexample
4178   if (GOMP_single_start ())
4179     body;
4180   GOMP_barrier ();
4181 @end smallexample
4183 while 
4185 @smallexample
4186   #pragma omp single copyprivate(x)
4187     body;
4188 @end smallexample
4190 becomes
4192 @smallexample
4193   datap = GOMP_single_copy_start ();
4194   if (datap == NULL)
4195     @{
4196       body;
4197       data.x = x;
4198       GOMP_single_copy_end (&data);
4199     @}
4200   else
4201     x = datap->x;
4202   GOMP_barrier ();
4203 @end smallexample
4207 @node Implementing OpenACC's PARALLEL construct
4208 @section Implementing OpenACC's PARALLEL construct
4210 @smallexample
4211   void GOACC_parallel ()
4212 @end smallexample
4216 @c ---------------------------------------------------------------------
4217 @c Reporting Bugs
4218 @c ---------------------------------------------------------------------
4220 @node Reporting Bugs
4221 @chapter Reporting Bugs
4223 Bugs in the GNU Offloading and Multi Processing Runtime Library should
4224 be reported via @uref{https://gcc.gnu.org/bugzilla/, Bugzilla}.  Please add
4225 "openacc", or "openmp", or both to the keywords field in the bug
4226 report, as appropriate.
4230 @c ---------------------------------------------------------------------
4231 @c GNU General Public License
4232 @c ---------------------------------------------------------------------
4234 @include gpl_v3.texi
4238 @c ---------------------------------------------------------------------
4239 @c GNU Free Documentation License
4240 @c ---------------------------------------------------------------------
4242 @include fdl.texi
4246 @c ---------------------------------------------------------------------
4247 @c Funding Free Software
4248 @c ---------------------------------------------------------------------
4250 @include funding.texi
4252 @c ---------------------------------------------------------------------
4253 @c Index
4254 @c ---------------------------------------------------------------------
4256 @node Library Index
4257 @unnumbered Library Index
4259 @printindex cp
4261 @bye