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

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

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
      call partarray(i,a(1:i,1:i))

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

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

4 posts / 0 new
Last post
For more complete information about compiler optimizations, see our Optimization Notice.

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.

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?

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

Leave a Comment

Please sign in to add a comment. Not a member? Join today