6.6 Using LAM/MPI with OSCAR
Before
we leave OSCAR, let's look at a programming example.
You can use this to convince yourself that everything is really
working. You can find several LAM/MPI examples in
/usr/share/doc/lam-oscar-7.0/examples and the
documentation in /opt/lam-7.0/share/lam/doc.
(For MPICH, look in
/opt/mpich-1.2.5.10-ch_p4-gcc/examples for code
and /opt/mpich-1.2.5.10-ch_p4-gcc/doc for
documentation.)
Log on as a user other than root and verify that LAM/MPI is selected
using switcher.
[sloanjd@amy doc]$ switcher mpi --show
user:default=lam-7.0
system:exists=true
If necessary, change this and log off and back on.
If you haven't logged onto the individual machines,
you need to do so now using ssh to register each
machine with ssh. You could do this with a
separate command for each machine.
[sloanjd@amy sloanjd]$ ssh node1
...
Using a shell looping command is probably better since it will ensure
that you don't skip any machines and can reduce
typing. With the Bash shell, the following command will initiate your
logon to the machines node1 through
node99, each in turn.
[sloanjd@amy sloanjd]$ for ((i=1; i<100; i++))
> do
> ssh node${i}
> done
Just adjust the loop for a different number of machines. You will
need to adjust the syntax accordingly for other shells. This goes
fairly quickly and you'll need to do this only once.
Create a file that lists the individual machines in the cluster by IP
address. For example, you might create a file called
myhosts like the following:
[sloanjd@amy sloanjd]$ cat myhosts
172.16.1.1
172.16.1.2
172.16.1.3
172.16.1.4
172.16.1.5
This should contain the server as well as the clients.
Next, run lamboot with the
file's name as an argument.
[sloanjd@amy sloanjd]$ lamboot myhosts
LAM 7.0/MPI 2 C++/ROMIO - Indiana University
You now have a LAM/MPI daemon running on each machine in your cluster.
Copy over the example you want to run, compile it with mpicc, and
then run it with mpirun.
[sloanjd@amy sloanjd]$ cp /usr/share/doc/lam-oscar-7.0/examples/
alltoall/alltoall.c $HOME
[sloanjd@amy sloanjd]$ mpicc -o alltoall alltoall.c
[sloanjd@amy sloanjd]$ mpirun -np 4 alltoall
Rank 0 not sending to myself
Rank 1 sending message "1" to rank 0
Rank 2 sending message "2" to rank 0
...
You should see additional output. The amount will depend on the
number of machines in myhosts. Happy coding,
everyone!
|