Commit cd34c3b6 authored by Peter W. Draper's avatar Peter W. Draper
Browse files

Merge branch 'gravity-links' into 'master'

Add cell links for gravity tasks

Add links for gravity tasks so that we can discover these from cells.

Also expunge external_gravity from cell.h.

See merge request !268
parents 0890b7d7 59d5eb87
...@@ -763,6 +763,9 @@ void cell_clean_links(struct cell *c, void *data) { ...@@ -763,6 +763,9 @@ void cell_clean_links(struct cell *c, void *data) {
c->force = NULL; c->force = NULL;
c->nr_force = 0; c->nr_force = 0;
c->grav = NULL;
c->nr_grav = 0;
} }
/** /**
......
...@@ -157,9 +157,6 @@ struct cell { ...@@ -157,9 +157,6 @@ struct cell {
/* Tasks for gravity tree. */ /* Tasks for gravity tree. */
struct task *grav_up, *grav_down; struct task *grav_up, *grav_down;
/* Task for external gravity */
struct task *grav_external;
/* Task for cooling */ /* Task for cooling */
struct task *cooling; struct task *cooling;
......
...@@ -1248,7 +1248,7 @@ void engine_make_external_gravity_tasks(struct engine *e) { ...@@ -1248,7 +1248,7 @@ void engine_make_external_gravity_tasks(struct engine *e) {
/* Is that neighbour local ? */ /* Is that neighbour local ? */
if (ci->nodeID != nodeID) continue; 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, scheduler_addtask(sched, task_type_self, task_subtype_external_grav, 0, 0,
ci, NULL, 0); ci, NULL, 0);
} }
...@@ -1329,59 +1329,104 @@ void engine_make_hydroloop_tasks(struct engine *e) { ...@@ -1329,59 +1329,104 @@ void engine_make_hydroloop_tasks(struct engine *e) {
/** /**
* @brief Counts the tasks associated with one cell and constructs the links * @brief Counts the tasks associated with one cell and constructs the links
* *
* For each hydrodynamic task, construct the links with the corresponding cell. * For each hydrodynamic and gravity task, construct the links with
* Similarly, construct the dependencies for all the sorting tasks. * the corresponding cell. Similarly, construct the dependencies for
* all the sorting tasks.
* *
* @param e The #engine. * @param e The #engine.
*/ */
void engine_count_and_link_tasks(struct engine *e) { 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; if (t->skip) continue;
/* Link sort tasks together. */ /* 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++) for (int j = 0; j < 8; j++)
if (t->ci->progeny[j] != NULL && t->ci->progeny[j]->sorts != NULL) { if (ci->progeny[j] != NULL && ci->progeny[j]->sorts != NULL) {
t->ci->progeny[j]->sorts->skip = 0; ci->progeny[j]->sorts->skip = 0;
scheduler_addunlock(sched, t->ci->progeny[j]->sorts, t); scheduler_addunlock(sched, ci->progeny[j]->sorts, t);
} }
/* Link density tasks to cells. */ /* Link self tasks to cells. */
if (t->type == task_type_self) { if (t->type == task_type_self) {
atomic_inc(&t->ci->nr_tasks); atomic_inc(&ci->nr_tasks);
if (t->subtype == task_subtype_density) { if (t->subtype == task_subtype_density) {
engine_addlink(e, &t->ci->density, t); engine_addlink(e, &ci->density, t);
atomic_inc(&t->ci->nr_density); 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) { } else if (t->type == task_type_pair) {
atomic_inc(&t->ci->nr_tasks); atomic_inc(&ci->nr_tasks);
atomic_inc(&t->cj->nr_tasks); atomic_inc(&cj->nr_tasks);
if (t->subtype == task_subtype_density) { if (t->subtype == task_subtype_density) {
engine_addlink(e, &t->ci->density, t); engine_addlink(e, &ci->density, t);
atomic_inc(&t->ci->nr_density); atomic_inc(&ci->nr_density);
engine_addlink(e, &t->cj->density, t); engine_addlink(e, &cj->density, t);
atomic_inc(&t->cj->nr_density); 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) { } 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) { if (t->subtype == task_subtype_density) {
engine_addlink(e, &t->ci->density, t); engine_addlink(e, &ci->density, t);
atomic_inc(&t->ci->nr_density); 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) { } else if (t->type == task_type_sub_pair) {
atomic_inc(&t->ci->nr_tasks); atomic_inc(&ci->nr_tasks);
atomic_inc(&t->cj->nr_tasks); atomic_inc(&cj->nr_tasks);
if (t->subtype == task_subtype_density) { if (t->subtype == task_subtype_density) {
engine_addlink(e, &t->ci->density, t); engine_addlink(e, &ci->density, t);
atomic_inc(&t->ci->nr_density); atomic_inc(&ci->nr_density);
engine_addlink(e, &t->cj->density, t); engine_addlink(e, &cj->density, t);
atomic_inc(&t->cj->nr_density); 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) { ...@@ -1873,14 +1918,16 @@ void engine_maketasks(struct engine *e) {
/* Split the tasks. */ /* Split the tasks. */
scheduler_splittasks(sched); scheduler_splittasks(sched);
/* Allocate the list of cell-task links. The maximum number of links /* Allocate the list of cell-task links. The maximum number of links is the
is the number of cells (s->tot_cells) times the number of neighbours (27) * number of cells (s->tot_cells) times the number of neighbours (26) times
times the number of interaction types (2, density and force). */ * 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); if (e->links != NULL) free(e->links);
#ifdef EXTRA_HYDRO_LOOP #ifdef EXTRA_HYDRO_LOOP
e->size_links = s->tot_cells * 27 * 3; e->size_links = s->tot_cells * (26 * 4 + 4);
#else #else
e->size_links = s->tot_cells * 27 * 2; e->size_links = s->tot_cells * (26 * 3 + 4);
#endif #endif
if ((e->links = malloc(sizeof(struct link) * e->size_links)) == NULL) if ((e->links = malloc(sizeof(struct link) * e->size_links)) == NULL)
error("Failed to allocate cell-task links."); error("Failed to allocate cell-task links.");
......
...@@ -395,6 +395,7 @@ void space_regrid(struct space *s, double cell_max, int verbose) { ...@@ -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_density = 0;
s->cells_top[k].nr_gradient = 0; s->cells_top[k].nr_gradient = 0;
s->cells_top[k].nr_force = 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].density = NULL;
s->cells_top[k].gradient = NULL; s->cells_top[k].gradient = NULL;
s->cells_top[k].force = NULL; s->cells_top[k].force = NULL;
...@@ -587,8 +588,7 @@ void space_rebuild(struct space *s, double cell_max, int verbose) { ...@@ -587,8 +588,7 @@ void space_rebuild(struct space *s, double cell_max, int verbose) {
for (size_t k = 1; k < nr_parts; k++) { for (size_t k = 1; k < nr_parts; k++) {
if (ind[k - 1] > ind[k]) { if (ind[k - 1] > ind[k]) {
error("Sort failed!"); error("Sort failed!");
} else if (ind[k] != cell_getid(s->cdim, } else if (ind[k] != cell_getid(s->cdim, s->parts[k].x[0] * s->iwidth[0],
s->parts[k].x[0] * s->iwidth[0],
s->parts[k].x[1] * s->iwidth[1], s->parts[k].x[1] * s->iwidth[1],
s->parts[k].x[2] * s->iwidth[2])) { s->parts[k].x[2] * s->iwidth[2])) {
error("Incorrect indices!"); error("Incorrect indices!");
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment