[Omp] VLAs in private clause

Marina Kraeva kraeva at iastate.edu
Mon Nov 3 11:24:21 PST 2003


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;
}








More information about the Omp mailing list