next up previous contents
Next: submittting multi-threaded jobs Up: submitting scalar jobs to Previous: submitting scalar jobs to   Contents

compiling and running OpenMP codes

If you have a source code containing OpenMP compiler directives you can compile and run them on an SMP (Symmetric Multi-Processor) compute node (e.g dual, quad cpu) to take advantage of all processors. There are two compilers available for this.
(1) The free Omni OpenMP compilers from pccluster.org. These use the underlying GNU compilers. To compile an OpenMP f77 or C program:
   omf77 [compiler options] -o myexec.exe  file.f -lpthread
   omcc  [compiler options] -o myexec.exe  file.c -lpthread
See the documentation in :
file:/opt/omni/lib/openmp/doc/index.html
on the front end server. By default the compiled code will run using 2 cpus if it is compiled on a dual cpu host and on 4 cpus if compiled on a quad processor etc. You can explicitly set the number of threads by setting the environment variable OMPC_NUM_PROCS. See the documentation.
(2) Using the PGI OpenMP compilers. If you have purchased a PGI compiler then you can compile OpenMP source code by using the -mp option to each of the compilers. e.g to compile Fortran 77, C or C++ OpenMP code :
  pgf77 [compiler options] -o myexec.exe -mp file.f   -lpthread
  pgf90 [compiler options] -o myexec.exe -mp file.f90 -lpthread
  pgcc  [compiler options] -o myexec.exe -mp file.c   -lpthread
  pgCC  [compiler options] -o myexec.exe -mp file.cc  -lpthread
You should use the PGI -Bstatic option to ensure that your code is statically linked in case the compiler libraries are not installed on the compute nodes.

For the PGI compilers you can control the number of parallel threads at execution time by setting the environment variable OMP_NUM_THREADS to the appropriate value. Unlike the Omni compilers the default number of threads is 1. To execute code on a dual or quad processor you will therefore need explicitly to explicitly set this variable - e.g on a dual cpu host you will need to type

    setenv OMP_NUM_THREADS 2
if you are using csh or tcsh shells, or
    export OMP_NUM_THREADS=2
if you are using the sh or bash shells. You may submit an OpenMP parallel job to a single SMP compute node using SGE. In which case you should probable set the OMP_NUM_THREADS variable in your job script. See [*].

There is an extensive documentation to OpenMP programming in the PGI Users' Guide. (3) Using the Intel OPenMP compilers. If you have an Intel Fortran (ifc) license or Intel C (icc) license then you can compile OpenMP source code using the -openmp opt ion :

 ifc   [compiler options] -o myexec.exe -openmp file.f   -lpthread
 ifc   [compiler options] -o myexec.exe -openmp file.f90 -lpthread
 icc   [compiler options] -o myexec.exe -openmp file.c   -lpthread
 icc   [compiler options] -o myexec.exe -openmp file.cca -lpthread
You should use the Intel -static option to ensure that your code is statically linked in case the compiler libraries are not installed on the compute nodes.

By default the number of threads is the same as the number of processors on the host you run the code - eg 2 for a dual processor machine.


next up previous contents
Next: submittting multi-threaded jobs Up: submitting scalar jobs to Previous: submitting scalar jobs to   Contents
2004-06-17