Question: Take any MPI code for estimating pi and change it to use pthreads. You can hard code the command line arguments and input of the
Take any MPI code for estimating pi and change it to use pthreads. You can hard code the command line arguments and input of the old code, and the number of threads. The main thread should create 5 new threads, which will compute partial values of pi and store them in distinct global memory locations. The main thread will then add these values and output the estimate of pi.
This is the MPI code I have.


Source2.cpp - Microsoft Visual Studio Express 2012 for Windows Desktop Quick Launch (Ctrl+Q) FILE EDIT VIEW PROJECT DEBUG TEAM TOOLS TEST WINDOW HELP Source2.cpp Sourcel.cpp cishw2.cpp HW4.cpp Solution Explorer E#include #include 2 Search Solution Explorer (Ctrl+, 4 Bint main (int argc, char argvl) Solution "Solution 110 projects) int myid, numproc, i; double pi-e.e, sum-9.9, begin-e., end -8.6, mypi, x, n, h; File fp; double input; fp fopen("input.txt", "w*") 18 12 13 14 15 16 17 18 19 20 21 MPI_Init (8argc, &argv); MPI-Comm rank (MPL-COWORLD, MPI-Comm size (MPI-COWORLD, 8myid); //Get process ID &numproc); //Get processes Number 1ORLD); //Synchronize all processes and get the begin tine MPI-Barrier(MPI-Cor begin MPI_Wtime); if(myid--9) //process fscanf(fp, "&input, &input) IInumber of intervals should be read from input.txt file by process MPI_Bcast (&input, 1, MPIDatatype, 0, MPI COMM WORLD); I/and then broadcast to other processes using user defined data type 23 25 26 27 /Each process will caculate a part of the sum h - 1.0 / (double) n; for (i -myid; i 2 Search Solution Explorer (Ctrl+, 4 Bint main (int argc, char argvl) Solution "Solution 110 projects) int myid, numproc, i; double pi-e.e, sum-9.9, begin-e., end -8.6, mypi, x, n, h; File fp; double input; fp fopen("input.txt", "w*") 18 12 13 14 15 16 17 18 19 20 21 MPI_Init (8argc, &argv); MPI-Comm rank (MPL-COWORLD, MPI-Comm size (MPI-COWORLD, 8myid); //Get process ID &numproc); //Get processes Number 1ORLD); //Synchronize all processes and get the begin tine MPI-Barrier(MPI-Cor begin MPI_Wtime); if(myid--9) //process fscanf(fp, "&input, &input) IInumber of intervals should be read from input.txt file by process MPI_Bcast (&input, 1, MPIDatatype, 0, MPI COMM WORLD); I/and then broadcast to other processes using user defined data type 23 25 26 27 /Each process will caculate a part of the sum h - 1.0 / (double) n; for (i -myid; i