Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Monte Carlo methods are a widely used class of computational algorithms for simulating the behavior of various physical and mathematical systems, as well as for

Monte Carlo methods are a widely used class of computational algorithms for simulating the behavior of various physical and mathematical systems, as well as for other types of computations. They are distinguished from other simulation methods by being stochastic, that is nondeterministic in some manner usually accomplished by using random numbers.

For this assignment you will write a Monte Carlo method implemented using Pthreads to compute an estimate for the value of PI. Once again, please use the mogul for your implementation.

To compute the value of PI we know that the area of circle is PI r2. Therefore, the area of a unit circle (r = 1) centered at (0, 0) would have an area of exactly PI units.

image text in transcribed

To compute the value of PI we can generate random numbers between -1 and 1 for x and y and determine if the point represented by x and y falls within the circle. The value of PI can therefore be estimated by computing the ratio of the number of points that fall on or within the circle over the total the number of points.

To determine if a point falls within the circle we know that the diameter of a circle can be computed by d = sqrt(x2 + y2). Therefore, if the sqrt(x2 + y2) then the point falls on or within the circle.

Your program should implement the Monte Carlo method by generating at least 5 million points (preferably 10 million points), e.g., n=10,000,000 random points and compute the ratio of the points on or within the circle over the total number of points used. Note each point is represented by (x, y) so each iteration will require 2 random values between -1.0 and 1.0 inclusive, one for x and one for y.

You should run your program varying the number of threads (t) from t=1 to 10. Each thread should compute n/t iterations of the experiment and return the number of points on or within the circle to the master. The master can then aggregate the results over all the threads to compute the final estimated value of PI.

Please turn in your program along with the plots for execution time vs. number of threads by midnight of the due date.

x,y) = (cos ?, sin ?) x,y) = (cos ?, sin ?)

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Modern Database Management

Authors: Jeff Hoffer, Ramesh Venkataraman, Heikki Topi

13th Edition Global Edition

1292263350, 978-1292263359

More Books

Students also viewed these Databases questions

Question

Compare and contrast cultural preferences for online privacy

Answered: 1 week ago

Question

Provide examples of the various microcultures in the United States

Answered: 1 week ago