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

Stange things using derived type allocatable

Andrew_Smith
Valued Contributor I
337 Views

The following code gives output:

1.000000
2.000000
3.000000
4.000000
-4.3160208E+08
-4.3160208E+08
-4.3160208E+08
-4.3160208E+08
-4.3160208E+08
-4.3160208E+08
-4.3160208E+08
-4.3160208E+08
-4.3160208E+08
-4.3160208E+08
-4.3160208E+08
-4.3160208E+08
-4.3160208E+08
-4.3160208E+08
-4.3160208E+08
-4.3160208E+08

module

subs

implicit none

type defType

real, allocatable :: a(:), b(:,:)

end type

contains

subroutine

sub1(myElem, i, n)

type(defType), intent(inout) :: myElem

integer, intent(in) :: i, n

integer status

allocate(myElem%a(n), myElem%b(n,n), stat = status)

if (status == 0) then

myElem%a =

float(i)

else

continue

end if

end subroutine

end module

program

BugTest

use subs

implicit none

integer , parameter :: sz1 = 20, sz2 = 10000

type(defType) :: myArray(sz1)

integer i

do i = 1, sz1

call sub1(myArray(i),i,sz2)

end do

open(10, file = 'Vals.txt')

do i = 1, sz1

write(10, *) myArray(i)%a(1)

end do

close(10)

end

program

Using VS2005 SP1, IVF 10.1.024, Vista64 SP1

Run in debug mode with deafult project settings.

if I reduce sz2 to 1000 I get sequential number output as I expect.

If I use OpenMP for the first loop using 4 cores I get:

1.000000
-4.3160208E+08
-4.3160208E+08
-4.3160208E+08
-4.3160208E+08
6.000000
-4.3160208E+08
-4.3160208E+08
-4.3160208E+08
-4.3160208E+08
11.00000
-4.3160208E+08
-4.3160208E+08
-4.3160208E+08
-4.3160208E+08
16.00000
-4.3160208E+08
-4.3160208E+08
-4.3160208E+08
-4.3160208E+08

Regards Andrew

0 Kudos
2 Replies
Steven_L_Intel1
Employee
337 Views
You're running out of virtual memory after the first four calls to sub by which time you have allocated 1,246,822,400 bytes of data. While the subsequent calls fail, the compiler is incorrectly setting the descriptor for the allocatable components assuming the allocate will succeed, and you get garbage. That bug is already being fixed.
0 Kudos
Steven_L_Intel1
Employee
337 Views
Oh, you are undoubtedly building a 32-bit application. You need to add an x64 configuration in order to build for 64-bits. This is described in the on-disk documentation on adding a target configuration.
0 Kudos
Reply