From b3eaf7e7f416c87dd98a17e7d90336b6bff77011 Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Sat, 5 Jul 2025 11:57:59 -0400 Subject: [PATCH] cache spcpu and tpcpu values so these thermo keywords can be used multiple times --- src/thermo.cpp | 18 ++++++++++++++---- src/thermo.h | 2 +- 2 files changed, 15 insertions(+), 5 deletions(-) diff --git a/src/thermo.cpp b/src/thermo.cpp index 8604ced41f..9c591e2428 100644 --- a/src/thermo.cpp +++ b/src/thermo.cpp @@ -1835,9 +1835,13 @@ void Thermo::compute_tpcpu() if (firststep == 0) { new_cpu = 0.0; dvalue = 0.0; + // if evaluated on the same step already used cached value + } else if (last_time == new_time) { + dvalue = last_tpcpu; + return; } else { new_cpu = timer->elapsed(Timer::TOTAL); - double cpu_diff = new_cpu - last_tpcpu; + double cpu_diff = new_cpu - last_cpu1; double time_diff = new_time - last_time; if (time_diff > 0.0 && cpu_diff > 0.0) dvalue = time_diff / cpu_diff; @@ -1846,7 +1850,8 @@ void Thermo::compute_tpcpu() } last_time = new_time; - last_tpcpu = new_cpu; + last_cpu1 = new_cpu; + last_tpcpu = dvalue; } /* ---------------------------------------------------------------------- */ @@ -1859,9 +1864,13 @@ void Thermo::compute_spcpu() if (firststep == 0) { new_cpu = 0.0; dvalue = 0.0; + // if evaluated on the same step already used cached value + } else if (last_step == new_step) { + dvalue = last_spcpu; + return; } else { new_cpu = timer->elapsed(Timer::TOTAL); - double cpu_diff = new_cpu - last_spcpu; + double cpu_diff = new_cpu - last_cpu2; auto step_diff = double(new_step - last_step); if (cpu_diff > 0.0) dvalue = step_diff / cpu_diff; @@ -1869,8 +1878,9 @@ void Thermo::compute_spcpu() dvalue = 0.0; } + last_cpu2 = new_cpu; last_step = new_step; - last_spcpu = new_cpu; + last_spcpu = dvalue; } /* ---------------------------------------------------------------------- */ diff --git a/src/thermo.h b/src/thermo.h index 7a8294c445..cfec9a3ec1 100644 --- a/src/thermo.h +++ b/src/thermo.h @@ -80,7 +80,7 @@ class Thermo : protected Pointers { int flushflag, lineflag; double last_tpcpu, last_spcpu; - double last_time; + double last_time, last_cpu1, last_cpu2; bigint last_step; bigint natoms;