Skip to content

Xaauvaal/MPI-Python-BubbleSort

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

16 Commits
 
 
 
 
 
 
 
 

Repository files navigation

MPI-BubbleSort

Running Bubble Sort Python with MPI Multinode Cluster on Ubuntu Desktop

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.

Table of Contents

Devices and Tools to Prepare

  1. Ubuntu Desktop
    • Ubuntu Desktop Master
    • Ubuntu Desktop Slave 1
    • Ubuntu Desktop Slave 2
    • Ubuntu Desktop Slave 3
  2. MPI (Master and Slave)
  3. SSH (Master and Slave)
  4. NFS (Master and Slave)
  5. Python Bubble Sort Code

Bridged Topology

Topology

Creating Master and Slave

  1. Ensure that each master and slave uses a Network Bridge Adapter and is connected to the internet.
  2. Determine which device will be the master, slave1, slave2, and slave3.
  3. Create a new user with the following command on the master and each slave:
    sudo adduser mpiuser
  4. Grant root access with the command:
    sudo usermod -aG sudo mpiuser
    Repeat the above steps for each slave.
  5. Log in to each server with the user mpiuser:
    su - mpiuser
  6. Update Ubuntu Desktop and install tools:
    sudo apt update && sudo apt upgrade
    sudo apt install net-tools vim
  7. Configure the /etc/hosts file on the master, slave1, slave2, and slave3. Register the IP and hostname of each computer.

SSH Configuration

  1. Install OpenSSH on the master and all slaves:
    sudo apt install openssh-server
  2. Generate a key on the master:
    ssh-keygen -t rsa
  3. Copy the public key to each slave using the following command in the .ssh directory:
    cd .ssh
    cat id_rsa.pub | ssh mpiuser@slave1 "mkdir .ssh; cat >> .ssh/authorized_keys"
    Repeat the command for each slave.

NFS Configuration

  1. Create a shared folder on the master and each slave:
    mkdir /home/mpiuser/bubble
  2. Install NFS on the master:
    sudo apt install nfs-kernel-server
  3. Configure the /etc/exports file on the master. Add the following line at the end of the file:
    /home/mpiuser/bubble *(rw,sync,no_root_squash,no_subtree_check)
    
    The Shared Folder location is the directory where the bubble file was created above.
  4. Restart NFS Server:
    sudo exportfs -a
    sudo systemctl restart nfs-kernel-server
  5. Install NFS on each slave:
    sudo apt install nfs-common
  6. Mount the shared folder from the master to each slave:
    sudo mount master:/home/mpiuser/bubble /home/mpiuser/bubble
    Repeat the command for each slave.

MPI Installation

  1. Install Open MPI on the master and all slaves:
    sudo apt install openmpi-bin libopenmpi-dev
  2. Install the MPI library via pip:
    sudo apt install python3-pip
    pip install mpi4py

Running Python Code - Bubble Sort

  1. Create a new Python file:

    touch /home/mpiuser/bubble/bubble.py
  2. Navigate to that directory and edit the Python file:

    cd /home/mpiuser/bubble
    nano bubble.py

    Then create the Python Bubble Sort code. Save by pressing CTRL + X and then press Y. bubble.py code

  3. Run the code on the master:

    mpirun -np 4 -host master,slave1,slave2,slave3 python3 bubble.py

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

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages