Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.
28445 Discussions

Segmentation fault for reshape of large array

XiaOaiX
Beginner
369 Views
program arrayreshape

  implicit none
  integer, parameter:: N=1000
  integer :: i,j
  real(8), allocatable, dimension(:,:):: a, b
  allocate(a(N,N))
  allocate(b(N,N))
   a=reshape([(1._16,i=1,N**2)],[N,N])
   b=reshape([(100._16,i=1,N**2)],[N,N])
end program

 

Using ifort (IFORT) 2021.6.0 20220226, it can be built without error, but there will be segmentation fault:

forrtl: severe (174): SIGSEGV, segmentation fault occurred
Image PC Routine Line Source
reshapeLargeMatri 0000000000404C7A Unknown Unknown Unknown
libc.so.6 00007F71C1EE48E0 Unknown Unknown Unknown
reshapeLargeMatri 000000000040387F Unknown Unknown Unknown
reshapeLargeMatri 0000000000403842 Unknown Unknown Unknown
libc.so.6 00007F71C1ECF290 Unknown Unknown Unknown
libc.so.6 00007F71C1ECF34A __libc_start_main Unknown Unknown
reshapeLargeMatri 0000000000403725 Unknown Unknown Unknown

 

Is this a bug? Changing to N=500, it runs without problem.

0 Kudos
2 Replies
jimdempseyatthecove
Honored Contributor III
365 Views

You are likely having stack overflow. Possible solutions:

a) Increase stack size

b) use option heap arrays

c) replace reshape with DO loop

 

Jim Dempsey

0 Kudos
andrew_4619
Honored Contributor II
355 Views

What Jim Said, additionally did you really intend kind=16 for for 1D arrays assigned to a kind=8 array? You can guess all manner of temp arrays need to be created on the stack for these lines.

0 Kudos
Reply