1 \input texinfo @c -*-texinfo-*-
4 @setfilename libgomp.info
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:
24 (b) The FSF's Back-Cover Text is:
26 You have freedom to copy and modify this GNU Manual, like GNU
27 software. Copies published by the Free Software Foundation raise
28 funds for GNU development.
32 @dircategory GNU Libraries
34 * libgomp: (libgomp). GNU Offloading and Multi Processing Runtime Library.
37 This manual documents libgomp, the GNU Offloading and Multi Processing
38 Runtime library. This is the GNU implementation of the OpenMP and
39 OpenACC APIs for parallel and accelerator programming in C/C++ and
42 Published by the Free Software Foundation
43 51 Franklin Street, Fifth Floor
44 Boston, MA 02110-1301 USA
50 @setchapternewpage odd
53 @title GNU Offloading and Multi Processing Runtime Library
54 @subtitle The GNU OpenMP and OpenACC Implementation
56 @vskip 0pt plus 1filll
57 @comment For the @value{version-GCC} Version*
59 Published by the Free Software Foundation @*
60 51 Franklin Street, Fifth Floor@*
61 Boston, MA 02110-1301, USA@*
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++
84 Originally, libgomp implemented the GNU OpenMP Runtime Library. Based
85 on this, support for OpenACC and offloading (both OpenACC and OpenMP
86 4's target construct) has been added later on, and the library's name
87 changed to GNU Offloading and Multi Processing Runtime Library.
92 @comment When you add a new menu item, please keep the right hand
93 @comment aligned to the same column. Do not use tabs. This provides
94 @comment better formatting.
97 * Enabling OpenMP:: How to enable OpenMP for your applications.
98 * Runtime Library Routines:: The OpenMP runtime application programming
100 * Environment Variables:: Influencing runtime behavior with environment
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
111 * Library Index:: Index of this documentation.
115 @c ---------------------------------------------------------------------
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,
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
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.
201 @node omp_get_active_level
202 @section @code{omp_get_active_level} -- Number of parallel regions
204 @item @emph{Description}:
205 This function returns the nesting level for the active parallel blocks,
206 which enclose the calling call.
209 @multitable @columnfractions .20 .80
210 @item @emph{Prototype}: @tab @code{int omp_get_active_level(void);}
213 @item @emph{Fortran}:
214 @multitable @columnfractions .20 .80
215 @item @emph{Interface}: @tab @code{integer function omp_get_active_level()}
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.
227 @node omp_get_ancestor_thread_num
228 @section @code{omp_get_ancestor_thread_num} -- Ancestor thread ID
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}.
237 @multitable @columnfractions .20 .80
238 @item @emph{Prototype}: @tab @code{int omp_get_ancestor_thread_num(int level);}
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}
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.
256 @node omp_get_cancellation
257 @section @code{omp_get_cancellation} -- Whether cancellation support is enabled
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
266 @multitable @columnfractions .20 .80
267 @item @emph{Prototype}: @tab @code{int omp_get_cancellation(void);}
270 @item @emph{Fortran}:
271 @multitable @columnfractions .20 .80
272 @item @emph{Interface}: @tab @code{logical function omp_get_cancellation()}
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.
284 @node omp_get_default_device
285 @section @code{omp_get_default_device} -- Get the default device for target regions
287 @item @emph{Description}:
288 Get the default device for target regions without device clause.
291 @multitable @columnfractions .20 .80
292 @item @emph{Prototype}: @tab @code{int omp_get_default_device(void);}
295 @item @emph{Fortran}:
296 @multitable @columnfractions .20 .80
297 @item @emph{Interface}: @tab @code{integer function omp_get_default_device()}
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.
309 @node omp_get_dynamic
310 @section @code{omp_get_dynamic} -- Dynamic teams setting
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
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
323 @multitable @columnfractions .20 .80
324 @item @emph{Prototype}: @tab @code{int omp_get_dynamic(void);}
327 @item @emph{Fortran}:
328 @multitable @columnfractions .20 .80
329 @item @emph{Interface}: @tab @code{logical function omp_get_dynamic()}
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.
342 @section @code{omp_get_level} -- Obtain the current nesting level
344 @item @emph{Description}:
345 This function returns the nesting level for the parallel blocks,
346 which enclose the calling call.
349 @multitable @columnfractions .20 .80
350 @item @emph{Prototype}: @tab @code{int omp_get_level(void);}
353 @item @emph{Fortran}:
354 @multitable @columnfractions .20 .80
355 @item @emph{Interface}: @tab @code{integer function omp_level()}
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.
367 @node omp_get_max_active_levels
368 @section @code{omp_get_max_active_levels} -- Maximum number of active regions
370 @item @emph{Description}:
371 This function obtains the maximum allowed number of nested, active parallel regions.
374 @multitable @columnfractions .20 .80
375 @item @emph{Prototype}: @tab @code{int omp_get_max_active_levels(void);}
378 @item @emph{Fortran}:
379 @multitable @columnfractions .20 .80
380 @item @emph{Interface}: @tab @code{integer function omp_get_max_active_levels()}
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.
392 @node omp_get_max_threads
393 @section @code{omp_get_max_threads} -- Maximum number of threads of parallel region
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}.
400 @multitable @columnfractions .20 .80
401 @item @emph{Prototype}: @tab @code{int omp_get_max_threads(void);}
404 @item @emph{Fortran}:
405 @multitable @columnfractions .20 .80
406 @item @emph{Interface}: @tab @code{integer function omp_get_max_threads()}
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.
419 @section @code{omp_get_nested} -- Nested parallel regions
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
432 @multitable @columnfractions .20 .80
433 @item @emph{Prototype}: @tab @code{int omp_get_nested(void);}
436 @item @emph{Fortran}:
437 @multitable @columnfractions .20 .80
438 @item @emph{Interface}: @tab @code{logical function omp_get_nested()}
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.
450 @node omp_get_num_devices
451 @section @code{omp_get_num_devices} -- Number of target devices
453 @item @emph{Description}:
454 Returns the number of target devices.
457 @multitable @columnfractions .20 .80
458 @item @emph{Prototype}: @tab @code{int omp_get_num_devices(void);}
461 @item @emph{Fortran}:
462 @multitable @columnfractions .20 .80
463 @item @emph{Interface}: @tab @code{integer function omp_get_num_devices()}
466 @item @emph{Reference}:
467 @uref{http://www.openmp.org/, OpenMP specification v4.0}, Section 3.2.25.
472 @node omp_get_num_procs
473 @section @code{omp_get_num_procs} -- Number of processors online
475 @item @emph{Description}:
476 Returns the number of processors online on that device.
479 @multitable @columnfractions .20 .80
480 @item @emph{Prototype}: @tab @code{int omp_get_num_procs(void);}
483 @item @emph{Fortran}:
484 @multitable @columnfractions .20 .80
485 @item @emph{Interface}: @tab @code{integer function omp_get_num_procs()}
488 @item @emph{Reference}:
489 @uref{http://www.openmp.org/, OpenMP specification v4.0}, Section 3.2.5.
494 @node omp_get_num_teams
495 @section @code{omp_get_num_teams} -- Number of teams
497 @item @emph{Description}:
498 Returns the number of teams in the current team region.
501 @multitable @columnfractions .20 .80
502 @item @emph{Prototype}: @tab @code{int omp_get_num_teams(void);}
505 @item @emph{Fortran}:
506 @multitable @columnfractions .20 .80
507 @item @emph{Interface}: @tab @code{integer function omp_get_num_teams()}
510 @item @emph{Reference}:
511 @uref{http://www.openmp.org/, OpenMP specification v4.0}, Section 3.2.26.
516 @node omp_get_num_threads
517 @section @code{omp_get_num_threads} -- Size of the active team
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.
531 @multitable @columnfractions .20 .80
532 @item @emph{Prototype}: @tab @code{int omp_get_num_threads(void);}
535 @item @emph{Fortran}:
536 @multitable @columnfractions .20 .80
537 @item @emph{Interface}: @tab @code{integer function omp_get_num_threads()}
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.
549 @node omp_get_proc_bind
550 @section @code{omp_get_proc_bind} -- Whether theads may be moved between CPUs
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}.
559 @multitable @columnfractions .20 .80
560 @item @emph{Prototype}: @tab @code{omp_proc_bind_t omp_get_proc_bind(void);}
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()}
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.
577 @node omp_get_schedule
578 @section @code{omp_get_schedule} -- Obtain the runtime scheduling method
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.
587 @multitable @columnfractions .20 .80
588 @item @emph{Prototype}: @tab @code{void omp_get_schedule(omp_sched_t *kind, int *modifier);}
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}
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.
607 @node omp_get_team_num
608 @section @code{omp_get_team_num} -- Get team number
610 @item @emph{Description}:
611 Returns the team number of the calling thread.
614 @multitable @columnfractions .20 .80
615 @item @emph{Prototype}: @tab @code{int omp_get_team_num(void);}
618 @item @emph{Fortran}:
619 @multitable @columnfractions .20 .80
620 @item @emph{Interface}: @tab @code{integer function omp_get_team_num()}
623 @item @emph{Reference}:
624 @uref{http://www.openmp.org/, OpenMP specification v4.0}, Section 3.2.27.
629 @node omp_get_team_size
630 @section @code{omp_get_team_size} -- Number of threads in a team
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}.
640 @multitable @columnfractions .20 .80
641 @item @emph{Prototype}: @tab @code{int omp_get_team_size(int level);}
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}
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.
659 @node omp_get_thread_limit
660 @section @code{omp_get_thread_limit} -- Maximum number of threads
662 @item @emph{Description}:
663 Return the maximum number of threads of the program.
666 @multitable @columnfractions .20 .80
667 @item @emph{Prototype}: @tab @code{int omp_get_thread_limit(void);}
670 @item @emph{Fortran}:
671 @multitable @columnfractions .20 .80
672 @item @emph{Interface}: @tab @code{integer function omp_get_thread_limit()}
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.
684 @node omp_get_thread_num
685 @section @code{omp_get_thread_num} -- Current thread ID
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.
695 @multitable @columnfractions .20 .80
696 @item @emph{Prototype}: @tab @code{int omp_get_thread_num(void);}
699 @item @emph{Fortran}:
700 @multitable @columnfractions .20 .80
701 @item @emph{Interface}: @tab @code{integer function omp_get_thread_num()}
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.
713 @node omp_in_parallel
714 @section @code{omp_in_parallel} -- Whether a parallel region is active
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.
722 @multitable @columnfractions .20 .80
723 @item @emph{Prototype}: @tab @code{int omp_in_parallel(void);}
726 @item @emph{Fortran}:
727 @multitable @columnfractions .20 .80
728 @item @emph{Interface}: @tab @code{logical function omp_in_parallel()}
731 @item @emph{Reference}:
732 @uref{http://www.openmp.org/, OpenMP specification v4.0}, Section 3.2.6.
737 @section @code{omp_in_final} -- Whether in final or included task region
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.
745 @multitable @columnfractions .20 .80
746 @item @emph{Prototype}: @tab @code{int omp_in_final(void);}
749 @item @emph{Fortran}:
750 @multitable @columnfractions .20 .80
751 @item @emph{Interface}: @tab @code{logical function omp_in_final()}
754 @item @emph{Reference}:
755 @uref{http://www.openmp.org/, OpenMP specification v4.0}, Section 3.2.21.
760 @node omp_is_initial_device
761 @section @code{omp_is_initial_device} -- Whether executing on the host device
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.
769 @multitable @columnfractions .20 .80
770 @item @emph{Prototype}: @tab @code{int omp_is_initial_device(void);}
773 @item @emph{Fortran}:
774 @multitable @columnfractions .20 .80
775 @item @emph{Interface}: @tab @code{logical function omp_is_initial_device()}
778 @item @emph{Reference}:
779 @uref{http://www.openmp.org/, OpenMP specification v4.0}, Section 3.2.28.
784 @node omp_set_default_device
785 @section @code{omp_set_default_device} -- Set the default device for target regions
787 @item @emph{Description}:
788 Set the default device for target regions without device clause. The argument
789 shall be a nonnegative device number.
792 @multitable @columnfractions .20 .80
793 @item @emph{Prototype}: @tab @code{void omp_set_default_device(int device_num);}
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}
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.
811 @node omp_set_dynamic
812 @section @code{omp_set_dynamic} -- Enable/disable dynamic teams
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.
821 @multitable @columnfractions .20 .80
822 @item @emph{Prototype}: @tab @code{void omp_set_dynamic(int dynamic_threads);}
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}
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.
840 @node omp_set_max_active_levels
841 @section @code{omp_set_max_active_levels} -- Limits the number of active parallel regions
843 @item @emph{Description}:
844 This function limits the maximum allowed number of nested, active
848 @multitable @columnfractions .20 .80
849 @item @emph{Prototype}: @tab @code{void omp_set_max_active_levels(int max_levels);}
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}
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.
868 @section @code{omp_set_nested} -- Enable/disable nested parallel regions
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.
877 @multitable @columnfractions .20 .80
878 @item @emph{Prototype}: @tab @code{void omp_set_nested(int nested);}
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}
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.
896 @node omp_set_num_threads
897 @section @code{omp_set_num_threads} -- Set upper team size limit
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.
905 @multitable @columnfractions .20 .80
906 @item @emph{Prototype}: @tab @code{void omp_set_num_threads(int num_threads);}
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}
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.
924 @node omp_set_schedule
925 @section @code{omp_set_schedule} -- Set the runtime scheduling method
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.
936 @multitable @columnfractions .20 .80
937 @item @emph{Prototype}: @tab @code{void omp_set_schedule(omp_sched_t kind, int modifier);}
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}
947 @item @emph{See also}:
948 @ref{omp_get_schedule}
951 @item @emph{Reference}:
952 @uref{http://www.openmp.org/, OpenMP specification v4.0}, Section 3.2.12.
958 @section @code{omp_init_lock} -- Initialize simple lock
960 @item @emph{Description}:
961 Initialize a simple lock. After initialization, the lock is in
965 @multitable @columnfractions .20 .80
966 @item @emph{Prototype}: @tab @code{void omp_init_lock(omp_lock_t *lock);}
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}
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.
985 @section @code{omp_set_lock} -- Wait for and set simple lock
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,
994 @multitable @columnfractions .20 .80
995 @item @emph{Prototype}: @tab @code{void omp_set_lock(omp_lock_t *lock);}
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}
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.
1014 @section @code{omp_test_lock} -- Test and set simple lock if available
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.
1024 @multitable @columnfractions .20 .80
1025 @item @emph{Prototype}: @tab @code{int omp_test_lock(omp_lock_t *lock);}
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}
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.
1043 @node omp_unset_lock
1044 @section @code{omp_unset_lock} -- Unset simple lock
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.
1054 @multitable @columnfractions .20 .80
1055 @item @emph{Prototype}: @tab @code{void omp_unset_lock(omp_lock_t *lock);}
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}
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.
1073 @node omp_destroy_lock
1074 @section @code{omp_destroy_lock} -- Destroy simple lock
1076 @item @emph{Description}:
1077 Destroy a simple lock. In order to be destroyed, a simple lock must be
1078 in the unlocked state.
1081 @multitable @columnfractions .20 .80
1082 @item @emph{Prototype}: @tab @code{void omp_destroy_lock(omp_lock_t *lock);}
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}
1091 @item @emph{See also}:
1094 @item @emph{Reference}:
1095 @uref{http://www.openmp.org/, OpenMP specification v4.0}, Section 3.3.2.
1100 @node omp_init_nest_lock
1101 @section @code{omp_init_nest_lock} -- Initialize nested lock
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.
1108 @multitable @columnfractions .20 .80
1109 @item @emph{Prototype}: @tab @code{void omp_init_nest_lock(omp_nest_lock_t *lock);}
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}
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.
1126 @node omp_set_nest_lock
1127 @section @code{omp_set_nest_lock} -- Wait for and set nested lock
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.
1136 @multitable @columnfractions .20 .80
1137 @item @emph{Prototype}: @tab @code{void omp_set_nest_lock(omp_nest_lock_t *lock);}
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}
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.
1155 @node omp_test_nest_lock
1156 @section @code{omp_test_nest_lock} -- Test and set nested lock if available
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.
1166 @multitable @columnfractions .20 .80
1167 @item @emph{Prototype}: @tab @code{int omp_test_nest_lock(omp_nest_lock_t *lock);}
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}
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.
1186 @node omp_unset_nest_lock
1187 @section @code{omp_unset_nest_lock} -- Unset nested lock
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.
1197 @multitable @columnfractions .20 .80
1198 @item @emph{Prototype}: @tab @code{void omp_unset_nest_lock(omp_nest_lock_t *lock);}
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}
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.
1216 @node omp_destroy_nest_lock
1217 @section @code{omp_destroy_nest_lock} -- Destroy nested lock
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.
1224 @multitable @columnfractions .20 .80
1225 @item @emph{Prototype}: @tab @code{void omp_destroy_nest_lock(omp_nest_lock_t *);}
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}
1234 @item @emph{See also}:
1237 @item @emph{Reference}:
1238 @uref{http://www.openmp.org/, OpenMP specification v4.0}, Section 3.3.2.
1244 @section @code{omp_get_wtick} -- Get timer precision
1246 @item @emph{Description}:
1247 Gets the timer precision, i.e., the number of seconds between two
1248 successive clock ticks.
1251 @multitable @columnfractions .20 .80
1252 @item @emph{Prototype}: @tab @code{double omp_get_wtick(void);}
1255 @item @emph{Fortran}:
1256 @multitable @columnfractions .20 .80
1257 @item @emph{Interface}: @tab @code{double precision function omp_get_wtick()}
1260 @item @emph{See also}:
1263 @item @emph{Reference}:
1264 @uref{http://www.openmp.org/, OpenMP specification v4.0}, Section 3.4.2.
1270 @section @code{omp_get_wtime} -- Elapsed wall clock time
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.
1279 @multitable @columnfractions .20 .80
1280 @item @emph{Prototype}: @tab @code{double omp_get_wtime(void);}
1283 @item @emph{Fortran}:
1284 @multitable @columnfractions .20 .80
1285 @item @emph{Interface}: @tab @code{double precision function omp_get_wtime()}
1288 @item @emph{See also}:
1291 @item @emph{Reference}:
1292 @uref{http://www.openmp.org/, OpenMP specification v4.0}, Section 3.4.1.
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.
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
1330 @node OMP_CANCELLATION
1331 @section @env{OMP_CANCELLATION} -- Set whether cancellation is activated
1332 @cindex Environment Variable
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
1347 @node OMP_DISPLAY_ENV
1348 @section @env{OMP_DISPLAY_ENV} -- Show OpenMP version and environment variables
1349 @cindex Environment Variable
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
1365 @node OMP_DEFAULT_DEVICE
1366 @section @env{OMP_DEFAULT_DEVICE} -- Set the device used in target regions
1367 @cindex Environment Variable
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
1387 @section @env{OMP_DYNAMIC} -- Dynamic adjustment of threads
1388 @cindex Environment Variable
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
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
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
1424 @section @env{OMP_NESTED} -- Nested parallel regions
1425 @cindex Environment Variable
1426 @cindex Implementation specific setting
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
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
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
1464 @section @env{OMP_PROC_BIND} -- Whether theads may be moved between CPUs
1465 @cindex Environment Variable
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
1491 @section @env{OMP_PLACES} -- Specifies on which CPUs the theads should be placed
1492 @cindex Environment Variable
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
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
1533 @section @env{OMP_STACKSIZE} -- Set default thread stack size
1534 @cindex Environment Variable
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
1546 @item @emph{Reference}:
1547 @uref{http://www.openmp.org/, OpenMP specification v4.0}, Section 4.7
1553 @section @env{OMP_SCHEDULE} -- How threads are scheduled
1554 @cindex Environment Variable
1555 @cindex Implementation specific setting
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
1573 @node OMP_THREAD_LIMIT
1574 @section @env{OMP_THREAD_LIMIT} -- Set the maximum number of threads
1575 @cindex Environment Variable
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
1591 @node OMP_WAIT_POLICY
1592 @section @env{OMP_WAIT_POLICY} -- How waiting threads are handled
1593 @cindex Environment Variable
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
1611 @node GOMP_CPU_AFFINITY
1612 @section @env{GOMP_CPU_AFFINITY} -- Bind threads to specific CPUs
1613 @cindex Environment Variable
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}
1645 @section @env{GOMP_DEBUG} -- Enable debugging output
1646 @cindex Environment Variable
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.
1658 @node GOMP_STACKSIZE
1659 @section @env{GOMP_STACKSIZE} -- Set default thread stack size
1660 @cindex Environment Variable
1661 @cindex Implementation specific setting
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}:
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}
1682 @node GOMP_SPINCOUNT
1683 @section @env{GOMP_SPINCOUNT} -- Set the busy-wait spin count
1684 @cindex Environment Variable
1685 @cindex Implementation specific setting
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}
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
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:
1721 @item @code{<thread-pool-count>} is the thread pool count for this scheduler
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.
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.
1749 @c ---------------------------------------------------------------------
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.
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::
1777 @node Implementing MASTER construct
1778 @section Implementing MASTER construct
1781 if (omp_get_thread_num () == 0)
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,
1797 void GOMP_critical_start (void);
1798 void GOMP_critical_end (void);
1801 so that we don't get COPY relocations from libgomp to the main
1804 With a specified name, use omp_set_lock and omp_unset_lock with
1805 name being transformed into a variable declared like
1808 omp_lock_t gomp_critical_user_<name> __attribute__((common))
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
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
1825 void GOMP_atomic_enter (void)
1826 void GOMP_atomic_exit (void)
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
1845 void GOMP_barrier (void)
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:
1889 #pragma omp for firstprivate(x) lastprivate(y)
1890 for (int i = 0; i < n; ++i)
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
1931 #pragma omp parallel
1940 void subfunction (void *data)
1947 GOMP_parallel_start (subfunction, &data, num_threads);
1948 subfunction (&data);
1949 GOMP_parallel_end ();
1953 void GOMP_parallel_start (void (*fn)(void *), void *data, unsigned num_threads)
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
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.
1971 void GOMP_parallel_end (void)
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
1982 #pragma omp parallel for
1983 for (i = lb; i <= ub; i++)
1990 void subfunction (void *data)
1993 while (GOMP_loop_static_next (&_s0, &_e0))
1996 for (i = _s0; i < _e1; i++)
1999 GOMP_loop_end_nowait ();
2002 GOMP_parallel_loop_static (subfunction, NULL, 0, lb, ub+1, 1, 0);
2004 GOMP_parallel_end ();
2008 #pragma omp for schedule(runtime)
2009 for (i = 0; i < n; i++)
2018 if (GOMP_loop_runtime_start (0, n, 1, &_s0, &_e0))
2021 for (i = _s0, i < _e0; i++)
2023 @} while (GOMP_loop_runtime_next (&_s0, _&e0));
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
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
2051 void GOMP_ordered_start (void)
2052 void GOMP_ordered_end (void)
2057 @node Implementing SECTIONS construct
2058 @section Implementing SECTIONS construct
2063 #pragma omp sections
2077 for (i = GOMP_sections_start (3); i != 0; i = GOMP_sections_next ())
2094 @node Implementing SINGLE construct
2095 @section Implementing SINGLE construct
2109 if (GOMP_single_start ())
2117 #pragma omp single copyprivate(x)
2124 datap = GOMP_single_copy_start ();
2129 GOMP_single_copy_end (&data);
2138 @c ---------------------------------------------------------------------
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 ---------------------------------------------------------------------
2168 @c ---------------------------------------------------------------------
2169 @c Funding Free Software
2170 @c ---------------------------------------------------------------------
2172 @include funding.texi
2174 @c ---------------------------------------------------------------------
2176 @c ---------------------------------------------------------------------
2179 @unnumbered Library Index