Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/fortran/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Arrays Fortran数组分配溢出_Arrays_Fortran_Stack_Overflow_Allocation - Fatal编程技术网

Arrays Fortran数组分配溢出

Arrays Fortran数组分配溢出,arrays,fortran,stack,overflow,allocation,Arrays,Fortran,Stack,Overflow,Allocation,我是Fortran新手,在模块内部的子例程中,我试图声明以下变量: real(kind = 8), dimension(dim*nnds, dim*nnds) :: Kgel 我得到以下信息: Unhandled exception at 0x009F4029 in Solver.exe: 0xC00000FD: Stack overflow (parameters: 0x00000000, 0x00602000). dim和NND是来自另一个模块的变量,我知道它们被正确地传递为: inte

我是Fortran新手,在模块内部的子例程中,我试图声明以下变量:

real(kind = 8), dimension(dim*nnds, dim*nnds) :: Kgel
我得到以下信息:

Unhandled exception at 0x009F4029 in Solver.exe: 0xC00000FD: Stack overflow (parameters: 0x00000000, 0x00602000).
dim和NND是来自另一个模块的变量,我知道它们被正确地传递为:

integer(kind = 8) :: nnds, dim
dim = 2
nnds = 937
如果我声明变量如下:

real(kind = 8), dimension(2*937, 2*937) :: Kgel
或者甚至像:

real(kind = 8), dimension(:, :), allocatable :: Kgel

allocate(Kgel(dim*nnds, dim*nnds))
它是有效的,那么为什么我不能像这样声明“Kgel”:

real(kind = 8), dimension(dim*nnds, dim*nnds) :: Kgel
非常感谢您抽出时间

更新

我的代码是这样的:

program MainTest

    use FirstModule
    use SecondModule

    call FirstSubRoutine
    call SecondSubRoutine

end program
real(kind = 8), dimension(:, :), allocatable :: Kgel
!...
allocate(Kgel(dim*nnds, dim*nnds))

这个小测试代码将复制我的问题

更新

通过更改“堆栈保留大小”,现在似乎可以正常工作:


要解决此问题,需要如下声明变量:

program MainTest

    use FirstModule
    use SecondModule

    call FirstSubRoutine
    call SecondSubRoutine

end program
real(kind = 8), dimension(:, :), allocatable :: Kgel
!...
allocate(Kgel(dim*nnds, dim*nnds))
或者,由于我在Visual Studio上使用“英特尔Fortran编译器”,因此在“项目属性”>“配置属性”>“Fortran”>“优化集”堆数组的0到n中:


“堆数组:在堆上而不是在堆栈上分配最小大小为n(以千字节为单位)的临时数组。使用0始终在堆上分配它们。保留为空不激活。”

请尝试创建一个完整(但最小)的示例,让我们看一下。如果没有这些,我们将不得不猜测许多方面。如何声明
dim
nnds
?您显示的代码是在主程序中还是在子例程中?这里没有足够的信息供任何人帮助。如果您找到一个选项,特别是编译器,将自动数组放在堆上而不是堆栈上,您的问题会消失吗?还有其他几个问题与这个概念有关,但是搜索编译器文档应该很容易,而不是那些问题。@carlos,这意味着当您将这两个参数传递到例程中并尝试创建一个称为自动数组的数组时,该数组被放在进程堆栈上。所需的内存量大约为27MB。如果堆栈没有足够的空间,则进程将终止。使用
ALLOCATABLE
属性并执行自己的内存分配将数组放入堆中。用户进程的堆通常比堆栈多得多。请将错误消息复制为文本,而不仅仅是在屏幕截图中。在并非绝对必要的地方避免截图。错误消息必须可搜索,以便有相同问题的人可以找到您的问题。这真的很重要。上传图片时,它总是在说明中告诉您这一点,请务必阅读说明。根据说明,我希望设置“堆数组”也能正常工作。只是不要留下空白。是否?@VladimirF n是要在堆上分配的数组的最小大小(以KB为单位)。如果设置为0,则所有数组都将在那里分配,而不是在堆栈上分配。尽管在我的例子中,无论我使用什么,只要代码不是空的(这是默认值),代码都会运行良好。