diff --git a/src/engine.c b/src/engine.c index ea2e9cbd8629a108252810dc056d34f9e4c954b8..df5c2e5394dfa7a4f63444a828cd323fed2b12a5 100644 --- a/src/engine.c +++ b/src/engine.c @@ -3149,16 +3149,6 @@ void engine_maketasks(struct engine *e) { if (e->sched.nr_tasks == 0 && (s->nr_gparts > 0 || s->nr_parts > 0)) error("We have particles but no hydro or gravity tasks were created."); - /* Split the tasks. */ - scheduler_splittasks(sched); - -#ifdef SWIFT_DEBUG_CHECKS - /* Verify that we are not left with invalid tasks */ - for (int i = 0; i < e->sched.nr_tasks; ++i) { - const struct task *t = &e->sched.tasks[i]; - if (t->ci == NULL && t->cj != NULL && !t->skip) error("Invalid task"); - } -#endif /* Free the old list of cell-task links. */ if (e->links != NULL) free(e->links); @@ -3184,12 +3174,23 @@ void engine_maketasks(struct engine *e) { if (e->policy & engine_policy_self_gravity) e->size_links += s->tot_cells * self_grav_tasks_per_cell; - /* Allocate the new list */ + /* Allocate the new link list */ if ((e->links = (struct link *)malloc(sizeof(struct link) * e->size_links)) == NULL) error("Failed to allocate cell-task links."); e->nr_links = 0; + /* Split the tasks. */ + scheduler_splittasks(sched); + +#ifdef SWIFT_DEBUG_CHECKS + /* Verify that we are not left with invalid tasks */ + for (int i = 0; i < e->sched.nr_tasks; ++i) { + const struct task *t = &e->sched.tasks[i]; + if (t->ci == NULL && t->cj != NULL && !t->skip) error("Invalid task"); + } +#endif + /* Count the number of tasks associated with each cell and store the density tasks in each cell, and make each sort depend on the sorts of its progeny. */ @@ -3212,10 +3213,15 @@ void engine_maketasks(struct engine *e) { threadpool_map(&e->threadpool, engine_make_extra_hydroloop_tasks_mapper, sched->tasks, sched->nr_tasks, sizeof(struct task), 0, e); + ticks tic2 = getticks(); /* Add the dependencies for the gravity stuff */ if (e->policy & (engine_policy_self_gravity | engine_policy_external_gravity)) engine_link_gravity_tasks(e); + message("Linking gravity tasks took %.3f %s.", + clocks_from_ticks(getticks() - tic2), clocks_getunit()); + + #ifdef WITH_MPI /* Add the communication tasks if MPI is being used. */ @@ -3268,15 +3274,31 @@ void engine_maketasks(struct engine *e) { } #endif + tic2 = getticks(); + /* Set the unlocks per task. */ scheduler_set_unlocks(sched); + message("Setting task unlocks took %.3f %s.", + clocks_from_ticks(getticks() - tic2), clocks_getunit()); + + tic2 = getticks(); + /* Rank the tasks. */ scheduler_ranktasks(sched); + message("Ranking tasks took %.3f %s.", + clocks_from_ticks(getticks() - tic2), clocks_getunit()); + + + tic2 = getticks(); + /* Weight the tasks. */ scheduler_reweight(sched, e->verbose); + message("Reweighting tasks took %.3f %s.", + clocks_from_ticks(getticks() - tic2), clocks_getunit()); + /* Set the tasks age. */ e->tasks_age = 0; diff --git a/src/engine.h b/src/engine.h index 38e0fc3c8b496ab09b5902348ac0c70417deace2..b29b5bb0bb6013e14c49f0d45bd072984822e012 100644 --- a/src/engine.h +++ b/src/engine.h @@ -339,6 +339,7 @@ struct engine { }; /* Function prototypes. */ +void engine_addlink(struct engine *e, struct link **l, struct task *t); void engine_barrier(struct engine *e); void engine_compute_next_snapshot_time(struct engine *e); void engine_compute_next_statistics_time(struct engine *e); diff --git a/src/scheduler.c b/src/scheduler.c index bddb9966d76723190a18b17114c706b4e8beaaeb..90f20d776361ea27d79083500f14f1ff536b894a 100644 --- a/src/scheduler.c +++ b/src/scheduler.c @@ -53,8 +53,6 @@ #include "timers.h" #include "version.h" -void engine_addlink(struct engine *e, struct link **l, struct task *t); - /** * @brief Re-set the list of active tasks. */ @@ -904,6 +902,8 @@ static void scheduler_splittask_gravity(struct task *t, struct scheduler *s) { t->type = task_type_grav_mm; t->subtype = task_subtype_none; + + /* 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); @@ -984,7 +984,9 @@ void scheduler_splittasks_mapper(void *map_data, int num_elements, } else if (t->type == task_type_grav_mesh) { /* For future use */ } else { +#ifdef SWIFT_DEBUG_CHECKS error("Unexpected task sub-type"); +#endif } } }