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

sending part of array to subroutine in fortran -segmentation error only for ifort compiler

sugumar_l_
Beginner
1,529 Views

I have written the Test code

      program test
      integer n,i
      parameter (n=10000)
      REAL a(n,n),b(n),c(n)
      a(1:n,1:n) = 0.0
      read(*,*)i
      call partarray(i,a(1:i,1:i))
      end

      subroutine partarray(I,a)
      integer i
      real a(i,i)
      write(*,*)"i",i
      write(*,*)"Reached the end of part array subroutine"
      return
      end

which works completely fine in gfortran. But ifort compiler throws segmentation error for i value in the range 1445 to 9999.

Any help in this regard will be greatly appreciated

0 Kudos
3 Replies
TimP
Honored Contributor III
1,529 Views

Your program would allocate storage for the array section, and might work better with -heap-arrays or with an increase in stack limit.  gfortran probably uses heap automatically, seeing that the array is large.

0 Kudos
sugumar_l_
Beginner
1,529 Views

Thanks for your relpy TimP.

The same program works for the particular value i=10000 but not say 9999(1444< i <1000). what can u comment about this. will the usage of any compiler flag help?

0 Kudos
jimdempseyatthecove
Honored Contributor III
1,529 Views

The way your program is coded, partarray requires a to be a contiguous block of memory of shape a(i,i). The generated code therefor must produce a temporary from the outer scoped array a(n,n). You have 3 ways to fix your code

a) increase stack (should you have large temps allocate from stack)
b) use heap arrays
c) declare an interface to partarray and in partarray use "real a(:,:)" (with interface reflecting this change)

Jim Dempsey

0 Kudos
Reply