Master-Slave / Worker-Supervisor Architecture Implemented using Open MPI in C++
- This code implements the numerical integration method 'Trapezoidal Rule' to calculate the definite integral over the provided lower and upper limits using Open MPI.
- It estimates the integral using the following formula.
The greater the number of divisions, the more accurate the estimated calculation of the integral becomes (see the gif below | source: wikipedia)
- 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.
- 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
- 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.
- Code gets stuck at MPI_FINALIZE() which I found is a common and recurring issue after some research. Ctrl + C to force exit.