diff --git a/src/cell.c b/src/cell.c index e463f3d15e09e00369a529d5b3f731f8ee1ba560..688ac54f315caad75cbe2e6c37d407f9e9733086 100644 --- a/src/cell.c +++ b/src/cell.c @@ -4444,6 +4444,9 @@ struct spart *cell_add_spart(struct engine *e, struct cell *const c) { top = top->parent; } + /* Lock the top-level cell as we are going to operate on it */ + lock_lock(&top->stars.star_formation_lock); + /* Are there any extra particles left? */ if (top->stars.count == top->stars.count_total - 1) { message("We ran out of star particles!"); @@ -4481,6 +4484,19 @@ struct spart *cell_add_spart(struct engine *e, struct cell *const c) { * current cell*/ cell_recursively_shift_sparts(top, progeny, /* main_branch=*/1); + /* Make sure the gravity will be recomputed for this particle in the next step + */ + struct cell *top2 = c; + while (top2->parent != NULL) { + top2->grav.ti_end_min = e->ti_current; + top2 = top2->parent; + } + top2->grav.ti_end_min = e->ti_current; + + /* Release the lock */ + if (lock_unlock(&top->stars.star_formation_lock) != 0) + error("Failed to unlock the top-level cell."); + /* We now have an empty spart as the first particle in that cell */ struct spart *sp = &c->stars.parts[0]; bzero(sp, sizeof(struct spart)); @@ -4493,13 +4509,6 @@ struct spart *cell_add_spart(struct engine *e, struct cell *const c) { /* Set it to the current time-bin */ sp->time_bin = e->min_active_bin; - top = c; - while (top->parent != NULL) { - top->grav.ti_end_min = e->ti_current; - top = top->parent; - } - top->grav.ti_end_min = e->ti_current; - #ifdef SWIFT_DEBUG_CHECKS /* Specify it was drifted to this point */ sp->ti_drift = e->ti_current; diff --git a/src/cell.h b/src/cell.h index 9bd192384f8fb28f80b8347eb181916e54fc56af..4d751bc43b5d41037ad873a2df3acc3dc5150796 100644 --- a/src/cell.h +++ b/src/cell.h @@ -514,6 +514,9 @@ struct cell { /*! Spin lock for various uses (#spart case). */ swift_lock_type lock; + /*! Spin lock for star formation use. */ + swift_lock_type star_formation_lock; + /*! Nr of #spart in this cell. */ int count; diff --git a/src/engine.c b/src/engine.c index b35a60caccbaf42c08ecd440d6538047a0fc1fb4..8f8a5c5492e1db1d47d9b9b335499eb4a5a4c3cb 100644 --- a/src/engine.c +++ b/src/engine.c @@ -2744,7 +2744,9 @@ void engine_skip_force_and_kick(struct engine *e) { t->type == task_type_star_formation || t->type == task_type_extra_ghost || t->subtype == task_subtype_gradient || - t->subtype == task_subtype_stars_feedback) + t->subtype == task_subtype_stars_feedback || + t->subtype == task_subtype_tend || t->subtype == task_subtype_rho || + t->subtype == task_subtype_gpart) t->skip = 1; } diff --git a/src/space.c b/src/space.c index 8c41560178162da7946a95b67ea8cca49f4c2572..f92830061085dcd439e6165977f693f8f00171a4 100644 --- a/src/space.c +++ b/src/space.c @@ -548,6 +548,8 @@ void space_regrid(struct space *s, int verbose) { error("Failed to init spinlock for multipoles."); if (lock_init(&s->cells_top[k].stars.lock) != 0) error("Failed to init spinlock for stars."); + if (lock_init(&s->cells_top[k].stars.star_formation_lock) != 0) + error("Failed to init spinlock for star formation."); } /* Set the cell location and sizes. */ @@ -3100,7 +3102,8 @@ void space_recycle(struct space *s, struct cell *c) { /* Clear the cell. */ if (lock_destroy(&c->lock) != 0 || lock_destroy(&c->grav.plock) != 0 || - lock_destroy(&c->mlock) != 0 || lock_destroy(&c->stars.lock) != 0) + lock_destroy(&c->mlock) != 0 || lock_destroy(&c->stars.lock) != 0 || + lock_destroy(&c->stars.star_formation_lock)) error("Failed to destroy spinlocks."); /* Lock the space. */ @@ -3149,7 +3152,8 @@ void space_recycle_list(struct space *s, struct cell *cell_list_begin, for (struct cell *c = cell_list_begin; c != NULL; c = c->next) { /* Clear the cell. */ if (lock_destroy(&c->lock) != 0 || lock_destroy(&c->grav.plock) != 0 || - lock_destroy(&c->mlock) != 0 || lock_destroy(&c->stars.lock) != 0) + lock_destroy(&c->mlock) != 0 || lock_destroy(&c->stars.lock) != 0 || + lock_destroy(&c->stars.star_formation_lock)) error("Failed to destroy spinlocks."); /* Count this cell. */ @@ -3248,7 +3252,8 @@ void space_getcells(struct space *s, int nr_cells, struct cell **cells) { if (lock_init(&cells[j]->hydro.lock) != 0 || lock_init(&cells[j]->grav.plock) != 0 || lock_init(&cells[j]->grav.mlock) != 0 || - lock_init(&cells[j]->stars.lock) != 0) + lock_init(&cells[j]->stars.lock) != 0 || + lock_init(&cells[j]->stars.star_formation_lock) != 0) error("Failed to initialize cell spinlocks."); } }