| 看到Fortran内置的一个数组操作函数“eoshift”,功能是将数组进行挪位。 就想测试一下它和普通方法的速度差异,代码如下:
 
 [Fortran] syntaxhighlighter_viewsource syntaxhighlighter_copycode 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为什么会使用栈?
 希望有前辈能够指导一下,感激不尽!
 
 
 |