1\input texinfo @c -*-texinfo-*-
2
3@c %**start of header
4@setfilename libgomp.info
5@settitle GNU libgomp
6@c %**end of header
7
8
9@copying
10Copyright @copyright{} 2006-2018 Free Software Foundation, Inc.
11
12Permission is granted to copy, distribute and/or modify this document
13under the terms of the GNU Free Documentation License, Version 1.3 or
14any later version published by the Free Software Foundation; with the
15Invariant Sections being ``Funding Free Software'', the Front-Cover
16texts being (a) (see below), and with the Back-Cover Texts being (b)
17(see below).  A copy of the license is included in the section entitled
18``GNU Free Documentation License''.
19
20(a) The FSF's Front-Cover Text is:
21
22     A GNU Manual
23
24(b) The FSF's Back-Cover Text is:
25
26     You have freedom to copy and modify this GNU Manual, like GNU
27     software.  Copies published by the Free Software Foundation raise
28     funds for GNU development.
29@end copying
30
31@ifinfo
32@dircategory GNU Libraries
33@direntry
34* libgomp: (libgomp).          GNU Offloading and Multi Processing Runtime Library.
35@end direntry
36
37This manual documents libgomp, the GNU Offloading and Multi Processing
38Runtime library.  This is the GNU implementation of the OpenMP and
39OpenACC APIs for parallel and accelerator programming in C/C++ and
40Fortran.
41
42Published by the Free Software Foundation
4351 Franklin Street, Fifth Floor
44Boston, MA 02110-1301 USA
45
46@insertcopying
47@end ifinfo
48
49
50@setchapternewpage odd
51
52@titlepage
53@title GNU Offloading and Multi Processing Runtime Library
54@subtitle The GNU OpenMP and OpenACC Implementation
55@page
56@vskip 0pt plus 1filll
57@comment For the @value{version-GCC} Version*
58@sp 1
59Published by the Free Software Foundation @*
6051 Franklin Street, Fifth Floor@*
61Boston, MA 02110-1301, USA@*
62@sp 1
63@insertcopying
64@end titlepage
65
66@summarycontents
67@contents
68@page
69
70
71@node Top
72@top Introduction
73@cindex Introduction
74
75This manual documents the usage of libgomp, the GNU Offloading and
76Multi Processing Runtime Library.  This includes the GNU
77implementation of the @uref{http://www.openmp.org, OpenMP} Application
78Programming Interface (API) for multi-platform shared-memory parallel
79programming in C/C++ and Fortran, and the GNU implementation of the
80@uref{https://www.openacc.org, OpenACC} Application Programming
81Interface (API) for offloading of code to accelerator devices in C/C++
82and Fortran.
83
84Originally, libgomp implemented the GNU OpenMP Runtime Library.  Based
85on this, support for OpenACC and offloading (both OpenACC and OpenMP
864's target construct) has been added later on, and the library's name
87changed to GNU Offloading and Multi Processing Runtime Library.
88
89
90
91@comment
92@comment  When you add a new menu item, please keep the right hand
93@comment  aligned to the same column.  Do not use tabs.  This provides
94@comment  better formatting.
95@comment
96@menu
97* Enabling OpenMP::            How to enable OpenMP for your applications.
98* 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
123
124
125@c ---------------------------------------------------------------------
126@c Enabling OpenMP
127@c ---------------------------------------------------------------------
128
129@node Enabling OpenMP
130@chapter Enabling OpenMP
131
132To activate the OpenMP extensions for C/C++ and Fortran, the compile-time
133flag @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
138arranges for automatic linking of the OpenMP runtime library
139(@ref{Runtime Library Routines}).
140
141A complete description of all OpenMP directives accepted may be found in
142the @uref{http://www.openmp.org, OpenMP Application Program Interface} manual,
143version 4.5.
144
145
146@c ---------------------------------------------------------------------
147@c Runtime Library Routines
148@c ---------------------------------------------------------------------
149
150@node Runtime Library Routines
151@chapter Runtime Library Routines
152
153The runtime routines described here are defined by Section 3 of the OpenMP
154specification in version 4.5.  The routines are structured in following
155three parts:
156
157@menu
158Control threads, processors and the parallel environment.  They have C
159linkage, and do not throw exceptions.
160
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
190
191Initialize, set, test, unset and destroy simple and nested locks.
192
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
203
204Portable, thread-based, wall clock timer.
205
206* omp_get_wtick::            Get timer precision.
207* omp_get_wtime::            Elapsed wall clock time.
208@end menu
209
210
211
212@node omp_get_active_level
213@section @code{omp_get_active_level} -- Number of parallel regions
214@table @asis
215@item @emph{Description}:
216This function returns the nesting level for the active parallel blocks,
217which enclose the calling call.
218
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
223
224@item @emph{Fortran}:
225@multitable @columnfractions .20 .80
226@item @emph{Interface}: @tab @code{integer function omp_get_active_level()}
227@end multitable
228
229@item @emph{See also}:
230@ref{omp_get_level}, @ref{omp_get_max_active_levels}, @ref{omp_set_max_active_levels}
231
232@item @emph{Reference}:
233@uref{http://www.openmp.org/, OpenMP specification v4.5}, Section 3.2.20.
234@end table
235
236
237
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}:
242This function returns the thread identification number for the given
243nesting level of the current thread.  For values of @var{level} outside
244zero 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}.
246
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
251
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
257
258@item @emph{See also}:
259@ref{omp_get_level}, @ref{omp_get_thread_num}, @ref{omp_get_team_size}
260
261@item @emph{Reference}:
262@uref{http://www.openmp.org/, OpenMP specification v4.5}, Section 3.2.18.
263@end table
264
265
266
267@node omp_get_cancellation
268@section @code{omp_get_cancellation} -- Whether cancellation support is enabled
269@table @asis
270@item @emph{Description}:
271This function returns @code{true} if cancellation is activated, @code{false}
272otherwise.  Here, @code{true} and @code{false} represent their language-specific
273counterparts.  Unless @env{OMP_CANCELLATION} is set true, cancellations are
274deactivated.
275
276@item @emph{C/C++}:
277@multitable @columnfractions .20 .80
278@item @emph{Prototype}: @tab @code{int omp_get_cancellation(void);}
279@end multitable
280
281@item @emph{Fortran}:
282@multitable @columnfractions .20 .80
283@item @emph{Interface}: @tab @code{logical function omp_get_cancellation()}
284@end multitable
285
286@item @emph{See also}:
287@ref{OMP_CANCELLATION}
288
289@item @emph{Reference}:
290@uref{http://www.openmp.org/, OpenMP specification v4.5}, Section 3.2.9.
291@end table
292
293
294
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}:
299Get the default device for target regions without device clause.
300
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
305
306@item @emph{Fortran}:
307@multitable @columnfractions .20 .80
308@item @emph{Interface}: @tab @code{integer function omp_get_default_device()}
309@end multitable
310
311@item @emph{See also}:
312@ref{OMP_DEFAULT_DEVICE}, @ref{omp_set_default_device}
313
314@item @emph{Reference}:
315@uref{http://www.openmp.org/, OpenMP specification v4.5}, Section 3.2.30.
316@end table
317
318
319
320@node omp_get_dynamic
321@section @code{omp_get_dynamic} -- Dynamic teams setting
322@table @asis
323@item @emph{Description}:
324This function returns @code{true} if enabled, @code{false} otherwise.
325Here, @code{true} and @code{false} represent their language-specific
326counterparts.
327
328The 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
331disabled by default.
332
333@item @emph{C/C++}:
334@multitable @columnfractions .20 .80
335@item @emph{Prototype}: @tab @code{int omp_get_dynamic(void);}
336@end multitable
337
338@item @emph{Fortran}:
339@multitable @columnfractions .20 .80
340@item @emph{Interface}: @tab @code{logical function omp_get_dynamic()}
341@end multitable
342
343@item @emph{See also}:
344@ref{omp_set_dynamic}, @ref{OMP_DYNAMIC}
345
346@item @emph{Reference}:
347@uref{http://www.openmp.org/, OpenMP specification v4.5}, Section 3.2.8.
348@end table
349
350
351
352@node omp_get_level
353@section @code{omp_get_level} -- Obtain the current nesting level
354@table @asis
355@item @emph{Description}:
356This function returns the nesting level for the parallel blocks,
357which enclose the calling call.
358
359@item @emph{C/C++}
360@multitable @columnfractions .20 .80
361@item @emph{Prototype}: @tab @code{int omp_get_level(void);}
362@end multitable
363
364@item @emph{Fortran}:
365@multitable @columnfractions .20 .80
366@item @emph{Interface}: @tab @code{integer function omp_level()}
367@end multitable
368
369@item @emph{See also}:
370@ref{omp_get_active_level}
371
372@item @emph{Reference}:
373@uref{http://www.openmp.org/, OpenMP specification v4.5}, Section 3.2.17.
374@end table
375
376
377
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}:
382This function obtains the maximum allowed number of nested, active parallel regions.
383
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
388
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
393
394@item @emph{See also}:
395@ref{omp_set_max_active_levels}, @ref{omp_get_active_level}
396
397@item @emph{Reference}:
398@uref{http://www.openmp.org/, OpenMP specification v4.5}, Section 3.2.16.
399@end table
400
401
402@node omp_get_max_task_priority
403@section @code{omp_get_max_task_priority} -- Maximum priority value
404that can be set for tasks.
405@table @asis
406@item @emph{Description}:
407This function obtains the maximum allowed priority number for tasks.
408
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
413
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
418
419@item @emph{Reference}:
420@uref{http://www.openmp.org/, OpenMP specification v4.5}, Section 3.2.29.
421@end table
422
423
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}:
428Return the maximum number of threads used for the current parallel region
429that does not use the clause @code{num_threads}.
430
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
435
436@item @emph{Fortran}:
437@multitable @columnfractions .20 .80
438@item @emph{Interface}: @tab @code{integer function omp_get_max_threads()}
439@end multitable
440
441@item @emph{See also}:
442@ref{omp_set_num_threads}, @ref{omp_set_dynamic}, @ref{omp_get_thread_limit}
443
444@item @emph{Reference}:
445@uref{http://www.openmp.org/, OpenMP specification v4.5}, Section 3.2.3.
446@end table
447
448
449
450@node omp_get_nested
451@section @code{omp_get_nested} -- Nested parallel regions
452@table @asis
453@item @emph{Description}:
454This function returns @code{true} if nested parallel regions are
455enabled, @code{false} otherwise.  Here, @code{true} and @code{false}
456represent their language-specific counterparts.
457
458Nested 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
461disabled by default.
462
463@item @emph{C/C++}:
464@multitable @columnfractions .20 .80
465@item @emph{Prototype}: @tab @code{int omp_get_nested(void);}
466@end multitable
467
468@item @emph{Fortran}:
469@multitable @columnfractions .20 .80
470@item @emph{Interface}: @tab @code{logical function omp_get_nested()}
471@end multitable
472
473@item @emph{See also}:
474@ref{omp_set_nested}, @ref{OMP_NESTED}
475
476@item @emph{Reference}:
477@uref{http://www.openmp.org/, OpenMP specification v4.5}, Section 3.2.11.
478@end table
479
480
481
482@node omp_get_num_devices
483@section @code{omp_get_num_devices} -- Number of target devices
484@table @asis
485@item @emph{Description}:
486Returns the number of target devices.
487
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
492
493@item @emph{Fortran}:
494@multitable @columnfractions .20 .80
495@item @emph{Interface}: @tab @code{integer function omp_get_num_devices()}
496@end multitable
497
498@item @emph{Reference}:
499@uref{http://www.openmp.org/, OpenMP specification v4.5}, Section 3.2.31.
500@end table
501
502
503
504@node omp_get_num_procs
505@section @code{omp_get_num_procs} -- Number of processors online
506@table @asis
507@item @emph{Description}:
508Returns the number of processors online on that device.
509
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
514
515@item @emph{Fortran}:
516@multitable @columnfractions .20 .80
517@item @emph{Interface}: @tab @code{integer function omp_get_num_procs()}
518@end multitable
519
520@item @emph{Reference}:
521@uref{http://www.openmp.org/, OpenMP specification v4.5}, Section 3.2.5.
522@end table
523
524
525
526@node omp_get_num_teams
527@section @code{omp_get_num_teams} -- Number of teams
528@table @asis
529@item @emph{Description}:
530Returns the number of teams in the current team region.
531
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
536
537@item @emph{Fortran}:
538@multitable @columnfractions .20 .80
539@item @emph{Interface}: @tab @code{integer function omp_get_num_teams()}
540@end multitable
541
542@item @emph{Reference}:
543@uref{http://www.openmp.org/, OpenMP specification v4.5}, Section 3.2.32.
544@end table
545
546
547
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}:
552Returns the number of threads in the current team.  In a sequential section of
553the program @code{omp_get_num_threads} returns 1.
554
555The default team size may be initialized at startup by the
556@env{OMP_NUM_THREADS} environment variable.  At runtime, the size
557of the current team may be set either by the @code{NUM_THREADS}
558clause or by @code{omp_set_num_threads}.  If none of the above were
559used to define a specific value and @env{OMP_DYNAMIC} is disabled,
560one thread per CPU online is used.
561
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
566
567@item @emph{Fortran}:
568@multitable @columnfractions .20 .80
569@item @emph{Interface}: @tab @code{integer function omp_get_num_threads()}
570@end multitable
571
572@item @emph{See also}:
573@ref{omp_get_max_threads}, @ref{omp_set_num_threads}, @ref{OMP_NUM_THREADS}
574
575@item @emph{Reference}:
576@uref{http://www.openmp.org/, OpenMP specification v4.5}, Section 3.2.2.
577@end table
578
579
580
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}:
585This functions returns the currently active thread affinity policy, which is
586set 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}.
589
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
594
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
599
600@item @emph{See also}:
601@ref{OMP_PROC_BIND}, @ref{OMP_PLACES}, @ref{GOMP_CPU_AFFINITY},
602
603@item @emph{Reference}:
604@uref{http://www.openmp.org/, OpenMP specification v4.5}, Section 3.2.22.
605@end table
606
607
608
609@node omp_get_schedule
610@section @code{omp_get_schedule} -- Obtain the runtime scheduling method
611@table @asis
612@item @emph{Description}:
613Obtain the runtime scheduling method.  The @var{kind} argument will be
614set 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.
617
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
622
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
629
630@item @emph{See also}:
631@ref{omp_set_schedule}, @ref{OMP_SCHEDULE}
632
633@item @emph{Reference}:
634@uref{http://www.openmp.org/, OpenMP specification v4.5}, Section 3.2.13.
635@end table
636
637
638
639@node omp_get_team_num
640@section @code{omp_get_team_num} -- Get team number
641@table @asis
642@item @emph{Description}:
643Returns the team number of the calling thread.
644
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
649
650@item @emph{Fortran}:
651@multitable @columnfractions .20 .80
652@item @emph{Interface}: @tab @code{integer function omp_get_team_num()}
653@end multitable
654
655@item @emph{Reference}:
656@uref{http://www.openmp.org/, OpenMP specification v4.5}, Section 3.2.33.
657@end table
658
659
660
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}:
665This function returns the number of threads in a thread team to which
666either the current thread or its ancestor belongs.  For values of @var{level}
667outside zero to @code{omp_get_level}, -1 is returned; if @var{level} is zero,
6681 is returned, and for @code{omp_get_level}, the result is identical
669to @code{omp_get_num_threads}.
670
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
675
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
681
682@item @emph{See also}:
683@ref{omp_get_num_threads}, @ref{omp_get_level}, @ref{omp_get_ancestor_thread_num}
684
685@item @emph{Reference}:
686@uref{http://www.openmp.org/, OpenMP specification v4.5}, Section 3.2.19.
687@end table
688
689
690
691@node omp_get_thread_limit
692@section @code{omp_get_thread_limit} -- Maximum number of threads
693@table @asis
694@item @emph{Description}:
695Return the maximum number of threads of the program.
696
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
701
702@item @emph{Fortran}:
703@multitable @columnfractions .20 .80
704@item @emph{Interface}: @tab @code{integer function omp_get_thread_limit()}
705@end multitable
706
707@item @emph{See also}:
708@ref{omp_get_max_threads}, @ref{OMP_THREAD_LIMIT}
709
710@item @emph{Reference}:
711@uref{http://www.openmp.org/, OpenMP specification v4.5}, Section 3.2.14.
712@end table
713
714
715
716@node omp_get_thread_num
717@section @code{omp_get_thread_num} -- Current thread ID
718@table @asis
719@item @emph{Description}:
720Returns a unique thread identification number within the current team.
721In a sequential parts of the program, @code{omp_get_thread_num}
722always returns 0.  In parallel regions the return value varies
723from 0 to @code{omp_get_num_threads}-1 inclusive.  The return
724value of the master thread of a team is always 0.
725
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
730
731@item @emph{Fortran}:
732@multitable @columnfractions .20 .80
733@item @emph{Interface}: @tab @code{integer function omp_get_thread_num()}
734@end multitable
735
736@item @emph{See also}:
737@ref{omp_get_num_threads}, @ref{omp_get_ancestor_thread_num}
738
739@item @emph{Reference}:
740@uref{http://www.openmp.org/, OpenMP specification v4.5}, Section 3.2.4.
741@end table
742
743
744
745@node omp_in_parallel
746@section @code{omp_in_parallel} -- Whether a parallel region is active
747@table @asis
748@item @emph{Description}:
749This function returns @code{true} if currently running in parallel,
750@code{false} otherwise.  Here, @code{true} and @code{false} represent
751their language-specific counterparts.
752
753@item @emph{C/C++}:
754@multitable @columnfractions .20 .80
755@item @emph{Prototype}: @tab @code{int omp_in_parallel(void);}
756@end multitable
757
758@item @emph{Fortran}:
759@multitable @columnfractions .20 .80
760@item @emph{Interface}: @tab @code{logical function omp_in_parallel()}
761@end multitable
762
763@item @emph{Reference}:
764@uref{http://www.openmp.org/, OpenMP specification v4.5}, Section 3.2.6.
765@end table
766
767
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}:
772This function returns @code{true} if currently running in a final
773or included task region, @code{false} otherwise.  Here, @code{true}
774and @code{false} represent their language-specific counterparts.
775
776@item @emph{C/C++}:
777@multitable @columnfractions .20 .80
778@item @emph{Prototype}: @tab @code{int omp_in_final(void);}
779@end multitable
780
781@item @emph{Fortran}:
782@multitable @columnfractions .20 .80
783@item @emph{Interface}: @tab @code{logical function omp_in_final()}
784@end multitable
785
786@item @emph{Reference}:
787@uref{http://www.openmp.org/, OpenMP specification v4.5}, Section 3.2.21.
788@end table
789
790
791
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}:
796This function returns @code{true} if currently running on the host device,
797@code{false} otherwise.  Here, @code{true} and @code{false} represent
798their language-specific counterparts.
799
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
804
805@item @emph{Fortran}:
806@multitable @columnfractions .20 .80
807@item @emph{Interface}: @tab @code{logical function omp_is_initial_device()}
808@end multitable
809
810@item @emph{Reference}:
811@uref{http://www.openmp.org/, OpenMP specification v4.5}, Section 3.2.34.
812@end table
813
814
815
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}:
820Set the default device for target regions without device clause.  The argument
821shall be a nonnegative device number.
822
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
827
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
833
834@item @emph{See also}:
835@ref{OMP_DEFAULT_DEVICE}, @ref{omp_get_default_device}
836
837@item @emph{Reference}:
838@uref{http://www.openmp.org/, OpenMP specification v4.5}, Section 3.2.29.
839@end table
840
841
842
843@node omp_set_dynamic
844@section @code{omp_set_dynamic} -- Enable/disable dynamic teams
845@table @asis
846@item @emph{Description}:
847Enable or disable the dynamic adjustment of the number of threads
848within a team.  The function takes the language-specific equivalent
849of @code{true} and @code{false}, where @code{true} enables dynamic
850adjustment of team sizes and @code{false} disables it.
851
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
856
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
862
863@item @emph{See also}:
864@ref{OMP_DYNAMIC}, @ref{omp_get_dynamic}
865
866@item @emph{Reference}:
867@uref{http://www.openmp.org/, OpenMP specification v4.5}, Section 3.2.7.
868@end table
869
870
871
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}:
876This function limits the maximum allowed number of nested, active
877parallel regions.
878
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
883
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
889
890@item @emph{See also}:
891@ref{omp_get_max_active_levels}, @ref{omp_get_active_level}
892
893@item @emph{Reference}:
894@uref{http://www.openmp.org/, OpenMP specification v4.5}, Section 3.2.15.
895@end table
896
897
898
899@node omp_set_nested
900@section @code{omp_set_nested} -- Enable/disable nested parallel regions
901@table @asis
902@item @emph{Description}:
903Enable or disable nested parallel regions, i.e., whether team members
904are allowed to create new teams.  The function takes the language-specific
905equivalent of @code{true} and @code{false}, where @code{true} enables
906dynamic adjustment of team sizes and @code{false} disables it.
907
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
912
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
918
919@item @emph{See also}:
920@ref{OMP_NESTED}, @ref{omp_get_nested}
921
922@item @emph{Reference}:
923@uref{http://www.openmp.org/, OpenMP specification v4.5}, Section 3.2.10.
924@end table
925
926
927
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}:
932Specifies the number of threads used by default in subsequent parallel
933sections, if those do not specify a @code{num_threads} clause.  The
934argument of @code{omp_set_num_threads} shall be a positive integer.
935
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
940
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
946
947@item @emph{See also}:
948@ref{OMP_NUM_THREADS}, @ref{omp_get_num_threads}, @ref{omp_get_max_threads}
949
950@item @emph{Reference}:
951@uref{http://www.openmp.org/, OpenMP specification v4.5}, Section 3.2.1.
952@end table
953
954
955
956@node omp_set_schedule
957@section @code{omp_set_schedule} -- Set the runtime scheduling method
958@table @asis
959@item @emph{Description}:
960Sets the runtime scheduling method.  The @var{kind} argument can have the
961value @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.
965For @code{omp_sched_auto} the @var{chunk_size} argument is ignored.
966
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
971
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
978
979@item @emph{See also}:
980@ref{omp_get_schedule}
981@ref{OMP_SCHEDULE}
982
983@item @emph{Reference}:
984@uref{http://www.openmp.org/, OpenMP specification v4.5}, Section 3.2.12.
985@end table
986
987
988
989@node omp_init_lock
990@section @code{omp_init_lock} -- Initialize simple lock
991@table @asis
992@item @emph{Description}:
993Initialize a simple lock.  After initialization, the lock is in
994an unlocked state.
995
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
1000
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
1006
1007@item @emph{See also}:
1008@ref{omp_destroy_lock}
1009
1010@item @emph{Reference}:
1011@uref{http://www.openmp.org/, OpenMP specification v4.5}, Section 3.3.1.
1012@end table
1013
1014
1015
1016@node omp_set_lock
1017@section @code{omp_set_lock} -- Wait for and set simple lock
1018@table @asis
1019@item @emph{Description}:
1020Before setting a simple lock, the lock variable must be initialized by
1021@code{omp_init_lock}.  The calling thread is blocked until the lock
1022is available.  If the lock is already held by the current thread,
1023a deadlock occurs.
1024
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
1029
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
1035
1036@item @emph{See also}:
1037@ref{omp_init_lock}, @ref{omp_test_lock}, @ref{omp_unset_lock}
1038
1039@item @emph{Reference}:
1040@uref{http://www.openmp.org/, OpenMP specification v4.5}, Section 3.3.4.
1041@end table
1042
1043
1044
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}:
1049Before 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}
1051does 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.
1054
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
1059
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
1065
1066@item @emph{See also}:
1067@ref{omp_init_lock}, @ref{omp_set_lock}, @ref{omp_set_lock}
1068
1069@item @emph{Reference}:
1070@uref{http://www.openmp.org/, OpenMP specification v4.5}, Section 3.3.6.
1071@end table
1072
1073
1074
1075@node omp_unset_lock
1076@section @code{omp_unset_lock} -- Unset simple lock
1077@table @asis
1078@item @emph{Description}:
1079A simple lock about to be unset must have been locked by @code{omp_set_lock}
1080or @code{omp_test_lock} before.  In addition, the lock must be held by the
1081thread calling @code{omp_unset_lock}.  Then, the lock becomes unlocked.  If one
1082or more threads attempted to set the lock before, one of them is chosen to,
1083again, set the lock to itself.
1084
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
1089
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
1095
1096@item @emph{See also}:
1097@ref{omp_set_lock}, @ref{omp_test_lock}
1098
1099@item @emph{Reference}:
1100@uref{http://www.openmp.org/, OpenMP specification v4.5}, Section 3.3.5.
1101@end table
1102
1103
1104
1105@node omp_destroy_lock
1106@section @code{omp_destroy_lock} -- Destroy simple lock
1107@table @asis
1108@item @emph{Description}:
1109Destroy a simple lock.  In order to be destroyed, a simple lock must be
1110in the unlocked state.
1111
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
1116
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
1122
1123@item @emph{See also}:
1124@ref{omp_init_lock}
1125
1126@item @emph{Reference}:
1127@uref{http://www.openmp.org/, OpenMP specification v4.5}, Section 3.3.3.
1128@end table
1129
1130
1131
1132@node omp_init_nest_lock
1133@section @code{omp_init_nest_lock} -- Initialize nested lock
1134@table @asis
1135@item @emph{Description}:
1136Initialize a nested lock.  After initialization, the lock is in
1137an unlocked state and the nesting count is set to zero.
1138
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
1143
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
1149
1150@item @emph{See also}:
1151@ref{omp_destroy_nest_lock}
1152
1153@item @emph{Reference}:
1154@uref{http://www.openmp.org/, OpenMP specification v4.5}, Section 3.3.1.
1155@end table
1156
1157
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}:
1162Before 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
1164is available.  If the lock is already held by the current thread, the
1165nesting count for the lock is incremented.
1166
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
1171
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
1177
1178@item @emph{See also}:
1179@ref{omp_init_nest_lock}, @ref{omp_unset_nest_lock}
1180
1181@item @emph{Reference}:
1182@uref{http://www.openmp.org/, OpenMP specification v4.5}, Section 3.3.4.
1183@end table
1184
1185
1186
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}:
1191Before 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.
1194If the lock is already held by the current thread, the new nesting count
1195is returned.  Otherwise, the return value equals zero.
1196
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
1201
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
1207
1208
1209@item @emph{See also}:
1210@ref{omp_init_lock}, @ref{omp_set_lock}, @ref{omp_set_lock}
1211
1212@item @emph{Reference}:
1213@uref{http://www.openmp.org/, OpenMP specification v4.5}, Section 3.3.6.
1214@end table
1215
1216
1217
1218@node omp_unset_nest_lock
1219@section @code{omp_unset_nest_lock} -- Unset nested lock
1220@table @asis
1221@item @emph{Description}:
1222A nested lock about to be unset must have been locked by @code{omp_set_nested_lock}
1223or @code{omp_test_nested_lock} before.  In addition, the lock must be held by the
1224thread calling @code{omp_unset_nested_lock}.  If the nesting count drops to zero, the
1225lock becomes unlocked.  If one ore more threads attempted to set the lock before,
1226one of them is chosen to, again, set the lock to itself.
1227
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
1232
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
1238
1239@item @emph{See also}:
1240@ref{omp_set_nest_lock}
1241
1242@item @emph{Reference}:
1243@uref{http://www.openmp.org/, OpenMP specification v4.5}, Section 3.3.5.
1244@end table
1245
1246
1247
1248@node omp_destroy_nest_lock
1249@section @code{omp_destroy_nest_lock} -- Destroy nested lock
1250@table @asis
1251@item @emph{Description}:
1252Destroy a nested lock.  In order to be destroyed, a nested lock must be
1253in the unlocked state and its nesting count must equal zero.
1254
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
1259
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
1265
1266@item @emph{See also}:
1267@ref{omp_init_lock}
1268
1269@item @emph{Reference}:
1270@uref{http://www.openmp.org/, OpenMP specification v4.5}, Section 3.3.3.
1271@end table
1272
1273
1274
1275@node omp_get_wtick
1276@section @code{omp_get_wtick} -- Get timer precision
1277@table @asis
1278@item @emph{Description}:
1279Gets the timer precision, i.e., the number of seconds between two
1280successive clock ticks.
1281
1282@item @emph{C/C++}:
1283@multitable @columnfractions .20 .80
1284@item @emph{Prototype}: @tab @code{double omp_get_wtick(void);}
1285@end multitable
1286
1287@item @emph{Fortran}:
1288@multitable @columnfractions .20 .80
1289@item @emph{Interface}: @tab @code{double precision function omp_get_wtick()}
1290@end multitable
1291
1292@item @emph{See also}:
1293@ref{omp_get_wtime}
1294
1295@item @emph{Reference}:
1296@uref{http://www.openmp.org/, OpenMP specification v4.5}, Section 3.4.2.
1297@end table
1298
1299
1300
1301@node omp_get_wtime
1302@section @code{omp_get_wtime} -- Elapsed wall clock time
1303@table @asis
1304@item @emph{Description}:
1305Elapsed wall clock time in seconds.  The time is measured per thread, no
1306guarantee can be made that two distinct threads measure the same time.
1307Time is measured from some "time in the past", which is an arbitrary time
1308guaranteed not to change during the execution of the program.
1309
1310@item @emph{C/C++}:
1311@multitable @columnfractions .20 .80
1312@item @emph{Prototype}: @tab @code{double omp_get_wtime(void);}
1313@end multitable
1314
1315@item @emph{Fortran}:
1316@multitable @columnfractions .20 .80
1317@item @emph{Interface}: @tab @code{double precision function omp_get_wtime()}
1318@end multitable
1319
1320@item @emph{See also}:
1321@ref{omp_get_wtick}
1322
1323@item @emph{Reference}:
1324@uref{http://www.openmp.org/, OpenMP specification v4.5}, Section 3.4.1.
1325@end table
1326
1327
1328
1329@c ---------------------------------------------------------------------
1330@c Environment Variables
1331@c ---------------------------------------------------------------------
1332
1333@node Environment Variables
1334@chapter Environment Variables
1335
1336The environment variables which beginning with @env{OMP_} are defined by
1337section 4 of the OpenMP specification in version 4.5, while those
1338beginning with @env{GOMP_} are GNU extensions.
1339
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
1361
1362
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}:
1368If set to @code{TRUE}, the cancellation is activated.  If set to @code{FALSE} or
1369if unset, cancellation is disabled and the @code{cancel} construct is ignored.
1370
1371@item @emph{See also}:
1372@ref{omp_get_cancellation}
1373
1374@item @emph{Reference}:
1375@uref{http://www.openmp.org/, OpenMP specification v4.5}, Section 4.11
1376@end table
1377
1378
1379
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}:
1385If set to @code{TRUE}, the OpenMP version number and the values
1386associated with the OpenMP environment variables are printed to @code{stderr}.
1387If set to @code{VERBOSE}, it additionally shows the value of the environment
1388variables which are GNU extensions.  If undefined or set to @code{FALSE},
1389this information will not be shown.
1390
1391
1392@item @emph{Reference}:
1393@uref{http://www.openmp.org/, OpenMP specification v4.5}, Section 4.12
1394@end table
1395
1396
1397
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}:
1403Set to choose the device which is used in a @code{target} region, unless the
1404value is overridden by @code{omp_set_default_device} or by a @code{device}
1405clause.  The value shall be the nonnegative device number. If no device with
1406the given device number exists, the code is executed on the host.  If unset,
1407device number 0 will be used.
1408
1409
1410@item @emph{See also}:
1411@ref{omp_get_default_device}, @ref{omp_set_default_device},
1412
1413@item @emph{Reference}:
1414@uref{http://www.openmp.org/, OpenMP specification v4.5}, Section 4.13
1415@end table
1416
1417
1418
1419@node OMP_DYNAMIC
1420@section @env{OMP_DYNAMIC} -- Dynamic adjustment of threads
1421@cindex Environment Variable
1422@table @asis
1423@item @emph{Description}:
1424Enable or disable the dynamic adjustment of the number of threads
1425within a team.  The value of this environment variable shall be
1426@code{TRUE} or @code{FALSE}.  If undefined, dynamic adjustment is
1427disabled by default.
1428
1429@item @emph{See also}:
1430@ref{omp_set_dynamic}
1431
1432@item @emph{Reference}:
1433@uref{http://www.openmp.org/, OpenMP specification v4.5}, Section 4.3
1434@end table
1435
1436
1437
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}:
1443Specifies the initial value for the maximum number of nested parallel
1444regions.  The value of this variable shall be a positive integer.
1445If undefined, the number of active levels is unlimited.
1446
1447@item @emph{See also}:
1448@ref{omp_set_max_active_levels}
1449
1450@item @emph{Reference}:
1451@uref{http://www.openmp.org/, OpenMP specification v4.5}, Section 4.9
1452@end table
1453
1454
1455
1456@node OMP_MAX_TASK_PRIORITY
1457@section @env{OMP_MAX_TASK_PRIORITY} -- Set the maximum priority
1458number that can be set for a task.
1459@cindex Environment Variable
1460@table @asis
1461@item @emph{Description}:
1462Specifies the initial value for the maximum priority value that can be
1463set for a task.  The value of this variable shall be a non-negative
1464integer, and zero is allowed.  If undefined, the default priority is
14650.
1466
1467@item @emph{See also}:
1468@ref{omp_get_max_task_priority}
1469
1470@item @emph{Reference}:
1471@uref{http://www.openmp.org/, OpenMP specification v4.5}, Section 4.14
1472@end table
1473
1474
1475
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}:
1482Enable or disable nested parallel regions, i.e., whether team members
1483are allowed to create new teams.  The value of this environment variable
1484shall be @code{TRUE} or @code{FALSE}.  If undefined, nested parallel
1485regions are disabled by default.
1486
1487@item @emph{See also}:
1488@ref{omp_set_nested}
1489
1490@item @emph{Reference}:
1491@uref{http://www.openmp.org/, OpenMP specification v4.5}, Section 4.6
1492@end table
1493
1494
1495
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}:
1502Specifies the default number of threads to use in parallel regions.  The
1503value of this variable shall be a comma-separated list of positive integers;
1504the value specified the number of threads to use for the corresponding nested
1505level.  If undefined one thread per CPU is used.
1506
1507@item @emph{See also}:
1508@ref{omp_set_num_threads}
1509
1510@item @emph{Reference}:
1511@uref{http://www.openmp.org/, OpenMP specification v4.5}, Section 4.2
1512@end table
1513
1514
1515
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}:
1521Specifies whether threads may be moved between processors.  If set to
1522@code{TRUE}, OpenMP theads should not be moved; if set to @code{FALSE}
1523they may be moved.  Alternatively, a comma separated list with the
1524values @code{MASTER}, @code{CLOSE} and @code{SPREAD} can be used to specify
1525the thread affinity policy for the corresponding nesting level.  With
1526@code{MASTER} the worker threads are in the same place partition as the
1527master thread.  With @code{CLOSE} those are kept close to the master thread
1528in contiguous place partitions.  And with @code{SPREAD} a sparse distribution
1529across the place partitions is used.
1530
1531When 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.
1533
1534@item @emph{See also}:
1535@ref{OMP_PLACES}, @ref{GOMP_CPU_AFFINITY}, @ref{omp_get_proc_bind}
1536
1537@item @emph{Reference}:
1538@uref{http://www.openmp.org/, OpenMP specification v4.5}, Section 4.4
1539@end table
1540
1541
1542
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}:
1548The thread placement can be either specified using an abstract name or by an
1549explicit list of the places.  The abstract names @code{threads}, @code{cores}
1550and @code{sockets} can be optionally followed by a positive number in
1551parentheses, which denotes the how many places shall be created.  With
1552@code{threads} each place corresponds to a single hardware thread; @code{cores}
1553to a single core with the corresponding number of hardware threads; and with
1554@code{sockets} the place corresponds to a single socket.  The resulting
1555placement can be shown by setting the @env{OMP_DISPLAY_ENV} environment
1556variable.
1557
1558Alternatively, the placement can be specified explicitly as comma-separated
1559list of places.  A place is specified by set of nonnegative numbers in curly
1560braces, denoting the denoting the hardware threads.  The hardware threads
1561belonging to a place can either be specified as comma-separated list of
1562nonnegative thread numbers or using an interval.  Multiple places can also be
1563either specified by a comma-separated list of places or by an interval.  To
1564specify an interval, a colon followed by the count is placed after after
1565the hardware thread number or the place.  Optionally, the length can be
1566followed by a colon and the stride number -- otherwise a unit stride is
1567assumed.  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"}.
1570
1571If @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
1573between CPUs following no placement policy.
1574
1575@item @emph{See also}:
1576@ref{OMP_PROC_BIND}, @ref{GOMP_CPU_AFFINITY}, @ref{omp_get_proc_bind},
1577@ref{OMP_DISPLAY_ENV}
1578
1579@item @emph{Reference}:
1580@uref{http://www.openmp.org/, OpenMP specification v4.5}, Section 4.5
1581@end table
1582
1583
1584
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}:
1590Set the default thread stack size in kilobytes, unless the number
1591is suffixed by @code{B}, @code{K}, @code{M} or @code{G}, in which
1592case the size is, respectively, in bytes, kilobytes, megabytes
1593or gigabytes.  This is different from @code{pthread_attr_setstacksize}
1594which gets the number of bytes as an argument.  If the stack size cannot
1595be set due to system constraints, an error is reported and the initial
1596stack size is left unchanged.  If undefined, the stack size is system
1597dependent.
1598
1599@item @emph{Reference}:
1600@uref{http://www.openmp.org/, OpenMP specification v4.5}, Section 4.7
1601@end table
1602
1603
1604
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}:
1611Allows to specify @code{schedule type} and @code{chunk size}.
1612The 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}
1614The optional @code{chunk} size shall be a positive integer.  If undefined,
1615dynamic scheduling and a chunk size of 1 is used.
1616
1617@item @emph{See also}:
1618@ref{omp_set_schedule}
1619
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
1623
1624
1625
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}:
1631Specifies the number of threads to use for the whole program.  The
1632value of this variable shall be a positive integer.  If undefined,
1633the number of threads is not limited.
1634
1635@item @emph{See also}:
1636@ref{OMP_NUM_THREADS}, @ref{omp_get_thread_limit}
1637
1638@item @emph{Reference}:
1639@uref{http://www.openmp.org/, OpenMP specification v4.5}, Section 4.10
1640@end table
1641
1642
1643
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}:
1649Specifies whether waiting threads should be active or passive.  If
1650the value is @code{PASSIVE}, waiting threads should not consume CPU
1651power while waiting; while the value is @code{ACTIVE} specifies that
1652they should.  If undefined, threads wait actively for a short time
1653before waiting passively.
1654
1655@item @emph{See also}:
1656@ref{GOMP_SPINCOUNT}
1657
1658@item @emph{Reference}:
1659@uref{http://www.openmp.org/, OpenMP specification v4.5}, Section 4.8
1660@end table
1661
1662
1663
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}:
1669Binds threads to specific CPUs.  The variable should contain a space-separated
1670or comma-separated list of CPUs.  This list may contain different kinds of
1671entries: either single CPU numbers in any order, a range of CPUs (M-N)
1672or 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
1674to CPU 0, the second to CPU 3, the third to CPU 1, the fourth to
1675CPU 2, the fifth to CPU 4, the sixth through tenth to CPUs 6, 8, 10, 12,
1676and 14 respectively and then start assigning back from the beginning of
1677the list.  @code{GOMP_CPU_AFFINITY=0} binds all threads to CPU 0.
1678
1679There is no libgomp library routine to determine whether a CPU affinity
1680specification is in effect.  As a workaround, language-specific library
1681functions, e.g., @code{getenv} in C or @code{GET_ENVIRONMENT_VARIABLE} in
1682Fortran, may be used to query the setting of the @code{GOMP_CPU_AFFINITY}
1683environment variable.  A defined CPU affinity on startup cannot be changed
1684or disabled during the runtime of the application.
1685
1686If 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.
1690
1691@item @emph{See also}:
1692@ref{OMP_PLACES}, @ref{OMP_PROC_BIND}
1693@end table
1694
1695
1696
1697@node GOMP_DEBUG
1698@section @env{GOMP_DEBUG} -- Enable debugging output
1699@cindex Environment Variable
1700@table @asis
1701@item @emph{Description}:
1702Enable debugging output.  The variable should be set to @code{0}
1703(disabled, also the default if not set), or @code{1} (enabled).
1704
1705If enabled, some debugging output will be printed during execution.
1706This is currently not specified in more detail, and subject to change.
1707@end table
1708
1709
1710
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}:
1717Set the default thread stack size in kilobytes.  This is different from
1718@code{pthread_attr_setstacksize} which gets the number of bytes as an
1719argument.  If the stack size cannot be set due to system constraints, an
1720error is reported and the initial stack size is left unchanged.  If undefined,
1721the stack size is system dependent.
1722
1723@item @emph{See also}:
1724@ref{OMP_STACKSIZE}
1725
1726@item @emph{Reference}:
1727@uref{http://gcc.gnu.org/ml/gcc-patches/2006-06/msg00493.html,
1728GCC Patches Mailinglist},
1729@uref{http://gcc.gnu.org/ml/gcc-patches/2006-06/msg00496.html,
1730GCC Patches Mailinglist}
1731@end table
1732
1733
1734
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}:
1741Determines how long a threads waits actively with consuming CPU power
1742before waiting passively without consuming CPU power.  The value may be
1743either @code{INFINITE}, @code{INFINITY} to always wait actively or an
1744integer which gives the number of spins of the busy-wait loop.  The
1745integer may optionally be followed by the following suffixes acting
1746as multiplication factors: @code{k} (kilo, thousand), @code{M} (mega,
1747million), @code{G} (giga, billion), or @code{T} (tera, trillion).
1748If undefined, 0 is used when @env{OMP_WAIT_POLICY} is @code{PASSIVE},
1749300,000 is used when @env{OMP_WAIT_POLICY} is undefined and
175030 billion is used when @env{OMP_WAIT_POLICY} is @code{ACTIVE}.
1751If there are more OpenMP threads than available CPUs, 1000 and 100
1752spins are used for @env{OMP_WAIT_POLICY} being @code{ACTIVE} or
1753undefined, respectively; unless the @env{GOMP_SPINCOUNT} is lower
1754or @env{OMP_WAIT_POLICY} is @code{PASSIVE}.
1755
1756@item @emph{See also}:
1757@ref{OMP_WAIT_POLICY}
1758@end table
1759
1760
1761
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}:
1768This environment variable is only used on the RTEMS real-time operating system.
1769It 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
1772separated by @code{:} where:
1773@itemize @bullet
1774@item @code{<thread-pool-count>} is the thread pool count for this scheduler
1775instance.
1776@item @code{$<priority>} is an optional priority for the worker threads of a
1777thread pool according to @code{pthread_setschedparam}.  In case a priority
1778value is omitted, then a worker thread will inherit the priority of the OpenMP
1779master thread that created it.  The priority of the worker thread is not
1780changed after creation, even if a new OpenMP master thread using the worker has
1781a different priority.
1782@item @code{@@<scheduler-name>} is the scheduler instance name according to the
1783RTEMS application configuration.
1784@end itemize
1785In case no thread pool configuration is specified for a scheduler instance,
1786then each OpenMP master thread of this scheduler instance will use its own
1787dynamically allocated thread pool.  To limit the worker thread count of the
1788thread pools, each OpenMP master thread must call @code{omp_set_num_threads}.
1789@item @emph{Example}:
1790Lets 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
1793scheduler instance @code{IO}.  In the scheduler instance @code{WRK0} there is
1794one thread pool available.  Since no priority is specified for this scheduler
1795instance, the worker thread inherits the priority of the OpenMP master thread
1796that created it.  In the scheduler instance @code{WRK1} there are three thread
1797pools available and their worker threads run at priority four.
1798@end table
1799
1800
1801
1802@c ---------------------------------------------------------------------
1803@c Enabling OpenACC
1804@c ---------------------------------------------------------------------
1805
1806@node Enabling OpenACC
1807@chapter Enabling OpenACC
1808
1809To activate the OpenACC extensions for C/C++ and Fortran, the compile-time
1810flag @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
1815arranges for automatic linking of the OpenACC runtime library
1816(@ref{OpenACC Runtime Library Routines}).
1817
1818A complete description of all OpenACC directives accepted may be found in
1819the @uref{https://www.openacc.org, OpenACC} Application Programming
1820Interface manual, version 2.0.
1821
1822Note that this is an experimental feature and subject to
1823change in future versions of GCC.  See
1824@uref{https://gcc.gnu.org/wiki/OpenACC} for more information.
1825
1826
1827
1828@c ---------------------------------------------------------------------
1829@c OpenACC Runtime Library Routines
1830@c ---------------------------------------------------------------------
1831
1832@node OpenACC Runtime Library Routines
1833@chapter OpenACC Runtime Library Routines
1834
1835The runtime routines described here are defined by section 3 of the OpenACC
1836specifications in version 2.0.
1837They have C linkage, and do not throw exceptions.
1838Generally, 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
1840acceleration device.
1841
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.
1891
1892API routines for target platforms.
1893
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
1899
1900
1901
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}
1906This function returns a value indicating the number of devices available
1907for the device type specified in @var{devicetype}.
1908
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
1913
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
1919
1920@item @emph{Reference}:
1921@uref{https://www.openacc.org, OpenACC specification v2.0}, section
19223.2.1.
1923@end table
1924
1925
1926
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}
1931This function indicates to the runtime library which device typr, specified
1932in @var{devicetype}, to use when executing a parallel or kernels region.
1933
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
1938
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
1944
1945@item @emph{Reference}:
1946@uref{https://www.openacc.org, OpenACC specification v2.0}, section
19473.2.2.
1948@end table
1949
1950
1951
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}
1956This function returns what device type will be used when executing a
1957parallel or kernels region.
1958
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
1963
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
1969
1970@item @emph{Reference}:
1971@uref{https://www.openacc.org, OpenACC specification v2.0}, section
19723.2.3.
1973@end table
1974
1975
1976
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}
1981This function will indicate to the runtime which device number,
1982specified by @var{num}, associated with the specifed device
1983type @var{devicetype}.
1984
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
1989
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
1996
1997@item @emph{Reference}:
1998@uref{https://www.openacc.org, OpenACC specification v2.0}, section
19993.2.4.
2000@end table
2001
2002
2003
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}
2008This function returns which device number associated with the specified device
2009type @var{devicetype}, will be used when executing a parallel or kernels
2010region.
2011
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
2016
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
2023
2024@item @emph{Reference}:
2025@uref{https://www.openacc.org, OpenACC specification v2.0}, section
20263.2.5.
2027@end table
2028
2029
2030
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}
2035This function tests for completion of the asynchrounous operation specified
2036in @var{arg}. In C/C++, a non-zero value will be returned to indicate
2037the specified asynchronous operation has completed. While Fortran will return
2038a @code{true}. If the asynchrounous operation has not completed, C/C++ returns
2039a zero and Fortran returns a @code{false}.
2040
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
2045
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
2052
2053@item @emph{Reference}:
2054@uref{https://www.openacc.org, OpenACC specification v2.0}, section
20553.2.6.
2056@end table
2057
2058
2059
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}
2064This function tests for completion of all asynchrounous operations.
2065In C/C++, a non-zero value will be returned to indicate all asynchronous
2066operations have completed. While Fortran will return a @code{true}. If
2067any asynchronous operation has not completed, C/C++ returns a zero and
2068Fortran returns a @code{false}.
2069
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
2074
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
2080
2081@item @emph{Reference}:
2082@uref{https://www.openacc.org, OpenACC specification v2.0}, section
20833.2.7.
2084@end table
2085
2086
2087
2088@node acc_wait
2089@section @code{acc_wait} -- Wait for completion of a specific asynchronous operation.
2090@table @asis
2091@item @emph{Description}
2092This function waits for completion of the asynchronous operation
2093specified in @var{arg}.
2094
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
2100
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
2108
2109@item @emph{Reference}:
2110@uref{https://www.openacc.org, OpenACC specification v2.0}, section
21113.2.8.
2112@end table
2113
2114
2115
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}
2120This function waits for the completion of all asynchronous operations.
2121
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
2127
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
2133
2134@item @emph{Reference}:
2135@uref{https://www.openacc.org, OpenACC specification v2.0}, section
21363.2.10.
2137@end table
2138
2139
2140
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}
2145This function enqueues a wait operation on the queue @var{async} for any
2146and all asynchronous operations that have been previously enqueued on
2147any queue.
2148
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
2153
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
2159
2160@item @emph{Reference}:
2161@uref{https://www.openacc.org, OpenACC specification v2.0}, section
21623.2.11.
2163@end table
2164
2165
2166
2167@node acc_wait_async
2168@section @code{acc_wait_async} -- Wait for completion of asynchronous operations.
2169@table @asis
2170@item @emph{Description}
2171This function enqueues a wait operation on queue @var{async} for any and all
2172asynchronous operations enqueued on queue @var{arg}.
2173
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
2178
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
2184
2185@item @emph{Reference}:
2186@uref{https://www.openacc.org, OpenACC specification v2.0}, section
21873.2.9.
2188@end table
2189
2190
2191
2192@node acc_init
2193@section @code{acc_init} -- Initialize runtime for a specific device type.
2194@table @asis
2195@item @emph{Description}
2196This function initializes the runtime for the device type specified in
2197@var{devicetype}.
2198
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
2203
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
2209
2210@item @emph{Reference}:
2211@uref{https://www.openacc.org, OpenACC specification v2.0}, section
22123.2.12.
2213@end table
2214
2215
2216
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}
2221This function shuts down the runtime for the device type specified in
2222@var{devicetype}.
2223
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
2228
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
2234
2235@item @emph{Reference}:
2236@uref{https://www.openacc.org, OpenACC specification v2.0}, section
22373.2.13.
2238@end table
2239
2240
2241
2242@node acc_on_device
2243@section @code{acc_on_device} -- Whether executing on a particular device
2244@table @asis
2245@item @emph{Description}:
2246This function returns whether the program is executing on a particular
2247device specified in @var{devicetype}. In C/C++ a non-zero value is
2248returned to indicate the device is execiting on the specified device type.
2249In Fortran, @code{true} will be returned. If the program is not executing
2250on the specified device type C/C++ will return a zero, while Fortran will
2251return @code{false}.
2252
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
2257
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
2264
2265
2266@item @emph{Reference}:
2267@uref{https://www.openacc.org, OpenACC specification v2.0}, section
22683.2.14.
2269@end table
2270
2271
2272
2273@node acc_malloc
2274@section @code{acc_malloc} -- Allocate device memory.
2275@table @asis
2276@item @emph{Description}
2277This function allocates @var{len} bytes of device memory. It returns
2278the device address of the allocated memory.
2279
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
2284
2285@item @emph{Reference}:
2286@uref{https://www.openacc.org, OpenACC specification v2.0}, section
22873.2.15.
2288@end table
2289
2290
2291
2292@node acc_free
2293@section @code{acc_free} -- Free device memory.
2294@table @asis
2295@item @emph{Description}
2296Free previously allocated device memory at the device address @code{a}.
2297
2298@item @emph{C/C++}:
2299@multitable @columnfractions .20 .80
2300@item @emph{Prototype}: @tab @code{acc_free(d_void *a);}
2301@end multitable
2302
2303@item @emph{Reference}:
2304@uref{https://www.openacc.org, OpenACC specification v2.0}, section
23053.2.16.
2306@end table
2307
2308
2309
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}
2314In C/C++, this function allocates @var{len} bytes of device memory
2315and maps it to the specified host address in @var{a}. The device
2316address of the newly allocated device memory is returned.
2317
2318In Fortran, two (2) forms are supported. In the first form, @var{a} specifies
2319a contiguous array section. The second form @var{a} specifies a
2320variable or array element and @var{len} specifies the length in bytes.
2321
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
2326
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
2335
2336@item @emph{Reference}:
2337@uref{https://www.openacc.org, OpenACC specification v2.0}, section
23383.2.17.
2339@end table
2340
2341
2342
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}
2347This 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
2349will be allocated and the host memory copied. The device address of
2350the newly allocated device memory is returned.
2351
2352In Fortran, two (2) forms are supported. In the first form, @var{a} specifies
2353a contiguous array section. The second form @var{a} specifies a variable or
2354array element and @var{len} specifies the length in bytes.
2355
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
2361
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
2375
2376@item @emph{Reference}:
2377@uref{https://www.openacc.org, OpenACC specification v2.0}, section
23783.2.18.
2379@end table
2380
2381
2382
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}
2387This function allocates device memory and maps it to host memory specified
2388by the host address @var{a} with a length of @var{len} bytes. In C/C++,
2389the function returns the device address of the allocated device memory.
2390
2391In Fortran, two (2) forms are supported. In the first form, @var{a} specifies
2392a contiguous array section. The second form @var{a} specifies a variable or
2393array element and @var{len} specifies the length in bytes.
2394
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
2399
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
2408
2409@item @emph{Reference}:
2410@uref{https://www.openacc.org, OpenACC specification v2.0}, section
24113.2.19.
2412@end table
2413
2414
2415
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}
2420This 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
2422will be allocated and mapped to host memory. In C/C++, the device address
2423of the newly allocated device memory is returned.
2424
2425In Fortran, two (2) forms are supported. In the first form, @var{a} specifies
2426a contiguous array section. The second form @var{a} specifies a variable or
2427array element and @var{len} specifies the length in bytes.
2428
2429
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
2435
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
2449
2450@item @emph{Reference}:
2451@uref{https://www.openacc.org, OpenACC specification v2.0}, section
24523.2.20.
2453@end table
2454
2455
2456
2457@node acc_copyout
2458@section @code{acc_copyout} -- Copy device memory to host memory.
2459@table @asis
2460@item @emph{Description}
2461This function copies mapped device memory to host memory which is specified
2462by host address @var{a} for a length @var{len} bytes in C/C++.
2463
2464In Fortran, two (2) forms are supported. In the first form, @var{a} specifies
2465a contiguous array section. The second form @var{a} specifies a variable or
2466array element and @var{len} specifies the length in bytes.
2467
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
2472
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
2481
2482@item @emph{Reference}:
2483@uref{https://www.openacc.org, OpenACC specification v2.0}, section
24843.2.21.
2485@end table
2486
2487
2488
2489@node acc_delete
2490@section @code{acc_delete} -- Free device memory.
2491@table @asis
2492@item @emph{Description}
2493This function frees previously allocated device memory specified by
2494the device address @var{a} and the length of @var{len} bytes.
2495
2496In Fortran, two (2) forms are supported. In the first form, @var{a} specifies
2497a contiguous array section. The second form @var{a} specifies a variable or
2498array element and @var{len} specifies the length in bytes.
2499
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
2504
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
2513
2514@item @emph{Reference}:
2515@uref{https://www.openacc.org, OpenACC specification v2.0}, section
25163.2.22.
2517@end table
2518
2519
2520
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}
2525This function updates the device copy from the previously mapped host memory.
2526The host memory is specified with the host address @var{a} and a length of
2527@var{len} bytes.
2528
2529In Fortran, two (2) forms are supported. In the first form, @var{a} specifies
2530a contiguous array section. The second form @var{a} specifies a variable or
2531array element and @var{len} specifies the length in bytes.
2532
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
2537
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
2546
2547@item @emph{Reference}:
2548@uref{https://www.openacc.org, OpenACC specification v2.0}, section
25493.2.23.
2550@end table
2551
2552
2553
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}
2558This function updates the host copy from the previously mapped device memory.
2559The host memory is specified with the host address @var{a} and a length of
2560@var{len} bytes.
2561
2562In Fortran, two (2) forms are supported. In the first form, @var{a} specifies
2563a contiguous array section. The second form @var{a} specifies a variable or
2564array element and @var{len} specifies the length in bytes.
2565
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
2570
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
2579
2580@item @emph{Reference}:
2581@uref{https://www.openacc.org, OpenACC specification v2.0}, section
25823.2.24.
2583@end table
2584
2585
2586
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}
2591This function maps previously allocated device and host memory. The device
2592memory is specified with the device address @var{d}. The host memory is
2593specified with the host address @var{h} and a length of @var{len}.
2594
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
2599
2600@item @emph{Reference}:
2601@uref{https://www.openacc.org, OpenACC specification v2.0}, section
26023.2.25.
2603@end table
2604
2605
2606
2607@node acc_unmap_data
2608@section @code{acc_unmap_data} -- Unmap device memory from host memory.
2609@table @asis
2610@item @emph{Description}
2611This function unmaps previously mapped device and host memory. The latter
2612specified by @var{h}.
2613
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
2618
2619@item @emph{Reference}:
2620@uref{https://www.openacc.org, OpenACC specification v2.0}, section
26213.2.26.
2622@end table
2623
2624
2625
2626@node acc_deviceptr
2627@section @code{acc_deviceptr} -- Get device pointer associated with specific host address.
2628@table @asis
2629@item @emph{Description}
2630This function returns the device address that has been mapped to the
2631host address specified by @var{h}.
2632
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
2637
2638@item @emph{Reference}:
2639@uref{https://www.openacc.org, OpenACC specification v2.0}, section
26403.2.27.
2641@end table
2642
2643
2644
2645@node acc_hostptr
2646@section @code{acc_hostptr} -- Get host pointer associated with specific device address.
2647@table @asis
2648@item @emph{Description}
2649This function returns the host address that has been mapped to the
2650device address specified by @var{d}.
2651
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
2656
2657@item @emph{Reference}:
2658@uref{https://www.openacc.org, OpenACC specification v2.0}, section
26593.2.28.
2660@end table
2661
2662
2663
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}
2668This function indicates whether the specified host address in @var{a} and a
2669length of @var{len} bytes is present on the device. In C/C++, a non-zero
2670value is returned to indicate the presence of the mapped memory on the
2671device. A zero is returned to indicate the memory is not mapped on the
2672device.
2673
2674In Fortran, two (2) forms are supported. In the first form, @var{a} specifies
2675a contiguous array section. The second form @var{a} specifies a variable or
2676array element and @var{len} specifies the length in bytes. If the host
2677memory is mapped to device memory, then a @code{true} is returned. Otherwise,
2678a @code{false} is return to indicate the mapped memory is not present.
2679
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
2684
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
2695
2696@item @emph{Reference}:
2697@uref{https://www.openacc.org, OpenACC specification v2.0}, section
26983.2.29.
2699@end table
2700
2701
2702
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}
2707This function copies host memory specified by host address of @var{src} to
2708device memory specified by the device address @var{dest} for a length of
2709@var{bytes} bytes.
2710
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
2715
2716@item @emph{Reference}:
2717@uref{https://www.openacc.org, OpenACC specification v2.0}, section
27183.2.30.
2719@end table
2720
2721
2722
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}
2727This function copies host memory specified by host address of @var{src} from
2728device memory specified by the device address @var{dest} for a length of
2729@var{bytes} bytes.
2730
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
2735
2736@item @emph{Reference}:
2737@uref{https://www.openacc.org, OpenACC specification v2.0}, section
27383.2.31.
2739@end table
2740
2741
2742
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}
2747This function returns the CUDA device handle. This handle is the same
2748as used by the CUDA Runtime or Driver API's.
2749
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
2754
2755@item @emph{Reference}:
2756@uref{https://www.openacc.org, OpenACC specification v2.0}, section
2757A.2.1.1.
2758@end table
2759
2760
2761
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}
2766This function returns the CUDA context handle. This handle is the same
2767as used by the CUDA Runtime or Driver API's.
2768
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
2773
2774@item @emph{Reference}:
2775@uref{https://www.openacc.org, OpenACC specification v2.0}, section
2776A.2.1.2.
2777@end table
2778
2779
2780
2781@node acc_get_cuda_stream
2782@section @code{acc_get_cuda_stream} -- Get CUDA stream handle.
2783@table @asis
2784@item @emph{Description}
2785This function returns the CUDA stream handle. This handle is the same
2786as used by the CUDA Runtime or Driver API's.
2787
2788@item @emph{C/C++}:
2789@multitable @columnfractions .20 .80
2790@item @emph{Prototype}: @tab @code{acc_get_cuda_stream(void);}
2791@end multitable
2792
2793@item @emph{Reference}:
2794@uref{https://www.openacc.org, OpenACC specification v2.0}, section
2795A.2.1.3.
2796@end table
2797
2798
2799
2800@node acc_set_cuda_stream
2801@section @code{acc_set_cuda_stream} -- Set CUDA stream handle.
2802@table @asis
2803@item @emph{Description}
2804This function associates the stream handle specified by @var{stream} with
2805the asynchronous value specified by @var{async}.
2806
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
2811
2812@item @emph{Reference}:
2813@uref{https://www.openacc.org, OpenACC specification v2.0}, section
2814A.2.1.4.
2815@end table
2816
2817
2818
2819@c ---------------------------------------------------------------------
2820@c OpenACC Environment Variables
2821@c ---------------------------------------------------------------------
2822
2823@node OpenACC Environment Variables
2824@chapter OpenACC Environment Variables
2825
2826The variables @env{ACC_DEVICE_TYPE} and @env{ACC_DEVICE_NUM}
2827are defined by section 4 of the OpenACC specification in version 2.0.
2828The variable @env{GCC_ACC_NOTIFY} is used for diagnostic purposes.
2829
2830@menu
2831* ACC_DEVICE_TYPE::
2832* ACC_DEVICE_NUM::
2833* GCC_ACC_NOTIFY::
2834@end menu
2835
2836
2837
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
28434.1.
2844@end table
2845
2846
2847
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
28534.2.
2854@end table
2855
2856
2857
2858@node GCC_ACC_NOTIFY
2859@section @code{GCC_ACC_NOTIFY}
2860@table @asis
2861@item @emph{Description}:
2862Print debug information pertaining to the accelerator.
2863@end table
2864
2865
2866
2867@c ---------------------------------------------------------------------
2868@c CUDA Streams Usage
2869@c ---------------------------------------------------------------------
2870
2871@node CUDA Streams Usage
2872@chapter CUDA Streams Usage
2873
2874This applies to the @code{nvptx} plugin only.
2875
2876The library provides elements that perform asynchronous movement of
2877data and asynchronous operation of computing constructs.  This
2878asynchronous functionality is implemented by making use of CUDA
2879streams@footnote{See "Stream Management" in "CUDA Driver API",
2880TRM-06703-001, Version 5.5, for additional information}.
2881
2882The primary means by that the asychronous functionality is accessed
2883is 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
2885first used with a directive, it creates a CUDA stream.  If an
2886@code{async-argument} is used with the @code{async} clause, then the
2887stream is associated with the specified @code{async-argument}.
2888
2889Following the creation of an association between a CUDA stream and the
2890@code{async-argument} of an @code{async} clause, both the @code{wait}
2891clause and the @code{wait} directive can be used.  When either the
2892clause or directive is used after stream creation, it creates a
2893rendezvous point whereby execution waits until all operations
2894associated with the @code{async-argument}, that is, stream, have
2895completed.
2896
2897Normally, the management of the streams that are created as a result of
2898using the @code{async} clause, is done without any intervention by the
2899caller.  This implies the association between the @code{async-argument}
2900and the CUDA stream will be maintained for the lifetime of the program.
2901However, this association can be changed through the use of the library
2902function @code{acc_set_cuda_stream}.  When the function
2903@code{acc_set_cuda_stream} is called, the CUDA stream that was
2904originally associated with the @code{async} clause will be destroyed.
2905Caution should be taken when changing the association as subsequent
2906references to the @code{async-argument} refer to a different
2907CUDA stream.
2908
2909
2910
2911@c ---------------------------------------------------------------------
2912@c OpenACC Library Interoperability
2913@c ---------------------------------------------------------------------
2914
2915@node OpenACC Library Interoperability
2916@chapter OpenACC Library Interoperability
2917
2918@section Introduction
2919
2920The OpenACC library uses the CUDA Driver API, and may interact with
2921programs that use the Runtime library directly, or another library
2922based 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
2925Interoperability", in "CUDA Driver API", TRM-06703-001, Version 5.5,
2926for additional information on library interoperability.}.
2927This chapter describes the use cases and what changes are
2928required in order to use both the OpenACC library and the CUBLAS and Runtime
2929libraries within a program.
2930
2931@section First invocation: NVIDIA CUBLAS library API
2932
2933In this first use case (see below), a function in the CUBLAS library is called
2934prior to any of the functions in the OpenACC library. More specifically, the
2935function @code{cublasCreate()}.
2936
2937When invoked, the function initializes the library and allocates the
2938hardware resources on the host and the device on behalf of the caller. Once
2939the initialization and allocation has completed, a handle is returned to the
2940caller. The OpenACC library also requires initialization and allocation of
2941hardware resources. Since the CUBLAS library has already allocated the
2942hardware resources for the device, all that is left to do is to initialize
2943the OpenACC library and acquire the hardware resources on the host.
2944
2945Prior to calling the OpenACC function that initializes the library and
2946allocate the host hardware resources, you need to acquire the device number
2947that was allocated during the call to @code{cublasCreate()}. The invoking of the
2948runtime library function @code{cudaGetDevice()} accomplishes this. Once
2949acquired, the device number is passed along with the device type as
2950parameters to the OpenACC library function @code{acc_set_device_num()}.
2951
2952Once the call to @code{acc_set_device_num()} has completed, the OpenACC
2953library uses the  context that was created during the call to
2954@code{cublasCreate()}. In other words, both libraries will be sharing the
2955same context.
2956
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    @}
2965
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    @}
2973
2974    /* Initialize OpenACC library and use device 'dev' */
2975    acc_set_device_num(dev, acc_device_nvidia);
2976
2977@end smallexample
2978@center Use Case 1
2979
2980@section First invocation: OpenACC library API
2981
2982In this second use case (see below), a function in the OpenACC library is
2983called prior to any of the functions in the CUBLAS library. More specificially,
2984the function @code{acc_set_device_num()}.
2985
2986In the use case presented here, the function @code{acc_set_device_num()}
2987is used to both initialize the OpenACC library and allocate the hardware
2988resources on the host and the device. In the call to the function, the
2989call parameters specify which device to use and what device
2990type to use, i.e., @code{acc_device_nvidia}. It should be noted that this
2991is but one method to initialize the OpenACC library and allocate the
2992appropriate hardware resources. Other methods are available through the
2993use of environment variables and these will be discussed in the next section.
2994
2995Once the call to @code{acc_set_device_num()} has completed, other OpenACC
2996functions 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
2998CUBLAS library. In the use case a call to @code{cublasCreate()} is made
2999subsequent to the calls to @code{acc_copyin()}.
3000As seen in the previous use case, a call to @code{cublasCreate()}
3001initializes the CUBLAS library and allocates the hardware resources on the
3002host and the device.  However, since the device has already been allocated,
3003@code{cublasCreate()} will only initialize the CUBLAS library and allocate
3004the appropriate hardware resources on the host. The context that was created
3005as part of the OpenACC initialization is shared with the CUBLAS library,
3006similarly to the first use case.
3007
3008@smallexample
3009    dev = 0;
3010
3011    acc_set_device_num(dev, acc_device_nvidia);
3012
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    @}
3020
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    @}
3028
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    @}
3036
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    @}
3044
3045    /* Copy the results from the device */
3046    acc_memcpy_from_device(&h_Y1[0], d_Y, N * sizeof (float));
3047
3048@end smallexample
3049@center Use Case 2
3050
3051@section OpenACC library and environment variables
3052
3053There are two environment variables associated with the OpenACC library
3054that may be used to control the device type and device number:
3055@env{ACC_DEVICE_TYPE} and @env{ACC_DEVICE_NUM}, respecively. These two
3056environement variables can be used as an alternative to calling
3057@code{acc_set_device_num()}. As seen in the second use case, the device
3058type and device number were specified using @code{acc_set_device_num()}.
3059If however, the aforementioned environment variables were set, then the
3060call to @code{acc_set_device_num()} would not be required.
3061
3062
3063The use of the environment variables is only relevant when an OpenACC function
3064is called prior to a call to @code{cudaCreate()}. If @code{cudaCreate()}
3065is called prior to a call to an OpenACC function, then you must call
3066@code{acc_set_device_num()}@footnote{More complete information
3067about @env{ACC_DEVICE_TYPE} and @env{ACC_DEVICE_NUM} can be found in
3068sections 4.1 and 4.2 of the @uref{https://www.openacc.org, OpenACC}
3069Application Programming Interface”, Version 2.0.}
3070
3071
3072
3073@c ---------------------------------------------------------------------
3074@c The libgomp ABI
3075@c ---------------------------------------------------------------------
3076
3077@node The libgomp ABI
3078@chapter The libgomp ABI
3079
3080The following sections present notes on the external ABI as
3081presented by libgomp.  Only maintainers should need them.
3082
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
3100
3101
3102@node Implementing MASTER construct
3103@section Implementing MASTER construct
3104
3105@smallexample
3106if (omp_get_thread_num () == 0)
3107  block
3108@end smallexample
3109
3110Alternately, we generate two copies of the parallel subfunction
3111and only include this in the version run by the master thread.
3112Surely this is not worthwhile though...
3113
3114
3115
3116@node Implementing CRITICAL construct
3117@section Implementing CRITICAL construct
3118
3119Without a specified name,
3120
3121@smallexample
3122  void GOMP_critical_start (void);
3123  void GOMP_critical_end (void);
3124@end smallexample
3125
3126so that we don't get COPY relocations from libgomp to the main
3127application.
3128
3129With a specified name, use omp_set_lock and omp_unset_lock with
3130name being transformed into a variable declared like
3131
3132@smallexample
3133  omp_lock_t gomp_critical_user_<name> __attribute__((common))
3134@end smallexample
3135
3136Ideally the ABI would specify that all zero is a valid unlocked
3137state, and so we wouldn't need to initialize this at
3138startup.
3139
3140
3141
3142@node Implementing ATOMIC construct
3143@section Implementing ATOMIC construct
3144
3145The target should implement the @code{__sync} builtins.
3146
3147Failing that we could add
3148
3149@smallexample
3150  void GOMP_atomic_enter (void)
3151  void GOMP_atomic_exit (void)
3152@end smallexample
3153
3154which reuses the regular lock code, but with yet another lock
3155object private to the library.
3156
3157
3158
3159@node Implementing FLUSH construct
3160@section Implementing FLUSH construct
3161
3162Expands to the @code{__sync_synchronize} builtin.
3163
3164
3165
3166@node Implementing BARRIER construct
3167@section Implementing BARRIER construct
3168
3169@smallexample
3170  void GOMP_barrier (void)
3171@end smallexample
3172
3173
3174@node Implementing THREADPRIVATE construct
3175@section Implementing THREADPRIVATE construct
3176
3177In _most_ cases we can map this directly to @code{__thread}.  Except
3178that OMP allows constructors for C++ objects.  We can either
3179refuse to support this (how often is it used?) or we can
3180implement something akin to .ctors.
3181
3182Even more ideally, this ctor feature is handled by extensions
3183to the main pthreads library.  Failing that, we can have a set
3184of entry points to register ctor functions to be called.
3185
3186
3187
3188@node Implementing PRIVATE clause
3189@section Implementing PRIVATE clause
3190
3191In association with a PARALLEL, or within the lexical extent
3192of a PARALLEL block, the variable becomes a local variable in
3193the parallel subfunction.
3194
3195In association with FOR or SECTIONS blocks, create a new
3196automatic variable within the current function.  This preserves
3197the semantic of new variable creation.
3198
3199
3200
3201@node Implementing FIRSTPRIVATE LASTPRIVATE COPYIN and COPYPRIVATE clauses
3202@section Implementing FIRSTPRIVATE LASTPRIVATE COPYIN and COPYPRIVATE clauses
3203
3204This seems simple enough for PARALLEL blocks.  Create a private
3205struct for communicating between the parent and subfunction.
3206In the parent, copy in values for scalar and "small" structs;
3207copy in addresses for others TREE_ADDRESSABLE types.  In the
3208subfunction, copy the value into the local variable.
3209
3210It is not clear what to do with bare FOR or SECTION blocks.
3211The only thing I can figure is that we do something like:
3212
3213@smallexample
3214#pragma omp for firstprivate(x) lastprivate(y)
3215for (int i = 0; i < n; ++i)
3216  body;
3217@end smallexample
3218
3219which becomes
3220
3221@smallexample
3222@{
3223  int x = x, y;
3224
3225  // for stuff
3226
3227  if (i == n)
3228    y = y;
3229@}
3230@end smallexample
3231
3232where the "x=x" and "y=y" assignments actually have different
3233uids for the two variables, i.e. not something you could write
3234directly in C.  Presumably this only makes sense if the "outer"
3235x and y are global variables.
3236
3237COPYPRIVATE would work the same way, except the structure
3238broadcast would have to happen via SINGLE machinery instead.
3239
3240
3241
3242@node Implementing REDUCTION clause
3243@section Implementing REDUCTION clause
3244
3245The private struct mentioned in the previous section should have
3246a pointer to an array of the type of the variable, indexed by the
3247thread's @var{team_id}.  The thread stores its final value into the
3248array, and after the barrier, the master thread iterates over the
3249array to collect the values.
3250
3251
3252@node Implementing PARALLEL construct
3253@section Implementing PARALLEL construct
3254
3255@smallexample
3256  #pragma omp parallel
3257  @{
3258    body;
3259  @}
3260@end smallexample
3261
3262becomes
3263
3264@smallexample
3265  void subfunction (void *data)
3266  @{
3267    use data;
3268    body;
3269  @}
3270
3271  setup data;
3272  GOMP_parallel_start (subfunction, &data, num_threads);
3273  subfunction (&data);
3274  GOMP_parallel_end ();
3275@end smallexample
3276
3277@smallexample
3278  void GOMP_parallel_start (void (*fn)(void *), void *data, unsigned num_threads)
3279@end smallexample
3280
3281The @var{FN} argument is the subfunction to be run in parallel.
3282
3283The @var{DATA} argument is a pointer to a structure used to
3284communicate data in and out of the subfunction, as discussed
3285above with respect to FIRSTPRIVATE et al.
3286
3287The @var{NUM_THREADS} argument is 1 if an IF clause is present
3288and false, or the value of the NUM_THREADS clause, if
3289present, or 0.
3290
3291The function needs to create the appropriate number of
3292threads and/or launch them from the dock.  It needs to
3293create the team structure and assign team ids.
3294
3295@smallexample
3296  void GOMP_parallel_end (void)
3297@end smallexample
3298
3299Tears down the team and returns us to the previous @code{omp_in_parallel()} state.
3300
3301
3302
3303@node Implementing FOR construct
3304@section Implementing FOR construct
3305
3306@smallexample
3307  #pragma omp parallel for
3308  for (i = lb; i <= ub; i++)
3309    body;
3310@end smallexample
3311
3312becomes
3313
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  @}
3326
3327  GOMP_parallel_loop_static (subfunction, NULL, 0, lb, ub+1, 1, 0);
3328  subfunction (NULL);
3329  GOMP_parallel_end ();
3330@end smallexample
3331
3332@smallexample
3333  #pragma omp for schedule(runtime)
3334  for (i = 0; i < n; i++)
3335    body;
3336@end smallexample
3337
3338becomes
3339
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
3352
3353Note that while it looks like there is trickiness to propagating
3354a non-constant STEP, there isn't really.  We're explicitly allowed
3355to evaluate it as many times as we want, and any variables involved
3356should automatically be handled as PRIVATE or SHARED like any other
3357variables.  So the expression should remain evaluable in the
3358subfunction.  We can also pull it into a local variable if we like,
3359but since its supposed to remain unchanged, we can also not if we like.
3360
3361If we have SCHEDULE(STATIC), and no ORDERED, then we ought to be
3362able to get away with no work-sharing context at all, since we can
3363simply perform the arithmetic directly in each thread to divide up
3364the iterations.  Which would mean that we wouldn't need to call any
3365of these routines.
3366
3367There are separate routines for handling loops with an ORDERED
3368clause.  Bookkeeping for that is non-trivial...
3369
3370
3371
3372@node Implementing ORDERED construct
3373@section Implementing ORDERED construct
3374
3375@smallexample
3376  void GOMP_ordered_start (void)
3377  void GOMP_ordered_end (void)
3378@end smallexample
3379
3380
3381
3382@node Implementing SECTIONS construct
3383@section Implementing SECTIONS construct
3384
3385A block as
3386
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
3398
3399becomes
3400
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
3417
3418
3419@node Implementing SINGLE construct
3420@section Implementing SINGLE construct
3421
3422A block like
3423
3424@smallexample
3425  #pragma omp single
3426  @{
3427    body;
3428  @}
3429@end smallexample
3430
3431becomes
3432
3433@smallexample
3434  if (GOMP_single_start ())
3435    body;
3436  GOMP_barrier ();
3437@end smallexample
3438
3439while
3440
3441@smallexample
3442  #pragma omp single copyprivate(x)
3443    body;
3444@end smallexample
3445
3446becomes
3447
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
3460
3461
3462
3463@node Implementing OpenACC's PARALLEL construct
3464@section Implementing OpenACC's PARALLEL construct
3465
3466@smallexample
3467  void GOACC_parallel ()
3468@end smallexample
3469
3470
3471
3472@c ---------------------------------------------------------------------
3473@c Reporting Bugs
3474@c ---------------------------------------------------------------------
3475
3476@node Reporting Bugs
3477@chapter Reporting Bugs
3478
3479Bugs in the GNU Offloading and Multi Processing Runtime Library should
3480be reported via @uref{http://gcc.gnu.org/bugzilla/, Bugzilla}.  Please add
3481"openacc", or "openmp", or both to the keywords field in the bug
3482report, as appropriate.
3483
3484
3485
3486@c ---------------------------------------------------------------------
3487@c GNU General Public License
3488@c ---------------------------------------------------------------------
3489
3490@include gpl_v3.texi
3491
3492
3493
3494@c ---------------------------------------------------------------------
3495@c GNU Free Documentation License
3496@c ---------------------------------------------------------------------
3497
3498@include fdl.texi
3499
3500
3501
3502@c ---------------------------------------------------------------------
3503@c Funding Free Software
3504@c ---------------------------------------------------------------------
3505
3506@include funding.texi
3507
3508@c ---------------------------------------------------------------------
3509@c Index
3510@c ---------------------------------------------------------------------
3511
3512@node Library Index
3513@unnumbered Library Index
3514
3515@printindex cp
3516
3517@bye
3518