Answered step by step
Verified Expert Solution
Question
1 Approved Answer
c) Ramanujan's formula for Pi calculation is as follows: 12V2 (4n)! 26390n + 1103 39611 2013 9 X N30 4 ECIE 1314 Operating Systems Consider
c) Ramanujan's formula for Pi calculation is as follows: 12V2 (4n)! 26390n + 1103 39611 2013 9 X N30 4 ECIE 1314 Operating Systems Consider the following Rust code to implement the # calculation using multithreads. use rayon: prelude::: : 2 use std::f64::conats::: 3 use std::time:: Instant; 4 use std::envi 5 6 In factorial (N: usize) - 164 //max N is 170 (N: ) -> 7 let retval - 1.0; B for a in 1..-N retval - retval" in as 164); N ); 1 9 retval 10 11 12 In calculatePI (NIter: usize) --> 164 13 let Factor = 12.0*SORT_21/9802.0; 14 // using parallel reduce 15 let Sum: 764 - 10..-Niter).iter).map 111 16 let n = 1 as 164; 17 lel Part = Factor + factorial (4+1)+(1103.0 + 26390.0+n/ 18 (factorial(i) -powf (4.0). 396_64.powf (4.0*n)); 19 Part 20 1).reduce (1 0.0, a, bl a + b): 21 1.0/Sum 22 23 En maini 25 let startTime - Instant:: now(); 26 // Check the calculateci pt with the constant pr 27 printin! "Estimated Pi: 1:.50)", calculatePI (40); 20 printin! ("Constant Fl: 1:.50)", PI); 29 lot Elapsedtime = StartTime.elapsed): 30 31 match env::var ("RAYON NUM_THREADS") 32 OK(NThreads) => printin! Using tl threads.", NThreads) 33 Err(e) => println("Could not read env variable U",el, 34 12 35 println("ime elapsed is: (!!)", ElapsedTime); 36 i. Debug the Rust code so that it can be run in multi-threads using Rayon. (4 marks) ii. The Ramanujan's r. calculation Rust code has been compiled and run on a multicore system with AMD Ryzen 9 5900X 4.80 GHz (12 cores with 24 threads) and 64 GBytes RAM. By setting the Rayon environment variable (RAYON_NUM_THREADS), the number of threads was set to 1 and 24, respectively, and the elapsed time is shown in Table 4. Calculate the speed up and predict the fraction of the serial part for NThreads = 24 using Amdahl's law. (4 marks) 4 Table 4. Elapsed Parallel Processing Time NThreads Elapsed Processing Time (in milliseconds) 1 108.4 24 7.2 iii. Calculate the upper bound limit of achievable speedup using Amdahl's law. (2 marks)
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started