OpenMP Application Program Interface

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.

This page is intentionally blank.

C O N T E N TS

1.

2.

Introduction

...............................................1

1.1

Scope

................................................1

1.2

Glossary

..............................................2

1.2.1

Threading Concepts

1.2.2

OpenMP Language Terminology

1.2.3

Synchronization Terminology

1.2.4

Tasking Terminology

1.2.5

Data Terminology

1.2.6

Implementation Terminology

1.3

Execution Model

1.4

Memory Model

..............................2

.....................2

........................8

..............................8

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10

. . . . . . . . . . . . . . . . . . . . . . . . 12

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17

1.4.1

Structure of the OpenMP Memory Model

1.4.2

Device Data Environments

1.4.3

The Flush Operation

1.4.4

OpenMP Memory Consistency

. . . . . . . . . . . . . . . 17

. . . . . . . . . . . . . . . . . . . . . . . . . 18

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19

. . . . . . . . . . . . . . . . . . . . . . 20

1.5

OpenMP Compliance

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 21

1.6

Normative References

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 22

1.7

Organization of this document

Directives

2.1

2.2

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . 23

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 25

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

Conditional Compilation

2.2.1

. . . . . . . . . . . . . . . . . . . . . . . . . . . . 31

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 32

Fixed Source Form Conditional Compilation Sentinels

. . . . 32

i

2.2.2

2.3

. . . . . . 33

Internal Control Variables

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 34

2.3.1

ICV Descriptions

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 35

2.3.2

ICV Initialization

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 36

2.3.3

Modifying and Retrieving ICV Values

2.3.4

How ICVs are Scoped

2.3.5

ICV Override Relationships

2.4

Array Sections

2.5

parallel Construct

. . . . . . . . . . . . . . . . . . 37

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . 39

. . . . . . . . . . . . . . . . . . . . . . . . . 40

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 42

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 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

2.7

Worksharing Constructs

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 53

2.7.1

Loop Construct

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 53

2.7.2

sections Construct

2.7.3

single Construct

2.7.4

workshare Construct

2.8

2.9

ii

Free Source Form Conditional Compilation Sentinel

SIMD Constructs

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 51

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 60

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 63

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . 65

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 68

2.8.1

simd construct

2.8.2

declare simd construct

2.8.3

Loop SIMD construct

Device Constructs

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 68

. . . . . . . . . . . . . . . . . . . . . . . . . . . 72

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 76

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 77

2.9.1

target data Construct

2.9.2

target Construct

2.9.3

target update Construct

. . . . . . . . . . . . . . . . . . . . . . . . . 81

2.9.4

declare target Directive

. . . . . . . . . . . . . . . . . . . . . . . . . 83

2.9.5

teams Construct

2.9.6

distribute Construct

2.9.7

distribute simd Construct

OpenMP API ? Version 4.0 - July 2013

. . . . . . . . . . . . . . . . . . . . . . . . . . . 77

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 79

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 86

. . . . . . . . . . . . . . . . . . . . . . . . . . . . 88

. . . . . . . . . . . . . . . . . . . . . . . 91

2.10

2.9.8

Distribute Parallel Loop Construct

2.9.9

Distribute Parallel Loop SIMD Construct

Combined Constructs

. . . . . . . . . . . . . . . . . . . . 92

. . . . . . . . . . . . . . . 94

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 95

2.10.1 Parallel Loop Construct

. . . . . . . . . . . . . . . . . . . . . . . . . . . . 95

2.10.2 parallel sections Construct

. . . . . . . . . . . . . . . . . . . . . 97

2.10.3 parallel workshare Construct

2.10.4 Parallel Loop SIMD Construct

2.10.5 target teams construct

. . . . . . . . . . . . . . . . . . . . 99

. . . . . . . . . . . . . . . . . . . . . . . 100

. . . . . . . . . . . . . . . . . . . . . . . . . . 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

2.10.10 Teams Distribute Parallel Loop Construct

. . . . . . . . . . 106

. . . . . . . . . . . . . . 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

2.11

Tasking Constructs

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 113

2.11.1 task Construct

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 113

2.11.2 taskyield Construct

2.11.3 Task Scheduling

2.12

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . 117

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 118

Master and Synchronization Constructs

2.12.1 master Construct

2.12.3 barrier Construct

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 122

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 123

2.12.4 taskwait Construct

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 125

2.12.5 taskgroup Construct

2.12.6 atomic Construct

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . 126

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 127

2.12.7 flush Construct

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 134

2.12.8 ordered Construct

Cancellation Constructs

. . . . . . . . . . . . . . . . . . . . . . 120

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 120

2.12.2 critical Construct

2.13

. . . . 111

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 138

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 140

iii

................
................

In order to avoid copyright disputes, this page is only a partial summary.

Google Online Preview   Download