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