Commit 7295cf3d authored by Matthieu Schaller's avatar Matthieu Schaller
Browse files

Only use atomic operations when SWIFT_TASKS_WITHOUT_ATOMICS is not defined

parent 3742104d
......@@ -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
}
/**
......
......@@ -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
}
/**
......
......@@ -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]);
}
}
......
......@@ -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];
......
......@@ -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
......
......@@ -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);
}
......
......@@ -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
}
}
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment