OpenMP OpenMP Application Program Interface Version 4.0-July 2013 Copyright 1997-2013 OpenMP Architecture Review Board. Permission to copy without fee all or part of this material is granted. provided the OpenMP Architecture Review Board copyright notice and the title of this document appear.Notice is given that copying is by permission of OpenMP Architecture Review Board
OpenMP Application Program Interface Version 4.0 - July 2013 Copyright © 1997-2013 OpenMP Architecture Review Board. Permission to copy without fee all or part of this material is granted, provided the OpenMP Architecture Review Board copyright notice and the title of this document appear. Notice is given that copying is by permission of OpenMP Architecture Review Board
CONTENTS 1.Introduction...................................1 1.1 Scope …1 1.2 Glossary............................................2 1.2.1 Threading Concepts..............................2 1.2.2 OpenMP Language Terminology .2 1.2.3 Synchronization Terminology ……8 1.2.4 Tasking Terminology 8 1.2.5 Data Terminology.................................10 1.2.6 Implementation Terminology …12 1.3 Execution Model ·。。4…44…。…。…。…。。。。…。4。……。。。444 14 1.4 Memory Model...........17 1.4.1 Structure of the OpenMP Memory Model...............17 1.4.2 Device Data Environments …18 1.4.3 The Flush Operation 19 1.4.4 OpenMP Memory Consistency......................20 1.5 OpenMP Compliance…… .21 1.6 Normative References ….22 1.7 Organization of this document 23 2.Directives....................25 2.1 Directive Format...........26 2.1.1 Fixed Source Form Directives .27 2.1.2 Free Source Form Directives........................28 2.1.3 Stand-Alone Directives............................31 2.2 Conditional Compilation .32 2.2.1 Fixed Source Form Conditional Compilation Sentinels ..32
i CONTENTS 1. Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1 1.1 Scope . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1 1.2 Glossary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2 1.2.1 Threading Concepts . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2 1.2.2 OpenMP Language Terminology . . . . . . . . . . . . . . . . . . . . . 2 1.2.3 Synchronization Terminology . . . . . . . . . . . . . . . . . . . . . . . . 8 1.2.4 Tasking Terminology . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8 1.2.5 Data Terminology . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10 1.2.6 Implementation Terminology . . . . . . . . . . . . . . . . . . . . . . . . 12 1.3 Execution Model . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14 1.4 Memory Model . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17 1.4.1 Structure of the OpenMP Memory Model . . . . . . . . . . . . . . . 17 1.4.2 Device Data Environments . . . . . . . . . . . . . . . . . . . . . . . . . 18 1.4.3 The Flush Operation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19 1.4.4 OpenMP Memory Consistency . . . . . . . . . . . . . . . . . . . . . . 20 1.5 OpenMP Compliance . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 21 1.6 Normative References . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 22 1.7 Organization of this document . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 23 2. Directives . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 25 2.1 Directive Format . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 26 2.1.1 Fixed Source Form Directives . . . . . . . . . . . . . . . . . . . . . . . 27 2.1.2 Free Source Form Directives . . . . . . . . . . . . . . . . . . . . . . . . 28 2.1.3 Stand-Alone Directives . . . . . . . . . . . . . . . . . . . . . . . . . . . . 31 2.2 Conditional Compilation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 32 2.2.1 Fixed Source Form Conditional Compilation Sentinels . . . . 32
2.2.2 Free Source Form Conditional Compilation Sentinel ..33 2.3 Internal Control Variables 。。。。。。。。。。。。。。。。。。。。。。。。。。。 34 2.3.1 ICV Descriptions .35 2.3.2 ICV Initialization .36 2.3.3 Modifying and Retrieving ICV Values 37 2.3.4 How ICVs are Scoped 39 2.3.5 ICV Override Relationships 40 2.4 Array Sections ....42 2.5 parallel Construct .44 2.5.1 Determining the Number of Threads for a parallel Region ....... 47 2.5.2 Controlling OpenMP Thread Affinity …….49 2.6 Canonical Loop Form 51 2.7 Worksharing Constructs 。。。”,。。,。。。。。。。。…。。。。。。。。。。。。。 53 2.7.1 Loop Construct .53 2.7.2 sections Construct 60 2.7.3 single Construct 63 2.7.4 workshare Construct ,。。。。。。+。年,+。。。。。,,。,。。。。 65 2.8 SIMD Constructs .68 2.8.1 simd construct 68 2.8.2 declare simd construct 72 2.8.3 Loop SIMD construct gg。。。。。。。。g。。。。。。。。。tg。。。g。。 76 2.9 Device Constructs .77 2.9.1 target data Construct .77 2.9.2 target Construct 79 2.9.3 target update Construct .81 2.9.4 declare target Directive 83 2.9.5 teams Construct .86 2.9.6 distribute Construct 88 2.9.7 distribute simd Construct 91 ii OpenMP API Version 4.0-July 2013
ii OpenMP API • Version 4.0 - July 2013 2.2.2 Free Source Form Conditional Compilation Sentinel . . . . . . 33 2.3 Internal Control Variables . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 34 2.3.1 ICV Descriptions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 35 2.3.2 ICV Initialization . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 36 2.3.3 Modifying and Retrieving ICV Values . . . . . . . . . . . . . . . . . . 37 2.3.4 How ICVs are Scoped . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 39 2.3.5 ICV Override Relationships . . . . . . . . . . . . . . . . . . . . . . . . . 40 2.4 Array Sections . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 42 2.5 parallel Construct . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 44 2.5.1 Determining the Number of Threads for a parallel Region . . . . . . . . . . . . . . . . . . . . . . . . . . . . 47 2.5.2 Controlling OpenMP Thread Affinity . . . . . . . . . . . . . . . . . . . 49 2.6 Canonical Loop Form . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 51 2.7 Worksharing Constructs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 53 2.7.1 Loop Construct . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 53 2.7.2 sections Construct . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 60 2.7.3 single Construct . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 63 2.7.4 workshare Construct . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 65 2.8 SIMD Constructs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 68 2.8.1 simd construct . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 68 2.8.2 declare simd construct . . . . . . . . . . . . . . . . . . . . . . . . . . . 72 2.8.3 Loop SIMD construct . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 76 2.9 Device Constructs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 77 2.9.1 target data Construct . . . . . . . . . . . . . . . . . . . . . . . . . . . 77 2.9.2 target Construct . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 79 2.9.3 target update Construct . . . . . . . . . . . . . . . . . . . . . . . . . 81 2.9.4 declare target Directive . . . . . . . . . . . . . . . . . . . . . . . . . 83 2.9.5 teams Construct . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 86 2.9.6 distribute Construct . . . . . . . . . . . . . . . . . . . . . . . . . . . . 88 2.9.7 distribute simd Construct . . . . . . . . . . . . . . . . . . . . . . . 91
2.9.8 Distribute Parallel Loop Construct 92 2.9.9 Distribute Parallel Loop SIMD Construct .94 2.10 Combined Constructs .95 2.10.1 Parallel Loop Construct............................95 2.10.2 parallel sections Construct 97 2.10.3 parallel workshare Construct .99 2.10.4 Parallel Loop SIMD Construct 100 2.10.5 target teams construct 101 2.10.6 teams distribute Construct .102 2.10.7 teams distribute simd Construct 104 2.10.8 target teams distribute Construct 105 2.10.9 target teams distribute simd Construct 106 2.10.10 Teams Distribute Parallel Loop Construct 107 2.10.11 Target Teams Distribute Parallel Loop Construct 109 2.10.12 Teams Distribute Parallel Loop SIMD Construct 110 2.10.13 Target Teams Distribute Parallel Loop SIMD Construct....111 2.11 Tasking Constructs........ .113 2.11.1 task Construct 113 2.11.2 taskyield Construct 。。。。。。。。。。。4。。。。。。。4 117 2.11.3 Task Scheduling.................................118 2.12 Master and Synchronization Constructs..................... 120 2.12.1 master Construct 120 2.12.2 critical Construct 122 2.12.3 barrier Construct 123 2.12.4 taskwait Construct 125 2.12.5 taskgroup Construct 126 2.12.6 atomic Construct 。。。。。。。。。。4。。。。。。。。。。。。。。。。。…… 127 2.12.7 flush Construct 134 2.12.8 ordered Construct 138 2.13 Cancellation Constructs 140
iii 2.9.8 Distribute Parallel Loop Construct . . . . . . . . . . . . . . . . . . . . 92 2.9.9 Distribute Parallel Loop SIMD Construct . . . . . . . . . . . . . . . 94 2.10 Combined Constructs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 95 2.10.1 Parallel Loop Construct . . . . . . . . . . . . . . . . . . . . . . . . . . . . 95 2.10.2 parallel sections Construct . . . . . . . . . . . . . . . . . . . . . 97 2.10.3 parallel workshare Construct . . . . . . . . . . . . . . . . . . . . 99 2.10.4 Parallel Loop SIMD Construct . . . . . . . . . . . . . . . . . . . . . . . 100 2.10.5 target teams construct . . . . . . . . . . . . . . . . . . . . . . . . . . 101 2.10.6 teams distribute Construct . . . . . . . . . . . . . . . . . . . . . . 102 2.10.7 teams distribute simd Construct . . . . . . . . . . . . . . . . . 104 2.10.8 target teams distribute Construct . . . . . . . . . . . . . . . 105 2.10.9 target teams distribute simd Construct . . . . . . . . . . 106 2.10.10 Teams Distribute Parallel Loop Construct . . . . . . . . . . . . . . 107 2.10.11 Target Teams Distribute Parallel Loop Construct . . . . . . . . . 109 2.10.12 Teams Distribute Parallel Loop SIMD Construct . . . . . . . . . 110 2.10.13 Target Teams Distribute Parallel Loop SIMD Construct . . . . 111 2.11 Tasking Constructs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 113 2.11.1 task Construct . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 113 2.11.2 taskyield Construct . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 117 2.11.3 Task Scheduling . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 118 2.12 Master and Synchronization Constructs . . . . . . . . . . . . . . . . . . . . . . 120 2.12.1 master Construct . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 120 2.12.2 critical Construct . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 122 2.12.3 barrier Construct . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 123 2.12.4 taskwait Construct . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 125 2.12.5 taskgroup Construct . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 126 2.12.6 atomic Construct . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 127 2.12.7 flush Construct . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 134 2.12.8 ordered Construct . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 138 2.13 Cancellation Constructs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 140
2.13.1 cancel Construct ….140 2.13.2 cancellation point Construct … 143 2.14 Data Environment ,146 2.14.1 Data-sharing Attribute Rules 2.14.2 threadprivate Directive .150 2.14.3 Data-Sharing Attribute Clauses 155 2.14.4 Data Copying Clauses .173 2.14.5 map Clause ....177 2.15 declare reduction Directive ......180 2.16 Nesting of Regions 186 3.Runtime Library Routines....................................187 3.1 Runtime Library Definitions …188 3.2 Execution Environment Routines 。,。。。。。。。。。。。。。。。。。。。。 189 3.2.1 omp set num threads .189 3.2.2 omp_get_num_threads ,191 3.2.3 omp_get_max_threads .192 3.2.4 omp_get_thread_num 。年+。。。。。年+。。。。。,,。。。,。。+ 193 3.2.5 omp get num procs ,195 3.2.6 omp_in_parallel ,196 3.2.7 omp_set_dynamic .197 3.2.8 omp_get_dynamic 。g年g。gg。。。。。。。。g。。g。。。。。。。。。。 198 3.2.9 omp_get_cancellation 199 3.2.10 omp_set_nested 200 3.2.11 omp_get_nested 201 3.2.12 omp set schedule 。g。。。。。。。。。g。。。。。。。。g。。。。。。 203 3.2.13 omp_get_schedule............................. 205 3.2.14 omp_get_thread_limit 206 3.2.15 omp_set_max_active_levels 207 3.2.16 omp_get_max_active_levels 209 iv OpenMP API.Version 4.0-July 2013
iv OpenMP API • Version 4.0 - July 2013 2.13.1 cancel Construct . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 140 2.13.2 cancellation point Construct . . . . . . . . . . . . . . . . . . . . 143 2.14 Data Environment . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 146 2.14.1 Data-sharing Attribute Rules . . . . . . . . . . . . . . . . . . . . . . . . 146 2.14.2 threadprivate Directive . . . . . . . . . . . . . . . . . . . . . . . . . 150 2.14.3 Data-Sharing Attribute Clauses . . . . . . . . . . . . . . . . . . . . . . 155 2.14.4 Data Copying Clauses . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 173 2.14.5 map Clause . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 177 2.15 declare reduction Directive . . . . . . . . . . . . . . . . . . . . . . . . . . . 180 2.16 Nesting of Regions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 186 3. Runtime Library Routines . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 187 3.1 Runtime Library Definitions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 188 3.2 Execution Environment Routines . . . . . . . . . . . . . . . . . . . . . . . . . . . 189 3.2.1 omp_set_num_threads . . . . . . . . . . . . . . . . . . . . . . . . . . 189 3.2.2 omp_get_num_threads . . . . . . . . . . . . . . . . . . . . . . . . . . 191 3.2.3 omp_get_max_threads . . . . . . . . . . . . . . . . . . . . . . . . . . 192 3.2.4 omp_get_thread_num . . . . . . . . . . . . . . . . . . . . . . . . . . . 193 3.2.5 omp_get_num_procs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 195 3.2.6 omp_in_parallel . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 196 3.2.7 omp_set_dynamic . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 197 3.2.8 omp_get_dynamic . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 198 3.2.9 omp_get_cancellation . . . . . . . . . . . . . . . . . . . . . . . . . 199 3.2.10 omp_set_nested . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 200 3.2.11 omp_get_nested . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 201 3.2.12 omp_set_schedule . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 203 3.2.13 omp_get_schedule . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 205 3.2.14 omp_get_thread_limit . . . . . . . . . . . . . . . . . . . . . . . . . 206 3.2.15 omp_set_max_active_levels . . . . . . . . . . . . . . . . . . . . 207 3.2.16 omp_get_max_active_levels . . . . . . . . . . . . . . . . . . . . 209
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