Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

need number 4.23 answered only. I posted 4.22 because 4.23 is based off of 4.22. ONLY IN C PROGRAMMING LANGUAGE!!!!! 422 An interesting way of

image text in transcribed

need number 4.23 answered only. I posted 4.22 because 4.23 is based off of 4.22. ONLY IN C PROGRAMMING LANGUAGE!!!!!

422 An interesting way of calculating 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 Figure 196 Chapter 4 Threads Figure 4.18 Monte Carlo technique for calculating pi. 4.18. (Assume that the radius of this circle is 1.) First, generate a series of random 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 by performing the following calculation: = 4 (number of points in circle) / (total number of points) Write a multithreaded version of this algorithm that creates a separate thread to generate a number of random the number of points that occur within the circle and store that result in a global variable. When this thread has exited, the parent thread will calculate and output the estimated value of . It is worth experimenting with the number of random points generated. As a general rule, the greater the number of points, the closer the approximation to In the source-code download for this text, we provide a sample program that provides a technique for generating random numbers, as well as determining if the random (xy) point occurs within the circle Readers interested in the details of the Monte Carlo method for esti- mating should consult the bibliography at the end of this chapter. In Chapter 5, we modify this exercise using relevant material from that chapter. The thread will count 4.23 Repeat Exercise 4.22, but instead of using a separate thread to generate random points, use OpenMP to parallelize the generation of points. Be careful not to place the calculation of in the parallel region, since you want to calculate only once

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 Security XI Status And Prospects

Authors: T.Y. Lin, Shelly Qian

1st Edition

0412820900, 978-0412820908

More Books

Students also viewed these Databases questions

Question

Apply critical thinking to the four stages of the writing process

Answered: 1 week ago