#include int main(int argc, char *argv[]) { int i, thread_id; int glob_nloops, priv_nloops; glob_nloops = 0; /

Business, Finance, Economics, Accounting, Operations Management, Computer Science, Electrical Engineering, Mechanical Engineering, Civil Engineering, Chemical Engineering, Algebra, Precalculus, Statistics and Probabilty, Advanced Math, Physics, Chemistry, Biology, Nursing, Psychology, Certifications, Tests, Prep, and more.
Post Reply
answerhappygod
Site Admin
Posts: 899603
Joined: Mon Aug 02, 2021 8:13 am

#include int main(int argc, char *argv[]) { int i, thread_id; int glob_nloops, priv_nloops; glob_nloops = 0; /

Post by answerhappygod »

#include <stdio.h>
int main(int
argc, char *argv[])
{
int i, thread_id;
int glob_nloops,
priv_nloops;
glob_nloops = 0;
// parallelize this code
…………………………
#pragma omp parallel private(priv_nloops, thread_id)
{
priv_nloops = 0;
thread_id =
……………………………………?
// parallelize this
code
#pragma omp for
…………………………………………
for
(i=0; i<100000; ++i)
{
++priv_nloops;
}
// make this code
critical
#pragma omp critical
……………………………………
{
printf("Thread %d is adding its iterations (%d) to sum
(%d), ",
thread_id, priv_nloops, glob_nloops);
glob_nloops += priv_nloops;
printf(" total nloops is now %d.\n", glob_nloops);
}
}
printf("Total # loop iterations is %d\n",
glob_nloops);
return 0;
}
p=1
p=2
p=4
Speed up
(S)
1
Efficiency
(E)
100%
Join a community of subject matter experts. Register for FREE to view solutions, replies, and use search function. Request answer by replying!
Post Reply