diff --git a/examples/ExternalPointMass/run.sh b/examples/ExternalPointMass/run.sh index 9f90ca395a5c8cf83e67928b3fdbd4d8529ac254..4ac513f09cb8ac8dcefc256a68478e215b8bc320 100755 --- a/examples/ExternalPointMass/run.sh +++ b/examples/ExternalPointMass/run.sh @@ -7,4 +7,4 @@ then python makeIC.py 10000 fi -../swift -g -t 2 externalPointMass.yml 2>&1 | tee output.log +../swift -g -t 1 externalPointMass.yml 2>&1 | tee output.log diff --git a/src/cell.c b/src/cell.c index 678d12dd7708960803d225e1bf2fff12e6cab7bd..d6a891aad404685a097f955503bc59615127ae40 100644 --- a/src/cell.c +++ b/src/cell.c @@ -854,8 +854,6 @@ void cell_set_super(struct cell *c, struct cell *super) { /* Set the super-cell */ c->super = super; - //if (c->nr_tasks == 0 && super == NULL) message("No tasks here"); - /* Recurse */ if (c->split) for (int k = 0; k < 8; k++) diff --git a/src/const.h b/src/const.h index afad73211546cf81cbb0e6a1179569e588952fec..43215e273d85456df66ec87720d63cfd90e11305 100644 --- a/src/const.h +++ b/src/const.h @@ -91,8 +91,8 @@ #define const_gravity_eta 0.025f /* External gravity properties */ -#define EXTERNAL_POTENTIAL_NONE -//#define EXTERNAL_POTENTIAL_POINTMASS +//#define EXTERNAL_POTENTIAL_NONE +#define EXTERNAL_POTENTIAL_POINTMASS //#define EXTERNAL_POTENTIAL_ISOTHERMALPOTENTIAL //#define EXTERNAL_POTENTIAL_DISC_PATCH @@ -103,6 +103,6 @@ //#define COOLING_GRACKLE /* Are we debugging ? */ -//#define SWIFT_DEBUG_CHECKS +#define SWIFT_DEBUG_CHECKS #endif /* SWIFT_CONST_H */ diff --git a/src/engine.c b/src/engine.c index 8e7b68fb5749bc97de4d997a86b8a135c4d3668b..7c3497b58b1d2e9d6e3918489b4a5278d1a455bb 100644 --- a/src/engine.c +++ b/src/engine.c @@ -110,72 +110,14 @@ void engine_addlink(struct engine *e, struct link **l, struct task *t) { res->next = atomic_swap(l, res); } -/** - * @brief Generate the gravity hierarchical tasks for a hierarchy of cells - - * i.e. all the O(Npart) tasks. - * - * Tasks are only created here. The dependencies will be added later on. - * - * @param e The #engine. - * @param c The #cell. - * @param gsuper The gsuper #cell. - */ -/* void engine_make_gravity_hierarchical_tasks(struct engine *e, struct cell *c) - * { */ - -/* struct scheduler *s = &e->sched; */ -/* const int is_with_external_gravity = */ -/* (e->policy & engine_policy_external_gravity); */ -/* const int is_fixdt = (e->policy & engine_policy_fixdt); */ - -/* /\* Are we in a cell with self/pair tasks ? *\/ */ -/* if (c->super == c) { */ - -/* /\* Local tasks only... *\/ */ -/* if (c->nodeID == e->nodeID) { */ - -/* /\* Add the init task. *\/ */ -/* if (c->init == NULL) */ -/* c->init = scheduler_addtask(s, task_type_init, task_subtype_none, 0, - * 0, */ -/* c, NULL, 0); */ - -/* /\* Add the kick task that matches the policy. *\/ */ -/* if (is_fixdt) { */ -/* if (c->kick == NULL) */ -/* c->kick = scheduler_addtask(s, task_type_kick_fixdt, */ -/* task_subtype_none, 0, 0, c, NULL, 0); - */ -/* } else { */ -/* if (c->kick == NULL) */ -/* c->kick = scheduler_addtask(s, task_type_kick, task_subtype_none, - * 0, */ -/* 0, c, NULL, 0); */ -/* } */ - -/* /\* External gravity task *\/ */ -/* if (is_with_external_gravity && c->grav_external == NULL) */ -/* c->grav_external = scheduler_addtask( */ -/* s, task_type_grav_external, task_subtype_none, 0, 0, c, NULL, 0); - */ -/* } */ - -/* } else { */ - -/* /\* Recurse. *\/ */ -/* if (c->split) */ -/* for (int k = 0; k < 8; k++) */ -/* if (c->progeny[k] != NULL) */ -/* engine_make_gravity_hierarchical_tasks(e, c->progeny[k]); */ -/* } */ -/* } */ - /** * @brief Generate the hydro hierarchical tasks for a hierarchy of cells - * i.e. all the O(Npart) tasks. * * Tasks are only created here. The dependencies will be added later on. * + * Note that there is no need to recurse below the super-cell. + * * @param e The #engine. * @param c The #cell. * @param super The super #cell. @@ -184,11 +126,10 @@ void engine_make_hierarchical_tasks(struct engine *e, struct cell *c) { struct scheduler *s = &e->sched; const int is_fixdt = (e->policy & engine_policy_fixdt); + const int is_hydro = (e->policy & engine_policy_hydro); const int is_with_cooling = (e->policy & engine_policy_cooling); - const int is_with_external_gravity = - (e->policy & engine_policy_external_gravity); - /* Are we in a cell with self/pair tasks ? */ + /* Are we in a super-cell ? */ if (c->super == c) { /* Local tasks only... */ @@ -208,27 +149,28 @@ void engine_make_hierarchical_tasks(struct engine *e, struct cell *c) { } /* Generate the ghost task. */ - c->ghost = scheduler_addtask(s, task_type_ghost, task_subtype_none, 0, 0, - c, NULL, 0); + if (is_hydro) + c->ghost = scheduler_addtask(s, task_type_ghost, task_subtype_none, 0, 0, + c, NULL, 0); #ifdef EXTRA_HYDRO_LOOP /* Generate the extra ghost task. */ - c->extra_ghost = scheduler_addtask(s, task_type_extra_ghost, - task_subtype_none, 0, 0, c, NULL, 0); + if (is_hydro) + c->extra_ghost = scheduler_addtask(s, task_type_extra_ghost, + task_subtype_none, 0, 0, c, NULL, 0); #endif - /* External gravity task */ - if (is_with_external_gravity) // && c->grav_external == NULL) - c->grav_external = scheduler_addtask( - s, task_type_grav_external, task_subtype_none, 0, 0, c, NULL, 0); - /* Cooling task */ if (is_with_cooling) c->cooling = scheduler_addtask(s, task_type_cooling, task_subtype_none, 0, 0, c, NULL, 0); } - } else { + } else { /* We are above the super-cell so need to go deeper */ + +#ifdef SWIFT_DEBUG_CHECKS + if (c->super != NULL) error("Incorrectly set super pointer"); +#endif /* Recurse. */ if (c->split) @@ -1283,6 +1225,30 @@ void engine_make_gravity_tasks(struct engine *e) { } } +void engine_make_external_gravity_tasks(struct engine *e) { + + struct space *s = e->s; + struct scheduler *sched = &e->sched; + const int nodeID = e->nodeID; + struct cell *cells = s->cells_top; + const int nr_cells = s->nr_cells; + + for (int cid = 0; cid < nr_cells; ++cid) { + + struct cell *ci = &cells[cid]; + + /* Skip cells without gravity particles */ + if (ci->gcount == 0) continue; + + /* Is that neighbour local ? */ + if (ci->nodeID != nodeID) continue; + + /* If the cells is local build a self-interaction */ + scheduler_addtask(sched, task_type_self, task_subtype_external_grav, 0, 0, + ci, NULL, 0); + } +} + /** * @brief Constructs the top-level pair tasks for the first hydro loop over * neighbours @@ -1435,6 +1401,22 @@ static inline void engine_make_gravity_dependencies(struct scheduler *sched, scheduler_addunlock(sched, c->super->grav_up, gravity); } +/** + * @brief Creates the dependency network for the external 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_external_gravity_dependencies( + struct scheduler *sched, struct task *gravity, struct cell *c) { + + /* init --> external gravity --> kick */ + scheduler_addunlock(sched, c->super->init, gravity); + scheduler_addunlock(sched, gravity, c->super->kick); +} + /** * @brief Creates all the task dependencies for the gravity * @@ -1480,13 +1462,21 @@ void engine_link_gravity_tasks(struct engine *e) { scheduler_addunlock(sched, t->ci->super->init, t); } - /* Self-interaction? */ + /* Self-interaction for self-gravity? */ if (t->type == task_type_self && t->subtype == task_subtype_grav) { engine_make_gravity_dependencies(sched, t, t->ci); } + /* Self-interaction for external gravity ? */ + else if (t->type == task_type_self && + t->subtype == task_subtype_external_grav) { + + engine_make_external_gravity_dependencies(sched, t, t->ci); + + } + /* Otherwise, pair interaction? */ else if (t->type == task_type_pair && t->subtype == task_subtype_grav) { @@ -1510,6 +1500,15 @@ void engine_link_gravity_tasks(struct engine *e) { } } + /* Sub-self-interaction for external gravity ? */ + else if (t->type == task_type_sub_self && + t->subtype == task_subtype_external_grav) { + + if (t->ci->nodeID == nodeID) { + engine_make_external_gravity_dependencies(sched, t, t->ci); + } + } + /* Otherwise, sub-pair interaction? */ else if (t->type == task_type_sub_pair && t->subtype == task_subtype_grav) { @@ -1785,12 +1784,6 @@ void engine_make_extra_hydroloop_tasks(struct engine *e) { #endif } - /* External gravity tasks should depend on init and unlock the kick */ - else if (t->type == task_type_grav_external) { - scheduler_addunlock(sched, t->ci->init, t); - scheduler_addunlock(sched, t, t->ci->kick); - } - /* Cooling tasks should depend on kick and does not unlock anything since it is the last task*/ else if (t->type == task_type_cooling) { @@ -1859,6 +1852,12 @@ void engine_maketasks(struct engine *e) { /* Add the gravity mm tasks. */ if (e->policy & engine_policy_self_gravity) engine_make_gravity_tasks(e); + /* Add the external gravity tasks. */ + if (e->policy & engine_policy_external_gravity) + engine_make_external_gravity_tasks(e); + + if (e->sched.nr_tasks == 0) error("No hydro or gravity tasks created."); + /* Split the tasks. */ scheduler_splittasks(sched); @@ -1882,13 +1881,14 @@ void engine_maketasks(struct engine *e) { /* 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. */ - if (e->policy & engine_policy_hydro) engine_count_and_link_tasks(e); + engine_count_and_link_tasks(e); /* Now that the pair tasks are at the right level, set the super pointers. */ for (int k = 0; k < nr_cells; k++) cell_set_super(&cells[k], NULL); /* Append hierarchical tasks to each cells */ - for (int k = 0; k < nr_cells; k++) engine_make_hierarchical_tasks(e, &cells[k]); + for (int k = 0; k < nr_cells; k++) + engine_make_hierarchical_tasks(e, &cells[k]); /* Run through the tasks and make force tasks for each density task. Each force task depends on the cell ghosts and unlocks the kick task @@ -1896,7 +1896,7 @@ void engine_maketasks(struct engine *e) { if (e->policy & engine_policy_hydro) engine_make_extra_hydroloop_tasks(e); /* Add the dependencies for the self-gravity stuff */ - if (e->policy & engine_policy_self_gravity) engine_link_gravity_tasks(e); + engine_link_gravity_tasks(e); #ifdef WITH_MPI @@ -2636,7 +2636,10 @@ void engine_init_particles(struct engine *e, int flag_entropy_ICs) { /* Add the tasks corresponding to external gravity to the masks */ if (e->policy & engine_policy_external_gravity) { - mask |= 1 << task_type_grav_external; + mask |= 1 << task_type_self; + mask |= 1 << task_type_sub_self; + + submask |= 1 << task_subtype_external_grav; } /* Add MPI tasks if need be */ @@ -2805,7 +2808,11 @@ void engine_step(struct engine *e) { /* Add the tasks corresponding to external gravity to the masks */ if (e->policy & engine_policy_external_gravity) { - mask |= 1 << task_type_grav_external; + + mask |= 1 << task_type_self; + mask |= 1 << task_type_sub_self; + + submask |= 1 << task_subtype_external_grav; } /* Add the tasks corresponding to cooling to the masks */ diff --git a/src/runner.c b/src/runner.c index 0a08bb5abf9af25aea889e3c9279eacb0271f388..fe81947a49194398682f621b0acefaa6ad249572 100644 --- a/src/runner.c +++ b/src/runner.c @@ -147,12 +147,12 @@ void runner_do_grav_external(struct runner *r, struct cell *c, int timer) { for (int i = 0; i < gcount; i++) { /* Get a direct pointer on the part. */ - struct gpart *restrict g = &gparts[i]; + struct gpart *restrict gp = &gparts[i]; /* Is this part within the time step? */ - if (g->ti_end <= ti_current) { + if (gp->ti_end <= ti_current) { - external_gravity_acceleration(time, potential, constants, g); + external_gravity_acceleration(time, potential, constants, gp); } } @@ -1243,9 +1243,12 @@ void *runner_main(void *data) { runner_doself2_force(r, ci); else if (t->subtype == task_subtype_grav) runner_doself_grav(r, ci, 1); + else if (t->subtype == task_subtype_external_grav) + runner_do_grav_external(r, ci, 1); else error("Unknown task subtype."); break; + case task_type_pair: if (t->subtype == task_subtype_density) runner_dopair1_density(r, ci, cj); @@ -1260,9 +1263,7 @@ void *runner_main(void *data) { else error("Unknown task subtype."); break; - case task_type_sort: - runner_do_sort(r, ci, t->flags, 1); - break; + case task_type_sub_self: if (t->subtype == task_subtype_density) runner_dosub_self1_density(r, ci, 1); @@ -1274,9 +1275,12 @@ void *runner_main(void *data) { runner_dosub_self2_force(r, ci, 1); else if (t->subtype == task_subtype_grav) runner_dosub_grav(r, ci, cj, 1); + else if (t->subtype == task_subtype_external_grav) + runner_do_grav_external(r, ci, 1); else error("Unknown task subtype."); break; + case task_type_sub_pair: if (t->subtype == task_subtype_density) runner_dosub_pair1_density(r, ci, cj, t->flags, 1); @@ -1291,6 +1295,10 @@ void *runner_main(void *data) { else error("Unknown task subtype."); break; + + case task_type_sort: + runner_do_sort(r, ci, t->flags, 1); + break; case task_type_init: runner_do_init(r, ci, 1); break; @@ -1334,9 +1342,6 @@ void *runner_main(void *data) { case task_type_grav_fft: runner_do_grav_fft(r); break; - case task_type_grav_external: - runner_do_grav_external(r, t->ci, 1); - break; case task_type_cooling: runner_do_cooling(r, t->ci, 1); break; diff --git a/src/task.c b/src/task.c index 8da526f57886fa68121061c8eae2316912e73a30..30e90f90a420a2efc742ec2c8d8454bf01d42e86 100644 --- a/src/task.c +++ b/src/task.c @@ -48,13 +48,12 @@ /* Task type names. */ const char *taskID_names[task_type_count] = { - "none", "sort", "self", "pair", "sub_self", - "sub_pair", "init", "ghost", "extra_ghost", "kick", - "kick_fixdt", "send", "recv", "grav_gather_m", "grav_fft", - "grav_mm", "grav_up", "grav_external", "cooling"}; + "none", "sort", "self", "pair", "sub_self", "sub_pair", + "init", "ghost", "extra_ghost", "kick", "kick_fixdt", "send", + "recv", "grav_gather_m", "grav_fft", "grav_mm", "grav_up", "cooling"}; const char *subtaskID_names[task_subtype_count] = { - "none", "density", "gradient", "force", "grav", "tend"}; + "none", "density", "gradient", "force", "grav", "external_grav", "tend"}; /** * @brief Computes the overlap between the parts array of two given cells. @@ -134,6 +133,7 @@ __attribute__((always_inline)) INLINE static enum task_actions task_acts_on( break; case task_subtype_grav: + case task_subtype_external_grav: return task_action_gpart; break; @@ -149,7 +149,14 @@ __attribute__((always_inline)) INLINE static enum task_actions task_acts_on( case task_type_kick_fixdt: case task_type_send: case task_type_recv: - return task_action_all; + if (t->ci->count > 0 && t->ci->gcount > 0) + return task_action_all; + else if (t->ci->count > 0) + return task_action_part; + else if (t->ci->gcount > 0) + return task_action_gpart; + else + error("Task without particles"); break; case task_type_grav_gather_m: @@ -159,10 +166,6 @@ __attribute__((always_inline)) INLINE static enum task_actions task_acts_on( return task_action_multipole; break; - case task_type_grav_external: - return task_action_gpart; - break; - default: error("Unknown task_action for task"); return task_action_none; @@ -392,3 +395,15 @@ void task_print_submask(unsigned int submask) { printf(" %s=%s", subtaskID_names[k], (submask & (1 << k)) ? "yes" : "no"); printf(" ]\n"); } + +/** + * @brief Print basic information about a task. + * + * @param t The #task. + */ +void task_print(const struct task *t) { + + message("Type:'%s' sub_type:'%s' wait=%d nr_unlocks=%d skip=%d", + taskID_names[t->type], subtaskID_names[t->subtype], t->wait, + t->nr_unlock_tasks, t->skip); +} diff --git a/src/task.h b/src/task.h index 4928dc00bcd7958efdd6987b5aec90ab4b3e92fa..efd3596144cc741bb84597cdfbecd402ba02bc33 100644 --- a/src/task.h +++ b/src/task.h @@ -53,7 +53,6 @@ enum task_types { task_type_grav_fft, task_type_grav_mm, task_type_grav_up, - task_type_grav_external, task_type_cooling, task_type_count } __attribute__((packed)); @@ -67,6 +66,7 @@ enum task_subtypes { task_subtype_gradient, task_subtype_force, task_subtype_grav, + task_subtype_external_grav, task_subtype_tend, task_subtype_count } __attribute__((packed)); @@ -159,5 +159,6 @@ int task_lock(struct task *t); void task_print_mask(unsigned int mask); void task_print_submask(unsigned int submask); void task_do_rewait(struct task *t); +void task_print(const struct task *t); #endif /* SWIFT_TASK_H */