Short intro - getting started with MPI in the lab (room P17 ASPC)

MPICH installation

MPICH2 is installed on some of the Windows workstations in the lab.

Every machine that will be used as a host for MPI processes must run spmd (it is already started as a windows service). You can check its status by typing in the command line

smpd -status

Launching MPI programs

Programs are launched as MPI pocesses with help of the mpiexec utility, which requires the executable of the program as argument. In its simplest form, launching program.exe as a MPI process on the local host is done by typing the command:

mpiexec program.exe

In order to launch n=2 processes on the same host, the command adds the flag -n:

mpiexec -n 2 program.exe

In order to launch processes on a different host, add the flag -host to the command:

mpiexec -host USER-PC-4 program.exe

In order to launch processes on several hosts, use flag -hosts:

mpiexec -hosts 2 USER-PC-2 USER-PC-4 program.exe

MPI programs belong to the SPMD paradigm, that means the same program is executed at different nodes. The executable of the program must be available at every host - either having it in a shared network folder, or by cvopying it on every node. Atention ! if the program is copied at every node, it must be placed in locations with the same name ! (in the folder C:\Users\pa\mpi which exoists on every computer )

The first time each session mpiexec is run it will ask for username and password. The username and password are the Windows login information. To prevent being asked for this in the future, this information can be encrypted into the Windows registry by running:

mpiexec -register

Running your first MPI application

An example which comes with MPICH is cpi.exe, a program for the computation of pi. The value of pi is computed in a number of iterations. The total number of iterations can be split across several MPI processes.

Copy the executable cpi.exe into your working directory c:\users\pa\mpi\

Launching with one process on local host:

mpiexec cpi

Launching with two processes on local host:

mpiexec -n 2 cpi

Launching with one process on another host:

mpiexec -host USER-PC-4 cpi

Launching on two hosts, with one process per host:

mpiexec -hosts 2 USER-PC-2 USER-PC-4 cpi

Launching on 3 hosts, with two processes per host (a total of 6 processes):

mpiexec -hosts 3 USER-PC-2 2 USER-PC-4 2 USER-PC-5 2 cpi

Instead of specifying hosts in the command line, you can write a host configuration file.

mpiexec -f configfile -n 6 cpi The configfile contains hosts and number of processes allowed per host.

Compiling and building a MPI application

MPICH supports applications in C and FORTRAN. Applications in C can be compiled with gcc or Visual C. Mainly you have to configure compiler options to add MPICH2/include to the included dir options and MPICH2/lib to the linker options.

Compiling and building with gcc

Env.c is a program which displays MPI environment info.

Compile with: gcc -I"c:\Program Files\MPICH2\include" -L"c:\Program Files\MPICH2\lib" -o Env.exe Env.c -lmpi

Launch on local host only, with 3 processes on local host: mpiexec -n 3 cpi

Launch on different hosts: Make sure before this that you copy the executable Env.exe on every intended host !!! mpiexec -hosts 2 USER-PC-2 USER-PC-4 Env

For further work