diff --git a/src/gravity/MultiSoftening/gravity.h b/src/gravity/MultiSoftening/gravity.h index 7cb2c50434b8a0399c80b0448ec93c66fbef572c..ce47dbe5ce13f03df8836a58972b544bc028fd6b 100644 --- a/src/gravity/MultiSoftening/gravity.h +++ b/src/gravity/MultiSoftening/gravity.h @@ -78,7 +78,11 @@ __attribute__((always_inline)) INLINE static float gravity_get_softening( __attribute__((always_inline)) INLINE static void gravity_add_comoving_potential(struct gpart* restrict gp, float pot) { +#ifdef SWIFT_TASKS_WITHOUT_ATOMICS + gp->potential += pot; +#else atomic_add_f(&gp->potential, pot); +#endif } /** diff --git a/src/gravity/Potential/gravity.h b/src/gravity/Potential/gravity.h index ff85f29c0a2b884f6cbc40d12b9baf066f16f15e..e467e05e0d9d9adbeecbf2192d4d5c50b18a9b5b 100644 --- a/src/gravity/Potential/gravity.h +++ b/src/gravity/Potential/gravity.h @@ -64,7 +64,11 @@ __attribute__((always_inline)) INLINE static float gravity_get_softening( __attribute__((always_inline)) INLINE static void gravity_add_comoving_potential(struct gpart* restrict gp, float pot) { +#ifdef SWIFT_TASKS_WITHOUT_ATOMICS + gp->potential += pot; +#else atomic_add_f(&gp->potential, pot); +#endif } /** diff --git a/src/gravity_cache.h b/src/gravity_cache.h index 6e55e3f44394e81fd169520a51c860336dfb991b..23103f05098df06705e2a9a9ce1ce83d99f57bdc 100644 --- a/src/gravity_cache.h +++ b/src/gravity_cache.h @@ -491,9 +491,15 @@ __attribute__((always_inline)) INLINE static void gravity_cache_write_back( /* Write stuff back to the particles */ for (int i = 0; i < gcount; ++i) { if (active[i]) { +#ifdef SWIFT_TASKS_WITHOUT_ATOMICS + gparts[i].a_grav[0] += a_x[i]; + gparts[i].a_grav[1] += a_y[i]; + gparts[i].a_grav[2] += a_z[i]; +#else atomic_add_f(&gparts[i].a_grav[0], a_x[i]); atomic_add_f(&gparts[i].a_grav[1], a_y[i]); atomic_add_f(&gparts[i].a_grav[2], a_z[i]); +#endif gravity_add_comoving_potential(&gparts[i], pot[i]); } } diff --git a/src/mesh_gravity.c b/src/mesh_gravity.c index 7cabd7bbae914f8ce1c934c16c728b8c853801ce..f36200718e952532da8c1c13453057deefb7eb51 100644 --- a/src/mesh_gravity.c +++ b/src/mesh_gravity.c @@ -334,10 +334,16 @@ void mesh_to_gparts_CIC(struct gpart* gp, const double* pot, const int N, /* ---- */ /* Store things back */ - gravity_add_comoving_potential(gp, p); +#ifdef SWIFT_TASKS_WITHOUT_ATOMICS + gp->a_grav[0] += fac * a[0]; + gp->a_grav[1] += fac * a[1]; + gp->a_grav[2] += fac * a[2]; +#else atomic_add_f(&gp->a_grav[0], fac * a[0]); atomic_add_f(&gp->a_grav[1], fac * a[1]); atomic_add_f(&gp->a_grav[2], fac * a[2]); +#endif + gravity_add_comoving_potential(gp, p); #ifdef SWIFT_GRAVITY_FORCE_CHECKS gp->potential_PM = p; gp->a_grav_PM[0] = fac * a[0]; diff --git a/src/multipole.h b/src/multipole.h index c4a51451db98b5cc961ec66ba0b59f25187c5d15..e7dcfbeb1f7a5b4fc6c993d619ba257dca016bdd 100644 --- a/src/multipole.h +++ b/src/multipole.h @@ -2589,9 +2589,15 @@ INLINE static void gravity_L2P(const struct grav_tensor *lb, #endif /* Update the particle */ +#ifdef SWIFT_TASKS_WITHOUT_ATOMICS + gp->a_grav[0] += a_grav[0]; + gp->a_grav[1] += a_grav[1]; + gp->a_grav[2] += a_grav[2]; +#else atomic_add_f(&gp->a_grav[0], a_grav[0]); atomic_add_f(&gp->a_grav[1], a_grav[1]); atomic_add_f(&gp->a_grav[2], a_grav[2]); +#endif gravity_add_comoving_potential(gp, pot); #ifdef SWIFT_GRAVITY_FORCE_CHECKS diff --git a/src/runner_doiact_grav.c b/src/runner_doiact_grav.c index 6d7a63db7fcaf9cd9809ff512a11e96d3110d2d3..bb914dc47ae48c042c8b19c84de88c727a2df624 100644 --- a/src/runner_doiact_grav.c +++ b/src/runner_doiact_grav.c @@ -1359,6 +1359,7 @@ static INLINE void runner_dopair_grav_mm_symmetric(struct runner *r, cj->grav.ti_old_multipole, cj->nodeID, ci->nodeID, e->ti_current); #endif +#ifndef SWIFT_TASKS_WITHOUT_ATOMICS /* Lock the multipoles * Note we impose a hierarchy to solve the dining philosopher problem */ if (ci < cj) { @@ -1368,15 +1369,18 @@ static INLINE void runner_dopair_grav_mm_symmetric(struct runner *r, lock_lock(&cj->grav.mlock); lock_lock(&ci->grav.mlock); } +#endif /* Let's interact at this level */ gravity_M2L_symmetric(&ci->grav.multipole->pot, &cj->grav.multipole->pot, multi_i, multi_j, ci->grav.multipole->CoM, cj->grav.multipole->CoM, props, periodic, dim, r_s_inv); +#ifndef SWIFT_TASKS_WITHOUT_ATOMICS /* Unlock the multipoles */ if (lock_unlock(&ci->grav.mlock) != 0) error("Failed to unlock multipole"); if (lock_unlock(&cj->grav.mlock) != 0) error("Failed to unlock multipole"); +#endif TIMER_TOC(timer_dopair_grav_mm); } @@ -1424,6 +1428,7 @@ static INLINE void runner_dopair_grav_mm_nonsym(struct runner *r, cj->grav.ti_old_multipole, cj->nodeID, ci->nodeID, e->ti_current); #endif +#ifndef SWIFT_TASKS_WITHOUT_ATOMICS /* Lock the multipoles * Note we impose a hierarchy to solve the dining philosopher problem */ if (ci < cj) { @@ -1433,14 +1438,17 @@ static INLINE void runner_dopair_grav_mm_nonsym(struct runner *r, lock_lock(&cj->grav.mlock); lock_lock(&ci->grav.mlock); } +#endif /* Let's interact at this level */ gravity_M2L_nonsym(&ci->grav.multipole->pot, multi_j, ci->grav.multipole->CoM, cj->grav.multipole->CoM, props, periodic, dim, r_s_inv); +#ifndef SWIFT_TASKS_WITHOUT_ATOMICS /* Unlock the multipoles */ if (lock_unlock(&ci->grav.mlock) != 0) error("Failed to unlock multipole"); if (lock_unlock(&cj->grav.mlock) != 0) error("Failed to unlock multipole"); +#endif TIMER_TOC(timer_dopair_grav_mm); } diff --git a/src/timestep_limiter_iact.h b/src/timestep_limiter_iact.h index 8c8fa7cee693036f509dd501d240d692d86f7b61..accfd33d0573fd98dccd6bb55acd18b2617cedcb 100644 --- a/src/timestep_limiter_iact.h +++ b/src/timestep_limiter_iact.h @@ -87,8 +87,12 @@ __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 */ + /* 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 } }