I am quoting p. 123 of the specifications. I cannot understand the purpose of this statement. Assume I use a pointer for a dynamically allocated object as in:
Code: Select all
int * x = new int[10];
#pragma omp parallel private(x)
{
int tid = omp_get_thread_num();
x = new int;
*x = tid;
sleep(1);
printf("tid, x = %d %d\n", tid, *x);
}
What I don't understand is why the specification has to clarify the data-sharing attribute of an object with dynamic storage duration. Is there an example where this rule applies and is used?
How can one use an object with dynamic storage duration without a pointer? One can use a reference to refer to a dynamically allocated object. But then the specification on p. 137 already states that a reference is not possible in the private clause. So a reference must be shared.
I tried to compiled different codes. Here are some results.
If I compile the following code
Code: Select all
int z = 3;
int & y = z;
#pragma omp parallel shared(y)
{
}
Code: Select all
test_sharing.c:17: error: ‘y’ is predetermined ‘shared’ for ‘shared’
Code: Select all
$ gcc --version
i686-apple-darwin11-llvm-gcc-4.2 (GCC) 4.2.1 (Based on Apple Inc. build 5658) (LLVM build 2336.9.00)
If I use a dynamically allocated pointer, it's the same thing:
Code: Select all
int * x = new int;
int & y = *x;
#pragma omp parallel shared(y)
{
}
If this reasoning is correct, it seems that the specification should really say something about references rather than dynamically allocated objects.
I would appreciate some clarification on this technical point. Thank you.