From ac2448b184e1df0144d5cae0988005caaa220b7e Mon Sep 17 00:00:00 2001 From: Matthieu Schaller <schaller@strw.leidenuniv.nl> Date: Tue, 31 Mar 2020 12:04:37 +0200 Subject: [PATCH] Apply the same change to the max operation taking place in the timestep limiter task --- src/accumulate.h | 61 +++++++++++++++++++++++++++++++++++++ src/timestep_limiter_iact.h | 8 ++--- 2 files changed, 63 insertions(+), 6 deletions(-) diff --git a/src/accumulate.h b/src/accumulate.h index a7e8e6c1bf..877ac23baa 100644 --- a/src/accumulate.h +++ b/src/accumulate.h @@ -24,6 +24,7 @@ /* Local includes */ #include "atomic.h" +#include "minmax.h" /** * @file accumulate.h @@ -144,4 +145,64 @@ __attribute__((always_inline)) INLINE static void accumulate_inc_ll( #endif } +/** + * @brief Compute the max of x and the value storedd at the location address + * and store the value at the address (int8_t version). + * + * When SWIFT_TASKS_WITHOUT_ATOMICS is *not* defined this function uses an + * atomic operation. + * + * @param address The address to update. + * @param x The value to max against *address. + */ +__attribute__((always_inline)) INLINE static void accumulate_max_c( + volatile int8_t *const address, const int8_t x) { + +#ifdef SWIFT_TASKS_WITHOUT_ATOMICS + *address = max(*address, x); +#else + atomic_max_c(address, x); +#endif +} + +/** + * @brief Compute the max of x and the value storedd at the location address + * and store the value at the address (int version). + * + * When SWIFT_TASKS_WITHOUT_ATOMICS is *not* defined this function uses an + * atomic operation. + * + * @param address The address to update. + * @param x The value to max against *address. + */ +__attribute__((always_inline)) INLINE static void accumulate_max_i( + volatile int *const address, const int x) { + +#ifdef SWIFT_TASKS_WITHOUT_ATOMICS + *address = max(*address, x); +#else + atomic_max(address, x); +#endif +} + +/** + * @brief Compute the max of x and the value storedd at the location address + * and store the value at the address (float version). + * + * When SWIFT_TASKS_WITHOUT_ATOMICS is *not* defined this function uses an + * atomic operation. + * + * @param address The address to update. + * @param x The value to max against *address. + */ +__attribute__((always_inline)) INLINE static void accumulate_max_f( + volatile float *const address, const float x) { + +#ifdef SWIFT_TASKS_WITHOUT_ATOMICS + *address = max(*address, x); +#else + atomic_max_f(address, x); +#endif +} + #endif /* SWIFT_ACCUMULATE_H */ diff --git a/src/timestep_limiter_iact.h b/src/timestep_limiter_iact.h index accfd33d05..839b1a3dc4 100644 --- a/src/timestep_limiter_iact.h +++ b/src/timestep_limiter_iact.h @@ -87,12 +87,8 @@ __attribute__((always_inline)) INLINE static void runner_iact_nonsym_limiter( /* Wake up the neighbour? */ if (pj->time_bin > pi->time_bin + time_bin_neighbour_max_delta_bin) { - /* Store the smallest time bin that woke up this particle */ -#ifdef SWIFT_TASKS_WITHOUT_ATOMICS - pj->limiter_data.wakeup = max(pj->limiter_data.wakeup, -pi->time_bin); -#else - atomic_max_c(&pj->limiter_data.wakeup, -pi->time_bin); -#endif + /* Store the smallest time bin that woke up this particle */ + accumulate_max_c(&pj->limiter_data.wakeup, -pi->time_bin); } } -- GitLab