OpenMP in Small Bites/Scoping
OpenMP in Small Bites/Scoping /
Jump to navigation
Jump to search
Revision as of 17:35, 2 November 2020 by Tim-cramer-c1e6@rwth-aachen.de (talk | contribs)
HPC.NRW | |
---|---|
Other HPC Courses | |
1. | Gprof Tutorial |
2. | Introduction to Linux in HPC |
OpenMP in Small Bites | |
1. | Overview |
2. | Worksharing |
3. | Data Scoping |
4. | Non-Uniform Memory Access
|
Video
Quiz
1. What is the default data scoping of variable in a parallel region when this variable is declared before a parallel region?
2. What is the data scoping of the variables
a
, b
, c
and d
in the following code snippet in the parallel region? What is printed when executing the code? int a = 0;
int b = 23;
int c = -3;
# pragma omp parallel num_threads(2) private(a) reduction(+:c)
{
int d = omp_get_thread_num();
a = 42 + d;
# pragma omp critical
b = 1;
c += a + b;
}
c = c / 2;
printf("a=%d, b=%d, c=%d\n", a, b, c)
3. The following code snippet is wrong due to a missing data sharing attribute. How can you fix it?
int i, int s = 0;
# pragma omp parallel for
for (i = 1; i < 100; i++){
s = s + a[i];
}