I've stumbled on a gfortran "Fortran runtime error" when using allocatable arrays inside OpenMP PARALLEL DO LOOPS
Consider the folowing reduced testcase. >> cat allocate_in_loop.f90 program allocate_in_loop use omp_lib, only: omp_get_num_threads,omp_get_thread_num implicit none integer :: numthreads,n,it,i integer, dimension(:), allocatable :: int_array ! !$OMP PARALLEL DEFAULT(shared) NUM_THREADS(4) numthreads=omp_get_num_threads() !$OMP DO PRIVATE(n,it,int_array,i) SCHEDULE(static) do n=1,numthreads it=omp_get_thread_num() allocate(int_array(3)) do i=1,3 int_array(i)=(it)*100+i write(*,'(a,i2,a,i1,a,i4)') 'thread :',it,' -->int_array(', & i,')=',int_array(i) end do deallocate(int_array) end do !$OMP END DO ! !$OMP END PARALLEL end program allocate_in_loop According to what I read in the OpenMP 2.5 Specification - in sections 2.8.3.3 page 75 - the usage of the allocatable array is correct since I allocate it and deallocate inside the OMP loop and it is not allocated upon entering the OMP DO loop. Gfortran compile fine with >> gfortran -fopenmp allocate_in_loop.f90 But fails on execution with: "Fortran runtime error: Attempting to allocate already allocated array." intel 9.1, pgi 6.1 and xl do fine, the output being for example... >> ./a.out thread : 0 --> int_array(1)= 1 thread : 0 --> int_array(2)= 2 thread : 0 --> int_array(3)= 3 thread : 1 --> int_array(1)= 101 thread : 1 --> int_array(2)= 102 thread : 1 --> int_array(3)= 103 thread : 2 --> int_array(1)= 201 thread : 2 --> int_array(2)= 202 thread : 2 --> int_array(3)= 203 thread : 3 --> int_array(1)= 301 thread : 3 --> int_array(2)= 302 thread : 3 --> int_array(3)= 303 Good bug squashing Benjamin -- Summary: Problem with allocatable arrays inside OpenMP do loop Product: gcc Version: 4.2.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: fortran AssignedTo: unassigned at gcc dot gnu dot org ReportedBy: benjamin dot reveille at gmail dot com GCC build triplet: i686-pc-linux-gnu GCC host triplet: i686-pc-linux-gnu GCC target triplet: i686-pc-linux-gnu http://gcc.gnu.org/bugzilla/show_bug.cgi?id=27916