Setting Up an MPICH2 Cluster with MPI-JAVA in Ubuntu

Creators: Amol Wagh & Cyril George (Interns at CDAC Pune from Jan 2011 to June 2011)

Email-Id: wagh.amol.m@gmail.com ,cyril.version1@gmail.com

This guide describes how to build a simple MPICH2 cluster in Ubuntu.

Here we have 4 nodes running Ubuntu 11.04 with these host names: ub0,ub1,ub2,ub3;

Hardware Requirements

1. Ubuntu Linux Machines - 32 Bit OS on an Intel Machine with multiple processors.
2. A network amongst the machines.

Software Requirements

1. MPICH2
2. MPIJava
3. Open SSH Server & clients.
4. NFS Kernel Server & clients.
5. Java
6. GCC

How to go about Creating a cluster on a Ubuntu Machine

1. Creating User and share folder

To start making a cluster we need to create a user with the same name and the same home folder on all the machines since we are going to create a cluster which will be treated as one computer while execution. To create a user issue the following commands:

user@ub0:~$ sudo mkdir /mirror

(user is your user with super user privileges and mirror is the directory name which we will mount and share on all machines)

user@ub0:~$ sudo adduser mpiu --home /mirror
user@ub0:~$ sudo chown mpiu /mirror

mpiu is the new username given to the user from which we are going to continue further steps.

Please login with mpiu user after logging out of the current user account

After creating the new user, we provide this user with administration privileges by going to System->Administration->Users and Groups and changing the privileges. A machine is identified by the hostname and the IP address on a network. Care must be taken that all machines have different hostname and IP address. For changing hostname of a machine you can do a

mpiu@ub0:~$ sudo gedit /etc/hostname

and change the hostname in that file and then restart the machine.

2. Installation of SSH

MPI (Message Passing Interface) uses SSH(Secure SHell network protocol) to communicate amongst the machines. Install SSH Server by issuing the following command on the terminal on all the machines

mpiu@ub0:~$ sudo apt-get install openssh-server

3. Installing GCC

Install build-essential package:

mpiu@ub0:~$ sudo apt-get install build-essential

4. Installing Java

Install Sun Java package:

mpiu@ub0:~$ sudo apt-get install sun-java6-jdk

5. Installing MPICH2

You can install mpich2 using Synaptic by typing:

sudo apt-get install mpich2

But this has to done on all machines.

Alternatively it can be installed from source...

Download MPICH2 source code from http://www-unix.mcs.anl.gov/mpi/mpich .

Extract .tar.bz2 file in /mirror. Also make a folder for MPICH installation.

mpiu@ub0:/mirror$ mkdir mpich2
mpiu@ub0:/mirror$ tar xvf mpich2-­(version).tar.gz
mpiu@ub0:/mirror$ cd mpich2-­(version)
mpiu@ub0:/mirror/mpich2-­(version)$ ./configure --­prefix=/mirror/mpich2 
mpiu@ub0:/mirror/mpich2-­(version)$ make
mpiu@ub0:/mirror/mpich2-­(version)$ make install

For more information about compilation see README file in source package.

After successfully compiling and installing mpich, add these lines to "/mirror/.bashrc"

gedit ~/.bashrc or gedit /mirror/.bashrc

Append these lines :
export PATH=/mirror/mpich2/bin:$PATH
export LD_LIBRARY_PATH=/mirror/mpich2/lib:$LD_LIBRARY_PATH
And close the file.

source ~/.bashrc or source /mirror/.bashrc

Next we run this command in order to define MPICH installation path to SSH.

mpiu@ub0:~$ sudo echo /mirror/mpich2/bin >> /etc/environment

For testing our installation run:

mpiu@ub0:~$  which mpiexec
mpiu@ub0:~$  which mpirun

6. Installing MPIJAVA

Download MPIJava source code from http://www.hpjava.org/mpiJava.html .

mpiu@ub0:/mirror$ gunzip -c mpiJava-1.2.5.tar.gz | tar -xvf -
mpiu@ub0:/mirror$ cd mpiJava
mpiu@ub0:/mirror$ ./configure

The configure step might ask for mpich2 include path : /mirror/mpich2/include
And the java path that it might ask for, do the following steps:

mpiu@ub0:/mirror$ which java (This will usually return /usr/bin/java)
mpiu@ub0:/mirror$ readlink -f /usr/bin/java (or the path returned by 'which java')

And paste the path that it returns(till the root java path) where it was asked while configuring.
After completion of these steps...

mpiu@ub0:/mirror$ make

For more information about compilation see README file in source package.

After successfully compiling and installing MPIJava, add these lines to "/mirror/.bashrc"

gedit ~/.bashrc or gedit /mirror/.bashrc

Append these lines :
export CLASSPATH=$CLASSPATH:/mirror/mpiJava/lib/classes/ export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/mirror/mpiJava/lib/ And close the file.

source ~/.bashrc or source /mirror/.bashrc

For testing our installation run:

mpiu@ub0:~/mirror/mpiJava/examples/simple$ javac Hello.java
mpiu@ub0:~/mirror/mpiJava/examples/simple$ mpiexec -n 10 java Hello

This Complete the installation of MPICH2 & MPIJava on the master node ub0 which we would use as our server to execute the programs.

7. 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:

mpiu@ub0:~$ sudo apt-get install nfs-kernel-server

8. Defining hostnames in etc/hosts/

Edit /etc/hosts like these:

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

Note that the file shouldn't be like this:

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
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.

9. Sharing Master Folder

Our master folder is /mirror. 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)

This can be done by issuing one of the following commands:

mpiu@ub0:~$ sudo gedit /etc/exports (And then append /mirror *(rw,sync) to the end of the file)
                  or
mpiu@ub0:~$ sudo echo  /mirror *(rw,sync) >> /etc/exports

Note than we store out data and programs only in master node and other nodes will access them with NFS.

10. Mounting /mirror in all other nodes

Now all we need to do is to mount the folder on the other nodes. This can be done manually each time like this:

mpiu@ub1:~$sudo mount ub0:/mirror /mirror
mpiu@ub2:~$sudo mount ub0:/mirror /mirror
mpiu@ub3:~$sudo mount ub0:/mirror /mirror

But it's better to change fstab in order to mount it on every boot. We do this by editing /etc/fstab and adding this line:

ub0:/mirror /mirror nfs
Notice the user name is same for all the machines but the hostname(node) is different.

11. Sharing Master Folder

Our master folder is /mirror. 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)

This can be done by issuing one of the following commands:

mpiu@ub0:~$ sudo gedit /etc/exports (And then append /mirror *(rw,sync) to the end of the file)
                  or
mpiu@ub0:~$ sudo echo  /mirror *(rw,sync) >> /etc/exports

Note than we store out data and programs only in master node and other nodes will access them with NFS.


Continued on this page https://help.ubuntu.com/community/Mpich2ClusterWithMpijavacontinued

Mpich2ClusterWithMpijava (last edited 2011-06-08 09:33:04 by 196)