Question
a) Give the contents of array x after the execution of the following OpenMP code fragment if possible, or give the error if there is
a)
Give the contents of array x after the execution of the following OpenMP code fragment if possible, or give the error if there is one. Assume that there are 5 threads all together:
int i, p, x[5] = {1,1,1,1,1},
y[5]={0,1,2,3,4}; #pragma omp parallel private (p) {
p=5; #pragma omp for
for (i=0; i<5; i++) x[i]=y[i]+p;
} /* omp end parallel */
b) Give the output of the following OpenMP code fragment if possible, or give the error if there is one. Assume that there are 4 threads all together:
int i; double sum = 0.0; #pragma omp parallel for reduction(+:sum)
for (i=1; i <= 4; i++) sum = sum + i;
printf("The sum is %lf ", sum); (c) Give the output of the following OpenMP code fragment if possible, or give the error if there is one. Assume that there are 4 threads all together:
int i; double sum; #pragma omp parallel private (sum) {
sum = 0.0; for (i=1; i <= 4; i++)
sum = sum + i; printf("The sum is %lf ", sum);
}
(d) Give the output of the following OpenMP code fragment if possible, or give the error if there is one. Assume that there are 4 threads all together:
int i; double sum = 0.0; #pragma omp parallel shared (sum) {
for (i=1; i <= 4; i++) sum = sum + i;
} printf("The sum is %lf ", sum);
(e) Give the output of the following OpenMP code if possible, or give the error if there is one. Assume that there are 4 threads all together:
int i; double sum = 0.0; #pragma omp parallel private (sum) {
for (i=1; i <= 4; i++) sum = sum + 1;
} printf("The sum is %lf ", sum);
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