Parallel Programming Using OpenMP
OpenMP is emerging as a standard for parallel processing on shared memory multiprocessor systems.
Directives within the code designate how and what parts of the code are to be parallelized;
environmental variables and a runtime library are used to enable use of the multiprocessors.
Overviews of OpenMP can be found in
OpenMP Overview on this web site and at
Wikipedia;
for details, see the OpenMP web-site and the
OpenMP 2.5 Specification.
Note the auto-parallel and SCSL library methods described in the prior two sections are
implemented through OpenMP on SGI systems.
Examples OpenMP parallel code for "Hello World" in Fortran, C, and C++ are available from
Wikipedia.
More comprehensive OpenMP example programs are provided from the
Sample Programs link off of the
OpenMP web site.
To compile an OpenMP program on SGI
using OpenMP directives, use the -openmp compiler option. With Fortran
programs, you will also need to specify the "-fpp" Fortran precompiler option. For example, to
compile a Fortran program called "my_prog.f" as "my_prog"
which contains OpenMP directives, you could enter:
ifort -o my_prog my_prog.f -fpp -openmp
In order to execute an OpenMP program and utilize the parallel programming environment, you need to specify the
number of threads to be used for processing.
This can be done internally within the program by using the OpenMP
"omp_set_num_threads" library call
or by defining the "OMP_NUM_THREADS" environmental variable. For example,
when using the Bourne, Korn, or Bash shells, you could set the environmental variable to use four processors
and execute the compiled program "my_prog"by entering the following pair of commands:
export OMP_NUM_THREADS=4
./my_prog
Note: C Shell and C Shell derivatives would use:
setenv OMP_NUM_THREADS 4
./my_prog
Some OpenMP Tutorials include:
|