• By

An updated, and community maintained, version of this guide is available at the Ubuntu Wiki

This guide describes how to building a simple MPICH cluster in ubuntu.

Note: you need a basic knowledge about MPICH and clustering.

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

1. Defining hostnames in etc/hosts/

Edit /etc/hosts like these:     localhost ub0 ub1 ub2 ub3

Note that the file shouldn’t be like this:     localhost     ub0 ub0 ub1 ub2 ub3

2. Installing NFS

To Install NFS just run this in terminal:

[email protected]:~$ sudo apt-get install nfs-kernel-server

3. Sharing Master Folder

Make a folder in all nodes, we’ll store our data and programs in this folder.

[email protected]:~$ sudo mkdir /mirror

And then we share it over nodes on the master node.

[email protected]:~$ 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.

4. Mounting /master in nodes

[email protected]:~$ sudo mount ub0:/mirror /mirror
[email protected]:~$ sudo mount ub0:/mirror /mirror
[email protected]:~$ sudo mount ub0:/mirror /mirror

it’s better to change fstab in order to mount it on every boot.

5. Defining a user for running MPI programs

We define a user with same name and same userid in all nodes with a home directory in /mirror.

Here we name it “mpiu”! Also we change the owner of /mirror to mpiu:

[email protected]:~$ sudo chown mpiu /mirror

6. Installing SSH Server

Run this command in all nodes in order to install OpenSSH Server

[email protected]:~$ sudo apt­-get install openssh­server

7. Setting up SSH with no pass phrase for communication between nodes

First we login with our new user:

[email protected]:~$ su - mpiu

Then we generate DSA key for mpiu:

[email protected]:~$ ssh­-keygen ­-t dsa

Leave passphrase empty.

Next we add this key to authorized keys:

[email protected]:~$ cd .ssh
[email protected]:~/.ssh$ cat id_pub.dsa >> authorized_keys

As the home directory of mpiu in all nodes is the same (/mirror/mpiu) , there is no need to run these commands on all nodes.

To test SSH run:

[email protected]:~$ ssh ub1 hostname

It should return remote hostname without asking for passphrase.

8. Installing GCC

Install build-essential package:

[email protected]:~$ sudo apt-get install build-essential

9.Installing Other Compilers

Other prefered compilers should be installed before installing MPICH.

In this step we install other compilers such as Inter Fortran, SGI compiler , … .

10. Installing MPICH2

Download MPICH2 source code from https://www.mpich.org/downloads/

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

[email protected]:/mirror$ mkidr mpich2
[email protected]:/mirror$ tar xvf mpich2-­1.0.5p3.tar.gz
[email protected]:/mirror$ cd mpich2­-1.0.5p3
[email protected]:/mirror/mpich2­-1.0.5p3$ ./configure --­prefix=/mirror/mpich2
[email protected]:/mirror/mpich2­-1.0.5p3$ make
[email protected]:/mirror/mpich2­-1.0.5p3$ sudo make install

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

After successfully compiling and installing mpich, add these lines to “/mirror/mpiu/.bashrc/”

export PATH=/mirror/mpich2/bin:$PATH
export PATH

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

[email protected]:~$ sudo echo /mirror/mpich2/bin >> /etc/environment

For testing our installation run:

[email protected]:~$  which mpd
[email protected]:~$  which mpiexec
[email protected]:~$  which mpirun

11. setting up MPD

Create mpd.hosts in mpiu’s home directory with nodes names:


and run :

[email protected]:~$ echo secretword=something   >> ~/.mpd.conf
[email protected]:~$ chmod 600 .mpd.conf

To test MPD run above commands. The output should be the current hostname.

[email protected]:~$ mpd &
[email protected]:~$ mpdtrace
[email protected]:~$ mpdallexit

After all run mpd daemon:

[email protected]:~$ mpdboot ­-np 4
[email protected]:~$ mpdtrace

The output should be name of all nodes.

There are some examples in “mpich2-1.0.5/examples”, we’ll run one :

[email protected]:~$ mpiexec -n 4 cpi

That’s it!

For more information visit: