UW AMath High Performance Scientific Computing
 
AMath 483/583 Class Notes
 
Spring Quarter, 2011

Previous topic

MPI

Next topic

Python

This Page

MPI with subroutine callsΒΆ

We have looked at several problems where a main program calls a subroutine that does much of the work. If such a program is converted to MPI, somewhat different approaches must be used than were possible with OpenMP:

  • In OpenMP, the subroutine is called by the single thread running the main program, and inside the subroutine a single omp parallel block is used to fork a set of threads that are used for the full computation.
  • In MPI, the first thing done in the main program must be MPI_INIT. It’s not possible to set some variables and call the subroutine in the main program and then call MPI_INIT in the subroutine, since global shared variables do not exist in the MPI model. So in this case every process must call the subroutine independently.

For an example of how MPI is used with subroutines, see the code in $CLASSHG/codes/mpi/quadrature, where Simpson’s method is implemented in this fashion. Compare to the OpenMP version of Homework 5.

Another example is given in $CLASSHG/codes/mpi/heat1d, where the 1 dimensional steady state heat conduction problem is solved using Jacobi iteration. This is the same problem solved in a $CLASSHG/codes/mpi/jacobi2_mpi.f90, where the implementation was done in a single program.

Note that the directories referenced above each have a Makefile and a file readme.txt with some hints on running the code and plotting results.