One way to get a numerical approximation of the number T is to use many terms in the formula 1 T= 41 (-1)* 1 1 – - + 7 1 ...] = 4 2k +1 k=0 A student implements this computation both in serial and parallel. The following listing gives the serial and parallel functions to compute number T, respectively The serial code estimates the number T correctly. However, the OpenMP parallel code does not. double seq_pi(int n){] double factor =1.0; double sum = 0.0; for (int k=0; k

Computer Networking: A Top-Down Approach (7th Edition)
7th Edition
ISBN:9780133594140
Author:James Kurose, Keith Ross
Publisher:James Kurose, Keith Ross
Chapter1: Computer Networks And The Internet
Section: Chapter Questions
Problem R1RQ: What is the difference between a host and an end system? List several different types of end...
icon
Related questions
Question
One way to get a numerical approximation of the number T is to use many terms in the formula
(-1)*
2k +1
1
1
ㅠ= 4[1
3
1
1
+
-... = 4
7
k=0
A student implements this computation both in serial and parallel. The following listing gives the serial and parallel functions to compute number T, respectively.
The serial code estimates the number T correctly. However, the OpenMP parallel code does not.
double seq_pi(int n){
double factor =1.0;
double sum = 0.0;
for (int k=0; k<n; k++) {
sum += factor/(2*k + 1);
factor = -factor;
}
return (4.0 * sum);
}
double par_pi(int n, int thread_count){
double factor = 1.0;
double sum = 0.0;
#pragma omp parallel for num_threads (thread_count) reduction (+:sum)
for(int k=0; k<n; k++) {
sum += factor/(2*k + 1);
factor = -factor;
return (4.0 * sum);
})
Which of the following statments is (or are) correct regarding the error(s) in the code?
O The scope of variable factor should be changed to private or firstprivate
O The code line sum += factor/(2*k + 1); should be enclosed in a #pragma omp critical section.
O There is a loop-carried deppendency in the parallel for loop.
O The scope of variable factor in the parallel region is incorrect.
Transcribed Image Text:One way to get a numerical approximation of the number T is to use many terms in the formula (-1)* 2k +1 1 1 ㅠ= 4[1 3 1 1 + -... = 4 7 k=0 A student implements this computation both in serial and parallel. The following listing gives the serial and parallel functions to compute number T, respectively. The serial code estimates the number T correctly. However, the OpenMP parallel code does not. double seq_pi(int n){ double factor =1.0; double sum = 0.0; for (int k=0; k<n; k++) { sum += factor/(2*k + 1); factor = -factor; } return (4.0 * sum); } double par_pi(int n, int thread_count){ double factor = 1.0; double sum = 0.0; #pragma omp parallel for num_threads (thread_count) reduction (+:sum) for(int k=0; k<n; k++) { sum += factor/(2*k + 1); factor = -factor; return (4.0 * sum); }) Which of the following statments is (or are) correct regarding the error(s) in the code? O The scope of variable factor should be changed to private or firstprivate O The code line sum += factor/(2*k + 1); should be enclosed in a #pragma omp critical section. O There is a loop-carried deppendency in the parallel for loop. O The scope of variable factor in the parallel region is incorrect.
Expert Solution
steps

Step by step

Solved in 2 steps

Blurred answer
Recommended textbooks for you
Computer Networking: A Top-Down Approach (7th Edi…
Computer Networking: A Top-Down Approach (7th Edi…
Computer Engineering
ISBN:
9780133594140
Author:
James Kurose, Keith Ross
Publisher:
PEARSON
Computer Organization and Design MIPS Edition, Fi…
Computer Organization and Design MIPS Edition, Fi…
Computer Engineering
ISBN:
9780124077263
Author:
David A. Patterson, John L. Hennessy
Publisher:
Elsevier Science
Network+ Guide to Networks (MindTap Course List)
Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:
9781337569330
Author:
Jill West, Tamara Dean, Jean Andrews
Publisher:
Cengage Learning
Concepts of Database Management
Concepts of Database Management
Computer Engineering
ISBN:
9781337093422
Author:
Joy L. Starks, Philip J. Pratt, Mary Z. Last
Publisher:
Cengage Learning
Prelude to Programming
Prelude to Programming
Computer Engineering
ISBN:
9780133750423
Author:
VENIT, Stewart
Publisher:
Pearson Education
Sc Business Data Communications and Networking, T…
Sc Business Data Communications and Networking, T…
Computer Engineering
ISBN:
9781119368830
Author:
FITZGERALD
Publisher:
WILEY