Commit 3fae14ae authored by Matthieu Schaller's avatar Matthieu Schaller
Browse files

Store the list of progeny pairs to compute M-M for in the task flag to save computing time.

parent be1a76c7
......@@ -2017,48 +2017,6 @@ void cell_activate_subcell_hydro_tasks(struct cell *ci, struct cell *cj,
} /* Otherwise, pair interation */
}
/**
* @brief Drift the multipoles that will be used in a M-M task.
*
* @param ci The first #cell we update.
* @param cj The second #cell we update.
* @param s The task #scheduler.
*/
void cell_activate_grav_mm_task(struct cell *ci, struct cell *cj,
struct scheduler *s) {
/* Some constants */
const struct engine *e = s->space->e;
// const integertime_t ti_current = e->ti_current;
/* Anything to do here? */
if (!cell_is_active_gravity_mm(ci, e) && !cell_is_active_gravity_mm(cj, e))
error("Inactive MM task being activated");
/* /\* Atomically drift the multipoles in the progenies of ci *\/ */
/* for (int i = 0; i < 8; i++) { */
/* struct cell *cpi = ci->progeny[i]; */
/* if (cpi != NULL) { */
/* lock_lock(&cpi->mlock); */
/* if (cpi->ti_old_multipole < ti_current) cell_drift_multipole(cpi, e);
*/
/* if (lock_unlock(&cpi->mlock) != 0) error("Impossible to unlock
* m-pole"); */
/* } */
/* } */
/* /\* Atomically drift the multipoles in the progenies of cj *\/ */
/* for (int j = 0; j < 8; j++) { */
/* struct cell *cpj = cj->progeny[j]; */
/* if (cpj != NULL) { */
/* lock_lock(&cpj->mlock); */
/* if (cpj->ti_old_multipole < ti_current) cell_drift_multipole(cpj, e);
*/
/* if (lock_unlock(&cpj->mlock) != 0) error("Impossible to unlock
* m-pole"); */
/* } */
/* } */
}
/**
* @brief Traverse a sub-cell task and activate the gravity drift tasks that
* are required by a self gravity task.
......@@ -2523,9 +2481,6 @@ int cell_unskip_gravity_tasks(struct cell *c, struct scheduler *s) {
(cj_active && cj_nodeID == nodeID)) {
scheduler_activate(s, t);
/* Drift the multipoles */
cell_activate_grav_mm_task(ci, cj, s);
}
}
......
......@@ -2273,7 +2273,7 @@ void *runner_main(void *data) {
runner_do_grav_long_range(r, t->ci, 1);
break;
case task_type_grav_mm:
runner_dopair_grav_mm_progenies(r, t->ci, t->cj);
runner_dopair_grav_mm_progenies(r, t->flags, t->ci, t->cj);
break;
case task_type_cooling:
runner_do_cooling(r, t->ci, 1);
......
......@@ -1308,13 +1308,21 @@ static INLINE void runner_dopair_grav_mm(struct runner *r,
runner_dopair_grav_mm_nonsym(r, cj, ci);
}
/**
* @brief Computes all the M-M interactions between all the well-separated (at
* rebuild) pairs of progenies of the two cells.
*
* @param r The #runner thread.
* @param flags The task flag containing the list of well-separated pairs as a
* bit-field.
* @param ci The first #cell.
* @param cj The second #cell.
*/
static INLINE void runner_dopair_grav_mm_progenies(struct runner *r,
const long long flags,
struct cell *restrict ci,
struct cell *restrict cj) {
const struct engine *e = r->e;
const struct space *s = e->s;
/* Loop over all pairs of progenies */
for (int i = 0; i < 8; i++) {
if (ci->progeny[i] != NULL) {
......@@ -1324,11 +1332,10 @@ static INLINE void runner_dopair_grav_mm_progenies(struct runner *r,
struct cell *cpi = ci->progeny[i];
struct cell *cpj = cj->progeny[j];
/* Did we agree to use an M-M interaction here at the last rebuild? */
if (cell_can_use_pair_mm_rebuild(cpi, cpj, e, s)) {
const int flag = i * 8 + j;
runner_dopair_grav_mm(r, cpi, cpj);
}
/* Did we agree to use an M-M interaction here at the last rebuild? */
if (flags & (1LL << flag)) runner_dopair_grav_mm(r, cpi, cpj);
}
}
}
......
......@@ -906,6 +906,7 @@ static void scheduler_splittask_gravity(struct task *t, struct scheduler *s) {
* progeny pairs */
t->type = task_type_grav_mm;
t->subtype = task_subtype_none;
t->flags = 0;
/* Make a task for every other pair of progeny */
for (int i = 0; i < 8; i++) {
......@@ -913,11 +914,22 @@ static void scheduler_splittask_gravity(struct task *t, struct scheduler *s) {
for (int j = 0; j < 8; j++) {
if (cj->progeny[j] != NULL) {
/* But only for pairs that cannot be replaced by a M-M
* interaction */
if (!cell_can_use_pair_mm_rebuild(ci->progeny[i],
cj->progeny[j], e, sp)) {
/* Can we use a M-M interaction here? */
if (cell_can_use_pair_mm_rebuild(ci->progeny[i],
cj->progeny[j], e, sp)) {
/* Flag this pair as being treated by the M-M task */
/* We use the 64 bits in the task->flags field to store */
/* this information. The corresponding taks will unpack the
*/
/* information and operate according to the choices made
* here. */
const int flag = i * 8 + j;
t->flags |= (1LL << flag);
} else {
/* Ok, we actually have to create a task */
scheduler_splittask_gravity(
scheduler_addtask(s, task_type_pair, task_subtype_grav,
0, 0, ci->progeny[i], cj->progeny[j]),
......@@ -927,6 +939,16 @@ static void scheduler_splittask_gravity(struct task *t, struct scheduler *s) {
}
}
}
/* Can none of the progenies use M-M calculations? */
if (t->flags == 0) {
t->type = task_type_none;
t->subtype = task_subtype_none;
t->ci = NULL;
t->cj = NULL;
t->skip = 1;
}
} /* Split the pair */
}
} /* pair interaction? */
......
......@@ -366,7 +366,7 @@ int task_lock(struct task *t) {
char buff[MPI_MAX_ERROR_STRING];
int len;
MPI_Error_string(err, buff, &len);
error("Failed to test request on send/recv task (tag=%i, %s).",
error("Failed to test request on send/recv task (tag=%lld, %s).",
t->flags, buff);
}
return res;
......
......@@ -128,6 +128,9 @@ struct task {
/*! List of tasks unlocked by this one */
struct task **unlock_tasks;
/*! Flags used to carry additional information (e.g. sort directions) */
long long flags;
#ifdef WITH_MPI
/*! Buffer for this task's communications */
......@@ -138,9 +141,6 @@ struct task {
#endif
/*! Flags used to carry additional information (e.g. sort directions) */
int flags;
/*! Rank of a task in the order */
int rank;
......
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