Text that applies only to programs whose base language is C90 only is shown as 2 follows C90 C90 specific text. C90 g Text that applies only to programs whose base language is C99 only is shown as follows: C99 C99 specific text... C99 7 Text that applies only to programs whose base language is C++only is shown as follows: C++ 8 C++specific text. C++ 0 Text that applies only to programs whose base language is Fortran is shown as follows: Fortran Fortran specific text...... Fortran Where an entire page consists of,for example,Fortran specific text,a marker is shown 13 at the top of the page like this: F0 rtran(c0nt)=-=-"-=-=--"-=----y 14 Some text is for information only,and is not part of the normative specification.Such text is designated as a note,like this: 16 Note-Non-normative text.. 24 OpenMP API.Version 4.0-July 2013
24 OpenMP API • Version 4.0 - July 2013 Text that applies only to programs whose base language is C90 only is shown as follows: C90 C90 C90 specific text... Text that applies only to programs whose base language is C99 only is shown as follows: C99 C99 C99 specific text... Text that applies only to programs whose base language is C++ only is shown as follows: C++ C++ C++ specific text... Text that applies only to programs whose base language is Fortran is shown as follows: Fortran Fortran Fortran specific text...... Where an entire page consists of, for example, Fortran specific text, a marker is shown Fortran (cont.) at the top of the page like this: Some text is for information only, and is not part of the normative specification. Such text is designated as a note, like this: Note – Non-normative text.... 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
1 CHAPTER 2 Directives 3 r describes the syntax and behavior of OpenMP directives,and is divided 4 5 The language-specific directive format(Section 2.1 on page 26) 6 .Mechanisms to control conditional compilation(Section 2.2 on page 32) How to specify and to use array sections for all base languages(Section 2.4 on page 8 42) 9 Control of OpenMP API ICVs(Section 2.3 on page 34) 0 .Details of each OpenMP directive(Section 2.5 on page 44 to Section 2.16 on page 11 186) =C/C++ 1 In C/C++,OpenMP directives are specified by using the #pragma mechanism provided 13 by the C and C++standards. C/C++ -Fortran In Fortran,OpenMP directives are specified by using special comments that are 1 identified by unique sentinels.Also,a special comment form is available for conditional 16 compilation Fortran 17 Compilers can therefore ignore OpenMP directives and conditionally compiled code if 81920 suppor of the OpenMP API isnot provided or enabled.Acompliant imp must provide an option or interface that ensures that underlying support of all OpenMP directives and OpenMP conditional compilation mechanisms is enabled.In the remainder of this document,the phrase OpenMP compilation is used to mean a 22 compilation with these OpenMP features enabled. 25
25 CHAPTER 2 Directives This chapter describes the syntax and behavior of OpenMP directives, and is divided into the following sections: • The language-specific directive format (Section 2.1 on page 26) • Mechanisms to control conditional compilation (Section 2.2 on page 32) • How to specify and to use array sections for all base languages (Section 2.4 on page 42) • Control of OpenMP API ICVs (Section 2.3 on page 34) • Details of each OpenMP directive (Section 2.5 on page 44 to Section 2.16 on page 186) C/C++ In C/C++, OpenMP directives are specified by using the #pragma mechanism provided C/C++ by the C and C++ standards. Fortran In Fortran, OpenMP directives are specified by using special comments that are identified by unique sentinels. Also, a special comment form is available for conditional Fortran compilation. Compilers can therefore ignore OpenMP directives and conditionally compiled code if support of the OpenMP API is not provided or enabled. A compliant implementation must provide an option or interface that ensures that underlying support of all OpenMP directives and OpenMP conditional compilation mechanisms is enabled. In the remainder of this document, the phrase OpenMP compilation is used to mean a compilation with these OpenMP features enabled. 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
Fortran Restrictions The following restriction applies to all OpenMP directives: 3 OpenMP directives may not appear in PURE or ELEMENTAL procedures Fortran 42.1 Directive Format -C/C++ 56 OpenMP directives for C/C++are specified with the pragm The syntax of an OpenMP directive is formally spec a preprocessing directive. ified by the grammar in Appendix B,and informally as follows #pragma omp directive-name [clause[[.]clause1...new-line Each directive starts with #pragma omp.The remainder of the directive follows the 9 conventio of theCand +standards for compiler directives.In particular,white space can be used before and after the#and sometimes white space must be used to separate the words in a directive.Preprocessing tokens following the #pragma omp 12 are subject to macro replacement. 14 Some OpenMP directives may be composed of consecutive #pragma preprocessing directives if specified in their syntax 15 Directives are case-sensitive. 6 An OpenMP executable directive applies to at most one succeeding statement,which 17 must be a structured block C/C++ Fortran OpenMP directives for Fortran are specified as follows sentinel directive-name [clause[f.I clausej. All OpenMP compiler directives must begin with a directive sentinel.The format of a 0 sentinel differs between fixed and free-form source files,as described in Section 2.1.1 21 on page 27 and Section 2.1.2 on page 28. 26 OpenMP API.Version 4.0-July 2013
26 OpenMP API • Version 4.0 - July 2013 Fortran Restrictions The following restriction applies to all OpenMP directives: Fortran • OpenMP directives may not appear in PURE or ELEMENTAL procedures. 2.1 Directive Format C/C++ OpenMP directives for C/C++ are specified with the pragma preprocessing directive. The syntax of an OpenMP directive is formally specified by the grammar in Appendix B, and informally as follows: Each directive starts with #pragma omp. The remainder of the directive follows the conventions of the C and C++ standards for compiler directives. In particular, white space can be used before and after the #, and sometimes white space must be used to separate the words in a directive. Preprocessing tokens following the #pragma omp are subject to macro replacement. Some OpenMP directives may be composed of consecutive #pragma preprocessing directives if specified in their syntax. Directives are case-sensitive. An OpenMP executable directive applies to at most one succeeding statement, which C/C++ must be a structured block. Fortran OpenMP directives for Fortran are specified as follows: All OpenMP compiler directives must begin with a directive sentinel. The format of a sentinel differs between fixed and free-form source files, as described in Section 2.1.1 on page 27 and Section 2.1.2 on page 28. #pragma omp directive-name [clause[ [,] clause]...] new-line sentinel directive-name [clause[[,] clause]...] 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
Directives are case insensitive.Directives cannot be embedded within continued statements,and statements cannot be embedded within directives. In order to simplify the presentation,free form is used for the syntax of OpenMP g directives for Fortran in the remainder of this document,except as noted. Fortran 56 Only one directive-name can be specified per directive(note that this includes combined directives,see Section 2.10 on page 95).The order in which clauses appear on directives is not significant.Clauses on directives may be repeated as needed,subject to the restrictions listed in the description of each clause. Some data-sharing attribute clauses(Section 2.14.3 on page 155),data copying clauses 10 (Section 2.14.4 on page 173),the threadprivate directive(Section 2.14.2 on page 11 150)and the flush directive (Section 2.12.7 on page 134)accept a list.A list consists 12 of a comma-separated collection of one or more list items. =C/C++ 131415 secti,subject to the restrictions specified in eh of the sections describing elauses and directives fo Section which a list appears. C/C++ Fortran 16 A list item is a variable,array section or common block name(enclosed in slashes), 1 subject to the restrictions specified in Section 2.4 on page 42 and in each of the sections 18 describing clauses and directives for which a list appears. -Fortran- Fortran 202.1.1 Fixed Source Form Directives 21 The following sentinels are recognized in fixed form source files 2 Sentinels must start in column I and appear as a single word with no intervening characters.Fortran fixed form line length,white space,continuation,and column rules 242500 column 6. Chapter 2 Directives 27
Chapter 2 Directives 27 Directives are case insensitive. Directives cannot be embedded within continued statements, and statements cannot be embedded within directives. In order to simplify the presentation, free form is used for the syntax of OpenMP Fortran directives for Fortran in the remainder of this document, except as noted. Only one directive-name can be specified per directive (note that this includes combined directives, see Section 2.10 on page 95). The order in which clauses appear on directives is not significant. Clauses on directives may be repeated as needed, subject to the restrictions listed in the description of each clause. Some data-sharing attribute clauses (Section 2.14.3 on page 155), data copying clauses (Section 2.14.4 on page 173), the threadprivate directive (Section 2.14.2 on page 150) and the flush directive (Section 2.12.7 on page 134) accept a list. A list consists of a comma-separated collection of one or more list items. C/C++ A list item is a variable or array section, subject to the restrictions specified in Section 2.4 on page 42 and in each of the sections describing clauses and directives for C/C++ which a list appears. Fortran A list item is a variable, array section or common block name (enclosed in slashes), subject to the restrictions specified in Section 2.4 on page 42 and in each of the sections Fortran describing clauses and directives for which a list appears. Fortran 2.1.1 Fixed Source Form Directives The following sentinels are recognized in fixed form source files: Sentinels must start in column 1 and appear as a single word with no intervening characters. Fortran fixed form line length, white space, continuation, and column rules apply to the directive line. Initial directive lines must have a space or zero in column 6, and continuation directive lines must have a character other than a space or a zero in column 6. !$omp | c$omp | *$omp 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
Comments may appear on the same line as a directive.The exclamation point initiates a comment when it appears after column 6.The comment extends to the end of the source line and is igored.If the first non-blank the directive sentinel of an 4 initial or continuation directive line is an exclamation point,the line is ignored. Note-in the following example,the three formats for specifying the directive are equivalent(the first line represents the position of the first 9 columns): c23456789 !Somp parallel do shared(a,b,c) 10 11 csomp parallel do 12 cSomp+shared(a,b,c) 13 4 csomp paralleldoshared(a,b,c) 152.1.2 Free Source Form Directives The following sentinel is recognized in free form source files: Somp 718 The sentinel can appear in any ol as long as it is preceded only by white space (spaces and tab characters).It must appear as a single word with oinrvening 19 character.Fortran free form line length,white space,and continuation rules apply to the 20 directive line.Initial directive lines must have a space after the sentinel.Continued 21 directive lines must have an ampersand(&)as the last non-blank character on the line 22 2324 ampersan 566728 hetcharacter after the directive sentine isnx line is ignored. 28 OpenMP API.Version 4.0-July 2013
28 OpenMP API • Version 4.0 - July 2013 Fortran (cont.) Comments may appear on the same line as a directive. The exclamation point initiates a comment when it appears after column 6. The comment extends to the end of the source line and is ignored. If the first non-blank character after the directive sentinel of an initial or continuation directive line is an exclamation point, the line is ignored. Note – in the following example, the three formats for specifying the directive are equivalent (the first line represents the position of the first 9 columns): c23456789 !$omp parallel do shared(a,b,c) c$omp parallel do c$omp+shared(a,b,c) c$omp paralleldoshared(a,b,c) 2.1.2 Free Source Form Directives The following sentinel is recognized in free form source files: The sentinel can appear in any column as long as it is preceded only by white space (spaces and tab characters). It must appear as a single word with no intervening character. Fortran free form line length, white space, and continuation rules apply to the directive line. Initial directive lines must have a space after the sentinel. Continued directive lines must have an ampersand (&) as the last non-blank character on the line, prior to any comment placed inside the directive. Continuation directive lines can have an ampersand after the directive sentinel with optional white space before and after the ampersand. Comments may appear on the same line as a directive. The exclamation point (!) initiates a comment. The comment extends to the end of the source line and is ignored. If the first non-blank character after the directive sentinel is an exclamation point, the line is ignored. !$omp 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