Calculating Standard Deviation Problem Statement:
Write a parallel c program to calculate standard deviation using MPI_Bcast, MPI_Reduce & MPI_Allreduce ONLY. Don’t use MPI_Send and MPI_Receive
Given:
An integer n (number of elements per each process).
Output:
Standard deviation of randomly generated (n * numberOfProcesses) elements.
How to Calculate Standard Deviation:
- Calculate the Mean.
- For each number, subtract the mean and square the result.
- Calculate the mean of the squared differences.
- Take the square root of step three results.
Parallelization Scenario:
Master Process:
- Read n from the user.
- Broadcast n to each slave process using MPI_Bcast. ✔ Calculate the square root of the mean of squared differences.
Slave Process:
- Get n through the MPI_Bcast call.
- Generate n random elements. So each process will generate n
- Calculate local sum of the generated n elements.
- Share this local sum with the rest of the processes using MPI_Allreduce.
- Calculate the global mean. (Total sum of elements / n * numOfProcesses).
- Calculate local sum of squared differences from the mean. Sum (n – mean)2
- Share this local sum of squared differences with the master process using MPI_Reduce call.
Reviews
There are no reviews yet.