This chapter gives guidelines for converting legacy programs using Sun or Cray directives and pragmas to OpenMP.
4.1 Converting Legacy Fortran Directives
Legacy Fortran programs use either Sun or Cray style parallelization directives. A description of these directives can be found in the chapter Parallelization in the Fortran Programming Guide.
4.1.1 Converting Sun-Style Directives
The following tables give OpenMP near equivalents to Sun parallelization directives and their subclauses. These are only suggestions.
TABLE 4-1 Converting Sun Parallelization Directives to OpenMP
Sun Directive
|
Equivalent OpenMP Directive
|
C$PAR DOALL [qualifiers]
|
!$omp parallel do [qualifiers]
|
C$PAR DOSERIAL
|
No exact equivalent. You can use:
!$omp master
loop
!$omp end master
|
C$PAR DOSERIAL*
|
No exact equivalent. You can use:
!$omp master
loopnest
!$omp end master
|
C$PAR TASKCOMMON block[,...]
|
!$omp threadprivate (/block/[,...])
|
The DOALL directive can take the following optional qualifier clauses:
TABLE 4-2 DOALL Qualifier Clauses and OpenMP Equivalent Clauses
Sun DOALL Clause
|
OpenMP PARALLEL DO Equivalent Clauses
|
PRIVATE(v1,v2,...)
|
private(v1,v2,...)
|
SHARED(v1,v2,...)
|
shared(v1,v2,...)
|
MAXCPUS(n)
|
num_threads(n). No exact equivalent.
|
READONLY(v1,v2,...)
|
No exact equivalent. For the private variables only in the list you can achieve the same effect by using firstprivate(list).
|
STOREBACK(v1,v2,...)
|
No exact equivalent. For the private variables only in the list you can achieve the same effect by using lastprivate(list).
|
SAVELAST
|
No exact equivalent. For private variables only you can achieve the same effect by using lastprivate(list).
|
REDUCTION(v1,v2,...)
|
reduction(operator:v1,v2,...) Must supply the reduction operator as well as the list of variables.
|
SCHEDTYPE(spec)
|
schedule(spec) (See TABLE 4-3)
|
The SCHEDTYPE(spec) clause accepts the following scheduling specifications:
TABLE 4-3 SCHEDTYPE Scheduling and OpenMP schedule Equivalents
SCHEDTYPE(spec)
|
OpenMP schedule(spec) Clause Equivalent
|
SCHEDTYPE(STATIC)
|
schedule(static)
|
SCHEDTYPE(SELF(chunksize))
|
schedule(dynamic,chunksize)
Default chunksize is 1.
|
SCHEDTYPE(FACTORING(m))
|
No OpenMP equivalent.
|
SCHEDTYPE(GSS(m))
|
schedule(guided, m)
Default m is 1.
|
4.1.1.1 Issues Between Sun-Style Directives and OpenMP
- Scoping of variables (shared or private) must be declared explicitly with OpenMP. With Sun directives, the compiler uses its own default scoping rules for variables not explicitly scoped in a PRIVATE or SHARED clause: all scalars are treated as PRIVATE, and all array references are SHARED. With OpenMP, the default data scope is SHARED unless a DEFAULT(PRIVATE) clause appears on the PARALLEL DO directive.
- Clauses on OpenMP directives do not accumulate; that is, there can be at most only one type of each clause on a directive.
- Since there is no DOSERIAL directive, mixing automatic and explicit OpenMP parallelization may have different effects: some loops may be automatically parallelized that would not have been with Sun directives.
- Because OpenMP provides a richer parallelism model, it might often be possible to get better performance by redesigning the parallelism strategies of a program that uses Sun directives to take advantage of these features.
4.1.2 Converting Cray-Style Directives
Cray-style Fortran parallelization directives are identical to Sun-style except that the sentinel that identifies these directives is !MIC$. Also, the set of qualifier clauses on the !MIC$ DOALL is different:
TABLE 4-4 OpenMP Equivalents for Cray-Style DOALL Qualifier Clauses
Cray DOALL Clause
|
OpenMP PARALLEL DO Equivalent Clauses
|
SHARED(v1,v2,...)
|
SHARED(v1,v2,...)
|
PRIVATE(v1,v2,...)
|
PRIVATE(v1,v2,...)
|
AUTOSCOPE
|
No equivalent. Scoping must be explicit, or with the DEFAULT clause.
|
SAVELAST
|
No exact equivalent. For private variables only you can achieve the same effect by using lastprivate(list).
|
MAXCPUS(n)
|
num_threads(n). No exact equivalent.
|
GUIDED
|
schedule(guided, m)
Default m is 1.
|
SINGLE
|
schedule(dynamic,1)
|
CHUNKSIZE(n)
|
schedule(dynamic,n)
|
NUMCHUNKS(m)
|
schedule(dynamic,n/m) where n is the number of iterations
|
4.1.2.1 Issues Between Cray-Style Directives and OpenMP Directives
The differences are the same as for Sun-style directives, except that there is no equivalent for the Cray AUTOSCOPE.
4.2 Converting Legacy C Pragmas
The C compiler accepts legacy pragmas for explicit parallelization. These are described in the C User's Guide. As with the Fortran directives, these are only suggestions.
The legacy parallelization pragmas are:
TABLE 4-5 Converting Legacy C Parallelization Pragmas to OpenMP
Legacy C Pragma
|
Equivalent OpenMP Pragma
|
#pragma MP taskloop [clauses]
|
#pragma omp parallel for [clauses]
|
#pragma MP serial_loop
|
No exact equivalent. You can use
#pragma omp master
loop
|
#pragma MP serial_loop_nested
|
No exact equivalent. You can use
#pragma omp master
loopnest
|
The taskloop pragma can take on one or more of the following optional clauses:
TABLE 4-6 taskloop Optional Clauses and OpenMP Equivalents
taskloop Clause
|
OpenMP parallel for Equivalent Clause
|
maxcpus(n)
|
No equivalent.
|
private(v1,v2,...)
|
private(v1,v2,...)
|
shared(v1,v2,...)
|
shared(v1,v2,...)
|
readonly(v1,v2,...)
|
No exact equivalent. For the private variables only in the list you can achieve the same effect by using firstprivate(list).
|
storeback(v1,v2,...)
|
No exact equivalent. For the private variables only in the list you can achieve the same effect by using lastprivate(list).
|
savelast
|
No exact equivalent. For private variables only you can achieve the same effect by using lastprivate(list).
|
reduction(v1,v2,...)
|
reduction(operator:v1,v2,...) Must supply the reduction operator as well as the list.
|
schedtype(spec)
|
schedule(spec) (See TABLE 4-7)
|
The schedtype(spec) clause accepts the following scheduling specifications:
TABLE 4-7 SCHEDTYPE Scheduling and OpenMP schedule Equivalents
schedtype(spec)
|
OpenMP schedule(spec) Clause Equivalent
|
SCHEDTYPE(STATIC)
|
schedule(static)
|
SCHEDTYPE(SELF(chunksize))
|
schedule(dynamic,chunksize)
Note: Default chunksize is 1.
|
SCHEDTYPE(FACTORING(m))
|
No OpenMP equivalent.
|
SCHEDTYPE(GSS(m))
|
schedule(guided, m)
Default m is 1.
|
4.2.1 Issues Between Legacy C Pragmas and OpenMP
- Variables declared within a parallel construct are scoped private. A default(none) clause on a #pragma omp parallel for directive causes the compiler to flag variables not scoped explicitly.
- Clauses on OpenMP directives do not accumulate; that is, there can be at most only one type of each clause on a directive.
- Since there is no serial_loop directive, mixing automatic and explicit OpenMP parallelization may have different effects: some loops may be automatically parallelized that would not have been with legacy C directives.
- Because OpenMP provides a richer parallelism model, it might often be possible to get better performance by redesigning the parallelism strategies of a program that uses legacy C directives to take advantage of these features.