diff --git a/src/cell.c b/src/cell.c index c694ef9abff1dd183ec135765b3d227f55116ead..640a87cc64d76993859be589a6bc5e5032556029 100644 --- a/src/cell.c +++ b/src/cell.c @@ -763,6 +763,9 @@ void cell_clean_links(struct cell *c, void *data) { c->force = NULL; c->nr_force = 0; + + c->grav = NULL; + c->nr_grav = 0; } /** diff --git a/src/cell.h b/src/cell.h index 576d2db695720b3aa1b49b89128496a7ca12a6bb..104b74312890e2fd7e2f31c5bae85deb893da0d2 100644 --- a/src/cell.h +++ b/src/cell.h @@ -157,9 +157,6 @@ struct cell { /* Tasks for gravity tree. */ struct task *grav_up, *grav_down; - /* Task for external gravity */ - struct task *grav_external; - /* Task for cooling */ struct task *cooling; diff --git a/src/engine.c b/src/engine.c index caaa54574b4d279361aa8adabdba13dc39a576f0..d61dcd0b97de87d4102f1e658c42b03e2b9b6a21 100644 --- a/src/engine.c +++ b/src/engine.c @@ -1248,7 +1248,7 @@ void engine_make_external_gravity_tasks(struct engine *e) { /* Is that neighbour local ? */ if (ci->nodeID != nodeID) continue; - /* If the cells is local build a self-interaction */ + /* If the cell is local build a self-interaction */ scheduler_addtask(sched, task_type_self, task_subtype_external_grav, 0, 0, ci, NULL, 0); } @@ -1329,59 +1329,104 @@ void engine_make_hydroloop_tasks(struct engine *e) { /** * @brief Counts the tasks associated with one cell and constructs the links * - * For each hydrodynamic task, construct the links with the corresponding cell. - * Similarly, construct the dependencies for all the sorting tasks. + * For each hydrodynamic and gravity task, construct the links with + * the corresponding cell. Similarly, construct the dependencies for + * all the sorting tasks. * * @param e The #engine. */ void engine_count_and_link_tasks(struct engine *e) { - struct scheduler *sched = &e->sched; + struct scheduler *const sched = &e->sched; + const int nr_tasks = sched->nr_tasks; - for (int ind = 0; ind < sched->nr_tasks; ind++) { + for (int ind = 0; ind < nr_tasks; ind++) { - struct task *t = &sched->tasks[ind]; + struct task *const t = &sched->tasks[ind]; + struct cell *const ci = t->ci; + struct cell *const cj = t->cj; if (t->skip) continue; /* Link sort tasks together. */ - if (t->type == task_type_sort && t->ci->split) + if (t->type == task_type_sort && ci->split) for (int j = 0; j < 8; j++) - if (t->ci->progeny[j] != NULL && t->ci->progeny[j]->sorts != NULL) { - t->ci->progeny[j]->sorts->skip = 0; - scheduler_addunlock(sched, t->ci->progeny[j]->sorts, t); + if (ci->progeny[j] != NULL && ci->progeny[j]->sorts != NULL) { + ci->progeny[j]->sorts->skip = 0; + scheduler_addunlock(sched, ci->progeny[j]->sorts, t); } - /* Link density tasks to cells. */ + /* Link self tasks to cells. */ if (t->type == task_type_self) { - atomic_inc(&t->ci->nr_tasks); + atomic_inc(&ci->nr_tasks); if (t->subtype == task_subtype_density) { - engine_addlink(e, &t->ci->density, t); - atomic_inc(&t->ci->nr_density); + engine_addlink(e, &ci->density, t); + atomic_inc(&ci->nr_density); + } + if (t->subtype == task_subtype_grav) { + engine_addlink(e, &ci->grav, t); + atomic_inc(&ci->nr_grav); } + if (t->subtype == task_subtype_external_grav) { + engine_addlink(e, &ci->grav, t); + atomic_inc(&ci->nr_grav); + } + + /* Link pair tasks to cells. */ } else if (t->type == task_type_pair) { - atomic_inc(&t->ci->nr_tasks); - atomic_inc(&t->cj->nr_tasks); + atomic_inc(&ci->nr_tasks); + atomic_inc(&cj->nr_tasks); if (t->subtype == task_subtype_density) { - engine_addlink(e, &t->ci->density, t); - atomic_inc(&t->ci->nr_density); - engine_addlink(e, &t->cj->density, t); - atomic_inc(&t->cj->nr_density); + engine_addlink(e, &ci->density, t); + atomic_inc(&ci->nr_density); + engine_addlink(e, &cj->density, t); + atomic_inc(&cj->nr_density); } + if (t->subtype == task_subtype_grav) { + engine_addlink(e, &ci->grav, t); + atomic_inc(&ci->nr_grav); + engine_addlink(e, &cj->grav, t); + atomic_inc(&cj->nr_grav); + } + + /* Link sub-self tasks to cells. */ } else if (t->type == task_type_sub_self) { - atomic_inc(&t->ci->nr_tasks); + atomic_inc(&ci->nr_tasks); if (t->subtype == task_subtype_density) { - engine_addlink(e, &t->ci->density, t); - atomic_inc(&t->ci->nr_density); + engine_addlink(e, &ci->density, t); + atomic_inc(&ci->nr_density); + } + if (t->subtype == task_subtype_grav) { + engine_addlink(e, &ci->grav, t); + atomic_inc(&ci->nr_grav); + } + if (t->subtype == task_subtype_external_grav) { + engine_addlink(e, &ci->grav, t); + atomic_inc(&ci->nr_grav); } + + /* Link sub-pair tasks to cells. */ } else if (t->type == task_type_sub_pair) { - atomic_inc(&t->ci->nr_tasks); - atomic_inc(&t->cj->nr_tasks); + atomic_inc(&ci->nr_tasks); + atomic_inc(&cj->nr_tasks); if (t->subtype == task_subtype_density) { - engine_addlink(e, &t->ci->density, t); - atomic_inc(&t->ci->nr_density); - engine_addlink(e, &t->cj->density, t); - atomic_inc(&t->cj->nr_density); + engine_addlink(e, &ci->density, t); + atomic_inc(&ci->nr_density); + engine_addlink(e, &cj->density, t); + atomic_inc(&cj->nr_density); + } + if (t->subtype == task_subtype_grav) { + engine_addlink(e, &ci->grav, t); + atomic_inc(&ci->nr_grav); + engine_addlink(e, &cj->grav, t); + atomic_inc(&cj->nr_grav); + } + if (t->subtype == task_subtype_external_grav) { + error("Found a sub-pair/external-gravity task..."); + engine_addlink(e, &ci->grav, t); + atomic_inc(&ci->nr_grav); + engine_addlink(e, &cj->grav, t); + atomic_inc(&cj->nr_grav); } } } @@ -1873,14 +1918,16 @@ void engine_maketasks(struct engine *e) { /* Split the tasks. */ scheduler_splittasks(sched); - /* Allocate the list of cell-task links. The maximum number of links - is the number of cells (s->tot_cells) times the number of neighbours (27) - times the number of interaction types (2, density and force). */ + /* Allocate the list of cell-task links. The maximum number of links is the + * number of cells (s->tot_cells) times the number of neighbours (26) times + * the number of interaction types, so 26 * 3 (density, force, grav) pairs + * and 4 (density, force, grav, ext_grav) self. + */ if (e->links != NULL) free(e->links); #ifdef EXTRA_HYDRO_LOOP - e->size_links = s->tot_cells * 27 * 3; + e->size_links = s->tot_cells * (26 * 4 + 4); #else - e->size_links = s->tot_cells * 27 * 2; + e->size_links = s->tot_cells * (26 * 3 + 4); #endif if ((e->links = malloc(sizeof(struct link) * e->size_links)) == NULL) error("Failed to allocate cell-task links."); diff --git a/src/space.c b/src/space.c index ed7ee5ef5715be67d0de44599d291a9a678a0f96..b7cf7b0b552682ce8f3370a4d85f647302817199 100644 --- a/src/space.c +++ b/src/space.c @@ -395,6 +395,7 @@ void space_regrid(struct space *s, double cell_max, int verbose) { s->cells_top[k].nr_density = 0; s->cells_top[k].nr_gradient = 0; s->cells_top[k].nr_force = 0; + s->cells_top[k].nr_grav = 0; s->cells_top[k].density = NULL; s->cells_top[k].gradient = NULL; s->cells_top[k].force = NULL; @@ -587,8 +588,7 @@ void space_rebuild(struct space *s, double cell_max, int verbose) { for (size_t k = 1; k < nr_parts; k++) { if (ind[k - 1] > ind[k]) { error("Sort failed!"); - } else if (ind[k] != cell_getid(s->cdim, - s->parts[k].x[0] * s->iwidth[0], + } else if (ind[k] != cell_getid(s->cdim, s->parts[k].x[0] * s->iwidth[0], s->parts[k].x[1] * s->iwidth[1], s->parts[k].x[2] * s->iwidth[2])) { error("Incorrect indices!");