i have a very weird question about OpenMP. for the example below, the variable "a" should be "shared" by default according to the rule of OpenMP (Chapter:2.9.1.2: Data-sharing Attribute Rules for Variables Referenced in a Region but not in a Construct: Objects with dynamic storage duration are shared). when i run it , i get:
adre1: 0x7f51640008c0
adre2: 0x7f51640008c0
adre3: 0x1122d40
adre4: 0x7f51640008c0
which makes sense.
void jl()
{
char *a=(char *)malloc(10);
printf("adre1: %p\n",a);
#pragma omp task
{
printf("adre2: %p\n",a);
a=(char *)malloc(10);
printf("adre3: %p\n",a);
}
#pragma omp taskwait
printf("adre4: %p\n",a);
}
But if i add "shared" after task like this :
void jl()
{
char *a=(char *)malloc(10);
a[1]='c';
printf("adre1: %p\n",a);
#pragma omp task shared(a)
{
printf("adre2: %p\n",a);
a=(char *)malloc(10);
printf("adre3: %p\n",a);
}
#pragma omp taskwait
printf("adre4: %p\n",a);
}
the output is :
adre1: 0x1cefd40
adre2: 0x1cefd40
adre3: 0x7f93d00008c0
adre4: 0x7f93d00008c0
i was confused here. see when you redirect the address of variable "a" inside the task, it is visible outside, but i can not find such a data-attribute rule in Openmp. and what is the difference between these two cases?