Skip to content

Compiling Hybrid Programs

Hybrid programs require including header files:

Language Header Files
Fortran 77 INCLUDE 'omp_lib.h'
INCLUDE 'mpif.h'
Fortran 90 use omp_lib
INCLUDE 'mpif.h'
Fortran 95 use omp_lib
INCLUDE 'mpif.h'
C #include <mpi.h>
#include <omp.h>
C++ #include <mpi.h>
#include <omp.h>

A few examples illustrate hybrid programs with task parallelism of OpenMP:

This example illustrates a hybrid program with loop-level (data) parallelism of OpenMP:

To see the available MPI libraries:

$ module avail impi
$ module avail openmpi

The following tables illustrate how to compile your hybrid (MPI/OpenMP) program. Any compiler flags accepted by Intel ifort/icc compilers are compatible with their respective MPI compiler.

Intel MPI (IMPI) with Intel Compiler

Language Command
Fortran 77 $ mpiifort -qopenmp myprogram.f -o myprogram
Fortran 90 $ mpiifort -openmp myprogram.f90 -o myprogram
Fortran 95 $ mpiifort -openmp myprogram.f90 -o myprogram
C $ mpiicc -qopenmp myprogram.c -o myprogram
C++ $ mpiicpc -qopenmp myprogram.cpp -o myprogram

OpenMPI with GNU Compiler

Language Command
Fortran 77 $ mpif77 -fopenmp myprogram.f -o myprogram
Fortran 90 $ mpif90 -fopenmp myprogram.f90 -o myprogram
Fortran 95 $ mpif90 -fopenmp myprogram.f95 -o myprogram
C $ mpicc -fopenmp myprogram.c -o myprogram
C++ $ mpiCC -fopenmp myprogram.cpp -o myprogram

The Intel and GNU compilers will not output anything for a successful compilation. Also, the Intel compiler does not recognize the suffix .f95.

Back to the Compiling Programs section