diff --git a/src/accumulate.h b/src/accumulate.h index a7e8e6c1bfe177755edbbf3aa830107ebff15c7b..877ac23baa1e9041c45a8d3dcc10a1d660ea6c68 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 accfd33d0573fd98dccd6bb55acd18b2617cedcb..839b1a3dc450ca12b8b0c8824fd75cd87063a7b8 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); } }