愤怒的三炮 发表于 2021-2-5 21:23:24

eoshift函数gfortran运行正常,intel Fortran运行却出错

看到Fortran内置的一个数组操作函数“eoshift”,功能是将数组进行挪位。
就想测试一下它和普通方法的速度差异,代码如下:
program eoshift_test
    implicit none
    integer:: i
    integer,dimension(:,:,:),allocatable:: a
    integer,dimension(:,:,:),allocatable:: temp !临时数组
    integer:: grid=1000,dim1=30 ! 数组大小
    real:: time_start, time_end ! 计时

    allocate(a(dim1,grid,grid))
    allocate(temp(dim1,grid,grid))

    a=0
    temp=0
    !===== 用 eoshift函数 ==================
    call cpu_time(time_start)
      a=eoshift(a,shift=1,boundary=0,dim=1)
    call cpu_time(time_end)
    write(*,*) 'function eoshift:'
    write(*,*) time_end-time_start,'seconds elapsed'

    !====== 用常规方法 =======================
    call cpu_time(time_start)
      do i =1, dim1-1
            temp(i,:,:)=a(i+1,:,:)
      end do
      a=temp
      a(dim1,:,:)=0
    call cpu_time(time_end)
    write(*,*) 'normal method:'
    write(*,*) time_end-time_start,'seconds elapsed'
end

用gfortran编译运行没有问题;
但是用Intel Fortran编译通过,运行时却报错“StackOverflow”;
在Linux下也是同样报错;

既然是栈溢出的问题,于是我将数组大小调整得很小,果然不报错了,但问题是:
1. 调用内置函数eoshift为什么gfortran没有StackOverflow,而ifort却StackOverflow了?
2. 我只知道a是我分配到内存里的,而内置函数eoshift为什么会使用栈?
希望有前辈能够指导一下,感激不尽!

fcode 发表于 2021-2-10 12:26:59

建议不要用intrinsic的函数处理数据量较大的数组。容易堆栈溢出,不同编译器处理方式不同。

愤怒的三炮 发表于 2021-2-14 15:56:33

好的,谢谢雪球,祝新春愉快!{:2_31:}
页: [1]
查看完整版本: eoshift函数gfortran运行正常,intel Fortran运行却出错