MpichCluster - Community Help Wiki
MpichCluster - Community Help Wiki
MpichCluster
Setting Up an MPICH2 Cluster in Ubuntu
This guide describes how to build a simple MPICH cluster in ubuntu.
Here we have 4 nodes running Ubuntu server with these host names:
ub0,ub1,ub2,ub3;
127.0.0.1 localhost
192.168.133.100 ub0
192.168.133.101 ub1
192.168.133.102 ub2
192.168.133.103 ub3
127.0.0.1 localhost
127.0.1.1 ub0
192.168.133.100 ub0
192.168.133.101 ub1
192.168.133.102 ub2
192.168.133.103 ub3
or like this:
127.0.0.1 localhost
127.0.1.1 ub0
192.168.133.101 ub1
https://help.ubuntu.com/community/MpichCluster Page 1 of 8
MpichCluster - Community Help Wiki 28/01/2017, 7)58 PM
192.168.133.102 ub2
192.168.133.103 ub3
otherwise other hosts will try to connect to localhost when they try to reach
ub0.
2. Installing NFS
NFS allows us to create a folder on the master node and have it synced on
all the other nodes. This folder can be used to store programs. To Install
NFS just run this in the master node's terminal:
To install the client program on other nodes run this command on each of
them:
Make a folder in all nodes, we'll store our data and programs in this folder.
And then we share the contents of this folder located on the master node to
all the other nodes. In order to do this we first edit the /etc/exports file on
the master node to contain the additional line
/mirror *(rw,sync)
https://help.ubuntu.com/community/MpichCluster Page 2 of 8
MpichCluster - Community Help Wiki 28/01/2017, 7)58 PM
This can be done using a text editor such as vim or by issuing this
command:
Now restart the nfs service on the master node to parse this configuration
once again.
Note than we store out data and programs only in master node and other
nodes will access them with NFS.
Now all we need to do is to mount the folder on the other nodes. This can
be done manually each time like this:
and remounting all partitions by issuing this on all the slave nodes:
https://help.ubuntu.com/community/MpichCluster Page 3 of 8
MpichCluster - Community Help Wiki 28/01/2017, 7)58 PM
We define a user with same name and same userid in all nodes with a
home directory in /mirror.
omid@ub0:~$ su - mpiu
mpiu@ub0:~$ cd .ssh
mpiu@ub0:~/.ssh$ cat id_rsa.pub >> authorized_keys
https://help.ubuntu.com/community/MpichCluster Page 4 of 8
MpichCluster - Community Help Wiki 28/01/2017, 7)58 PM
If you are asked to enter a passphrase every time, you need to set up a
keychain. This is done easily by installing... Keychain.
And to tell it where your keys are and to start an ssh-agent automatically
edit your ~/.bashrc file to contain the following lines (where id_rsa is the
name of your private key file):
Exit and login once again or do a source ~/.bashrc for the changes to take
effect.
Now your hostname via ssh command should return the other node's
hostname without asking for a password or a passphrase. Check that this
works for all the slave nodes.
8. Installing GCC
To be able to compile all the code on our master node (it's sufficient to do it
https://help.ubuntu.com/community/MpichCluster Page 5 of 8
MpichCluster - Community Help Wiki 28/01/2017, 7)58 PM
only there if we do it inside the /mirror folder and all the libraries are in
place on other machines) we need a compiler.
You can get gcc and other necessary stuff by installing the build-essential
package:
In this step you may install other compilers such as Inter Fortran, SGI
compiler , ...
Now the last ingredient we need installed on all the machines is the MPI
implementation. You can install MPICH2 using Synaptic by typing:
To test that the program did indeed install successfully enter this on all the
machines:
https://help.ubuntu.com/community/MpichCluster Page 6 of 8
MpichCluster - Community Help Wiki 28/01/2017, 7)58 PM
11. Testing
Change directory to your mirror folder and write this MPI helloworld
program in a file mpi_hello.c (courtesy of this blog):
#include <stdio.h>
#include <mpi.h>
MPI_Init(&argc, &argv);
MPI_Comm_size(MPI_COMM_WORLD, &nprocs);
MPI_Comm_rank(MPI_COMM_WORLD, &myrank);
MPI_Finalize();
return 0;
}
Compile it:
https://help.ubuntu.com/community/MpichCluster Page 7 of 8
MpichCluster - Community Help Wiki 28/01/2017, 7)58 PM
References
https://help.ubuntu.com/community/MpichCluster Page 8 of 8