Commit 8dcd4ac0 authored by Matthieu Schaller's avatar Matthieu Schaller
Browse files

Merge branch 'lock_before_removing_particles' into 'master'

Lock before removing particles

See merge request !858
parents 06c31aa4 5bd48e07
......@@ -4332,23 +4332,34 @@ void cell_drift_part(struct cell *c, const struct engine *e, int force) {
/* In non-periodic BC runs, remove particles that crossed the border */
if (!periodic) {
/* Did the particle leave the box? */
if ((p->x[0] > dim[0]) || (p->x[0] < 0.) || // x
(p->x[1] > dim[1]) || (p->x[1] < 0.) || // y
(p->x[2] > dim[2]) || (p->x[2] < 0.)) { // z
/* One last action before death? */
hydro_remove_part(p, xp);
lock_lock(&e->s->lock);
/* Remove the particle entirely */
struct gpart *gp = p->gpart;
cell_remove_part(e, c, p, xp);
/* Re-check that the particle has not been removed
* by another thread before we do the deed. */
if (!part_is_inhibited(p, e)) {
/* and it's gravity friend */
if (gp != NULL) {
cell_remove_gpart(e, c, gp);
/* One last action before death? */
hydro_remove_part(p, xp);
/* Remove the particle entirely */
struct gpart *gp = p->gpart;
cell_remove_part(e, c, p, xp);
/* and it's gravity friend */
if (gp != NULL) {
cell_remove_gpart(e, c, gp);
}
}
if (lock_unlock(&e->s->lock) != 0)
error("Failed to unlock the space!");
continue;
}
}
......@@ -4492,13 +4503,24 @@ void cell_drift_gpart(struct cell *c, const struct engine *e, int force) {
/* In non-periodic BC runs, remove particles that crossed the border */
if (!periodic) {
/* Did the particle leave the box? */
if ((gp->x[0] > dim[0]) || (gp->x[0] < 0.) || // x
(gp->x[1] > dim[1]) || (gp->x[1] < 0.) || // y
(gp->x[2] > dim[2]) || (gp->x[2] < 0.)) { // z
/* Remove the particle entirely */
cell_remove_gpart(e, c, gp);
lock_lock(&e->s->lock);
/* Re-check that the particle has not been removed
* by another thread before we do the deed. */
if (!gpart_is_inhibited(gp, e)) {
/* Remove the particle entirely */
cell_remove_gpart(e, c, gp);
}
if (lock_unlock(&e->s->lock) != 0)
error("Failed to unlock the space!");
continue;
}
......@@ -4622,17 +4644,28 @@ void cell_drift_spart(struct cell *c, const struct engine *e, int force) {
/* In non-periodic BC runs, remove particles that crossed the border */
if (!periodic) {
/* Did the particle leave the box? */
if ((sp->x[0] > dim[0]) || (sp->x[0] < 0.) || // x
(sp->x[1] > dim[1]) || (sp->x[1] < 0.) || // y
(sp->x[2] > dim[2]) || (sp->x[2] < 0.)) { // z
/* Remove the particle entirely */
struct gpart *gp = sp->gpart;
cell_remove_spart(e, c, sp);
lock_lock(&e->s->lock);
/* Re-check that the particle has not been removed
* by another thread before we do the deed. */
if (!spart_is_inhibited(sp, e)) {
/* Remove the particle entirely */
struct gpart *gp = sp->gpart;
cell_remove_spart(e, c, sp);
/* and it's gravity friend */
cell_remove_gpart(e, c, gp);
}
/* and it's gravity friend */
cell_remove_gpart(e, c, gp);
if (lock_unlock(&e->s->lock) != 0)
error("Failed to unlock the space!");
continue;
}
......@@ -4792,12 +4825,22 @@ void cell_drift_bpart(struct cell *c, const struct engine *e, int force) {
(bp->x[1] > dim[1]) || (bp->x[1] < 0.) || // y
(bp->x[2] > dim[2]) || (bp->x[2] < 0.)) { // z
/* Remove the particle entirely */
struct gpart *gp = bp->gpart;
cell_remove_bpart(e, c, bp);
lock_lock(&e->s->lock);
/* Re-check that the particle has not been removed
* by another thread before we do the deed. */
if (!bpart_is_inhibited(bp, e)) {
/* Remove the particle entirely */
struct gpart *gp = bp->gpart;
cell_remove_bpart(e, c, bp);
/* and it's gravity friend */
cell_remove_gpart(e, c, gp);
}
/* and it's gravity friend */
cell_remove_gpart(e, c, gp);
if (lock_unlock(&e->s->lock) != 0)
error("Failed to unlock the space!");
continue;
}
......
......@@ -3820,10 +3820,20 @@ void runner_do_swallow(struct runner *r, struct cell *c, int timer) {
message("BH %lld removing particle %lld", bp->id, p->id);
/* Finally, remove the gas particle from the system */
struct gpart *gp = p->gpart;
cell_remove_part(e, c, p, xp);
cell_remove_gpart(e, c, gp);
lock_lock(&e->s->lock);
/* Re-check that the particle has not been removed
* by another thread before we do the deed. */
if (!part_is_inhibited(p, e)) {
/* Finally, remove the gas particle from the system */
struct gpart *gp = p->gpart;
cell_remove_part(e, c, p, xp);
cell_remove_gpart(e, c, gp);
}
if (lock_unlock(&e->s->lock) != 0)
error("Failed to unlock the space!");
}
/* In any case, prevent the particle from being re-swallowed */
......@@ -3853,10 +3863,20 @@ void runner_do_swallow(struct runner *r, struct cell *c, int timer) {
message("BH %lld removing particle %lld (foreign BH case)",
bp->id, p->id);
/* Finally, remove the gas particle from the system */
struct gpart *gp = p->gpart;
cell_remove_part(e, c, p, xp);
cell_remove_gpart(e, c, gp);
lock_lock(&e->s->lock);
/* Re-check that the particle has not been removed
* by another thread before we do the deed. */
if (!part_is_inhibited(p, e)) {
/* Finally, remove the gas particle from the system */
struct gpart *gp = p->gpart;
cell_remove_part(e, c, p, xp);
cell_remove_gpart(e, c, gp);
}
if (lock_unlock(&e->s->lock) != 0)
error("Failed to unlock the space!");
found = 1;
break;
......
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