Dear List,
I'm working on generalizing the fix_bond_swap to work for the mSRP polymer model. This is horribly tricky, and my code keeps crashing. Hence I started to valgrind to check for memory problems. I get some errors that persist even if I remove most of my code, keeping only the skeleton code to request and build a full neighbor list.
Using the in.srp example and LAMMPS dated 31/3 running on a single core compiled with gcc -O0 -ggdb, valgrind does not report any memory issues except a few leaks. To the source code, I have added the dummy testtest fix (source below). The dummy fix requests a full pair list, and and does nothing except call neighbor->build_one(fulllist,1) in postintegrate.
When I add "fix test all testtest 50" to the in.srp script instantiate the dummy fix. I get the valgrind warnings below, ending with a segmentation fault.
Now if I instead do a "run 0" before instantiating the dummy fix, then it runs without any errors.
This suggests to me that there is some subtle bug at play somewhere in the neighbor code that is triggered by this combination of force field and neighbor list requests.
==22394== Memcheck, a memory error detector
==22394== Copyright (C) 2002-2015, and GNU GPL'd, by Julian Seward et al.
==22394== Using Valgrind-3.11.0 and LibVEX; rerun with -h for copyright info
==22394== Command: lmp_master_gdb -in in.srp
==22394==
LAMMPS (31 Mar 2017)
Reading data file ...
orthogonal box = (0 0 0) to (10 10 10)
1 by 1 by 1 MPI processor grid
reading atoms ...
3000 atoms
reading velocities ...
3000 velocities
scanning bonds ...
1 = max bonds/atom
reading bonds ...
2700 bonds
Finding 1-2 1-3 1-4 neighbors ...
special bond factors lj: 1 1 1
special bond factors coul: 1 1 1
2 = max # of 1-2 neighbors
2 = max # of special neighbors
Using type 2 for bond particles
Thermo normalization turned off by pair srp (../pair_srp.cpp:498)
!!!!!!!!!!!!!!!! INIT_LIST WAS CALLED!!!!!!!!!!!!!!!!!!!!!!Neighbor list info ...
update every 10 steps, delay 10 steps, check yes
max neighbors/atom: 2000, page size: 100000
master list distance cutoff = 3
ghost atom cutoff = 3.6
binsize = 1.5, bins = 7 7 7
4 neighbor lists, perpetual/occasional/extra = 3 1 0
(1) pair dpd, perpetual, skip from (4)
attributes: half, newton on
pair build: skip
stencil: none
bin: none
(2) pair srp, perpetual, skip from (4)
attributes: half, newton on
pair build: skip
stencil: none
bin: none
(3) fix testtest, occasional
attributes: full, newton on
pair build: full/bin
stencil: full/bin/3d
bin: standard
(4) neighbor class addition, perpetual
attributes: half, newton on
pair build: half/bin/newton
stencil: half/bin/3d/newton
bin: standard
Setting up Verlet run ...
Unit style : lj
Current step : 0
Time step : 0.01
Removed/inserted 0/2700 bond particles. (../fix_srp.cpp:249)
Per MPI rank memory allocation (min/avg/max) = 22.76 | 22.76 | 22.76 Mbytes
Step Temp PotEng v_nPotEng Press Atoms v_natoms Lx Ly Lz
0 0.98262092 31772.336 10.590779 60.690437 5700 3000 10 10 10
==22394== Invalid write of size 4
==22394== at 0x70C236: LAMMPS_NS::NPairFullBin::build(LAMMPS_NS::NeighList*) (npair_full_bin.cpp:115)
==22394== by 0x74A03E: LAMMPS_NS::Neighbor::build_one(LAMMPS_NS::NeighList*, int) (neighbor.cpp:2194)
==22394== by 0x85CBCB: LAMMPS_NS::FixTest::post_integrate() (fix_test.cpp:103)
==22394== by 0xAEA14F: LAMMPS_NS::Modify::post_integrate() (modify.cpp:378)
==22394== by 0xBBAC4F: LAMMPS_NS::Verlet::run(int) (verlet.cpp:248)
==22394== by 0x5FC958: LAMMPS_NS::Run::command(int, char**) (run.cpp:183)
==22394== by 0xB05444: void LAMMPS_NS::Input::command_creator<LAMMPS_NS::Run>(LAMMPS_NS::LAMMPS*, int, char**) (input.cpp:861)
==22394== by 0xAFF504: LAMMPS_NS::Input::execute_command() (input.cpp:844)
==22394== by 0xAFCB7D: LAMMPS_NS::Input::file() (input.cpp:244)
==22394== by 0xA3E1DF: main (main.cpp:44)
==22394== Address 0xea55ff0 is 0 bytes after a block of size 12,000 alloc'd
==22394== at 0x4C2DB8F: malloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==22394== by 0x62B4A8: LAMMPS_NS::Memory::smalloc(long, char const*) (memory.cpp:58)
==22394== by 0x52B9D1: int* LAMMPS_NS::Memory::create<int>(int*&, int, char const*) (memory.h:61)
==22394== by 0x760092: LAMMPS_NS::NeighList::grow(int, int) (neigh_list.cpp:216)
==22394== by 0x744FB8: LAMMPS_NS::Neighbor::init_pair() (neighbor.cpp:832)
==22394== by 0x7412D9: LAMMPS_NS::Neighbor::init() (neighbor.cpp:483)
==22394== by 0xB42B34: LAMMPS_NS::LAMMPS::init() (lammps.cpp:718)
==22394== by 0x5FC895: LAMMPS_NS::Run::command(int, char**) (run.cpp:177)
==22394== by 0xB05444: void LAMMPS_NS::Input::command_creator<LAMMPS_NS::Run>(LAMMPS_NS::LAMMPS*, int, char**) (input.cpp:861)
==22394== by 0xAFF504: LAMMPS_NS::Input::execute_command() (input.cpp:844)
==22394== by 0xAFCB7D: LAMMPS_NS::Input::file() (input.cpp:244)
==22394== by 0xA3E1DF: main (main.cpp:44)
==22394==
==22394== Invalid write of size 8
==22394== at 0x70C253: LAMMPS_NS::NPairFullBin::build(LAMMPS_NS::NeighList*) (npair_full_bin.cpp:116)
==22394== by 0x74A03E: LAMMPS_NS::Neighbor::build_one(LAMMPS_NS::NeighList*, int) (neighbor.cpp:2194)
==22394== by 0x85CBCB: LAMMPS_NS::FixTest::post_integrate() (fix_test.cpp:103)
==22394== by 0xAEA14F: LAMMPS_NS::Modify::post_integrate() (modify.cpp:378)
==22394== by 0xBBAC4F: LAMMPS_NS::Verlet::run(int) (verlet.cpp:248)
==22394== by 0x5FC958: LAMMPS_NS::Run::command(int, char**) (run.cpp:183)
==22394== by 0xB05444: void LAMMPS_NS::Input::command_creator<LAMMPS_NS::Run>(LAMMPS_NS::LAMMPS*, int, char**) (input.cpp:861)
==22394== by 0xAFF504: LAMMPS_NS::Input::execute_command() (input.cpp:844)
==22394== by 0xAFCB7D: LAMMPS_NS::Input::file() (input.cpp:244)
==22394== by 0xA3E1DF: main (main.cpp:44)
==22394== Address 0xf3bbda0 is 0 bytes after a block of size 24,000 alloc'd
==22394== at 0x4C2DB8F: malloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==22394== by 0x62B4A8: LAMMPS_NS::Memory::smalloc(long, char const*) (memory.cpp:58)
==22394== by 0x7600ED: LAMMPS_NS::NeighList::grow(int, int) (neigh_list.cpp:218)
==22394== by 0x744FB8: LAMMPS_NS::Neighbor::init_pair() (neighbor.cpp:832)
==22394== by 0x7412D9: LAMMPS_NS::Neighbor::init() (neighbor.cpp:483)
==22394== by 0xB42B34: LAMMPS_NS::LAMMPS::init() (lammps.cpp:718)
==22394== by 0x5FC895: LAMMPS_NS::Run::command(int, char**) (run.cpp:177)
==22394== by 0xB05444: void LAMMPS_NS::Input::command_creator<LAMMPS_NS::Run>(LAMMPS_NS::LAMMPS*, int, char**) (input.cpp:861)
==22394== by 0xAFF504: LAMMPS_NS::Input::execute_command() (input.cpp:844)
==22394== by 0xAFCB7D: LAMMPS_NS::Input::file() (input.cpp:244)
==22394== by 0xA3E1DF: main (main.cpp:44)
==22394==
:
in fact valgrind dies with a segmentation fault at the end of the output.
my fix is:
#include <math.h>
#include <stdlib.h>
#include <string.h>
#include "fix_test.h"
#include "atom.h"
#include "force.h"
#include "pair.h"
#include "bond.h"
#include "angle.h"
#include "neighbor.h"
#include "neigh_list.h"
#include "neigh_request.h"
#include "group.h"
#include "comm.h"
#include "domain.h"
#include "modify.h"
#include "compute.h"
#include "random_mars.h"
#include "citeme.h"
#include "memory.h"
#include "error.h"
#include "pair_hybrid.h"
#include "update.h"
using namespace LAMMPS_NS;
using namespace FixConst;
/* ---------------------------------------------------------------------- */
FixTest::FixTest(LAMMPS *lmp, int narg, char **arg) :
Fix(lmp, narg, arg), listfull(NULL)
{
if (narg <4) error->all(FLERR,"Illegal fix test command");
nevery = force->inumeric(FLERR,arg[3]);
if (nevery <= 0) error->all(FLERR,"Illegal fix bond/swap command");
force_reneighbor = 1;
next_reneighbor = -1;
global_freq = 1;
extvector = 0;
}
/* ---------------------------------------------------------------------- */
FixTest::~FixTest()
{
}
/* ---------------------------------------------------------------------- */
int FixTest::setmask()
{
int mask = 0;
mask |= POST_INTEGRATE;
return mask;
}
/* ---------------------------------------------------------------------- */
void FixTest::init()
{
// Need both full neighbor list.
int irequest_full = neighbor->request(this,instance_me);
neighbor->requests[irequest_full]->pair = 0;
neighbor->requests[irequest_full]->fix = 1;
neighbor->requests[irequest_full]->half = 0;
neighbor->requests[irequest_full]->full = 1;
neighbor->requests[irequest_full]->occasional= 1;
}
/* ---------------------------------------------------------------------- */
void FixTest::init_list(int id, NeighList *ptr)
{
printf("!!!!!!!!!!!!!!!! INIT_LIST WAS CALLED!!!!!!!!!!!!!!!!!!!!!!");
listfull=ptr;
}
void FixTest::post_integrate()
{
if (update->ntimestep % nevery) return;
if (!listfull) error->all(FLERR,"listfull null");
neighbor->build_one(listfull,1);
// now do something here
}
/* ---------------------------------------------------------------------- */
int FixTest::modify_param(int narg, char **arg)
{
return 0;
}