This directory contains some examples of the use of MPI, the Message Passing Interface, with a FORTRAN77 program.
MPI is a library of message passing routines. The library allows a user to write a program in a familiar language, such as C, C++, FORTRAN77 or FORTRAN90, and carry out a computation in parallel on an arbitrary number of cooperating computers.
A remarkable feature of MPI is that the user writes a single program which runs on all the computers. However, because each computer is assigned a unique identifying number, it is possible for different actions to occur on different machines, even though they run the same program:
if ( I am processor A ) then
add a bunch of numbers
else if ( I am processor B ) then
multipy a matrix times a vector
end
Another feature of MPI is that the data stored on each computer is entirely separate from that stored on other computers. If one computer needs data from another, or wants to send a particular value to all the other computers, it must explicitly call the appropriate library routine requesting a data transfer. Depending on the library routine called, it may be necessary for both sender and receiver to be "on the line" at the same time (which means that one will probably have to wait for the other to show up), or it is possible for the sender to send the message to a buffer, for later delivery, allowing the sender to proceed immediately to further computation.
Here is a simple example of what a piece of the program would look like, in which the number X is presumed to have been computed by processor A and needed by processor B:
if ( I am processor A ) then
call MPI_Send ( X )
else if ( I am processor B ) then
call MPI_Recv ( X )
end
Often, an MPI program is written so that one computer supervises the work, creating data, issuing it to the worker computers, and gathering and printing the results at the end. Other models are also possible.
It should be clear that a program using MPI to execute in parallel will look much different from a corresponding sequential version. The user must divide the problem data among the different processes, rewrite the algorithm to divide up work among the processes, and add explicit calls to transfer values as needed from the process where a data item "lives" to a process that needs that value.
A FORTRAN77 program, subroutine or function that calls any MPI function, or uses an MPI-defined variable, must include the line
include "mpif.h"
so that the types of the MPI variables are defined. If you'd like
to see what goes on in the include file, you can copy
mpif_sample.h, a sample version of
such a file. (They can vary somewhat from one implementation or
machine to another.)
You probably compile and link your program with a single command, as in
f77 myprog.f
Depending on the computer that you are using, you may be able
to compile an MPI program with a similar command, which automatically
locates the include file and the compiled libraries that you will
need. This command is likely to be:
mpif77 myprog.f
Some systems allow users to run an MPI program interactively. You do this with the mpirun command:
mpirun -np 4 a.out
This command requests that the executable program a.out
be run, right now, using 4 processors.
The mpirun command may be a convenience for beginners, with very small jobs, but this is not the way to go once you have a large lengthy program to run! Also, what actually happens can vary from machine to machine. When you ask for 4 processors, for instance,
CONDOR is the remote queueing system which was used to submit MPI jobs to the FSU SCS clusters.
HEAT_MPI is a FORTRAN77 program which solves the 1D time dependent heat equation using the finite difference method, with parallelization from MPI.
LAMMPS is a FORTRAN77 program which carries out a molecular dynamics simulation using MPI. A serial version can be created by linking the program with the MPI_STUBS library.
METIS is a C library (and a family of executable programs based on it) which can partition the nodes of a graph or the elements of a finite element mesh in a way suitable for further treatment by parallel processing.
MPI examples are also available in a C version, and a C++ version, and a FORTRAN90 version.
MPI_CONDOR is a directory of sample CONDOR scripts for running FORTRAN77 programs under MPI on the FSU SCS cluster.
MPI_ECLIPSE is a directory of sample LoadLeveler scripts for running FORTRAN77 programs under MPI on the FSU SCS Eclipse IBM SP system.
MPI_INTRODUCTION is a one page introduction to MPI.
MPI_MORE_INFO contains a list of references, web sites, examples and tutorials on MPI.
MPI_STUBS is a FORTRAN77 library of "stub" MPI routines, which allows a user to compile, load, and possibly run an MPI program on a serial machine.
MPI_SYSX is a directory of sample PBS scripts for running FORTRAN77 programs under MPI on System X.
OPEN_MP is a simple system for parallel programming which relies on the use of shared memory.
PETSC is a scientific programming library for parallel programming, which requires MPI in order to run.
PLTMG_SINGLE is a FORTRAN77 finite element program which can be compiled and run with the MPI library.
PTHREADS is a set of C examples which illustrate the use of the POSIX thread library to carry out parallel program execution.
QUAD_MPI is a FORTRAN77 program which approximates an integral using a quadrature rule, and carries out the computation in parallel using MPI.
SATISFIABILITY_MPI is a FORTRAN77 program which demonstrates, for a particular circuit, an exhaustive search for solutions of the circuit satisfiability problem, using MPI to carry out the calculation in parallel.
SGE is the Sun Grid Engine, a remote queueing system.
BONES passes a vector of real data from one process to another. It was used as an introductory example in an MPI workshop.
BUFFON_LAPLACE is an "embarassingly parallel" program which carries out a randomized series of Buffon-Laplace trials.
DAY1_EX3 works out exercise #3 assigned after day 1 of a workshop on MPI. The instructions were to have process 1 generate some integers, send them to process 3 which used some of those values to generate some real numbers which were then sent back to process 1.
HELLO simply prints out "Hello, world!" from each MPI process.
INTERVALS estimates an integral by dividing an interval into subintervals, and having the servant processes estimate the integral over each subinterval.
MATMAT multiplies two matrices.
MATVEC multiplies a matrix times a vector.
POISSON_BAND is a revision to POISSON_SERIAL, which divides the physical region into horizontal strips, assigns a process to each strip, and uses MPI_SEND and MPI_RECV to pass interface data between processes.
POISSON_SERIAL solves the Poisson equation on a 2D grid. This version of the program does not use MPI, and is provided for comparison.
QUADRATURE estimates an integral.
SEARCH searches a vector for occurrences of a particular value.
TASK_DIVISION is a serial code that simply suggests how T tasks could automatically and evenly be divided among P processors.
TYPE demonstrates the use of a user-defined datatype.
VERSION calls a routine which reports the MPI version and subversion values.
You can go up one level to the FORTRAN77 source codes.