Intel® Moderncode for Parallel Architectures
Support for developing parallel programming applications on Intel® Architecture.
1696 Discussions

allocatable array should only be allocate in omp zone?

vectorzhang
Beginner
215 Views
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!
0 Kudos
1 Reply
jimdempseyatthecove
Honored Contributor III
215 Views
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
0 Kudos
Reply