Carleton College


Cluster Home Page

About the Cluster

Cluster Access

MPI Info

Write / Compile / Run MPI Programs

Single Processor Jobs


Physics Home Page

Chemistry Home Page



Writing, Compiling, and Running Programs Written with MPI


Writing programs that use MPI can seem a bit tricky.  Below you can find examples of programs written in Fortran and C++ that employ MPI functions.  These examples are provided "as-is" and do not do anything particularly interesting.  You may feel free to download these programs, compile and run them.

Looking for information about MPI Library calls can be a gruelling experience.  One good source of information for specific C and C++ MPI library functions are the man pages.  For example "man MPI_Recv" will give you detailed information on that particular function call, but it's not particularly helpful in finding the "right" MPI call for any given situation.

One source that I've found helpful can be found at www.iitk.ac.in/cc/param/mpi_calls.html.  They have posted information on the some of the most common MPI function calls for both C/C++ and Fortran.

Two Important Things to Remember when Running MPI Jobs:

  1. BE REASONABLE!  You will have the ability to send your program to as many processors as are available.  However, taking over all the resources is not a respectful thing to do, and is unfair to your fellow researchers / programmers.  ABUSE OF THE CLUSTER WILL NOT BE TOLERATED.
  2. The Master Node is to be used for programming and compilation.  Please do not run your computational jobs on the Master Node.   This will take valueable CPU time way from the other users... and that's what the "Compute" nodes are for!

A Quick Example of Compiling Fortran Code with MPI

This example will refer to the example program "matrix.f" (to view, click here).  The steps outlined should work for any other generic Fortran program (provided special libraries are not required at compile-time.  To compile a Fortran program that uses MPI, you must use the one of the MPI compile scripts.  On our cluster we have two such scripts, "mpif77" and "mpif90" to compile Fortran77 and Fortran90 code respectively.  Check out the man pages for these scripts to see all the options available.  

These scripts invoke the Intel compilers the college has purchased, and consequently have many options beyond the standard g77 compilers, and can produce compiled programs that are optimized for our architecture.  For more information about the Intel compiler flags and optimizations, type "man ifc".

1.  To compile the program "matrix.f" (a Fortran90-style program), type "mpif90 -o matrix.out matrix.f".

This will produce a number of warnings which can be disabled by adding the -w95 flag (I used a number of "tabs" in my code, which was technically not supported until Fortran95... the -w95 flag turns off warnings specific to Fortran95).

2.  To run the newly compiled executable, type "mpirun --nolocal -np N matrix.out" (where "N" = the number of processors you want to dedicate to your program and "--nolocal" tells the program not to run on the Master Node).

A Quick Example of Compiling C/C++ Code with MPI

This example will refer to the example program "matrix.cpp" (to view, click here).  The steps outlined should work for any other generic C/C++ program (provided special libraries are not required at compile-time.  To compile a C/C++ program that uses MPI, you must use the MPI compile scripts "mpiCC".  Check out the man pages for these scripts to see all the options available.  

This script invokes the Intel compiler the college has purchased, and consequently have many options beyond the standard gcc / g++ compilers, and can produce compiled programs that are optimized for our architecture.  For more information about the Intel compiler flags and optimizations, type "man icc".

1.  To compile the program "matrix.cpp" type "mpiCC -o matrix.out matrix.cpp".

2.  To run the newly compiled executable, type "mpirun --nolocal -np N matrix.out" (where "N" = the number of processors you want to dedicate to your program and "--nolocal" tells the program not to run on the Master Node).

That's it!  You may notice that compiling your code will create a file with the same name, but with ".o" appended at the end.  It is safe to delete it after your have compiled your code.
Back to Cluster Homepage
Page Maintained by: Josh Allen
Last Modified: April 20, 2005