Skip to content

Commit 6f36281

Browse files
author
Johannes Lang
committed
Fixed incorrect condition to grow time step in CPU branch
1 parent 5adb969 commit 6f36281

9 files changed

Lines changed: 19 additions & 11 deletions

File tree

RG-Evo

8.93 MB
Binary file not shown.

RG-Evo-shared

4 KB
Binary file not shown.

include/io/io_utils.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ struct SimulationDataSnapshot {
1616
std::vector<double> debug_step_memory;
1717
double energy;
1818
double t_current;
19+
int method; // 1=RK54, 2=SSPRK104, 3+=SERK2(2*(method-2))
1920
int current_len, current_loop;
2021
SimulationConfig config_snapshot;
2122

run.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@ module purge
1818

1919
# Load a current GPU toolchain. The cluster module tree moved away from
2020
# accel/nvhpc/24.9, so try the CUDA modules that are available now.
21-
if ! module load cuda/12.5 2>/dev/null; then
22-
if ! module load cuda/12.2 2>/dev/null; then
21+
if ! module load accel/cuda/12.5 2>/dev/null; then
22+
if ! module load accel/cuda/12.2 2>/dev/null; then
2323
module load accel/nvhpc/24.9
2424
fi
2525
fi

src/io/io_output.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
#include "convolution/convolution.cuh"
1010
#include "core/device_utils.cuh"
1111
#include "EOMs/time_steps.hpp"
12+
#include "EOMs/rk_data.hpp"
1213
#include "version/version_info.hpp"
1314
#include <fstream>
1415
#include <iostream>
@@ -485,8 +486,7 @@ void saveParametersToFileAsync(const std::string& dirPath, double delta, double
485486
params << "current_loop = " << snapshot.current_loop << std::endl;
486487
params << "current_delta = " << delta << std::endl;
487488
params << "current_delta_t = " << delta_t << std::endl;
488-
// Note: We can't access rk->host->init in async context, so we'll use a default
489-
params << "current_method = N/A (async)" << std::endl;
489+
params << "current_method = " << (snapshot.method == 1 ? "RK54" : snapshot.method == 2 ? "SSPRK104" : "SERK2(" + std::to_string(2 * (snapshot.method - 2)) + ")") << std::endl;
490490
params << "current_t1grid_size = " << snapshot.t1grid.size() << std::endl;
491491
params << "current_QK0 = " << snapshot.QKv[(snapshot.t1grid.size() - 1) * snapshot.current_len] << std::endl;
492492
params << "current_QR0 = " << snapshot.QRv[(snapshot.t1grid.size() - 1) * snapshot.current_len] << std::endl;

src/io/io_output.cu

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111
#include "convolution/convolution.cuh"
1212
#include "core/device_utils.cuh"
1313
#include "EOMs/time_steps.hpp"
14+
#include "EOMs/rk_data.hpp"
15+
#include "EOMs/device_rk_data.hpp"
1416
#include "version/version_info.hpp"
1517
#include <fstream>
1618
#include <iostream>
@@ -148,7 +150,7 @@ SimulationDataSnapshot createDataSnapshot()
148150
copyDeviceToSnapshot(snapshot.QKB1int, sim->device->QKB1int);
149151
copyDeviceToSnapshot(snapshot.QRB1int, sim->device->QRB1int);
150152
copyDeviceToSnapshot(snapshot.theta, sim->device->theta);
151-
snapshot.t_current = snapshot.t1grid.back();
153+
cudaMemcpy(&snapshot.method, &rk->device->init, sizeof(int), cudaMemcpyDeviceToHost); // Store the RK method used on GPU
152154
} else {
153155
// For CPU runs, copy from host vectors as before
154156
snapshot.QKv = sim->host->QKv;
@@ -164,6 +166,7 @@ SimulationDataSnapshot createDataSnapshot()
164166
snapshot.QRB1int = sim->host->QRB1int;
165167
snapshot.theta = sim->host->theta;
166168
snapshot.t_current = sim->host->t1grid.back();
169+
snapshot.method = rk->host->init; // Store the RK method used on CPU
167170
}
168171

169172
// Calculate energy

src/io/io_save_params.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -396,7 +396,7 @@ void saveParametersToFileAsync(const std::string& dirPath, double delta, double
396396
params << "current_loop = " << snapshot.current_loop << std::endl;
397397
params << "current_delta = " << delta << std::endl;
398398
params << "current_delta_t = " << delta_t << std::endl;
399-
params << "current_method = N/A (async)" << std::endl;
399+
params << "current_method = " << (snapshot.method == 1 ? "RK54" : snapshot.method == 2 ? "SSPRK104" : "SERK2(" + std::to_string(2 * (snapshot.method - 2)) + ")") << std::endl;
400400
params << "current_t1grid_size = " << snapshot.t1grid.size() << std::endl;
401401
params << "current_QK0 = " << snapshot.QKv[(snapshot.t1grid.size() - 1) * snapshot.current_len] << std::endl;
402402
params << "current_QR0 = " << snapshot.QRv[(snapshot.t1grid.size() - 1) * snapshot.current_len] << std::endl;

src/io/io_snapshot_host.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ SimulationDataSnapshot createDataSnapshot() {
3131
snapshot.QRB1int = sim->host->QRB1int;
3232
snapshot.theta = sim->host->theta;
3333
snapshot.t_current = sim->host->t1grid.empty() ? 0.0 : sim->host->t1grid.back();
34+
snapshot.method = rk->host->init; // Store the RK method used on CPU
3435

3536
std::vector<double> temp(config.len, 0.0);
3637
std::vector<double> lastQKv = getLastLenEntries(sim->host->QKv, config.len);

src/simulation/simulation_runner.cpp

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ int runSimulation() {
137137
#endif
138138
config.delta_old = config.delta;
139139
config.delta = update(pool);
140-
140+
141141
if (config.tail_fit_enabled) {
142142
#if DMFE_WITH_CUDA
143143
// Optional tail fit/blend near theta->1 (toggle with --tail-fit)
@@ -250,11 +250,14 @@ int runSimulation() {
250250
}
251251
}
252252

253-
// primitive time-step adaptation
253+
// primitive time-step adaptation
254254
#if DMFE_WITH_CUDA
255-
if (config.delta < config.delta_max && config.loop > 5 &&
255+
if ((config.gpu && (config.delta < config.delta_max && config.loop > 5 &&
256+
(config.delta < 1.1 * config.delta_old || config.delta_old < config.delta_max/1000) &&
257+
config.rmax[rk->device->init-1] / config.specRad > config.delta_t && (config.gpu ? sim->device->delta_t_ratio.back() : sim->host->delta_t_ratio.back()) == 1.0)) ||
258+
(!config.gpu && (config.delta < config.delta_max && config.loop > 5 &&
256259
(config.delta < 1.1 * config.delta_old || config.delta_old < config.delta_max/1000) &&
257-
config.rmax[rk->device->init-1] / config.specRad > config.delta_t && (config.gpu ? sim->device->delta_t_ratio.back() : sim->host->delta_t_ratio.back()) == 1.0)
260+
config.rmax[rk->host->init-1] / config.specRad > config.delta_t && sim->host->delta_t_ratio.back() == 1.0)))
258261
#else
259262
if (config.delta < config.delta_max && config.loop > 5 &&
260263
(config.delta < 1.1 * config.delta_old || config.delta_old < config.delta_max/1000) &&
@@ -316,7 +319,7 @@ int runSimulation() {
316319
#endif
317320

318321
// Status: continuous multi-line TUI for TTY when debug is off; otherwise line-per-iteration
319-
std::string method = (rk->host->init == 1 ? "RK54" : rk->host->init == 2 ? "SSPRK104" : "SERK2(" + std::to_string(2 * (rk->host->init - 2)) + ")");
322+
std::string method = config.gpu ? (rk->device->init == 1 ? "RK54" : rk->device->init == 2 ? "SSPRK104" : "SERK2(" + std::to_string(2 * (rk->device->init - 2)) + ")") : (rk->host->init == 1 ? "RK54" : rk->host->init == 2 ? "SSPRK104" : "SERK2(" + std::to_string(2 * (rk->host->init - 2)) + ")");
320323
if (continuous_status) {
321324
ui.update_status(t, config.tmax, config.loop, config.delta_t, method);
322325
} else if (config.debug) {

0 commit comments

Comments
 (0)