Running MPI applications with OpenMPI

On-line Resources

MPI FAQ from open-mpi.org, contains lots of useful information about using OpenMPI
MPI Tutorial from llnl.gov
some more MPI Tutorials from lam-mpi.org
http://www.mpi-forum.org/: the standard

Compiling your program

  • You need to #include <mpi.h> in your C or C++ source code that makes calls to MPI library functions.
  • Use the mpicc compiler to compile your MPI program written in C (see the http://www.open-mpi.org/faq for compilers for other languages.)
  • You do not need to set your PATH or your LD_LIBRARY_PATH environment variables on our system (they have been set for you).

    Example programs:

    Some example MPI programs to try out are available here:
    /home/newhall/public/mpi_examples/
    

    Running your program

    The first step is to set up ssh'ing without passwords, so that spawing processes on remote hosts doesn't require a password. See the Summary near the bottom of the page for steps for setting up ssh-agent: ssh without password

    orterrun, mpirun

    orterrun or mpirun (they are interchangable) are used to run mpi applications. They take command line arguments that specify the number of processes to spawn, the set of machines on which to run the application processes (or you can specify a hostfile containing the machine names), and the command to run. For example,
    To run a simple command:
    ------------------------
    
      orterun -np 2 --host orange,sesame   excecutable  its_args
    
    example:
    
      orterun -np 2 --host orange,sesame  uptime 
     
    
    To run a command using a hostfile
    ----------------------------------
    % cat myhosts
      # a line starting with # is a comment
      # use slots=X, for machines with X processors
      basil
      rosemary
      nutmeg
      cinnamon
      wasabi slots=2
      orange slots=4
    
    % mpirun -np 4 --hostfile myhosts hello_c
    
      Hello, world (from basil), I am 0 of 4
      Hello, world (from nutmeg), I am 2 of 4
      Hello, world (from rosemary), I am 1 of 4
      Hello, world (from cinnamon), I am 3 of 4
    
    
    To run a master/slave program
    -----------------------------
    % cat myapp
     # master is the name of the master executable, slave is slave
     -np 1 master
     -np 6 slave
    
    % mpirun --hostfile myhosts --app myapp
    master: allocating block (0, 0) - (19, 19) to process 1
    master: allocating block (20, 0) - (39, 19) to process 2
    master: allocating block (40, 0) - (59, 19) to process 3
    ...
    master: allocating block (500, 500) - (511, 511) to process 2
    master: done.