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

标签 fortran valgrind intel-fortran memory-corruption memcheck

作为我研究的一部分,我目前正在为 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 的问题,但现在我看到了内存损坏的影响,而且这是我看到的唯一错误,我开始警惕它。

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

最佳答案

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 返回与上面看到的基本相同的输出。

这是史蒂夫的完整回复。

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.

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

关于Fortran90 valgrind 输出帮助。代码执行开始时发生无法解释的错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43104421/

相关文章:

python - MPI,fortran master和Pythonworker之间的互通?

operator-overloading - 在 Fortran 重载赋值中检查自赋值

vim - 为 pFUnit 测试框架扩展 vim Fortran 语法文件

c - C 中无法释放内存

valgrind - helgrind 报告一场没有冲突的比赛 - 这意味着什么?

linker - 堡垒: error #10037: could not find 'link'

compiler-errors - gfortran : compile source codes from hierarchically dependent subroutine files

c - MIPS 上的 Valgrind 报告没有堆使用

io - 有没有办法使用名单 I/O 功能来读取具有可分配组件的派生类型?

c - Fortran 调用 C : How do I get an efficient vectorised function