Program crash for array copy with ifort
Asked Answered
M

2

6

This program crashes with Illegal instruction: 4 on MacOSX Lion and ifort (IFORT) 12.1.0 20111011

program foo
      real, pointer :: a(:,:), b(:,:)
      allocate(a(5400, 5400))
      allocate(b(5400, 3600))
      a=1.0
      b(:, 1:3600) = a(:, 1:3600)

      print *, a
      print *, b

      deallocate(a)
      deallocate(b)

end program 

The same program works with gfortran. I don't see any problem. Any ideas ? Unrolling the copy and performing the explicit loop over the columns works in both compilers.

Note that with allocatable instead of pointer I have no problems.

The behavior is the same if the statement is either inside a module or not. I confirm the same behavior on ifort (IFORT) 12.1.3 20120130.

Apparently, no problem occurs with Linux and ifort 12.1.5

I tried to increase the stack size with the following linking options

ifort -Wl,-stack_size,0x40000000,-stack_addr,0xf0000000 test.f90

but I still get the same error. Increasing ulimit -s to hard same problem.

Edit 2: I did some more debugging and apparently the problem happens when the array splicing operation

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

involves a value suspiciously close to 16 M of data.

I am comparing the opcodes produced, but if there is a way to see an intermediate code form that is more communicative, I'd gladly appreciate it.

Maury answered 28/8, 2012 at 21:7 Comment(3)
I also get "illegal instruction" with ifort 12.1.1.246 on Mac Snow Leopard. I suggest reporting on the Intel Fortran Forum or submitting a bug report. Maybe it is fixed in 12.1.5?Bevus
And I get it with ifort 12.0.3 on Mac Snow Leopard. Perhaps this bug has been there for a bit...Slipsheet
Apparently, the problem exists on (some) linux boxes as well: the code segfaults on CentOS 5.5 and ifort 12.1.Contredanse
S
7

Your program is correct (though I would prefer allocatable to pointer if you do not need to be able to repoint it). The problem is that ifort by default places all array temporaries on the stack, no matter how large they are. And it seems to need an array temporary for the copy operation you are doing here. To work around ifort's stupid default behavior, always use the -heap-arrays flag when compiling. I.e.

ifort -o test test.f90 -heap-arrays 1600

The number behind -heap-arrays is the threshold where it should begin using the heap. For sizes below this, the stack is used. I chose a pretty low number here - you can probably safely use higher ones. In theory stack arrays are faster, but the difference is usually totally negligible. I wish intel would fix this behavior. Every other compiler has sensible defaults for this setting.

Sherlene answered 29/10, 2012 at 1:39 Comment(0)
L
1

Use "allocatable" instead of "pointer".

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

Assigning a floating point number to a pointer looks dubious to me.

Latvia answered 28/10, 2012 at 23:50 Comment(1)
There is nothing wrong with assigning a number to an allocated pointer in fortran. Fotran pointers are not like C pointers, and aside from the => operator and the associated builtin behave mostly like allocatable arrays.Sherlene

© 2022 - 2024 — McMap. All rights reserved.