From 3348cd78f4e78e52d13f895d0f8b2ba7dfb95445 Mon Sep 17 00:00:00 2001 From: Matthieu Schaller <matthieu.schaller@durham.ac.uk> Date: Tue, 22 Mar 2016 09:26:39 +0000 Subject: [PATCH] Save a sqrtf() call per particle in drift task --- src/runner.c | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/src/runner.c b/src/runner.c index 7eedb6adc7..92eb8c3df7 100644 --- a/src/runner.c +++ b/src/runner.c @@ -709,16 +709,18 @@ void runner_dodrift(struct runner *r, struct cell *c, int timer) { /* Predict the values of the extra fields */ hydro_predict_extra(p, xp, ti_old, ti_current, timeBase); - /* Compute motion since last cell construction */ - const float dx = - sqrtf((p->x[0] - xp->x_old[0]) * (p->x[0] - xp->x_old[0]) + - (p->x[1] - xp->x_old[1]) * (p->x[1] - xp->x_old[1]) + - (p->x[2] - xp->x_old[2]) * (p->x[2] - xp->x_old[2])); + /* Compute (square of) motion since last cell construction */ + const float dx = (p->x[0] - xp->x_old[0]) * (p->x[0] - xp->x_old[0]) + + (p->x[1] - xp->x_old[1]) * (p->x[1] - xp->x_old[1]) + + (p->x[2] - xp->x_old[2]) * (p->x[2] - xp->x_old[2]); dx_max = fmaxf(dx_max, dx); /* Maximal smoothing length */ h_max = fmaxf(p->h, h_max); } + + /* Now, get the maximal particle motion from its square */ + dx_max = sqrtf(dx_max); } /* Otherwise, aggregate data from children. */ -- GitLab