Problem with memory allocation in REAXFF calculations

I am having a problem with some REAXFF calculations after upgrading to LAMMPS 7Jan2022 (also with the most recent stable release). With the attached input the run immediately dies with:

ERROR on proc 0: Failed to allocate -15980 bytes for array reaxff/species:molmap (…/memory.cpp:66)

It does not matter whether I use one or multiple cores. The same input works with LAMMPS 29Oct20. I have noticed that there have been larger changes in the REAXFF code between these releases, but the old input syntax is supposed to still work. Changing reax/c to reaxff does not solve the issue either.

Best Regards,
Jörg-Rüdiger Hill

There is no input attached.

Sorry, the system does not allow me to upload files.

Your account is new. So that is the spam protection at work. I have changed you account status to regular user. Please try again.

The input files to reproduce the problem:
reaxff_problem.tar.bz2 (21.5 KB)

You are using a modified version of fix reaxff/species. LAMMPS version doesn’t have terse keyword.

Sorry, forgot to remove this. The problem occurs also when you remove this keyword.

Well, there also is the issue that you have modified the code to work with dynamic groups.
Since you are using nevery=1 it should be OK, though.

The reason for the error message is that you have no atoms in your fix group. This is not anticipated by the existing code and thus will lead to a negative number of molecules and then trying to allocate a negative size array as a consequence, which ultimately causes the error.

The following patch should address this:

  diff --git a/src/REAXFF/fix_reaxff_species.cpp b/src/REAXFF/fix_reaxff_species.cpp
  index 352dd33f62..0f5af77453 100644
  --- a/src/REAXFF/fix_reaxff_species.cpp
  +++ b/src/REAXFF/fix_reaxff_species.cpp
  @@ -26,6 +26,7 @@
   #include "error.h"
   #include "fix_ave_atom.h"
   #include "force.h"
  +#include "group.h"
   #include "memory.h"
   #include "modify.h"
   #include "neigh_list.h"
  @@ -68,6 +69,7 @@ FixReaxFFSpecies::FixReaxFFSpecies(LAMMPS *lmp, int narg, char **arg) : Fix(lmp,
     nevery = utils::inumeric(FLERR, arg[3], false, lmp);
     nrepeat = utils::inumeric(FLERR, arg[4], false, lmp);
     global_freq = nfreq = utils::inumeric(FLERR, arg[5], false, lmp);
  +  if (nrepeat == 1) dynamic_group_allow = 1;
   
     comm_forward = 4;
   
  @@ -394,9 +396,7 @@ void FixReaxFFSpecies::Output_ReaxFF_Bonds(bigint ntimestep, FILE * /*fp*/)
     Nmole = Nspec = 0;
   
     FindMolecule();
  -
     SortMolecule(Nmole);
  -
     FindSpecies(Nmole, Nspec);
   
     vector_nmole = Nmole;
  @@ -521,16 +521,21 @@ void FixReaxFFSpecies::SortMolecule(int &Nmole)
       hi = MAX(hi, nint(clusterID[n]));
     }
     int flagall;
  -  MPI_Allreduce(&flag, &flagall, 1, MPI_INT, MPI_SUM, world);
  -  if (flagall && me == 0)
  -    error->warning(FLERR, "Atom with cluster ID = 0 included in fix reaxff/species group");
     MPI_Allreduce(&lo, &idlo, 1, MPI_INT, MPI_MIN, world);
     MPI_Allreduce(&hi, &idhi, 1, MPI_INT, MPI_MAX, world);
  +  int nlen = idhi - idlo + 1;
  +  if (nlen <= 0) {  // no atoms in group
  +    Nmole = 0;
  +    return;
  +  }
     if (idlo == ntotal)
       if (me == 0)
  -      error->warning(FLERR, "Atom with cluster ID = maxmol included in fix reaxff/species group");
  +      error->warning(FLERR, "Atom with cluster ID = maxmol included in fix reaxff/species group {}",group->names[igroup]);
  +
  +  MPI_Allreduce(&flag, &flagall, 1, MPI_INT, MPI_SUM, world);
  +  if (flagall && me == 0)
  +    error->warning(FLERR, "Atom with cluster ID = 0 included in fix reaxff/species group {}", group->names[igroup]);
   
  -  int nlen = idhi - idlo + 1;
     memory->create(molmap, nlen, "reaxff/species:molmap");
     for (n = 0; n < nlen; n++) molmap[n] = 0;

This patch is now submitted for inclusion into the next LAMMPS patch release: Fix reaxff/species update for dynamic groups and empty groups by akohlmey · Pull Request #3395 · lammps/lammps · GitHub