I now assume that you have first.c in your directory.
Before we go through this program in detail, let us compile it and run first. To compile first.c simply say:
gustav@jupiter:~/mpi/simplempi 240 $ hcc -o first first.c -lmpi gustav@jupiter:~/mpi/simplempi 241 $
hcc is a convenience wrapper for the local native C compiler. It is a part of LAM system. On our systems it seems to prefer GNU C. It knows about the location of LAM libraries which is why you don't have to specify -L/opt/lam/lib. But note that if you compile an MPI program you do have to specify -lmpi.
To run this program invoke it through the mpirun command. For example:
gustav@jupiter:~/mpi/simplempi 243 $ mpirun -w N `pwd`/first -- `uname -n` Greetings to the master (jupiter, 5) from (cisr, 0) Greetings to the master (jupiter, 5) from (mercury, 1) Greetings to the master (jupiter, 5) from (venus, 2) Greetings to the master (jupiter, 5) from (earth, 3) Greetings to the master (jupiter, 5) from (mars, 4) Greetings to the master (jupiter, 5) from (saturn, 6) Greetings to the master (jupiter, 5) from (uranus, 7) Greetings to the master (jupiter, 5) from (bacchus, 8) Greetings to the master (jupiter, 5) from (ceres, 9) Greetings to the master (jupiter, 5) from (diana, 10) Greetings to the master (jupiter, 5) from (minerva, 11) Greetings to the master (jupiter, 5) from (vesta, 12) gustav@jupiter:~/mpi/simplempi 244 $
The -w switch tells mpirun not to exit before all MPI
processes complete. The capital N tells mpirun to run the job
on all nodes of the LAM engine.
We have to specify the full pathname of the binary if it is
not located on the normal command search path. This pathname must be
identical on all machines running LAM, unless a -s switch is used,
in which case the binary is loaded from your local node and distributed
to other nodes through LAM channels. Finally we have the double hyphen,
--
, which
marks the beginning of command line arguments referring
to our MPI program. The only argument we pass to our first
MPI program is the name of the machine
from which the program is invoked. This name is generated dynamically by
UNIX command uname -n.
Like with all other LAM commands you can obtain more information about mpirun and hcc by issuing the commands
gustav@jupiter:~/mpi/simplempi 244 $ man mpirunand
gustav@jupiter:~/mpi/simplempi 245 $ man hcc