Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

1. Program-1. An interesting way of calculating n is to use a technique known as Monte Carlo, which involves randomization. This technique works as follows.

image text in transcribedimage text in transcribed

1. Program-1. An interesting way of calculating n is to use a technique known as Monte Carlo, which involves randomization. This technique works as follows. Suppose you have a circle inscribed within a square, as shown in the figure (assume that the radius of this circle is 1; thus we have a square of size 2x2). First, generate a series of points as simple (x, y) coordinates. These points must fall within the Cartesian coordinates that bound the square. Of the total number of random points that are generated, some will occur within the circle. Next, estimate a by performing the following calculation: 1-4 (number of points in circle) / (total number of points) Write a multi-threaded version of this algorithm that creates a separate thread (the slave- thread) to generate a number of random points. The slave-thread will count the number of points that occur within the circle (the hit_count) and store that result in the global variable circle_count. When the slave-thread has exited, the parent thread (the master-thread) will calculate and output the estimated value of t. It is worth experimenting with the number of random points generated. As a general rules, the greater the number of random points, the closer the approximation of t. Note: Program-l contains only 2 threads, a master-thread and its single slave-thread. Below, are codes for generating random numbers, as well as codes for determining if the random (x, y) point occurs within the circle. /* Generates a double precision random number */ double random_double() return random() / ((double) RAND MAX + 1); /* seed the random number generator */ srandom( (unsigned) time (NULL)); /*generate random numbers between -1.0 and +1.0 (exclusive) */ /* to obtain a random (x, y) point*/ x = random_double() * 2.0 - 1.0; y = random_double() * 2.0 - 1.0; /* is (x, y) point within the circle ? */ if ( sqrt (x*x + y*y)

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

Step: 3

blur-text-image

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

Database Systems For Advanced Applications 27th International Conference Dasfaa 2022 Virtual Event April 11 14 2022 Proceedings Part 2 Lncs 13246

Authors: Arnab Bhattacharya ,Janice Lee Mong Li ,Divyakant Agrawal ,P. Krishna Reddy ,Mukesh Mohania ,Anirban Mondal ,Vikram Goyal ,Rage Uday Kiran

1st Edition

3031001257, 978-3031001253

More Books

Students also viewed these Databases questions

Question

How autonomous should the target be left after the merger deal?

Answered: 1 week ago