diff --git a/src/engine.c b/src/engine.c index 1ff7a7d46b7d3abe482a90875c0b8d7219ee506b..443be97cb4adf53051523a7a8f8af750f477da33 100644 --- a/src/engine.c +++ b/src/engine.c @@ -2253,16 +2253,18 @@ void engine_rebuild(struct engine *e) { * @brief Prepare the #engine by re-building the cells and tasks. * * @param e The #engine to prepare. - * @param nodrift Whether to drift particles before rebuilding or not. Will + * @param drift_all Whether to drift particles before rebuilding or not. Will * not be necessary if all particles have already been * drifted (before repartitioning for instance). + * @param deferskip Whether to defer the skip until after the rebuild. + * Needed after a repartition. */ -void engine_prepare(struct engine *e, int nodrift) { +void engine_prepare(struct engine *e, int drift_all, int deferskip) { TIMER_TIC; /* Unskip active tasks and check for rebuild */ - engine_unskip(e); + if (!deferskip) engine_unskip(e); /* Run through the tasks and mark as skip or not. */ int rebuild = e->forcerebuild; @@ -2280,7 +2282,7 @@ void engine_prepare(struct engine *e, int nodrift) { if (rebuild) { /* Drift all particles to the current time if needed. */ - if (!nodrift) engine_drift_all(e); + if (drift_all) engine_drift_all(e); #ifdef SWIFT_DEBUG_CHECKS /* Check that all cells have been drifted to the current time */ @@ -2289,6 +2291,7 @@ void engine_prepare(struct engine *e, int nodrift) { engine_rebuild(e); } + if (deferskip) engine_unskip(e); /* Re-rank the tasks every now and then. */ if (e->tasks_age % engine_tasksreweight == 1) { @@ -2566,7 +2569,7 @@ void engine_init_particles(struct engine *e, int flag_entropy_ICs) { if (e->nodeID == 0) message("Running initialisation fake time-step."); - engine_prepare(e, 1); + engine_prepare(e, 0, 0); engine_marktasks(e); @@ -2671,7 +2674,7 @@ void engine_step(struct engine *e) { if (repart) engine_repartition(e); /* Prepare the space. */ - engine_prepare(e, (drift_all || repart)); + engine_prepare(e, !(drift_all || repart), repart); if (e->verbose) engine_print_task_counts(e); diff --git a/src/engine.h b/src/engine.h index 5d72c23cda0101d99f318d44c925f5f3dec87173..87c2ea0a94058fe5a0af39c0eb02a72676d0794c 100644 --- a/src/engine.h +++ b/src/engine.h @@ -228,7 +228,7 @@ void engine_init(struct engine *e, struct space *s, const struct cooling_function_data *cooling, struct sourceterms *sourceterms); void engine_launch(struct engine *e, int nr_runners); -void engine_prepare(struct engine *e, int nodrift); +void engine_prepare(struct engine *e, int drift_all, int deferskip); void engine_print(struct engine *e); void engine_init_particles(struct engine *e, int flag_entropy_ICs); void engine_step(struct engine *e);