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

Possible bug when function used to fill an array

_xl_
Beginner
513 Views
Hi,
We recently noticed a difference of comportement between gfortran and ifort with function filling an array.
Ifort crashes with segmentation fault with big arrays whereas gfortran just work.
I updated to last ifort version :
ifort (IFORT) 12.1.0 20111011
Here is an example reproducing the problem :

program toto
implicit none
real, allocatable :: tata(:)
integer(kind=8) :: length, max
length = 2**10
max = 2**(30)
do while (length .lt. max)
print *, "length", length
allocate(tata(length))
tata = titi(length)
deallocate(tata)
print *, "length", length
length = length * 2
end do
contains
function titi(length)
integer(kind=8) :: length
real, dimension(length) :: titi
titi = 1.0
end function titi
end program toto
GFortran output :
length 1024
length 1024
length 2048
length 2048
length 4096
length 4096
length 8192
length 8192
length 16384
length 16384
length 32768
length 32768
length 65536
length 65536
length 131072
length 131072
length 262144
length 262144
length 524288
length 524288
length 1048576
length 1048576
length 2097152
length 2097152
length 4194304
length 4194304
length 8388608
length 8388608
length 16777216
length 16777216
length 33554432
length 33554432
length 67108864
length 67108864
length 134217728
length 134217728
length 268435456
length 268435456
length 536870912
length 536870912
ifort output :
length 1024 1073741824
length 1024
length 1024
length 2048
length 2048
length 4096
length 4096
length 8192
length 8192
length 16384
length 16384
length 32768
length 32768
length 65536
length 65536
length 131072
length 131072
length 262144
length 262144
length 524288
length 524288
length 1048576
length 1048576
length 2097152
zsh: segmentation fault ./a.out
The machine is a Bi quad coreIntel Xeon CPU E5410 @ 2.33GHz running debian squeeze 6.0.3 with kernel2.6.32-5-amd64
Thanks,
XL.
0 Kudos
2 Replies
Ron_Green
Moderator
513 Views
"Useful Links" at the top of this forum has common mistakes/problems such as this:

http://software.intel.com/en-us/articles/determining-root-cause-of-sigsegv-or-sigbus-errors/

ron
0 Kudos
_xl_
Beginner
513 Views
Ok, thanks,
Does that mean that in my case ifort creates a temporary array to store values inside titi function and then copy it to tata array whereas gfortran directly works into tata array ?
So is it better to use a subroutine with tata in INTENT(OUT) if we want to work directly on tata array ?
Thanks,
XL.
EDIT : OK I found the answer in the attached PDF to your link, i have to use au subroutine.
0 Kudos
Reply