diff --git a/src/engine.c b/src/engine.c index c18f9012de44571b5a9f2177b920bb5a720b8e07..ad2b5ef6a2eabcb66f4949ed088b43ec305ed44e 100644 --- a/src/engine.c +++ b/src/engine.c @@ -1265,6 +1265,23 @@ void engine_count_and_link_tasks(struct engine *e) { } } +/** + * @brief Creates the dependency network for the gravity tasks of a given cell. + * + * @param sched The #scheduler. + * @param gravity The gravity task to link. + * @param c The cell. + */ +static inline void engine_make_gravity_dependencies(struct scheduler *sched, + struct task *gravity, + struct cell *c) { + + /* init --> gravity --> kick */ + /* grav_up --> gravity ( --> kick) */ + scheduler_addunlock(sched, c->super->init, gravity); + scheduler_addunlock(sched, c->super->grav_up, gravity); + scheduler_addunlock(sched, gravity, c->super->kick); +} /** * @brief Creates all the task dependencies for the gravity @@ -1285,6 +1302,8 @@ void engine_link_gravity_tasks(struct engine *e) { struct task *fft = scheduler_addtask(sched, task_type_grav_fft, task_subtype_none, 0, 0, NULL, NULL, 0); + scheduler_addunlock(sched, gather, fft); + for (int k = 0; k < nr_tasks; k++) { /* Get a pointer to the task. */ @@ -1296,7 +1315,6 @@ void engine_link_gravity_tasks(struct engine *e) { /* Multipole construction */ if (t->type == task_type_grav_up) { scheduler_addunlock(sched, t, gather); - scheduler_addunlock(sched, t, fft); } /* Long-range interaction */ @@ -1332,15 +1350,22 @@ void engine_link_gravity_tasks(struct engine *e) { } - /* Otherwise, sub interaction? */ - else if (t->type == task_type_sub && t->subtype == task_subtype_grav) { + /* Otherwise, sub-self interaction? */ + else if (t->type == task_type_sub_self && t->subtype == task_subtype_grav) { + + if (t->ci->nodeID == nodeID) { + engine_make_gravity_dependencies(sched, t, t->ci); + } + } + + /* Otherwise, sub-pair interaction? */ + else if (t->type == task_type_sub_pair && t->subtype == task_subtype_grav) { if (t->ci->nodeID == nodeID) { engine_make_gravity_dependencies(sched, t, t->ci); } - if (t->cj != NULL && t->cj->nodeID == nodeID && - t->ci->super != t->cj->super) { + if (t->cj->nodeID == nodeID && t->ci->super != t->cj->super) { engine_make_gravity_dependencies(sched, t, t->cj); } diff --git a/src/partition.c b/src/partition.c index dbec9f7ebd976a9779d4a54ee536e0e4eef331b2..6df437826de796c05143b2003dbdacb971d9b7be 100644 --- a/src/partition.c +++ b/src/partition.c @@ -504,8 +504,7 @@ static void repart_edge_metis(int partweights, int bothweights, int nodeID, } /* Pair? */ - else if (t->type == task_type_pair || - (t->type == task_type_sub_pair)) { + else if (t->type == task_type_pair || (t->type == task_type_sub_pair)) { /* In-cell pair? */ if (ci == cj) { /* Add weight to vertex for ci. */ diff --git a/src/runner.c b/src/runner.c index ecbabb83cfccdd207b850eb4430e7f23a0719f41..f382b52df41d6ea9f96bbb239d171c8faed88a84 100644 --- a/src/runner.c +++ b/src/runner.c @@ -1087,6 +1087,8 @@ void *runner_main(void *data) { runner_dosub_self1_density(r, ci, 1); else if (t->subtype == task_subtype_force) runner_dosub_self2_force(r, ci, 1); + else if (t->subtype == task_subtype_grav) + runner_dosub_grav(r, ci, cj, 1); else error("Unknown task subtype."); break; @@ -1095,6 +1097,8 @@ void *runner_main(void *data) { runner_dosub_pair1_density(r, ci, cj, t->flags, 1); else if (t->subtype == task_subtype_force) runner_dosub_pair2_force(r, ci, cj, t->flags, 1); + else if (t->subtype == task_subtype_grav) + runner_dosub_grav(r, ci, cj, 1); else error("Unknown task subtype."); break; diff --git a/src/task.c b/src/task.c index 8cbbc1bd909fcc65e51679c6f2445ea76e7104a1..f3aa87400b9e1f23378545236b4a4c9cf8350d9a 100644 --- a/src/task.c +++ b/src/task.c @@ -142,7 +142,6 @@ void task_unlock(struct task *t) { } break; - case task_type_grav_mm: cell_gunlocktree(ci); break; @@ -218,6 +217,10 @@ int task_lock(struct task *t) { } break; + case task_type_grav_mm: + cell_glocktree(ci); + break; + default: break; }