Running An MPI Cluster Within A LAN MPI Tutorial
Running An MPI Cluster Within A LAN MPI Tutorial
MPI Tutorial
Tutorials
Recommended Books
About
As with other tutorials, I am assuming you run Linux machines. The following
tutorial was tested with Ubuntu, but it should be the same with any other
distribution. And also, let’s consider your machine to be manager and the other
one as worker
Pre-requisite
If you have not installed MPICH2 in each of the machines, follow the steps here.
$ cat /etc/hosts
127.0.0.1 localhost
172.50.88.34 worker
The worker here is the machine you’d like to do your computation with.
Likewise, do the same about manager in the worker.
https://mpitutorial.com/tutorials/running-an-mpi-cluster-within-a-lan/ 1/8
1/1/22, 7:56 PM Running an MPI Cluster within a LAN · MPI Tutorial
Follow prompts and you will be good. Please don’t use useradd command to
create a new user as that doesn’t create a separate home for new users.
$ sudo apt
-get install openssh-server
And right after that, login with your newly created account
$ su - mpiuser
Since the ssh server is already installed, you must be able to login to other
machines by ssh username@hostname , at which you will be prompted to enter
the password of the username . To enable more easier login, we generate keys
and copy them to other machines’ list of authorized_keys .
$ ssh-keygen -t dsa
You can as well generate RSA keys. But again, it is totally up to you. If you want
more security, go with RSA. Else, DSA should do just fine. Now, add the
generated key to each of the other computers. In our case, the worker machine.
Do the above step for each of the worker machines and your own user
(localhost).
This will setup openssh-server for you to securely communicate with the
worker machines. ssh all machines once, so they get added to your list of
known_hosts . This is a very simple but essential step failing which
passwordless ssh will be a trouble.
$ eval `ssh-agent`
$ ssh-add ~/.ssh/id_dsa
https://mpitutorial.com/tutorials/running-an-mpi-cluster-within-a-lan/ 2/8
1/1/22, 7:56 PM Running an MPI Cluster within a LAN · MPI Tutorial
Now, assuming you’ve properly added your keys to other machines, you must be
able to login to other machines without any password prompt.
$ ssh worker
NFS-Server
Install the required packages by
Now, (assuming you are still logged into mpiuser ), let’s create a folder by the
name cloud that we will share across in the network.
$ mkdir cloud
$ cat /etc/exports
/home/mpiuser/cloud *(rw,sync,no_root_squash,no_subtree_check)
Here, instead of * you can specifically give out the IP address to which you
want to share this folder to. But, this will just make our job easier.
rw: This is to enable both read and write option. ro is for read-only.
sync: This applies changes to the shared directory only after changes are
committed.
no_subtree_check: This option prevents the subtree checking. When a
shared directory is the subdirectory of a larger filesystem, nfs performs
scans of every directory above it, in order to verify its permissions and
details. Disabling the subtree check may increase the reliability of NFS, but
reduce security.
no_root_squash: This allows root account to connect to the folder.
https://mpitutorial.com/tutorials/running-an-mpi-cluster-within-a-lan/ 3/8
1/1/22, 7:56 PM Running an MPI Cluster within a LAN · MPI Tutorial
$ exportfs -a
Run the above command, every time you make a change to /etc/exports .
NFS-worker
Install the required packages
$ mkdir cloud
$ df -h
To make the mount permanent so you don’t have to manually mount the shared
directory everytime you do a system reboot, you can create an entry in your file
systems table - i.e., /etc/fstab file like this:
$ cat /etc/fstab
https://mpitutorial.com/tutorials/running-an-mpi-cluster-within-a-lan/ 4/8
1/1/22, 7:56 PM Running an MPI Cluster within a LAN · MPI Tutorial
Or if you want to compile your own code, the name of which let’s say is
mpi_sample.c , you will compile it the way given below, to generate an
executable mpi_sample .
First copy your executable into the shared directory cloud or better yet, compile
your code within the NFS shared directory.
$ cd cloud/
$ pwd
/home/mpiuser/cloud
This should spin up your program in all of the machines that your manager is
connected to.
https://mpitutorial.com/tutorials/running-an-mpi-cluster-within-a-lan/ 5/8
1/1/22, 7:56 PM Running an MPI Cluster within a LAN · MPI Tutorial
you need to have the IP address entry of manager and the corresponding
worker node.
$ cat /etc/hosts
127.0.0.1 localhost
#127.0.1.1 1944
172.50.88.22 manager
172.50.88.56 worker1
172.50.88.34 worker2
172.50.88.54 worker3
172.50.88.60 worker4
172.50.88.46 worker5
$ cat /etc/hosts
127.0.0.1 localhost
#127.0.1.1 1947
172.50.88.22 manager
172.50.88.54 worker3
Whenever you try to run a process parallely using MPI, you can either run
the process locally or run it as a combination of local and remote nodes.
You cannot invoke a process only on other nodes.
To make this more clear, from manager node, this script can be invoked.
But, the following is not correct and will result in an error if invoked from
manager .
https://mpitutorial.com/tutorials/running-an-mpi-cluster-within-a-lan/ 6/8
1/1/22, 7:56 PM Running an MPI Cluster within a LAN · MPI Tutorial
Should you have any issues in setting up your local cluster, please don’t hesitate
to comment below so we can try to sort it out.
Want to contribute?
This site is hosted entirely on GitHub. This site is no longer being actively
contributed to by the original author (Wes Kendall), but it was placed on GitHub
in the hopes that others would write high-quality MPI tutorials. Click here for more
information about how you can contribute.
https://mpitutorial.com/tutorials/running-an-mpi-cluster-within-a-lan/ 7/8
1/1/22, 7:56 PM Running an MPI Cluster within a LAN · MPI Tutorial
LOG IN WITH
Name
https://mpitutorial.com/tutorials/running-an-mpi-cluster-within-a-lan/ 8/8