- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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!
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!
Link Copied
1 Reply
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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
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
Reply
Topic Options
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page