I don't understand the following question:
Specify four possible outputs of the code when it is compiled with -fopenmp
and executed with two OpenMP threads:
int x = 0;
#pragma omp parallel
{
#pragma omp single
{
#pragma omp task
{
x++;
printf("task 1: %d\n", x);
}
#pragma omp task
{
x++;
printf("task 2: %d\n", x);
}
}
}
What "special" impact would the -fopenmp
have on this?
Are these possible outputs:
What about other possible outputs?
The two possibilities that you showed:
task 1: 1
task 2: 2
task 2: 1
task 1: 2
And
When the x++
execute first in both tasks, and print the first task then the second:
task 1: 2
task 2: 2
When the x++
execute first in both tasks, and print the second task then the first:
task 2: 2
task 1: 2