[Omp] VLAs in private clause
Shah, Sanjiv
sanjiv.shah at intel.com
Wed Nov 5 10:01:37 PST 2003
I am afraid Fedor and KSG were right, I was wrong. This is not a VLA at
all, it is simply a formal argument. I didn't look at the example and
assumed it was a VLA we were talking about, as the text stated.
Sanjiv
-----Original Message-----
From: Omp-bounces at openmp.org [mailto:Omp-bounces at openmp.org] On Behalf
Of Fedor V. Sergeev
Sent: Tuesday, November 04, 2003 7:54 PM
To: Marina Kraeva
Cc: omp at openmp.org
Subject: RE: [Omp] VLAs in private clause
On Tue, 4 Nov 2003, Shah, Sanjiv wrote:
> KSG,
>
> This isn't quite correct. VLA's are an ANSI C 99 feature, and
> privatizing them is allowed, and it is the implementation's
> responsibility to allocate the storage for them.
Well, the testcase presented here is somewhat more tricky than that.
Generally VLAs are objects (C standard notion) and thus it would be
quite
logical to privatize them as a single array object, reserving a space
and
having no problems to access it.
Thus the testcase like this one:
void func(int n, int m) {
int a[n][m];
#pragma omp parallel private(a)
{
a[1][1]=1;
}
}
should work fine.
However original testcase is
void func(int n, int m, int a[n][m])
and here we get a VLA parameter. According to c99 (ISO/IEC 9899:1999),
"6.7.5.3 Function declarators" an array-type parameter is actually being
adjusted to pointer-type.
Thus "a" here is not int[n][m], it is int (*)[m], which is a pointer.
Attempt to access privatized pointer can lead to disasters. Segmentation
fault in Marina's case.
That, btw, explains why things start working with firstprivate.
regards,
Fedor.
>
> Marina, your example looks like legal OpenMP to me, and the compilers
> you are using appear to not support the mix of OpenMP and ANSI C99
> VLA's. This isn't surprising, since the OpenMP spec isn't crystal
clear
> on this point.
>
> Regards,
> Sanjiv
>
> -----Original Message-----
> From: Omp-bounces at openmp.org [mailto:Omp-bounces at openmp.org] On Behalf
> Of Kang Su
> Sent: Monday, November 03, 2003 8:05 PM
> To: Marina Kraeva; omp at openmp.org
> Subject: Re: [Omp] VLAs in private clause
>
>
> The problem with your code is that 'private' variables
> have an indeterminate value. Thus the address of 'a'
> is pointing to "who knows where". With 'firstprivate'
> this is fixed due to the fact that 'firstprivate' will
> construct the object.
>
> Also you use non-const array sizes, but I guess that
> works on a lot compilers.
>
> Thanks,
>
> KSG
>
>
> --- Marina Kraeva <kraeva at iastate.edu> wrote:
> > Hi,
> >
> > I have a question on listing VLAs (Variable Length
> > Arrays) as private.
> > The following example fails on 3 different platforms
> > (segmentation fault). One
> > of the compilers gave a warning that "Variable "a"
> > is used before it is
> > defined".
> > I don't understand where and how I was supposed to
> > define this "a". If I list
> > "a" as firstprivate (like in the example A.27 of the
> > C/C++ OpenMP API 2.0), then
> > everything works fine. Can anyone comment on this
> > example?
> >
> > Thanks!
> > Marina.
> >
> > ======================================
> > #include <omp.h>
> > #include <stdlib.h>
> >
> > int N = 10;
> > int M = 10;
> >
> > void func(int n, int m, int a[n][m]);
> >
> > void func(int n, int m, int a[n][m]) {
> > #pragma omp parallel private(a)
> > {
> > a[1][1]=1;
> > }
> > }
> >
> > int main()
> > {
> > int i, j;
> > int a[N][M];
> >
> > omp_set_dynamic(0);
> > omp_set_num_threads(2);
> >
> > for (i=0; i<N; i++)
> > for (j=0; j<M; j++)
> > a[i][j] = 1;
> >
> > func(N, M, a);
> >
> > return 0;
> > }
> >
> >
> >
> >
> >
> > _______________________________________________
> > Omp mailing list
> > Omp at openmp.org
> > http://openmp.org/mailman/listinfo/omp_openmp.org
>
>
> __________________________________
> Do you Yahoo!?
> Exclusive Video Premiere - Britney Spears
> http://launch.yahoo.com/promos/britneyspears/
>
> _______________________________________________
> Omp mailing list
> Omp at openmp.org
> http://openmp.org/mailman/listinfo/omp_openmp.org
>
> _______________________________________________
> Omp mailing list
> Omp at openmp.org
> http://openmp.org/mailman/listinfo/omp_openmp.org
>
_______________________________________________
Omp mailing list
Omp at openmp.org
http://openmp.org/mailman/listinfo/omp_openmp.org
More information about the Omp
mailing list