Question: This formula is used for computing pi ( pi ) , and it takes a lot of terms on the right - hand side before

This formula is used for computing pi(pi), and it takes a lot of terms on the right-hand side before
pi value is very accurate. Meaning that the bigger the n, the more accurate the pi estimation.
The following serial code uses this formula:
for (i =0; i n; i++){
if(i%2==0)
factor=1;
else
factor=-1;
sum += factor/(2*i+1);
}
pi =4.0*sum;
Write a multithreaded program by using c++ that calculates pi using the above formula by dividing the iterations
in the for loop among the threads. To simplify the computations, let's assume that the number of
working threads is 2 and n=1000000.
After the two working threads split the iterations and each thread has its own local sum, they update
the global variable sum, and the parent thread outputs the sum (i.e., pi estimation) once the
workers have exited.
Note that if there is a critical section, you need to protect it from race condition.
This formula is used for computing pi ( pi ) ,

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 Programming Questions!