MSc in Network Centered Computing

Module: PVM and MPI

MPI shell scripts

MPI compile scripts

With MPI you will need additional libraries and parameters to compile the C code. To make the live easier for you it is better to use a shell script, which includes all the needed parameters. For that reason you should create a new file in your mpi_directory called "mcc".
Add the following rows into this file:

#!/bin/sh
#script to compile all C-progs in the subdirs
if [ $1 ]
then
echo "start compiling"
mpicc $1.c -c -xCC
mpicc $1.o -o $1 -lm
echo "done"
else
echo "Parameter (filename without ending .c) missing."
fi

Save the file and make it executable with chmod: "chmod u+x mcc"
Now you can compile your code just with a simple command "mcc program_name"

Before you can try to test your program you need to add some environment variables. Just execute the following command.

module add mpi

If you get the error message "command not found" after the "module add mpi" command, then you should update you login profile. Run the following command and after it logout and login again:
/etc/local/dotfiles/restore_ssu

Use the following command to run your MPI program on more than one processor:
mpirun -np 2 program_name (the 2 stand for two processors, change the number to run it on more processors)

examples

Here is a simple MPI example:
cpi.c


back to the main page

© Oliver Otto - The University of Reading / Salford