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 serversudo apt-get install nfs-kernel-servera.2 sharing Master folderadd one line to /etc/exportssudo gedit /etc/exports/mirror *(rw,sync)a.3 create foldersudo mkdir /mirrora.4 start NFS service on master nodesudo /etc/init.d/nfs-kernel-server startb. mounting master shared folder in other non-master nodesb.1 add the ip address of ub0 in /etc/hostssudo gedit /etc/hostsyou will find127.0.0.1 localhost192.168.0.71 muhammad-desktop192.168.0.70 ub0Note: if you found that your IP is 127.0.1.1 please change it to your IPb.2 create mount point and mount itsudo mkdir /mirrorsudo mount ub0:/mirror /mirrorc. create a universal user mpiu on all nodessudo chmod 777 /mirrorsudo useradd -gusers -s/bin/bash -d/mirror -m mpiud. Setting up SSH with no pass phrase for communication between nodesd.1 login as mpiusudo su - mpiud.2 generate DSA key for mpiu:ssh -keygen -t dsaNote: Leave passphrase empty.d.3 add content in id_dsa.pub to authorized keyscd .sshcat id_dsa.pub >> authorized_keysd.4 testssh ub1
3. Download MPICH-2 and build it
resources: MPICH-2 document
downloads:
3.1 Installing GCCsudo apt-get install build-essential3.2 Installing MPICH2cd /mirrormkidr mpich2tar xvf mpich2- 1.0.7rc1.tar.gzcd mpich2 -1.0.7rc1./configure -- prefix=/mirror/mpich2makesudo make install3.3 setup linux environment variables in .bash_profileadd two lines into .bash_profileexport PATH=/mirror/mpich2/bin:$PATHexport LD_LIBRARY_PATH=/mirror/mpich2/lib:$LD_LIBRARY_PATHupdate PATH in /etc/environment (variables defined there willautomatically apply at login for all sessions)sudo gedit /etc/environmentyou will findPATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games"add :/mirror/mpich2/bin into the end PATHto be something like thatPATH="/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, forexampleub0ub14.2 Create some credentialecho secretword=something >> ~/.mpd.confchmod 600 .mpd.conf4.3. Start MPI MPD on the cluster for all nodesmpdboot -n <number of hosts defined in mpd.hosts>mpdtraceThe output should be name of all nodes.if this does not workwe can start the mpds manuallygo 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 itin mpich2-1.0.7rc1/examples",there is a parallel program to calculate PI (cpi)copy cpi.c to /mirrormpicc cpi.c -o cpimpiexec -n 4 ./cpiit 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 0int 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 SPMDworld is */MPI_Comm_rank(MPI_COMM_WORLD,&myid); /* and this processes' rank is *//* At this point, all the programs are running equivalently, the rankis used todistinguish the roles of the programs in the SPMD model, with rank 0often usedspecially... */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 weaksynchronization point */return 0;}
go to the Developer guide
Thanks to
http://puliu.blogspot.com/2008_03_01_archive.htmlhttp://pka.engr.ccny.cuny.edu/~jmao/node/51
Yours Moataz Muhammed
No comments