diff --git a/src/cell.c b/src/cell.c index 4e55906eb36a9b73399609055a31a90a240af9c0..33fad78ccc6ed3e1ab10beff81afb95a96d8e7ff 100644 --- a/src/cell.c +++ b/src/cell.c @@ -3725,7 +3725,7 @@ void cell_recursively_shift_sparts(struct cell *c, c->stars.parts++; } -struct spart *cell_add_spart(const struct engine *e, struct cell *const c) { +struct spart *cell_add_spart(struct engine *e, struct cell *const c) { if (c->nodeID != engine_rank) error("Adding spart on a foreign node"); @@ -3748,8 +3748,11 @@ struct spart *cell_add_spart(const struct engine *e, struct cell *const c) { } /* Are there any extra particles left? */ - if (top->stars.count == top->stars.count_total) - error("We ran out of star particles!"); + if (top->stars.count == top->stars.count_total) { + message("We ran out of star particles!"); + atomic_inc(&e->forcerebuild); + return NULL; + } /* Number of particles to shift in order to get a free space. */ const int n_copy = &top->stars.parts[top->stars.count] - c->stars.parts; @@ -3798,10 +3801,12 @@ struct spart *cell_add_spart(const struct engine *e, struct cell *const c) { sp->time_bin = e->min_active_bin; #ifdef SWIFT_DEBUG_CHECKS + /* Specify it was drifted to this point */ sp->ti_drift = e->ti_current; #endif - e->s->nr_extra_sparts--; + /* Register that we used one of the free slots. */ + atomic_dec(&e->s->nr_extra_sparts); return sp; } diff --git a/src/cell.h b/src/cell.h index 9fd4158a6ef485d02bc2d5e407f885e3f488a7d5..11699a2ce506a1e3546b492b03e4095cbf63424d 100644 --- a/src/cell.h +++ b/src/cell.h @@ -667,7 +667,7 @@ void cell_set_super_mapper(void *map_data, int num_elements, void *extra_data); void cell_check_spart_pos(const struct cell *c, const struct spart *global_sparts); int cell_has_tasks(struct cell *c); -struct spart *cell_add_spart(const struct engine *e, struct cell *c); +struct spart *cell_add_spart(struct engine *e, struct cell *c); void cell_remove_part(const struct engine *e, struct cell *c, struct part *p, struct xpart *xp); void cell_remove_gpart(const struct engine *e, struct cell *c, diff --git a/src/runner.c b/src/runner.c index 04403c95a489a69baea77201446288f2c7fbf0f7..6edb69d06e7af41e3081a6adc2e6d90a2f49b5d4 100644 --- a/src/runner.c +++ b/src/runner.c @@ -492,7 +492,7 @@ void runner_do_cooling(struct runner *r, struct cell *c, int timer) { */ void runner_do_star_formation(struct runner *r, struct cell *c, int timer) { - const struct engine *e = r->e; + struct engine *e = r->e; const struct cosmology *cosmo = e->cosmology; const int count = c->hydro.count; struct part *restrict parts = c->hydro.parts; @@ -526,12 +526,15 @@ void runner_do_star_formation(struct runner *r, struct cell *c, int timer) { message("c->cellID=%d Removing particle id=%lld rho=%e", c->cellID, p->id, rho); - /* Destroy the gas particle and get it's gpart friend */ - struct gpart *gp = cell_convert_part_to_gpart(e, c, p, xp); - /* Create a fresh (empty) spart */ struct spart *sp = cell_add_spart(e, c); + /* Did we run out of free spart slots? */ + if (sp == NULL) continue; + + /* Destroy the gas particle and get it's gpart friend */ + struct gpart *gp = cell_convert_part_to_gpart(e, c, p, xp); + /* Assign the ID back */ sp->id = gp->id_or_neg_offset; gp->type = swift_type_stars; @@ -566,13 +569,6 @@ void runner_do_star_formation(struct runner *r, struct cell *c, int timer) { } } - if (c->super == c) { -#ifdef SWIFT_DEBUG_CHECKS - /* Check that everything went OK */ - cell_check_spart_pos(c, e->s->sparts); -#endif - } - if (timer) TIMER_TOC(timer_do_star_formation); }