commit d140a6a08a9d677da5451b8de1d769c9840663f6
parent 2562762c17ca9c5f80b30c7016dca66bba884f0a
Author: Anders Damsgaard <anders@adamsgaard.dk>
Date: Wed, 14 Jan 2026 08:40:45 +0100
feat(cngf-pf): add benchmark mode with -B flag
Diffstat:
1 file changed, 14 insertions(+), 15 deletions(-)
diff --git a/cngf-pf.c b/cngf-pf.c
@@ -10,8 +10,6 @@
#include "arg.h"
-/* uncomment to print time spent per time step to stdout */
-/* #define BENCHMARK_PERFORMANCE */
char *argv0;
@@ -21,6 +19,7 @@ usage(void)
fprintf(stderr, "usage: %s "
"[-A grain-nonlocal-ampl] "
"[-a fluid-pressure-ampl] "
+ "[-B] "
"[-b grain-rate-dependence] "
"[-C fluid-compressibility] "
"[-c grain-cohesion] "
@@ -68,14 +67,13 @@ int
main(int argc, char *argv[])
{
int i, normalize = 0, dt_override = 0, ret, iter, max_iter = 100000;
+ int benchmark = 0;
double new_phi, new_k, filetimeclock;
struct simulation sim;
double rtol = 1e-5;
-#ifdef BENCHMARK_PERFORMANCE
clock_t t_begin, t_end;
double t_elapsed;
-#endif
#ifdef __OpenBSD__
if (pledge("stdio wpath cpath", NULL) == -1)
@@ -93,6 +91,9 @@ main(int argc, char *argv[])
case 'a':
sim.p_f_mod_ampl = atof(EARGF(usage()));
break;
+ case 'B':
+ benchmark = 1;
+ break;
case 'b':
sim.b = atof(EARGF(usage()));
break;
@@ -276,21 +277,12 @@ main(int argc, char *argv[])
filetimeclock = 0.0;
iter = 0;
+ t_begin = clock();
do {
-
-#ifdef BENCHMARK_PERFORMANCE
- t_begin = clock();
-#endif
-
if (coupled_shear_solver(&sim, max_iter, rtol)) {
free_arrays(&sim);
exit(10);
}
-#ifdef BENCHMARK_PERFORMANCE
- t_end = clock();
- t_elapsed = (double) (t_end - t_begin) / CLOCKS_PER_SEC;
- printf("time spent per time step = %g s\n", t_elapsed);
-#endif
if ((filetimeclock >= sim.file_dt || iter == 1) &&
strncmp(sim.name, DEFAULT_SIMULATION_NAME,
@@ -302,8 +294,15 @@ main(int argc, char *argv[])
iter++;
} while (sim.t < sim.t_end);
+ t_end = clock();
+ t_elapsed = (double) (t_end - t_begin) / CLOCKS_PER_SEC;
- print_output(&sim, stdout, normalize);
+ if (!benchmark)
+ print_output(&sim, stdout, normalize);
+ else {
+ fprintf(stderr, "benchmark: elapsed_time=%.6f\n", t_elapsed);
+ print_solver_stats(stderr);
+ }
free_arrays(&sim);
return 0;