(Solved) : Parallel Programming Question Using Language C Write Pthreads Program Uses Monte Carlo Met Q44096892 . . .
ParallelProgramming Question: Using language C,write a Pthreads program that uses a Monte Carlomethod to estimate π as follows:
Suppose we toss dartsrandomly at a square dartboard, whose bullseye is at the origin,and whose sides are 2 feet in length. Suppose also that there is acircle inscribed in the square dartboard. The radius of the circleis 1 foot, and its area is π square feet. If the points that arehit by the darts are uniformly distributed (and we always hit thesquare), then the number of darts that hit inside the circle shouldapproximately satisfy the equation
number in circle/totalnumber of tosses = π/4 ,
since the ratio of thearea of the circle to the area of the square is π/4.
We can use thisformula to estimate the value of π with a random numbergenerator:
number in circle =0;
for (toss = 0; toss< number of tosses; toss++) {
x = random doublebetween −1 and 1;
y = random doublebetween −1 and 1;
distance squared = x∗x+ y∗y;
if (distance squared<= 1) number in circle++;
}
pi estimate = 4∗numberin circle/((double) number of tosses);
This is called a“Monte Carlo” method, since it uses randomness (the darttosses).
Write a Pthreadsprogram that uses a Monte Carlo method to estimate π. The mainthread should read in the total number of tosses and print theestimate. You may want to use long long ints for the number of hitsin the circle and the number of tosses, since both may have to bevery large to get a reasonable estimate of π .
Expert Answer
Answer to Parallel Programming Question: Using language C, write a Pthreads program that uses a Monte Carlo method to estimate π …
OR