Skip to content

Master-Slave / Worker-Supervisor Architecture Implemented using Open MPI in C++

License

Notifications You must be signed in to change notification settings

MuhammadHabibKhan/master-slave-mpi

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 

Repository files navigation

master-slave-mpi

Master-Slave / Worker-Supervisor Architecture Implemented using Open MPI in C++

About

  • This code implements the numerical integration method 'Trapezoidal Rule' to calculate the definite integral over the provided lower and upper limits using Open MPI.

Trapezoidal Rule

  • It estimates the integral using the following formula.

trapezoidal  

The greater the number of divisions, the more accurate the estimated calculation of the integral becomes (see the gif below | source: wikipedia)

Trapezium2

Calculations

  • The looped part of the formula is calculated as per how many divisions you want in your calculation. This workload is divided among the different MPI processes for faster calculation.
  • However, in this current implementation, I have not assigned any workload to master or rank 0. It only calculates the end terms and multiplies the result with width.

Running the Code

NOTE: mpiCC -> C++ | mpicc -> C

  • The code is based on Open MPI which may be pre-installed on your linux distro.
  • Type the following command to see location of the library.
mpiCC --showme
  • If not installed, type the following command to install binaries, documentation and lib files of Open MPI.
sudo apt install openmpi-bin openmpi-doc libopenmpi-dev
  • Open MPI is generally stored under
/usr/include/x86-64-linux-gnu/
  • Make sure the path is included in your includePath as well as path to your binaries.
  • Use the following command to compile the MPI code.
mpiCC trap.cpp -o trap.exe
  • Use mpirun or mpiexec command to run the code. (here 4 is the number of MPI Process that will execute)
mpirun --hostfile config.txt -np 4 trap.exe

Configuration

  • Change the expressions (marked with *** comments) according to the integral you are calculating.
  • Please change the config file and replace the IP address with that of your devices in the cluster.
  • Set slots as per your need | slots are amount of process that will run on a device.
  • Use --oversubscribe to run processes > number of cores.

Issues

  • Code gets stuck at MPI_FINALIZE() which I found is a common and recurring issue after some research. Ctrl + C to force exit.

Additional Material

  • Use this guide to create cluster with your devices.
  • Use this guide to run WSL on your Windows machine to run Unix-based code with VSCode.
  • You can contact me for a sequential implementation of the trapzoidal rule that uses of muParser to parse expressions and integrate that into the cluster.

About

Master-Slave / Worker-Supervisor Architecture Implemented using Open MPI in C++

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Languages