ERROR on proc X: Failed to reallocate -Y bytes for array vector:vector (src/memory.cpp:102)

I got this error when the commands write_data or write_restart are issued. This happens with version 22 Jul 2025 - Update 4, but not with the current develop (patch_30Mar2026-1211-g5af1318e9e). I attach a (rather elaborate) input script to reproduce the error.

reallocate_bug.tgz (115.6 KB)

Please try with this patch:

 git show f99ab6954ae99e23f44997a6d8d1b888aa22e3b8
  commit f99ab6954ae99e23f44997a6d8d1b888aa22e3b8
  gpg: Signature made Fri 08 May 2026 11:50:54 AM EDT
  gpg:                using RSA key EEA103764C6C633EDC8AC428D9B44E93BF0C375A
  gpg:                issuer "[email protected]"
  gpg: Good signature from "Axel Kohlmeyer <[email protected]>" [ultimate]
  Author: Axel Kohlmeyer <[email protected]>
  Date:   Fri May 8 11:40:36 2026 -0400
  
      ncountmax must remain > 0
  
  diff --git a/src/fix_vector.cpp b/src/fix_vector.cpp
  index aa91c21f7a..b3325a8d39 100644
  --- a/src/fix_vector.cpp
  +++ b/src/fix_vector.cpp
  @@ -159,7 +159,8 @@ FixVector::FixVector(LAMMPS *lmp, int narg, char **arg) :
   
     vector = nullptr;
     array = nullptr;
  -  ncount = ncountmax = nindex = 0;
  +  ncount = nindex = 0;
  +  ncountmax = 1;
     if (values.size() == 1)
       size_vector = 0;
     else
  @@ -226,6 +227,7 @@ void FixVector::init()
     bigint finalstep = update->endstep / nevery * nevery;
     if (finalstep > update->endstep) finalstep -= nevery;
     ncountmax = (finalstep - initialstep) / nevery + 1;
  +  if (ncountmax <= 0) ncountmax = 1;
     if (ncountmax > nmaxval) ncountmax = nmaxval;
     if (values.size() == 1)
       memory->grow(vector, ncountmax, "vector:vector");
1 Like

Applied to commit 611ca3b7f8525ba802373b04f9e3d632d515f7e3 and it works. Thanks!

newbies

patch -u src/fix_vector.cpp -i /tmp/vector.patch