[Omp] VLAs in private clause
Kang Su
kangsu at yahoo.com
Mon Nov 3 18:04:57 PST 2003
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/
More information about the Omp
mailing list