2018-01-22 Sebastian Perta <sebastian.perta@renesas.com>
[official-gcc.git] / libgomp / libgomp.texi
blobc994a404d06393da5d5096c38ab39c1ee2eadd5d
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-2018 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
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{http://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 * Runtime Library Routines::   The OpenMP runtime application programming 
99                                interface.
100 * Environment Variables::      Influencing runtime behavior with environment 
101                                variables.
102 * Enabling OpenACC::           How to enable OpenACC for your
103                                applications.
104 * OpenACC Runtime Library Routines:: The OpenACC runtime application
105                                programming interface.
106 * OpenACC Environment Variables:: Influencing OpenACC runtime behavior with
107                                environment variables.
108 * CUDA Streams Usage::         Notes on the implementation of
109                                asynchronous operations.
110 * OpenACC Library Interoperability:: OpenACC library interoperability with the
111                                NVIDIA CUBLAS library.
112 * The libgomp ABI::            Notes on the external ABI presented by libgomp.
113 * Reporting Bugs::             How to report bugs in the GNU Offloading and
114                                Multi Processing Runtime Library.
115 * Copying::                    GNU general public license says
116                                how you can copy and share libgomp.
117 * GNU Free Documentation License::
118                                How you can copy and share this manual.
119 * Funding::                    How to help assure continued work for free 
120                                software.
121 * Library Index::              Index of this documentation.
122 @end menu
125 @c ---------------------------------------------------------------------
126 @c Enabling OpenMP
127 @c ---------------------------------------------------------------------
129 @node Enabling OpenMP
130 @chapter Enabling OpenMP
132 To activate the OpenMP extensions for C/C++ and Fortran, the compile-time 
133 flag @command{-fopenmp} must be specified.  This enables the OpenMP directive
134 @code{#pragma omp} in C/C++ and @code{!$omp} directives in free form, 
135 @code{c$omp}, @code{*$omp} and @code{!$omp} directives in fixed form, 
136 @code{!$} conditional compilation sentinels in free form and @code{c$},
137 @code{*$} and @code{!$} sentinels in fixed form, for Fortran.  The flag also
138 arranges for automatic linking of the OpenMP runtime library 
139 (@ref{Runtime Library Routines}).
141 A complete description of all OpenMP directives accepted may be found in 
142 the @uref{http://www.openmp.org, OpenMP Application Program Interface} manual,
143 version 4.5.
146 @c ---------------------------------------------------------------------
147 @c Runtime Library Routines
148 @c ---------------------------------------------------------------------
150 @node Runtime Library Routines
151 @chapter Runtime Library Routines
153 The runtime routines described here are defined by Section 3 of the OpenMP
154 specification in version 4.5.  The routines are structured in following
155 three parts:
157 @menu
158 Control threads, processors and the parallel environment.  They have C
159 linkage, and do not throw exceptions.
161 * omp_get_active_level::        Number of active parallel regions
162 * omp_get_ancestor_thread_num:: Ancestor thread ID
163 * omp_get_cancellation::        Whether cancellation support is enabled
164 * omp_get_default_device::      Get the default device for target regions
165 * omp_get_dynamic::             Dynamic teams setting
166 * omp_get_level::               Number of parallel regions
167 * omp_get_max_active_levels::   Maximum number of active regions
168 * omp_get_max_task_priority::   Maximum task priority value that can be set
169 * omp_get_max_threads::         Maximum number of threads of parallel region
170 * omp_get_nested::              Nested parallel regions
171 * omp_get_num_devices::         Number of target devices
172 * omp_get_num_procs::           Number of processors online
173 * omp_get_num_teams::           Number of teams
174 * omp_get_num_threads::         Size of the active team
175 * omp_get_proc_bind::           Whether theads may be moved between CPUs
176 * omp_get_schedule::            Obtain the runtime scheduling method
177 * omp_get_team_num::            Get team number
178 * omp_get_team_size::           Number of threads in a team
179 * omp_get_thread_limit::        Maximum number of threads
180 * omp_get_thread_num::          Current thread ID
181 * omp_in_parallel::             Whether a parallel region is active
182 * omp_in_final::                Whether in final or included task region
183 * omp_is_initial_device::       Whether executing on the host device
184 * omp_set_default_device::      Set the default device for target regions
185 * omp_set_dynamic::             Enable/disable dynamic teams
186 * omp_set_max_active_levels::   Limits the number of active parallel regions
187 * omp_set_nested::              Enable/disable nested parallel regions
188 * omp_set_num_threads::         Set upper team size limit
189 * omp_set_schedule::            Set the runtime scheduling method
191 Initialize, set, test, unset and destroy simple and nested locks.
193 * omp_init_lock::            Initialize simple lock
194 * omp_set_lock::             Wait for and set simple lock
195 * omp_test_lock::            Test and set simple lock if available
196 * omp_unset_lock::           Unset simple lock
197 * omp_destroy_lock::         Destroy simple lock
198 * omp_init_nest_lock::       Initialize nested lock
199 * omp_set_nest_lock::        Wait for and set simple lock
200 * omp_test_nest_lock::       Test and set nested lock if available
201 * omp_unset_nest_lock::      Unset nested lock
202 * omp_destroy_nest_lock::    Destroy nested lock
204 Portable, thread-based, wall clock timer.
206 * omp_get_wtick::            Get timer precision.
207 * omp_get_wtime::            Elapsed wall clock time.
208 @end menu
212 @node omp_get_active_level
213 @section @code{omp_get_active_level} -- Number of parallel regions
214 @table @asis
215 @item @emph{Description}:
216 This function returns the nesting level for the active parallel blocks,
217 which enclose the calling call.
219 @item @emph{C/C++}
220 @multitable @columnfractions .20 .80
221 @item @emph{Prototype}: @tab @code{int omp_get_active_level(void);}
222 @end multitable
224 @item @emph{Fortran}:
225 @multitable @columnfractions .20 .80
226 @item @emph{Interface}: @tab @code{integer function omp_get_active_level()}
227 @end multitable
229 @item @emph{See also}:
230 @ref{omp_get_level}, @ref{omp_get_max_active_levels}, @ref{omp_set_max_active_levels}
232 @item @emph{Reference}:
233 @uref{http://www.openmp.org/, OpenMP specification v4.5}, Section 3.2.20.
234 @end table
238 @node omp_get_ancestor_thread_num
239 @section @code{omp_get_ancestor_thread_num} -- Ancestor thread ID
240 @table @asis
241 @item @emph{Description}:
242 This function returns the thread identification number for the given
243 nesting level of the current thread.  For values of @var{level} outside
244 zero to @code{omp_get_level} -1 is returned; if @var{level} is
245 @code{omp_get_level} the result is identical to @code{omp_get_thread_num}.
247 @item @emph{C/C++}
248 @multitable @columnfractions .20 .80
249 @item @emph{Prototype}: @tab @code{int omp_get_ancestor_thread_num(int level);}
250 @end multitable
252 @item @emph{Fortran}:
253 @multitable @columnfractions .20 .80
254 @item @emph{Interface}: @tab @code{integer function omp_get_ancestor_thread_num(level)}
255 @item                   @tab @code{integer level}
256 @end multitable
258 @item @emph{See also}:
259 @ref{omp_get_level}, @ref{omp_get_thread_num}, @ref{omp_get_team_size}
261 @item @emph{Reference}:
262 @uref{http://www.openmp.org/, OpenMP specification v4.5}, Section 3.2.18.
263 @end table
267 @node omp_get_cancellation
268 @section @code{omp_get_cancellation} -- Whether cancellation support is enabled
269 @table @asis
270 @item @emph{Description}:
271 This function returns @code{true} if cancellation is activated, @code{false}
272 otherwise.  Here, @code{true} and @code{false} represent their language-specific
273 counterparts.  Unless @env{OMP_CANCELLATION} is set true, cancellations are
274 deactivated.
276 @item @emph{C/C++}:
277 @multitable @columnfractions .20 .80
278 @item @emph{Prototype}: @tab @code{int omp_get_cancellation(void);}
279 @end multitable
281 @item @emph{Fortran}:
282 @multitable @columnfractions .20 .80
283 @item @emph{Interface}: @tab @code{logical function omp_get_cancellation()}
284 @end multitable
286 @item @emph{See also}:
287 @ref{OMP_CANCELLATION}
289 @item @emph{Reference}:
290 @uref{http://www.openmp.org/, OpenMP specification v4.5}, Section 3.2.9.
291 @end table
295 @node omp_get_default_device
296 @section @code{omp_get_default_device} -- Get the default device for target regions
297 @table @asis
298 @item @emph{Description}:
299 Get the default device for target regions without device clause.
301 @item @emph{C/C++}:
302 @multitable @columnfractions .20 .80
303 @item @emph{Prototype}: @tab @code{int omp_get_default_device(void);}
304 @end multitable
306 @item @emph{Fortran}:
307 @multitable @columnfractions .20 .80
308 @item @emph{Interface}: @tab @code{integer function omp_get_default_device()}
309 @end multitable
311 @item @emph{See also}:
312 @ref{OMP_DEFAULT_DEVICE}, @ref{omp_set_default_device}
314 @item @emph{Reference}:
315 @uref{http://www.openmp.org/, OpenMP specification v4.5}, Section 3.2.30.
316 @end table
320 @node omp_get_dynamic
321 @section @code{omp_get_dynamic} -- Dynamic teams setting
322 @table @asis
323 @item @emph{Description}:
324 This function returns @code{true} if enabled, @code{false} otherwise. 
325 Here, @code{true} and @code{false} represent their language-specific 
326 counterparts.
328 The dynamic team setting may be initialized at startup by the 
329 @env{OMP_DYNAMIC} environment variable or at runtime using
330 @code{omp_set_dynamic}.  If undefined, dynamic adjustment is
331 disabled by default.
333 @item @emph{C/C++}:
334 @multitable @columnfractions .20 .80
335 @item @emph{Prototype}: @tab @code{int omp_get_dynamic(void);}
336 @end multitable
338 @item @emph{Fortran}:
339 @multitable @columnfractions .20 .80
340 @item @emph{Interface}: @tab @code{logical function omp_get_dynamic()}
341 @end multitable
343 @item @emph{See also}:
344 @ref{omp_set_dynamic}, @ref{OMP_DYNAMIC}
346 @item @emph{Reference}:
347 @uref{http://www.openmp.org/, OpenMP specification v4.5}, Section 3.2.8.
348 @end table
352 @node omp_get_level
353 @section @code{omp_get_level} -- Obtain the current nesting level
354 @table @asis
355 @item @emph{Description}:
356 This function returns the nesting level for the parallel blocks,
357 which enclose the calling call.
359 @item @emph{C/C++}
360 @multitable @columnfractions .20 .80
361 @item @emph{Prototype}: @tab @code{int omp_get_level(void);}
362 @end multitable
364 @item @emph{Fortran}:
365 @multitable @columnfractions .20 .80
366 @item @emph{Interface}: @tab @code{integer function omp_level()}
367 @end multitable
369 @item @emph{See also}:
370 @ref{omp_get_active_level}
372 @item @emph{Reference}:
373 @uref{http://www.openmp.org/, OpenMP specification v4.5}, Section 3.2.17.
374 @end table
378 @node omp_get_max_active_levels
379 @section @code{omp_get_max_active_levels} -- Maximum number of active regions
380 @table @asis
381 @item @emph{Description}:
382 This function obtains the maximum allowed number of nested, active parallel regions.
384 @item @emph{C/C++}
385 @multitable @columnfractions .20 .80
386 @item @emph{Prototype}: @tab @code{int omp_get_max_active_levels(void);}
387 @end multitable
389 @item @emph{Fortran}:
390 @multitable @columnfractions .20 .80
391 @item @emph{Interface}: @tab @code{integer function omp_get_max_active_levels()}
392 @end multitable
394 @item @emph{See also}:
395 @ref{omp_set_max_active_levels}, @ref{omp_get_active_level}
397 @item @emph{Reference}:
398 @uref{http://www.openmp.org/, OpenMP specification v4.5}, Section 3.2.16.
399 @end table
402 @node omp_get_max_task_priority
403 @section @code{omp_get_max_task_priority} -- Maximum priority value
404 that can be set for tasks.
405 @table @asis
406 @item @emph{Description}:
407 This function obtains the maximum allowed priority number for tasks.
409 @item @emph{C/C++}
410 @multitable @columnfractions .20 .80
411 @item @emph{Prototype}: @tab @code{int omp_get_max_task_priority(void);}
412 @end multitable
414 @item @emph{Fortran}:
415 @multitable @columnfractions .20 .80
416 @item @emph{Interface}: @tab @code{integer function omp_get_max_task_priority()}
417 @end multitable
419 @item @emph{Reference}:
420 @uref{http://www.openmp.org/, OpenMP specification v4.5}, Section 3.2.29.
421 @end table
424 @node omp_get_max_threads
425 @section @code{omp_get_max_threads} -- Maximum number of threads of parallel region
426 @table @asis
427 @item @emph{Description}:
428 Return the maximum number of threads used for the current parallel region
429 that does not use the clause @code{num_threads}.
431 @item @emph{C/C++}:
432 @multitable @columnfractions .20 .80
433 @item @emph{Prototype}: @tab @code{int omp_get_max_threads(void);}
434 @end multitable
436 @item @emph{Fortran}:
437 @multitable @columnfractions .20 .80
438 @item @emph{Interface}: @tab @code{integer function omp_get_max_threads()}
439 @end multitable
441 @item @emph{See also}:
442 @ref{omp_set_num_threads}, @ref{omp_set_dynamic}, @ref{omp_get_thread_limit}
444 @item @emph{Reference}:
445 @uref{http://www.openmp.org/, OpenMP specification v4.5}, Section 3.2.3.
446 @end table
450 @node omp_get_nested
451 @section @code{omp_get_nested} -- Nested parallel regions
452 @table @asis
453 @item @emph{Description}:
454 This function returns @code{true} if nested parallel regions are
455 enabled, @code{false} otherwise.  Here, @code{true} and @code{false}
456 represent their language-specific counterparts.
458 Nested parallel regions may be initialized at startup by the 
459 @env{OMP_NESTED} environment variable or at runtime using
460 @code{omp_set_nested}.  If undefined, nested parallel regions are
461 disabled by default.
463 @item @emph{C/C++}:
464 @multitable @columnfractions .20 .80
465 @item @emph{Prototype}: @tab @code{int omp_get_nested(void);}
466 @end multitable
468 @item @emph{Fortran}:
469 @multitable @columnfractions .20 .80
470 @item @emph{Interface}: @tab @code{logical function omp_get_nested()}
471 @end multitable
473 @item @emph{See also}:
474 @ref{omp_set_nested}, @ref{OMP_NESTED}
476 @item @emph{Reference}:
477 @uref{http://www.openmp.org/, OpenMP specification v4.5}, Section 3.2.11.
478 @end table
482 @node omp_get_num_devices
483 @section @code{omp_get_num_devices} -- Number of target devices
484 @table @asis
485 @item @emph{Description}:
486 Returns the number of target devices.
488 @item @emph{C/C++}:
489 @multitable @columnfractions .20 .80
490 @item @emph{Prototype}: @tab @code{int omp_get_num_devices(void);}
491 @end multitable
493 @item @emph{Fortran}:
494 @multitable @columnfractions .20 .80
495 @item @emph{Interface}: @tab @code{integer function omp_get_num_devices()}
496 @end multitable
498 @item @emph{Reference}:
499 @uref{http://www.openmp.org/, OpenMP specification v4.5}, Section 3.2.31.
500 @end table
504 @node omp_get_num_procs
505 @section @code{omp_get_num_procs} -- Number of processors online
506 @table @asis
507 @item @emph{Description}:
508 Returns the number of processors online on that device.
510 @item @emph{C/C++}:
511 @multitable @columnfractions .20 .80
512 @item @emph{Prototype}: @tab @code{int omp_get_num_procs(void);}
513 @end multitable
515 @item @emph{Fortran}:
516 @multitable @columnfractions .20 .80
517 @item @emph{Interface}: @tab @code{integer function omp_get_num_procs()}
518 @end multitable
520 @item @emph{Reference}:
521 @uref{http://www.openmp.org/, OpenMP specification v4.5}, Section 3.2.5.
522 @end table
526 @node omp_get_num_teams
527 @section @code{omp_get_num_teams} -- Number of teams
528 @table @asis
529 @item @emph{Description}:
530 Returns the number of teams in the current team region.
532 @item @emph{C/C++}:
533 @multitable @columnfractions .20 .80
534 @item @emph{Prototype}: @tab @code{int omp_get_num_teams(void);}
535 @end multitable
537 @item @emph{Fortran}:
538 @multitable @columnfractions .20 .80
539 @item @emph{Interface}: @tab @code{integer function omp_get_num_teams()}
540 @end multitable
542 @item @emph{Reference}:
543 @uref{http://www.openmp.org/, OpenMP specification v4.5}, Section 3.2.32.
544 @end table
548 @node omp_get_num_threads
549 @section @code{omp_get_num_threads} -- Size of the active team
550 @table @asis
551 @item @emph{Description}:
552 Returns the number of threads in the current team.  In a sequential section of
553 the program @code{omp_get_num_threads} returns 1.
555 The default team size may be initialized at startup by the 
556 @env{OMP_NUM_THREADS} environment variable.  At runtime, the size
557 of the current team may be set either by the @code{NUM_THREADS}
558 clause or by @code{omp_set_num_threads}.  If none of the above were
559 used to define a specific value and @env{OMP_DYNAMIC} is disabled,
560 one thread per CPU online is used.
562 @item @emph{C/C++}:
563 @multitable @columnfractions .20 .80
564 @item @emph{Prototype}: @tab @code{int omp_get_num_threads(void);}
565 @end multitable
567 @item @emph{Fortran}:
568 @multitable @columnfractions .20 .80
569 @item @emph{Interface}: @tab @code{integer function omp_get_num_threads()}
570 @end multitable
572 @item @emph{See also}:
573 @ref{omp_get_max_threads}, @ref{omp_set_num_threads}, @ref{OMP_NUM_THREADS}
575 @item @emph{Reference}:
576 @uref{http://www.openmp.org/, OpenMP specification v4.5}, Section 3.2.2.
577 @end table
581 @node omp_get_proc_bind
582 @section @code{omp_get_proc_bind} -- Whether theads may be moved between CPUs
583 @table @asis
584 @item @emph{Description}:
585 This functions returns the currently active thread affinity policy, which is
586 set via @env{OMP_PROC_BIND}.  Possible values are @code{omp_proc_bind_false},
587 @code{omp_proc_bind_true}, @code{omp_proc_bind_master},
588 @code{omp_proc_bind_close} and @code{omp_proc_bind_spread}.
590 @item @emph{C/C++}:
591 @multitable @columnfractions .20 .80
592 @item @emph{Prototype}: @tab @code{omp_proc_bind_t omp_get_proc_bind(void);}
593 @end multitable
595 @item @emph{Fortran}:
596 @multitable @columnfractions .20 .80
597 @item @emph{Interface}: @tab @code{integer(kind=omp_proc_bind_kind) function omp_get_proc_bind()}
598 @end multitable
600 @item @emph{See also}:
601 @ref{OMP_PROC_BIND}, @ref{OMP_PLACES}, @ref{GOMP_CPU_AFFINITY},
603 @item @emph{Reference}:
604 @uref{http://www.openmp.org/, OpenMP specification v4.5}, Section 3.2.22.
605 @end table
609 @node omp_get_schedule
610 @section @code{omp_get_schedule} -- Obtain the runtime scheduling method
611 @table @asis
612 @item @emph{Description}:
613 Obtain the runtime scheduling method.  The @var{kind} argument will be
614 set to the value @code{omp_sched_static}, @code{omp_sched_dynamic},
615 @code{omp_sched_guided} or @code{omp_sched_auto}.  The second argument,
616 @var{chunk_size}, is set to the chunk size.
618 @item @emph{C/C++}
619 @multitable @columnfractions .20 .80
620 @item @emph{Prototype}: @tab @code{void omp_get_schedule(omp_sched_t *kind, int *chunk_size);}
621 @end multitable
623 @item @emph{Fortran}:
624 @multitable @columnfractions .20 .80
625 @item @emph{Interface}: @tab @code{subroutine omp_get_schedule(kind, chunk_size)}
626 @item                   @tab @code{integer(kind=omp_sched_kind) kind}
627 @item                   @tab @code{integer chunk_size}
628 @end multitable
630 @item @emph{See also}:
631 @ref{omp_set_schedule}, @ref{OMP_SCHEDULE}
633 @item @emph{Reference}:
634 @uref{http://www.openmp.org/, OpenMP specification v4.5}, Section 3.2.13.
635 @end table
639 @node omp_get_team_num
640 @section @code{omp_get_team_num} -- Get team number
641 @table @asis
642 @item @emph{Description}:
643 Returns the team number of the calling thread.
645 @item @emph{C/C++}:
646 @multitable @columnfractions .20 .80
647 @item @emph{Prototype}: @tab @code{int omp_get_team_num(void);}
648 @end multitable
650 @item @emph{Fortran}:
651 @multitable @columnfractions .20 .80
652 @item @emph{Interface}: @tab @code{integer function omp_get_team_num()}
653 @end multitable
655 @item @emph{Reference}:
656 @uref{http://www.openmp.org/, OpenMP specification v4.5}, Section 3.2.33.
657 @end table
661 @node omp_get_team_size
662 @section @code{omp_get_team_size} -- Number of threads in a team
663 @table @asis
664 @item @emph{Description}:
665 This function returns the number of threads in a thread team to which
666 either the current thread or its ancestor belongs.  For values of @var{level}
667 outside zero to @code{omp_get_level}, -1 is returned; if @var{level} is zero,
668 1 is returned, and for @code{omp_get_level}, the result is identical
669 to @code{omp_get_num_threads}.
671 @item @emph{C/C++}:
672 @multitable @columnfractions .20 .80
673 @item @emph{Prototype}: @tab @code{int omp_get_team_size(int level);}
674 @end multitable
676 @item @emph{Fortran}:
677 @multitable @columnfractions .20 .80
678 @item @emph{Interface}: @tab @code{integer function omp_get_team_size(level)}
679 @item                   @tab @code{integer level}
680 @end multitable
682 @item @emph{See also}:
683 @ref{omp_get_num_threads}, @ref{omp_get_level}, @ref{omp_get_ancestor_thread_num}
685 @item @emph{Reference}:
686 @uref{http://www.openmp.org/, OpenMP specification v4.5}, Section 3.2.19.
687 @end table
691 @node omp_get_thread_limit
692 @section @code{omp_get_thread_limit} -- Maximum number of threads
693 @table @asis
694 @item @emph{Description}:
695 Return the maximum number of threads of the program.
697 @item @emph{C/C++}:
698 @multitable @columnfractions .20 .80
699 @item @emph{Prototype}: @tab @code{int omp_get_thread_limit(void);}
700 @end multitable
702 @item @emph{Fortran}:
703 @multitable @columnfractions .20 .80
704 @item @emph{Interface}: @tab @code{integer function omp_get_thread_limit()}
705 @end multitable
707 @item @emph{See also}:
708 @ref{omp_get_max_threads}, @ref{OMP_THREAD_LIMIT}
710 @item @emph{Reference}:
711 @uref{http://www.openmp.org/, OpenMP specification v4.5}, Section 3.2.14.
712 @end table
716 @node omp_get_thread_num
717 @section @code{omp_get_thread_num} -- Current thread ID
718 @table @asis
719 @item @emph{Description}:
720 Returns a unique thread identification number within the current team.
721 In a sequential parts of the program, @code{omp_get_thread_num}
722 always returns 0.  In parallel regions the return value varies
723 from 0 to @code{omp_get_num_threads}-1 inclusive.  The return
724 value of the master thread of a team is always 0.
726 @item @emph{C/C++}:
727 @multitable @columnfractions .20 .80
728 @item @emph{Prototype}: @tab @code{int omp_get_thread_num(void);}
729 @end multitable
731 @item @emph{Fortran}:
732 @multitable @columnfractions .20 .80
733 @item @emph{Interface}: @tab @code{integer function omp_get_thread_num()}
734 @end multitable
736 @item @emph{See also}:
737 @ref{omp_get_num_threads}, @ref{omp_get_ancestor_thread_num}
739 @item @emph{Reference}:
740 @uref{http://www.openmp.org/, OpenMP specification v4.5}, Section 3.2.4.
741 @end table
745 @node omp_in_parallel
746 @section @code{omp_in_parallel} -- Whether a parallel region is active
747 @table @asis
748 @item @emph{Description}:
749 This function returns @code{true} if currently running in parallel,
750 @code{false} otherwise.  Here, @code{true} and @code{false} represent
751 their language-specific counterparts.
753 @item @emph{C/C++}:
754 @multitable @columnfractions .20 .80
755 @item @emph{Prototype}: @tab @code{int omp_in_parallel(void);}
756 @end multitable
758 @item @emph{Fortran}:
759 @multitable @columnfractions .20 .80
760 @item @emph{Interface}: @tab @code{logical function omp_in_parallel()}
761 @end multitable
763 @item @emph{Reference}:
764 @uref{http://www.openmp.org/, OpenMP specification v4.5}, Section 3.2.6.
765 @end table
768 @node omp_in_final
769 @section @code{omp_in_final} -- Whether in final or included task region
770 @table @asis
771 @item @emph{Description}:
772 This function returns @code{true} if currently running in a final
773 or included task region, @code{false} otherwise.  Here, @code{true}
774 and @code{false} represent their language-specific counterparts.
776 @item @emph{C/C++}:
777 @multitable @columnfractions .20 .80
778 @item @emph{Prototype}: @tab @code{int omp_in_final(void);}
779 @end multitable
781 @item @emph{Fortran}:
782 @multitable @columnfractions .20 .80
783 @item @emph{Interface}: @tab @code{logical function omp_in_final()}
784 @end multitable
786 @item @emph{Reference}:
787 @uref{http://www.openmp.org/, OpenMP specification v4.5}, Section 3.2.21.
788 @end table
792 @node omp_is_initial_device
793 @section @code{omp_is_initial_device} -- Whether executing on the host device
794 @table @asis
795 @item @emph{Description}:
796 This function returns @code{true} if currently running on the host device,
797 @code{false} otherwise.  Here, @code{true} and @code{false} represent
798 their language-specific counterparts.
800 @item @emph{C/C++}:
801 @multitable @columnfractions .20 .80
802 @item @emph{Prototype}: @tab @code{int omp_is_initial_device(void);}
803 @end multitable
805 @item @emph{Fortran}:
806 @multitable @columnfractions .20 .80
807 @item @emph{Interface}: @tab @code{logical function omp_is_initial_device()}
808 @end multitable
810 @item @emph{Reference}:
811 @uref{http://www.openmp.org/, OpenMP specification v4.5}, Section 3.2.34.
812 @end table
816 @node omp_set_default_device
817 @section @code{omp_set_default_device} -- Set the default device for target regions
818 @table @asis
819 @item @emph{Description}:
820 Set the default device for target regions without device clause.  The argument
821 shall be a nonnegative device number.
823 @item @emph{C/C++}:
824 @multitable @columnfractions .20 .80
825 @item @emph{Prototype}: @tab @code{void omp_set_default_device(int device_num);}
826 @end multitable
828 @item @emph{Fortran}:
829 @multitable @columnfractions .20 .80
830 @item @emph{Interface}: @tab @code{subroutine omp_set_default_device(device_num)}
831 @item                   @tab @code{integer device_num}
832 @end multitable
834 @item @emph{See also}:
835 @ref{OMP_DEFAULT_DEVICE}, @ref{omp_get_default_device}
837 @item @emph{Reference}:
838 @uref{http://www.openmp.org/, OpenMP specification v4.5}, Section 3.2.29.
839 @end table
843 @node omp_set_dynamic
844 @section @code{omp_set_dynamic} -- Enable/disable dynamic teams
845 @table @asis
846 @item @emph{Description}:
847 Enable or disable the dynamic adjustment of the number of threads 
848 within a team.  The function takes the language-specific equivalent
849 of @code{true} and @code{false}, where @code{true} enables dynamic 
850 adjustment of team sizes and @code{false} disables it.
852 @item @emph{C/C++}:
853 @multitable @columnfractions .20 .80
854 @item @emph{Prototype}: @tab @code{void omp_set_dynamic(int dynamic_threads);}
855 @end multitable
857 @item @emph{Fortran}:
858 @multitable @columnfractions .20 .80
859 @item @emph{Interface}: @tab @code{subroutine omp_set_dynamic(dynamic_threads)}
860 @item                   @tab @code{logical, intent(in) :: dynamic_threads}
861 @end multitable
863 @item @emph{See also}:
864 @ref{OMP_DYNAMIC}, @ref{omp_get_dynamic}
866 @item @emph{Reference}:
867 @uref{http://www.openmp.org/, OpenMP specification v4.5}, Section 3.2.7.
868 @end table
872 @node omp_set_max_active_levels
873 @section @code{omp_set_max_active_levels} -- Limits the number of active parallel regions
874 @table @asis
875 @item @emph{Description}:
876 This function limits the maximum allowed number of nested, active
877 parallel regions.
879 @item @emph{C/C++}
880 @multitable @columnfractions .20 .80
881 @item @emph{Prototype}: @tab @code{void omp_set_max_active_levels(int max_levels);}
882 @end multitable
884 @item @emph{Fortran}:
885 @multitable @columnfractions .20 .80
886 @item @emph{Interface}: @tab @code{subroutine omp_set_max_active_levels(max_levels)}
887 @item                   @tab @code{integer max_levels}
888 @end multitable
890 @item @emph{See also}:
891 @ref{omp_get_max_active_levels}, @ref{omp_get_active_level}
893 @item @emph{Reference}:
894 @uref{http://www.openmp.org/, OpenMP specification v4.5}, Section 3.2.15.
895 @end table
899 @node omp_set_nested
900 @section @code{omp_set_nested} -- Enable/disable nested parallel regions
901 @table @asis
902 @item @emph{Description}:
903 Enable or disable nested parallel regions, i.e., whether team members
904 are allowed to create new teams.  The function takes the language-specific
905 equivalent of @code{true} and @code{false}, where @code{true} enables 
906 dynamic adjustment of team sizes and @code{false} disables it.
908 @item @emph{C/C++}:
909 @multitable @columnfractions .20 .80
910 @item @emph{Prototype}: @tab @code{void omp_set_nested(int nested);}
911 @end multitable
913 @item @emph{Fortran}:
914 @multitable @columnfractions .20 .80
915 @item @emph{Interface}: @tab @code{subroutine omp_set_nested(nested)}
916 @item                   @tab @code{logical, intent(in) :: nested}
917 @end multitable
919 @item @emph{See also}:
920 @ref{OMP_NESTED}, @ref{omp_get_nested}
922 @item @emph{Reference}:
923 @uref{http://www.openmp.org/, OpenMP specification v4.5}, Section 3.2.10.
924 @end table
928 @node omp_set_num_threads
929 @section @code{omp_set_num_threads} -- Set upper team size limit
930 @table @asis
931 @item @emph{Description}:
932 Specifies the number of threads used by default in subsequent parallel 
933 sections, if those do not specify a @code{num_threads} clause.  The
934 argument of @code{omp_set_num_threads} shall be a positive integer.
936 @item @emph{C/C++}:
937 @multitable @columnfractions .20 .80
938 @item @emph{Prototype}: @tab @code{void omp_set_num_threads(int num_threads);}
939 @end multitable
941 @item @emph{Fortran}:
942 @multitable @columnfractions .20 .80
943 @item @emph{Interface}: @tab @code{subroutine omp_set_num_threads(num_threads)}
944 @item                   @tab @code{integer, intent(in) :: num_threads}
945 @end multitable
947 @item @emph{See also}:
948 @ref{OMP_NUM_THREADS}, @ref{omp_get_num_threads}, @ref{omp_get_max_threads}
950 @item @emph{Reference}:
951 @uref{http://www.openmp.org/, OpenMP specification v4.5}, Section 3.2.1.
952 @end table
956 @node omp_set_schedule
957 @section @code{omp_set_schedule} -- Set the runtime scheduling method
958 @table @asis
959 @item @emph{Description}:
960 Sets the runtime scheduling method.  The @var{kind} argument can have the
961 value @code{omp_sched_static}, @code{omp_sched_dynamic},
962 @code{omp_sched_guided} or @code{omp_sched_auto}.  Except for
963 @code{omp_sched_auto}, the chunk size is set to the value of
964 @var{chunk_size} if positive, or to the default value if zero or negative.
965 For @code{omp_sched_auto} the @var{chunk_size} argument is ignored.
967 @item @emph{C/C++}
968 @multitable @columnfractions .20 .80
969 @item @emph{Prototype}: @tab @code{void omp_set_schedule(omp_sched_t kind, int chunk_size);}
970 @end multitable
972 @item @emph{Fortran}:
973 @multitable @columnfractions .20 .80
974 @item @emph{Interface}: @tab @code{subroutine omp_set_schedule(kind, chunk_size)}
975 @item                   @tab @code{integer(kind=omp_sched_kind) kind}
976 @item                   @tab @code{integer chunk_size}
977 @end multitable
979 @item @emph{See also}:
980 @ref{omp_get_schedule}
981 @ref{OMP_SCHEDULE}
983 @item @emph{Reference}:
984 @uref{http://www.openmp.org/, OpenMP specification v4.5}, Section 3.2.12.
985 @end table
989 @node omp_init_lock
990 @section @code{omp_init_lock} -- Initialize simple lock
991 @table @asis
992 @item @emph{Description}:
993 Initialize a simple lock.  After initialization, the lock is in
994 an unlocked state.
996 @item @emph{C/C++}:
997 @multitable @columnfractions .20 .80
998 @item @emph{Prototype}: @tab @code{void omp_init_lock(omp_lock_t *lock);}
999 @end multitable
1001 @item @emph{Fortran}:
1002 @multitable @columnfractions .20 .80
1003 @item @emph{Interface}: @tab @code{subroutine omp_init_lock(svar)}
1004 @item                   @tab @code{integer(omp_lock_kind), intent(out) :: svar}
1005 @end multitable
1007 @item @emph{See also}:
1008 @ref{omp_destroy_lock}
1010 @item @emph{Reference}: 
1011 @uref{http://www.openmp.org/, OpenMP specification v4.5}, Section 3.3.1.
1012 @end table
1016 @node omp_set_lock
1017 @section @code{omp_set_lock} -- Wait for and set simple lock
1018 @table @asis
1019 @item @emph{Description}:
1020 Before setting a simple lock, the lock variable must be initialized by 
1021 @code{omp_init_lock}.  The calling thread is blocked until the lock 
1022 is available.  If the lock is already held by the current thread, 
1023 a deadlock occurs.
1025 @item @emph{C/C++}:
1026 @multitable @columnfractions .20 .80
1027 @item @emph{Prototype}: @tab @code{void omp_set_lock(omp_lock_t *lock);}
1028 @end multitable
1030 @item @emph{Fortran}:
1031 @multitable @columnfractions .20 .80
1032 @item @emph{Interface}: @tab @code{subroutine omp_set_lock(svar)}
1033 @item                   @tab @code{integer(omp_lock_kind), intent(inout) :: svar}
1034 @end multitable
1036 @item @emph{See also}:
1037 @ref{omp_init_lock}, @ref{omp_test_lock}, @ref{omp_unset_lock}
1039 @item @emph{Reference}: 
1040 @uref{http://www.openmp.org/, OpenMP specification v4.5}, Section 3.3.4.
1041 @end table
1045 @node omp_test_lock
1046 @section @code{omp_test_lock} -- Test and set simple lock if available
1047 @table @asis
1048 @item @emph{Description}:
1049 Before setting a simple lock, the lock variable must be initialized by 
1050 @code{omp_init_lock}.  Contrary to @code{omp_set_lock}, @code{omp_test_lock} 
1051 does not block if the lock is not available.  This function returns
1052 @code{true} upon success, @code{false} otherwise.  Here, @code{true} and
1053 @code{false} represent their language-specific counterparts.
1055 @item @emph{C/C++}:
1056 @multitable @columnfractions .20 .80
1057 @item @emph{Prototype}: @tab @code{int omp_test_lock(omp_lock_t *lock);}
1058 @end multitable
1060 @item @emph{Fortran}:
1061 @multitable @columnfractions .20 .80
1062 @item @emph{Interface}: @tab @code{logical function omp_test_lock(svar)}
1063 @item                   @tab @code{integer(omp_lock_kind), intent(inout) :: svar}
1064 @end multitable
1066 @item @emph{See also}:
1067 @ref{omp_init_lock}, @ref{omp_set_lock}, @ref{omp_set_lock}
1069 @item @emph{Reference}: 
1070 @uref{http://www.openmp.org/, OpenMP specification v4.5}, Section 3.3.6.
1071 @end table
1075 @node omp_unset_lock
1076 @section @code{omp_unset_lock} -- Unset simple lock
1077 @table @asis
1078 @item @emph{Description}:
1079 A simple lock about to be unset must have been locked by @code{omp_set_lock}
1080 or @code{omp_test_lock} before.  In addition, the lock must be held by the
1081 thread calling @code{omp_unset_lock}.  Then, the lock becomes unlocked.  If one
1082 or more threads attempted to set the lock before, one of them is chosen to,
1083 again, set the lock to itself.
1085 @item @emph{C/C++}:
1086 @multitable @columnfractions .20 .80
1087 @item @emph{Prototype}: @tab @code{void omp_unset_lock(omp_lock_t *lock);}
1088 @end multitable
1090 @item @emph{Fortran}:
1091 @multitable @columnfractions .20 .80
1092 @item @emph{Interface}: @tab @code{subroutine omp_unset_lock(svar)}
1093 @item                   @tab @code{integer(omp_lock_kind), intent(inout) :: svar}
1094 @end multitable
1096 @item @emph{See also}:
1097 @ref{omp_set_lock}, @ref{omp_test_lock}
1099 @item @emph{Reference}: 
1100 @uref{http://www.openmp.org/, OpenMP specification v4.5}, Section 3.3.5.
1101 @end table
1105 @node omp_destroy_lock
1106 @section @code{omp_destroy_lock} -- Destroy simple lock
1107 @table @asis
1108 @item @emph{Description}:
1109 Destroy a simple lock.  In order to be destroyed, a simple lock must be
1110 in the unlocked state. 
1112 @item @emph{C/C++}:
1113 @multitable @columnfractions .20 .80
1114 @item @emph{Prototype}: @tab @code{void omp_destroy_lock(omp_lock_t *lock);}
1115 @end multitable
1117 @item @emph{Fortran}:
1118 @multitable @columnfractions .20 .80
1119 @item @emph{Interface}: @tab @code{subroutine omp_destroy_lock(svar)}
1120 @item                   @tab @code{integer(omp_lock_kind), intent(inout) :: svar}
1121 @end multitable
1123 @item @emph{See also}:
1124 @ref{omp_init_lock}
1126 @item @emph{Reference}: 
1127 @uref{http://www.openmp.org/, OpenMP specification v4.5}, Section 3.3.3.
1128 @end table
1132 @node omp_init_nest_lock
1133 @section @code{omp_init_nest_lock} -- Initialize nested lock
1134 @table @asis
1135 @item @emph{Description}:
1136 Initialize a nested lock.  After initialization, the lock is in
1137 an unlocked state and the nesting count is set to zero.
1139 @item @emph{C/C++}:
1140 @multitable @columnfractions .20 .80
1141 @item @emph{Prototype}: @tab @code{void omp_init_nest_lock(omp_nest_lock_t *lock);}
1142 @end multitable
1144 @item @emph{Fortran}:
1145 @multitable @columnfractions .20 .80
1146 @item @emph{Interface}: @tab @code{subroutine omp_init_nest_lock(nvar)}
1147 @item                   @tab @code{integer(omp_nest_lock_kind), intent(out) :: nvar}
1148 @end multitable
1150 @item @emph{See also}:
1151 @ref{omp_destroy_nest_lock}
1153 @item @emph{Reference}:
1154 @uref{http://www.openmp.org/, OpenMP specification v4.5}, Section 3.3.1.
1155 @end table
1158 @node omp_set_nest_lock
1159 @section @code{omp_set_nest_lock} -- Wait for and set nested lock
1160 @table @asis
1161 @item @emph{Description}:
1162 Before setting a nested lock, the lock variable must be initialized by 
1163 @code{omp_init_nest_lock}.  The calling thread is blocked until the lock
1164 is available.  If the lock is already held by the current thread, the
1165 nesting count for the lock is incremented.
1167 @item @emph{C/C++}:
1168 @multitable @columnfractions .20 .80
1169 @item @emph{Prototype}: @tab @code{void omp_set_nest_lock(omp_nest_lock_t *lock);}
1170 @end multitable
1172 @item @emph{Fortran}:
1173 @multitable @columnfractions .20 .80
1174 @item @emph{Interface}: @tab @code{subroutine omp_set_nest_lock(nvar)}
1175 @item                   @tab @code{integer(omp_nest_lock_kind), intent(inout) :: nvar}
1176 @end multitable
1178 @item @emph{See also}:
1179 @ref{omp_init_nest_lock}, @ref{omp_unset_nest_lock}
1181 @item @emph{Reference}: 
1182 @uref{http://www.openmp.org/, OpenMP specification v4.5}, Section 3.3.4.
1183 @end table
1187 @node omp_test_nest_lock
1188 @section @code{omp_test_nest_lock} -- Test and set nested lock if available
1189 @table @asis
1190 @item @emph{Description}:
1191 Before setting a nested lock, the lock variable must be initialized by 
1192 @code{omp_init_nest_lock}.  Contrary to @code{omp_set_nest_lock},
1193 @code{omp_test_nest_lock} does not block if the lock is not available. 
1194 If the lock is already held by the current thread, the new nesting count 
1195 is returned.  Otherwise, the return value equals zero.
1197 @item @emph{C/C++}:
1198 @multitable @columnfractions .20 .80
1199 @item @emph{Prototype}: @tab @code{int omp_test_nest_lock(omp_nest_lock_t *lock);}
1200 @end multitable
1202 @item @emph{Fortran}:
1203 @multitable @columnfractions .20 .80
1204 @item @emph{Interface}: @tab @code{logical function omp_test_nest_lock(nvar)}
1205 @item                   @tab @code{integer(omp_nest_lock_kind), intent(inout) :: nvar}
1206 @end multitable
1209 @item @emph{See also}:
1210 @ref{omp_init_lock}, @ref{omp_set_lock}, @ref{omp_set_lock}
1212 @item @emph{Reference}: 
1213 @uref{http://www.openmp.org/, OpenMP specification v4.5}, Section 3.3.6.
1214 @end table
1218 @node omp_unset_nest_lock
1219 @section @code{omp_unset_nest_lock} -- Unset nested lock
1220 @table @asis
1221 @item @emph{Description}:
1222 A nested lock about to be unset must have been locked by @code{omp_set_nested_lock}
1223 or @code{omp_test_nested_lock} before.  In addition, the lock must be held by the
1224 thread calling @code{omp_unset_nested_lock}.  If the nesting count drops to zero, the
1225 lock becomes unlocked.  If one ore more threads attempted to set the lock before,
1226 one of them is chosen to, again, set the lock to itself.
1228 @item @emph{C/C++}:
1229 @multitable @columnfractions .20 .80
1230 @item @emph{Prototype}: @tab @code{void omp_unset_nest_lock(omp_nest_lock_t *lock);}
1231 @end multitable
1233 @item @emph{Fortran}:
1234 @multitable @columnfractions .20 .80
1235 @item @emph{Interface}: @tab @code{subroutine omp_unset_nest_lock(nvar)}
1236 @item                   @tab @code{integer(omp_nest_lock_kind), intent(inout) :: nvar}
1237 @end multitable
1239 @item @emph{See also}:
1240 @ref{omp_set_nest_lock}
1242 @item @emph{Reference}: 
1243 @uref{http://www.openmp.org/, OpenMP specification v4.5}, Section 3.3.5.
1244 @end table
1248 @node omp_destroy_nest_lock
1249 @section @code{omp_destroy_nest_lock} -- Destroy nested lock
1250 @table @asis
1251 @item @emph{Description}:
1252 Destroy a nested lock.  In order to be destroyed, a nested lock must be
1253 in the unlocked state and its nesting count must equal zero.
1255 @item @emph{C/C++}:
1256 @multitable @columnfractions .20 .80
1257 @item @emph{Prototype}: @tab @code{void omp_destroy_nest_lock(omp_nest_lock_t *);}
1258 @end multitable
1260 @item @emph{Fortran}:
1261 @multitable @columnfractions .20 .80
1262 @item @emph{Interface}: @tab @code{subroutine omp_destroy_nest_lock(nvar)}
1263 @item                   @tab @code{integer(omp_nest_lock_kind), intent(inout) :: nvar}
1264 @end multitable
1266 @item @emph{See also}:
1267 @ref{omp_init_lock}
1269 @item @emph{Reference}: 
1270 @uref{http://www.openmp.org/, OpenMP specification v4.5}, Section 3.3.3.
1271 @end table
1275 @node omp_get_wtick
1276 @section @code{omp_get_wtick} -- Get timer precision
1277 @table @asis
1278 @item @emph{Description}:
1279 Gets the timer precision, i.e., the number of seconds between two 
1280 successive clock ticks.
1282 @item @emph{C/C++}:
1283 @multitable @columnfractions .20 .80
1284 @item @emph{Prototype}: @tab @code{double omp_get_wtick(void);}
1285 @end multitable
1287 @item @emph{Fortran}:
1288 @multitable @columnfractions .20 .80
1289 @item @emph{Interface}: @tab @code{double precision function omp_get_wtick()}
1290 @end multitable
1292 @item @emph{See also}:
1293 @ref{omp_get_wtime}
1295 @item @emph{Reference}: 
1296 @uref{http://www.openmp.org/, OpenMP specification v4.5}, Section 3.4.2.
1297 @end table
1301 @node omp_get_wtime
1302 @section @code{omp_get_wtime} -- Elapsed wall clock time
1303 @table @asis
1304 @item @emph{Description}:
1305 Elapsed wall clock time in seconds.  The time is measured per thread, no
1306 guarantee can be made that two distinct threads measure the same time.
1307 Time is measured from some "time in the past", which is an arbitrary time
1308 guaranteed not to change during the execution of the program.
1310 @item @emph{C/C++}:
1311 @multitable @columnfractions .20 .80
1312 @item @emph{Prototype}: @tab @code{double omp_get_wtime(void);}
1313 @end multitable
1315 @item @emph{Fortran}:
1316 @multitable @columnfractions .20 .80
1317 @item @emph{Interface}: @tab @code{double precision function omp_get_wtime()}
1318 @end multitable
1320 @item @emph{See also}:
1321 @ref{omp_get_wtick}
1323 @item @emph{Reference}: 
1324 @uref{http://www.openmp.org/, OpenMP specification v4.5}, Section 3.4.1.
1325 @end table
1329 @c ---------------------------------------------------------------------
1330 @c Environment Variables
1331 @c ---------------------------------------------------------------------
1333 @node Environment Variables
1334 @chapter Environment Variables
1336 The environment variables which beginning with @env{OMP_} are defined by
1337 section 4 of the OpenMP specification in version 4.5, while those
1338 beginning with @env{GOMP_} are GNU extensions.
1340 @menu
1341 * OMP_CANCELLATION::        Set whether cancellation is activated
1342 * OMP_DISPLAY_ENV::         Show OpenMP version and environment variables
1343 * OMP_DEFAULT_DEVICE::      Set the device used in target regions
1344 * OMP_DYNAMIC::             Dynamic adjustment of threads
1345 * OMP_MAX_ACTIVE_LEVELS::   Set the maximum number of nested parallel regions
1346 * OMP_MAX_TASK_PRIORITY::   Set the maximum task priority value
1347 * OMP_NESTED::              Nested parallel regions
1348 * OMP_NUM_THREADS::         Specifies the number of threads to use
1349 * OMP_PROC_BIND::           Whether theads may be moved between CPUs
1350 * OMP_PLACES::              Specifies on which CPUs the theads should be placed
1351 * OMP_STACKSIZE::           Set default thread stack size
1352 * OMP_SCHEDULE::            How threads are scheduled
1353 * OMP_THREAD_LIMIT::        Set the maximum number of threads
1354 * OMP_WAIT_POLICY::         How waiting threads are handled
1355 * GOMP_CPU_AFFINITY::       Bind threads to specific CPUs
1356 * GOMP_DEBUG::              Enable debugging output
1357 * GOMP_STACKSIZE::          Set default thread stack size
1358 * GOMP_SPINCOUNT::          Set the busy-wait spin count
1359 * GOMP_RTEMS_THREAD_POOLS:: Set the RTEMS specific thread pools
1360 @end menu
1363 @node OMP_CANCELLATION
1364 @section @env{OMP_CANCELLATION} -- Set whether cancellation is activated
1365 @cindex Environment Variable
1366 @table @asis
1367 @item @emph{Description}:
1368 If set to @code{TRUE}, the cancellation is activated.  If set to @code{FALSE} or
1369 if unset, cancellation is disabled and the @code{cancel} construct is ignored.
1371 @item @emph{See also}:
1372 @ref{omp_get_cancellation}
1374 @item @emph{Reference}:
1375 @uref{http://www.openmp.org/, OpenMP specification v4.5}, Section 4.11
1376 @end table
1380 @node OMP_DISPLAY_ENV
1381 @section @env{OMP_DISPLAY_ENV} -- Show OpenMP version and environment variables
1382 @cindex Environment Variable
1383 @table @asis
1384 @item @emph{Description}:
1385 If set to @code{TRUE}, the OpenMP version number and the values
1386 associated with the OpenMP environment variables are printed to @code{stderr}.
1387 If set to @code{VERBOSE}, it additionally shows the value of the environment
1388 variables which are GNU extensions.  If undefined or set to @code{FALSE},
1389 this information will not be shown.
1392 @item @emph{Reference}:
1393 @uref{http://www.openmp.org/, OpenMP specification v4.5}, Section 4.12
1394 @end table
1398 @node OMP_DEFAULT_DEVICE
1399 @section @env{OMP_DEFAULT_DEVICE} -- Set the device used in target regions
1400 @cindex Environment Variable
1401 @table @asis
1402 @item @emph{Description}:
1403 Set to choose the device which is used in a @code{target} region, unless the
1404 value is overridden by @code{omp_set_default_device} or by a @code{device}
1405 clause.  The value shall be the nonnegative device number. If no device with
1406 the given device number exists, the code is executed on the host.  If unset,
1407 device number 0 will be used.
1410 @item @emph{See also}:
1411 @ref{omp_get_default_device}, @ref{omp_set_default_device},
1413 @item @emph{Reference}:
1414 @uref{http://www.openmp.org/, OpenMP specification v4.5}, Section 4.13
1415 @end table
1419 @node OMP_DYNAMIC
1420 @section @env{OMP_DYNAMIC} -- Dynamic adjustment of threads
1421 @cindex Environment Variable
1422 @table @asis
1423 @item @emph{Description}:
1424 Enable or disable the dynamic adjustment of the number of threads 
1425 within a team.  The value of this environment variable shall be 
1426 @code{TRUE} or @code{FALSE}.  If undefined, dynamic adjustment is
1427 disabled by default.
1429 @item @emph{See also}:
1430 @ref{omp_set_dynamic}
1432 @item @emph{Reference}: 
1433 @uref{http://www.openmp.org/, OpenMP specification v4.5}, Section 4.3
1434 @end table
1438 @node OMP_MAX_ACTIVE_LEVELS
1439 @section @env{OMP_MAX_ACTIVE_LEVELS} -- Set the maximum number of nested parallel regions
1440 @cindex Environment Variable
1441 @table @asis
1442 @item @emph{Description}:
1443 Specifies the initial value for the maximum number of nested parallel
1444 regions.  The value of this variable shall be a positive integer.
1445 If undefined, the number of active levels is unlimited.
1447 @item @emph{See also}:
1448 @ref{omp_set_max_active_levels}
1450 @item @emph{Reference}: 
1451 @uref{http://www.openmp.org/, OpenMP specification v4.5}, Section 4.9
1452 @end table
1456 @node OMP_MAX_TASK_PRIORITY
1457 @section @env{OMP_MAX_TASK_PRIORITY} -- Set the maximum priority
1458 number that can be set for a task.
1459 @cindex Environment Variable
1460 @table @asis
1461 @item @emph{Description}:
1462 Specifies the initial value for the maximum priority value that can be
1463 set for a task.  The value of this variable shall be a non-negative
1464 integer, and zero is allowed.  If undefined, the default priority is
1467 @item @emph{See also}:
1468 @ref{omp_get_max_task_priority}
1470 @item @emph{Reference}: 
1471 @uref{http://www.openmp.org/, OpenMP specification v4.5}, Section 4.14
1472 @end table
1476 @node OMP_NESTED
1477 @section @env{OMP_NESTED} -- Nested parallel regions
1478 @cindex Environment Variable
1479 @cindex Implementation specific setting
1480 @table @asis
1481 @item @emph{Description}:
1482 Enable or disable nested parallel regions, i.e., whether team members
1483 are allowed to create new teams.  The value of this environment variable 
1484 shall be @code{TRUE} or @code{FALSE}.  If undefined, nested parallel 
1485 regions are disabled by default.
1487 @item @emph{See also}:
1488 @ref{omp_set_nested}
1490 @item @emph{Reference}: 
1491 @uref{http://www.openmp.org/, OpenMP specification v4.5}, Section 4.6
1492 @end table
1496 @node OMP_NUM_THREADS
1497 @section @env{OMP_NUM_THREADS} -- Specifies the number of threads to use
1498 @cindex Environment Variable
1499 @cindex Implementation specific setting
1500 @table @asis
1501 @item @emph{Description}:
1502 Specifies the default number of threads to use in parallel regions.  The 
1503 value of this variable shall be a comma-separated list of positive integers;
1504 the value specified the number of threads to use for the corresponding nested
1505 level.  If undefined one thread per CPU is used.
1507 @item @emph{See also}:
1508 @ref{omp_set_num_threads}
1510 @item @emph{Reference}: 
1511 @uref{http://www.openmp.org/, OpenMP specification v4.5}, Section 4.2
1512 @end table
1516 @node OMP_PROC_BIND
1517 @section @env{OMP_PROC_BIND} -- Whether theads may be moved between CPUs
1518 @cindex Environment Variable
1519 @table @asis
1520 @item @emph{Description}:
1521 Specifies whether threads may be moved between processors.  If set to
1522 @code{TRUE}, OpenMP theads should not be moved; if set to @code{FALSE}
1523 they may be moved.  Alternatively, a comma separated list with the
1524 values @code{MASTER}, @code{CLOSE} and @code{SPREAD} can be used to specify
1525 the thread affinity policy for the corresponding nesting level.  With
1526 @code{MASTER} the worker threads are in the same place partition as the
1527 master thread.  With @code{CLOSE} those are kept close to the master thread
1528 in contiguous place partitions.  And with @code{SPREAD} a sparse distribution
1529 across the place partitions is used.
1531 When undefined, @env{OMP_PROC_BIND} defaults to @code{TRUE} when
1532 @env{OMP_PLACES} or @env{GOMP_CPU_AFFINITY} is set and @code{FALSE} otherwise.
1534 @item @emph{See also}:
1535 @ref{OMP_PLACES}, @ref{GOMP_CPU_AFFINITY}, @ref{omp_get_proc_bind}
1537 @item @emph{Reference}:
1538 @uref{http://www.openmp.org/, OpenMP specification v4.5}, Section 4.4
1539 @end table
1543 @node OMP_PLACES
1544 @section @env{OMP_PLACES} -- Specifies on which CPUs the theads should be placed
1545 @cindex Environment Variable
1546 @table @asis
1547 @item @emph{Description}:
1548 The thread placement can be either specified using an abstract name or by an
1549 explicit list of the places.  The abstract names @code{threads}, @code{cores}
1550 and @code{sockets} can be optionally followed by a positive number in
1551 parentheses, which denotes the how many places shall be created.  With
1552 @code{threads} each place corresponds to a single hardware thread; @code{cores}
1553 to a single core with the corresponding number of hardware threads; and with
1554 @code{sockets} the place corresponds to a single socket.  The resulting
1555 placement can be shown by setting the @env{OMP_DISPLAY_ENV} environment
1556 variable.
1558 Alternatively, the placement can be specified explicitly as comma-separated
1559 list of places.  A place is specified by set of nonnegative numbers in curly
1560 braces, denoting the denoting the hardware threads.  The hardware threads
1561 belonging to a place can either be specified as comma-separated list of
1562 nonnegative thread numbers or using an interval.  Multiple places can also be
1563 either specified by a comma-separated list of places or by an interval.  To
1564 specify an interval, a colon followed by the count is placed after after
1565 the hardware thread number or the place.  Optionally, the length can be
1566 followed by a colon and the stride number -- otherwise a unit stride is
1567 assumed.  For instance, the following specifies the same places list:
1568 @code{"@{0,1,2@}, @{3,4,6@}, @{7,8,9@}, @{10,11,12@}"};
1569 @code{"@{0:3@}, @{3:3@}, @{7:3@}, @{10:3@}"}; and @code{"@{0:2@}:4:3"}.
1571 If @env{OMP_PLACES} and @env{GOMP_CPU_AFFINITY} are unset and
1572 @env{OMP_PROC_BIND} is either unset or @code{false}, threads may be moved
1573 between CPUs following no placement policy.
1575 @item @emph{See also}:
1576 @ref{OMP_PROC_BIND}, @ref{GOMP_CPU_AFFINITY}, @ref{omp_get_proc_bind},
1577 @ref{OMP_DISPLAY_ENV}
1579 @item @emph{Reference}:
1580 @uref{http://www.openmp.org/, OpenMP specification v4.5}, Section 4.5
1581 @end table
1585 @node OMP_STACKSIZE
1586 @section @env{OMP_STACKSIZE} -- Set default thread stack size
1587 @cindex Environment Variable
1588 @table @asis
1589 @item @emph{Description}:
1590 Set the default thread stack size in kilobytes, unless the number
1591 is suffixed by @code{B}, @code{K}, @code{M} or @code{G}, in which
1592 case the size is, respectively, in bytes, kilobytes, megabytes
1593 or gigabytes.  This is different from @code{pthread_attr_setstacksize}
1594 which gets the number of bytes as an argument.  If the stack size cannot
1595 be set due to system constraints, an error is reported and the initial
1596 stack size is left unchanged.  If undefined, the stack size is system
1597 dependent.
1599 @item @emph{Reference}: 
1600 @uref{http://www.openmp.org/, OpenMP specification v4.5}, Section 4.7
1601 @end table
1605 @node OMP_SCHEDULE
1606 @section @env{OMP_SCHEDULE} -- How threads are scheduled
1607 @cindex Environment Variable
1608 @cindex Implementation specific setting
1609 @table @asis
1610 @item @emph{Description}:
1611 Allows to specify @code{schedule type} and @code{chunk size}. 
1612 The value of the variable shall have the form: @code{type[,chunk]} where
1613 @code{type} is one of @code{static}, @code{dynamic}, @code{guided} or @code{auto}
1614 The optional @code{chunk} size shall be a positive integer.  If undefined,
1615 dynamic scheduling and a chunk size of 1 is used.
1617 @item @emph{See also}:
1618 @ref{omp_set_schedule}
1620 @item @emph{Reference}: 
1621 @uref{http://www.openmp.org/, OpenMP specification v4.5}, Sections 2.7.1.1 and 4.1
1622 @end table
1626 @node OMP_THREAD_LIMIT
1627 @section @env{OMP_THREAD_LIMIT} -- Set the maximum number of threads
1628 @cindex Environment Variable
1629 @table @asis
1630 @item @emph{Description}:
1631 Specifies the number of threads to use for the whole program.  The
1632 value of this variable shall be a positive integer.  If undefined,
1633 the number of threads is not limited.
1635 @item @emph{See also}:
1636 @ref{OMP_NUM_THREADS}, @ref{omp_get_thread_limit}
1638 @item @emph{Reference}: 
1639 @uref{http://www.openmp.org/, OpenMP specification v4.5}, Section 4.10
1640 @end table
1644 @node OMP_WAIT_POLICY
1645 @section @env{OMP_WAIT_POLICY} -- How waiting threads are handled
1646 @cindex Environment Variable
1647 @table @asis
1648 @item @emph{Description}:
1649 Specifies whether waiting threads should be active or passive.  If
1650 the value is @code{PASSIVE}, waiting threads should not consume CPU
1651 power while waiting; while the value is @code{ACTIVE} specifies that
1652 they should.  If undefined, threads wait actively for a short time
1653 before waiting passively.
1655 @item @emph{See also}:
1656 @ref{GOMP_SPINCOUNT}
1658 @item @emph{Reference}: 
1659 @uref{http://www.openmp.org/, OpenMP specification v4.5}, Section 4.8
1660 @end table
1664 @node GOMP_CPU_AFFINITY
1665 @section @env{GOMP_CPU_AFFINITY} -- Bind threads to specific CPUs
1666 @cindex Environment Variable
1667 @table @asis
1668 @item @emph{Description}:
1669 Binds threads to specific CPUs.  The variable should contain a space-separated
1670 or comma-separated list of CPUs.  This list may contain different kinds of 
1671 entries: either single CPU numbers in any order, a range of CPUs (M-N) 
1672 or a range with some stride (M-N:S).  CPU numbers are zero based.  For example,
1673 @code{GOMP_CPU_AFFINITY="0 3 1-2 4-15:2"} will bind the initial thread
1674 to CPU 0, the second to CPU 3, the third to CPU 1, the fourth to 
1675 CPU 2, the fifth to CPU 4, the sixth through tenth to CPUs 6, 8, 10, 12,
1676 and 14 respectively and then start assigning back from the beginning of
1677 the list.  @code{GOMP_CPU_AFFINITY=0} binds all threads to CPU 0.
1679 There is no libgomp library routine to determine whether a CPU affinity
1680 specification is in effect.  As a workaround, language-specific library 
1681 functions, e.g., @code{getenv} in C or @code{GET_ENVIRONMENT_VARIABLE} in 
1682 Fortran, may be used to query the setting of the @code{GOMP_CPU_AFFINITY} 
1683 environment variable.  A defined CPU affinity on startup cannot be changed 
1684 or disabled during the runtime of the application.
1686 If both @env{GOMP_CPU_AFFINITY} and @env{OMP_PROC_BIND} are set,
1687 @env{OMP_PROC_BIND} has a higher precedence.  If neither has been set and
1688 @env{OMP_PROC_BIND} is unset, or when @env{OMP_PROC_BIND} is set to
1689 @code{FALSE}, the host system will handle the assignment of threads to CPUs.
1691 @item @emph{See also}:
1692 @ref{OMP_PLACES}, @ref{OMP_PROC_BIND}
1693 @end table
1697 @node GOMP_DEBUG
1698 @section @env{GOMP_DEBUG} -- Enable debugging output
1699 @cindex Environment Variable
1700 @table @asis
1701 @item @emph{Description}:
1702 Enable debugging output.  The variable should be set to @code{0}
1703 (disabled, also the default if not set), or @code{1} (enabled).
1705 If enabled, some debugging output will be printed during execution.
1706 This is currently not specified in more detail, and subject to change.
1707 @end table
1711 @node GOMP_STACKSIZE
1712 @section @env{GOMP_STACKSIZE} -- Set default thread stack size
1713 @cindex Environment Variable
1714 @cindex Implementation specific setting
1715 @table @asis
1716 @item @emph{Description}:
1717 Set the default thread stack size in kilobytes.  This is different from
1718 @code{pthread_attr_setstacksize} which gets the number of bytes as an 
1719 argument.  If the stack size cannot be set due to system constraints, an 
1720 error is reported and the initial stack size is left unchanged.  If undefined,
1721 the stack size is system dependent.
1723 @item @emph{See also}:
1724 @ref{OMP_STACKSIZE}
1726 @item @emph{Reference}: 
1727 @uref{http://gcc.gnu.org/ml/gcc-patches/2006-06/msg00493.html, 
1728 GCC Patches Mailinglist}, 
1729 @uref{http://gcc.gnu.org/ml/gcc-patches/2006-06/msg00496.html,
1730 GCC Patches Mailinglist}
1731 @end table
1735 @node GOMP_SPINCOUNT
1736 @section @env{GOMP_SPINCOUNT} -- Set the busy-wait spin count
1737 @cindex Environment Variable
1738 @cindex Implementation specific setting
1739 @table @asis
1740 @item @emph{Description}:
1741 Determines how long a threads waits actively with consuming CPU power
1742 before waiting passively without consuming CPU power.  The value may be
1743 either @code{INFINITE}, @code{INFINITY} to always wait actively or an
1744 integer which gives the number of spins of the busy-wait loop.  The
1745 integer may optionally be followed by the following suffixes acting
1746 as multiplication factors: @code{k} (kilo, thousand), @code{M} (mega,
1747 million), @code{G} (giga, billion), or @code{T} (tera, trillion).
1748 If undefined, 0 is used when @env{OMP_WAIT_POLICY} is @code{PASSIVE},
1749 300,000 is used when @env{OMP_WAIT_POLICY} is undefined and
1750 30 billion is used when @env{OMP_WAIT_POLICY} is @code{ACTIVE}.
1751 If there are more OpenMP threads than available CPUs, 1000 and 100
1752 spins are used for @env{OMP_WAIT_POLICY} being @code{ACTIVE} or
1753 undefined, respectively; unless the @env{GOMP_SPINCOUNT} is lower
1754 or @env{OMP_WAIT_POLICY} is @code{PASSIVE}.
1756 @item @emph{See also}:
1757 @ref{OMP_WAIT_POLICY}
1758 @end table
1762 @node GOMP_RTEMS_THREAD_POOLS
1763 @section @env{GOMP_RTEMS_THREAD_POOLS} -- Set the RTEMS specific thread pools
1764 @cindex Environment Variable
1765 @cindex Implementation specific setting
1766 @table @asis
1767 @item @emph{Description}:
1768 This environment variable is only used on the RTEMS real-time operating system.
1769 It determines the scheduler instance specific thread pools.  The format for
1770 @env{GOMP_RTEMS_THREAD_POOLS} is a list of optional
1771 @code{<thread-pool-count>[$<priority>]@@<scheduler-name>} configurations
1772 separated by @code{:} where:
1773 @itemize @bullet
1774 @item @code{<thread-pool-count>} is the thread pool count for this scheduler
1775 instance.
1776 @item @code{$<priority>} is an optional priority for the worker threads of a
1777 thread pool according to @code{pthread_setschedparam}.  In case a priority
1778 value is omitted, then a worker thread will inherit the priority of the OpenMP
1779 master thread that created it.  The priority of the worker thread is not
1780 changed after creation, even if a new OpenMP master thread using the worker has
1781 a different priority.
1782 @item @code{@@<scheduler-name>} is the scheduler instance name according to the
1783 RTEMS application configuration.
1784 @end itemize
1785 In case no thread pool configuration is specified for a scheduler instance,
1786 then each OpenMP master thread of this scheduler instance will use its own
1787 dynamically allocated thread pool.  To limit the worker thread count of the
1788 thread pools, each OpenMP master thread must call @code{omp_set_num_threads}.
1789 @item @emph{Example}:
1790 Lets suppose we have three scheduler instances @code{IO}, @code{WRK0}, and
1791 @code{WRK1} with @env{GOMP_RTEMS_THREAD_POOLS} set to
1792 @code{"1@@WRK0:3$4@@WRK1"}.  Then there are no thread pool restrictions for
1793 scheduler instance @code{IO}.  In the scheduler instance @code{WRK0} there is
1794 one thread pool available.  Since no priority is specified for this scheduler
1795 instance, the worker thread inherits the priority of the OpenMP master thread
1796 that created it.  In the scheduler instance @code{WRK1} there are three thread
1797 pools available and their worker threads run at priority four.
1798 @end table
1802 @c ---------------------------------------------------------------------
1803 @c Enabling OpenACC
1804 @c ---------------------------------------------------------------------
1806 @node Enabling OpenACC
1807 @chapter Enabling OpenACC
1809 To activate the OpenACC extensions for C/C++ and Fortran, the compile-time 
1810 flag @option{-fopenacc} must be specified.  This enables the OpenACC directive
1811 @code{#pragma acc} in C/C++ and @code{!$accp} directives in free form,
1812 @code{c$acc}, @code{*$acc} and @code{!$acc} directives in fixed form,
1813 @code{!$} conditional compilation sentinels in free form and @code{c$},
1814 @code{*$} and @code{!$} sentinels in fixed form, for Fortran.  The flag also
1815 arranges for automatic linking of the OpenACC runtime library 
1816 (@ref{OpenACC Runtime Library Routines}).
1818 A complete description of all OpenACC directives accepted may be found in 
1819 the @uref{https://www.openacc.org, OpenACC} Application Programming
1820 Interface manual, version 2.0.
1822 Note that this is an experimental feature and subject to
1823 change in future versions of GCC.  See
1824 @uref{https://gcc.gnu.org/wiki/OpenACC} for more information.
1828 @c ---------------------------------------------------------------------
1829 @c OpenACC Runtime Library Routines
1830 @c ---------------------------------------------------------------------
1832 @node OpenACC Runtime Library Routines
1833 @chapter OpenACC Runtime Library Routines
1835 The runtime routines described here are defined by section 3 of the OpenACC
1836 specifications in version 2.0.
1837 They have C linkage, and do not throw exceptions.
1838 Generally, they are available only for the host, with the exception of
1839 @code{acc_on_device}, which is available for both the host and the
1840 acceleration device.
1842 @menu
1843 * acc_get_num_devices::         Get number of devices for the given device
1844                                 type.
1845 * acc_set_device_type::         Set type of device accelerator to use.
1846 * acc_get_device_type::         Get type of device accelerator to be used.
1847 * acc_set_device_num::          Set device number to use.
1848 * acc_get_device_num::          Get device number to be used.
1849 * acc_async_test::              Tests for completion of a specific asynchronous
1850                                 operation.
1851 * acc_async_test_all::          Tests for completion of all asychronous
1852                                 operations.
1853 * acc_wait::                    Wait for completion of a specific asynchronous
1854                                 operation.
1855 * acc_wait_all::                Waits for completion of all asyncrhonous
1856                                 operations.
1857 * acc_wait_all_async::          Wait for completion of all asynchronous
1858                                 operations.
1859 * acc_wait_async::              Wait for completion of asynchronous operations.
1860 * acc_init::                    Initialize runtime for a specific device type.
1861 * acc_shutdown::                Shuts down the runtime for a specific device
1862                                 type.
1863 * acc_on_device::               Whether executing on a particular device
1864 * acc_malloc::                  Allocate device memory.
1865 * acc_free::                    Free device memory.
1866 * acc_copyin::                  Allocate device memory and copy host memory to
1867                                 it.
1868 * acc_present_or_copyin::       If the data is not present on the device,
1869                                 allocate device memory and copy from host
1870                                 memory.
1871 * acc_create::                  Allocate device memory and map it to host
1872                                 memory.
1873 * acc_present_or_create::       If the data is not present on the device,
1874                                 allocate device memory and map it to host
1875                                 memory.
1876 * acc_copyout::                 Copy device memory to host memory.
1877 * acc_delete::                  Free device memory.
1878 * acc_update_device::           Update device memory from mapped host memory.
1879 * acc_update_self::             Update host memory from mapped device memory.
1880 * acc_map_data::                Map previously allocated device memory to host
1881                                 memory.
1882 * acc_unmap_data::              Unmap device memory from host memory.
1883 * acc_deviceptr::               Get device pointer associated with specific
1884                                 host address.
1885 * acc_hostptr::                 Get host pointer associated with specific
1886                                 device address.
1887 * acc_is_present::              Indiciate whether host variable / array is
1888                                 present on device.
1889 * acc_memcpy_to_device::        Copy host memory to device memory.
1890 * acc_memcpy_from_device::      Copy device memory to host memory.
1892 API routines for target platforms.
1894 * acc_get_current_cuda_device:: Get CUDA device handle.
1895 * acc_get_current_cuda_context::Get CUDA context handle.
1896 * acc_get_cuda_stream::         Get CUDA stream handle.
1897 * acc_set_cuda_stream::         Set CUDA stream handle.
1898 @end menu
1902 @node acc_get_num_devices
1903 @section @code{acc_get_num_devices} -- Get number of devices for given device type
1904 @table @asis
1905 @item @emph{Description}
1906 This function returns a value indicating the number of devices available
1907 for the device type specified in @var{devicetype}. 
1909 @item @emph{C/C++}:
1910 @multitable @columnfractions .20 .80
1911 @item @emph{Prototype}: @tab @code{int acc_get_num_devices(acc_device_t devicetype);}
1912 @end multitable
1914 @item @emph{Fortran}:
1915 @multitable @columnfractions .20 .80
1916 @item @emph{Interface}: @tab @code{integer function acc_get_num_devices(devicetype)}
1917 @item                  @tab @code{integer(kind=acc_device_kind) devicetype}
1918 @end multitable
1920 @item @emph{Reference}:
1921 @uref{https://www.openacc.org, OpenACC specification v2.0}, section
1922 3.2.1.
1923 @end table
1927 @node acc_set_device_type
1928 @section @code{acc_set_device_type} -- Set type of device accelerator to use.
1929 @table @asis
1930 @item @emph{Description}
1931 This function indicates to the runtime library which device typr, specified
1932 in @var{devicetype}, to use when executing a parallel or kernels region. 
1934 @item @emph{C/C++}:
1935 @multitable @columnfractions .20 .80
1936 @item @emph{Prototype}: @tab @code{acc_set_device_type(acc_device_t devicetype);}
1937 @end multitable
1939 @item @emph{Fortran}:
1940 @multitable @columnfractions .20 .80
1941 @item @emph{Interface}: @tab @code{subroutine acc_set_device_type(devicetype)}
1942 @item                   @tab @code{integer(kind=acc_device_kind) devicetype}
1943 @end multitable
1945 @item @emph{Reference}:
1946 @uref{https://www.openacc.org, OpenACC specification v2.0}, section
1947 3.2.2.
1948 @end table
1952 @node acc_get_device_type
1953 @section @code{acc_get_device_type} -- Get type of device accelerator to be used.
1954 @table @asis
1955 @item @emph{Description}
1956 This function returns what device type will be used when executing a
1957 parallel or kernels region.
1959 @item @emph{C/C++}:
1960 @multitable @columnfractions .20 .80
1961 @item @emph{Prototype}: @tab @code{acc_device_t acc_get_device_type(void);}
1962 @end multitable
1964 @item @emph{Fortran}:
1965 @multitable @columnfractions .20 .80
1966 @item @emph{Interface}: @tab @code{function acc_get_device_type(void)}
1967 @item                  @tab @code{integer(kind=acc_device_kind) acc_get_device_type}
1968 @end multitable
1970 @item @emph{Reference}:
1971 @uref{https://www.openacc.org, OpenACC specification v2.0}, section
1972 3.2.3.
1973 @end table
1977 @node acc_set_device_num
1978 @section @code{acc_set_device_num} -- Set device number to use.
1979 @table @asis
1980 @item @emph{Description}
1981 This function will indicate to the runtime which device number,
1982 specified by @var{num}, associated with the specifed device
1983 type @var{devicetype}.
1985 @item @emph{C/C++}:
1986 @multitable @columnfractions .20 .80
1987 @item @emph{Prototype}: @tab @code{acc_set_device_num(int num, acc_device_t devicetype);}
1988 @end multitable
1990 @item @emph{Fortran}:
1991 @multitable @columnfractions .20 .80
1992 @item @emph{Interface}: @tab @code{subroutine acc_set_device_num(devicenum, devicetype)}
1993 @item                   @tab @code{integer devicenum}
1994 @item                   @tab @code{integer(kind=acc_device_kind) devicetype}
1995 @end multitable
1997 @item @emph{Reference}:
1998 @uref{https://www.openacc.org, OpenACC specification v2.0}, section
1999 3.2.4.
2000 @end table
2004 @node acc_get_device_num
2005 @section @code{acc_get_device_num} -- Get device number to be used.
2006 @table @asis
2007 @item @emph{Description}
2008 This function returns which device number associated with the specified device
2009 type @var{devicetype}, will be used when executing a parallel or kernels
2010 region.
2012 @item @emph{C/C++}:
2013 @multitable @columnfractions .20 .80
2014 @item @emph{Prototype}: @tab @code{int acc_get_device_num(acc_device_t devicetype);}
2015 @end multitable
2017 @item @emph{Fortran}:
2018 @multitable @columnfractions .20 .80
2019 @item @emph{Interface}: @tab @code{function acc_get_device_num(devicetype)}
2020 @item                   @tab @code{integer(kind=acc_device_kind) devicetype}
2021 @item                   @tab @code{integer acc_get_device_num}
2022 @end multitable
2024 @item @emph{Reference}:
2025 @uref{https://www.openacc.org, OpenACC specification v2.0}, section
2026 3.2.5.
2027 @end table
2031 @node acc_async_test
2032 @section @code{acc_async_test} -- Test for completion of a specific asynchronous operation.
2033 @table @asis
2034 @item @emph{Description}
2035 This function tests for completion of the asynchrounous operation specified
2036 in @var{arg}. In C/C++, a non-zero value will be returned to indicate
2037 the specified asynchronous operation has completed. While Fortran will return
2038 a @code{true}. If the asynchrounous operation has not completed, C/C++ returns
2039 a zero and Fortran returns a @code{false}.
2041 @item @emph{C/C++}:
2042 @multitable @columnfractions .20 .80
2043 @item @emph{Prototype}: @tab @code{int acc_async_test(int arg);}
2044 @end multitable
2046 @item @emph{Fortran}:
2047 @multitable @columnfractions .20 .80
2048 @item @emph{Interface}: @tab @code{function acc_async_test(arg)}
2049 @item                   @tab @code{integer(kind=acc_handle_kind) arg}
2050 @item                   @tab @code{logical acc_async_test}
2051 @end multitable
2053 @item @emph{Reference}:
2054 @uref{https://www.openacc.org, OpenACC specification v2.0}, section
2055 3.2.6.
2056 @end table
2060 @node acc_async_test_all
2061 @section @code{acc_async_test_all} -- Tests for completion of all asynchronous operations.
2062 @table @asis
2063 @item @emph{Description}
2064 This function tests for completion of all asynchrounous operations.
2065 In C/C++, a non-zero value will be returned to indicate all asynchronous
2066 operations have completed. While Fortran will return a @code{true}. If
2067 any asynchronous operation has not completed, C/C++ returns a zero and
2068 Fortran returns a @code{false}.
2070 @item @emph{C/C++}:
2071 @multitable @columnfractions .20 .80
2072 @item @emph{Prototype}: @tab @code{int acc_async_test_all(void);}
2073 @end multitable
2075 @item @emph{Fortran}:
2076 @multitable @columnfractions .20 .80
2077 @item @emph{Interface}: @tab @code{function acc_async_test()}
2078 @item                   @tab @code{logical acc_get_device_num}
2079 @end multitable
2081 @item @emph{Reference}:
2082 @uref{https://www.openacc.org, OpenACC specification v2.0}, section
2083 3.2.7.
2084 @end table
2088 @node acc_wait
2089 @section @code{acc_wait} -- Wait for completion of a specific asynchronous operation.
2090 @table @asis
2091 @item @emph{Description}
2092 This function waits for completion of the asynchronous operation
2093 specified in @var{arg}.
2095 @item @emph{C/C++}:
2096 @multitable @columnfractions .20 .80
2097 @item @emph{Prototype}: @tab @code{acc_wait(arg);}
2098 @item @emph{Prototype (OpenACC 1.0 compatibility)}: @tab @code{acc_async_wait(arg);}
2099 @end multitable
2101 @item @emph{Fortran}:
2102 @multitable @columnfractions .20 .80
2103 @item @emph{Interface}: @tab @code{subroutine acc_wait(arg)}
2104 @item                   @tab @code{integer(acc_handle_kind) arg}
2105 @item @emph{Interface (OpenACC 1.0 compatibility)}: @tab @code{subroutine acc_async_wait(arg)}
2106 @item                                               @tab @code{integer(acc_handle_kind) arg}
2107 @end multitable
2109 @item @emph{Reference}:
2110 @uref{https://www.openacc.org, OpenACC specification v2.0}, section
2111 3.2.8.
2112 @end table
2116 @node acc_wait_all
2117 @section @code{acc_wait_all} -- Waits for completion of all asynchronous operations.
2118 @table @asis
2119 @item @emph{Description}
2120 This function waits for the completion of all asynchronous operations.
2122 @item @emph{C/C++}:
2123 @multitable @columnfractions .20 .80
2124 @item @emph{Prototype}: @tab @code{acc_wait_all(void);}
2125 @item @emph{Prototype (OpenACC 1.0 compatibility)}: @tab @code{acc_async_wait_all(void);}
2126 @end multitable
2128 @item @emph{Fortran}:
2129 @multitable @columnfractions .20 .80
2130 @item @emph{Interface}: @tab @code{subroutine acc_wait_all()}
2131 @item @emph{Interface (OpenACC 1.0 compatibility)}: @tab @code{subroutine acc_async_wait_all()}
2132 @end multitable
2134 @item @emph{Reference}:
2135 @uref{https://www.openacc.org, OpenACC specification v2.0}, section
2136 3.2.10.
2137 @end table
2141 @node acc_wait_all_async
2142 @section @code{acc_wait_all_async} -- Wait for completion of all asynchronous operations.
2143 @table @asis
2144 @item @emph{Description}
2145 This function enqueues a wait operation on the queue @var{async} for any
2146 and all asynchronous operations that have been previously enqueued on
2147 any queue.
2149 @item @emph{C/C++}:
2150 @multitable @columnfractions .20 .80
2151 @item @emph{Prototype}: @tab @code{acc_wait_all_async(int async);}
2152 @end multitable
2154 @item @emph{Fortran}:
2155 @multitable @columnfractions .20 .80
2156 @item @emph{Interface}: @tab @code{subroutine acc_wait_all_async(async)}
2157 @item                   @tab @code{integer(acc_handle_kind) async}
2158 @end multitable
2160 @item @emph{Reference}:
2161 @uref{https://www.openacc.org, OpenACC specification v2.0}, section
2162 3.2.11.
2163 @end table
2167 @node acc_wait_async
2168 @section @code{acc_wait_async} -- Wait for completion of asynchronous operations.
2169 @table @asis
2170 @item @emph{Description}
2171 This function enqueues a wait operation on queue @var{async} for any and all
2172 asynchronous operations enqueued on queue @var{arg}.
2174 @item @emph{C/C++}:
2175 @multitable @columnfractions .20 .80
2176 @item @emph{Prototype}: @tab @code{acc_wait_async(int arg, int async);}
2177 @end multitable
2179 @item @emph{Fortran}:
2180 @multitable @columnfractions .20 .80
2181 @item @emph{Interface}: @tab @code{subroutine acc_wait_async(arg, async)}
2182 @item                   @tab @code{integer(acc_handle_kind) arg, async}
2183 @end multitable
2185 @item @emph{Reference}:
2186 @uref{https://www.openacc.org, OpenACC specification v2.0}, section
2187 3.2.9.
2188 @end table
2192 @node acc_init
2193 @section @code{acc_init} -- Initialize runtime for a specific device type.
2194 @table @asis
2195 @item @emph{Description}
2196 This function initializes the runtime for the device type specified in
2197 @var{devicetype}.
2199 @item @emph{C/C++}:
2200 @multitable @columnfractions .20 .80
2201 @item @emph{Prototype}: @tab @code{acc_init(acc_device_t devicetype);}
2202 @end multitable
2204 @item @emph{Fortran}:
2205 @multitable @columnfractions .20 .80
2206 @item @emph{Interface}: @tab @code{subroutine acc_init(devicetype)}
2207 @item                   @tab @code{integer(acc_device_kind) devicetype}
2208 @end multitable
2210 @item @emph{Reference}:
2211 @uref{https://www.openacc.org, OpenACC specification v2.0}, section
2212 3.2.12.
2213 @end table
2217 @node acc_shutdown
2218 @section @code{acc_shutdown} -- Shuts down the runtime for a specific device type.
2219 @table @asis
2220 @item @emph{Description}
2221 This function shuts down the runtime for the device type specified in
2222 @var{devicetype}.
2224 @item @emph{C/C++}:
2225 @multitable @columnfractions .20 .80
2226 @item @emph{Prototype}: @tab @code{acc_shutdown(acc_device_t devicetype);}
2227 @end multitable
2229 @item @emph{Fortran}:
2230 @multitable @columnfractions .20 .80
2231 @item @emph{Interface}: @tab @code{subroutine acc_shutdown(devicetype)}
2232 @item                   @tab @code{integer(acc_device_kind) devicetype}
2233 @end multitable
2235 @item @emph{Reference}:
2236 @uref{https://www.openacc.org, OpenACC specification v2.0}, section
2237 3.2.13.
2238 @end table
2242 @node acc_on_device
2243 @section @code{acc_on_device} -- Whether executing on a particular device
2244 @table @asis
2245 @item @emph{Description}:
2246 This function returns whether the program is executing on a particular
2247 device specified in @var{devicetype}. In C/C++ a non-zero value is
2248 returned to indicate the device is execiting on the specified device type.
2249 In Fortran, @code{true} will be returned. If the program is not executing
2250 on the specified device type C/C++ will return a zero, while Fortran will
2251 return @code{false}.
2253 @item @emph{C/C++}:
2254 @multitable @columnfractions .20 .80
2255 @item @emph{Prototype}: @tab @code{acc_on_device(acc_device_t devicetype);}
2256 @end multitable
2258 @item @emph{Fortran}:
2259 @multitable @columnfractions .20 .80
2260 @item @emph{Interface}: @tab @code{function acc_on_device(devicetype)}
2261 @item                   @tab @code{integer(acc_device_kind) devicetype}
2262 @item                   @tab @code{logical acc_on_device}
2263 @end multitable
2266 @item @emph{Reference}:
2267 @uref{https://www.openacc.org, OpenACC specification v2.0}, section
2268 3.2.14.
2269 @end table
2273 @node acc_malloc
2274 @section @code{acc_malloc} -- Allocate device memory.
2275 @table @asis
2276 @item @emph{Description}
2277 This function allocates @var{len} bytes of device memory. It returns
2278 the device address of the allocated memory.
2280 @item @emph{C/C++}:
2281 @multitable @columnfractions .20 .80
2282 @item @emph{Prototype}: @tab @code{d_void* acc_malloc(size_t len);}
2283 @end multitable
2285 @item @emph{Reference}:
2286 @uref{https://www.openacc.org, OpenACC specification v2.0}, section
2287 3.2.15.
2288 @end table
2292 @node acc_free
2293 @section @code{acc_free} -- Free device memory.
2294 @table @asis
2295 @item @emph{Description}
2296 Free previously allocated device memory at the device address @code{a}.
2298 @item @emph{C/C++}:
2299 @multitable @columnfractions .20 .80
2300 @item @emph{Prototype}: @tab @code{acc_free(d_void *a);}
2301 @end multitable
2303 @item @emph{Reference}:
2304 @uref{https://www.openacc.org, OpenACC specification v2.0}, section
2305 3.2.16.
2306 @end table
2310 @node acc_copyin
2311 @section @code{acc_copyin} -- Allocate device memory and copy host memory to it.
2312 @table @asis
2313 @item @emph{Description}
2314 In C/C++, this function allocates @var{len} bytes of device memory
2315 and maps it to the specified host address in @var{a}. The device
2316 address of the newly allocated device memory is returned.
2318 In Fortran, two (2) forms are supported. In the first form, @var{a} specifies
2319 a contiguous array section. The second form @var{a} specifies a
2320 variable or array element and @var{len} specifies the length in bytes.
2322 @item @emph{C/C++}:
2323 @multitable @columnfractions .20 .80
2324 @item @emph{Prototype}: @tab @code{void *acc_copyin(h_void *a, size_t len);}
2325 @end multitable
2327 @item @emph{Fortran}:
2328 @multitable @columnfractions .20 .80
2329 @item @emph{Interface}: @tab @code{subroutine acc_copyin(a)}
2330 @item                   @tab @code{type, dimension(:[,:]...) :: a}
2331 @item @emph{Interface}: @tab @code{subroutine acc_copyin(a, len)}
2332 @item                   @tab @code{type, dimension(:[,:]...) :: a}
2333 @item                   @tab @code{integer len}
2334 @end multitable
2336 @item @emph{Reference}:
2337 @uref{https://www.openacc.org, OpenACC specification v2.0}, section
2338 3.2.17.
2339 @end table
2343 @node acc_present_or_copyin
2344 @section @code{acc_present_or_copyin} -- If the data is not present on the device, allocate device memory and copy from host memory.
2345 @table @asis
2346 @item @emph{Description}
2347 This function tests if the host data specifed by @var{a} and of length
2348 @var{len} is present or not. If it is not present, then device memory
2349 will be allocated and the host memory copied. The device address of
2350 the newly allocated device memory is returned.
2352 In Fortran, two (2) forms are supported. In the first form, @var{a} specifies
2353 a contiguous array section. The second form @var{a} specifies a variable or
2354 array element and @var{len} specifies the length in bytes.
2356 @item @emph{C/C++}:
2357 @multitable @columnfractions .20 .80
2358 @item @emph{Prototype}: @tab @code{void *acc_present_or_copyin(h_void *a, size_t len);}
2359 @item @emph{Prototype}: @tab @code{void *acc_pcopyin(h_void *a, size_t len);}
2360 @end multitable
2362 @item @emph{Fortran}:
2363 @multitable @columnfractions .20 .80
2364 @item @emph{Interface}: @tab @code{subroutine acc_present_or_copyin(a)}
2365 @item                   @tab @code{type, dimension(:[,:]...) :: a}
2366 @item @emph{Interface}: @tab @code{subroutine acc_present_or_copyin(a, len)}
2367 @item                   @tab @code{type, dimension(:[,:]...) :: a}
2368 @item                   @tab @code{integer len}
2369 @item @emph{Interface}: @tab @code{subroutine acc_pcopyin(a)}
2370 @item                   @tab @code{type, dimension(:[,:]...) :: a}
2371 @item @emph{Interface}: @tab @code{subroutine acc_pcopyin(a, len)}
2372 @item                   @tab @code{type, dimension(:[,:]...) :: a}
2373 @item                   @tab @code{integer len}
2374 @end multitable
2376 @item @emph{Reference}:
2377 @uref{https://www.openacc.org, OpenACC specification v2.0}, section
2378 3.2.18.
2379 @end table
2383 @node acc_create
2384 @section @code{acc_create} -- Allocate device memory and map it to host memory.
2385 @table @asis
2386 @item @emph{Description}
2387 This function allocates device memory and maps it to host memory specified
2388 by the host address @var{a} with a length of @var{len} bytes. In C/C++,
2389 the function returns the device address of the allocated device memory.
2391 In Fortran, two (2) forms are supported. In the first form, @var{a} specifies
2392 a contiguous array section. The second form @var{a} specifies a variable or
2393 array element and @var{len} specifies the length in bytes.
2395 @item @emph{C/C++}:
2396 @multitable @columnfractions .20 .80
2397 @item @emph{Prototype}: @tab @code{void *acc_create(h_void *a, size_t len);}
2398 @end multitable
2400 @item @emph{Fortran}:
2401 @multitable @columnfractions .20 .80
2402 @item @emph{Interface}: @tab @code{subroutine acc_create(a)}
2403 @item                   @tab @code{type, dimension(:[,:]...) :: a}
2404 @item @emph{Interface}: @tab @code{subroutine acc_create(a, len)}
2405 @item                   @tab @code{type, dimension(:[,:]...) :: a}
2406 @item                   @tab @code{integer len}
2407 @end multitable
2409 @item @emph{Reference}:
2410 @uref{https://www.openacc.org, OpenACC specification v2.0}, section
2411 3.2.19.
2412 @end table
2416 @node acc_present_or_create
2417 @section @code{acc_present_or_create} -- If the data is not present on the device, allocate device memory and map it to host memory.
2418 @table @asis
2419 @item @emph{Description}
2420 This function tests if the host data specifed by @var{a} and of length
2421 @var{len} is present or not. If it is not present, then device memory
2422 will be allocated and mapped to host memory. In C/C++, the device address
2423 of the newly allocated device memory is returned.
2425 In Fortran, two (2) forms are supported. In the first form, @var{a} specifies
2426 a contiguous array section. The second form @var{a} specifies a variable or
2427 array element and @var{len} specifies the length in bytes.
2430 @item @emph{C/C++}:
2431 @multitable @columnfractions .20 .80
2432 @item @emph{Prototype}: @tab @code{void *acc_present_or_create(h_void *a, size_t len)}
2433 @item @emph{Prototype}: @tab @code{void *acc_pcreate(h_void *a, size_t len)}
2434 @end multitable
2436 @item @emph{Fortran}:
2437 @multitable @columnfractions .20 .80
2438 @item @emph{Interface}: @tab @code{subroutine acc_present_or_create(a)}
2439 @item                   @tab @code{type, dimension(:[,:]...) :: a}
2440 @item @emph{Interface}: @tab @code{subroutine acc_present_or_create(a, len)}
2441 @item                   @tab @code{type, dimension(:[,:]...) :: a}
2442 @item                   @tab @code{integer len}
2443 @item @emph{Interface}: @tab @code{subroutine acc_pcreate(a)}
2444 @item                   @tab @code{type, dimension(:[,:]...) :: a}
2445 @item @emph{Interface}: @tab @code{subroutine acc_pcreate(a, len)}
2446 @item                   @tab @code{type, dimension(:[,:]...) :: a}
2447 @item                   @tab @code{integer len}
2448 @end multitable
2450 @item @emph{Reference}:
2451 @uref{https://www.openacc.org, OpenACC specification v2.0}, section
2452 3.2.20.
2453 @end table
2457 @node acc_copyout
2458 @section @code{acc_copyout} -- Copy device memory to host memory.
2459 @table @asis
2460 @item @emph{Description}
2461 This function copies mapped device memory to host memory which is specified
2462 by host address @var{a} for a length @var{len} bytes in C/C++.
2464 In Fortran, two (2) forms are supported. In the first form, @var{a} specifies
2465 a contiguous array section. The second form @var{a} specifies a variable or
2466 array element and @var{len} specifies the length in bytes.
2468 @item @emph{C/C++}:
2469 @multitable @columnfractions .20 .80
2470 @item @emph{Prototype}: @tab @code{acc_copyout(h_void *a, size_t len);}
2471 @end multitable
2473 @item @emph{Fortran}:
2474 @multitable @columnfractions .20 .80
2475 @item @emph{Interface}: @tab @code{subroutine acc_copyout(a)}
2476 @item                   @tab @code{type, dimension(:[,:]...) :: a}
2477 @item @emph{Interface}: @tab @code{subroutine acc_copyout(a, len)}
2478 @item                   @tab @code{type, dimension(:[,:]...) :: a}
2479 @item                   @tab @code{integer len}
2480 @end multitable
2482 @item @emph{Reference}:
2483 @uref{https://www.openacc.org, OpenACC specification v2.0}, section
2484 3.2.21.
2485 @end table
2489 @node acc_delete
2490 @section @code{acc_delete} -- Free device memory.
2491 @table @asis
2492 @item @emph{Description}
2493 This function frees previously allocated device memory specified by
2494 the device address @var{a} and the length of @var{len} bytes.
2496 In Fortran, two (2) forms are supported. In the first form, @var{a} specifies
2497 a contiguous array section. The second form @var{a} specifies a variable or
2498 array element and @var{len} specifies the length in bytes.
2500 @item @emph{C/C++}:
2501 @multitable @columnfractions .20 .80
2502 @item @emph{Prototype}: @tab @code{acc_delete(h_void *a, size_t len);}
2503 @end multitable
2505 @item @emph{Fortran}:
2506 @multitable @columnfractions .20 .80
2507 @item @emph{Interface}: @tab @code{subroutine acc_delete(a)}
2508 @item                   @tab @code{type, dimension(:[,:]...) :: a}
2509 @item @emph{Interface}: @tab @code{subroutine acc_delete(a, len)}
2510 @item                   @tab @code{type, dimension(:[,:]...) :: a}
2511 @item                   @tab @code{integer len}
2512 @end multitable
2514 @item @emph{Reference}:
2515 @uref{https://www.openacc.org, OpenACC specification v2.0}, section
2516 3.2.22.
2517 @end table
2521 @node acc_update_device
2522 @section @code{acc_update_device} -- Update device memory from mapped host memory.
2523 @table @asis
2524 @item @emph{Description}
2525 This function updates the device copy from the previously mapped host memory.
2526 The host memory is specified with the host address @var{a} and a length of
2527 @var{len} bytes.
2529 In Fortran, two (2) forms are supported. In the first form, @var{a} specifies
2530 a contiguous array section. The second form @var{a} specifies a variable or
2531 array element and @var{len} specifies the length in bytes.
2533 @item @emph{C/C++}:
2534 @multitable @columnfractions .20 .80
2535 @item @emph{Prototype}: @tab @code{acc_update_device(h_void *a, size_t len);}
2536 @end multitable
2538 @item @emph{Fortran}:
2539 @multitable @columnfractions .20 .80
2540 @item @emph{Interface}: @tab @code{subroutine acc_update_device(a)}
2541 @item                   @tab @code{type, dimension(:[,:]...) :: a}
2542 @item @emph{Interface}: @tab @code{subroutine acc_update_device(a, len)}
2543 @item                   @tab @code{type, dimension(:[,:]...) :: a}
2544 @item                   @tab @code{integer len}
2545 @end multitable
2547 @item @emph{Reference}:
2548 @uref{https://www.openacc.org, OpenACC specification v2.0}, section
2549 3.2.23.
2550 @end table
2554 @node acc_update_self
2555 @section @code{acc_update_self} -- Update host memory from mapped device memory.
2556 @table @asis
2557 @item @emph{Description}
2558 This function updates the host copy from the previously mapped device memory.
2559 The host memory is specified with the host address @var{a} and a length of
2560 @var{len} bytes.
2562 In Fortran, two (2) forms are supported. In the first form, @var{a} specifies
2563 a contiguous array section. The second form @var{a} specifies a variable or
2564 array element and @var{len} specifies the length in bytes.
2566 @item @emph{C/C++}:
2567 @multitable @columnfractions .20 .80
2568 @item @emph{Prototype}: @tab @code{acc_update_self(h_void *a, size_t len);}
2569 @end multitable
2571 @item @emph{Fortran}:
2572 @multitable @columnfractions .20 .80
2573 @item @emph{Interface}: @tab @code{subroutine acc_update_self(a)}
2574 @item                   @tab @code{type, dimension(:[,:]...) :: a}
2575 @item @emph{Interface}: @tab @code{subroutine acc_update_self(a, len)}
2576 @item                   @tab @code{type, dimension(:[,:]...) :: a}
2577 @item                   @tab @code{integer len}
2578 @end multitable
2580 @item @emph{Reference}:
2581 @uref{https://www.openacc.org, OpenACC specification v2.0}, section
2582 3.2.24.
2583 @end table
2587 @node acc_map_data
2588 @section @code{acc_map_data} -- Map previously allocated device memory to host memory.
2589 @table @asis
2590 @item @emph{Description}
2591 This function maps previously allocated device and host memory. The device
2592 memory is specified with the device address @var{d}. The host memory is
2593 specified with the host address @var{h} and a length of @var{len}.
2595 @item @emph{C/C++}:
2596 @multitable @columnfractions .20 .80
2597 @item @emph{Prototype}: @tab @code{acc_map_data(h_void *h, d_void *d, size_t len);}
2598 @end multitable
2600 @item @emph{Reference}:
2601 @uref{https://www.openacc.org, OpenACC specification v2.0}, section
2602 3.2.25.
2603 @end table
2607 @node acc_unmap_data
2608 @section @code{acc_unmap_data} -- Unmap device memory from host memory.
2609 @table @asis
2610 @item @emph{Description}
2611 This function unmaps previously mapped device and host memory. The latter
2612 specified by @var{h}.
2614 @item @emph{C/C++}:
2615 @multitable @columnfractions .20 .80
2616 @item @emph{Prototype}: @tab @code{acc_unmap_data(h_void *h);}
2617 @end multitable
2619 @item @emph{Reference}:
2620 @uref{https://www.openacc.org, OpenACC specification v2.0}, section
2621 3.2.26.
2622 @end table
2626 @node acc_deviceptr
2627 @section @code{acc_deviceptr} -- Get device pointer associated with specific host address.
2628 @table @asis
2629 @item @emph{Description}
2630 This function returns the device address that has been mapped to the
2631 host address specified by @var{h}.
2633 @item @emph{C/C++}:
2634 @multitable @columnfractions .20 .80
2635 @item @emph{Prototype}: @tab @code{void *acc_deviceptr(h_void *h);}
2636 @end multitable
2638 @item @emph{Reference}:
2639 @uref{https://www.openacc.org, OpenACC specification v2.0}, section
2640 3.2.27.
2641 @end table
2645 @node acc_hostptr
2646 @section @code{acc_hostptr} -- Get host pointer associated with specific device address.
2647 @table @asis
2648 @item @emph{Description}
2649 This function returns the host address that has been mapped to the
2650 device address specified by @var{d}.
2652 @item @emph{C/C++}:
2653 @multitable @columnfractions .20 .80
2654 @item @emph{Prototype}: @tab @code{void *acc_hostptr(d_void *d);}
2655 @end multitable
2657 @item @emph{Reference}:
2658 @uref{https://www.openacc.org, OpenACC specification v2.0}, section
2659 3.2.28.
2660 @end table
2664 @node acc_is_present
2665 @section @code{acc_is_present} -- Indicate whether host variable / array is present on device.
2666 @table @asis
2667 @item @emph{Description}
2668 This function indicates whether the specified host address in @var{a} and a
2669 length of @var{len} bytes is present on the device. In C/C++, a non-zero
2670 value is returned to indicate the presence of the mapped memory on the
2671 device. A zero is returned to indicate the memory is not mapped on the
2672 device.
2674 In Fortran, two (2) forms are supported. In the first form, @var{a} specifies
2675 a contiguous array section. The second form @var{a} specifies a variable or
2676 array element and @var{len} specifies the length in bytes. If the host
2677 memory is mapped to device memory, then a @code{true} is returned. Otherwise,
2678 a @code{false} is return to indicate the mapped memory is not present.
2680 @item @emph{C/C++}:
2681 @multitable @columnfractions .20 .80
2682 @item @emph{Prototype}: @tab @code{int acc_is_present(h_void *a, size_t len);}
2683 @end multitable
2685 @item @emph{Fortran}:
2686 @multitable @columnfractions .20 .80
2687 @item @emph{Interface}: @tab @code{function acc_is_present(a)}
2688 @item                   @tab @code{type, dimension(:[,:]...) :: a}
2689 @item                   @tab @code{logical acc_is_present}
2690 @item @emph{Interface}: @tab @code{function acc_is_present(a, len)}
2691 @item                   @tab @code{type, dimension(:[,:]...) :: a}
2692 @item                   @tab @code{integer len}
2693 @item                   @tab @code{logical acc_is_present}
2694 @end multitable
2696 @item @emph{Reference}:
2697 @uref{https://www.openacc.org, OpenACC specification v2.0}, section
2698 3.2.29.
2699 @end table
2703 @node acc_memcpy_to_device
2704 @section @code{acc_memcpy_to_device} -- Copy host memory to device memory.
2705 @table @asis
2706 @item @emph{Description}
2707 This function copies host memory specified by host address of @var{src} to
2708 device memory specified by the device address @var{dest} for a length of
2709 @var{bytes} bytes.
2711 @item @emph{C/C++}:
2712 @multitable @columnfractions .20 .80
2713 @item @emph{Prototype}: @tab @code{acc_memcpy_to_device(d_void *dest, h_void *src, size_t bytes);}
2714 @end multitable
2716 @item @emph{Reference}:
2717 @uref{https://www.openacc.org, OpenACC specification v2.0}, section
2718 3.2.30.
2719 @end table
2723 @node acc_memcpy_from_device
2724 @section @code{acc_memcpy_from_device} -- Copy device memory to host memory.
2725 @table @asis
2726 @item @emph{Description}
2727 This function copies host memory specified by host address of @var{src} from
2728 device memory specified by the device address @var{dest} for a length of
2729 @var{bytes} bytes.
2731 @item @emph{C/C++}:
2732 @multitable @columnfractions .20 .80
2733 @item @emph{Prototype}: @tab @code{acc_memcpy_from_device(d_void *dest, h_void *src, size_t bytes);}
2734 @end multitable
2736 @item @emph{Reference}:
2737 @uref{https://www.openacc.org, OpenACC specification v2.0}, section
2738 3.2.31.
2739 @end table
2743 @node acc_get_current_cuda_device
2744 @section @code{acc_get_current_cuda_device} -- Get CUDA device handle.
2745 @table @asis
2746 @item @emph{Description}
2747 This function returns the CUDA device handle. This handle is the same
2748 as used by the CUDA Runtime or Driver API's.
2750 @item @emph{C/C++}:
2751 @multitable @columnfractions .20 .80
2752 @item @emph{Prototype}: @tab @code{void *acc_get_current_cuda_device(void);}
2753 @end multitable
2755 @item @emph{Reference}:
2756 @uref{https://www.openacc.org, OpenACC specification v2.0}, section
2757 A.2.1.1.
2758 @end table
2762 @node acc_get_current_cuda_context
2763 @section @code{acc_get_current_cuda_context} -- Get CUDA context handle.
2764 @table @asis
2765 @item @emph{Description}
2766 This function returns the CUDA context handle. This handle is the same
2767 as used by the CUDA Runtime or Driver API's.
2769 @item @emph{C/C++}:
2770 @multitable @columnfractions .20 .80
2771 @item @emph{Prototype}: @tab @code{acc_get_current_cuda_context(void);}
2772 @end multitable
2774 @item @emph{Reference}:
2775 @uref{https://www.openacc.org, OpenACC specification v2.0}, section
2776 A.2.1.2.
2777 @end table
2781 @node acc_get_cuda_stream
2782 @section @code{acc_get_cuda_stream} -- Get CUDA stream handle.
2783 @table @asis
2784 @item @emph{Description}
2785 This function returns the CUDA stream handle. This handle is the same
2786 as used by the CUDA Runtime or Driver API's.
2788 @item @emph{C/C++}:
2789 @multitable @columnfractions .20 .80
2790 @item @emph{Prototype}: @tab @code{acc_get_cuda_stream(void);}
2791 @end multitable
2793 @item @emph{Reference}:
2794 @uref{https://www.openacc.org, OpenACC specification v2.0}, section
2795 A.2.1.3.
2796 @end table
2800 @node acc_set_cuda_stream
2801 @section @code{acc_set_cuda_stream} -- Set CUDA stream handle.
2802 @table @asis
2803 @item @emph{Description}
2804 This function associates the stream handle specified by @var{stream} with
2805 the asynchronous value specified by @var{async}.
2807 @item @emph{C/C++}:
2808 @multitable @columnfractions .20 .80
2809 @item @emph{Prototype}: @tab @code{acc_set_cuda_stream(int async void *stream);}
2810 @end multitable
2812 @item @emph{Reference}:
2813 @uref{https://www.openacc.org, OpenACC specification v2.0}, section
2814 A.2.1.4.
2815 @end table
2819 @c ---------------------------------------------------------------------
2820 @c OpenACC Environment Variables
2821 @c ---------------------------------------------------------------------
2823 @node OpenACC Environment Variables
2824 @chapter OpenACC Environment Variables
2826 The variables @env{ACC_DEVICE_TYPE} and @env{ACC_DEVICE_NUM}
2827 are defined by section 4 of the OpenACC specification in version 2.0.
2828 The variable @env{GCC_ACC_NOTIFY} is used for diagnostic purposes.
2830 @menu
2831 * ACC_DEVICE_TYPE::
2832 * ACC_DEVICE_NUM::
2833 * GCC_ACC_NOTIFY::
2834 @end menu
2838 @node ACC_DEVICE_TYPE
2839 @section @code{ACC_DEVICE_TYPE}
2840 @table @asis
2841 @item @emph{Reference}:
2842 @uref{https://www.openacc.org, OpenACC specification v2.0}, section
2843 4.1.
2844 @end table
2848 @node ACC_DEVICE_NUM
2849 @section @code{ACC_DEVICE_NUM}
2850 @table @asis
2851 @item @emph{Reference}:
2852 @uref{https://www.openacc.org, OpenACC specification v2.0}, section
2853 4.2.
2854 @end table
2858 @node GCC_ACC_NOTIFY
2859 @section @code{GCC_ACC_NOTIFY}
2860 @table @asis
2861 @item @emph{Description}:
2862 Print debug information pertaining to the accelerator.
2863 @end table
2867 @c ---------------------------------------------------------------------
2868 @c CUDA Streams Usage
2869 @c ---------------------------------------------------------------------
2871 @node CUDA Streams Usage
2872 @chapter CUDA Streams Usage
2874 This applies to the @code{nvptx} plugin only.
2876 The library provides elements that perform asynchronous movement of
2877 data and asynchronous operation of computing constructs.  This
2878 asynchronous functionality is implemented by making use of CUDA
2879 streams@footnote{See "Stream Management" in "CUDA Driver API",
2880 TRM-06703-001, Version 5.5, for additional information}.
2882 The primary means by that the asychronous functionality is accessed
2883 is through the use of those OpenACC directives which make use of the
2884 @code{async} and @code{wait} clauses.  When the @code{async} clause is
2885 first used with a directive, it creates a CUDA stream.  If an
2886 @code{async-argument} is used with the @code{async} clause, then the
2887 stream is associated with the specified @code{async-argument}.
2889 Following the creation of an association between a CUDA stream and the
2890 @code{async-argument} of an @code{async} clause, both the @code{wait}
2891 clause and the @code{wait} directive can be used.  When either the
2892 clause or directive is used after stream creation, it creates a
2893 rendezvous point whereby execution waits until all operations
2894 associated with the @code{async-argument}, that is, stream, have
2895 completed.
2897 Normally, the management of the streams that are created as a result of
2898 using the @code{async} clause, is done without any intervention by the
2899 caller.  This implies the association between the @code{async-argument}
2900 and the CUDA stream will be maintained for the lifetime of the program.
2901 However, this association can be changed through the use of the library
2902 function @code{acc_set_cuda_stream}.  When the function
2903 @code{acc_set_cuda_stream} is called, the CUDA stream that was
2904 originally associated with the @code{async} clause will be destroyed.
2905 Caution should be taken when changing the association as subsequent
2906 references to the @code{async-argument} refer to a different
2907 CUDA stream.
2911 @c ---------------------------------------------------------------------
2912 @c OpenACC Library Interoperability
2913 @c ---------------------------------------------------------------------
2915 @node OpenACC Library Interoperability
2916 @chapter OpenACC Library Interoperability
2918 @section Introduction
2920 The OpenACC library uses the CUDA Driver API, and may interact with
2921 programs that use the Runtime library directly, or another library
2922 based on the Runtime library, e.g., CUBLAS@footnote{See section 2.26,
2923 "Interactions with the CUDA Driver API" in
2924 "CUDA Runtime API", Version 5.5, and section 2.27, "VDPAU
2925 Interoperability", in "CUDA Driver API", TRM-06703-001, Version 5.5,
2926 for additional information on library interoperability.}.
2927 This chapter describes the use cases and what changes are
2928 required in order to use both the OpenACC library and the CUBLAS and Runtime
2929 libraries within a program.
2931 @section First invocation: NVIDIA CUBLAS library API
2933 In this first use case (see below), a function in the CUBLAS library is called
2934 prior to any of the functions in the OpenACC library. More specifically, the
2935 function @code{cublasCreate()}.
2937 When invoked, the function initializes the library and allocates the
2938 hardware resources on the host and the device on behalf of the caller. Once
2939 the initialization and allocation has completed, a handle is returned to the
2940 caller. The OpenACC library also requires initialization and allocation of
2941 hardware resources. Since the CUBLAS library has already allocated the
2942 hardware resources for the device, all that is left to do is to initialize
2943 the OpenACC library and acquire the hardware resources on the host.
2945 Prior to calling the OpenACC function that initializes the library and
2946 allocate the host hardware resources, you need to acquire the device number
2947 that was allocated during the call to @code{cublasCreate()}. The invoking of the
2948 runtime library function @code{cudaGetDevice()} accomplishes this. Once
2949 acquired, the device number is passed along with the device type as
2950 parameters to the OpenACC library function @code{acc_set_device_num()}.
2952 Once the call to @code{acc_set_device_num()} has completed, the OpenACC
2953 library uses the  context that was created during the call to
2954 @code{cublasCreate()}. In other words, both libraries will be sharing the
2955 same context.
2957 @smallexample
2958     /* Create the handle */
2959     s = cublasCreate(&h);
2960     if (s != CUBLAS_STATUS_SUCCESS)
2961     @{
2962         fprintf(stderr, "cublasCreate failed %d\n", s);
2963         exit(EXIT_FAILURE);
2964     @}
2966     /* Get the device number */
2967     e = cudaGetDevice(&dev);
2968     if (e != cudaSuccess)
2969     @{
2970         fprintf(stderr, "cudaGetDevice failed %d\n", e);
2971         exit(EXIT_FAILURE);
2972     @}
2974     /* Initialize OpenACC library and use device 'dev' */
2975     acc_set_device_num(dev, acc_device_nvidia);
2977 @end smallexample
2978 @center Use Case 1 
2980 @section First invocation: OpenACC library API
2982 In this second use case (see below), a function in the OpenACC library is
2983 called prior to any of the functions in the CUBLAS library. More specificially,
2984 the function @code{acc_set_device_num()}.
2986 In the use case presented here, the function @code{acc_set_device_num()}
2987 is used to both initialize the OpenACC library and allocate the hardware
2988 resources on the host and the device. In the call to the function, the
2989 call parameters specify which device to use and what device
2990 type to use, i.e., @code{acc_device_nvidia}. It should be noted that this
2991 is but one method to initialize the OpenACC library and allocate the
2992 appropriate hardware resources. Other methods are available through the
2993 use of environment variables and these will be discussed in the next section.
2995 Once the call to @code{acc_set_device_num()} has completed, other OpenACC
2996 functions can be called as seen with multiple calls being made to
2997 @code{acc_copyin()}. In addition, calls can be made to functions in the
2998 CUBLAS library. In the use case a call to @code{cublasCreate()} is made
2999 subsequent to the calls to @code{acc_copyin()}.
3000 As seen in the previous use case, a call to @code{cublasCreate()}
3001 initializes the CUBLAS library and allocates the hardware resources on the
3002 host and the device.  However, since the device has already been allocated,
3003 @code{cublasCreate()} will only initialize the CUBLAS library and allocate
3004 the appropriate hardware resources on the host. The context that was created
3005 as part of the OpenACC initialization is shared with the CUBLAS library,
3006 similarly to the first use case.
3008 @smallexample
3009     dev = 0;
3011     acc_set_device_num(dev, acc_device_nvidia);
3013     /* Copy the first set to the device */
3014     d_X = acc_copyin(&h_X[0], N * sizeof (float));
3015     if (d_X == NULL)
3016     @{ 
3017         fprintf(stderr, "copyin error h_X\n");
3018         exit(EXIT_FAILURE);
3019     @}
3021     /* Copy the second set to the device */
3022     d_Y = acc_copyin(&h_Y1[0], N * sizeof (float));
3023     if (d_Y == NULL)
3024     @{ 
3025         fprintf(stderr, "copyin error h_Y1\n");
3026         exit(EXIT_FAILURE);
3027     @}
3029     /* Create the handle */
3030     s = cublasCreate(&h);
3031     if (s != CUBLAS_STATUS_SUCCESS)
3032     @{
3033         fprintf(stderr, "cublasCreate failed %d\n", s);
3034         exit(EXIT_FAILURE);
3035     @}
3037     /* Perform saxpy using CUBLAS library function */
3038     s = cublasSaxpy(h, N, &alpha, d_X, 1, d_Y, 1);
3039     if (s != CUBLAS_STATUS_SUCCESS)
3040     @{
3041         fprintf(stderr, "cublasSaxpy failed %d\n", s);
3042         exit(EXIT_FAILURE);
3043     @}
3045     /* Copy the results from the device */
3046     acc_memcpy_from_device(&h_Y1[0], d_Y, N * sizeof (float));
3048 @end smallexample
3049 @center Use Case 2
3051 @section OpenACC library and environment variables
3053 There are two environment variables associated with the OpenACC library
3054 that may be used to control the device type and device number:
3055 @env{ACC_DEVICE_TYPE} and @env{ACC_DEVICE_NUM}, respecively. These two
3056 environement variables can be used as an alternative to calling
3057 @code{acc_set_device_num()}. As seen in the second use case, the device
3058 type and device number were specified using @code{acc_set_device_num()}.
3059 If however, the aforementioned environment variables were set, then the
3060 call to @code{acc_set_device_num()} would not be required.
3063 The use of the environment variables is only relevant when an OpenACC function
3064 is called prior to a call to @code{cudaCreate()}. If @code{cudaCreate()}
3065 is called prior to a call to an OpenACC function, then you must call
3066 @code{acc_set_device_num()}@footnote{More complete information
3067 about @env{ACC_DEVICE_TYPE} and @env{ACC_DEVICE_NUM} can be found in
3068 sections 4.1 and 4.2 of the @uref{https://www.openacc.org, OpenACC}
3069 Application Programming Interface”, Version 2.0.}
3073 @c ---------------------------------------------------------------------
3074 @c The libgomp ABI
3075 @c ---------------------------------------------------------------------
3077 @node The libgomp ABI
3078 @chapter The libgomp ABI
3080 The following sections present notes on the external ABI as 
3081 presented by libgomp.  Only maintainers should need them.
3083 @menu
3084 * Implementing MASTER construct::
3085 * Implementing CRITICAL construct::
3086 * Implementing ATOMIC construct::
3087 * Implementing FLUSH construct::
3088 * Implementing BARRIER construct::
3089 * Implementing THREADPRIVATE construct::
3090 * Implementing PRIVATE clause::
3091 * Implementing FIRSTPRIVATE LASTPRIVATE COPYIN and COPYPRIVATE clauses::
3092 * Implementing REDUCTION clause::
3093 * Implementing PARALLEL construct::
3094 * Implementing FOR construct::
3095 * Implementing ORDERED construct::
3096 * Implementing SECTIONS construct::
3097 * Implementing SINGLE construct::
3098 * Implementing OpenACC's PARALLEL construct::
3099 @end menu
3102 @node Implementing MASTER construct
3103 @section Implementing MASTER construct
3105 @smallexample
3106 if (omp_get_thread_num () == 0)
3107   block
3108 @end smallexample
3110 Alternately, we generate two copies of the parallel subfunction
3111 and only include this in the version run by the master thread.
3112 Surely this is not worthwhile though...
3116 @node Implementing CRITICAL construct
3117 @section Implementing CRITICAL construct
3119 Without a specified name,
3121 @smallexample
3122   void GOMP_critical_start (void);
3123   void GOMP_critical_end (void);
3124 @end smallexample
3126 so that we don't get COPY relocations from libgomp to the main
3127 application.
3129 With a specified name, use omp_set_lock and omp_unset_lock with
3130 name being transformed into a variable declared like
3132 @smallexample
3133   omp_lock_t gomp_critical_user_<name> __attribute__((common))
3134 @end smallexample
3136 Ideally the ABI would specify that all zero is a valid unlocked
3137 state, and so we wouldn't need to initialize this at
3138 startup.
3142 @node Implementing ATOMIC construct
3143 @section Implementing ATOMIC construct
3145 The target should implement the @code{__sync} builtins.
3147 Failing that we could add
3149 @smallexample
3150   void GOMP_atomic_enter (void)
3151   void GOMP_atomic_exit (void)
3152 @end smallexample
3154 which reuses the regular lock code, but with yet another lock
3155 object private to the library.
3159 @node Implementing FLUSH construct
3160 @section Implementing FLUSH construct
3162 Expands to the @code{__sync_synchronize} builtin.
3166 @node Implementing BARRIER construct
3167 @section Implementing BARRIER construct
3169 @smallexample
3170   void GOMP_barrier (void)
3171 @end smallexample
3174 @node Implementing THREADPRIVATE construct
3175 @section Implementing THREADPRIVATE construct
3177 In _most_ cases we can map this directly to @code{__thread}.  Except
3178 that OMP allows constructors for C++ objects.  We can either
3179 refuse to support this (how often is it used?) or we can 
3180 implement something akin to .ctors.
3182 Even more ideally, this ctor feature is handled by extensions
3183 to the main pthreads library.  Failing that, we can have a set
3184 of entry points to register ctor functions to be called.
3188 @node Implementing PRIVATE clause
3189 @section Implementing PRIVATE clause
3191 In association with a PARALLEL, or within the lexical extent
3192 of a PARALLEL block, the variable becomes a local variable in
3193 the parallel subfunction.
3195 In association with FOR or SECTIONS blocks, create a new
3196 automatic variable within the current function.  This preserves
3197 the semantic of new variable creation.
3201 @node Implementing FIRSTPRIVATE LASTPRIVATE COPYIN and COPYPRIVATE clauses
3202 @section Implementing FIRSTPRIVATE LASTPRIVATE COPYIN and COPYPRIVATE clauses
3204 This seems simple enough for PARALLEL blocks.  Create a private 
3205 struct for communicating between the parent and subfunction.
3206 In the parent, copy in values for scalar and "small" structs;
3207 copy in addresses for others TREE_ADDRESSABLE types.  In the 
3208 subfunction, copy the value into the local variable.
3210 It is not clear what to do with bare FOR or SECTION blocks.
3211 The only thing I can figure is that we do something like:
3213 @smallexample
3214 #pragma omp for firstprivate(x) lastprivate(y)
3215 for (int i = 0; i < n; ++i)
3216   body;
3217 @end smallexample
3219 which becomes
3221 @smallexample
3223   int x = x, y;
3225   // for stuff
3227   if (i == n)
3228     y = y;
3230 @end smallexample
3232 where the "x=x" and "y=y" assignments actually have different
3233 uids for the two variables, i.e. not something you could write
3234 directly in C.  Presumably this only makes sense if the "outer"
3235 x and y are global variables.
3237 COPYPRIVATE would work the same way, except the structure 
3238 broadcast would have to happen via SINGLE machinery instead.
3242 @node Implementing REDUCTION clause
3243 @section Implementing REDUCTION clause
3245 The private struct mentioned in the previous section should have 
3246 a pointer to an array of the type of the variable, indexed by the 
3247 thread's @var{team_id}.  The thread stores its final value into the 
3248 array, and after the barrier, the master thread iterates over the
3249 array to collect the values.
3252 @node Implementing PARALLEL construct
3253 @section Implementing PARALLEL construct
3255 @smallexample
3256   #pragma omp parallel
3257   @{
3258     body;
3259   @}
3260 @end smallexample
3262 becomes
3264 @smallexample
3265   void subfunction (void *data)
3266   @{
3267     use data;
3268     body;
3269   @}
3271   setup data;
3272   GOMP_parallel_start (subfunction, &data, num_threads);
3273   subfunction (&data);
3274   GOMP_parallel_end ();
3275 @end smallexample
3277 @smallexample
3278   void GOMP_parallel_start (void (*fn)(void *), void *data, unsigned num_threads)
3279 @end smallexample
3281 The @var{FN} argument is the subfunction to be run in parallel.
3283 The @var{DATA} argument is a pointer to a structure used to 
3284 communicate data in and out of the subfunction, as discussed
3285 above with respect to FIRSTPRIVATE et al.
3287 The @var{NUM_THREADS} argument is 1 if an IF clause is present
3288 and false, or the value of the NUM_THREADS clause, if
3289 present, or 0.
3291 The function needs to create the appropriate number of
3292 threads and/or launch them from the dock.  It needs to
3293 create the team structure and assign team ids.
3295 @smallexample
3296   void GOMP_parallel_end (void)
3297 @end smallexample
3299 Tears down the team and returns us to the previous @code{omp_in_parallel()} state.
3303 @node Implementing FOR construct
3304 @section Implementing FOR construct
3306 @smallexample
3307   #pragma omp parallel for
3308   for (i = lb; i <= ub; i++)
3309     body;
3310 @end smallexample
3312 becomes
3314 @smallexample
3315   void subfunction (void *data)
3316   @{
3317     long _s0, _e0;
3318     while (GOMP_loop_static_next (&_s0, &_e0))
3319     @{
3320       long _e1 = _e0, i;
3321       for (i = _s0; i < _e1; i++)
3322         body;
3323     @}
3324     GOMP_loop_end_nowait ();
3325   @}
3327   GOMP_parallel_loop_static (subfunction, NULL, 0, lb, ub+1, 1, 0);
3328   subfunction (NULL);
3329   GOMP_parallel_end ();
3330 @end smallexample
3332 @smallexample
3333   #pragma omp for schedule(runtime)
3334   for (i = 0; i < n; i++)
3335     body;
3336 @end smallexample
3338 becomes
3340 @smallexample
3341   @{
3342     long i, _s0, _e0;
3343     if (GOMP_loop_runtime_start (0, n, 1, &_s0, &_e0))
3344       do @{
3345         long _e1 = _e0;
3346         for (i = _s0, i < _e0; i++)
3347           body;
3348       @} while (GOMP_loop_runtime_next (&_s0, _&e0));
3349     GOMP_loop_end ();
3350   @}
3351 @end smallexample
3353 Note that while it looks like there is trickiness to propagating
3354 a non-constant STEP, there isn't really.  We're explicitly allowed
3355 to evaluate it as many times as we want, and any variables involved
3356 should automatically be handled as PRIVATE or SHARED like any other
3357 variables.  So the expression should remain evaluable in the 
3358 subfunction.  We can also pull it into a local variable if we like,
3359 but since its supposed to remain unchanged, we can also not if we like.
3361 If we have SCHEDULE(STATIC), and no ORDERED, then we ought to be
3362 able to get away with no work-sharing context at all, since we can
3363 simply perform the arithmetic directly in each thread to divide up
3364 the iterations.  Which would mean that we wouldn't need to call any
3365 of these routines.
3367 There are separate routines for handling loops with an ORDERED
3368 clause.  Bookkeeping for that is non-trivial...
3372 @node Implementing ORDERED construct
3373 @section Implementing ORDERED construct
3375 @smallexample
3376   void GOMP_ordered_start (void)
3377   void GOMP_ordered_end (void)
3378 @end smallexample
3382 @node Implementing SECTIONS construct
3383 @section Implementing SECTIONS construct
3385 A block as 
3387 @smallexample
3388   #pragma omp sections
3389   @{
3390     #pragma omp section
3391     stmt1;
3392     #pragma omp section
3393     stmt2;
3394     #pragma omp section
3395     stmt3;
3396   @}
3397 @end smallexample
3399 becomes
3401 @smallexample
3402   for (i = GOMP_sections_start (3); i != 0; i = GOMP_sections_next ())
3403     switch (i)
3404       @{
3405       case 1:
3406         stmt1;
3407         break;
3408       case 2:
3409         stmt2;
3410         break;
3411       case 3:
3412         stmt3;
3413         break;
3414       @}
3415   GOMP_barrier ();
3416 @end smallexample
3419 @node Implementing SINGLE construct
3420 @section Implementing SINGLE construct
3422 A block like 
3424 @smallexample
3425   #pragma omp single
3426   @{
3427     body;
3428   @}
3429 @end smallexample
3431 becomes
3433 @smallexample
3434   if (GOMP_single_start ())
3435     body;
3436   GOMP_barrier ();
3437 @end smallexample
3439 while 
3441 @smallexample
3442   #pragma omp single copyprivate(x)
3443     body;
3444 @end smallexample
3446 becomes
3448 @smallexample
3449   datap = GOMP_single_copy_start ();
3450   if (datap == NULL)
3451     @{
3452       body;
3453       data.x = x;
3454       GOMP_single_copy_end (&data);
3455     @}
3456   else
3457     x = datap->x;
3458   GOMP_barrier ();
3459 @end smallexample
3463 @node Implementing OpenACC's PARALLEL construct
3464 @section Implementing OpenACC's PARALLEL construct
3466 @smallexample
3467   void GOACC_parallel ()
3468 @end smallexample
3472 @c ---------------------------------------------------------------------
3473 @c Reporting Bugs
3474 @c ---------------------------------------------------------------------
3476 @node Reporting Bugs
3477 @chapter Reporting Bugs
3479 Bugs in the GNU Offloading and Multi Processing Runtime Library should
3480 be reported via @uref{http://gcc.gnu.org/bugzilla/, Bugzilla}.  Please add
3481 "openacc", or "openmp", or both to the keywords field in the bug
3482 report, as appropriate.
3486 @c ---------------------------------------------------------------------
3487 @c GNU General Public License
3488 @c ---------------------------------------------------------------------
3490 @include gpl_v3.texi
3494 @c ---------------------------------------------------------------------
3495 @c GNU Free Documentation License
3496 @c ---------------------------------------------------------------------
3498 @include fdl.texi
3502 @c ---------------------------------------------------------------------
3503 @c Funding Free Software
3504 @c ---------------------------------------------------------------------
3506 @include funding.texi
3508 @c ---------------------------------------------------------------------
3509 @c Index
3510 @c ---------------------------------------------------------------------
3512 @node Library Index
3513 @unnumbered Library Index
3515 @printindex cp
3517 @bye