1 \input texinfo @c -*-texinfo-*-
4 @setfilename libgomp.info
10 Copyright @copyright{} 2006 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.1 or
14 any later version published by the Free Software Foundation; with the
15 Invariant Sections being ``GNU General Public License'' and ``Funding
16 Free Software'', the Front-Cover
17 texts being (a) (see below), and with the Back-Cover Texts being (b)
18 (see below). A copy of the license is included in the section entitled
19 ``GNU Free Documentation License''.
21 (a) The FSF's Front-Cover Text is:
25 (b) The FSF's Back-Cover Text is:
27 You have freedom to copy and modify this GNU Manual, like GNU
28 software. Copies published by the Free Software Foundation raise
29 funds for GNU development.
33 @dircategory GNU Libraries
35 * libgomp: (libgomp). GNU OpenMP runtime library
38 This manual documents the GNU implementation of the OpenMP API for
39 multi-platform shared-memory parallel programming in C/C++ and Fortran.
41 Published by the Free Software Foundation
42 51 Franklin Street, Fifth Floor
43 Boston, MA 02110-1301 USA
49 @setchapternewpage odd
52 @title The GNU OpenMP Implementation
54 @vskip 0pt plus 1filll
55 @comment For the @value{version-GCC} Version*
57 Published by the Free Software Foundation @*
58 51 Franklin Street, Fifth Floor@*
59 Boston, MA 02110-1301, USA@*
73 This manual documents the usage of libgomp, the GNU implementation of the
74 @uref{http://www.openmp.org, OpenMP} Application Programming Interface (API)
75 for multi-platform shared-memory parallel programming in C/C++ and Fortran.
80 @comment When you add a new menu item, please keep the right hand
81 @comment aligned to the same column. Do not use tabs. This provides
82 @comment better formatting.
85 * Enabling OpenMP:: How to enable OpenMP for your applications.
86 * Runtime Library Routines:: The OpenMP runtime application programming
88 * Environment Variables:: Influencing runtime behavior with environment
90 * The libgomp ABI:: Notes on the external ABI presented by libgomp.
91 * Reporting Bugs:: How to report bugs in GNU OpenMP.
92 * Copying:: GNU general public license says
93 how you can copy and share libgomp.
94 * GNU Free Documentation License::
95 How you can copy and share this manual.
96 * Funding:: How to help assure continued work for free
98 * Index:: Index of this documentation.
102 @c ---------------------------------------------------------------------
104 @c ---------------------------------------------------------------------
106 @node Enabling OpenMP
107 @chapter Enabling OpenMP
109 To activate the OpenMP extensions for C/C++ and Fortran, the compile-time
110 flag @command{-fopenmp} must be specified. This enables the OpenMP directive
111 @code{#pragma omp} in C/C++ and @code{!$omp} directives in free form,
112 @code{c$omp}, @code{*$omp} and @code{!$omp} directives in fixed form,
113 @code{!$} conditional compilation sentinels in free form and @code{c$},
114 @code{*$} and @code{!$} sentinels in fixed form, for Fortran. The flag also
115 arranges for automatic linking of the OpenMP runtime library
116 (@ref{Runtime Library Routines}).
118 A complete description of all OpenMP directives accepted may be found in
119 the @uref{http://www.openmp.org, OpenMP Application Program Interface} manual,
123 @c ---------------------------------------------------------------------
124 @c Runtime Library Routines
125 @c ---------------------------------------------------------------------
127 @node Runtime Library Routines
128 @chapter Runtime Library Routines
130 The runtime routines described here are defined by section 3 of the OpenMP
131 specifications in version 2.5.
133 Control threads, processors and the parallel environment.
136 * omp_get_dynamic:: Dynamic teams setting
137 * omp_get_max_threads:: Maximum number of threads
138 * omp_get_nested:: Nested parallel regions
139 * omp_get_num_procs:: Number of processors online
140 * omp_get_num_threads:: Size of the active team
141 * omp_get_thread_num:: Current thread ID
142 * omp_in_parallel:: Whether a parallel region is active
143 * omp_set_dynamic:: Enable/disable dynamic teams
144 * omp_set_nested:: Enable/disable nested parallel regions
145 * omp_set_num_threads:: Set upper team size limit
148 Initialize, set, test, unset and destroy simple and nested locks.
151 * omp_init_lock:: Initialize simple lock
152 * omp_set_lock:: Wait for and set simple lock
153 * omp_test_lock:: Test and set simple lock if available
154 * omp_unset_lock:: Unset simple lock
155 * omp_destroy_lock:: Destroy simple lock
156 * omp_init_nest_lock:: Initialize nested lock
157 * omp_set_nest_lock:: Wait for and set simple lock
158 * omp_test_nest_lock:: Test and set nested lock if available
159 * omp_unset_nest_lock:: Unset nested lock
160 * omp_destroy_nest_lock:: Destroy nested lock
163 Portable, thread-based, wall clock timer.
166 * omp_get_wtick:: Get timer precision.
167 * omp_get_wtime:: Elapsed wall clock time.
170 @node omp_get_dynamic
171 @section @code{omp_get_dynamic} -- Dynamic teams setting
173 @item @emph{Description}:
174 This function returns @code{true} if enabled, @code{false} otherwise.
175 Here, @code{true} and @code{false} represent their language-specific
178 The dynamic team setting may be initialized at startup by the
179 @code{OMP_DYNAMIC} environment variable or at runtime using
180 @code{omp_set_dynamic}. If undefined, dynamic adjustment is
184 @multitable @columnfractions .20 .80
185 @item @emph{Prototype}: @tab @code{int omp_get_dynamic();}
188 @item @emph{Fortran}:
189 @multitable @columnfractions .20 .80
190 @item @emph{Interface}: @tab @code{logical function omp_get_dynamic()}
193 @item @emph{See also}:
194 @ref{omp_set_dynamic}, @ref{OMP_DYNAMIC}
196 @item @emph{Reference}:
197 @uref{http://www.openmp.org/, OpenMP specifications v2.5}, section 3.2.8.
202 @node omp_get_max_threads
203 @section @code{omp_get_max_threads} -- Maximum number of threads
205 @item @emph{Description}:
206 Return the maximum number of threads used for parallel regions that do
207 not use the clause @code{num_threads}.
210 @multitable @columnfractions .20 .80
211 @item @emph{Prototype}: @tab @code{int omp_get_max_threads();}
214 @item @emph{Fortran}:
215 @multitable @columnfractions .20 .80
216 @item @emph{Interface}: @tab @code{integer function omp_get_max_threads()}
219 @item @emph{See also}:
220 @ref{omp_set_num_threads}, @ref{omp_set_dynamic}
222 @item @emph{Reference}:
223 @uref{http://www.openmp.org/, OpenMP specifications v2.5}, section 3.2.3.
229 @section @code{omp_get_nested} -- Nested parallel regions
231 @item @emph{Description}:
232 This function returns @code{true} if nested parallel regions are
233 enabled, @code{false} otherwise. Here, @code{true} and @code{false}
234 represent their language-specific counterparts.
236 Nested parallel regions may be initialized at startup by the
237 @code{OMP_NESTED} environment variable or at runtime using
238 @code{omp_set_nested}. If undefined, nested parallel regions are
242 @multitable @columnfractions .20 .80
243 @item @emph{Prototype}: @tab @code{int omp_get_nested();}
246 @item @emph{Fortran}:
247 @multitable @columnfractions .20 .80
248 @item @emph{Interface}: @tab @code{integer function omp_get_nested()}
251 @item @emph{See also}:
252 @ref{omp_set_nested}, @ref{OMP_NESTED}
254 @item @emph{Reference}:
255 @uref{http://www.openmp.org/, OpenMP specifications v2.5}, section 3.2.10.
260 @node omp_get_num_procs
261 @section @code{omp_get_num_procs} -- Number of processors online
263 @item @emph{Description}:
264 Returns the number of processors online.
267 @multitable @columnfractions .20 .80
268 @item @emph{Prototype}: @tab @code{int omp_get_num_procs();}
271 @item @emph{Fortran}:
272 @multitable @columnfractions .20 .80
273 @item @emph{Interface}: @tab @code{integer function omp_get_num_procs()}
276 @item @emph{Reference}:
277 @uref{http://www.openmp.org/, OpenMP specifications v2.5}, section 3.2.5.
282 @node omp_get_num_threads
283 @section @code{omp_get_num_threads} -- Size of the active team
285 @item @emph{Description}:
286 The number of threads in the current team. In a sequential section of
287 the program @code{omp_get_num_threads} returns 1.
289 The default team size may be initialized at startup by the
290 @code{OMP_NUM_THREADS} environment variable. At runtime, the size
291 of the current team may be set either by the @code{NUM_THREADS}
292 clause or by @code{omp_set_num_threads}. If none of the above were
293 used to define a specific value and @code{OMP_DYNAMIC} is disabled,
294 one thread per CPU online is used.
297 @multitable @columnfractions .20 .80
298 @item @emph{Prototype}: @tab @code{int omp_get_num_threads();}
301 @item @emph{Fortran}:
302 @multitable @columnfractions .20 .80
303 @item @emph{Interface}: @tab @code{integer function omp_get_num_threads()}
306 @item @emph{See also}:
307 @ref{omp_get_max_threads}, @ref{omp_set_num_threads}, @ref{OMP_NUM_THREADS}
309 @item @emph{Reference}:
310 @uref{http://www.openmp.org/, OpenMP specifications v2.5}, section 3.2.2.
315 @node omp_get_thread_num
316 @section @code{omp_get_thread_num} -- Current thread ID
318 @item @emph{Description}:
319 Unique thread identification number. In a sequential parts of the program,
320 @code{omp_get_thread_num} always returns 0. In parallel regions the return
321 value varies from 0 to @code{omp_get_max_threads}-1 inclusive. The return
322 value of the master thread of a team is always 0.
325 @multitable @columnfractions .20 .80
326 @item @emph{Prototype}: @tab @code{int omp_get_thread_num();}
329 @item @emph{Fortran}:
330 @multitable @columnfractions .20 .80
331 @item @emph{Interface}: @tab @code{integer function omp_get_thread_num()}
334 @item @emph{See also}:
335 @ref{omp_get_max_threads}
337 @item @emph{Reference}:
338 @uref{http://www.openmp.org/, OpenMP specifications v2.5}, section 3.2.4.
343 @node omp_in_parallel
344 @section @code{omp_in_parallel} -- Whether a parallel region is active
346 @item @emph{Description}:
347 This function returns @code{true} if currently running in parallel,
348 @code{false} otherwise. Here, @code{true} and @code{false} represent
349 their language-specific counterparts.
352 @multitable @columnfractions .20 .80
353 @item @emph{Prototype}: @tab @code{int omp_in_parallel();}
356 @item @emph{Fortran}:
357 @multitable @columnfractions .20 .80
358 @item @emph{Interface}: @tab @code{logical function omp_in_parallel()}
361 @item @emph{Reference}:
362 @uref{http://www.openmp.org/, OpenMP specifications v2.5}, section 3.2.6.
366 @node omp_set_dynamic
367 @section @code{omp_set_dynamic} -- Enable/disable dynamic teams
369 @item @emph{Description}:
370 Enable or disable the dynamic adjustment of the number of threads
371 within a team. The function takes the language-specific equivalent
372 of @code{true} and @code{false}, where @code{true} enables dynamic
373 adjustment of team sizes and @code{false} disables it.
376 @multitable @columnfractions .20 .80
377 @item @emph{Prototype}: @tab @code{void omp_set_dynamic(int);}
380 @item @emph{Fortran}:
381 @multitable @columnfractions .20 .80
382 @item @emph{Interface}: @tab @code{subroutine omp_set_dynamic(set)}
383 @item @tab @code{integer, intent(in) :: set}
386 @item @emph{See also}:
387 @ref{OMP_DYNAMIC}, @ref{omp_get_dynamic}
389 @item @emph{Reference}:
390 @uref{http://www.openmp.org/, OpenMP specifications v2.5}, section 3.2.7.
396 @section @code{omp_set_nested} -- Enable/disable nested parallel regions
398 @item @emph{Description}:
399 Enable or disable nested parallel regions, i.e., whether team members
400 are allowed to create new teams. The function takes the language-specific
401 equivalent of @code{true} and @code{false}, where @code{true} enables
402 dynamic adjustment of team sizes and @code{false} disables it.
405 @multitable @columnfractions .20 .80
406 @item @emph{Prototype}: @tab @code{void omp_set_dynamic(int);}
409 @item @emph{Fortran}:
410 @multitable @columnfractions .20 .80
411 @item @emph{Interface}: @tab @code{subroutine omp_set_dynamic(set)}
412 @item @tab @code{integer, intent(in) :: set}
415 @item @emph{See also}:
416 @ref{OMP_NESTED}, @ref{omp_get_nested}
418 @item @emph{Reference}:
419 @uref{http://www.openmp.org/, OpenMP specifications v2.5}, section 3.2.9.
424 @node omp_set_num_threads
425 @section @code{omp_set_num_threads} -- Set upper team size limit
427 @item @emph{Description}:
428 Specifies the number of threads used by default in subsequent parallel
429 sections, if those do not specify a @code{num_threads} clause. The
430 argument of @code{omp_set_num_threads} shall be a positive integer.
433 @multitable @columnfractions .20 .80
434 @item @emph{Prototype}: @tab @code{void omp_set_num_threads(int);}
437 @item @emph{Fortran}:
438 @multitable @columnfractions .20 .80
439 @item @emph{Interface}: @tab @code{subroutine omp_set_num_threads(set)}
440 @item @tab @code{integer, intent(in) :: set}
443 @item @emph{See also}:
444 @ref{OMP_NUM_THREADS}, @ref{omp_get_num_threads}, @ref{omp_get_max_threads}
446 @item @emph{Reference}:
447 @uref{http://www.openmp.org/, OpenMP specifications v2.5}, section 3.2.1.
453 @section @code{omp_init_lock} -- Initialize simple lock
455 @item @emph{Description}:
456 Initialize a simple lock. After initialization, the lock is in
460 @multitable @columnfractions .20 .80
461 @item @emph{Prototype}: @tab @code{void omp_init_lock(omp_lock_t *lock);}
464 @item @emph{Fortran}:
465 @multitable @columnfractions .20 .80
466 @item @emph{Interface}: @tab @code{subroutine omp_init_lock(lock)}
467 @item @tab @code{integer(omp_lock_kind), intent(out) :: lock}
470 @item @emph{See also}:
471 @ref{omp_destroy_lock}
473 @item @emph{Reference}:
474 @uref{http://www.openmp.org/, OpenMP specifications v2.5}, section 3.3.1.
480 @section @code{omp_set_lock} -- Wait for and set simple lock
482 @item @emph{Description}:
483 Before setting a simple lock, the lock variable must be initialized by
484 @code{omp_init_lock}. The calling thread is blocked until the lock
485 is available. If the lock is already held by the current thread,
489 @multitable @columnfractions .20 .80
490 @item @emph{Prototype}: @tab @code{void omp_set_lock(omp_lock_t *lock);}
493 @item @emph{Fortran}:
494 @multitable @columnfractions .20 .80
495 @item @emph{Interface}: @tab @code{subroutine omp_set_lock(lock)}
496 @item @tab @code{integer(omp_lock_kind), intent(out) :: lock}
499 @item @emph{See also}:
500 @ref{omp_init_lock}, @ref{omp_test_lock}, @ref{omp_unset_lock}
502 @item @emph{Reference}:
503 @uref{http://www.openmp.org/, OpenMP specifications v2.5}, section 3.3.3.
509 @section @code{omp_test_lock} -- Test and set simple lock if available
511 @item @emph{Description}:
512 Before setting a simple lock, the lock variable must be initialized by
513 @code{omp_init_lock}. Contrary to @code{omp_set_lock}, @code{omp_test_lock}
514 does not block if the lock is not available. This function returns
515 @code{true} upon success,@code{false} otherwise. Here, @code{true} and
516 @code{false} represent their language-specific counterparts.
519 @multitable @columnfractions .20 .80
520 @item @emph{Prototype}: @tab @code{int omp_test_lock(omp_lock_t *lock);}
523 @item @emph{Fortran}:
524 @multitable @columnfractions .20 .80
525 @item @emph{Interface}: @tab @code{subroutine omp_test_lock(lock)}
526 @item @tab @code{logical(omp_logical_kind) :: omp_test_lock}
527 @item @tab @code{integer(omp_lock_kind), intent(out) :: lock}
530 @item @emph{See also}:
531 @ref{omp_init_lock}, @ref{omp_set_lock}, @ref{omp_set_lock}
533 @item @emph{Reference}:
534 @uref{http://www.openmp.org/, OpenMP specifications v2.5}, section 3.3.5.
540 @section @code{omp_unset_lock} -- Unset simple lock
542 @item @emph{Description}:
543 A simple lock about to be unset must have been locked by @code{omp_set_lock}
544 or @code{omp_test_lock} before. In addition, the lock must be held by the
545 thread calling @code{omp_unset_lock}. Then, the lock becomes unlocked. If one
546 ore more threads attempted to set the lock before, one of them is chosen to,
547 again, set the lock for itself.
550 @multitable @columnfractions .20 .80
551 @item @emph{Prototype}: @tab @code{void omp_unset_lock(omp_lock_t *lock);}
554 @item @emph{Fortran}:
555 @multitable @columnfractions .20 .80
556 @item @emph{Interface}: @tab @code{subroutine omp_unset_lock(lock)}
557 @item @tab @code{integer(omp_lock_kind), intent(out) :: lock}
560 @item @emph{See also}:
561 @ref{omp_set_lock}, @ref{omp_test_lock}
563 @item @emph{Reference}:
564 @uref{http://www.openmp.org/, OpenMP specifications v2.5}, section 3.3.4.
569 @node omp_destroy_lock
570 @section @code{omp_destroy_lock} -- Destroy simple lock
572 @item @emph{Description}:
573 Destroy a simple lock. In order to be destroyed, a simple lock must be
574 in the unlocked state.
577 @multitable @columnfractions .20 .80
578 @item @emph{Prototype}: @tab @code{void omp_destroy_lock(omp_lock_t *);}
581 @item @emph{Fortran}:
582 @multitable @columnfractions .20 .80
583 @item @emph{Interface}: @tab @code{subroutine omp_destroy_lock(lock)}
584 @item @tab @code{integer(omp_lock_kind), intent(inout) :: lock}
587 @item @emph{See also}:
590 @item @emph{Reference}:
591 @uref{http://www.openmp.org/, OpenMP specifications v2.5}, section 3.3.2.
596 @node omp_init_nest_lock
597 @section @code{omp_init_nest_lock} -- Initialize nested lock
599 @item @emph{Description}:
600 Initialize a nested lock. After initialization, the lock is in
601 an unlocked state and the nesting count is set to zero.
604 @multitable @columnfractions .20 .80
605 @item @emph{Prototype}: @tab @code{void omp_init_nest_lock(omp_nest_lock_t *lock);}
608 @item @emph{Fortran}:
609 @multitable @columnfractions .20 .80
610 @item @emph{Interface}: @tab @code{subroutine omp_init_nest_lock(lock)}
611 @item @tab @code{integer(omp_nest_lock_kind), intent(out) :: lock}
614 @item @emph{See also}:
615 @ref{omp_destroy_nest_lock}
617 @item @emph{Reference}:
618 @uref{http://www.openmp.org/, OpenMP specifications v2.5}, section 3.3.1.
622 @node omp_set_nest_lock
623 @section @code{omp_set_nest_lock} -- Wait for and set simple lock
625 @item @emph{Description}:
626 Before setting a nested lock, the lock variable must be initialized by
627 @code{omp_init_nest_lock}. The calling thread is blocked until the lock
628 is available. If the lock is already held by the current thread, the
629 nesting count for the lock in incremented.
632 @multitable @columnfractions .20 .80
633 @item @emph{Prototype}: @tab @code{void omp_set_nest_lock(omp_nest_lock_t *lock);}
636 @item @emph{Fortran}:
637 @multitable @columnfractions .20 .80
638 @item @emph{Interface}: @tab @code{subroutine omp_set_nest_lock(lock)}
639 @item @tab @code{integer(omp_nest_lock_kind), intent(out) :: lock}
642 @item @emph{See also}:
643 @ref{omp_init_nest_lock}, @ref{omp_unset_nest_lock}
645 @item @emph{Reference}:
646 @uref{http://www.openmp.org/, OpenMP specifications v2.5}, section 3.3.3.
651 @node omp_test_nest_lock
652 @section @code{omp_test_nest_lock} -- Test and set nested lock if available
654 @item @emph{Description}:
655 Before setting a nested lock, the lock variable must be initialized by
656 @code{omp_init_nest_lock}. Contrary to @code{omp_set_nest_lock},
657 @code{omp_test_nest_lock} does not block if the lock is not available.
658 If the lock is already held by the current thread, the new nesting count
659 is returned. Otherwise, the return value equals zero.
662 @multitable @columnfractions .20 .80
663 @item @emph{Prototype}: @tab @code{int omp_test_nest_lock(omp_nest_lock_t *lock);}
666 @item @emph{Fortran}:
667 @multitable @columnfractions .20 .80
668 @item @emph{Interface}: @tab @code{integer function omp_test_nest_lock(lock)}
669 @item @tab @code{integer(omp_integer_kind) :: omp_test_nest_lock}
670 @item @tab @code{integer(omp_nest_lock_kind), intent(inout) :: lock}
674 @item @emph{See also}:
675 @ref{omp_init_lock}, @ref{omp_set_lock}, @ref{omp_set_lock}
677 @item @emph{Reference}:
678 @uref{http://www.openmp.org/, OpenMP specifications v2.5}, section 3.3.5.
683 @node omp_unset_nest_lock
684 @section @code{omp_unset_nest_lock} -- Unset nested lock
686 @item @emph{Description}:
687 A nested lock about to be unset must have been locked by @code{omp_set_nested_lock}
688 or @code{omp_test_nested_lock} before. In addition, the lock must be held by the
689 thread calling @code{omp_unset_nested_lock}. If the nesting count drops to zero, the
690 lock becomes unlocked. If one ore more threads attempted to set the lock before,
691 one of them is chosen to, again, set the lock for itself.
694 @multitable @columnfractions .20 .80
695 @item @emph{Prototype}: @tab @code{void omp_unset_nest_lock(omp_nest_lock_t *lock);}
698 @item @emph{Fortran}:
699 @multitable @columnfractions .20 .80
700 @item @emph{Interface}: @tab @code{subroutine omp_unset_nest_lock(lock)}
701 @item @tab @code{integer(omp_nest_lock_kind), intent(out) :: lock}
704 @item @emph{See also}:
705 @ref{omp_set_nest_lock}
707 @item @emph{Reference}:
708 @uref{http://www.openmp.org/, OpenMP specifications v2.5}, section 3.3.4.
713 @node omp_destroy_nest_lock
714 @section @code{omp_destroy_nest_lock} -- Destroy nested lock
716 @item @emph{Description}:
717 Destroy a nested lock. In order to be destroyed, a nested lock must be
718 in the unlocked state and its nesting count must equal zero.
721 @multitable @columnfractions .20 .80
722 @item @emph{Prototype}: @tab @code{void omp_destroy_nest_lock(omp_nest_lock_t *);}
725 @item @emph{Fortran}:
726 @multitable @columnfractions .20 .80
727 @item @emph{Interface}: @tab @code{subroutine omp_destroy_nest_lock(lock)}
728 @item @tab @code{integer(omp_nest_lock_kind), intent(inout) :: lock}
731 @item @emph{See also}:
734 @item @emph{Reference}:
735 @uref{http://www.openmp.org/, OpenMP specifications v2.5}, section 3.3.2.
741 @section @code{omp_get_wtick} -- Get timer precision
743 @item @emph{Description}:
744 Gets the timer precision, i.e., the number of seconds between two
745 successive clock ticks.
748 @multitable @columnfractions .20 .80
749 @item @emph{Prototype}: @tab @code{double omp_get_wtick();}
752 @item @emph{Fortran}:
753 @multitable @columnfractions .20 .80
754 @item @emph{Interface}: @tab @code{double precision function omp_get_wtick()}
757 @item @emph{See also}:
760 @item @emph{Reference}:
761 @uref{http://www.openmp.org/, OpenMP specifications v2.5}, section 3.4.2.
767 @section @code{omp_get_wtime} -- Elapsed wall clock time
769 @item @emph{Description}:
770 Elapsed wall clock time in seconds. The time is measured per thread, no
771 guarantee can bee made that two distinct threads measure the same time.
772 Time is measured from some "time in the past". On POSIX compliant systems
773 the seconds since the Epoch (00:00:00 UTC, January 1, 1970) are returned.
776 @multitable @columnfractions .20 .80
777 @item @emph{Prototype}: @tab @code{double omp_get_wtime();}
780 @item @emph{Fortran}:
781 @multitable @columnfractions .20 .80
782 @item @emph{Interface}: @tab @code{double precision function omp_get_wtime()}
785 @item @emph{See also}:
788 @item @emph{Reference}:
789 @uref{http://www.openmp.org/, OpenMP specifications v2.5}, section 3.4.1.
794 @c ---------------------------------------------------------------------
795 @c Environment Variables
796 @c ---------------------------------------------------------------------
798 @node Environment Variables
799 @chapter Environment Variables
801 The variables @env{OMP_DYNAMIC}, @env{OMP_NESTED}, @env{OMP_NUM_THREADS} and
802 @env{OMP_SCHEDULE} are defined by section 4 of the OpenMP specifications in
803 version 2.5, while @env{GOMP_CPU_AFFINITY} and @env{GOMP_STACKSIZE} are GNU
807 * OMP_DYNAMIC:: Dynamic adjustment of threads
808 * OMP_NESTED:: Nested parallel regions
809 * OMP_NUM_THREADS:: Specifies the number of threads to use
810 * OMP_SCHEDULE:: How threads are scheduled
811 * GOMP_CPU_AFFINITY:: Bind threads to specific CPUs
812 * GOMP_STACKSIZE:: Set default thread stack size
817 @section @env{OMP_DYNAMIC} -- Dynamic adjustment of threads
818 @cindex Environment Variable
819 @cindex Implementation specific setting
821 @item @emph{Description}:
822 Enable or disable the dynamic adjustment of the number of threads
823 within a team. The value of this environment variable shall be
824 @code{TRUE} or @code{FALSE}. If undefined, dynamic adjustment is
827 @item @emph{See also}:
828 @ref{omp_set_dynamic}
830 @item @emph{Reference}:
831 @uref{http://www.openmp.org/, OpenMP specifications v2.5}, section 4.3
837 @section @env{OMP_NESTED} -- Nested parallel regions
838 @cindex Environment Variable
839 @cindex Implementation specific setting
841 @item @emph{Description}:
842 Enable or disable nested parallel regions, i.e., whether team members
843 are allowed to create new teams. The value of this environment variable
844 shall be @code{TRUE} or @code{FALSE}. If undefined, nested parallel
845 regions are disabled by default.
847 @item @emph{See also}:
850 @item @emph{Reference}:
851 @uref{http://www.openmp.org/, OpenMP specifications v2.5}, section 4.4
856 @node OMP_NUM_THREADS
857 @section @env{OMP_NUM_THREADS} -- Specifies the number of threads to use
858 @cindex Environment Variable
859 @cindex Implementation specific setting
861 @item @emph{Description}:
862 Specifies the default number of threads to use in parallel regions. The
863 value of this variable shall be positive integer. If undefined one thread
864 per CPU online is used.
866 @item @emph{See also}:
867 @ref{omp_set_num_threads}
869 @item @emph{Reference}:
870 @uref{http://www.openmp.org/, OpenMP specifications v2.5}, section 4.2
876 @section @env{OMP_SCHEDULE} -- How threads are scheduled
877 @cindex Environment Variable
878 @cindex Implementation specific setting
880 @item @emph{Description}:
881 Allows to specify @code{schedule type} and @code{chunk size}.
882 The value of the variable shall have the form: @code{type[,chunk]} where
883 @code{type} is one of @code{static}, @code{dynamic} or @code{guided}.
884 The optional @code{chunk size} shall be a positive integer. If undefined,
885 dynamic scheduling and a chunk size of 1 is used.
887 @item @emph{Reference}:
888 @uref{http://www.openmp.org/, OpenMP specifications v2.5}, sections 2.5.1 and 4.1
893 @node GOMP_CPU_AFFINITY
894 @section @env{GOMP_CPU_AFFINITY} -- Bind threads to specific CPUs
895 @cindex Environment Variable
897 @item @emph{Description}:
898 Binds threads to specific CPUs. The variable should contain a space- or
899 comma-separated list of CPUs. This list may contain different kind of
900 entries: either single CPU numbers in any order, a range of CPUs (M-N)
901 or a range with some stride (M-N:S). CPU numbers are zero based. For example,
902 @code{GOMP_CPU_AFFINITY="0 3 1-2 4-15:2"} will bind the initial thread
903 to CPU 0, the second to CPU 3, the third to CPU 1, the fourth to
904 CPU 2, the fifth to CPU 4, the sixth through tenth to CPUs 6, 8, 10, 12,
905 and 14 respectively and then start assigning back from the beginning of
906 the list. @code{GOMP_CPU_AFFINITY=0} binds all threads to CPU 0.
908 There is no GNU OpenMP library routine to determine whether a CPU affinity
909 specification is in effect. As a workaround, language-specific library
910 functions, e.g., @code{getenv} in C or @code{GET_ENVIRONMENT_VARIABLE} in
911 Fortran, may be used to query the setting of the @code{GOMP_CPU_AFFINITY}
912 environment variable. A defined CPU affinity on startup cannot be changed
913 or disabled during the runtime of the application.
915 If this environment variable is omitted, the host system will handle the
916 assignment of threads to CPUs.
922 @section @env{GOMP_STACKSIZE} -- Set default thread stack size
923 @cindex Environment Variable
924 @cindex Implementation specific setting
926 @item @emph{Description}:
927 Set the default thread stack size in kilobytes. This is in opposition
928 to @code{pthread_attr_setstacksize} which gets the number of bytes as an
929 argument. If the stacksize can not be set due to system constraints, an
930 error is reported and the initial stacksize is left unchanged. If undefined,
931 the stack size is system dependent.
933 @item @emph{Reference}:
934 @uref{http://gcc.gnu.org/ml/gcc-patches/2006-06/msg00493.html,
935 GCC Patches Mailinglist},
936 @uref{http://gcc.gnu.org/ml/gcc-patches/2006-06/msg00496.html,
937 GCC Patches Mailinglist}
942 @c ---------------------------------------------------------------------
944 @c ---------------------------------------------------------------------
946 @node The libgomp ABI
947 @chapter The libgomp ABI
949 The following sections present notes on the external ABI as
950 presented by libgomp. Only maintainers should need them.
953 * Implementing MASTER construct::
954 * Implementing CRITICAL construct::
955 * Implementing ATOMIC construct::
956 * Implementing FLUSH construct::
957 * Implementing BARRIER construct::
958 * Implementing THREADPRIVATE construct::
959 * Implementing PRIVATE clause::
960 * Implementing FIRSTPRIVATE LASTPRIVATE COPYIN and COPYPRIVATE clauses::
961 * Implementing REDUCTION clause::
962 * Implementing PARALLEL construct::
963 * Implementing FOR construct::
964 * Implementing ORDERED construct::
965 * Implementing SECTIONS construct::
966 * Implementing SINGLE construct::
970 @node Implementing MASTER construct
971 @section Implementing MASTER construct
974 if (omp_get_thread_num () == 0)
978 Alternately, we generate two copies of the parallel subfunction
979 and only include this in the version run by the master thread.
980 Surely that's not worthwhile though...
984 @node Implementing CRITICAL construct
985 @section Implementing CRITICAL construct
987 Without a specified name,
990 void GOMP_critical_start (void);
991 void GOMP_critical_end (void);
994 so that we don't get COPY relocations from libgomp to the main
997 With a specified name, use omp_set_lock and omp_unset_lock with
998 name being transformed into a variable declared like
1001 omp_lock_t gomp_critical_user_<name> __attribute__((common))
1004 Ideally the ABI would specify that all zero is a valid unlocked
1005 state, and so we wouldn't actually need to initialize this at
1010 @node Implementing ATOMIC construct
1011 @section Implementing ATOMIC construct
1013 The target should implement the @code{__sync} builtins.
1015 Failing that we could add
1018 void GOMP_atomic_enter (void)
1019 void GOMP_atomic_exit (void)
1022 which reuses the regular lock code, but with yet another lock
1023 object private to the library.
1027 @node Implementing FLUSH construct
1028 @section Implementing FLUSH construct
1030 Expands to the @code{__sync_synchronize} builtin.
1034 @node Implementing BARRIER construct
1035 @section Implementing BARRIER construct
1038 void GOMP_barrier (void)
1042 @node Implementing THREADPRIVATE construct
1043 @section Implementing THREADPRIVATE construct
1045 In _most_ cases we can map this directly to @code{__thread}. Except
1046 that OMP allows constructors for C++ objects. We can either
1047 refuse to support this (how often is it used?) or we can
1048 implement something akin to .ctors.
1050 Even more ideally, this ctor feature is handled by extensions
1051 to the main pthreads library. Failing that, we can have a set
1052 of entry points to register ctor functions to be called.
1056 @node Implementing PRIVATE clause
1057 @section Implementing PRIVATE clause
1059 In association with a PARALLEL, or within the lexical extent
1060 of a PARALLEL block, the variable becomes a local variable in
1061 the parallel subfunction.
1063 In association with FOR or SECTIONS blocks, create a new
1064 automatic variable within the current function. This preserves
1065 the semantic of new variable creation.
1069 @node Implementing FIRSTPRIVATE LASTPRIVATE COPYIN and COPYPRIVATE clauses
1070 @section Implementing FIRSTPRIVATE LASTPRIVATE COPYIN and COPYPRIVATE clauses
1072 Seems simple enough for PARALLEL blocks. Create a private
1073 struct for communicating between parent and subfunction.
1074 In the parent, copy in values for scalar and "small" structs;
1075 copy in addresses for others TREE_ADDRESSABLE types. In the
1076 subfunction, copy the value into the local variable.
1078 Not clear at all what to do with bare FOR or SECTION blocks.
1079 The only thing I can figure is that we do something like
1082 #pragma omp for firstprivate(x) lastprivate(y)
1083 for (int i = 0; i < n; ++i)
1100 where the "x=x" and "y=y" assignments actually have different
1101 uids for the two variables, i.e. not something you could write
1102 directly in C. Presumably this only makes sense if the "outer"
1103 x and y are global variables.
1105 COPYPRIVATE would work the same way, except the structure
1106 broadcast would have to happen via SINGLE machinery instead.
1110 @node Implementing REDUCTION clause
1111 @section Implementing REDUCTION clause
1113 The private struct mentioned in the previous section should have
1114 a pointer to an array of the type of the variable, indexed by the
1115 thread's @var{team_id}. The thread stores its final value into the
1116 array, and after the barrier the master thread iterates over the
1117 array to collect the values.
1120 @node Implementing PARALLEL construct
1121 @section Implementing PARALLEL construct
1124 #pragma omp parallel
1133 void subfunction (void *data)
1140 GOMP_parallel_start (subfunction, &data, num_threads);
1141 subfunction (&data);
1142 GOMP_parallel_end ();
1146 void GOMP_parallel_start (void (*fn)(void *), void *data, unsigned num_threads)
1149 The @var{FN} argument is the subfunction to be run in parallel.
1151 The @var{DATA} argument is a pointer to a structure used to
1152 communicate data in and out of the subfunction, as discussed
1153 above with respect to FIRSTPRIVATE et al.
1155 The @var{NUM_THREADS} argument is 1 if an IF clause is present
1156 and false, or the value of the NUM_THREADS clause, if
1159 The function needs to create the appropriate number of
1160 threads and/or launch them from the dock. It needs to
1161 create the team structure and assign team ids.
1164 void GOMP_parallel_end (void)
1167 Tears down the team and returns us to the previous @code{omp_in_parallel()} state.
1171 @node Implementing FOR construct
1172 @section Implementing FOR construct
1175 #pragma omp parallel for
1176 for (i = lb; i <= ub; i++)
1183 void subfunction (void *data)
1186 while (GOMP_loop_static_next (&_s0, &_e0))
1189 for (i = _s0; i < _e1; i++)
1192 GOMP_loop_end_nowait ();
1195 GOMP_parallel_loop_static (subfunction, NULL, 0, lb, ub+1, 1, 0);
1197 GOMP_parallel_end ();
1201 #pragma omp for schedule(runtime)
1202 for (i = 0; i < n; i++)
1211 if (GOMP_loop_runtime_start (0, n, 1, &_s0, &_e0))
1214 for (i = _s0, i < _e0; i++)
1216 @} while (GOMP_loop_runtime_next (&_s0, _&e0));
1221 Note that while it looks like there is trickyness to propagating
1222 a non-constant STEP, there isn't really. We're explicitly allowed
1223 to evaluate it as many times as we want, and any variables involved
1224 should automatically be handled as PRIVATE or SHARED like any other
1225 variables. So the expression should remain evaluable in the
1226 subfunction. We can also pull it into a local variable if we like,
1227 but since its supposed to remain unchanged, we can also not if we like.
1229 If we have SCHEDULE(STATIC), and no ORDERED, then we ought to be
1230 able to get away with no work-sharing context at all, since we can
1231 simply perform the arithmetic directly in each thread to divide up
1232 the iterations. Which would mean that we wouldn't need to call any
1235 There are separate routines for handling loops with an ORDERED
1236 clause. Bookkeeping for that is non-trivial...
1240 @node Implementing ORDERED construct
1241 @section Implementing ORDERED construct
1244 void GOMP_ordered_start (void)
1245 void GOMP_ordered_end (void)
1250 @node Implementing SECTIONS construct
1251 @section Implementing SECTIONS construct
1256 #pragma omp sections
1270 for (i = GOMP_sections_start (3); i != 0; i = GOMP_sections_next ())
1287 @node Implementing SINGLE construct
1288 @section Implementing SINGLE construct
1302 if (GOMP_single_start ())
1310 #pragma omp single copyprivate(x)
1317 datap = GOMP_single_copy_start ();
1322 GOMP_single_copy_end (&data);
1331 @c ---------------------------------------------------------------------
1333 @c ---------------------------------------------------------------------
1335 @node Reporting Bugs
1336 @chapter Reporting Bugs
1338 Bugs in the GNU OpenMP implementation should be reported via
1339 @uref{http://gcc.gnu.org/bugzilla/, bugzilla}. In all cases, please add
1340 "openmp" to the keywords field in the bug report.
1344 @c ---------------------------------------------------------------------
1345 @c GNU General Public License
1346 @c ---------------------------------------------------------------------
1352 @c ---------------------------------------------------------------------
1353 @c GNU Free Documentation License
1354 @c ---------------------------------------------------------------------
1360 @c ---------------------------------------------------------------------
1361 @c Funding Free Software
1362 @c ---------------------------------------------------------------------
1364 @include funding.texi
1366 @c ---------------------------------------------------------------------
1368 @c ---------------------------------------------------------------------