作为我研究的一部分,我目前正在为 Fortran90 中的一个讨厌的偏微分方程编写一个大型非线性求解器。我遇到了一个问题,我认为内存损坏问题困扰着我的代码,我正在尝试追踪它;为此,我选择使用 valgrind,因为这在过去对我有用。不幸的是,我在代码执行开始时收到一条无法解释的错误消息,请参见下文:
==18257== Memcheck, a memory error detector
==18257== Copyright (C) 2002-2015, and GNU GPL'd, by Julian Seward et al.
==18257== Using Valgrind-3.11.0 and LibVEX; rerun with -h for copyright info
==18257== Command: ./JFNKsolver
==18257==
==18257== Conditional jump or move depends on uninitialised value(s)
==18257== at 0x6F7F7D: __intel_sse2_strcpy (in /home/cseinen/Documents/1_Thesis_Work/ThesisGit/Model/Source_Code/JFNKsolver)
==18257== by 0x6AA1C0: for__open_proc (in /home/cseinen/Documents/1_Thesis_Work/ThesisGit/Model/Source_Code/JFNKsolver)
==18257== by 0x67EF6C: for__open_default (in /home/cseinen/Documents/1_Thesis_Work/ThesisGit/Model/Source_Code/JFNKsolver)
==18257== by 0x69878D: for_write_seq_lis (in /home/cseinen/Documents/1_Thesis_Work/ThesisGit/Model/Source_Code/JFNKsolver)
==18257== by 0x65BA69: MAIN__ (JFNKsolver.f90:146)
==18257== by 0x402DAD: main (in /home/cseinen/Documents/1_Thesis_Work/ThesisGit/Model/Source_Code/JFNKsolver)
==18257== Uninitialised value was created by a stack allocation
==18257== at 0x6AA07D: for__open_proc (in /home/cseinen/Documents/1_Thesis_Work/ThesisGit/Model/Source_Code/JFNKsolver)
==18257==
==18257== Conditional jump or move depends on uninitialised value(s)
==18257== at 0x6F7F7D: __intel_sse2_strcpy (in /home/cseinen/Documents/1_Thesis_Work/ThesisGit/Model/Source_Code/JFNKsolver)
==18257== by 0x677DA5: for__add_to_lf_table (in /home/cseinen/Documents/1_Thesis_Work/ThesisGit/Model/Source_Code/JFNKsolver)
==18257== by 0x6ABA13: for__open_proc (in /home/cseinen/Documents/1_Thesis_Work/ThesisGit/Model/Source_Code/JFNKsolver)
==18257== by 0x67EF6C: for__open_default (in /home/cseinen/Documents/1_Thesis_Work/ThesisGit/Model/Source_Code/JFNKsolver)
==18257== by 0x69878D: for_write_seq_lis (in /home/cseinen/Documents/1_Thesis_Work/ThesisGit/Model/Source_Code/JFNKsolver)
==18257== by 0x65BA69: MAIN__ (JFNKsolver.f90:146)
==18257== by 0x402DAD: main (in /home/cseinen/Documents/1_Thesis_Work/ThesisGit/Model/Source_Code/JFNKsolver)
==18257== Uninitialised value was created by a stack allocation
==18257== at 0x6AA07D: for__open_proc (in /home/cseinen/Documents/1_Thesis_Work/ThesisGit/Model/Source_Code/JFNKsolver)
==18257==
我通过运行我的代码得到了这个错误valgrind --track-origins=yes ./JFNKsolver
。
现在我知道,通常,这些错误意味着在某处使用了一个未初始化的变量,但奇怪的是它出现在我的代码中真正发生任何事情之前,它指向by 0x65BA69: MAIN__ (JFNKsolver.f90:146)
一个测试打印语句,即print *, "Test"
在下面的代码。
program JFNKsolver
use modelparams
use initialization
use forcing
use domain_routines
use solver_routines
use var_routines
use csv_file
use validation_routines
use validsoln_routines
implicit none
real(kind = dbl_kind) :: &
time, &
norm_test
integer(kind = int_kind) :: &
nxT, nyT, &
nxN, nyN, &
nxU, nyU, &
nxV, nyV, &
nt, &
nU_pnts, &
nV_pnts, &
nT_pnts, &
nN_pnts, &
nHT_pnts, &
nHN_pnts, &
si, &
tmp_size, &
i, j, ij
integer(kind = int_kind), allocatable, dimension (:) :: &
indxUi, indxUj, &
indxVi, indxVj, &
indxTi, indxTj, &
indxNi, indxNj, &
haloTi, haloTj, &
haloNi, haloNj
real(kind = dbl_kind), allocatable, dimension (:) :: &
Au, res_NL, u_update, &
b, b_0, vpb_forc
integer(kind = int_kind), allocatable, dimension (:,:,:) :: &
ulmsk, vlmsk, &
uimsk, vimsk, &
Timsk, Nimsk, &
Tlmsk, Nlmsk
real(kind = dbl_kind), allocatable, dimension (:,:) :: &
ugrid, vgrid, &
uResgrid, vResgrid, &
uocn_u, uocn_v, &
vocn_u, vocn_v, &
uwnd_u, uwnd_v, &
vwnd_u, vwnd_v, &
h_u, h_v, h_T, &
A_T, &
P_T, P_N, &
zeta_T, zeta_N, &
eta_T, eta_N, &
Cw_u, Cw_v, &
dist_T, dist_N, &
dist_gx_T, &
dist_gy_T
print *, "Test"
请注意,我删除了注释以清理它,并且类型变量在 modelparams 模块中初始化。任何人都可以提供一些可能导致这种情况的见解吗?use
它可以通过语句链接到我正在使用的模块吗?我最初认为这是 valgrind 的问题,但现在我看到了内存损坏的影响,而且这是我看到的唯一错误,我已经开始警惕了。
注意:我认为存在内存损坏问题的原因是因为我看到求解器的行为发生了变化,只是因为存在不应该改变任何东西的代码。这是我为帮助验证代码而添加的一项功能,我对此进行了广泛的测试。