According to the OpenMP memory model , the following is indicated:
int *p0 = NULL, *p1 = NULL;
#pragma omp parallel shared(p0,p1)
{
int x;
p0 = &x; p1 = &x;
*p1 ... *p0 ...
}
My example is as follows:
int *p0 = NULL, *p1 = NULL;
#pragma omp parallel shared(p0,p1)
{
int x;
p0 = &x; p1 = &x;
#pragma omp flush
#pragma omp barrier
*p1 ... *p0 ...
#pragma omp barrier
}
Is this wrong? I cannot find something in a memory model that would forbid it.
I assume that my toy example is correct, since in the memory model in 3.1 they allow the task to have access to a private variable while the programmer ensures that he is still alive. Given the fact that tasks can be decoupled, they can theoretically be executed as part of another workflow, which allows the OpenMP thread to access the private memory of another.
source
share