私はFortranが初めてで、モジュール内のサブルーチン内で次の変数を宣言しようとしています:
real(kind = 8), dimension(dim*nnds, dim*nnds) :: Kgel
そして、私は次のようになります:
Unhandled exception at 0x009F4029 in Solver.exe: 0xC00000FD: Stack overflow (parameters: 0x00000000, 0x00602000).
dim と nnds は別のモジュールからの変数であり、次のように正しく渡されていることがわかっています。
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
.
module FirstModule
integer(kind = 8) :: nnds, dim
contains
subroutine FirstSubRoutine()
!does stuff and eventually
dim = 2
nnds = 937
end subroutine
end module
.
module SecondModule
use FirstModule
contains
subroutine SecondSubRoutine()
real(kind = 8), dimension(nnds*dim, nnds*dim) :: Kgel
!print *, dim -> dim = 2
!print *, nnds -> nnds = 937
!pause
!but this works:
!real(kind = 8), dimension(:, :), allocatable :: Kgel
!allocate(Kgel(dim*nnds, dim*nnds))
end subroutine
end module
この小さなテスト コードで問題が再現されます。
アップデート
「スタック予約サイズ」を変更すると、正常に動作するようになりました。
