Introduction to and resources for Parallel Computing with Fortran

Lecture notes: Lecture 1          Lecture 2    (thanks for Plamen Krastev)

OpenMP resources: home page for OpenMP   online notes     tutorial 

also: Parallel Programming in OpenMP, by Chandra, Dagum, Kohr, Maydan, McDonald, Menon

OpenMP example: computing matrix elements of r^4 in radial h.o. basis:


to compile with Intel, use -openmp switch; with gnu -fopenmp
will automatically find available threads

to set number of threads


or whatever number of threads you want.

OpenMP example: Monte Carlo calculation of volume of n-dimensional sphere:
(Note: this version must be compiled with an OpenMP flag or switch. On the other hand, it is an example
of OpenMP not speeding up time significantly)


MPI examples (due to P. Krastev)

To compile, must use  mpif90

To run,

> mpiexec -n 4  EXECUTABLE < input

this starts EXECUTABLE on 4 processors

(Note: on some

NOTE: It is possible to compile MPI code in serial mode, but one must supply dummy MPI routines (typically one creates a
file of these) that do nothing, as well as a file mpif.h that defines MPI variables.

MPI version of homertrap.f90

Examples by P. Krastev:

Dot product: 
serial  serial_dot.f90 myf90lib.f90     parallel  parallel_dot.f90 myf90lib.f90

  Matrix-vector multiply
serial  serial_matvec.f90  + myf90lib.f90    parallel  parallel_matvec.f90   + myf90lib.f90

  Lanczos algorithm
 serial  slanczos.f90  + myf90lib.f90         parallel  planczos.f90 + myf90lib.f90