[Omp] VLAs in private clause

Shah, Sanjiv sanjiv.shah at intel.com
Tue Nov 4 13:57:27 PST 2003


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.

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




More information about the Omp mailing list