使用ifort进行数组复制的程序崩溃 [英] Program crash for array copy with ifort

查看:85
本文介绍了使用ifort进行数组复制的程序崩溃的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在MacOSX Lion和ifort(IFORT)12.1.0 20111011上,该程序在Illegal instruction: 4时崩溃

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 

同一程序可用于gfortran.我没看到任何问题.有任何想法吗 ?在两个编译器中都可以展开副本并在各列上执行显式循环.

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.

如果语句在模块内部或不在模块内部,则行为相同. 我在ifort(IFORT)12.1.3 20120130上确认了相同的行为.

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.

显然,Linux和ifort 12.1.5没问题

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

但是我仍然遇到相同的错误.将ulimit -s增加到同样的难题.

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)

涉及的值可疑地接近16M数据.

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.

推荐答案

您的程序是正确的(尽管如果您不需要重新指向指针,我希望将其分配给指针).问题在于,默认情况下,ifort会将所有数组临时变量放置在堆栈上,无论它们的大小如何.似乎需要一个临时数组用于您在此处执行的复制操作.要解决ifort愚蠢的默认行为,总是在编译时使用-heap-arrays标志.即

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

-heap-arrays后面的数字是开始使用堆的阈值.对于低于此尺寸的尺寸,将使用堆栈.我在这里选择了一个很小的数字-您可以放心使用更高的数字.从理论上讲,堆栈数组的速度更快,但差异通常可以忽略不计.我希望intel可以解决此问题.其他所有编译器都有此设置的合理默认值.

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.

这篇关于使用ifort进行数组复制的程序崩溃的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆