diff --git a/src/cell.c b/src/cell.c index 8728f32cb04f2f1de389386b632371a27d523bb9..d246a0b0cef09494829b453c8d861d74c445ae53 100644 --- a/src/cell.c +++ b/src/cell.c @@ -892,3 +892,79 @@ int cell_is_drift_needed(struct cell *c, int ti_current) { /* No neighbouring cell has active particles. Drift not necessary */ return 0; } + +/** + * @brief Un-skips all the tasks associated with a given cell and checks + * if the space needs to be rebuilt. + * + * @param c the #cell. + * + * @return 1 If the space needs rebuilding. 0 otherwise. + */ +int cell_unskip_tasks(struct cell *c) { + + /* Un-skip the density tasks involved with this cell. */ + for (struct link *l = c->density; l != NULL; l = l->next) { + struct task *t = l->t; + const struct cell *ci = t->ci; + const struct cell *cj = t->cj; + t->skip = 0; + + /* Set the correct sorting flags */ + if (t->type == task_type_pair) { + if (!(ci->sorted & (1 << t->flags))) { + atomic_or(&ci->sorts->flags, (1 << t->flags)); + ci->sorts->skip = 0; + } + if (!(cj->sorted & (1 << t->flags))) { + atomic_or(&cj->sorts->flags, (1 << t->flags)); + cj->sorts->skip = 0; + } + } + + /* Check whether there was too much particle motion */ + if (t->type == task_type_pair || t->type == task_type_sub_pair) { + if (t->tight && + (max(ci->h_max, cj->h_max) + ci->dx_max + cj->dx_max > cj->dmin || + ci->dx_max > space_maxreldx * ci->h_max || + cj->dx_max > space_maxreldx * cj->h_max)) + return 1; + +#ifdef WITH_MPI + /* Activate the recv tasks. */ + if (ci->nodeID != engine_rank) { + if (ci->recv_xv != NULL) ci->recv_xv->skip = 0; + if (ci->recv_rho != NULL) ci->recv_rho->skip = 0; + if (ci->recv_gradient != NULL) ci->recv_gradient->skip = 0; + if (ci->recv_ti != NULL) ci->recv_ti->skip = 0; + } else if (cj->nodeID != engine_rank) { + if (cj->recv_xv != NULL) cj->recv_xv->skip = 0; + if (cj->recv_rho != NULL) cj->recv_rho->skip = 0; + if (cj->recv_gradient != NULL) cj->recv_gradient->skip = 0; + if (cj->recv_ti != NULL) cj->recv_ti->skip = 0; + } +#endif + } + } + + /* Unskip all the other task types. */ + for (struct link *l = c->gradient; l != NULL; l = l->next) l->t->skip = 0; + for (struct link *l = c->force; l != NULL; l = l->next) l->t->skip = 0; + for (struct link *l = c->grav; l != NULL; l = l->next) l->t->skip = 0; +#ifdef WITH_MPI + for (struct link *l = c->send_xv; l != NULL; l = l->next) l->t->skip = 0; + for (struct link *l = c->send_rho; l != NULL; l = l->next) l->t->skip = 0; + for (struct link *l = c->send_gradient; l != NULL; l = l->next) + l->t->skip = 0; + for (struct link *l = c->send_ti; l != NULL; l = l->next) l->t->skip = 0; +#endif + if (c->extra_ghost != NULL) c->extra_ghost->skip = 0; + if (c->ghost != NULL) c->ghost->skip = 0; + if (c->init != NULL) c->init->skip = 0; + if (c->kick != NULL) c->kick->skip = 0; + if (c->cooling != NULL) c->cooling->skip = 0; + if (c->sourceterms != NULL) c->sourceterms->skip = 0; + if (c->grav_external != NULL) c->grav_external->skip = 0; + + return 0; +} diff --git a/src/cell.h b/src/cell.h index f87420c86c5765f42fe04e8dee95558edff90cf9..289a68e5456eb2f6d1917de65170aa590c37e0a4 100644 --- a/src/cell.h +++ b/src/cell.h @@ -240,5 +240,6 @@ int cell_are_neighbours(const struct cell *restrict ci, void cell_check_multipole(struct cell *c, void *data); void cell_clean(struct cell *c); int cell_is_drift_needed(struct cell *c, int ti_current); +int cell_unskip_tasks(struct cell *c); #endif /* SWIFT_CELL_H */ diff --git a/src/engine.c b/src/engine.c index cee11667f18ed28aff7bbd2e6fd7038c16fbd105..e42a785a13abc04241a27f89a87ce4b82eee563f 100644 --- a/src/engine.c +++ b/src/engine.c @@ -2800,8 +2800,6 @@ void engine_step(struct engine *e) { submask |= 1 << task_subtype_tend; } - engine_print_task_counts(e); - if (e->verbose) engine_print_task_counts(e); /* Send off the runners. */ diff --git a/src/runner.c b/src/runner.c index eba7b2b93e2d1884736fb9107406a98a4668c71d..410458fadb91886ba7492418a40db75f1dc6c4e3 100644 --- a/src/runner.c +++ b/src/runner.c @@ -765,6 +765,9 @@ static void runner_do_drift(struct cell *c, struct engine *e) { c->updated = 0; c->g_updated = 0; + /* Should we abort as a rebuild has been triggered ? */ + if (e->forcerebuild) return; + /* Do we need to drift ? */ if (!e->drift_all && !cell_is_drift_needed(c, ti_current)) return; @@ -907,59 +910,13 @@ static void runner_do_drift(struct cell *c, struct engine *e) { /* Update the time of the last drift */ c->ti_old = ti_current; - /* Do we have at least one active particle in the cell ?*/ - if (c->ti_end_min > ti_current) return; + /* Now let's un-skip the tasks associated with this active cell */ + if (c->ti_end_min == ti_current) { - /* Un-skip the density tasks involved with this cell. */ - for (struct link *l = c->density; l != NULL; l = l->next) { - struct task *t = l->t; - const struct cell *ci = t->ci; - const struct cell *cj = t->cj; - t->skip = 0; - if (t->type == task_type_pair) { - if (!(ci->sorted & (1 << t->flags))) { - atomic_or(&ci->sorts->flags, (1 << t->flags)); - ci->sorts->skip = 0; - } - if (!(cj->sorted & (1 << t->flags))) { - atomic_or(&cj->sorts->flags, (1 << t->flags)); - cj->sorts->skip = 0; - } - } - if (t->type == task_type_pair || t->type == task_type_sub_pair) { - if (t->tight && - (max(ci->h_max, cj->h_max) + ci->dx_max + cj->dx_max > cj->dmin || - ci->dx_max > space_maxreldx * ci->h_max || - cj->dx_max > space_maxreldx * cj->h_max)) - e->forcerebuild = 1; -#ifdef WITH_MPI - /* Activate the recv tasks. */ - if (ci->nodeID != engine_rank) { - if (ci->recv_xv != NULL) ci->recv_xv->skip = 0; - if (ci->recv_rho != NULL) ci->recv_rho->skip = 0; - if (ci->recv_ti != NULL) ci->recv_ti->skip = 0; - } else if (cj->nodeID != engine_rank) { - if (cj->recv_xv != NULL) cj->recv_xv->skip = 0; - if (cj->recv_rho != NULL) cj->recv_rho->skip = 0; - if (cj->recv_ti != NULL) cj->recv_ti->skip = 0; - } -#endif - } - } + const int forcerebuild = cell_unskip_tasks(c); - /* Unskip all the other task types. */ - for (struct link *l = c->gradient; l != NULL; l = l->next) l->t->skip = 0; - for (struct link *l = c->force; l != NULL; l = l->next) l->t->skip = 0; - for (struct link *l = c->grav; l != NULL; l = l->next) l->t->skip = 0; -#ifdef WITH_MPI - for (struct link *l = c->send_xv; l != NULL; l = l->next) l->t->skip = 0; - for (struct link *l = c->send_rho; l != NULL; l = l->next) l->t->skip = 0; - for (struct link *l = c->send_ti; l != NULL; l = l->next) l->t->skip = 0; -#endif - if (c->extra_ghost != NULL) c->extra_ghost->skip = 0; - if (c->ghost != NULL) c->ghost->skip = 0; - if (c->init != NULL) c->init->skip = 0; - if (c->kick != NULL) c->kick->skip = 0; + if (forcerebuild) atomic_inc(&e->forcerebuild); + } } /**