Breaking News

Developing and running Parallel application with MPICH


Developing and running Parallel application with MPICH


  

 1. Go get Ubuntu at http://www.ubuntu.com/getubuntu/download

I am using Desktop version version 8.10, Intrepid Ibex

2. Linux environment setup

a. setup NFS server on master node (ub0)
a.1 install NFS server
sudo apt-get install nfs-kernel-server
a.2 sharing Master folder
add one line to /etc/exports
sudo gedit /etc/exports
/mirror *(rw,sync)
a.3 create folder
sudo mkdir /mirror
a.4 start NFS service on master node
sudo /etc/init.d/nfs-kernel-server start


b. mounting master shared folder in other non-master nodes 
b.1 add the ip address of ub0 in /etc/hosts
sudo gedit /etc/hosts
you will find 

 127.0.0.1            localhost
 192.168.0.71      muhammad-desktop
 192.168.0.70      ub0


  Note: if you found that your IP is 127.0.1.1 please change it to your IP


b.2 create mount point and mount it
sudo mkdir /mirror
sudo mount ub0:/mirror /mirror

c. create a universal user mpiu on all nodes
sudo chmod 777 /mirror
sudo useradd -gusers -s/bin/bash -d/mirror -m mpiu

d. Setting up SSH with no pass phrase for communication between nodes
d.1 login as mpiu
sudo su - mpiu
d.2 generate DSA key for mpiu:
ssh -keygen -t dsa
Note: Leave passphrase empty.
d.3 add content in id_dsa.pub to authorized keys
cd .ssh
cat id_dsa.pub >> authorized_keys
d.4 test
ssh ub1

3. Download MPICH-2 and build it

  resources: MPICH-2 document
downloads:
3.1 Installing GCC
sudo apt-get install build-essential
3.2 Installing MPICH2
cd /mirror
mkidr mpich2
tar xvf mpich2- 1.0.7rc1.tar.gz
cd mpich2 -1.0.7rc1
./configure -- prefix=/mirror/mpich2
make
sudo make install
3.3 setup linux environment variables in .bash_profile
add two lines into .bash_profile
export PATH=/mirror/mpich2/bin:$PATH
export LD_LIBRARY_PATH=/mirror/mpich2/lib:$LD_LIBRARY_PATH
update PATH in /etc/environment (variables defined there will 
automatically apply at login for all sessions)
sudo gedit /etc/environment

you will find 
PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games"

add :/mirror/mpich2/bin into the end PATH
to be something like that 
PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/mirror/mpich2/bin"

4. Setup MPICH-2 MPD

4.1 Create mpd.hosts in mpiu's home directory with nodes names, for 
example
ub0
ub1
4.2 Create some credential
echo secretword=something >> ~/.mpd.conf
chmod 600 .mpd.conf
4.3. Start MPI MPD on the cluster for all nodes
mpdboot -n <number of hosts defined in mpd.hosts>
mpdtrace
The output should be name of all nodes.
if this does not work
we can start the mpds manually
go to the master node (ub0)
mpd &
it will output something like that 
  [1] 9230

  mpdtrace -l  it will output something like that
  muhammad-desktop_43814 (192.168.0.71)

  note: the Master serves at the port 43814 we get it from    muhammad-desktop_43814(192.168.0.71)

  go to the slave nodes and connect to the master (ub0) mpd daemon
  mpd -h ub0 -p 43814 &
  then list all the cluster mode with this command
  mpdtrace -l

  it will output like this

  muhammad-desktop_43814 (192.168.0.71)
mpiuser_43932 (192.168.0.70)
4.4. compile an example and run it
in mpich2-1.0.7rc1/examples",there is a parallel program to calculate PI (cpi)
copy cpi.c to /mirror
mpicc cpi.c -o cpi
mpiexec -n 4 ./cpi
it should display something like:
0: pi is approximately 3.1415926...., Error is .....
0: wall clock time = ....
troubleshoot in mpich2-doc-install.pdf Appendix A: Troubleshooting MPDs

HelloWorld.c (from wiki)
/*
"Hello World" Type MPI Test Program
*/
#include <mpi.h>
#include <stdio.h>
#include <string.h>
#define BUFSIZE 128
#define TAG 0
int main(int argc, char *argv[])
{
char idstr[32];
char buff[BUFSIZE];
int numprocs;
int myid;
int i;
MPI_Status stat;
MPI_Init(&argc,&argv); /* all MPI programs start with MPI_Init; all 'N' 
processes exist thereafter */
MPI_Comm_size(MPI_COMM_WORLD,&numprocs); /* find out how big the SPMD 
world is */
MPI_Comm_rank(MPI_COMM_WORLD,&myid); /* and this processes' rank is */
/* At this point, all the programs are running equivalently, the rank 
is used to
distinguish the roles of the programs in the SPMD model, with rank 0 
often used
specially... */
if(myid == 0)
{
printf("%d: We have %d processors\n", myid, numprocs);
for(i=1;i<numprocs;i++)
{
sprintf(buff, "Hello %d! ", i);
MPI_Send(buff, BUFSIZE, MPI_CHAR, i, TAG, MPI_COMM_WORLD);
}
for(i=1;i<numprocs;i++){
MPI_Recv(buff, BUFSIZE, MPI_CHAR, i, TAG, MPI_COMM_WORLD, &stat);
printf("%d: %s\n", myid, buff);
}
}
else
{
/* receive from rank 0: */
MPI_Recv(buff, BUFSIZE, MPI_CHAR, 0, TAG, MPI_COMM_WORLD, &stat);
sprintf(idstr, "Processor %d ", myid);
strcat(buff, idstr);
strcat(buff, "reporting for duty\n");
/* send to rank 0: */
MPI_Send(buff, BUFSIZE, MPI_CHAR, 0, TAG, MPI_COMM_WORLD);
}
MPI_Finalize(); /* MPI Programs end with MPI Finalize; this is a weak 
synchronization point */
return 0;
}


go to the Developer guide 



Thanks to 

http://puliu.blogspot.com/2008_03_01_archive.html
http://pka.engr.ccny.cuny.edu/~jmao/node/51



Yours Moataz Muhammed

No comments