diff --git a/examples/main.c b/examples/main.c index 302abb3935764a4e4c114e6678b398a11ca60b0b..fa373027b0db3f6809224732e175fdc3aaad2198 100644 --- a/examples/main.c +++ b/examples/main.c @@ -954,9 +954,6 @@ int main(int argc, char *argv[]) { engine_config(0, &e, params, nr_nodes, myrank, nr_threads, with_aff, talking, restart_file); - /* Initialise the FOF parameters. */ - if (with_fof) fof_init(&s); - if (myrank == 0) { clocks_gettime(&toc); message("engine_init took %.3f %s.", clocks_diff(&tic, &toc), diff --git a/src/engine.c b/src/engine.c index fb54f7251ac19571d528c6bca37891a144dfd83e..61bbc609fdd724120a629daf9725520d18214c50 100644 --- a/src/engine.c +++ b/src/engine.c @@ -2136,6 +2136,24 @@ void engine_rebuild(struct engine *e, int repartitioned, const ticks tic = getticks(); + /* Perform FOF search to seed black holes. */ + if (e->policy & engine_policy_fof && e->step != 0) { + + /* Initialise FOF parameters and allocate FOF arrays. */ + fof_init(e->s); + + /* Make FOF tasks and activate them. */ + engine_make_fof_tasks(e); + + /* Perform local FOF tasks. */ + engine_launch(e); + + /* Perform FOF search over foreign particles and + * find groups which require black hole seeding. */ + fof_search_tree(e->s); + + } + /* Clear the forcerebuild flag, whatever it was. */ e->forcerebuild = 0; e->restarting = 0; @@ -3263,26 +3281,6 @@ void engine_step(struct engine *e) { error("Obtained a time-step of size 0"); #endif - /* Perform FOF search to seed black holes. */ - if (e->policy & engine_policy_fof && !(e->step % 10)) { - - fof_init(e->s); - - struct scheduler *s = &e->sched; - - for(int i=0; i<s->nr_tasks; i++) { - - struct task *t = &s->tasks[i]; - - if (t->type == task_type_fof_self || t->type == task_type_fof_pair) scheduler_activate(s, t); - else t->skip = 1; - } - - engine_launch(e); - - fof_search_tree(e->s); - } - /********************************************************/ /* OK, we are done with the regular stuff. Time for i/o */ /********************************************************/ @@ -3392,13 +3390,6 @@ void engine_check_for_dumps(struct engine *e) { #endif } - /* Perform a FOF search. */ - if (e->run_fof) { - - fof_search_tree(e->s); - e->run_fof = 0; - } - /* Dump... */ #ifdef WITH_LOGGER /* Write a file containing the offsets in the particle logger. */ diff --git a/src/engine.h b/src/engine.h index 056111f4b9ae611caf2483956abc6b74d54f753f..17cee47fe6f407ac11b624d148b4814fde2dd3d0 100644 --- a/src/engine.h +++ b/src/engine.h @@ -476,6 +476,9 @@ void engine_print_task_counts(const struct engine *e); /* Function prototypes, engine_maketasks.c. */ void engine_maketasks(struct engine *e); +/* Function prototypes, engine_maketasks.c. */ +void engine_make_fof_tasks(struct engine *e); + /* Function prototypes, engine_marktasks.c. */ int engine_marktasks(struct engine *e); diff --git a/src/engine_maketasks.c b/src/engine_maketasks.c index 020f3b4f1ab6d732e70cfd375b0054b3dfe0f25d..e20457416a7eee329a12a1100373c50b72b1837a 100644 --- a/src/engine_maketasks.c +++ b/src/engine_maketasks.c @@ -2303,6 +2303,61 @@ void engine_make_fofloop_tasks_mapper(void *map_data, int num_elements, } } +/** + * @brief Fill the #space's task list with FOF tasks. + * + * @param e The #engine we are working with. + */ +void engine_make_fof_tasks(struct engine *e) { + + struct space *s = e->s; + struct scheduler *sched = &e->sched; + ticks tic = getticks(); + + tic = getticks(); + + /* Construct a FOF loop over neighbours */ + if (e->policy & engine_policy_fof) + threadpool_map(&e->threadpool, engine_make_fofloop_tasks_mapper, NULL, + s->nr_cells, 1, 0, e); + + if (e->verbose) + message("Making FOF tasks took %.3f %s.", + clocks_from_ticks(getticks() - tic), clocks_getunit()); + + tic = getticks(); + + /* Split the tasks. */ + scheduler_splittasks(sched); + + if (e->verbose) + message("Splitting FOF tasks took %.3f %s.", + clocks_from_ticks(getticks() - tic), clocks_getunit()); + + tic = getticks(); + + /* Activate all FOF tasks by default. */ + for(int i=0; i<sched->nr_tasks; i++) { + + struct task *t = &sched->tasks[i]; + + if (t->type == task_type_fof_self || t->type == task_type_fof_pair) scheduler_activate(sched, t); + } + + if (e->verbose) + message("Activating FOF tasks took %.3f %s.", + clocks_from_ticks(getticks() - tic), clocks_getunit()); + +#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 + +} + /** * @brief Fill the #space's task list. * @@ -2326,11 +2381,6 @@ void engine_maketasks(struct engine *e) { threadpool_map(&e->threadpool, engine_make_hydroloop_tasks_mapper, NULL, s->nr_cells, 1, 0, e); - /* Construct a FOF loop over neighbours */ - if (e->policy & engine_policy_fof) - threadpool_map(&e->threadpool, engine_make_fofloop_tasks_mapper, NULL, - s->nr_cells, 1, 0, e); - if (e->verbose) message("Making hydro tasks took %.3f %s.", clocks_from_ticks(getticks() - tic2), clocks_getunit()); diff --git a/src/scheduler.c b/src/scheduler.c index 90d67563034ecce818d0e13ac7145b7f38e010df..ab9ff41d3dc18aba9a81db130d115fcc7f084d46 100644 --- a/src/scheduler.c +++ b/src/scheduler.c @@ -1249,7 +1249,7 @@ static void scheduler_splittask_fof(struct task *t, struct scheduler *s) { break; } - /* Is this cell even split and the task does not violate h ? */ + /* Is this cell even split? */ if (cell_can_split_self_fof_task(ci)) { /* Take a step back (we're going to recycle the current task)... */