Install and configure MPI
This article explains how to install and configure MPI to be able to run the ESTEL model in parallel on a network of computers. Note that this article is merely a quick run through the MPI Installer's Guide at http://www-unix.mcs.anl.gov/mpi/mpich2/.
This article is general an can be used to configure MPI for any application requiring a Fortran 90 compiler really.
Pre-requesites
ssh key authentication
To use MPI on a network of computers, you need to be able to log in any of the computer without user interaction (password etc...) This is easily achieved using secure shell key authentication. The methodology to setup ssh to use key authentication is described in the article entitled " Configure ssh for MPI".
Fortran 90 compiler
You need a Fortran90 compiler to compile and run the TELEMAC system. When running simulations in parallel mode, MPI use a wrapper to your existing compiler, usually called mpif90
. This wrapper is built when MPI is compiled and therefore, you need to have a Fortran 90 compiler installed before you attempt to compile MPI.
Download MPI
You can download from http://www-unix.mcs.anl.gov/mpi/mpich2/. You will end up with a gzipped tarball called something like mpich2.tar.gz
with a version number in the name as well. Note that the TELEMAC system uses MPI-1 statements but we encourage you to install MPICH-2 (which is backward compatible) as TELEMAC will probably move towards MPI 2 at some point in the future.
For the sake of this article, we assume that you have extracted the tarball into a directory called /path/to/mpi-download/
.
Compilation
The compilation of MPI is fairly straightforward but beforehand, you need to create an install folder (called /path/to/mpi/
here) and a build folder (called /path/to/mpi-build/
here):
$ mkdir /path/to/mpi
$ mkdir /tmp/mpi-build
To configure the MPI build, the only required step is to assign to the environment variable F90
the name of your Fortran 90 compiler. This name needs to be in your PATH
or you have to give the full path to the Fortran 90- compiler if not. Then the configure
command will automatically configure the build for you:
cd /tmp/mpi-build
export F90=f90compiler
/path/to/mpi-download/configure --prefix=/path/to/mpi 2>&1 | tee configure.log
This will test many factors on your machine and configure the build. If the configure
command finished without problem, you are ready to build MPI. Note that you can inspect configure.log
for problems. In particular, you want to make sure that the Fortran 90 compiler is OK for the build.
To compile and install MPI, just issue the standard make
and make install
commands:
make
make install
This will install MPI in /path/to/mpi/
.
Note that you will need to install MPI on all the nodes in your network that will be used for MPI jobs. As they probably have the same computer architecture, you could just copy the /path/to/mpi
accross.
Configuration of MPI
PATH
Add /path/to/mpi/bin
to PATH
. This often means adding the following lines to your .bashrc
file:
PATH=/path/to/mpi/bin:$PATH
export PATH
Now, you should be able to see the MPI Fortran 90 wrapper mpif90
and the MPI multiprocessor daemon mpd>
:
$ which mpif90
/path/to/mpi/bin/mpif90
$ which mpd
/path/to/mpi/bin/mpd
Note that the PATH
needs to be set on each node which will be used for MPI simulations. This is straightforward if your home directory is shared for all the nodes or you need to do it manually otherwise.
Password in .mpd.conf
MPI requires a file in your home directory called .mpd.conf
(yes, there are two dots) which contains the line:
secretword=something_secret_but_don't_use_your_real_password
This file should be readable and writable only by you.
Check if this needs to be done on all nodes.... and if the secret thing needs to be the same. Probably yes.
Now that the passord has been set, you should be able to start the multiprocessor daemon on one host with the command mpd &
. You can check it is up with mpdtrace
, run a simple command via MPI with mpiexec
and bring it down with mpdallexit
, for instance when trying on the master:
master $ mpd &
[1] 17187
master $ mpdtrace
master
master $ mpiexec -l -n 2 hostname
0: master
1: master
master $ mpdallexit
It is interesting to note that we asked for two processes with the mpiexec
command with the arguments -n 2
although we have only one machine in our network yet. The mpd
is intelligent enough to just wrap around. In the output above, the hostname
is used and we can see that processes 0 and 1 return the sdame value so thay are definitely run on the same host. This is very useful to test parallel programs on a single machine.
Hosts in mpd.hosts
To be able to send the processes to other hosts on the network, create a file in your home directory called mpd.hosts
which contain a list of the nodes to be used by MPI, one per line. If the network consists of the master and two slaves slave1 and slave2, mpd.conf
would contain:
master.full.domain
slave1.full.domain
slave2.full.domain
This file should be created on the master node, i.e. the one that you will use to launch MPI jobs. All the hosts in the list need to have a working installation of MPI.
Using an mpd
ring
To dispatch MPI rocesses to other hosts on the network, we need to start a ring of multiprocessor daemons, which we will simply call a mpd
ring. The ring is started from the master node and will include the nodes in the mpd.hosts
file.
Start the ring
The mpd
ring is started from the master node with the mpdboot
command. The syntax is self-explanatory:
master $ mpd -n 3 -f ~/mpd.hosts
In the example above, "3" is the number of nodes to include in the ring. By default, the master is always included in the ring.
The option -f
is used to specify the name of the hosts file.
Test the ring
The command mpdtrace
can be used to list which machines are in the ring:
master $ mpdtrace
master
slave1
slave2
To test the ring, use mpdringtest
. That will send a message to circle around the ring (a loop) and tell you how long it took. One loop is very fast so make the message circle round a few times:
master $ mpdringtest 100
time for 1000 loops = 0.998109102249 seconds
You can also send a command in parallel using mpiexec
. The option -l
will append the process number before the output of the command. The option -n 5
request the job to start 5 processes, as we only have 3 hosts in the ring, the processes will "wrap around" as shown in the listing below; "master" and "slave2" have been used twice:
master $ mpiexec -l -n 5 hostname
2: slave1
1: master
4: master
0: slave2
3: slave2
If you can do this, congratulations! You should be able to run parallel ESTEL jobs on your ring now!
Just remember to start a mpd
ring before running your parallel job.
Close the ring
The command mpdallexit
is used to terminate the mpd
ring:
master $ mpdallexit
Trouble shooting
The MPI Installer's Guide has a good section about troubleshooting (Appendix A). To summarise things that might be helpful:
- make sure you can start
mpd
on each host separately first - check that the
/etc/hosts
on each host is correct and has an entry for each host with the right IP address. - read the MPI manual!
- take your time...