From c1c29386ad0296ff601a1c8240fd73ffe66a096a Mon Sep 17 00:00:00 2001 From: Matthieu Schaller <schaller@strw.leidenuniv.nl> Date: Sun, 12 Aug 2018 20:41:34 +0200 Subject: [PATCH] Separeated the M-M tasks from the other gravity tasks in the cells' linked-lists. --- examples/main.c | 2 +- src/cell.c | 41 ++++++++++++++++++++++------------------- src/cell.h | 3 +++ src/engine.c | 27 +++++++++++++++------------ src/runner.c | 4 ++-- src/scheduler.c | 4 ++-- src/space.c | 1 + 7 files changed, 46 insertions(+), 36 deletions(-) diff --git a/examples/main.c b/examples/main.c index eaeb597a12..7a45dc1d94 100644 --- a/examples/main.c +++ b/examples/main.c @@ -893,7 +893,7 @@ int main(int argc, char *argv[]) { "from t=%.3e until t=%.3e with %d ranks, %d threads / rank and %d " "task queues / rank (dt_min=%.3e, dt_max=%.3e)...", e.time_begin, e.time_end, nr_nodes, e.nr_threads, e.sched.nr_queues, - e.dt_min, e.dt_max); + e.dt_min, e.dt_max); fflush(stdout); } } diff --git a/src/cell.c b/src/cell.c index d36cbbb500..e8038db1da 100644 --- a/src/cell.c +++ b/src/cell.c @@ -1095,6 +1095,7 @@ void cell_clean_links(struct cell *c, void *data) { c->gradient = NULL; c->force = NULL; c->grav = NULL; + c->grav_mm = NULL; } /** @@ -2271,7 +2272,7 @@ int cell_unskip_gravity_tasks(struct cell *c, struct scheduler *s) { } else if (t->type == task_type_pair) { cell_activate_subcell_grav_tasks(ci, cj, s); } else if (t->type == task_type_grav_mm) { - cell_activate_grav_mm_task(ci, cj, s); + error("Incorrectyl linked M-M task!"); } } @@ -2325,28 +2326,29 @@ int cell_unskip_gravity_tasks(struct cell *c, struct scheduler *s) { } #endif } + } - if (t->type == task_type_grav_mm) { + for (struct link *l = c->grav_mm; l != NULL; l = l->next) { + struct task *t = l->t; + struct cell *ci = t->ci; + struct cell *cj = t->cj; + const int ci_active = cell_is_active_gravity(ci, e); + const int cj_active = (cj != NULL) ? cell_is_active_gravity(cj, e) : 0; #ifdef WITH_MPI - /* Activate the send/recv tasks. */ - if (ci_nodeID != nodeID) { - - /* If the foreign cell is active, we want its ti_end values. */ - if (ci_active) scheduler_activate(s, ci->recv_ti); - - /* If the local cell is active, send its ti_end values. */ - if (cj_active) scheduler_activate_send(s, cj->send_ti, ci_nodeID); - - } else if (cj_nodeID != nodeID) { + const int ci_nodeID = ci->nodeID; + const int cj_nodeID = (cj != NULL) ? cj->nodeID : -1; +#else + const int ci_nodeID = nodeID; + const int cj_nodeID = nodeID; +#endif - /* If the foreign cell is active, we want its ti_end values. */ - if (cj_active) scheduler_activate(s, cj->recv_ti); + if (t->type != task_type_grav_mm) error("Incorrectly linked gravity task!"); - /* If the local cell is active, send its ti_end values. */ - if (ci_active) scheduler_activate_send(s, ci->send_ti, cj_nodeID); - } -#endif + /* Only activate tasks that involve a local active cell. */ + if ((ci_active && ci_nodeID == nodeID) || + (cj_active && cj_nodeID == nodeID)) { + cell_activate_grav_mm_task(ci, cj, s); } } @@ -2420,7 +2422,8 @@ void cell_set_super_hydro(struct cell *c, struct cell *super_hydro) { void cell_set_super_gravity(struct cell *c, struct cell *super_gravity) { /* Are we in a cell with some kind of self/pair task ? */ - if (super_gravity == NULL && c->grav != NULL) super_gravity = c; + if (super_gravity == NULL && (c->grav != NULL || c->grav_mm != NULL)) + super_gravity = c; /* Set the super-cell */ c->super_gravity = super_gravity; diff --git a/src/cell.h b/src/cell.h index 31d525b02b..534f9d704d 100644 --- a/src/cell.h +++ b/src/cell.h @@ -216,6 +216,9 @@ struct cell { /*! Linked list of the tasks computing this cell's gravity forces. */ struct link *grav; + /*! Linked list of the tasks computing this cell's gravity M-M forces. */ + struct link *grav_mm; + /*! The task computing this cell's sorts. */ struct task *sorts; diff --git a/src/engine.c b/src/engine.c index 265571b464..04694b2c9c 100644 --- a/src/engine.c +++ b/src/engine.c @@ -1582,8 +1582,7 @@ void engine_addtasks_recv_gravity(struct engine *e, struct cell *c, c->recv_grav = t_grav; for (struct link *l = c->grav; l != NULL; l = l->next) - if (l->t->type != task_type_grav_mm) - scheduler_addunlock(s, t_grav, l->t); + scheduler_addunlock(s, t_grav, l->t); /* Recurse? */ if (c->split) @@ -3823,7 +3822,7 @@ void engine_print_task_counts(struct engine *e) { int count_recv_gpart = 0; int count_send_tiend = 0; int count_recv_tiend = 0; - + /* Count and print the number of each task type. */ int counts[task_type_count + 1]; for (int k = 0; k <= task_type_count; k++) counts[k] = 0; @@ -3833,14 +3832,18 @@ void engine_print_task_counts(struct engine *e) { else { counts[(int)tasks[k].type] += 1; - if(tasks[k].type == task_type_send && tasks[k].subtype == task_subtype_gpart) - ++count_send_gpart; - if(tasks[k].type == task_type_send && tasks[k].subtype == task_subtype_tend) - ++count_send_tiend; - if(tasks[k].type == task_type_recv && tasks[k].subtype == task_subtype_gpart) - ++count_recv_gpart; - if(tasks[k].type == task_type_recv && tasks[k].subtype == task_subtype_tend) - ++count_recv_tiend; + if (tasks[k].type == task_type_send && + tasks[k].subtype == task_subtype_gpart) + ++count_send_gpart; + if (tasks[k].type == task_type_send && + tasks[k].subtype == task_subtype_tend) + ++count_send_tiend; + if (tasks[k].type == task_type_recv && + tasks[k].subtype == task_subtype_gpart) + ++count_recv_gpart; + if (tasks[k].type == task_type_recv && + tasks[k].subtype == task_subtype_tend) + ++count_recv_tiend; } } message("Total = %d (per cell = %d)", nr_tasks, @@ -3860,7 +3863,7 @@ void engine_print_task_counts(struct engine *e) { message("send_tiend = %d", count_send_tiend); message("recv_gpart = %d", count_recv_gpart); message("recv_tiend = %d", count_recv_tiend); - + message("nr_parts = %zu.", e->s->nr_parts); message("nr_gparts = %zu.", e->s->nr_gparts); message("nr_sparts = %zu.", e->s->nr_sparts); diff --git a/src/runner.c b/src/runner.c index f6f769d2f4..187e601315 100644 --- a/src/runner.c +++ b/src/runner.c @@ -2001,8 +2001,8 @@ void runner_do_recv_spart(struct runner *r, struct cell *c, int timer) { #endif /* ... and store. */ - //c->ti_gravity_end_min = ti_gravity_end_min; - //c->ti_gravity_end_max = ti_gravity_end_max; + // c->ti_gravity_end_min = ti_gravity_end_min; + // c->ti_gravity_end_max = ti_gravity_end_max; c->ti_old_gpart = ti_current; if (timer) TIMER_TOC(timer_dorecv_spart); diff --git a/src/scheduler.c b/src/scheduler.c index 3b52cb5704..8204351c2b 100644 --- a/src/scheduler.c +++ b/src/scheduler.c @@ -897,8 +897,8 @@ static void scheduler_splittask_gravity(struct task *t, struct scheduler *s) { /* Since this task will not be split, we can already link it */ atomic_inc(&ci->nr_tasks); atomic_inc(&cj->nr_tasks); - engine_addlink(e, &ci->grav, t); - engine_addlink(e, &cj->grav, t); + engine_addlink(e, &ci->grav_mm, t); + engine_addlink(e, &cj->grav_mm, t); break; } diff --git a/src/space.c b/src/space.c index 6f98e788e9..caf7795536 100644 --- a/src/space.c +++ b/src/space.c @@ -168,6 +168,7 @@ void space_rebuild_recycle_mapper(void *map_data, int num_elements, c->gradient = NULL; c->force = NULL; c->grav = NULL; + c->grav_mm = NULL; c->dx_max_part = 0.0f; c->dx_max_sort = 0.0f; c->sorted = 0; -- GitLab