You are on page 1of 9









2.0 CONFIGURATION 2.1 Add the nodes to the hosts file 2.2 Installing NFS 2.3 Sharing Master Folder 2.4 Mounting /master in nodes 2.5 Defining a user for running MPI programs 2.6 Installing SSH Server 2.7 Setting up password less SSH for communication between nodes 2.8 Installing MPICH2 2.9 Setting up a machinefile 3 4 4 5 5 5 6 6 7

3.0 TESTING THE CONFIGURATION 3.1 Producing output and results 3.2 Compiling code 8 9


1.1 Hardware The Beowulf Cluster Server comprises of the following hardware parts : A Local Area Network Server / Head / Master node (common names for the same machine) Slave nodes

1.2 Software All nodes (including the Master node) run the following software : GNU/Linux OS Linux Ubuntu Desktop or Server Edition Network File System (NFS) Secure Shell (SSH) Message Passing Interface (MPI) MPICH2 , a high-performance and widely portable implementation of the MPI Standard, designed to implement all of MPI-1 and MPI-2 (including dynamic process management, one-sided operations, parallel I/O, and other extensions).


2.1 Add the nodes to the hosts file It is easier if the nodes can be accessed with their host name rather than their IP address. It will also make things a lot easier later on. To do this, add the nodes to the hosts file of all nodes. All nodes should have a static local IP address set and all nodes are already properly configured. Edit the hosts file sudo vim /etc/hosts like below and remember that we need to do this for all nodes : localhost node0 node1 node2

After that, we need to try and check the connections by issuing the Ping command. Make sure every nodes are reachable.

2.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 : cluster@node0:~$ sudo apt-get install nfs-server

To install the client program on the Slave nodes run this command on each of them: cluster@node1:~$ sudo apt-get install nfs-client

2.3 Sharing Master Folder Make a folder in all of the Master and Slave nodes, which we will be using to store our data and programs in this folder. cluster@node0:~$ sudo mkdir /mirror

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)

This can be done using a text editor such as vim or by issuing this command : cluster@node0:~$ echo "/mirror *(rw,sync)" | sudo tee -a /etc/exports

Now restart the NFS service on the Master node to parse this configuration once again. cluster@node0:~$ sudo service nfs-kernel-server restart

Note than we store data and programs only in the Master node and other nodes will only access them using NFS.

2.4 Mounting /Master in nodes Now all we need to do is to mount the folder on the rest of the nodes. This can be done manually separately like the following : cluster@node1:~$ sudo mount node0:/mirror /mirror cluster@node2:~$ sudo mount node0:/mirror /mirror

But it would be better to change fstab in order to mount it on every boot. We do this by editing /etc/fstab and adding this line: node0:/mirror /mirror nfs

And remount all partitions by issuing the following command on all of the Slave nodes: cluster@node1:~$ sudo mount -a cluster@node2:~$ sudo mount -a

2.5 Defining a user for running MPI programs We define a user with the same name and same user ID in all of the nodes with a home directory in /mirror. Here we name it mpiuser. Also, we will change the owner of /mirror to mpiuser : cluster@node0:~$ sudo chown mpiuser /mirror

2.6 Installing the SSH Server Run this command in all of the nodes in order to install the OpenSSH Server : cluster@node0:~$ sudo apt-get install openssh-server

2.7 Setting up password less SSH for communication between nodes First we login with our new user to the Master node: 5

cluster@node0:~$ su mpiuser

Then we generate an RSA key pair for mpiuser: mpiuser@node0:~$ ssh-keygen -t rsa

We can keep the default ~/.ssh/id_rsa location. It is suggested to enter a strong passphrase for security reasons. Next, we add this key to the authorized keys : mpiuser@node0:~$ cd .ssh mpiuser@node0:~/.ssh$ cat id_pub.dsa >> authorized_keys

The home directory of mpiuser in all nodes is the same (/mirror/mpiuser), there is no need to run these commands on all nodes. If we didn't mirror the home directory, we can use ssh-copy-id <hostname> to copy a public key to another machine's authorized_keys file safely.

To test SSH run : mpiuser@node0:~$ ssh ub1 hostname

Now our hostname via the 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.

2.8 Installing MPICH2 Now the last task we need to install on all the machines is the MPI implementation. We can install MPICH2 using Synaptic by typing : sudo apt-get install mpich2

Alternatively, MPICH2 can be installed from source as explained in the MPICH installer guide or we can try using some other implementation such as OpenMPI. To test that the program did indeed install successfully enter this on all the machines : mpiuser@node0:~$ mpiuser@node0:~$ which mpiexec which mpirun

2.9 Setting up a machinefile Create a file called "machinefile" in mpiuser's home directory with node names followed by a colon and a number of processes to spawn: node2:2 node1 node0 # this will spawn 2 processes on node2 # this will spawn 1 process on node1 # this will spawn 1 process on node0


3.1 Produce output and result by issuing code. Change the directory to our mirror folder and write this MPI helloworld program in a file named 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; }

3.2 Compiling code Compile the following code: mpiuser@node0:~$ mpicc mpi_hello.c -o mpi_hello And run it (the parameter next to -n specifies the number of processes to spawn and distribute among nodes) : mpiuser@node0:~$ mpiexec -n 8 -f machinefile ./mpi_hello

We should now see an output similar to this : Hello from processor 0 of 3 Hello from processor 1 of 3 Hello from processor 2 of 3 Hello from processor 3 of 3