Bug fix

Hello,

I found and fixed a minor bug in fix_addforce.cpp.

The bug occurs when any processor owns no atoms at the start of a run. Initialization calls FixAddForce::post_force(), but if nlocal = 0, sforce is never created, i.e.

  if ((varflag == ATOM || estyle == ATOM) && nlocal > maxatom) {
    maxatom = atom->nmax;
    memory->destroy(sforce);
    memory->create(sforce,maxatom,4,"addforce:sforce");
  }

is skipped. This induces an MPI_Allreduce error at runtime that kills the run without saying much else. A simple fix that works:

  if ((nlocal==0) || ( (varflag == ATOM || estyle == ATOM) && nlocal > maxatom)) { ... }

With this modification, the code runs as expected.

If balance were working perfectly, and if everyone who needed to knew enough to use balance, this might not be an issue, but it looks like balance.cpp is currently undergoing a lot of development.

Thanks

Are you running the current version of LAMMPS?
I'm thinking this may be already fixed.

I don't see where a check like you advocate is necessary.
Which Allreduce is causing an issue? I don't see one
in fix addforce that is wrong.

Steve

Steve,

I had pulled from the git repository an hour or so before I posted, in order to check whether it had already been fixed. But, I had neglected to make from scratch, and had evidently linked to a few outdated objects. I checked for the bug this morning using a clean make -- and the bug disappeared. So, you are right, this bug had already been resolved.

I believe the problematic call to MPI_Allreduce had been located in an inherited member function that attempted to reduce an unallocated sforce array.

Thanks,
Seth.