allocatable array should only be allocate in omp zone?

allocatable array should only be allocate in omp zone?

I have a question about allocatable array in omp zone.
An allocatable array, which is private in parallel zone, is already allocated before go to the parallel zone, why there is still an error 'attempt to fetch from allocatable variable *** which is not allocated'?
Is it should allocate in each thread? or there is any other way?

thanks!

2 posts / 0 new
Last post
For more complete information about compiler optimizations, see our Optimization Notice.

When you want private allocatable arrays inside a parallel region (zone) have an unallocated array descriptor outside the region and then perform the thread allocation within the region.

C++

double* array;
...
#pragma omp parallel private(array)
{
array = new double[sizeArray];
#pragma omp for
for(int i = 0; i < sizeOther; ++i)
{
...
}
delete [] array;
}

Fortran would use different looking OpenMP directives. The design would be the same.

Note, the C++ programmer would be advised to place the double* array; inside the scope of the parallel region.
The Fortran programmer must declare the array descriptor up at the variable declaration section of the subroutine. This is why you pass in an empty array descriptor.

Jim Dempsey

www.quickthreadprogramming.com

Login to leave a comment.