[PR67828] don't unswitch on default defs of non-parms
[official-gcc.git] / libgomp / libgomp.texi
blob06b1c67fc02787bf76df8e0f8e9a08b59d21e610
1 \input texinfo @c -*-texinfo-*-
3 @c %**start of header
4 @setfilename libgomp.info
5 @settitle GNU libgomp
6 @c %**end of header
9 @copying
10 Copyright @copyright{} 2006-2015 Free Software Foundation, Inc.
12 Permission is granted to copy, distribute and/or modify this document
13 under the terms of the GNU Free Documentation License, Version 1.3 or
14 any later version published by the Free Software Foundation; with the
15 Invariant Sections being ``Funding Free Software'', the Front-Cover
16 texts being (a) (see below), and with the Back-Cover Texts being (b)
17 (see below).  A copy of the license is included in the section entitled
18 ``GNU Free Documentation License''.
20 (a) The FSF's Front-Cover Text is:
22      A GNU Manual
24 (b) The FSF's Back-Cover Text is:
26      You have freedom to copy and modify this GNU Manual, like GNU
27      software.  Copies published by the Free Software Foundation raise
28      funds for GNU development.
29 @end copying
31 @ifinfo
32 @dircategory GNU Libraries
33 @direntry
34 * libgomp: (libgomp).          GNU Offloading and Multi Processing Runtime Library.
35 @end direntry
37 This manual documents libgomp, the GNU Offloading and Multi Processing
38 Runtime library.  This is the GNU implementation of the OpenMP and
39 OpenACC APIs for parallel and accelerator programming in C/C++ and
40 Fortran.
42 Published by the Free Software Foundation
43 51 Franklin Street, Fifth Floor
44 Boston, MA 02110-1301 USA
46 @insertcopying
47 @end ifinfo
50 @setchapternewpage odd
52 @titlepage
53 @title GNU Offloading and Multi Processing Runtime Library
54 @subtitle The GNU OpenMP and OpenACC Implementation
55 @page
56 @vskip 0pt plus 1filll
57 @comment For the @value{version-GCC} Version*
58 @sp 1
59 Published by the Free Software Foundation @*
60 51 Franklin Street, Fifth Floor@*
61 Boston, MA 02110-1301, USA@*
62 @sp 1
63 @insertcopying
64 @end titlepage
66 @summarycontents
67 @contents
68 @page
71 @node Top
72 @top Introduction
73 @cindex Introduction
75 This manual documents the usage of libgomp, the GNU Offloading and
76 Multi Processing Runtime Library.  This includes the GNU
77 implementation of the @uref{http://www.openmp.org, OpenMP} Application
78 Programming Interface (API) for multi-platform shared-memory parallel
79 programming in C/C++ and Fortran, and the GNU implementation of the
80 @uref{http://www.openacc.org/, OpenACC} Application Programming
81 Interface (API) for offloading of code to accelerator devices in C/C++
82 and Fortran.
84 Originally, libgomp implemented the GNU OpenMP Runtime Library.  Based
85 on this, support for OpenACC and offloading (both OpenACC and OpenMP
86 4's target construct) has been added later on, and the library's name
87 changed to GNU Offloading and Multi Processing Runtime Library.
91 @comment
92 @comment  When you add a new menu item, please keep the right hand
93 @comment  aligned to the same column.  Do not use tabs.  This provides
94 @comment  better formatting.
95 @comment
96 @menu
97 * Enabling OpenMP::            How to enable OpenMP for your applications.
98 * Runtime Library Routines::   The OpenMP runtime application programming 
99                                interface.
100 * Environment Variables::      Influencing runtime behavior with environment 
101                                variables.
102 * The libgomp ABI::            Notes on the external ABI presented by libgomp.
103 * Reporting Bugs::             How to report bugs in the GNU Offloading and
104                                Multi Processing Runtime Library.
105 * Copying::                    GNU general public license says
106                                how you can copy and share libgomp.
107 * GNU Free Documentation License::
108                                How you can copy and share this manual.
109 * Funding::                    How to help assure continued work for free 
110                                software.
111 * Library Index::              Index of this documentation.
112 @end menu
115 @c ---------------------------------------------------------------------
116 @c Enabling OpenMP
117 @c ---------------------------------------------------------------------
119 @node Enabling OpenMP
120 @chapter Enabling OpenMP
122 To activate the OpenMP extensions for C/C++ and Fortran, the compile-time 
123 flag @command{-fopenmp} must be specified.  This enables the OpenMP directive
124 @code{#pragma omp} in C/C++ and @code{!$omp} directives in free form, 
125 @code{c$omp}, @code{*$omp} and @code{!$omp} directives in fixed form, 
126 @code{!$} conditional compilation sentinels in free form and @code{c$},
127 @code{*$} and @code{!$} sentinels in fixed form, for Fortran.  The flag also
128 arranges for automatic linking of the OpenMP runtime library 
129 (@ref{Runtime Library Routines}).
131 A complete description of all OpenMP directives accepted may be found in 
132 the @uref{http://www.openmp.org, OpenMP Application Program Interface} manual,
133 version 4.0.
136 @c ---------------------------------------------------------------------
137 @c Runtime Library Routines
138 @c ---------------------------------------------------------------------
140 @node Runtime Library Routines
141 @chapter Runtime Library Routines
143 The runtime routines described here are defined by Section 3 of the OpenMP
144 specification in version 4.0.  The routines are structured in following
145 three parts:
147 @menu
148 Control threads, processors and the parallel environment.  They have C
149 linkage, and do not throw exceptions.
151 * omp_get_active_level::        Number of active parallel regions
152 * omp_get_ancestor_thread_num:: Ancestor thread ID
153 * omp_get_cancellation::        Whether cancellation support is enabled
154 * omp_get_default_device::      Get the default device for target regions
155 * omp_get_dynamic::             Dynamic teams setting
156 * omp_get_level::               Number of parallel regions
157 * omp_get_max_active_levels::   Maximum number of active regions
158 * omp_get_max_threads::         Maximum number of threads of parallel region
159 * omp_get_nested::              Nested parallel regions
160 * omp_get_num_devices::         Number of target devices
161 * omp_get_num_procs::           Number of processors online
162 * omp_get_num_teams::           Number of teams
163 * omp_get_num_threads::         Size of the active team
164 * omp_get_proc_bind::           Whether theads may be moved between CPUs
165 * omp_get_schedule::            Obtain the runtime scheduling method
166 * omp_get_team_num::            Get team number
167 * omp_get_team_size::           Number of threads in a team
168 * omp_get_thread_limit::        Maximum number of threads
169 * omp_get_thread_num::          Current thread ID
170 * omp_in_parallel::             Whether a parallel region is active
171 * omp_in_final::                Whether in final or included task region
172 * omp_is_initial_device::       Whether executing on the host device
173 * omp_set_default_device::      Set the default device for target regions
174 * omp_set_dynamic::             Enable/disable dynamic teams
175 * omp_set_max_active_levels::   Limits the number of active parallel regions
176 * omp_set_nested::              Enable/disable nested parallel regions
177 * omp_set_num_threads::         Set upper team size limit
178 * omp_set_schedule::            Set the runtime scheduling method
180 Initialize, set, test, unset and destroy simple and nested locks.
182 * omp_init_lock::            Initialize simple lock
183 * omp_set_lock::             Wait for and set simple lock
184 * omp_test_lock::            Test and set simple lock if available
185 * omp_unset_lock::           Unset simple lock
186 * omp_destroy_lock::         Destroy simple lock
187 * omp_init_nest_lock::       Initialize nested lock
188 * omp_set_nest_lock::        Wait for and set simple lock
189 * omp_test_nest_lock::       Test and set nested lock if available
190 * omp_unset_nest_lock::      Unset nested lock
191 * omp_destroy_nest_lock::    Destroy nested lock
193 Portable, thread-based, wall clock timer.
195 * omp_get_wtick::            Get timer precision.
196 * omp_get_wtime::            Elapsed wall clock time.
197 @end menu
201 @node omp_get_active_level
202 @section @code{omp_get_active_level} -- Number of parallel regions
203 @table @asis
204 @item @emph{Description}:
205 This function returns the nesting level for the active parallel blocks,
206 which enclose the calling call.
208 @item @emph{C/C++}
209 @multitable @columnfractions .20 .80
210 @item @emph{Prototype}: @tab @code{int omp_get_active_level(void);}
211 @end multitable
213 @item @emph{Fortran}:
214 @multitable @columnfractions .20 .80
215 @item @emph{Interface}: @tab @code{integer function omp_get_active_level()}
216 @end multitable
218 @item @emph{See also}:
219 @ref{omp_get_level}, @ref{omp_get_max_active_levels}, @ref{omp_set_max_active_levels}
221 @item @emph{Reference}:
222 @uref{http://www.openmp.org/, OpenMP specification v4.0}, Section 3.2.20.
223 @end table
227 @node omp_get_ancestor_thread_num
228 @section @code{omp_get_ancestor_thread_num} -- Ancestor thread ID
229 @table @asis
230 @item @emph{Description}:
231 This function returns the thread identification number for the given
232 nesting level of the current thread.  For values of @var{level} outside
233 zero to @code{omp_get_level} -1 is returned; if @var{level} is
234 @code{omp_get_level} the result is identical to @code{omp_get_thread_num}.
236 @item @emph{C/C++}
237 @multitable @columnfractions .20 .80
238 @item @emph{Prototype}: @tab @code{int omp_get_ancestor_thread_num(int level);}
239 @end multitable
241 @item @emph{Fortran}:
242 @multitable @columnfractions .20 .80
243 @item @emph{Interface}: @tab @code{integer function omp_get_ancestor_thread_num(level)}
244 @item                   @tab @code{integer level}
245 @end multitable
247 @item @emph{See also}:
248 @ref{omp_get_level}, @ref{omp_get_thread_num}, @ref{omp_get_team_size}
250 @item @emph{Reference}:
251 @uref{http://www.openmp.org/, OpenMP specification v4.0}, Section 3.2.18.
252 @end table
256 @node omp_get_cancellation
257 @section @code{omp_get_cancellation} -- Whether cancellation support is enabled
258 @table @asis
259 @item @emph{Description}:
260 This function returns @code{true} if cancellation is activated, @code{false}
261 otherwise.  Here, @code{true} and @code{false} represent their language-specific
262 counterparts.  Unless @env{OMP_CANCELLATION} is set true, cancellations are
263 deactivated.
265 @item @emph{C/C++}:
266 @multitable @columnfractions .20 .80
267 @item @emph{Prototype}: @tab @code{int omp_get_cancellation(void);}
268 @end multitable
270 @item @emph{Fortran}:
271 @multitable @columnfractions .20 .80
272 @item @emph{Interface}: @tab @code{logical function omp_get_cancellation()}
273 @end multitable
275 @item @emph{See also}:
276 @ref{OMP_CANCELLATION}
278 @item @emph{Reference}:
279 @uref{http://www.openmp.org/, OpenMP specification v4.0}, Section 3.2.9.
280 @end table
284 @node omp_get_default_device
285 @section @code{omp_get_default_device} -- Get the default device for target regions
286 @table @asis
287 @item @emph{Description}:
288 Get the default device for target regions without device clause.
290 @item @emph{C/C++}:
291 @multitable @columnfractions .20 .80
292 @item @emph{Prototype}: @tab @code{int omp_get_default_device(void);}
293 @end multitable
295 @item @emph{Fortran}:
296 @multitable @columnfractions .20 .80
297 @item @emph{Interface}: @tab @code{integer function omp_get_default_device()}
298 @end multitable
300 @item @emph{See also}:
301 @ref{OMP_DEFAULT_DEVICE}, @ref{omp_set_default_device}
303 @item @emph{Reference}:
304 @uref{http://www.openmp.org/, OpenMP specification v4.0}, Section 3.2.24.
305 @end table
309 @node omp_get_dynamic
310 @section @code{omp_get_dynamic} -- Dynamic teams setting
311 @table @asis
312 @item @emph{Description}:
313 This function returns @code{true} if enabled, @code{false} otherwise. 
314 Here, @code{true} and @code{false} represent their language-specific 
315 counterparts.
317 The dynamic team setting may be initialized at startup by the 
318 @env{OMP_DYNAMIC} environment variable or at runtime using
319 @code{omp_set_dynamic}.  If undefined, dynamic adjustment is
320 disabled by default.
322 @item @emph{C/C++}:
323 @multitable @columnfractions .20 .80
324 @item @emph{Prototype}: @tab @code{int omp_get_dynamic(void);}
325 @end multitable
327 @item @emph{Fortran}:
328 @multitable @columnfractions .20 .80
329 @item @emph{Interface}: @tab @code{logical function omp_get_dynamic()}
330 @end multitable
332 @item @emph{See also}:
333 @ref{omp_set_dynamic}, @ref{OMP_DYNAMIC}
335 @item @emph{Reference}:
336 @uref{http://www.openmp.org/, OpenMP specification v4.0}, Section 3.2.8.
337 @end table
341 @node omp_get_level
342 @section @code{omp_get_level} -- Obtain the current nesting level
343 @table @asis
344 @item @emph{Description}:
345 This function returns the nesting level for the parallel blocks,
346 which enclose the calling call.
348 @item @emph{C/C++}
349 @multitable @columnfractions .20 .80
350 @item @emph{Prototype}: @tab @code{int omp_get_level(void);}
351 @end multitable
353 @item @emph{Fortran}:
354 @multitable @columnfractions .20 .80
355 @item @emph{Interface}: @tab @code{integer function omp_level()}
356 @end multitable
358 @item @emph{See also}:
359 @ref{omp_get_active_level}
361 @item @emph{Reference}:
362 @uref{http://www.openmp.org/, OpenMP specification v4.0}, Section 3.2.17.
363 @end table
367 @node omp_get_max_active_levels
368 @section @code{omp_get_max_active_levels} -- Maximum number of active regions
369 @table @asis
370 @item @emph{Description}:
371 This function obtains the maximum allowed number of nested, active parallel regions.
373 @item @emph{C/C++}
374 @multitable @columnfractions .20 .80
375 @item @emph{Prototype}: @tab @code{int omp_get_max_active_levels(void);}
376 @end multitable
378 @item @emph{Fortran}:
379 @multitable @columnfractions .20 .80
380 @item @emph{Interface}: @tab @code{integer function omp_get_max_active_levels()}
381 @end multitable
383 @item @emph{See also}:
384 @ref{omp_set_max_active_levels}, @ref{omp_get_active_level}
386 @item @emph{Reference}:
387 @uref{http://www.openmp.org/, OpenMP specification v4.0}, Section 3.2.16.
388 @end table
392 @node omp_get_max_threads
393 @section @code{omp_get_max_threads} -- Maximum number of threads of parallel region
394 @table @asis
395 @item @emph{Description}:
396 Return the maximum number of threads used for the current parallel region
397 that does not use the clause @code{num_threads}.
399 @item @emph{C/C++}:
400 @multitable @columnfractions .20 .80
401 @item @emph{Prototype}: @tab @code{int omp_get_max_threads(void);}
402 @end multitable
404 @item @emph{Fortran}:
405 @multitable @columnfractions .20 .80
406 @item @emph{Interface}: @tab @code{integer function omp_get_max_threads()}
407 @end multitable
409 @item @emph{See also}:
410 @ref{omp_set_num_threads}, @ref{omp_set_dynamic}, @ref{omp_get_thread_limit}
412 @item @emph{Reference}:
413 @uref{http://www.openmp.org/, OpenMP specification v4.0}, Section 3.2.3.
414 @end table
418 @node omp_get_nested
419 @section @code{omp_get_nested} -- Nested parallel regions
420 @table @asis
421 @item @emph{Description}:
422 This function returns @code{true} if nested parallel regions are
423 enabled, @code{false} otherwise.  Here, @code{true} and @code{false}
424 represent their language-specific counterparts.
426 Nested parallel regions may be initialized at startup by the 
427 @env{OMP_NESTED} environment variable or at runtime using
428 @code{omp_set_nested}.  If undefined, nested parallel regions are
429 disabled by default.
431 @item @emph{C/C++}:
432 @multitable @columnfractions .20 .80
433 @item @emph{Prototype}: @tab @code{int omp_get_nested(void);}
434 @end multitable
436 @item @emph{Fortran}:
437 @multitable @columnfractions .20 .80
438 @item @emph{Interface}: @tab @code{logical function omp_get_nested()}
439 @end multitable
441 @item @emph{See also}:
442 @ref{omp_set_nested}, @ref{OMP_NESTED}
444 @item @emph{Reference}:
445 @uref{http://www.openmp.org/, OpenMP specification v4.0}, Section 3.2.11.
446 @end table
450 @node omp_get_num_devices
451 @section @code{omp_get_num_devices} -- Number of target devices
452 @table @asis
453 @item @emph{Description}:
454 Returns the number of target devices.
456 @item @emph{C/C++}:
457 @multitable @columnfractions .20 .80
458 @item @emph{Prototype}: @tab @code{int omp_get_num_devices(void);}
459 @end multitable
461 @item @emph{Fortran}:
462 @multitable @columnfractions .20 .80
463 @item @emph{Interface}: @tab @code{integer function omp_get_num_devices()}
464 @end multitable
466 @item @emph{Reference}:
467 @uref{http://www.openmp.org/, OpenMP specification v4.0}, Section 3.2.25.
468 @end table
472 @node omp_get_num_procs
473 @section @code{omp_get_num_procs} -- Number of processors online
474 @table @asis
475 @item @emph{Description}:
476 Returns the number of processors online on that device.
478 @item @emph{C/C++}:
479 @multitable @columnfractions .20 .80
480 @item @emph{Prototype}: @tab @code{int omp_get_num_procs(void);}
481 @end multitable
483 @item @emph{Fortran}:
484 @multitable @columnfractions .20 .80
485 @item @emph{Interface}: @tab @code{integer function omp_get_num_procs()}
486 @end multitable
488 @item @emph{Reference}:
489 @uref{http://www.openmp.org/, OpenMP specification v4.0}, Section 3.2.5.
490 @end table
494 @node omp_get_num_teams
495 @section @code{omp_get_num_teams} -- Number of teams
496 @table @asis
497 @item @emph{Description}:
498 Returns the number of teams in the current team region.
500 @item @emph{C/C++}:
501 @multitable @columnfractions .20 .80
502 @item @emph{Prototype}: @tab @code{int omp_get_num_teams(void);}
503 @end multitable
505 @item @emph{Fortran}:
506 @multitable @columnfractions .20 .80
507 @item @emph{Interface}: @tab @code{integer function omp_get_num_teams()}
508 @end multitable
510 @item @emph{Reference}:
511 @uref{http://www.openmp.org/, OpenMP specification v4.0}, Section 3.2.26.
512 @end table
516 @node omp_get_num_threads
517 @section @code{omp_get_num_threads} -- Size of the active team
518 @table @asis
519 @item @emph{Description}:
520 Returns the number of threads in the current team.  In a sequential section of
521 the program @code{omp_get_num_threads} returns 1.
523 The default team size may be initialized at startup by the 
524 @env{OMP_NUM_THREADS} environment variable.  At runtime, the size
525 of the current team may be set either by the @code{NUM_THREADS}
526 clause or by @code{omp_set_num_threads}.  If none of the above were
527 used to define a specific value and @env{OMP_DYNAMIC} is disabled,
528 one thread per CPU online is used.
530 @item @emph{C/C++}:
531 @multitable @columnfractions .20 .80
532 @item @emph{Prototype}: @tab @code{int omp_get_num_threads(void);}
533 @end multitable
535 @item @emph{Fortran}:
536 @multitable @columnfractions .20 .80
537 @item @emph{Interface}: @tab @code{integer function omp_get_num_threads()}
538 @end multitable
540 @item @emph{See also}:
541 @ref{omp_get_max_threads}, @ref{omp_set_num_threads}, @ref{OMP_NUM_THREADS}
543 @item @emph{Reference}:
544 @uref{http://www.openmp.org/, OpenMP specification v4.0}, Section 3.2.2.
545 @end table
549 @node omp_get_proc_bind
550 @section @code{omp_get_proc_bind} -- Whether theads may be moved between CPUs
551 @table @asis
552 @item @emph{Description}:
553 This functions returns the currently active thread affinity policy, which is
554 set via @env{OMP_PROC_BIND}.  Possible values are @code{omp_proc_bind_false},
555 @code{omp_proc_bind_true}, @code{omp_proc_bind_master},
556 @code{omp_proc_bind_close} and @code{omp_proc_bind_spread}.
558 @item @emph{C/C++}:
559 @multitable @columnfractions .20 .80
560 @item @emph{Prototype}: @tab @code{omp_proc_bind_t omp_get_proc_bind(void);}
561 @end multitable
563 @item @emph{Fortran}:
564 @multitable @columnfractions .20 .80
565 @item @emph{Interface}: @tab @code{integer(kind=omp_proc_bind_kind) function omp_get_proc_bind()}
566 @end multitable
568 @item @emph{See also}:
569 @ref{OMP_PROC_BIND}, @ref{OMP_PLACES}, @ref{GOMP_CPU_AFFINITY},
571 @item @emph{Reference}:
572 @uref{http://www.openmp.org/, OpenMP specification v4.0}, Section 3.2.22.
573 @end table
577 @node omp_get_schedule
578 @section @code{omp_get_schedule} -- Obtain the runtime scheduling method
579 @table @asis
580 @item @emph{Description}:
581 Obtain the runtime scheduling method.  The @var{kind} argument will be
582 set to the value @code{omp_sched_static}, @code{omp_sched_dynamic},
583 @code{omp_sched_guided} or @code{omp_sched_auto}.  The second argument,
584 @var{modifier}, is set to the chunk size.
586 @item @emph{C/C++}
587 @multitable @columnfractions .20 .80
588 @item @emph{Prototype}: @tab @code{void omp_get_schedule(omp_sched_t *kind, int *modifier);}
589 @end multitable
591 @item @emph{Fortran}:
592 @multitable @columnfractions .20 .80
593 @item @emph{Interface}: @tab @code{subroutine omp_get_schedule(kind, modifier)}
594 @item                   @tab @code{integer(kind=omp_sched_kind) kind}
595 @item                   @tab @code{integer modifier}
596 @end multitable
598 @item @emph{See also}:
599 @ref{omp_set_schedule}, @ref{OMP_SCHEDULE}
601 @item @emph{Reference}:
602 @uref{http://www.openmp.org/, OpenMP specification v4.0}, Section 3.2.13.
603 @end table
607 @node omp_get_team_num
608 @section @code{omp_get_team_num} -- Get team number
609 @table @asis
610 @item @emph{Description}:
611 Returns the team number of the calling thread.
613 @item @emph{C/C++}:
614 @multitable @columnfractions .20 .80
615 @item @emph{Prototype}: @tab @code{int omp_get_team_num(void);}
616 @end multitable
618 @item @emph{Fortran}:
619 @multitable @columnfractions .20 .80
620 @item @emph{Interface}: @tab @code{integer function omp_get_team_num()}
621 @end multitable
623 @item @emph{Reference}:
624 @uref{http://www.openmp.org/, OpenMP specification v4.0}, Section 3.2.27.
625 @end table
629 @node omp_get_team_size
630 @section @code{omp_get_team_size} -- Number of threads in a team
631 @table @asis
632 @item @emph{Description}:
633 This function returns the number of threads in a thread team to which
634 either the current thread or its ancestor belongs.  For values of @var{level}
635 outside zero to @code{omp_get_level}, -1 is returned; if @var{level} is zero,
636 1 is returned, and for @code{omp_get_level}, the result is identical
637 to @code{omp_get_num_threads}.
639 @item @emph{C/C++}:
640 @multitable @columnfractions .20 .80
641 @item @emph{Prototype}: @tab @code{int omp_get_team_size(int level);}
642 @end multitable
644 @item @emph{Fortran}:
645 @multitable @columnfractions .20 .80
646 @item @emph{Interface}: @tab @code{integer function omp_get_team_size(level)}
647 @item                   @tab @code{integer level}
648 @end multitable
650 @item @emph{See also}:
651 @ref{omp_get_num_threads}, @ref{omp_get_level}, @ref{omp_get_ancestor_thread_num}
653 @item @emph{Reference}:
654 @uref{http://www.openmp.org/, OpenMP specification v4.0}, Section 3.2.19.
655 @end table
659 @node omp_get_thread_limit
660 @section @code{omp_get_thread_limit} -- Maximum number of threads
661 @table @asis
662 @item @emph{Description}:
663 Return the maximum number of threads of the program.
665 @item @emph{C/C++}:
666 @multitable @columnfractions .20 .80
667 @item @emph{Prototype}: @tab @code{int omp_get_thread_limit(void);}
668 @end multitable
670 @item @emph{Fortran}:
671 @multitable @columnfractions .20 .80
672 @item @emph{Interface}: @tab @code{integer function omp_get_thread_limit()}
673 @end multitable
675 @item @emph{See also}:
676 @ref{omp_get_max_threads}, @ref{OMP_THREAD_LIMIT}
678 @item @emph{Reference}:
679 @uref{http://www.openmp.org/, OpenMP specification v4.0}, Section 3.2.14.
680 @end table
684 @node omp_get_thread_num
685 @section @code{omp_get_thread_num} -- Current thread ID
686 @table @asis
687 @item @emph{Description}:
688 Returns a unique thread identification number within the current team.
689 In a sequential parts of the program, @code{omp_get_thread_num}
690 always returns 0.  In parallel regions the return value varies
691 from 0 to @code{omp_get_num_threads}-1 inclusive.  The return
692 value of the master thread of a team is always 0.
694 @item @emph{C/C++}:
695 @multitable @columnfractions .20 .80
696 @item @emph{Prototype}: @tab @code{int omp_get_thread_num(void);}
697 @end multitable
699 @item @emph{Fortran}:
700 @multitable @columnfractions .20 .80
701 @item @emph{Interface}: @tab @code{integer function omp_get_thread_num()}
702 @end multitable
704 @item @emph{See also}:
705 @ref{omp_get_num_threads}, @ref{omp_get_ancestor_thread_num}
707 @item @emph{Reference}:
708 @uref{http://www.openmp.org/, OpenMP specification v4.0}, Section 3.2.4.
709 @end table
713 @node omp_in_parallel
714 @section @code{omp_in_parallel} -- Whether a parallel region is active
715 @table @asis
716 @item @emph{Description}:
717 This function returns @code{true} if currently running in parallel,
718 @code{false} otherwise.  Here, @code{true} and @code{false} represent
719 their language-specific counterparts.
721 @item @emph{C/C++}:
722 @multitable @columnfractions .20 .80
723 @item @emph{Prototype}: @tab @code{int omp_in_parallel(void);}
724 @end multitable
726 @item @emph{Fortran}:
727 @multitable @columnfractions .20 .80
728 @item @emph{Interface}: @tab @code{logical function omp_in_parallel()}
729 @end multitable
731 @item @emph{Reference}:
732 @uref{http://www.openmp.org/, OpenMP specification v4.0}, Section 3.2.6.
733 @end table
736 @node omp_in_final
737 @section @code{omp_in_final} -- Whether in final or included task region
738 @table @asis
739 @item @emph{Description}:
740 This function returns @code{true} if currently running in a final
741 or included task region, @code{false} otherwise.  Here, @code{true}
742 and @code{false} represent their language-specific counterparts.
744 @item @emph{C/C++}:
745 @multitable @columnfractions .20 .80
746 @item @emph{Prototype}: @tab @code{int omp_in_final(void);}
747 @end multitable
749 @item @emph{Fortran}:
750 @multitable @columnfractions .20 .80
751 @item @emph{Interface}: @tab @code{logical function omp_in_final()}
752 @end multitable
754 @item @emph{Reference}:
755 @uref{http://www.openmp.org/, OpenMP specification v4.0}, Section 3.2.21.
756 @end table
760 @node omp_is_initial_device
761 @section @code{omp_is_initial_device} -- Whether executing on the host device
762 @table @asis
763 @item @emph{Description}:
764 This function returns @code{true} if currently running on the host device,
765 @code{false} otherwise.  Here, @code{true} and @code{false} represent
766 their language-specific counterparts.
768 @item @emph{C/C++}:
769 @multitable @columnfractions .20 .80
770 @item @emph{Prototype}: @tab @code{int omp_is_initial_device(void);}
771 @end multitable
773 @item @emph{Fortran}:
774 @multitable @columnfractions .20 .80
775 @item @emph{Interface}: @tab @code{logical function omp_is_initial_device()}
776 @end multitable
778 @item @emph{Reference}:
779 @uref{http://www.openmp.org/, OpenMP specification v4.0}, Section 3.2.28.
780 @end table
784 @node omp_set_default_device
785 @section @code{omp_set_default_device} -- Set the default device for target regions
786 @table @asis
787 @item @emph{Description}:
788 Set the default device for target regions without device clause.  The argument
789 shall be a nonnegative device number.
791 @item @emph{C/C++}:
792 @multitable @columnfractions .20 .80
793 @item @emph{Prototype}: @tab @code{void omp_set_default_device(int device_num);}
794 @end multitable
796 @item @emph{Fortran}:
797 @multitable @columnfractions .20 .80
798 @item @emph{Interface}: @tab @code{subroutine omp_set_default_device(device_num)}
799 @item                   @tab @code{integer device_num}
800 @end multitable
802 @item @emph{See also}:
803 @ref{OMP_DEFAULT_DEVICE}, @ref{omp_get_default_device}
805 @item @emph{Reference}:
806 @uref{http://www.openmp.org/, OpenMP specification v4.0}, Section 3.2.23.
807 @end table
811 @node omp_set_dynamic
812 @section @code{omp_set_dynamic} -- Enable/disable dynamic teams
813 @table @asis
814 @item @emph{Description}:
815 Enable or disable the dynamic adjustment of the number of threads 
816 within a team.  The function takes the language-specific equivalent
817 of @code{true} and @code{false}, where @code{true} enables dynamic 
818 adjustment of team sizes and @code{false} disables it.
820 @item @emph{C/C++}:
821 @multitable @columnfractions .20 .80
822 @item @emph{Prototype}: @tab @code{void omp_set_dynamic(int dynamic_threads);}
823 @end multitable
825 @item @emph{Fortran}:
826 @multitable @columnfractions .20 .80
827 @item @emph{Interface}: @tab @code{subroutine omp_set_dynamic(dynamic_threads)}
828 @item                   @tab @code{logical, intent(in) :: dynamic_threads}
829 @end multitable
831 @item @emph{See also}:
832 @ref{OMP_DYNAMIC}, @ref{omp_get_dynamic}
834 @item @emph{Reference}:
835 @uref{http://www.openmp.org/, OpenMP specification v4.0}, Section 3.2.7.
836 @end table
840 @node omp_set_max_active_levels
841 @section @code{omp_set_max_active_levels} -- Limits the number of active parallel regions
842 @table @asis
843 @item @emph{Description}:
844 This function limits the maximum allowed number of nested, active
845 parallel regions.
847 @item @emph{C/C++}
848 @multitable @columnfractions .20 .80
849 @item @emph{Prototype}: @tab @code{void omp_set_max_active_levels(int max_levels);}
850 @end multitable
852 @item @emph{Fortran}:
853 @multitable @columnfractions .20 .80
854 @item @emph{Interface}: @tab @code{subroutine omp_set_max_active_levels(max_levels)}
855 @item                   @tab @code{integer max_levels}
856 @end multitable
858 @item @emph{See also}:
859 @ref{omp_get_max_active_levels}, @ref{omp_get_active_level}
861 @item @emph{Reference}:
862 @uref{http://www.openmp.org/, OpenMP specification v4.0}, Section 3.2.15.
863 @end table
867 @node omp_set_nested
868 @section @code{omp_set_nested} -- Enable/disable nested parallel regions
869 @table @asis
870 @item @emph{Description}:
871 Enable or disable nested parallel regions, i.e., whether team members
872 are allowed to create new teams.  The function takes the language-specific
873 equivalent of @code{true} and @code{false}, where @code{true} enables 
874 dynamic adjustment of team sizes and @code{false} disables it.
876 @item @emph{C/C++}:
877 @multitable @columnfractions .20 .80
878 @item @emph{Prototype}: @tab @code{void omp_set_nested(int nested);}
879 @end multitable
881 @item @emph{Fortran}:
882 @multitable @columnfractions .20 .80
883 @item @emph{Interface}: @tab @code{subroutine omp_set_nested(nested)}
884 @item                   @tab @code{logical, intent(in) :: nested}
885 @end multitable
887 @item @emph{See also}:
888 @ref{OMP_NESTED}, @ref{omp_get_nested}
890 @item @emph{Reference}:
891 @uref{http://www.openmp.org/, OpenMP specification v4.0}, Section 3.2.10.
892 @end table
896 @node omp_set_num_threads
897 @section @code{omp_set_num_threads} -- Set upper team size limit
898 @table @asis
899 @item @emph{Description}:
900 Specifies the number of threads used by default in subsequent parallel 
901 sections, if those do not specify a @code{num_threads} clause.  The
902 argument of @code{omp_set_num_threads} shall be a positive integer.
904 @item @emph{C/C++}:
905 @multitable @columnfractions .20 .80
906 @item @emph{Prototype}: @tab @code{void omp_set_num_threads(int num_threads);}
907 @end multitable
909 @item @emph{Fortran}:
910 @multitable @columnfractions .20 .80
911 @item @emph{Interface}: @tab @code{subroutine omp_set_num_threads(num_threads)}
912 @item                   @tab @code{integer, intent(in) :: num_threads}
913 @end multitable
915 @item @emph{See also}:
916 @ref{OMP_NUM_THREADS}, @ref{omp_get_num_threads}, @ref{omp_get_max_threads}
918 @item @emph{Reference}:
919 @uref{http://www.openmp.org/, OpenMP specification v4.0}, Section 3.2.1.
920 @end table
924 @node omp_set_schedule
925 @section @code{omp_set_schedule} -- Set the runtime scheduling method
926 @table @asis
927 @item @emph{Description}:
928 Sets the runtime scheduling method.  The @var{kind} argument can have the
929 value @code{omp_sched_static}, @code{omp_sched_dynamic},
930 @code{omp_sched_guided} or @code{omp_sched_auto}.  Except for
931 @code{omp_sched_auto}, the chunk size is set to the value of
932 @var{modifier} if positive, or to the default value if zero or negative.
933 For @code{omp_sched_auto} the @var{modifier} argument is ignored.
935 @item @emph{C/C++}
936 @multitable @columnfractions .20 .80
937 @item @emph{Prototype}: @tab @code{void omp_set_schedule(omp_sched_t kind, int modifier);}
938 @end multitable
940 @item @emph{Fortran}:
941 @multitable @columnfractions .20 .80
942 @item @emph{Interface}: @tab @code{subroutine omp_set_schedule(kind, modifier)}
943 @item                   @tab @code{integer(kind=omp_sched_kind) kind}
944 @item                   @tab @code{integer modifier}
945 @end multitable
947 @item @emph{See also}:
948 @ref{omp_get_schedule}
949 @ref{OMP_SCHEDULE}
951 @item @emph{Reference}:
952 @uref{http://www.openmp.org/, OpenMP specification v4.0}, Section 3.2.12.
953 @end table
957 @node omp_init_lock
958 @section @code{omp_init_lock} -- Initialize simple lock
959 @table @asis
960 @item @emph{Description}:
961 Initialize a simple lock.  After initialization, the lock is in
962 an unlocked state.
964 @item @emph{C/C++}:
965 @multitable @columnfractions .20 .80
966 @item @emph{Prototype}: @tab @code{void omp_init_lock(omp_lock_t *lock);}
967 @end multitable
969 @item @emph{Fortran}:
970 @multitable @columnfractions .20 .80
971 @item @emph{Interface}: @tab @code{subroutine omp_init_lock(svar)}
972 @item                   @tab @code{integer(omp_lock_kind), intent(out) :: svar}
973 @end multitable
975 @item @emph{See also}:
976 @ref{omp_destroy_lock}
978 @item @emph{Reference}: 
979 @uref{http://www.openmp.org/, OpenMP specification v4.0}, Section 3.3.1.
980 @end table
984 @node omp_set_lock
985 @section @code{omp_set_lock} -- Wait for and set simple lock
986 @table @asis
987 @item @emph{Description}:
988 Before setting a simple lock, the lock variable must be initialized by 
989 @code{omp_init_lock}.  The calling thread is blocked until the lock 
990 is available.  If the lock is already held by the current thread, 
991 a deadlock occurs.
993 @item @emph{C/C++}:
994 @multitable @columnfractions .20 .80
995 @item @emph{Prototype}: @tab @code{void omp_set_lock(omp_lock_t *lock);}
996 @end multitable
998 @item @emph{Fortran}:
999 @multitable @columnfractions .20 .80
1000 @item @emph{Interface}: @tab @code{subroutine omp_set_lock(svar)}
1001 @item                   @tab @code{integer(omp_lock_kind), intent(inout) :: svar}
1002 @end multitable
1004 @item @emph{See also}:
1005 @ref{omp_init_lock}, @ref{omp_test_lock}, @ref{omp_unset_lock}
1007 @item @emph{Reference}: 
1008 @uref{http://www.openmp.org/, OpenMP specification v4.0}, Section 3.3.3.
1009 @end table
1013 @node omp_test_lock
1014 @section @code{omp_test_lock} -- Test and set simple lock if available
1015 @table @asis
1016 @item @emph{Description}:
1017 Before setting a simple lock, the lock variable must be initialized by 
1018 @code{omp_init_lock}.  Contrary to @code{omp_set_lock}, @code{omp_test_lock} 
1019 does not block if the lock is not available.  This function returns
1020 @code{true} upon success, @code{false} otherwise.  Here, @code{true} and
1021 @code{false} represent their language-specific counterparts.
1023 @item @emph{C/C++}:
1024 @multitable @columnfractions .20 .80
1025 @item @emph{Prototype}: @tab @code{int omp_test_lock(omp_lock_t *lock);}
1026 @end multitable
1028 @item @emph{Fortran}:
1029 @multitable @columnfractions .20 .80
1030 @item @emph{Interface}: @tab @code{logical function omp_test_lock(svar)}
1031 @item                   @tab @code{integer(omp_lock_kind), intent(inout) :: svar}
1032 @end multitable
1034 @item @emph{See also}:
1035 @ref{omp_init_lock}, @ref{omp_set_lock}, @ref{omp_set_lock}
1037 @item @emph{Reference}: 
1038 @uref{http://www.openmp.org/, OpenMP specification v4.0}, Section 3.3.5.
1039 @end table
1043 @node omp_unset_lock
1044 @section @code{omp_unset_lock} -- Unset simple lock
1045 @table @asis
1046 @item @emph{Description}:
1047 A simple lock about to be unset must have been locked by @code{omp_set_lock}
1048 or @code{omp_test_lock} before.  In addition, the lock must be held by the
1049 thread calling @code{omp_unset_lock}.  Then, the lock becomes unlocked.  If one
1050 or more threads attempted to set the lock before, one of them is chosen to,
1051 again, set the lock to itself.
1053 @item @emph{C/C++}:
1054 @multitable @columnfractions .20 .80
1055 @item @emph{Prototype}: @tab @code{void omp_unset_lock(omp_lock_t *lock);}
1056 @end multitable
1058 @item @emph{Fortran}:
1059 @multitable @columnfractions .20 .80
1060 @item @emph{Interface}: @tab @code{subroutine omp_unset_lock(svar)}
1061 @item                   @tab @code{integer(omp_lock_kind), intent(inout) :: svar}
1062 @end multitable
1064 @item @emph{See also}:
1065 @ref{omp_set_lock}, @ref{omp_test_lock}
1067 @item @emph{Reference}: 
1068 @uref{http://www.openmp.org/, OpenMP specification v4.0}, Section 3.3.4.
1069 @end table
1073 @node omp_destroy_lock
1074 @section @code{omp_destroy_lock} -- Destroy simple lock
1075 @table @asis
1076 @item @emph{Description}:
1077 Destroy a simple lock.  In order to be destroyed, a simple lock must be
1078 in the unlocked state. 
1080 @item @emph{C/C++}:
1081 @multitable @columnfractions .20 .80
1082 @item @emph{Prototype}: @tab @code{void omp_destroy_lock(omp_lock_t *lock);}
1083 @end multitable
1085 @item @emph{Fortran}:
1086 @multitable @columnfractions .20 .80
1087 @item @emph{Interface}: @tab @code{subroutine omp_destroy_lock(svar)}
1088 @item                   @tab @code{integer(omp_lock_kind), intent(inout) :: svar}
1089 @end multitable
1091 @item @emph{See also}:
1092 @ref{omp_init_lock}
1094 @item @emph{Reference}: 
1095 @uref{http://www.openmp.org/, OpenMP specification v4.0}, Section 3.3.2.
1096 @end table
1100 @node omp_init_nest_lock
1101 @section @code{omp_init_nest_lock} -- Initialize nested lock
1102 @table @asis
1103 @item @emph{Description}:
1104 Initialize a nested lock.  After initialization, the lock is in
1105 an unlocked state and the nesting count is set to zero.
1107 @item @emph{C/C++}:
1108 @multitable @columnfractions .20 .80
1109 @item @emph{Prototype}: @tab @code{void omp_init_nest_lock(omp_nest_lock_t *lock);}
1110 @end multitable
1112 @item @emph{Fortran}:
1113 @multitable @columnfractions .20 .80
1114 @item @emph{Interface}: @tab @code{subroutine omp_init_nest_lock(nvar)}
1115 @item                   @tab @code{integer(omp_nest_lock_kind), intent(out) :: nvar}
1116 @end multitable
1118 @item @emph{See also}:
1119 @ref{omp_destroy_nest_lock}
1121 @item @emph{Reference}:
1122 @uref{http://www.openmp.org/, OpenMP specification v4.0}, Section 3.3.1.
1123 @end table
1126 @node omp_set_nest_lock
1127 @section @code{omp_set_nest_lock} -- Wait for and set nested lock
1128 @table @asis
1129 @item @emph{Description}:
1130 Before setting a nested lock, the lock variable must be initialized by 
1131 @code{omp_init_nest_lock}.  The calling thread is blocked until the lock
1132 is available.  If the lock is already held by the current thread, the
1133 nesting count for the lock is incremented.
1135 @item @emph{C/C++}:
1136 @multitable @columnfractions .20 .80
1137 @item @emph{Prototype}: @tab @code{void omp_set_nest_lock(omp_nest_lock_t *lock);}
1138 @end multitable
1140 @item @emph{Fortran}:
1141 @multitable @columnfractions .20 .80
1142 @item @emph{Interface}: @tab @code{subroutine omp_set_nest_lock(nvar)}
1143 @item                   @tab @code{integer(omp_nest_lock_kind), intent(inout) :: nvar}
1144 @end multitable
1146 @item @emph{See also}:
1147 @ref{omp_init_nest_lock}, @ref{omp_unset_nest_lock}
1149 @item @emph{Reference}: 
1150 @uref{http://www.openmp.org/, OpenMP specification v4.0}, Section 3.3.3.
1151 @end table
1155 @node omp_test_nest_lock
1156 @section @code{omp_test_nest_lock} -- Test and set nested lock if available
1157 @table @asis
1158 @item @emph{Description}:
1159 Before setting a nested lock, the lock variable must be initialized by 
1160 @code{omp_init_nest_lock}.  Contrary to @code{omp_set_nest_lock},
1161 @code{omp_test_nest_lock} does not block if the lock is not available. 
1162 If the lock is already held by the current thread, the new nesting count 
1163 is returned.  Otherwise, the return value equals zero.
1165 @item @emph{C/C++}:
1166 @multitable @columnfractions .20 .80
1167 @item @emph{Prototype}: @tab @code{int omp_test_nest_lock(omp_nest_lock_t *lock);}
1168 @end multitable
1170 @item @emph{Fortran}:
1171 @multitable @columnfractions .20 .80
1172 @item @emph{Interface}: @tab @code{logical function omp_test_nest_lock(nvar)}
1173 @item                   @tab @code{integer(omp_nest_lock_kind), intent(inout) :: nvar}
1174 @end multitable
1177 @item @emph{See also}:
1178 @ref{omp_init_lock}, @ref{omp_set_lock}, @ref{omp_set_lock}
1180 @item @emph{Reference}: 
1181 @uref{http://www.openmp.org/, OpenMP specification v4.0}, Section 3.3.5.
1182 @end table
1186 @node omp_unset_nest_lock
1187 @section @code{omp_unset_nest_lock} -- Unset nested lock
1188 @table @asis
1189 @item @emph{Description}:
1190 A nested lock about to be unset must have been locked by @code{omp_set_nested_lock}
1191 or @code{omp_test_nested_lock} before.  In addition, the lock must be held by the
1192 thread calling @code{omp_unset_nested_lock}.  If the nesting count drops to zero, the
1193 lock becomes unlocked.  If one ore more threads attempted to set the lock before,
1194 one of them is chosen to, again, set the lock to itself.
1196 @item @emph{C/C++}:
1197 @multitable @columnfractions .20 .80
1198 @item @emph{Prototype}: @tab @code{void omp_unset_nest_lock(omp_nest_lock_t *lock);}
1199 @end multitable
1201 @item @emph{Fortran}:
1202 @multitable @columnfractions .20 .80
1203 @item @emph{Interface}: @tab @code{subroutine omp_unset_nest_lock(nvar)}
1204 @item                   @tab @code{integer(omp_nest_lock_kind), intent(inout) :: nvar}
1205 @end multitable
1207 @item @emph{See also}:
1208 @ref{omp_set_nest_lock}
1210 @item @emph{Reference}: 
1211 @uref{http://www.openmp.org/, OpenMP specification v4.0}, Section 3.3.4.
1212 @end table
1216 @node omp_destroy_nest_lock
1217 @section @code{omp_destroy_nest_lock} -- Destroy nested lock
1218 @table @asis
1219 @item @emph{Description}:
1220 Destroy a nested lock.  In order to be destroyed, a nested lock must be
1221 in the unlocked state and its nesting count must equal zero.
1223 @item @emph{C/C++}:
1224 @multitable @columnfractions .20 .80
1225 @item @emph{Prototype}: @tab @code{void omp_destroy_nest_lock(omp_nest_lock_t *);}
1226 @end multitable
1228 @item @emph{Fortran}:
1229 @multitable @columnfractions .20 .80
1230 @item @emph{Interface}: @tab @code{subroutine omp_destroy_nest_lock(nvar)}
1231 @item                   @tab @code{integer(omp_nest_lock_kind), intent(inout) :: nvar}
1232 @end multitable
1234 @item @emph{See also}:
1235 @ref{omp_init_lock}
1237 @item @emph{Reference}: 
1238 @uref{http://www.openmp.org/, OpenMP specification v4.0}, Section 3.3.2.
1239 @end table
1243 @node omp_get_wtick
1244 @section @code{omp_get_wtick} -- Get timer precision
1245 @table @asis
1246 @item @emph{Description}:
1247 Gets the timer precision, i.e., the number of seconds between two 
1248 successive clock ticks.
1250 @item @emph{C/C++}:
1251 @multitable @columnfractions .20 .80
1252 @item @emph{Prototype}: @tab @code{double omp_get_wtick(void);}
1253 @end multitable
1255 @item @emph{Fortran}:
1256 @multitable @columnfractions .20 .80
1257 @item @emph{Interface}: @tab @code{double precision function omp_get_wtick()}
1258 @end multitable
1260 @item @emph{See also}:
1261 @ref{omp_get_wtime}
1263 @item @emph{Reference}: 
1264 @uref{http://www.openmp.org/, OpenMP specification v4.0}, Section 3.4.2.
1265 @end table
1269 @node omp_get_wtime
1270 @section @code{omp_get_wtime} -- Elapsed wall clock time
1271 @table @asis
1272 @item @emph{Description}:
1273 Elapsed wall clock time in seconds.  The time is measured per thread, no
1274 guarantee can be made that two distinct threads measure the same time.
1275 Time is measured from some "time in the past", which is an arbitrary time
1276 guaranteed not to change during the execution of the program.
1278 @item @emph{C/C++}:
1279 @multitable @columnfractions .20 .80
1280 @item @emph{Prototype}: @tab @code{double omp_get_wtime(void);}
1281 @end multitable
1283 @item @emph{Fortran}:
1284 @multitable @columnfractions .20 .80
1285 @item @emph{Interface}: @tab @code{double precision function omp_get_wtime()}
1286 @end multitable
1288 @item @emph{See also}:
1289 @ref{omp_get_wtick}
1291 @item @emph{Reference}: 
1292 @uref{http://www.openmp.org/, OpenMP specification v4.0}, Section 3.4.1.
1293 @end table
1297 @c ---------------------------------------------------------------------
1298 @c Environment Variables
1299 @c ---------------------------------------------------------------------
1301 @node Environment Variables
1302 @chapter Environment Variables
1304 The environment variables which beginning with @env{OMP_} are defined by
1305 section 4 of the OpenMP specification in version 4.0, while those
1306 beginning with @env{GOMP_} are GNU extensions.
1308 @menu
1309 * OMP_CANCELLATION::        Set whether cancellation is activated
1310 * OMP_DISPLAY_ENV::         Show OpenMP version and environment variables
1311 * OMP_DEFAULT_DEVICE::      Set the device used in target regions
1312 * OMP_DYNAMIC::             Dynamic adjustment of threads
1313 * OMP_MAX_ACTIVE_LEVELS::   Set the maximum number of nested parallel regions
1314 * OMP_NESTED::              Nested parallel regions
1315 * OMP_NUM_THREADS::         Specifies the number of threads to use
1316 * OMP_PROC_BIND::           Whether theads may be moved between CPUs
1317 * OMP_PLACES::              Specifies on which CPUs the theads should be placed
1318 * OMP_STACKSIZE::           Set default thread stack size
1319 * OMP_SCHEDULE::            How threads are scheduled
1320 * OMP_THREAD_LIMIT::        Set the maximum number of threads
1321 * OMP_WAIT_POLICY::         How waiting threads are handled
1322 * GOMP_CPU_AFFINITY::       Bind threads to specific CPUs
1323 * GOMP_DEBUG::              Enable debugging output
1324 * GOMP_STACKSIZE::          Set default thread stack size
1325 * GOMP_SPINCOUNT::          Set the busy-wait spin count
1326 * GOMP_RTEMS_THREAD_POOLS:: Set the RTEMS specific thread pools
1327 @end menu
1330 @node OMP_CANCELLATION
1331 @section @env{OMP_CANCELLATION} -- Set whether cancellation is activated
1332 @cindex Environment Variable
1333 @table @asis
1334 @item @emph{Description}:
1335 If set to @code{TRUE}, the cancellation is activated.  If set to @code{FALSE} or
1336 if unset, cancellation is disabled and the @code{cancel} construct is ignored.
1338 @item @emph{See also}:
1339 @ref{omp_get_cancellation}
1341 @item @emph{Reference}:
1342 @uref{http://www.openmp.org/, OpenMP specification v4.0}, Section 4.11
1343 @end table
1347 @node OMP_DISPLAY_ENV
1348 @section @env{OMP_DISPLAY_ENV} -- Show OpenMP version and environment variables
1349 @cindex Environment Variable
1350 @table @asis
1351 @item @emph{Description}:
1352 If set to @code{TRUE}, the OpenMP version number and the values
1353 associated with the OpenMP environment variables are printed to @code{stderr}.
1354 If set to @code{VERBOSE}, it additionally shows the value of the environment
1355 variables which are GNU extensions.  If undefined or set to @code{FALSE},
1356 this information will not be shown.
1359 @item @emph{Reference}:
1360 @uref{http://www.openmp.org/, OpenMP specification v4.0}, Section 4.12
1361 @end table
1365 @node OMP_DEFAULT_DEVICE
1366 @section @env{OMP_DEFAULT_DEVICE} -- Set the device used in target regions
1367 @cindex Environment Variable
1368 @table @asis
1369 @item @emph{Description}:
1370 Set to choose the device which is used in a @code{target} region, unless the
1371 value is overridden by @code{omp_set_default_device} or by a @code{device}
1372 clause.  The value shall be the nonnegative device number. If no device with
1373 the given device number exists, the code is executed on the host.  If unset,
1374 device number 0 will be used.
1377 @item @emph{See also}:
1378 @ref{omp_get_default_device}, @ref{omp_set_default_device},
1380 @item @emph{Reference}:
1381 @uref{http://www.openmp.org/, OpenMP specification v4.0}, Section 4.11
1382 @end table
1386 @node OMP_DYNAMIC
1387 @section @env{OMP_DYNAMIC} -- Dynamic adjustment of threads
1388 @cindex Environment Variable
1389 @table @asis
1390 @item @emph{Description}:
1391 Enable or disable the dynamic adjustment of the number of threads 
1392 within a team.  The value of this environment variable shall be 
1393 @code{TRUE} or @code{FALSE}.  If undefined, dynamic adjustment is
1394 disabled by default.
1396 @item @emph{See also}:
1397 @ref{omp_set_dynamic}
1399 @item @emph{Reference}: 
1400 @uref{http://www.openmp.org/, OpenMP specification v4.0}, Section 4.3
1401 @end table
1405 @node OMP_MAX_ACTIVE_LEVELS
1406 @section @env{OMP_MAX_ACTIVE_LEVELS} -- Set the maximum number of nested parallel regions
1407 @cindex Environment Variable
1408 @table @asis
1409 @item @emph{Description}:
1410 Specifies the initial value for the maximum number of nested parallel
1411 regions.  The value of this variable shall be a positive integer.
1412 If undefined, the number of active levels is unlimited.
1414 @item @emph{See also}:
1415 @ref{omp_set_max_active_levels}
1417 @item @emph{Reference}: 
1418 @uref{http://www.openmp.org/, OpenMP specification v4.0}, Section 4.9
1419 @end table
1423 @node OMP_NESTED
1424 @section @env{OMP_NESTED} -- Nested parallel regions
1425 @cindex Environment Variable
1426 @cindex Implementation specific setting
1427 @table @asis
1428 @item @emph{Description}:
1429 Enable or disable nested parallel regions, i.e., whether team members
1430 are allowed to create new teams.  The value of this environment variable 
1431 shall be @code{TRUE} or @code{FALSE}.  If undefined, nested parallel 
1432 regions are disabled by default.
1434 @item @emph{See also}:
1435 @ref{omp_set_nested}
1437 @item @emph{Reference}: 
1438 @uref{http://www.openmp.org/, OpenMP specification v4.0}, Section 4.6
1439 @end table
1443 @node OMP_NUM_THREADS
1444 @section @env{OMP_NUM_THREADS} -- Specifies the number of threads to use
1445 @cindex Environment Variable
1446 @cindex Implementation specific setting
1447 @table @asis
1448 @item @emph{Description}:
1449 Specifies the default number of threads to use in parallel regions.  The 
1450 value of this variable shall be a comma-separated list of positive integers;
1451 the value specified the number of threads to use for the corresponding nested
1452 level.  If undefined one thread per CPU is used.
1454 @item @emph{See also}:
1455 @ref{omp_set_num_threads}
1457 @item @emph{Reference}: 
1458 @uref{http://www.openmp.org/, OpenMP specification v4.0}, Section 4.2
1459 @end table
1463 @node OMP_PROC_BIND
1464 @section @env{OMP_PROC_BIND} -- Whether theads may be moved between CPUs
1465 @cindex Environment Variable
1466 @table @asis
1467 @item @emph{Description}:
1468 Specifies whether threads may be moved between processors.  If set to
1469 @code{TRUE}, OpenMP theads should not be moved; if set to @code{FALSE}
1470 they may be moved.  Alternatively, a comma separated list with the
1471 values @code{MASTER}, @code{CLOSE} and @code{SPREAD} can be used to specify
1472 the thread affinity policy for the corresponding nesting level.  With
1473 @code{MASTER} the worker threads are in the same place partition as the
1474 master thread.  With @code{CLOSE} those are kept close to the master thread
1475 in contiguous place partitions.  And with @code{SPREAD} a sparse distribution
1476 across the place partitions is used.
1478 When undefined, @env{OMP_PROC_BIND} defaults to @code{TRUE} when
1479 @env{OMP_PLACES} or @env{GOMP_CPU_AFFINITY} is set and @code{FALSE} otherwise.
1481 @item @emph{See also}:
1482 @ref{OMP_PLACES}, @ref{GOMP_CPU_AFFINITY}, @ref{omp_get_proc_bind}
1484 @item @emph{Reference}:
1485 @uref{http://www.openmp.org/, OpenMP specification v4.0}, Section 4.4
1486 @end table
1490 @node OMP_PLACES
1491 @section @env{OMP_PLACES} -- Specifies on which CPUs the theads should be placed
1492 @cindex Environment Variable
1493 @table @asis
1494 @item @emph{Description}:
1495 The thread placement can be either specified using an abstract name or by an
1496 explicit list of the places.  The abstract names @code{threads}, @code{cores}
1497 and @code{sockets} can be optionally followed by a positive number in
1498 parentheses, which denotes the how many places shall be created.  With
1499 @code{threads} each place corresponds to a single hardware thread; @code{cores}
1500 to a single core with the corresponding number of hardware threads; and with
1501 @code{sockets} the place corresponds to a single socket.  The resulting
1502 placement can be shown by setting the @env{OMP_DISPLAY_ENV} environment
1503 variable.
1505 Alternatively, the placement can be specified explicitly as comma-separated
1506 list of places.  A place is specified by set of nonnegative numbers in curly
1507 braces, denoting the denoting the hardware threads.  The hardware threads
1508 belonging to a place can either be specified as comma-separated list of
1509 nonnegative thread numbers or using an interval.  Multiple places can also be
1510 either specified by a comma-separated list of places or by an interval.  To
1511 specify an interval, a colon followed by the count is placed after after
1512 the hardware thread number or the place.  Optionally, the length can be
1513 followed by a colon and the stride number -- otherwise a unit stride is
1514 assumed.  For instance, the following specifies the same places list:
1515 @code{"@{0,1,2@}, @{3,4,6@}, @{7,8,9@}, @{10,11,12@}"};
1516 @code{"@{0:3@}, @{3:3@}, @{7:3@}, @{10:3@}"}; and @code{"@{0:2@}:4:3"}.
1518 If @env{OMP_PLACES} and @env{GOMP_CPU_AFFINITY} are unset and
1519 @env{OMP_PROC_BIND} is either unset or @code{false}, threads may be moved
1520 between CPUs following no placement policy.
1522 @item @emph{See also}:
1523 @ref{OMP_PROC_BIND}, @ref{GOMP_CPU_AFFINITY}, @ref{omp_get_proc_bind},
1524 @ref{OMP_DISPLAY_ENV}
1526 @item @emph{Reference}:
1527 @uref{http://www.openmp.org/, OpenMP specification v4.0}, Section 4.5
1528 @end table
1532 @node OMP_STACKSIZE
1533 @section @env{OMP_STACKSIZE} -- Set default thread stack size
1534 @cindex Environment Variable
1535 @table @asis
1536 @item @emph{Description}:
1537 Set the default thread stack size in kilobytes, unless the number
1538 is suffixed by @code{B}, @code{K}, @code{M} or @code{G}, in which
1539 case the size is, respectively, in bytes, kilobytes, megabytes
1540 or gigabytes.  This is different from @code{pthread_attr_setstacksize}
1541 which gets the number of bytes as an argument.  If the stack size cannot
1542 be set due to system constraints, an error is reported and the initial
1543 stack size is left unchanged.  If undefined, the stack size is system
1544 dependent.
1546 @item @emph{Reference}: 
1547 @uref{http://www.openmp.org/, OpenMP specification v4.0}, Section 4.7
1548 @end table
1552 @node OMP_SCHEDULE
1553 @section @env{OMP_SCHEDULE} -- How threads are scheduled
1554 @cindex Environment Variable
1555 @cindex Implementation specific setting
1556 @table @asis
1557 @item @emph{Description}:
1558 Allows to specify @code{schedule type} and @code{chunk size}. 
1559 The value of the variable shall have the form: @code{type[,chunk]} where
1560 @code{type} is one of @code{static}, @code{dynamic}, @code{guided} or @code{auto}
1561 The optional @code{chunk} size shall be a positive integer.  If undefined,
1562 dynamic scheduling and a chunk size of 1 is used.
1564 @item @emph{See also}:
1565 @ref{omp_set_schedule}
1567 @item @emph{Reference}: 
1568 @uref{http://www.openmp.org/, OpenMP specification v4.0}, Sections 2.7.1 and 4.1
1569 @end table
1573 @node OMP_THREAD_LIMIT
1574 @section @env{OMP_THREAD_LIMIT} -- Set the maximum number of threads
1575 @cindex Environment Variable
1576 @table @asis
1577 @item @emph{Description}:
1578 Specifies the number of threads to use for the whole program.  The
1579 value of this variable shall be a positive integer.  If undefined,
1580 the number of threads is not limited.
1582 @item @emph{See also}:
1583 @ref{OMP_NUM_THREADS}, @ref{omp_get_thread_limit}
1585 @item @emph{Reference}: 
1586 @uref{http://www.openmp.org/, OpenMP specification v4.0}, Section 4.10
1587 @end table
1591 @node OMP_WAIT_POLICY
1592 @section @env{OMP_WAIT_POLICY} -- How waiting threads are handled
1593 @cindex Environment Variable
1594 @table @asis
1595 @item @emph{Description}:
1596 Specifies whether waiting threads should be active or passive.  If
1597 the value is @code{PASSIVE}, waiting threads should not consume CPU
1598 power while waiting; while the value is @code{ACTIVE} specifies that
1599 they should.  If undefined, threads wait actively for a short time
1600 before waiting passively.
1602 @item @emph{See also}:
1603 @ref{GOMP_SPINCOUNT}
1605 @item @emph{Reference}: 
1606 @uref{http://www.openmp.org/, OpenMP specification v4.0}, Section 4.8
1607 @end table
1611 @node GOMP_CPU_AFFINITY
1612 @section @env{GOMP_CPU_AFFINITY} -- Bind threads to specific CPUs
1613 @cindex Environment Variable
1614 @table @asis
1615 @item @emph{Description}:
1616 Binds threads to specific CPUs.  The variable should contain a space-separated
1617 or comma-separated list of CPUs.  This list may contain different kinds of 
1618 entries: either single CPU numbers in any order, a range of CPUs (M-N) 
1619 or a range with some stride (M-N:S).  CPU numbers are zero based.  For example,
1620 @code{GOMP_CPU_AFFINITY="0 3 1-2 4-15:2"} will bind the initial thread
1621 to CPU 0, the second to CPU 3, the third to CPU 1, the fourth to 
1622 CPU 2, the fifth to CPU 4, the sixth through tenth to CPUs 6, 8, 10, 12,
1623 and 14 respectively and then start assigning back from the beginning of
1624 the list.  @code{GOMP_CPU_AFFINITY=0} binds all threads to CPU 0.
1626 There is no libgomp library routine to determine whether a CPU affinity
1627 specification is in effect.  As a workaround, language-specific library 
1628 functions, e.g., @code{getenv} in C or @code{GET_ENVIRONMENT_VARIABLE} in 
1629 Fortran, may be used to query the setting of the @code{GOMP_CPU_AFFINITY} 
1630 environment variable.  A defined CPU affinity on startup cannot be changed 
1631 or disabled during the runtime of the application.
1633 If both @env{GOMP_CPU_AFFINITY} and @env{OMP_PROC_BIND} are set,
1634 @env{OMP_PROC_BIND} has a higher precedence.  If neither has been set and
1635 @env{OMP_PROC_BIND} is unset, or when @env{OMP_PROC_BIND} is set to
1636 @code{FALSE}, the host system will handle the assignment of threads to CPUs.
1638 @item @emph{See also}:
1639 @ref{OMP_PLACES}, @ref{OMP_PROC_BIND}
1640 @end table
1644 @node GOMP_DEBUG
1645 @section @env{GOMP_DEBUG} -- Enable debugging output
1646 @cindex Environment Variable
1647 @table @asis
1648 @item @emph{Description}:
1649 Enable debugging output.  The variable should be set to @code{0}
1650 (disabled, also the default if not set), or @code{1} (enabled).
1652 If enabled, some debugging output will be printed during execution.
1653 This is currently not specified in more detail, and subject to change.
1654 @end table
1658 @node GOMP_STACKSIZE
1659 @section @env{GOMP_STACKSIZE} -- Set default thread stack size
1660 @cindex Environment Variable
1661 @cindex Implementation specific setting
1662 @table @asis
1663 @item @emph{Description}:
1664 Set the default thread stack size in kilobytes.  This is different from
1665 @code{pthread_attr_setstacksize} which gets the number of bytes as an 
1666 argument.  If the stack size cannot be set due to system constraints, an 
1667 error is reported and the initial stack size is left unchanged.  If undefined,
1668 the stack size is system dependent.
1670 @item @emph{See also}:
1671 @ref{OMP_STACKSIZE}
1673 @item @emph{Reference}: 
1674 @uref{http://gcc.gnu.org/ml/gcc-patches/2006-06/msg00493.html, 
1675 GCC Patches Mailinglist}, 
1676 @uref{http://gcc.gnu.org/ml/gcc-patches/2006-06/msg00496.html,
1677 GCC Patches Mailinglist}
1678 @end table
1682 @node GOMP_SPINCOUNT
1683 @section @env{GOMP_SPINCOUNT} -- Set the busy-wait spin count
1684 @cindex Environment Variable
1685 @cindex Implementation specific setting
1686 @table @asis
1687 @item @emph{Description}:
1688 Determines how long a threads waits actively with consuming CPU power
1689 before waiting passively without consuming CPU power.  The value may be
1690 either @code{INFINITE}, @code{INFINITY} to always wait actively or an
1691 integer which gives the number of spins of the busy-wait loop.  The
1692 integer may optionally be followed by the following suffixes acting
1693 as multiplication factors: @code{k} (kilo, thousand), @code{M} (mega,
1694 million), @code{G} (giga, billion), or @code{T} (tera, trillion).
1695 If undefined, 0 is used when @env{OMP_WAIT_POLICY} is @code{PASSIVE},
1696 300,000 is used when @env{OMP_WAIT_POLICY} is undefined and
1697 30 billion is used when @env{OMP_WAIT_POLICY} is @code{ACTIVE}.
1698 If there are more OpenMP threads than available CPUs, 1000 and 100
1699 spins are used for @env{OMP_WAIT_POLICY} being @code{ACTIVE} or
1700 undefined, respectively; unless the @env{GOMP_SPINCOUNT} is lower
1701 or @env{OMP_WAIT_POLICY} is @code{PASSIVE}.
1703 @item @emph{See also}:
1704 @ref{OMP_WAIT_POLICY}
1705 @end table
1709 @node GOMP_RTEMS_THREAD_POOLS
1710 @section @env{GOMP_RTEMS_THREAD_POOLS} -- Set the RTEMS specific thread pools
1711 @cindex Environment Variable
1712 @cindex Implementation specific setting
1713 @table @asis
1714 @item @emph{Description}:
1715 This environment variable is only used on the RTEMS real-time operating system.
1716 It determines the scheduler instance specific thread pools.  The format for
1717 @env{GOMP_RTEMS_THREAD_POOLS} is a list of optional
1718 @code{<thread-pool-count>[$<priority>]@@<scheduler-name>} configurations
1719 separated by @code{:} where:
1720 @itemize @bullet
1721 @item @code{<thread-pool-count>} is the thread pool count for this scheduler
1722 instance.
1723 @item @code{$<priority>} is an optional priority for the worker threads of a
1724 thread pool according to @code{pthread_setschedparam}.  In case a priority
1725 value is omitted, then a worker thread will inherit the priority of the OpenMP
1726 master thread that created it.  The priority of the worker thread is not
1727 changed after creation, even if a new OpenMP master thread using the worker has
1728 a different priority.
1729 @item @code{@@<scheduler-name>} is the scheduler instance name according to the
1730 RTEMS application configuration.
1731 @end itemize
1732 In case no thread pool configuration is specified for a scheduler instance,
1733 then each OpenMP master thread of this scheduler instance will use its own
1734 dynamically allocated thread pool.  To limit the worker thread count of the
1735 thread pools, each OpenMP master thread must call @code{omp_set_num_threads}.
1736 @item @emph{Example}:
1737 Lets suppose we have three scheduler instances @code{IO}, @code{WRK0}, and
1738 @code{WRK1} with @env{GOMP_RTEMS_THREAD_POOLS} set to
1739 @code{"1@@WRK0:3$4@@WRK1"}.  Then there are no thread pool restrictions for
1740 scheduler instance @code{IO}.  In the scheduler instance @code{WRK0} there is
1741 one thread pool available.  Since no priority is specified for this scheduler
1742 instance, the worker thread inherits the priority of the OpenMP master thread
1743 that created it.  In the scheduler instance @code{WRK1} there are three thread
1744 pools available and their worker threads run at priority four.
1745 @end table
1749 @c ---------------------------------------------------------------------
1750 @c The libgomp ABI
1751 @c ---------------------------------------------------------------------
1753 @node The libgomp ABI
1754 @chapter The libgomp ABI
1756 The following sections present notes on the external ABI as 
1757 presented by libgomp.  Only maintainers should need them.
1759 @menu
1760 * Implementing MASTER construct::
1761 * Implementing CRITICAL construct::
1762 * Implementing ATOMIC construct::
1763 * Implementing FLUSH construct::
1764 * Implementing BARRIER construct::
1765 * Implementing THREADPRIVATE construct::
1766 * Implementing PRIVATE clause::
1767 * Implementing FIRSTPRIVATE LASTPRIVATE COPYIN and COPYPRIVATE clauses::
1768 * Implementing REDUCTION clause::
1769 * Implementing PARALLEL construct::
1770 * Implementing FOR construct::
1771 * Implementing ORDERED construct::
1772 * Implementing SECTIONS construct::
1773 * Implementing SINGLE construct::
1774 @end menu
1777 @node Implementing MASTER construct
1778 @section Implementing MASTER construct
1780 @smallexample
1781 if (omp_get_thread_num () == 0)
1782   block
1783 @end smallexample
1785 Alternately, we generate two copies of the parallel subfunction
1786 and only include this in the version run by the master thread.
1787 Surely this is not worthwhile though...
1791 @node Implementing CRITICAL construct
1792 @section Implementing CRITICAL construct
1794 Without a specified name,
1796 @smallexample
1797   void GOMP_critical_start (void);
1798   void GOMP_critical_end (void);
1799 @end smallexample
1801 so that we don't get COPY relocations from libgomp to the main
1802 application.
1804 With a specified name, use omp_set_lock and omp_unset_lock with
1805 name being transformed into a variable declared like
1807 @smallexample
1808   omp_lock_t gomp_critical_user_<name> __attribute__((common))
1809 @end smallexample
1811 Ideally the ABI would specify that all zero is a valid unlocked
1812 state, and so we wouldn't need to initialize this at
1813 startup.
1817 @node Implementing ATOMIC construct
1818 @section Implementing ATOMIC construct
1820 The target should implement the @code{__sync} builtins.
1822 Failing that we could add
1824 @smallexample
1825   void GOMP_atomic_enter (void)
1826   void GOMP_atomic_exit (void)
1827 @end smallexample
1829 which reuses the regular lock code, but with yet another lock
1830 object private to the library.
1834 @node Implementing FLUSH construct
1835 @section Implementing FLUSH construct
1837 Expands to the @code{__sync_synchronize} builtin.
1841 @node Implementing BARRIER construct
1842 @section Implementing BARRIER construct
1844 @smallexample
1845   void GOMP_barrier (void)
1846 @end smallexample
1849 @node Implementing THREADPRIVATE construct
1850 @section Implementing THREADPRIVATE construct
1852 In _most_ cases we can map this directly to @code{__thread}.  Except
1853 that OMP allows constructors for C++ objects.  We can either
1854 refuse to support this (how often is it used?) or we can 
1855 implement something akin to .ctors.
1857 Even more ideally, this ctor feature is handled by extensions
1858 to the main pthreads library.  Failing that, we can have a set
1859 of entry points to register ctor functions to be called.
1863 @node Implementing PRIVATE clause
1864 @section Implementing PRIVATE clause
1866 In association with a PARALLEL, or within the lexical extent
1867 of a PARALLEL block, the variable becomes a local variable in
1868 the parallel subfunction.
1870 In association with FOR or SECTIONS blocks, create a new
1871 automatic variable within the current function.  This preserves
1872 the semantic of new variable creation.
1876 @node Implementing FIRSTPRIVATE LASTPRIVATE COPYIN and COPYPRIVATE clauses
1877 @section Implementing FIRSTPRIVATE LASTPRIVATE COPYIN and COPYPRIVATE clauses
1879 This seems simple enough for PARALLEL blocks.  Create a private 
1880 struct for communicating between the parent and subfunction.
1881 In the parent, copy in values for scalar and "small" structs;
1882 copy in addresses for others TREE_ADDRESSABLE types.  In the 
1883 subfunction, copy the value into the local variable.
1885 It is not clear what to do with bare FOR or SECTION blocks.
1886 The only thing I can figure is that we do something like:
1888 @smallexample
1889 #pragma omp for firstprivate(x) lastprivate(y)
1890 for (int i = 0; i < n; ++i)
1891   body;
1892 @end smallexample
1894 which becomes
1896 @smallexample
1898   int x = x, y;
1900   // for stuff
1902   if (i == n)
1903     y = y;
1905 @end smallexample
1907 where the "x=x" and "y=y" assignments actually have different
1908 uids for the two variables, i.e. not something you could write
1909 directly in C.  Presumably this only makes sense if the "outer"
1910 x and y are global variables.
1912 COPYPRIVATE would work the same way, except the structure 
1913 broadcast would have to happen via SINGLE machinery instead.
1917 @node Implementing REDUCTION clause
1918 @section Implementing REDUCTION clause
1920 The private struct mentioned in the previous section should have 
1921 a pointer to an array of the type of the variable, indexed by the 
1922 thread's @var{team_id}.  The thread stores its final value into the 
1923 array, and after the barrier, the master thread iterates over the
1924 array to collect the values.
1927 @node Implementing PARALLEL construct
1928 @section Implementing PARALLEL construct
1930 @smallexample
1931   #pragma omp parallel
1932   @{
1933     body;
1934   @}
1935 @end smallexample
1937 becomes
1939 @smallexample
1940   void subfunction (void *data)
1941   @{
1942     use data;
1943     body;
1944   @}
1946   setup data;
1947   GOMP_parallel_start (subfunction, &data, num_threads);
1948   subfunction (&data);
1949   GOMP_parallel_end ();
1950 @end smallexample
1952 @smallexample
1953   void GOMP_parallel_start (void (*fn)(void *), void *data, unsigned num_threads)
1954 @end smallexample
1956 The @var{FN} argument is the subfunction to be run in parallel.
1958 The @var{DATA} argument is a pointer to a structure used to 
1959 communicate data in and out of the subfunction, as discussed
1960 above with respect to FIRSTPRIVATE et al.
1962 The @var{NUM_THREADS} argument is 1 if an IF clause is present
1963 and false, or the value of the NUM_THREADS clause, if
1964 present, or 0.
1966 The function needs to create the appropriate number of
1967 threads and/or launch them from the dock.  It needs to
1968 create the team structure and assign team ids.
1970 @smallexample
1971   void GOMP_parallel_end (void)
1972 @end smallexample
1974 Tears down the team and returns us to the previous @code{omp_in_parallel()} state.
1978 @node Implementing FOR construct
1979 @section Implementing FOR construct
1981 @smallexample
1982   #pragma omp parallel for
1983   for (i = lb; i <= ub; i++)
1984     body;
1985 @end smallexample
1987 becomes
1989 @smallexample
1990   void subfunction (void *data)
1991   @{
1992     long _s0, _e0;
1993     while (GOMP_loop_static_next (&_s0, &_e0))
1994     @{
1995       long _e1 = _e0, i;
1996       for (i = _s0; i < _e1; i++)
1997         body;
1998     @}
1999     GOMP_loop_end_nowait ();
2000   @}
2002   GOMP_parallel_loop_static (subfunction, NULL, 0, lb, ub+1, 1, 0);
2003   subfunction (NULL);
2004   GOMP_parallel_end ();
2005 @end smallexample
2007 @smallexample
2008   #pragma omp for schedule(runtime)
2009   for (i = 0; i < n; i++)
2010     body;
2011 @end smallexample
2013 becomes
2015 @smallexample
2016   @{
2017     long i, _s0, _e0;
2018     if (GOMP_loop_runtime_start (0, n, 1, &_s0, &_e0))
2019       do @{
2020         long _e1 = _e0;
2021         for (i = _s0, i < _e0; i++)
2022           body;
2023       @} while (GOMP_loop_runtime_next (&_s0, _&e0));
2024     GOMP_loop_end ();
2025   @}
2026 @end smallexample
2028 Note that while it looks like there is trickiness to propagating
2029 a non-constant STEP, there isn't really.  We're explicitly allowed
2030 to evaluate it as many times as we want, and any variables involved
2031 should automatically be handled as PRIVATE or SHARED like any other
2032 variables.  So the expression should remain evaluable in the 
2033 subfunction.  We can also pull it into a local variable if we like,
2034 but since its supposed to remain unchanged, we can also not if we like.
2036 If we have SCHEDULE(STATIC), and no ORDERED, then we ought to be
2037 able to get away with no work-sharing context at all, since we can
2038 simply perform the arithmetic directly in each thread to divide up
2039 the iterations.  Which would mean that we wouldn't need to call any
2040 of these routines.
2042 There are separate routines for handling loops with an ORDERED
2043 clause.  Bookkeeping for that is non-trivial...
2047 @node Implementing ORDERED construct
2048 @section Implementing ORDERED construct
2050 @smallexample
2051   void GOMP_ordered_start (void)
2052   void GOMP_ordered_end (void)
2053 @end smallexample
2057 @node Implementing SECTIONS construct
2058 @section Implementing SECTIONS construct
2060 A block as 
2062 @smallexample
2063   #pragma omp sections
2064   @{
2065     #pragma omp section
2066     stmt1;
2067     #pragma omp section
2068     stmt2;
2069     #pragma omp section
2070     stmt3;
2071   @}
2072 @end smallexample
2074 becomes
2076 @smallexample
2077   for (i = GOMP_sections_start (3); i != 0; i = GOMP_sections_next ())
2078     switch (i)
2079       @{
2080       case 1:
2081         stmt1;
2082         break;
2083       case 2:
2084         stmt2;
2085         break;
2086       case 3:
2087         stmt3;
2088         break;
2089       @}
2090   GOMP_barrier ();
2091 @end smallexample
2094 @node Implementing SINGLE construct
2095 @section Implementing SINGLE construct
2097 A block like 
2099 @smallexample
2100   #pragma omp single
2101   @{
2102     body;
2103   @}
2104 @end smallexample
2106 becomes
2108 @smallexample
2109   if (GOMP_single_start ())
2110     body;
2111   GOMP_barrier ();
2112 @end smallexample
2114 while 
2116 @smallexample
2117   #pragma omp single copyprivate(x)
2118     body;
2119 @end smallexample
2121 becomes
2123 @smallexample
2124   datap = GOMP_single_copy_start ();
2125   if (datap == NULL)
2126     @{
2127       body;
2128       data.x = x;
2129       GOMP_single_copy_end (&data);
2130     @}
2131   else
2132     x = datap->x;
2133   GOMP_barrier ();
2134 @end smallexample
2138 @c ---------------------------------------------------------------------
2139 @c Reporting Bugs
2140 @c ---------------------------------------------------------------------
2142 @node Reporting Bugs
2143 @chapter Reporting Bugs
2145 Bugs in the GNU Offloading and Multi Processing Runtime Library should
2146 be reported via @uref{http://gcc.gnu.org/bugzilla/, Bugzilla}.  Please add
2147 "openacc", or "openmp", or both to the keywords field in the bug
2148 report, as appropriate.
2152 @c ---------------------------------------------------------------------
2153 @c GNU General Public License
2154 @c ---------------------------------------------------------------------
2156 @include gpl_v3.texi
2160 @c ---------------------------------------------------------------------
2161 @c GNU Free Documentation License
2162 @c ---------------------------------------------------------------------
2164 @include fdl.texi
2168 @c ---------------------------------------------------------------------
2169 @c Funding Free Software
2170 @c ---------------------------------------------------------------------
2172 @include funding.texi
2174 @c ---------------------------------------------------------------------
2175 @c Index
2176 @c ---------------------------------------------------------------------
2178 @node Library Index
2179 @unnumbered Library Index
2181 @printindex cp
2183 @bye