Starting from:

$30

CS471-Assignment 2 MPI Solved

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:

1.  Calculate the Mean.

2.  For each number, subtract the mean and square the result.

3.  Calculate the mean of the squared differences.

4.  Take the square root of step three results.

1



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 numbers.

✔                    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.

More products