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

CVF fails with this program

arjen_markus1
Beginner
1,167 Views
Hello,
the following program produces a runtime error (apparently in the first line
- stack overflow) with CVF 6.6C on Windows XP:
program aha
implicit none
!
! No problem with allocatable arrays
! With pointers we do have a problem
!
integer, dimension(:,:), pointer :: a, b
integer :: ierr, ierr2
write(*,*) 'Started ...'
allocate(a(1000,1000),stat=ierr)
allocate(b(2000,1000),stat=ierr2)
write(*,*) ierr, ierr2
a = 1
!
! Remove this statement and all will work
!
b(1:1000,1:1000) = a(1:1000,1:1000)
write(*,*) a(3,3), b(3,3)
end program
Removing the assignment b(...) = a(...) causes the program to function
correctly.
If you change the pointer attribute to "allocatable", it also works
correctly.
However, as this is an excerpt of programs where allocatable
is not an option (typically thingsallocated in subroutines), I would
like to know how we can solve this problem.
Kind regards,
Arjen Markus
0 Kudos
8 Replies
Steven_L_Intel1
Employee
1,167 Views
I suggest you write:

b(1:1000,:) = a

instead. It may help. Or add /link /stack:10000000 to the command switches (or set the linker stack reserve setting to 10000000).
0 Kudos
arjen_markus1
Beginner
1,167 Views
The first option (change the line to b(1:1000,:) = a) did not work.
Changing the stack reserve did solve it.

Thanks,

Arjen
0 Kudos
Steven_L_Intel1
Employee
1,167 Views
You should also keep in mind memory layout of arrays and try to arrange things so that you're doing contiguous moves. Your assignment skips blocks of 1000 elements so the compiler creates a temporary copy. If you reversed the order of the indexes, then the assignment would be contiguous.
0 Kudos
arjen_markus1
Beginner
1,167 Views
Hm, you are right - that could be the reason for this failure ...
However, when I tried with a one-dimensional version I had the same
problem:


program aha
implicit none
!
! No problem with allocatable arrays
! With pointers we do have a problem
!
integer, dimension(:), pointer :: a, b
integer :: ierr, ierr2

write(*,*) 'Started ...'
allocate(a(1000000),stat=ierr)
allocate(b(2000000),stat=ierr2)
write(*,*) ierr, ierr2
a = 1
b(1:1000000) = a(1:1000000)

write(*,*) a(33), b(33)
end program


exhibits the same problem

Regards,

Arjen
0 Kudos
Steven_L_Intel1
Employee
1,167 Views
Don't use array section notation unless you need to (write A and not A(1:10000)). But I can see in this case it doesn't matter. Hmm.
0 Kudos
jimdempseyatthecove
Honored Contributor III
1,167 Views

Increasing the stack is not what I would call a practical solution as you realy do (may) not want to create a temporary array for a simple assignment.

What happens if you replace

b(1:1000,1:1000) = a(1:1000,1:1000)


with

FORALL(I=1:1000) b(1:1000,I) = a(1:1000,I)

The compiler/runtime used to have a diagnosticwarning when array temporaries were created/used. This option appears to have been removed in the latest release. The option was used to identify potential performance problem areas. Loss of this option must have been deemed as progress....

Jim Dempsey

0 Kudos
Steven_L_Intel1
Employee
1,167 Views
The warning you're referring to is only for arguments in calls - it was never supported for temps created in statements.

I agree that raising the stack is not an ideal fix. In the Intel compiler, work is in progress to optionally allocate these temps on the heap. This example points out where the compiler's detection of where temps can be avoided could still be improved.
0 Kudos
arjen_markus1
Beginner
1,167 Views
Just a small update:
I downloaded Intel Visual Fortran 9.1 for Windows yesterday for evaluation purposes and tried it on this very same program. The crash was completely
similar.

Interestingly enough, it happens at _start up_ - not when the statement is to
executed.

Regards,

Arjen

0 Kudos
Reply