Write a multithreaded program that calculates pi using the above formula by dividing the iterations in...
Fantastic news! We've Found the answer you've been seeking!
Question:
Transcribed Image Text:
Write a multithreaded program 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 will output 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 the race condition. Option 2. 7=41- 1 1 + for (i = 0; i<n; i++) { if(i82==0) factor=1; factor=-1; sum += factor/(2*1+1); } pi= 4.0 sum; else 1 5 7 This formula is used for computing pi(a), 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: ++ (−1)²2_¹ 2n+1 Write a multithreaded program 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 will output 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 the race condition. Option 2. 7=41- 1 1 + for (i = 0; i<n; i++) { if(i82==0) factor=1; factor=-1; sum += factor/(2*1+1); } pi= 4.0 sum; else 1 5 7 This formula is used for computing pi(a), 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: ++ (−1)²2_¹ 2n+1 Write a multithreaded program 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 will output 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 the race condition. Option 2. 7=41- 1 1 + for (i = 0; i<n; i++) { if(i82==0) factor=1; factor=-1; sum += factor/(2*1+1); } pi= 4.0 sum; else 1 5 7 This formula is used for computing pi(a), 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: ++ (−1)²2_¹ 2n+1 Write a multithreaded program 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 will output 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 the race condition. Option 2. 7=41- 1 1 + for (i = 0; i<n; i++) { if(i82==0) factor=1; factor=-1; sum += factor/(2*1+1); } pi= 4.0 sum; else 1 5 7 This formula is used for computing pi(a), 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: ++ (−1)²2_¹ 2n+1
Expert Answer:
Answer rating: 100% (QA)
include include define NUMBEROFTHREADS 2 define N 1000000 double sum 00 pthreadmutext mutex void calculatePIvoid threadNumber long tNum longthreadNumb... View the full answer
Related Book For
Elementary Statistics A step by step approach
ISBN: 978-0073386102
8th edition
Authors: Allan Bluman
Posted Date:
Students also viewed these finance questions
-
Write a multithreaded program that implements the banker's algorithm discussed in Section 7.5.3. Create n threads that request and release resources from the bank. The banker will grant the request...
-
The outer loop controls the number of students. Note that the inner loop of this program is always executed exactly three times, once for each day of the long weekend. Modify the code so that the...
-
Assume that Kevin has been working for you for five years. He has had an excellent work history and has received generous pay raises in response. The raises have been so generous that Kevin is quite...
-
1. The two taxes paid on most purchases are the amount of each tax is % and and the % respectively. 2. Use the "10% + 5%" method of estimating total cost. Estimated Rounded Cost Item Cost 10% 5%...
-
Firm B is considering whether to pursue an R&D effort to develop a powerful new microchip. One concern with the design is that the chip might generate too much heat operating at high speeds. Indeed,...
-
As a general rule government employees (WRKGOVT: 1 = Government, 2 = Private) have more job security than do private sector employees. Do they also have higher incomes RINCOME)? a. Conduct a test to...
-
In the following contingency table, the row and column totals are presented, but the data for one row and one column have been omitted. Thus, there are data for only r 1 rows and c 1 columns. Show...
-
At December 31, 2012, Northern Corporation reported the stockholders equity accounts shown here (with dollar amounts in millions, except per-share amounts). Common stock $4.00 par value per share,...
-
Pinder Co. produces and sells high-quality video equipment. To finance its operations, Pinder issued $20,000,000 of four-year, 8% bonds, with interest payable semiannually, at a market (effective)...
-
Simtek projects year-end EBIT of $800M which is expected to grow at 5% annually, and capital expenditures will equal depreciation. Simtek has $4,590M of 6% perpetual debt trading at face value and no...
-
Keyser Company's record of transactions for the month of April is as follows. Instructions a. Assuming that periodic inventory records are kept, compute the inventory at April 30 using (1) LIFO and...
-
Explain the need for contingency funding in project budgets, and its various aspects.
-
Discuss the activity-based costing method in developing a project budget.
-
Discuss the different types of payment arrangements that are used to manage expenditures in projects.
-
Describe the key features in developing a project budget.
-
Define the term cash flow.
-
Roger Elliot, vice president and loan officer of the First National Bank of Cincinnati, was recently alerted to the deteriorating financial position of one of his clients, Seal-best, Inc., by his...
-
You are standing on the top of a building and throw a ball vertically upward. After 2 seconds, the ball passes you on the way down, and 2 seconds after that, it hits the ground below. a. What is the...
-
a. Number of pizzas sold by Pizza Express each day. b. Relative humidity levels in operating rooms at local hospitals. c. Number of bananas in a bunch at several local supermarkets. d. Lifetimes (in...
-
The table below shows the number of students (in thousands) participating in various programs at both two-year and four-year institutions. At = 0.05, can it be concluded that there is a relationship...
-
The dean of students wants to see whether there is a significant difference in ages of resident students and commuting students. She selects a sample of 50 students from each group. The ages are...
-
Consider the MOSFET class-AB output stage in Figure 8.26. The parameters are: \(V_{D D}=10 \mathrm{~V}\) and \(R_{L}=100 \Omega\). For transistors \(M_{n}\) and \(M_{p}, V_{T N}=\) \(-V_{T P}=1...
-
An enhancement-mode MOSFET class-AB output stage is shown in Figure P8.29. The threshold voltage of each transistor is \(V_{T N}=-V_{T P}=1 \mathrm{~V}\) and the conduction parameters of the output...
-
For the inductively coupled amplifier in Figure 8.28(a), the parameters are: \(V_{C C}=15 \mathrm{~V}, R_{E}=0.1 \mathrm{k} \Omega\), and \(R_{L}=1 \mathrm{k} \Omega\). The transistor parameters are...
Study smarter with the SolutionInn App