[Omp] A question about OpenMP 2.5
Tim Prince
n8tm at aol.com
Wed Mar 21 04:57:46 PDT 2007
anmey at rz.rwth-aachen.de wrote:
> Dear all,
>
> I don't think that the question was related to the OpenMP memory model,
> but to the wording and understanding of the current OpenMP specification.
>
> Brad looked at a perfectly legal piece of code
> (I slightly modified it using default(none) etc.)
> > void a1(int n, float *a, float *b)
> > {
> > int i;
> > #pragma omp parallel for default(none) shared(a,b) private(i,n)
> > for (i=1; i<n; i++) /* i is private by default */
> > b[i] = (a[i] + a[i-1]) / 2.0;
> > }
>
> and thinks that when reading the specs, the result of this loop shall be
> undefined.
>
> if the memory regions to which a and b are pointing to do not overlap
> (aliasing) multiple threads are writing to different memory locations
> and not to the same variable as b[i] is not a variable.
> This is not related to atomicity etc.
Appropriate use of restrict and (possibly) const qualifiers would be
required to permit this loop to be optimized, in the absence of omp
directive. As written, overlap is not excluded.
I don't think the OpenMP standard says so explicitly, but the omp
directive is likely to be taken as an assertion of no aliasing, thus
permitting threading, but possibly not permitting full optimization of
code executed by each thread.
More information about the Omp
mailing list