3.2.17 omp get level …….210 3.2.18 omp_get_ancestor_thread_num .211 3.2.19 omp_get_team_size 212 3.2.20 omp_get_active_level .214 3.2.21omp_in fina1..........215 3.2.22 omp_get_proc bind .216 3.2.23 omp set default device 218 3.2.24 omp_get_default_device .219 3.2.25 omp_get_num_devices .220 3.2.26 omp_get_num teams .221 3.2.27 omp_get_team num 222 3.2.28 omp is initial device .223 3.3 Lock Routines...... .224 3.3.1 omp_init_lock and omp_init_nest_lock .226 3.3.2 omp destroy lock and omp destroy nest lock 227 3.3.3 omp set lock and omp set nest lock............228 3.3.4 omp_unset_lock and omp_unset_nest_lock ...229 3.3.5 omp test_lock and omp_test nest_lock .231 3.4 Timing Routines ,233 3.4.1 omp_get_wtime.................................233 3.4.2 omp_get_wtick .234 4.Environment Variables ,237 4.1 OMP SCHEDULE .238 4.2 OMP NUM THREADS .239 4.3 OMP DYNAMIC 240 4.4 OMP PROC BIND .241 4.5 OMP PLACES .241 4.6 OMP NESTED .243 4.7 OMP STACKSIZE 244
v 3.2.17 omp_get_level . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 210 3.2.18 omp_get_ancestor_thread_num . . . . . . . . . . . . . . . . . . 211 3.2.19 omp_get_team_size . . . . . . . . . . . . . . . . . . . . . . . . . . . . 212 3.2.20 omp_get_active_level . . . . . . . . . . . . . . . . . . . . . . . . . 214 3.2.21 omp_in_final . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 215 3.2.22 omp_get_proc_bind . . . . . . . . . . . . . . . . . . . . . . . . . . . . 216 3.2.23 omp_set_default_device . . . . . . . . . . . . . . . . . . . . . . . 218 3.2.24 omp_get_default_device . . . . . . . . . . . . . . . . . . . . . . . 219 3.2.25 omp_get_num_devices . . . . . . . . . . . . . . . . . . . . . . . . . . 220 3.2.26 omp_get_num_teams . . . . . . . . . . . . . . . . . . . . . . . . . . . . 221 3.2.27 omp_get_team_num . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 222 3.2.28 omp_is_initial_device . . . . . . . . . . . . . . . . . . . . . . . . 223 3.3 Lock Routines . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 224 3.3.1 omp_init_lock and omp_init_nest_lock . . . . . . . . . 226 3.3.2 omp_destroy_lock and omp_destroy_nest_lock . . . 227 3.3.3 omp_set_lock and omp_set_nest_lock . . . . . . . . . . . . 228 3.3.4 omp_unset_lock and omp_unset_nest_lock . . . . . . . 229 3.3.5 omp_test_lock and omp_test_nest_lock . . . . . . . . . . 231 3.4 Timing Routines . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 233 3.4.1 omp_get_wtime . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 233 3.4.2 omp_get_wtick . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 234 4. Environment Variables . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 237 4.1 OMP_SCHEDULE . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 238 4.2 OMP_NUM_THREADS . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 239 4.3 OMP_DYNAMIC . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 240 4.4 OMP_PROC_BIND . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 241 4.5 OMP_PLACES . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 241 4.6 OMP_NESTED . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 243 4.7 OMP_STACKSIZE . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 244
4.8 OMP WAIT POLICY .245 4.9 OMP MAX ACTIVE LEVELS 245 4.10 OMP THREAD LIMIT 246 4.11 OMP CANCELLATION 246 4.12 OMP_DISPLAY_ENV 247 4.13 OMP DEFAULT DEVICE 。。。44。▣。。。。。。。。。。。。。。。。▣+。。。。。 248 A.Stubs for Runtime Library Routines ,249 A.1 C/C++Stub Routines 250 A.2 Fortran Stub Routines 257 B.OpenMP C and C++Grammar.................................265 B.1 Notation .265 B.2 Rules 266 C.Interface Declarations .287 C.1 Example of the omp.h Header File 288 C.2 Example of an Interface Declaration include File ....290 C.3 Example of a Fortran Interface Declaration module 293 C.4 Example of a Generic Interface for a Library Routine …….298 D.OpenMP Implementation-Defined Behaviors .299 E.Features History .303 E.1 Version 3.1 to 4.0 Differences .303 E.2 Version 3.0 to 3.1 Differences 。。。。。。。。。。。。。。。。。。 304 E.3 Version 2.5 to 3.0 Differences .305 Index.........................309 vi OpenMP API.Version 4.0-July 2013
vi OpenMP API • Version 4.0 - July 2013 4.8 OMP_WAIT_POLICY . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 245 4.9 OMP_MAX_ACTIVE_LEVELS . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 245 4.10 OMP_THREAD_LIMIT . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 246 4.11 OMP_CANCELLATION . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 246 4.12 OMP_DISPLAY_ENV . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 247 4.13 OMP_DEFAULT_DEVICE . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 248 A. Stubs for Runtime Library Routines . . . . . . . . . . . . . . . . . . . . . . . . . . . . 249 A.1 C/C++ Stub Routines . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 250 A.2 Fortran Stub Routines . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 257 B. OpenMP C and C++ Grammar . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 265 B.1 Notation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 265 B.2 Rules . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 266 C. Interface Declarations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 287 C.1 Example of the omp.h Header File . . . . . . . . . . . . . . . . . . . . . . . . . 288 C.2 Example of an Interface Declaration include File . . . . . . . . . . . . . 290 C.3 Example of a Fortran Interface Declaration module . . . . . . . . . . . . 293 C.4 Example of a Generic Interface for a Library Routine . . . . . . . . . . . . 298 D. OpenMP Implementation-Defined Behaviors . . . . . . . . . . . . . . . . . . . . . 299 E. Features History . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 303 E.1 Version 3.1 to 4.0 Differences . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 303 E.2 Version 3.0 to 3.1 Differences . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 304 E.3 Version 2.5 to 3.0 Differences . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 305 Index . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 309
1 CHAPTER 1 Introduction yroutines,and environment variables 5 一cmeree8 AP)formyC.士 the specification of the OpenMP and Fortran programs. This providesamodel for paralle that is 89 shared n 10 following web site 11 http://www.openmp.org The directives,library routines,and environment variables defined in this document 13 allow users to create and manage parallel programs while permitting portability.The directives extend the C,C++and Fortran base languages with single program multiple 6 data(SPMD)constructs,tasking constructs,device constructs,worksharing constructs. 16718 and synchronization constructs,and they provide support for sharing and ivatizing data.The functionality oon rol the runtin e en nvironment is provided ndrbCompiehat support the OpenMPP brary 19 include a command line option to the compiler that activates and allows interpretation of 2 all OpenMP directives. 21 1.1 Scope The OpenMP API covers only user-directed parallelization,wherein the programmer 23 explicitly specifies the actions to be taken by the compiler and runtime system in order to execute the program in parallel.OpenMP-compliant implementations are not required 25 to check for data dependencies,data conflicts.race conditions,or deadlocks,any of which may
1 CHAPTER 1 Introduction The collection of compiler directives, library routines, and environment variables described in this document collectively define the specification of the OpenMP Application Program Interface (OpenMP API) for shared-memory parallelism in C, C++ and Fortran programs. This specification provides a model for parallel programming that is portable across shared memory architectures from different vendors. Compilers from numerous vendors support the OpenMP API. More information about the OpenMP API can be found at the following web site http://www.openmp.org The directives, library routines, and environment variables defined in this document allow users to create and manage parallel programs while permitting portability. The directives extend the C, C++ and Fortran base languages with single program multiple data (SPMD) constructs, tasking constructs, device constructs, worksharing constructs, and synchronization constructs, and they provide support for sharing and privatizing data. The functionality to control the runtime environment is provided by library routines and environment variables. Compilers that support the OpenMP API often include a command line option to the compiler that activates and allows interpretation of all OpenMP directives. 1.1 Scope The OpenMP API covers only user-directed parallelization, wherein the programmer explicitly specifies the actions to be taken by the compiler and runtime system in order to execute the program in parallel. OpenMP-compliant implementations are not required to check for data dependencies, data conflicts, race conditions, or deadlocks, any of which may occur in conforming programs. In addition, compliant implementations are not required to check for code sequences that cause a program to be classified as non- 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27
conforming.Application developers are responsible for correctly using the OpenMP API 23 to produ ice a co rming program. T eOpenMP API does not cover comp generated automatic parallelization and directives to the compiler to assist such parallelization. 1.2 Glossary 51.2.1 Threading Concepts 7 thread An execution entity with a stack and associated static memory,called threadprivate memory. OpenMP thread A thread that is managed by the OpenMP runtime system. thread-safe routine A routine that performs the intended function even when executed concurrently (by more than one thread). 2 processor Implementation defined hardware unit on which one or more OpenMP threads can execute. 14 device An implementation defined logical execution engine 15 COMMENT:A device could have one or more processors 16 host device The device on which the OpenMP program begins execution 17 target device A device onto which code and data may be offloaded from the host device. 181.2.2 OpenMP Language Terminology 2 base language 22 COMMENT:See Section 1.6 on page 22 for a listing of current base languages 2 for the OpenMP API. 24 base program A program written in a base language 2 OpenMP API.Version 4.0-July 2013
2 OpenMP API • Version 4.0 - July 2013 conforming. Application developers are responsible for correctly using the OpenMP API to produce a conforming program. The OpenMP API does not cover compiler-generated automatic parallelization and directives to the compiler to assist such parallelization. 1.2 Glossary 1.2.1 Threading Concepts thread An execution entity with a stack and associated static memory, called threadprivate memory. OpenMP thread A thread that is managed by the OpenMP runtime system. thread-safe routine A routine that performs the intended function even when executed concurrently (by more than one thread). processor Implementation defined hardware unit on which one or more OpenMP threads can execute. device An implementation defined logical execution engine. COMMENT: A device could have one or more processors. host device The device on which the OpenMP program begins execution target device A device onto which code and data may be offloaded from the host device. 1.2.2 OpenMP Language Terminology base language A programming language that serves as the foundation of the OpenMP specification. COMMENT: See Section 1.6 on page 22 for a listing of current base languages for the OpenMP API. base program A program written in a base language. 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
2 structured block For C/C++,an executable statement,possibly compound,with a single entry at the top and a single exit at the bottom,or an OpenMP construct. 34 For Forran,a block of statements with asinge the top and a single exit at the bottom,or an OpenMP construct. COMMENTS: For all base languages, > Access to the structured block must not be the result of a branch 89 The point of exit cannot be a branch out of the structured block. o For C/C++: 11 The point of entry must not be a call to setjmp(). 12 longjmp ()and throw (must not violate the entry/exit criteria. 13 Calls to exit (are allowed in a structured block. 1415 16 corresponding compound statement obtained by enclosing it in 7 and would be a structured block. 19 For Fortran: 20 STop statements are allowed in a structured block. :2 enclosing context In C/C++,the innermost scope enclosing an OpenMP directive 出 In Fortran,the innermost scoping unit enclosing an OpenMP directive. 始 directive In C/C++,a #pragma,and in Fortran,a comment,that specifies OpenMP program behavior. 9 COMMENT:See Section 2.1 on page 26 for a description of OpenMP directive syntax 28 white space A non-empty sequence of space and/or horizontal tab characters. 2930 OpenMP program A progra m that con nsists of a base program,annotated with OpenMP directives and runtime library routines 3 conforming program An OpenMP program that follows all the rules and restrictions of the OpenMP 2 specification. Chapter 1 Introduction 3
Chapter 1 Introduction 3 structured block For C/C++, an executable statement, possibly compound, with a single entry at the top and a single exit at the bottom, or an OpenMP construct. For Fortran, a block of executable statements with a single entry at the top and a single exit at the bottom, or an OpenMP construct. COMMENTS: For all base languages, • Access to the structured block must not be the result of a branch. • The point of exit cannot be a branch out of the structured block. For C/C++: • The point of entry must not be a call to setjmp(). • longjmp() and throw() must not violate the entry/exit criteria. • Calls to exit() are allowed in a structured block. • An expression statement, iteration statement, selection statement, or try block is considered to be a structured block if the corresponding compound statement obtained by enclosing it in { and } would be a structured block. For Fortran: • STOP statements are allowed in a structured block. enclosing context In C/C++, the innermost scope enclosing an OpenMP directive. In Fortran, the innermost scoping unit enclosing an OpenMP directive. directive In C/C++, a #pragma, and in Fortran, a comment, that specifies OpenMP program behavior. COMMENT: See Section 2.1 on page 26 for a description of OpenMP directive syntax. white space A non-empty sequence of space and/or horizontal tab characters. OpenMP program A program that consists of a base program, annotated with OpenMP directives and runtime library routines. conforming program An OpenMP program that follows all the rules and restrictions of the OpenMP specification. 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32