y---------------…F0 rtran(c0nt)"=-------=-------y 123 One or more blanks or horizontal tabs must be used to separate adjacent keywords in directives in free source form,except in the following cases,where white space is optional between the given set of keywords: 4 declare reduction declare simd 6 declare target distribute parallel do 6 distribute parallel do simd 9 distribute simd 10 do simd 11 end atomic 12 end critical 13 end distribute 14 end distribute parallel do 15 end distribute parallel do simd end distribute simd 17 end do 18 end do simd 19 end master 20 end ordered 21 end parallel 22 end parallel do 23 end parallel do simd 24 end parallel sections 25 end parallel workshare 26 end sections 27 end simd Chapter 2 Directives 29
Chapter 2 Directives 29 Fortran (cont.) One or more blanks or horizontal tabs must be used to separate adjacent keywords in directives in free source form, except in the following cases, where white space is optional between the given set of keywords: declare reduction declare simd declare target distribute parallel do distribute parallel do simd distribute simd do simd end atomic end critical end distribute end distribute parallel do end distribute parallel do simd end distribute simd end do end do simd end master end ordered end parallel end parallel do end parallel do simd end parallel sections end parallel workshare end sections end simd 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
---------=---F0rtan(cont)------------y end single 2 end target end target data 4 end target teams end target teams distribute end target teams distribute parallel do end target teams distribute parallel do simd end target teams distribute simd 9 end task 10 end task group 11 end teams end teams distribute 13 end teams distribute parallel do end teams distribute parallel do simd 购 end teams distribute simd 6 end workshare parallel do 18 parallel do simd 9 parallel sections 20 parallel workshare 21 target data 22 target teams 23 target teams distribute 24 target teams distribute parallel do 名 target teams distribute parallel do simd 26 target teams distribute simd 30 OpenMP API.Version 4.0-July 2013
30 OpenMP API • Version 4.0 - July 2013 Fortran (cont.) end single end target end target data end target teams end target teams distribute end target teams distribute parallel do end target teams distribute parallel do simd end target teams distribute simd end task end task group end teams end teams distribute end teams distribute parallel do end teams distribute parallel do simd end teams distribute simd end workshare parallel do parallel do simd parallel sections parallel workshare target data target teams target teams distribute target teams distribute parallel do target teams distribute parallel do simd target teams distribute simd 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
target update 2 teams distribute 0 teams distribute parallel do teams distribute parallel do simd teams distribute simd 6 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): 123456789 9 ISomp parallel do ISomp shared(a,b,c) 11 12 !Somp parallel& 13 !Somp&do shared(a,b,c) 15 !Somp paralleldo shared(a,b,c) 16 Fortran 172.1.3 Stand-Alone Directives 18 Summary 19 Stand-alone directives are executable directives that have no associated user code. 20 Description 2 Stand-alone directives do not have any associated executable user code.Instead,they represent executable statements that typically do not have succinct equivalent statements in the base languages.There are some restrictions on the placement of a stand-alone 2425 directive withina program.A tand-alon e direc ive may be placed ony ata point where a base language executable statement is allowed. Chapter 2 Directives 31
Chapter 2 Directives 31 target update teams distribute teams distribute parallel do teams distribute parallel do simd teams distribute simd 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): !23456789 !$omp parallel do & !$omp shared(a,b,c) !$omp parallel & !$omp&do shared(a,b,c) !$omp paralleldo shared(a,b,c) Fortran 2.1.3 Stand-Alone Directives Summary Stand-alone directives are executable directives that have no associated user code. Description Stand-alone directives do not have any associated executable user code. Instead, they represent executable statements that typically do not have succinct equivalent statements in the base languages. There are some restrictions on the placement of a stand-alone directive within a program. A stand-alone directive may be placed only at a point where a base language executable statement is allowed. 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
1 Restrictions C/C++ For C/C++,a stand-alone directive may not be used in place of the statement following an if,while,do,switch,or label.See Appendix B for the formal grammar. C/C++ -Fortran For Fortran,a stand-alone directive may not be used as the action statement in an if statement or as the executable statement following a label if the label is referenced in the program. Fortran 7 2.2 Conditional Compilation 8 In implementations that support a preprocessor,themacro name is defined to have the decimal of the version of thOpenMP API that the implementation por 12 If this macro is the subject of a #define or a #undef preprocessing directive,the behavior is unspecifiec -Fortran- The OpenMP API requires Fortran lines to be compiled conditionally,as described in the following sections. 152.2.1 Fixed Source Form Conditional Compilation 16 Sentinels 18 The following conditional compilation sentinels are recognized in fixed form source 令|*9|c9 9 To enable conditional compilation,a line with a conditional compilation sentinel must 20 satisfy the following criteria The sentinel must start in column I and appear as a single word with no intervening white space 32 OpenMP API.Version 4.0-July 2013
32 OpenMP API • Version 4.0 - July 2013 Restrictions C/C++ For C/C++, a stand-alone directive may not be used in place of the statement following C/C++ an if, while, do, switch, or label. See Appendix B for the formal grammar. Fortran For Fortran, a stand-alone directive may not be used as the action statement in an if statement or as the executable statement following a label if the label is referenced in Fortran the program. 2.2 Conditional Compilation In implementations that support a preprocessor, the _OPENMP macro name is defined to have the decimal value yyyymm where yyyy and mm are the year and month designations of the version of the OpenMP API that the implementation supports. If this macro is the subject of a #define or a #undef preprocessing directive, the behavior is unspecified. Fortran The OpenMP API requires Fortran lines to be compiled conditionally, as described in the following sections. 2.2.1 Fixed Source Form Conditional Compilation Sentinels The following conditional compilation sentinels are recognized in fixed form source files: To enable conditional compilation, a line with a conditional compilation sentinel must satisfy the following criteria: • The sentinel must start in column 1 and appear as a single word with no intervening white space. !$ | *$ | c$ 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
12 After the sentinel is replaced with two spaces,initial lines must have a space or zero in column 6 and only white space and numbers in columns I through 5. 9 After the sentinel is replaced with two spaces,continuation lines must have a 45 character other than a space or zero in column 6 and only white space in columns I through 5. 67 If these criteria are met,the sentinel is replaced by two spaces.If these criteria are not met,the line is left unchanged. Note-in the following example,the two forms for specifying conditional compilation in fixed source form are equivalent(the first line represents the position of the first 9 10 columns): 11 c23456789 1213 1$10 iam omp_get_thread_num()+ $& index #ifdef_OPENMP 10 iam omp get thread num()+ 18 index #endif 202.2.2 Free Source Form Conditional Compilation S Sentinel 22 The following conditional compilation sentinel is recognized in free form source files: 4$ 23 To enable conditional compilation,a line with a conditional compilation sentinel must 2 satisfy the following criteria: 25 The sentinel can appear in any column but must be preceded only by white space 26 The sentinel must appear as a single word with no intervening white space. 27 Initial lines must have a space after the sentinel. Chapter 2 Directives 33
Chapter 2 Directives 33 Fortran (cont.) • After the sentinel is replaced with two spaces, initial lines must have a space or zero in column 6 and only white space and numbers in columns 1 through 5. • After the sentinel is replaced with two spaces, continuation lines must have a character other than a space or zero in column 6 and only white space in columns 1 through 5. If these criteria are met, the sentinel is replaced by two spaces. If these criteria are not met, the line is left unchanged. Note – in the following example, the two forms for specifying conditional compilation in fixed source form are equivalent (the first line represents the position of the first 9 columns): c23456789 !$ 10 iam = omp_get_thread_num() + !$ & index #ifdef _OPENMP 10 iam = omp_get_thread_num() + & index #endif 2.2.2 Free Source Form Conditional Compilation Sentinel The following conditional compilation sentinel is recognized in free form source files: To enable conditional compilation, a line with a conditional compilation sentinel must satisfy the following criteria: • The sentinel can appear in any column but must be preceded only by white space. • The sentinel must appear as a single word with no intervening white space. • Initial lines must have a space after the sentinel. !$ 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