Fortran 95 Openmp Directives
Fortran 95 Openmp Directives
The Sun Fortran 95 compiler supports the OpenMP 2.0 Fortran API. The
-mp=openmp and -openmp compiler flags enable these directives.
This section lists the OpenMP directives, library routines, and environment variables
supported by f95. For details about parallel programming with OpenMP, see the
OpenMP 2.0 Fortran specification at http://www.openmp.org/.
The following table summarizes the OpenMP directives supported by f95. Items
enclosed in square brackets ([...]) are optional. The compiler permits comments to
follow an exclamation mark (!) on the same line as the directive. When compiling
with -mp=openmp or -openmp, the CPP/FPP variable _OPENMP is defined and
may be used for conditional compilation within #ifdef _OPENMP and #endif.
1
TABLE D-2 Summary of OpenMP Directives in Fortran 95 (Continued)
2 •
TABLE D-2 Summary of OpenMP Directives in Fortran 95 (Continued)
Synchronization Directives
MASTER Directive !$OMP MASTER
block of Fortran statements with no transfers in or out
!$OMP END MASTER
4 •
TABLE D-2 Summary of OpenMP Directives in Fortran 95 (Continued)
All the threads in the team share the variables that appear in
list, and access the same storage area.
DEFAULT Clause DEFAULT(PRIVATE | SHARED | NONE)
6 •
TABLE D-2 Summary of OpenMP Directives in Fortran 95 (Continued)
OMP_GET_NUM_THREADS Function
INTEGER FUNCTION OMP_GET_NUM_THREADS()
Returns the number of threads currently in the team executing the
parallel region from which it is called.
OMP_GET_MAX_THREADS Function
INTEGER FUNCTION OMP_GET_MAX_THREADS()
Returns the maximum value that can be returned by calls to the
OMP_GET_NUM_THREADS function.
OMP_GET_THREAD_NUM Function
INTEGER FUNCTION OMP_GET_THREAD_NUM()
Returns the thread number within the team. This is a number
between 0 and OMP_GET_NUM_THREADS()-1.The master thread is
thread 0.
OMP_GET_NUM_PROCS Function
INTEGER FUNCTION OMP_GET_NUM_PROCS()
Returns the number of processors that are available to the program.
OMP_IN_PARALLEL Function
LOGICAL FUNCTION OMP_IN_PARALLEL()
Returns .TRUE. if called from within the dynamic extent of a region
executing in parallel, and .FALSE. otherwise.
8 •
TABLE D-3 Summary of Fortran 95 OpenMP Library Routines (Continued)
OMP_SET_DYNAMIC Subroutine
SUBROUTINE OMP_SET_DYNAMIC(logical_expr)
OMP_GET_DYNAMIC Function
LOGICAL FUNCTION OMP_GET_DYNAMIC()
Two types of locks are supported: simple locks and nestable locs. Nestable locks may
be locked multiple times by the same thread before being unlocked; simple locks
may not be locked if they are already in a locked state. Simple lock variables may
only be passed to simple lock routines, and nested lock variables only to nested lock
routines.
OMP_INIT_LOCK Subroutine
SUBROUTINE OMP_INIT_LOCK(var)
SUBROUTINE OMP_INIT_NEST_LOCK(var)
OMP_SET_LOCK Subroutine
SUBROUTINE OMP_SET_LOCK(var)
SUBROUTINE OMP_SET_NEST_LOCK(var)
Forces the executing thread to wait until the specified lock is
available. The thread is granted ownership of the lock when it is
available.
OMP_UNSET_LOCK Subroutine
SUBROUTINE OMP_UNSET_LOCK(var)
SUBROUTINE OMP_UNSET_NEST_LOCK(var)
Releases the executing thread from ownership of the lock. Behavior
is undefined if the thread does not own that lock.
OMP_TEST_LOCK Function
LOGICAL FUNCTION OMP_TEST_LOCK(var)
INTEGER FUNCTION OMP_TEST_NEST_LOCK(nvar)
Attempts to set the lock associated with lock variable. Returns
.TRUE. if the simple lock was set successfully, .FALSE. otherwise.
OMP_TEST_NEST_LOCK returns the new nesting count if the lock
associated with nvar was set successfully, otherwise it returns 0.
Timing Routines
These two routines support a portable wall-clock timer.
OMP_GET_WTIME Function
DOUBLE PRECISION FUNCTION OMP_GET_WTIME()
Returns a double precision value equal to the elapsed wallclock
time in seconds since “some arbitrary time in the past”
OMP_GET_WTICK Function
DOUBLE PRECISION FUNCTION OMP_GET_WTICK()
Returns a double precision value equal to the number of seconds
between successive clock ticks.
10 •
OpenMP Environment Variables
The following table summarizes the OpenMP Fortran API environment variables
that control the execution of OpenMP programs.
OMP_SCHEDULE
Sets schedule type for DO and PARALLEL DO directives specified with schedule type
RUNTIME. Example: setenv OMP_SCHEDULE “GUIDED,4”. If not defined, a default value
of STATIC is used. Value is “type[,chunk]”
OMP_NUM_THREADS
Sets the number of threads to use during execution, unless set by a call to
OMP_SET_NUM_THREADS() subroutine. Example: setenv OMP_NUM_THREADS 16
If not set, a default of 1 is used. Value is a positive integer.
OMP_DYNAMIC
Enables or disables dynamic adjustment of the number of threads available for execution
of parallel regions. Example: setenv OMP_DYNAMIC FALSE
If not set, a default value of TRUE is used. Value is TRUE or FALSE.
OMP_NESTED
Enables or disables nested parallelism. Example: setenv OMP_NESTED TRUE
Value is TRUE or FALSE. The default, if not set, is FALSE.