weixin_39924573
weixin_39924573
2020-12-09 06:45

realloc bug

Resetting the coulomb interaction when an LB fluid has been set up triggers a memory allocation problem. This minimal script:


setmd box_l 24 24 24
setmd time_step 1
setmd skin 0.1
inter coulomb 1.0 p3m  4.5 24 6 0.6 1e-5
lbfluid cpu agrid 1 dens 1.0 visc 1.0 tau 1.0
integrate 1
#exit  ;# if we stop here, there's no realloc error
inter coulomb 0

fails on my mac:


   malloc: *** error for object 0x7fe20a617788: pointer being realloc'd was not allocated
   Signal: Abort trap: 6 (6)
   Signal code:  (0)
   libsystem_platform.dylib  0x00007fff8e204f1a _sigtramp + 26
   ???                       0x0000000109e5ae00 0x0 + 4461014528
   libsystem_c.dylib         0x00007fff913499b3 abort + 129
   libsystem_malloc.dylib    0x00007fff9432d20f realloc + 385
   libEspressoCore.dylib     0x000000010991e7d0 _Z7lb_initv + 352
   libEspressoCore.dylib     0x00000001098f7643 _Z21dd_on_geometry_changei + 531
   libEspressoCore.dylib     0x00000001099140b3 _Z17on_coulomb_changev + 163
   libEspressoCore.dylib     0x0000000109916b6d _Z19coulomb_set_bjerrumd + 189
   Espresso                  0x000000010989663d _Z30tclcommand_inter_parse_coulombP10Tcl_InterpiPPc + 221
   Espresso                  0x0000000109897aa2 _Z16tclcommand_interPvP10Tcl_InterpiPPc + 498
   Tcl                       0x0000000109b34de1 TclInvokeStringCommand + 124
   Tcl                       0x0000000109b362b5 Tcl_ListMathFuncs + 1896
   Tcl                       0x0000000109b373e6 Tcl_EvalEx + 1801
   Tcl                       0x0000000109b36cf7 Tcl_EvalEx + 26
   Tcl                       0x0000000109b96ec9 Tcl_FSEvalFileEx + 317
   Tcl                       0x0000000109b9cabb Tcl_Main + 808
   Espresso                  0x0000000109899cd7 main + 71 
   libdyld.dylib             0x00007fff95c9c5c9 start + 1 

This happens (at least) in the last build: commit 14e0f7fc13fa2a9a154372c83c89b5952afaa062 Merge: 20d8108 e34f30a Author: Florian Weik florianweik.com Date: Tue Apr 12 14:23:56 2016 +0200


    Merge pull request #579 from dschwoerer/bd_cpu

    Make BD work without GPU

With configuration options:


#define ELECTROSTATICS
#define LB
#define LENNARD_JONES

该提问来源于开源项目:espressomd/espresso

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 复制链接分享
  • 邀请回答

7条回答

  • weixin_39740283 weixin_39740283 4月前

    Does anybody have an idea why dd_on_geometry_change calls on_box_change? As far as I understand it can't actually change the box length.

    点赞 评论 复制链接分享
  • weixin_39924573 weixin_39924573 4月前

    I guess it's not needed in this case, but is done for "safety" only. Anyway, in principle this should not harm. I think the problem could occur when switching the fluid population pointers, at lb.cc:2772 in lb_collide_stream. I'm doing some checks right now.

    M

    On Wed, Apr 13, 2016 at 10:27 AM, Florian Weik notifications.com wrote:

    Does anybody have an idea why dd_on_geometry_change calls on_box_change? As far as I understand it can't actually change the box length.

    — You are receiving this because you authored the thread. Reply to this email directly or view it on GitHub https://github.com/espressomd/espresso/issues/583#issuecomment-209300990

    University of Vienna

    点赞 评论 复制链接分享
  • weixin_39924573 weixin_39924573 4月前

    Yes, I guess the problem is there. First the complete array (including both populations) is allocated with (lb.cpp:1832)

    
    lbfluid[0]    = (double**) Utils::realloc(*lbfluid,2*lbmodel.n_veloc*
    

    sizeof(double )); lbfluid[0][0] = (double) Utils::realloc(_lbfluid,2 lblattice.halo_grid_volume_lbmodel.n_veloc*sizeof(double));

    Then the pointers are swapped (lb.cpp:2768)

    
    lbfluid[0] = lbfluid[1];
    
    lbfluid[1] = tmp;
    

    And then the realloc is called again, but now lbfluid[0] is not the original pointer anymore.

    A solution could be to allocate separately the space for lbfluid[0] and lbfluid[1]. Do you agree with this?

    On Wed, Apr 13, 2016 at 10:38 AM, Marcello Sega marcello.sega.com wrote:

    I guess it's not needed in this case, but is done for "safety" only. Anyway, in principle this should not harm. I think the problem could occur when switching the fluid population pointers, at lb.cc:2772 in lb_collide_stream. I'm doing some checks right now.

    M

    On Wed, Apr 13, 2016 at 10:27 AM, Florian Weik notifications.com wrote:

    Does anybody have an idea why dd_on_geometry_change calls on_box_change? As far as I understand it can't actually change the box length.

    — You are receiving this because you authored the thread. Reply to this email directly or view it on GitHub https://github.com/espressomd/espresso/issues/583#issuecomment-209300990

    University of Vienna

    University of Vienna

    点赞 评论 复制链接分享
  • weixin_39740283 weixin_39740283 4月前

    Yes, this seems to be the problem. Funny enough this means that resizing the fluid has always been broken an nobody noticed. I'm going to fix this.

    点赞 评论 复制链接分享
  • weixin_39924573 weixin_39924573 4月前

    I prepared a patch already... will send it in 1 minute

    点赞 评论 复制链接分享
  • weixin_39924573 weixin_39924573 4月前

    I created a pull request:

    https://github.com/espressomd/espresso/pull/585/commits/a53058fc8a8fc6156c60465d235f6079df181acd

    点赞 评论 复制链接分享
  • weixin_39924573 weixin_39924573 4月前

    fixed

    点赞 评论 复制链接分享