Question: The simplest harmonic progression is 1/1, 1/2, 1/3, Let S n = S n i = 1 1/ i . Write a parallel program in

The simplest harmonic progression is 1/1, 1/2, 1/3, Let Sn = Sni = 1 1/i.

Write a parallel program in C/C++ using OpenMP that computes these sums to arbitrary precision after the decimal point. For example, S7 = 2.592857142847, to 12 digits of precision after the decimal point.

Below is the MPI version of the code but we need it to work using OpenMP:

main(int argc, char *argc[])

{

int i, n, d, id, p;

double sum;

MPI_Init(&argc, &argv);

MPI_Comm_rank(MPI_COMM_WORLD, &id);

MPI_Comm_size(MPI_COMM_WORLD, &p);

if (id == 0) {

printf(Please input n?);

scanf(%d, &n);

printf(Please input d?);

scanf(%d, &d);

}

MPI_Bcast(&n, 1, MPI_INT, 0, MPI_COMM_WORLD);

for (i = id; i <= n; i += p) {

sum += 1/i;

}

MPI_Reduce(&sum, &sum, 1, MPI_DOUBLE, MPI_SUM, 0,

MPI_COMM_WORLD);

if (id == 0) {

printf(The sum = %.*d , d, sum);

}

MPI_Finalize();

return 0;

}

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!