Commit 65391edd authored by Matthieu Schaller's avatar Matthieu Schaller
Browse files

Also use atomics when running the gravity checks

parent cc95ff35
......@@ -2467,12 +2467,12 @@ INLINE static void gravity_L2P(const struct grav_tensor *lb,
#ifdef SWIFT_DEBUG_CHECKS
if (lb->num_interacted == 0) error("Interacting with empty field tensor");
gp->num_interacted += lb->num_interacted;
atomic_add(&gp->num_interacted, lb->num_interacted);
#endif
#ifdef SWIFT_GRAVITY_FORCE_CHECKS
gp->num_interacted_m2l += lb->num_interacted_tree;
gp->num_interacted_pm += lb->num_interacted_pm;
atomic_add(&gp->num_interacted_m2l, lb->num_interacted_tree);
atomic_add(&gp->num_interacted_pm, lb->num_interacted_pm);
#endif
/* Local accumulator */
......@@ -2595,9 +2595,9 @@ INLINE static void gravity_L2P(const struct grav_tensor *lb,
gravity_add_comoving_potential(gp, pot);
#ifdef SWIFT_GRAVITY_FORCE_CHECKS
gp->a_grav_m2l[0] += a_grav[0];
gp->a_grav_m2l[1] += a_grav[1];
gp->a_grav_m2l[2] += a_grav[2];
atomic_add_f(&gp->a_grav_m2l[0], a_grav[0]);
atomic_add_f(&gp->a_grav_m2l[1], a_grav[1]);
atomic_add_f(&gp->a_grav_m2l[2], a_grav[2]);
#endif
}
......
......@@ -270,7 +270,7 @@ static INLINE void runner_dopair_grav_pp_full(
#ifdef SWIFT_GRAVITY_FORCE_CHECKS
/* Update the p2p interaction counter if it's not a padded gpart */
if (pjd < gcount_j && !gpart_is_inhibited(&gparts_j[pjd], e))
gparts_i[pid].num_interacted_p2p++;
atomic_inc(&gparts_i[pid].num_interacted_p2p);
#endif
}
......@@ -281,9 +281,9 @@ static INLINE void runner_dopair_grav_pp_full(
ci_cache->pot[pid] += pot;
#ifdef SWIFT_GRAVITY_FORCE_CHECKS
gparts_i[pid].a_grav_p2p[0] += a_x;
gparts_i[pid].a_grav_p2p[1] += a_y;
gparts_i[pid].a_grav_p2p[2] += a_z;
atomic_add_f(&gparts_i[pid].a_grav_p2p[0], a_x);
atomic_add_f(&gparts_i[pid].a_grav_p2p[1], a_y);
atomic_add_f(&gparts_i[pid].a_grav_p2p[2], a_z);
#endif
}
}
......@@ -426,7 +426,7 @@ static INLINE void runner_dopair_grav_pp_truncated(
#ifdef SWIFT_GRAVITY_FORCE_CHECKS
/* Update the p2p interaction counter if it's not a padded gpart */
if (pjd < gcount_j && !gpart_is_inhibited(&gparts_j[pjd], e))
gparts_i[pid].num_interacted_p2p++;
atomic_inc(&gparts_i[pid].num_interacted_p2p);
#endif
}
......@@ -437,9 +437,9 @@ static INLINE void runner_dopair_grav_pp_truncated(
ci_cache->pot[pid] += pot;
#ifdef SWIFT_GRAVITY_FORCE_CHECKS
gparts_i[pid].a_grav_p2p[0] += a_x;
gparts_i[pid].a_grav_p2p[1] += a_y;
gparts_i[pid].a_grav_p2p[2] += a_z;
atomic_add_f(&gparts_i[pid].a_grav_p2p[0], a_x);
atomic_add_f(&gparts_i[pid].a_grav_p2p[1], a_y);
atomic_add_f(&gparts_i[pid].a_grav_p2p[2], a_z);
#endif
}
}
......@@ -572,10 +572,11 @@ static INLINE void runner_dopair_grav_pm_full(
#ifdef SWIFT_GRAVITY_FORCE_CHECKS
/* Update the M2P interaction counter and forces. */
if (pid < gcount_i) {
gparts_i[pid].num_interacted_m2p += cj->grav.multipole->m_pole.num_gpart;
gparts_i[pid].a_grav_m2p[0] += f_x;
gparts_i[pid].a_grav_m2p[1] += f_y;
gparts_i[pid].a_grav_m2p[2] += f_z;
atomic_add(&gparts_i[pid].num_interacted_m2p,
cj->grav.multipole->m_pole.num_gpart);
atomic_add_f(&gparts_i[pid].a_grav_m2p[0], f_x);
atomic_add_f(&gparts_i[pid].a_grav_m2p[1], f_y);
atomic_add_f(&gparts_i[pid].a_grav_m2p[2], f_z);
}
#endif
}
......@@ -714,10 +715,11 @@ static INLINE void runner_dopair_grav_pm_truncated(
#ifdef SWIFT_GRAVITY_FORCE_CHECKS
/* Update the M2P interaction counter and forces. */
if (pid < gcount_i) {
gparts_i[pid].num_interacted_m2p += cj->grav.multipole->m_pole.num_gpart;
gparts_i[pid].a_grav_m2p[0] += f_x;
gparts_i[pid].a_grav_m2p[1] += f_y;
gparts_i[pid].a_grav_m2p[2] += f_z;
atomic_add(&gparts_i[pid].num_interacted_m2p,
cj->grav.multipole->m_pole.num_gpart);
atomic_add_f(&gparts_i[pid].a_grav_m2p[0], f_x);
atomic_add_f(&gparts_i[pid].a_grav_m2p[1], f_y);
atomic_add_f(&gparts_i[pid].a_grav_m2p[2], f_z);
}
#endif
}
......@@ -1049,7 +1051,7 @@ static INLINE void runner_doself_grav_pp_full(
#ifdef SWIFT_GRAVITY_FORCE_CHECKS
/* Update the P2P interaction counter if it's not a padded gpart */
if (pjd < gcount && !gpart_is_inhibited(&gparts[pjd], e))
gparts[pid].num_interacted_p2p++;
atomic_inc(&gparts[pid].num_interacted_p2p);
#endif
}
......@@ -1060,9 +1062,9 @@ static INLINE void runner_doself_grav_pp_full(
ci_cache->pot[pid] += pot;
#ifdef SWIFT_GRAVITY_FORCE_CHECKS
gparts[pid].a_grav_p2p[0] += a_x;
gparts[pid].a_grav_p2p[1] += a_y;
gparts[pid].a_grav_p2p[2] += a_z;
atomic_add_f(&gparts[pid].a_grav_p2p[0], a_x);
atomic_add_f(&gparts[pid].a_grav_p2p[1], a_y);
atomic_add_f(&gparts[pid].a_grav_p2p[2], a_z);
#endif
}
}
......@@ -1188,7 +1190,7 @@ static INLINE void runner_doself_grav_pp_truncated(
#ifdef SWIFT_GRAVITY_FORCE_CHECKS
/* Update the P2P interaction counter if it's not a padded gpart */
if (pjd < gcount && !gpart_is_inhibited(&gparts[pjd], e))
gparts[pid].num_interacted_p2p++;
atomic_inc(&gparts[pid].num_interacted_p2p);
#endif
}
......@@ -1199,9 +1201,9 @@ static INLINE void runner_doself_grav_pp_truncated(
ci_cache->pot[pid] += pot;
#ifdef SWIFT_GRAVITY_FORCE_CHECKS
gparts[pid].a_grav_p2p[0] += a_x;
gparts[pid].a_grav_p2p[1] += a_y;
gparts[pid].a_grav_p2p[2] += a_z;
atomic_add_f(&gparts[pid].a_grav_p2p[0], a_x);
atomic_add_f(&gparts[pid].a_grav_p2p[1], a_y);
atomic_add_f(&gparts[pid].a_grav_p2p[2], a_z);
#endif
}
}
......@@ -1676,9 +1678,9 @@ void runner_dopair_recursive_grav(struct runner *r, struct cell *ci,
#ifdef SWIFT_GRAVITY_FORCE_CHECKS
/* Need to account for the interactions we missed */
if (cell_is_active_gravity(ci, e))
multi_i->pot.num_interacted_pm += multi_j->m_pole.num_gpart;
atomic_add(&multi_i->pot.num_interacted_pm, multi_j->m_pole.num_gpart);
if (cell_is_active_gravity(cj, e))
multi_j->pot.num_interacted_pm += multi_i->m_pole.num_gpart;
atomic_add(&multi_j->pot.num_interacted_pm, multi_i->m_pole.num_gpart);
#endif
return;
}
......@@ -1889,7 +1891,7 @@ void runner_do_grav_long_range(struct runner *r, struct cell *ci, int timer) {
#ifdef SWIFT_GRAVITY_FORCE_CHECKS
/* Need to account for the interactions we missed */
multi_i->pot.num_interacted_pm += multi_j->m_pole.num_gpart;
atomic_add(&multi_i->pot.num_interacted_pm, multi_j->m_pole.num_gpart);
#endif
/* Record that this multipole received a contribution */
......
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