This guide provides step-by-step instructions for creating a master and slave, configuring SSH, configuring NFS, installing MPI, and running Bubble Sort code with Python on Ubuntu Desktop.
- Devices and Tools to Prepare
- Bridged Topology
- Creating Master and Slave
- SSH Configuration
- NFS Configuration
- MPI Installation
- Running Python Code - Bubble Sort
- Ubuntu Desktop
- Ubuntu Desktop Master
- Ubuntu Desktop Slave 1
- Ubuntu Desktop Slave 2
- Ubuntu Desktop Slave 3
- MPI (Master and Slave)
- SSH (Master and Slave)
- NFS (Master and Slave)
- Python Bubble Sort Code
- Ensure that each master and slave uses a Network Bridge Adapter and is connected to the internet.
- Determine which device will be the master, slave1, slave2, and slave3.
- Create a new user with the following command on the master and each slave:
sudo adduser mpiuser
- Grant root access with the command:
Repeat the above steps for each slave.
sudo usermod -aG sudo mpiuser
- Log in to each server with the user
mpiuser:su - mpiuser
- Update Ubuntu Desktop and install tools:
sudo apt update && sudo apt upgrade sudo apt install net-tools vim - Configure the
/etc/hostsfile on the master, slave1, slave2, and slave3. Register the IP and hostname of each computer.
- Install OpenSSH on the master and all slaves:
sudo apt install openssh-server
- Generate a key on the master:
ssh-keygen -t rsa
- Copy the public key to each slave using the following command in the
.sshdirectory:Repeat the command for each slave.cd .ssh cat id_rsa.pub | ssh mpiuser@slave1 "mkdir .ssh; cat >> .ssh/authorized_keys"
- Create a shared folder on the master and each slave:
mkdir /home/mpiuser/bubble
- Install NFS on the master:
sudo apt install nfs-kernel-server
- Configure the
/etc/exportsfile on the master. Add the following line at the end of the file:The Shared Folder location is the directory where the bubble file was created above./home/mpiuser/bubble *(rw,sync,no_root_squash,no_subtree_check) - Restart NFS Server:
sudo exportfs -a sudo systemctl restart nfs-kernel-server
- Install NFS on each slave:
sudo apt install nfs-common
- Mount the shared folder from the master to each slave:
Repeat the command for each slave.
sudo mount master:/home/mpiuser/bubble /home/mpiuser/bubble
- Install Open MPI on the master and all slaves:
sudo apt install openmpi-bin libopenmpi-dev
- Install the MPI library via pip:
sudo apt install python3-pip pip install mpi4py
-
Create a new Python file:
touch /home/mpiuser/bubble/bubble.py
-
Navigate to that directory and edit the Python file:
cd /home/mpiuser/bubble nano bubble.pyThen create the Python Bubble Sort code. Save by pressing
CTRL + Xand then pressY. bubble.py code -
Run the code on the master:
mpirun -np 4 -host master,slave1,slave2,slave3 python3 bubble.py
If the output like this appears, it has been successful, displaying the output on both the master and slaves, with the output being 4, which is the output from the master, slave1, slave2, and slave3. So what we sorted here is an array: [5, 3, 4, 1, 2] sorted to [1, 2, 3, 4, 5].
