Fortran90 valgrind 输出帮助。代码执行开始时发生无法解释的错误

Fortran90 valgrind output help. Unexplained error happening at the beginning of code execution

作为我研究的一部分,我目前正在为 Fort运行90 中的一个讨厌的偏微分方程编写一个大型非线性求解器。我 运行 遇到了一个问题,我认为内存损坏问题正在困扰我的代码,我正试图追踪它;为此,我选择使用 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 结合后得到了这个错误。

现在我知道,通常情况下,这些错误意味着某处使用了未初始化的变量,但 st运行ge 的事情是它出现在我的代码中真正发生任何事情之前,它通过 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 的问题,但现在我看到了内存损坏的影响,而且这是我看到的唯一错误,我开始警惕它。

注意:我认为存在内存损坏问题的原因是因为我看到我的求解器的行为发生了变化,只是因为存在不应该改变任何东西的代码。这是我为帮助验证代码而添加的一项功能,我已经 运行 对此进行了广泛的测试。

Steve Lionel 在 Intel Developer Zone 回答了基本相同的问题。

这里是使用的示例程序:

Program Main
  implicit none
  write(*,*) "123"
End Program

编译:

$ ifort -g main.f90

然后调用:

$ valgrind -v --track-origins=yes --leak-check=full ./a.out

Valgrind returns 与上面看到的输出基本相同。

这是史蒂夫的完整回复。

Yes, you are correct. You have implicitly opened a file, which requires allocated memory. The file is not closed, so that memory remains allocated at the end of the program. Even if the file is closed (and there is an implicit close when the program exits, not all of the bookkeeping memory may be deallocated. valgrind doesn't understand Fortran.

You may not be able to get rid of all of the valgrind complaints.

所以,如果我是你,我会忽略这些警告并查看你可能拥有的任何其他警告。