diff --git a/examples/main.c b/examples/main.c index 3328220a5e8e1e6c90234ad4a3fb4ef5b4e46d6d..32264f185f2d7cd7efb010f667ce74e486114c9d 100644 --- a/examples/main.c +++ b/examples/main.c @@ -56,9 +56,6 @@ #define ENGINE_POLICY engine_policy_none #endif - - - /** * @brief Main routine that loads a few particles and generates some output. * @@ -121,7 +118,8 @@ int main(int argc, char *argv[]) { #if defined(HAVE_SETAFFINITY) && defined(HAVE_LIBNUMA) && defined(_GNU_SOURCE) if ((ENGINE_POLICY) & engine_policy_setaffinity) { /* Ensure the NUMA node on which we initialise (first touch) everything - * doesn't change before engine_init allocates NUMA-local workers. Otherwise, + * doesn't change before engine_init allocates NUMA-local workers. + * Otherwise, * we may be scheduled elsewhere between the two times. */ cpu_set_t affinity; @@ -342,7 +340,8 @@ int main(int argc, char *argv[]) { tic = getticks(); if (myrank == 0) message("nr_nodes is %i.", nr_nodes); engine_init(&e, &s, dt_max, nr_threads, nr_queues, nr_nodes, myrank, - ENGINE_POLICY | engine_policy_steal, 0, time_end, dt_min, dt_max); + ENGINE_POLICY | engine_policy_steal | engine_policy_hydro, 0, + time_end, dt_min, dt_max); if (myrank == 0) message("engine_init took %.3f ms.", ((double)(getticks() - tic)) / CPU_TPS * 1000); diff --git a/src/engine.c b/src/engine.c index afbefca78732c53f3aecb66691767fe8fd5c4142..4fd9fff3ca6eb9346a47f6b4a2b4bc1c5e39b09f 100644 --- a/src/engine.c +++ b/src/engine.c @@ -1722,15 +1722,48 @@ void engine_init_particles(struct engine *e) { // message("\n0th DENSITY CALC\n"); - /* Now do a density calculation */ - TIMER_TIC; - engine_launch(e, e->nr_threads, - (1 << task_type_sort) | (1 << task_type_self) | - (1 << task_type_pair) | (1 << task_type_sub) | - (1 << task_type_init) | (1 << task_type_ghost) | - (1 << task_type_send) | (1 << task_type_recv), - 1 << task_subtype_density); + /* Build the masks corresponding to the policy */ + unsigned int mask = 0; + unsigned int submask = 0; + + /* We always have sort tasks */ + mask |= 1 << task_type_sort; + + /* Add the tasks corresponding to hydro operations to the masks */ + if ((e->policy & engine_policy_hydro) == engine_policy_hydro) { + + mask |= 1 << task_type_init; + mask |= 1 << task_type_self; + mask |= 1 << task_type_pair; + mask |= 1 << task_type_sub; + mask |= 1 << task_type_ghost; + + submask |= 1 << task_subtype_density; + } + + /* Add the tasks corresponding to self-gravity to the masks */ + if ((e->policy & engine_policy_self_gravity) == engine_policy_self_gravity) { + + /* Nothing here for now */ + } + + /* Add the tasks corresponding to self-gravity to the masks */ + if ((e->policy & engine_policy_external_gravity) == + engine_policy_external_gravity) { + + /* Nothing here for now */ + } + /* Add MPI tasks if need be */ + if ((e->policy & engine_policy_mpi) == engine_policy_mpi) { + + mask |= 1 << task_type_send; + mask |= 1 << task_type_recv; + } + + /* Now, launch the calculation */ + TIMER_TIC; + engine_launch(e, e->nr_threads, mask, submask); TIMER_TOC(timer_runners); // message("\n0th ENTROPY CONVERSION\n"); @@ -1834,16 +1867,50 @@ if ( e->nodeID == 0 ) /* Prepare the space. */ engine_prepare(e); + /* Build the masks corresponding to the policy */ + unsigned int mask = 0; + unsigned int submask = 0; + + /* We always have sort tasks and kick tasks */ + mask |= 1 << task_type_sort; + mask |= 1 << task_type_kick; + + /* Add the tasks corresponding to hydro operations to the masks */ + if ((e->policy & engine_policy_hydro) == engine_policy_hydro) { + + mask |= 1 << task_type_init; + mask |= 1 << task_type_self; + mask |= 1 << task_type_pair; + mask |= 1 << task_type_sub; + mask |= 1 << task_type_ghost; + + submask |= 1 << task_subtype_density; + submask |= 1 << task_subtype_force; + } + + /* Add the tasks corresponding to self-gravity to the masks */ + if ((e->policy & engine_policy_self_gravity) == engine_policy_self_gravity) { + + /* Nothing here for now */ + } + + /* Add the tasks corresponding to self-gravity to the masks */ + if ((e->policy & engine_policy_external_gravity) == + engine_policy_external_gravity) { + + /* Nothing here for now */ + } + + /* Add MPI tasks if need be */ + if ((e->policy & engine_policy_mpi) == engine_policy_mpi) { + + mask |= 1 << task_type_send; + mask |= 1 << task_type_recv; + } + /* Send off the runners. */ TIMER_TIC; - engine_launch(e, e->nr_threads, - (1 << task_type_sort) | (1 << task_type_self) | - (1 << task_type_pair) | (1 << task_type_sub) | - (1 << task_type_init) | (1 << task_type_ghost) | - (1 << task_type_kick) | (1 << task_type_send) | - (1 << task_type_recv), - (1 << task_subtype_density) | (1 << task_subtype_force)); - + engine_launch(e, e->nr_threads, mask, submask); TIMER_TOC(timer_runners); TIMER_TOC2(timer_step); @@ -2259,14 +2326,14 @@ void engine_print_policy(struct engine *e) { if (e->nodeID == 0) { printf("[000] engine_policy: engine policies are [ "); for (int k = 1; k < 32; k++) - if (e->policy & 1 << k) printf(" %s,", engine_policy_names[k + 1]); + if (e->policy & (1 << k)) printf(" %s,", engine_policy_names[k + 1]); printf(" ]\n"); fflush(stdout); } #else printf("engine_policy: engine policies are [ "); for (int k = 1; k < 32; k++) - if (e->policy & 1 << k) printf(" %s,", engine_policy_names[k + 1]); + if (e->policy & (1 << k)) printf(" %s,", engine_policy_names[k + 1]); printf(" ]\n"); fflush(stdout); #endif