tAdd compile-time option to report performance to stdout - cngf-pf - continuum … | |
git clone git://src.adamsgaard.dk/cngf-pf | |
Log | |
Files | |
Refs | |
README | |
LICENSE | |
--- | |
commit 76510832b863589eaf491e7555b6557a470e8fe3 | |
parent d7784f92664ba94b5c19934fc6f585b268b8d54d | |
Author: Anders Damsgaard <[email protected]> | |
Date: Tue, 12 Nov 2019 16:47:52 +0100 | |
Add compile-time option to report performance to stdout | |
Diffstat: | |
M main.c | 18 ++++++++++++++++++ | |
1 file changed, 18 insertions(+), 0 deletions(-) | |
--- | |
diff --git a/main.c b/main.c | |
t@@ -3,6 +3,7 @@ | |
#include <math.h> | |
#include <getopt.h> | |
#include <string.h> | |
+#include <time.h> | |
#include "simulation.h" | |
#include "fluid.h" | |
t@@ -24,6 +25,9 @@ | |
#define RTOL_STRESS 1e-3 | |
#define MAX_ITER_STRESS 20000 | |
+/* uncomment to print time spent per time step to stdout */ | |
+/*#define BENCHMARK_PERFORMANCE*/ | |
+ | |
static void | |
usage(void) | |
{ | |
t@@ -139,6 +143,10 @@ main(int argc, char* argv[]) | |
const char* optstring; | |
unsigned long iter, stressiter; | |
double new_phi, new_k, filetimeclock, res_norm, mu_wall_orig; | |
+#ifdef BENCHMARK_PERFORMANCE | |
+ clock_t t_begin, t_end; | |
+ double t_elapsed; | |
+#endif | |
/* load with default values */ | |
sim = init_sim(); | |
t@@ -345,6 +353,10 @@ main(int argc, char* argv[]) | |
res_norm = NAN; | |
while (sim.t <= sim.t_end) { | |
+#ifdef BENCHMARK_PERFORMANCE | |
+ t_begin = clock(); | |
+#endif | |
+ | |
stressiter = 0; | |
do { | |
if (sim.fluid) { | |
t@@ -390,6 +402,12 @@ main(int argc, char* argv[]) | |
} while ((!isnan(sim.v_x_fix) || !isnan(sim.v_x_limit)) | |
&& fabs(res_norm) > RTOL_STRESS); | |
+#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 (!isnan(sim.v_x_limit)) | |
sim.mu_wall = mu_wall_orig; | |
sim.t += sim.dt; |