Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.
29592 ディスカッション

MAXVAL Stack overflow problem

Amalia_B_
ビギナー
1,070件の閲覧回数

I have a large 3-dimensional array and I'm trying to do an element-by-element maximum on the first 2 dimensions using the MAXVAL function.  When I do, I get a stack overflow error.  Is there a size limit to the MAXVAL intrinsic function?  The code is abbreviated below with constants in the array declarations and allocations instead of variables just to show the size:

program main

real, allocatable :: arr2(:,:), arr3(:,:,:)

allocate( arr3( 0:1000, 1:440, 1:6 ), source = 0.0 )

allocate( arr2( 0:1000, 1:440 ), source = 0.0 )

...! assign values to arr3

!---This gives me the stack overflow error---

arr2 = maxval( arr3,dim=3)

!------------

!-----This code works of course when broken out----

do concurrent( i = 0:1000, j = 1:440 )
   arr2(i,j) = max( arr3(i,j,1), arr3(i,j,2), arr3(i,j,3), &
                    arr3(i,j,4), arr3(i,j,5), arr3(i,j,6) )
end do

!-----------------------

But I would think is much less efficient.  Is this a compiler bug?

Amalia

0 件の賞賛
2 返答(返信)
Steven_L_Intel1
従業員
1,070件の閲覧回数

The problem is that the compiler is constructing a temporary value for the result of maxval and it puts this on the stack by default. I suggest that you add the /heap-arrays option (Fortran > Optimization > Heap Arrays > 0) to have it used the heap for these temps.

John_Campbell
新規コントリビューター II
1,070件の閲覧回数

Amalia,

You may find the problem disappear if you restructure arr3 to: allocate( arr3( 1:6, 0:1000, 1:440 ), source = 0.0 ). This would certainly improve the memory access performance.

John

返信