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%...
-
Comparative balance sheets for 2011 and 2010 and a statement of income for 2011 are given below for Metagrobolize Industries. Additional information from the accounting records of Metagrobolize also...
-
Explain why a constant force on the vibrating mass has no effect on the steady-state vibration.
-
What are the key obstacles facing computer engineers regarding the development of quantum computers?
-
Norton Industries is installing a new computer system. The activities, the activity times, and the project network are as follows: The critical path calculation shows B-D-E-F-H is the critical path,...
-
a system administrator is performing patchwork to their organizations system. the administrator realizes the maintenance window will close before they complete the patchwork. what action must the...
-
Copy Fast Services was opened by Jarenz on January 1, 2008 with a cash investment of P 10,000. Additional transactions for the month are as follows: Jan 245678 6 7 8 9 14 15 19 20 25 6456 33333 30 31...
-
For Starbucks identify a roll management will play during The change process, means to achieve collaboration, how servant leadership can be utilized by management, and the role of technology in...
-
Can the survivors of a deceased person sue for defamation based on statements made about the deceased?
-
True Or False Manufacturers are obligated to use the most durable design possible.
-
In strict liability cases a. courts are fairly liberal about letting plaintiffs pose the question to the jury on the issue of whether a defect existed at the time it left the manufacturer. b. the...
-
If a plaintiff injures himself while misusing a hammer, a court could a. conclude that the manufacturer had no duty to produce a hammer that could withstand this type of misuse. b. conclude that the...
-
True Or False In a design-defect case the question is whether the defendant chose a design that posed an unreasonable danger to the plaintiff.
-
Alain is married and the father of two young children. He owns an excavation firm. Every month, he must pay $3,000 in fixed costs including rent, equipment rental and professional liability...
-
For each equation, (a) Write it in slope-intercept form (b) Give the slope of the line (c) Give the y-intercept (d) Graph the line. 7x - 3y = 3
-
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...
-
The following information has been extracted from the financial statements and the notes of Champigon Ltd. Required (a) Calculate the following for 2023 to one decimal place: i. current ratio ii....
-
Comparative figures from the statement of financial position for Warder Ltd are shown below. Required (a) Prepare common size statements for the company for both years, and comment on what this...
-
The following information has been extracted from the financial statements and notes thereto of Bass and Dide Ltd, consultants. Required (a) Calculate the following ratios for 2025: i. return on...
Study smarter with the SolutionInn App