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

stack overflow in write-stmt with 2d-array

Michael_R_2
Beginner
285 Views

Dear developers,

I observed a bug under Win7(64-bit) with  Intel-12.1.2  Fortran-compiler :

In a write-stmt  the Intel-compiler uses the stack, where it is not necessary, and then (certainly) aborts with a stack overflow, if the stack is too small.

Here are example stmts:

 

     real, allocatable :: realarray(:,:)

     ndim=500000

     allocate(  realarray(ndim,3) )

     realarray = 0.0 

     open(100, form='unformatted')

    write(100)   realarray( :, 2 )                      ! --> this works

    write(100)   realarray( :ndim, 2 )              ! --> this should be exacly the same, but results in a stack overflow

    write(100)   realarray( :ndim-100, 2 )       ! --> results also in a stack overflow

I remember darkly, that this kind of bug  already appeared with the good old COMPAQ-Ftn-compiler.

Note, that this bug with the 2d-array does not occur for a 1d-array.

   Greetings     Michael R.

 

 

 

 

0 Kudos
3 Replies
mecej4
Honored Contributor III
285 Views

The problem persists with the 15.0.1.148 32- and 64-bit compilers on Windows 8.1. With the former, the traceback fails to give the line numbers, as well.

0 Kudos
Simon_Geard
New Contributor I
285 Views

If you want a work around you could try setting /heap-arrays (Fortran>Optimization) .

0 Kudos
Steven_L_Intel1
Employee
285 Views

It's not a bug, but perhaps a missed opportunity for optimization. In the second and third cases the compiler doesn't recognize that it can just use ndim or ndim-100 as the upper bound for an array slice and then use the general slice code it does for the first case - instead it creates a temporary that overflows the stack. I will suggest to the developers that they try to optimize this case as well, but it may be a while before they get to it. /heap-arrays is certainly a good workaround.

0 Kudos
Reply