From 4243af30d7ed4781534730adf11c417ffd9148c1 Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Thu, 30 May 2019 23:54:59 -0400 Subject: [PATCH 1/3] properly store 64-bit integers for next_reneighbor into double type buffers for restarts of fixes also store number of attemps and number of successes in restart and retrieve those from it --- src/MC/fix_atom_swap.cpp | 11 ++++++++--- src/MC/fix_gcmc.cpp | 24 +++++++++++++++++++++--- src/MISC/fix_deposit.cpp | 4 ++-- 3 files changed, 31 insertions(+), 8 deletions(-) diff --git a/src/MC/fix_atom_swap.cpp b/src/MC/fix_atom_swap.cpp index 12b5d65f4a..aad8d7447f 100644 --- a/src/MC/fix_atom_swap.cpp +++ b/src/MC/fix_atom_swap.cpp @@ -771,10 +771,12 @@ double FixAtomSwap::memory_usage() void FixAtomSwap::write_restart(FILE *fp) { int n = 0; - double list[4]; + double list[6]; list[n++] = random_equal->state(); list[n++] = random_unequal->state(); - list[n++] = next_reneighbor; + list[n++] = ubuf(next_reneighbor).d; + list[n++] = nswap_attempts; + list[n++] = nswap_successes; if (comm->me == 0) { int size = n * sizeof(double); @@ -798,5 +800,8 @@ void FixAtomSwap::restart(char *buf) seed = static_cast (list[n++]); random_unequal->reset(seed); - next_reneighbor = static_cast (list[n++]); + next_reneighbor = (bigint) ubuf(list[n++]).i; + + nswap_attempts = static_cast(list[n++]); + nswap_successes = static_cast(list[n++]); } diff --git a/src/MC/fix_gcmc.cpp b/src/MC/fix_gcmc.cpp index f1664e3540..f3a11a1000 100644 --- a/src/MC/fix_gcmc.cpp +++ b/src/MC/fix_gcmc.cpp @@ -2531,10 +2531,19 @@ double FixGCMC::memory_usage() void FixGCMC::write_restart(FILE *fp) { int n = 0; - double list[4]; + double list[12]; list[n++] = random_equal->state(); list[n++] = random_unequal->state(); - list[n++] = next_reneighbor; + list[n++] = ubuf(next_reneighbor).d; + list[n++] = ntranslation_attempts; + list[n++] = ntranslation_successes; + list[n++] = nrotation_attempts; + list[n++] = nrotation_successes; + list[n++] = ndeletion_attempts; + list[n++] = ndeletion_successes; + list[n++] = ninsertion_attempts; + list[n++] = ninsertion_successes; + if (comm->me == 0) { int size = n * sizeof(double); @@ -2558,7 +2567,16 @@ void FixGCMC::restart(char *buf) seed = static_cast (list[n++]); random_unequal->reset(seed); - next_reneighbor = static_cast (list[n++]); + next_reneighbor = (bigint) ubuf(list[n++]).i; + + ntranslation_attempts = list[n++]; + ntranslation_successes = list[n++]; + nrotation_attempts = list[n++]; + nrotation_successes = list[n++]; + ndeletion_attempts = list[n++]; + ndeletion_successes = list[n++]; + ninsertion_attempts = list[n++]; + ninsertion_successes = list[n++]; } void FixGCMC::grow_molecule_arrays(int nmolatoms) { diff --git a/src/MISC/fix_deposit.cpp b/src/MISC/fix_deposit.cpp index 1428299eb7..a1d0669f32 100644 --- a/src/MISC/fix_deposit.cpp +++ b/src/MISC/fix_deposit.cpp @@ -802,7 +802,7 @@ void FixDeposit::write_restart(FILE *fp) list[n++] = random->state(); list[n++] = ninserted; list[n++] = nfirst; - list[n++] = next_reneighbor; + list[n++] = ubuf(next_reneighbor).d; if (comm->me == 0) { int size = n * sizeof(double); @@ -823,7 +823,7 @@ void FixDeposit::restart(char *buf) seed = static_cast (list[n++]); ninserted = static_cast (list[n++]); nfirst = static_cast (list[n++]); - next_reneighbor = static_cast (list[n++]); + next_reneighbor = (bigint) ubuf(list[n++]).i; random->reset(seed); } From f73c848ee404be8a704bf247e42b99b14bf8b6d2 Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Fri, 31 May 2019 00:31:36 -0400 Subject: [PATCH 2/3] detect and error out when timestep was reset when restarting fixes atom/swap, gcmc, or deposit --- src/MC/fix_atom_swap.cpp | 5 +++++ src/MC/fix_gcmc.cpp | 6 +++++- src/MISC/fix_deposit.cpp | 7 ++++++- 3 files changed, 16 insertions(+), 2 deletions(-) diff --git a/src/MC/fix_atom_swap.cpp b/src/MC/fix_atom_swap.cpp index aad8d7447f..7d817ffbb1 100644 --- a/src/MC/fix_atom_swap.cpp +++ b/src/MC/fix_atom_swap.cpp @@ -777,6 +777,7 @@ void FixAtomSwap::write_restart(FILE *fp) list[n++] = ubuf(next_reneighbor).d; list[n++] = nswap_attempts; list[n++] = nswap_successes; + list[n++] = ubuf(update->ntimestep).d; if (comm->me == 0) { int size = n * sizeof(double); @@ -804,4 +805,8 @@ void FixAtomSwap::restart(char *buf) nswap_attempts = static_cast(list[n++]); nswap_successes = static_cast(list[n++]); + + bigint ntimestep_restart = (bigint) ubuf(list[n++]).i; + if (ntimestep_restart != update->ntimestep) + error->all(FLERR,"Must not reset timestep when restarting fix atom/swap"); } diff --git a/src/MC/fix_gcmc.cpp b/src/MC/fix_gcmc.cpp index f3a11a1000..7ab0879335 100644 --- a/src/MC/fix_gcmc.cpp +++ b/src/MC/fix_gcmc.cpp @@ -2543,7 +2543,7 @@ void FixGCMC::write_restart(FILE *fp) list[n++] = ndeletion_successes; list[n++] = ninsertion_attempts; list[n++] = ninsertion_successes; - + list[n++] = ubuf(update->ntimestep).d; if (comm->me == 0) { int size = n * sizeof(double); @@ -2577,6 +2577,10 @@ void FixGCMC::restart(char *buf) ndeletion_successes = list[n++]; ninsertion_attempts = list[n++]; ninsertion_successes = list[n++]; + + bigint ntimestep_restart = (bigint) ubuf(list[n++]).i; + if (ntimestep_restart != update->ntimestep) + error->all(FLERR,"Must not reset timestep when restarting fix gcmc"); } void FixGCMC::grow_molecule_arrays(int nmolatoms) { diff --git a/src/MISC/fix_deposit.cpp b/src/MISC/fix_deposit.cpp index a1d0669f32..66aed34846 100644 --- a/src/MISC/fix_deposit.cpp +++ b/src/MISC/fix_deposit.cpp @@ -798,11 +798,12 @@ void FixDeposit::options(int narg, char **arg) void FixDeposit::write_restart(FILE *fp) { int n = 0; - double list[4]; + double list[5]; list[n++] = random->state(); list[n++] = ninserted; list[n++] = nfirst; list[n++] = ubuf(next_reneighbor).d; + list[n++] = ubuf(update->ntimestep).d; if (comm->me == 0) { int size = n * sizeof(double); @@ -825,6 +826,10 @@ void FixDeposit::restart(char *buf) nfirst = static_cast (list[n++]); next_reneighbor = (bigint) ubuf(list[n++]).i; + bigint ntimestep_restart = (bigint) ubuf(list[n++]).i; + if (ntimestep_restart != update->ntimestep) + error->all(FLERR,"Must not reset timestep when restarting this fix"); + random->reset(seed); } From 8b169d97f5fc063081edaec35764412cc97d12a3 Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Fri, 31 May 2019 00:58:10 -0400 Subject: [PATCH 3/3] update documentation for updates to fix restarting --- doc/src/fix_atom_swap.txt | 7 ++++++- doc/src/fix_deposit.txt | 4 ++++ doc/src/fix_gcmc.txt | 7 ++++++- 3 files changed, 16 insertions(+), 2 deletions(-) diff --git a/doc/src/fix_atom_swap.txt b/doc/src/fix_atom_swap.txt index 22091eca00..cb6bc26aa1 100644 --- a/doc/src/fix_atom_swap.txt +++ b/doc/src/fix_atom_swap.txt @@ -141,11 +141,16 @@ specify if this should be done. This fix writes the state of the fix to "binary restart files"_restart.html. This includes information about the random -number generator seed, the next timestep for MC exchanges, etc. See +number generator seed, the next timestep for MC exchanges, the number +of exchange attempts and successes etc. See the "read_restart"_read_restart.html command for info on how to re-specify a fix in an input script that reads a restart file, so that the operation of the fix continues in an uninterrupted fashion. +NOTE: For this to work correctly, the timestep must [not] be changed +after reading the restart with "reset_timestep"_reset_timestep.html. +The fix will try to detect it and stop with an error. + None of the "fix_modify"_fix_modify.html options are relevant to this fix. diff --git a/doc/src/fix_deposit.txt b/doc/src/fix_deposit.txt index fd12d4bb45..9ab125a55f 100644 --- a/doc/src/fix_deposit.txt +++ b/doc/src/fix_deposit.txt @@ -261,6 +261,10 @@ next timestep for deposition, etc. See the a fix in an input script that reads a restart file, so that the operation of the fix continues in an uninterrupted fashion. +NOTE: For this to work correctly, the timestep must [not] be changed +after reading the restart with "reset_timestep"_reset_timestep.html. +The fix will try to detect it and stop with an error. + None of the "fix_modify"_fix_modify.html options are relevant to this fix. No global or per-atom quantities are stored by this fix for access by various "output commands"_Howto_output.html. No parameter diff --git a/doc/src/fix_gcmc.txt b/doc/src/fix_gcmc.txt index 8a66a007a3..3c0f2c2f17 100644 --- a/doc/src/fix_gcmc.txt +++ b/doc/src/fix_gcmc.txt @@ -373,11 +373,16 @@ adds all inserted atoms of the specified type to the This fix writes the state of the fix to "binary restart files"_restart.html. This includes information about the random -number generator seed, the next timestep for MC exchanges, etc. See +number generator seed, the next timestep for MC exchanges, the number +of MC step attempts and successes etc. See the "read_restart"_read_restart.html command for info on how to re-specify a fix in an input script that reads a restart file, so that the operation of the fix continues in an uninterrupted fashion. +NOTE: For this to work correctly, the timestep must [not] be changed +after reading the restart with "reset_timestep"_reset_timestep.html. +The fix will try to detect it and stop with an error. + None of the "fix_modify"_fix_modify.html options are relevant to this fix.