PrepAway - Latest Free Exam Questions & Answers

Which code segment should you insert at line 13?

You develop a parallel application that will be deployed on a Windows HPC Server 2008 cluster. You write the following code segment that computes an approximation to Pi. (Line numbers are included for reference only.)

01 static int totDarts = 10000;
02 int numDarts = 0;
04 MPI_Comm_size(MPI_COMM_WORLD, &commSize);
05 MPI_Comm_rank(MPI_COMM_WORLD, &commRank);
07 for(i = 0; i < totDarts; i++) {
08 x = 2 * (randomNr() – 0.5);
09 y = 2 * (randomNr() – 0.5);
10 if (x*x + y*y <= 1.0)
11 ++numDarts;
12 }
14 if(commRank == 0) {
15 pi = 4 * total/(commSize * totDarts);
16 printf("Pi = %dn", pi);
17 }

You need to ensure that the total number of numDarts is only available on the process that has a rank 0.
Which code segment should you insert at line 13?

PrepAway - Latest Free Exam Questions & Answers

A.
MPI_Reduce(&numDarts, &total, 1, MPI_INT, MPI_SUM, 0, MPI_COMM_WORLD)

B.
MPI_Allreduce(&total, &numDarts, 1, MPI_INT, MPI_SUM, MPI_COMM_WORLD)

C.
MPI_Gather(&numDarts, 1, MPI_INT, &total, 1, MPI_INT, 0, MPI_COMM_WORLD)

D.
MPI_Allgather(&numDarts, 1, MPI_INT, &total, 1, MPI_INT, MPI_COMM_WORLD)


Leave a Reply