Commit 516551d8 authored by Pedro Gonnet's avatar Pedro Gonnet Committed by Matthieu Schaller
Browse files

use a threadpool_map for engine_make_hydro_tasks.

parent ddad736c
...@@ -1814,9 +1814,15 @@ void engine_make_external_gravity_tasks(struct engine *e) { ...@@ -1814,9 +1814,15 @@ void engine_make_external_gravity_tasks(struct engine *e) {
* Additional loop over neighbours can later be added by simply duplicating * Additional loop over neighbours can later be added by simply duplicating
* all the tasks created by this function. * all the tasks created by this function.
* *
* @param e The #engine. * @param map_data Offset of first two indices disguised as a pointer.
* @param num_elements Number of cells to traverse.
* @param extra_data The #engine.
*/ */
void engine_make_hydroloop_tasks(struct engine *e) { void engine_make_hydroloop_tasks_mapper(void *map_data, int num_elements,
void *extra_data) {
/* Extract the engine pointer. */
struct engine *e = (struct engine *)extra_data;
struct space *s = e->s; struct space *s = e->s;
struct scheduler *sched = &e->sched; struct scheduler *sched = &e->sched;
...@@ -1824,13 +1830,16 @@ void engine_make_hydroloop_tasks(struct engine *e) { ...@@ -1824,13 +1830,16 @@ void engine_make_hydroloop_tasks(struct engine *e) {
const int *cdim = s->cdim; const int *cdim = s->cdim;
struct cell *cells = s->cells_top; struct cell *cells = s->cells_top;
/* Run through the highest level of cells and add pairs. */ /* Loop through the elements, which are just byte offsets from NULL. */
for (int i = 0; i < cdim[0]; i++) { for (int ind = 0; ind < num_elements; ind++) {
for (int j = 0; j < cdim[1]; j++) {
for (int k = 0; k < cdim[2]; k++) { /* Get the cell index. */
const int cid = (size_t)(map_data + ind);
const int i = cid / (cdim[1] * cdim[0]);
const int j = (cid / cdim[0]) % cdim[1];
const int k = cid % (cdim[0] * cdim[1]);
/* Get the cell */ /* Get the cell */
const int cid = cell_getid(cdim, i, j, k);
struct cell *ci = &cells[cid]; struct cell *ci = &cells[cid];
/* Skip cells without hydro particles */ /* Skip cells without hydro particles */
...@@ -1838,8 +1847,8 @@ void engine_make_hydroloop_tasks(struct engine *e) { ...@@ -1838,8 +1847,8 @@ void engine_make_hydroloop_tasks(struct engine *e) {
/* If the cells is local build a self-interaction */ /* If the cells is local build a self-interaction */
if (ci->nodeID == nodeID) if (ci->nodeID == nodeID)
scheduler_addtask(sched, task_type_self, task_subtype_density, 0, 0, scheduler_addtask(sched, task_type_self, task_subtype_density, 0, 0, ci,
ci, NULL); NULL);
/* Now loop over all the neighbours of this cell */ /* Now loop over all the neighbours of this cell */
for (int ii = -1; ii < 2; ii++) { for (int ii = -1; ii < 2; ii++) {
...@@ -1865,12 +1874,9 @@ void engine_make_hydroloop_tasks(struct engine *e) { ...@@ -1865,12 +1874,9 @@ void engine_make_hydroloop_tasks(struct engine *e) {
continue; continue;
/* Construct the pair task */ /* Construct the pair task */
const int sid = const int sid = sortlistID[(kk + 1) + 3 * ((jj + 1) + 3 * (ii + 1))];
sortlistID[(kk + 1) + 3 * ((jj + 1) + 3 * (ii + 1))]; scheduler_addtask(sched, task_type_pair, task_subtype_density, sid, 0,
scheduler_addtask(sched, task_type_pair, task_subtype_density, ci, cj);
sid, 0, ci, cj);
}
}
} }
} }
} }
...@@ -2175,7 +2181,7 @@ void engine_make_extra_hydroloop_tasks(struct engine *e) { ...@@ -2175,7 +2181,7 @@ void engine_make_extra_hydroloop_tasks(struct engine *e) {
scheduler_addunlock(sched, t->ci->super->sorts, t); scheduler_addunlock(sched, t->ci->super->sorts, t);
#ifdef EXTRA_HYDRO_LOOP #ifdef EXTRA_HYDRO_LOOP
/* Start by constructing the task for the second and third hydro loop */ /* Start by constructing the task for the second and third hydro loop. */
struct task *t2 = scheduler_addtask( struct task *t2 = scheduler_addtask(
sched, task_type_self, task_subtype_gradient, 0, 0, t->ci, NULL); sched, task_type_self, task_subtype_gradient, 0, 0, t->ci, NULL);
struct task *t3 = scheduler_addtask( struct task *t3 = scheduler_addtask(
...@@ -2424,7 +2430,10 @@ void engine_maketasks(struct engine *e) { ...@@ -2424,7 +2430,10 @@ void engine_maketasks(struct engine *e) {
scheduler_reset(sched, s->tot_cells * engine_maxtaskspercell); scheduler_reset(sched, s->tot_cells * engine_maxtaskspercell);
/* Construct the firt hydro loop over neighbours */ /* Construct the firt hydro loop over neighbours */
if (e->policy & engine_policy_hydro) engine_make_hydroloop_tasks(e); if (e->policy & engine_policy_hydro) {
threadpool_map(&e->threadpool, engine_make_hydroloop_tasks_mapper, NULL,
s->nr_cells, 1, 0, e);
}
/* Add the self gravity tasks. */ /* Add the self gravity tasks. */
if (e->policy & engine_policy_self_gravity) engine_make_self_gravity_tasks(e); if (e->policy & engine_policy_self_gravity) engine_make_self_gravity_tasks(e);
...@@ -2641,8 +2650,8 @@ void engine_marktasks_mapper(void *map_data, int num_elements, ...@@ -2641,8 +2650,8 @@ void engine_marktasks_mapper(void *map_data, int num_elements,
scheduler_activate(s, l->t); scheduler_activate(s, l->t);
/* Drift the cell which will be sent at the level at which it is /* Drift the cell which will be sent at the level at which it is
sent, sent, i.e. drift the cell specified in the send task (l->t)
i.e. drift the cell specified in the send task (l->t) itself. */ itself. */
cell_activate_drift_part(l->t->ci, s); cell_activate_drift_part(l->t->ci, s);
if (cell_is_active(cj, e)) { if (cell_is_active(cj, e)) {
...@@ -2699,8 +2708,8 @@ void engine_marktasks_mapper(void *map_data, int num_elements, ...@@ -2699,8 +2708,8 @@ void engine_marktasks_mapper(void *map_data, int num_elements,
scheduler_activate(s, l->t); scheduler_activate(s, l->t);
/* Drift the cell which will be sent at the level at which it is /* Drift the cell which will be sent at the level at which it is
sent, sent, i.e. drift the cell specified in the send task (l->t)
i.e. drift the cell specified in the send task (l->t) itself. */ itself. */
cell_activate_drift_part(l->t->ci, s); cell_activate_drift_part(l->t->ci, s);
if (cell_is_active(ci, e)) { if (cell_is_active(ci, e)) {
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment