Program crash for array copy with ifort

后端 未结 2 1137
-上瘾入骨i
-上瘾入骨i 2021-01-18 09:45

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

program foo
      real, pointer :: a(:,:), b(:         


        
相关标签:
2条回答
  • 2021-01-18 10:17

    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.

    0 讨论(0)
  • 2021-01-18 10:20

    Use "allocatable" instead of "pointer".

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

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

    0 讨论(0)
提交回复
热议问题