Sunteți pe pagina 1din 2

Installing MPI

*For more detail understanding please go through the websites FOR INSTALLING MPI IN UBUNTU Refer: ** OpenMPI on Ubuntu 9.04 - MPI - e-Notes.html A. Install OpenMPI $ sudo apt-get install libopenmpi-dev openmpi-bin openmpi-doc $ sudo apt-get install ssh B. Configure SSH $ ssh-keygen -t dsa $ cd ~/.ssh $ cat id_dsa.pub >> authorized_keys C. MPI Program Example Filename: MPI_Hello.c #include <stdio.h> #include <mpi.h> int main(int argc, char** argv) { int myrank, nprocs; MPI_Init(&argc, &argv); MPI_Comm_size(MPI_COMM_WORLD, &nprocs); MPI_Comm_rank(MPI_COMM_WORLD, &myrank); printf("Hello from processor %d of %d\n", myrank, nprocs); MPI_Finalize(); return 0; } D. Compilation $ mpicc MPI_Hello.c -o MPI_Hello E. Execution $ mpiexec -n 5 MPI_Hello This command is for running the program in single machine Please dont try in cluster

FOR CREATING CLUSTER


Refer: http://techtinkering.com/articles/?id=32 Setting up the Machines I am making several assumptions in this article: 1. 2. 3. 4. 5. 6. You have at least two machines connected via a TCP/IP network. Each machine is using the same processor architecture, to ease sharing your program executables. The machines all have Linux installed. Each machine has a common login user name, such as mpiuser, common password mpiuser. I will refer to the common login as mpiuser for the rest of this article. Each machine has mpiuser sharing the same home folder, : file system/ home/mpiuser/mpi (mpi is the folder) I will refer to each of the slaves nodes as slave1, slave2, etc. You, however, can choose whatever host names you like.

1) Slave Nodes
$ sudo apt-get install openssh-server

2) Master nodes
First of all go to (gksu gedit /etc/hosts) and note down ip addresses and name of all slaves.
Add the machine name and ip address of the slave along with add the ip address in front of your machine name also which will set for local host ip address by default

1. 2. 3 4

$ sudo apt-get install openssh-client $ ssh-keygen -t dsa $ cp /home/mpiuser/.ssh/id_dsa.pub /home/mpiuser/.ssh/authorized_keys $ scp /home/mpiuser/.ssh/id_dsa.pub mpiuser@slave1:.ssh/authorized_keys (slave1 is the machine name of the slave and mpiuser is login name of the slave) 5 $ chmod 700 /home/mpiuser/.ssh 6 $ chmod 600 /home/mpiuser/.ssh/authorized_keys (here it may ask for creating .ssh folder so give the path as it will suggest in the bracket) 7 $ ssh-add ~/.ssh/id_dsa 8 $ ssh slave1 (slave1 is machine name) 9 Create a hostfile with name .mpi_hostfile containing name of all slaves including master name. see attachments for example. mpiuser (my login name will be there by default) mpiuser-desktop (slave 1 should be added. Similarly if there are any slaves they all must be added) .c file and hostfile should remain in same folder.

3 compile your c file by following command.


1. $ mpicc hallo.c after compiling copy exe file to slaves using following command. 2 "rsync * slave1:/home/rohan/mpi" (slave1 is the machine name of the slave 1) "rsync * slave2:/home/likewin/mpi" (slave2 is the machine name of the slave 2) This command copies the file from /home/likewin/mpi to slave1

4 Now run program by following command


$ mpirun -np 2 --hostfile sri.mpi_hostfile ./a.out make it 3) (2 is number of slave in the cluster if the there are 3

S-ar putea să vă placă și