Commit f8776762 authored by Pedro Gonnet's avatar Pedro Gonnet
Browse files

change sort task flags to be zero by default and only switch on those that are...

change sort task flags to be zero by default and only switch on those that are needed, avoids pre-emptively computing all the sorts for a cell since they may never be needed between two sort cleanups.
parent be6e65aa
......@@ -1575,8 +1575,6 @@ void cell_activate_subcell_tasks(struct cell *ci, struct cell *cj,
cj->requires_sorts = ti_current;
ci->dx_max_sort_old = ci->dx_max_sort;
cj->dx_max_sort_old = cj->dx_max_sort;
atomic_or(&ci->sorts->flags, (1 << sid));
atomic_or(&cj->sorts->flags, (1 << sid));
/* Activate the drifts if the cells are local. */
if (ci->nodeID == engine_rank) scheduler_activate(s, ci->drift_part);
......@@ -1584,22 +1582,28 @@ void cell_activate_subcell_tasks(struct cell *ci, struct cell *cj,
if (ci->dx_max_sort > space_maxreldx * ci->dmin) {
for (struct cell *finger = ci; finger != NULL; finger = finger->parent) {
finger->sorted = 0;
if (finger->requires_sorts == ti_current)
if (finger->requires_sorts == ti_current) {
atomic_or(&finger->sorts->flags, finger->sorted);
scheduler_activate(s, finger->sorts);
}
finger->sorted = 0;
}
}
if (!(ci->sorted & (1 << sid))) {
atomic_or(&ci->sorts->flags, (1 << sid));
scheduler_activate(s, ci->sorts);
}
if (cj->dx_max_sort > space_maxreldx * cj->dmin) {
for (struct cell *finger = cj; finger != NULL; finger = finger->parent) {
finger->sorted = 0;
if (finger->requires_sorts == ti_current)
if (finger->requires_sorts == ti_current) {
atomic_or(&finger->sorts->flags, finger->sorted);
scheduler_activate(s, finger->sorts);
}
finger->sorted = 0;
}
}
if (!(cj->sorted & (1 << sid))) {
atomic_or(&cj->sorts->flags, (1 << sid));
scheduler_activate(s, cj->sorts);
}
}
......@@ -1640,32 +1644,30 @@ int cell_unskip_tasks(struct cell *c, struct scheduler *s) {
if (ci->dx_max_sort > space_maxreldx * ci->dmin) {
for (struct cell *finger = ci; finger != NULL;
finger = finger->parent) {
finger->sorted = 0;
if (finger->requires_sorts == ti_current)
if (finger->requires_sorts == ti_current) {
atomic_or(&finger->sorts->flags, finger->sorted);
scheduler_activate(s, finger->sorts);
}
finger->sorted = 0;
}
}
if (!(ci->sorted & (1 << t->flags))) {
#ifdef SWIFT_DEBUG_CHECKS
if (!(ci->sorts->flags & (1 << t->flags)))
error("bad flags in sort task.");
#endif
atomic_or(&ci->sorts->flags, (1 << t->flags));
scheduler_activate(s, ci->sorts);
if (ci->nodeID == engine_rank) scheduler_activate(s, ci->drift_part);
}
if (cj->dx_max_sort > space_maxreldx * cj->dmin) {
for (struct cell *finger = cj; finger != NULL;
finger = finger->parent) {
finger->sorted = 0;
if (finger->requires_sorts == ti_current)
if (finger->requires_sorts == ti_current) {
atomic_or(&finger->sorts->flags, finger->sorted);
scheduler_activate(s, finger->sorts);
}
finger->sorted = 0;
}
}
if (!(cj->sorted & (1 << t->flags))) {
#ifdef SWIFT_DEBUG_CHECKS
if (!(cj->sorts->flags & (1 << t->flags)))
error("bad flags in sort task.");
#endif
atomic_or(&cj->sorts->flags, (1 << t->flags));
scheduler_activate(s, cj->sorts);
if (cj->nodeID == engine_rank) scheduler_activate(s, cj->drift_part);
}
......
......@@ -2585,32 +2585,30 @@ void engine_marktasks_mapper(void *map_data, int num_elements,
if (ci->dx_max_sort > space_maxreldx * ci->dmin) {
for (struct cell *finger = ci; finger != NULL;
finger = finger->parent) {
finger->sorted = 0;
if (finger->requires_sorts == ti_current)
if (finger->requires_sorts == ti_current) {
atomic_or(&finger->sorts->flags, finger->sorted);
scheduler_activate(s, finger->sorts);
}
finger->sorted = 0;
}
}
if (!(ci->sorted & (1 << t->flags))) {
#ifdef SWIFT_DEBUG_CHECKS
if (!(ci->sorts->flags & (1 << t->flags)))
error("bad flags in sort task.");
#endif
atomic_or(&ci->sorts->flags, (1 << t->flags));
scheduler_activate(s, ci->sorts);
if (ci->nodeID == engine_rank) scheduler_activate(s, ci->drift_part);
}
if (cj->dx_max_sort > space_maxreldx * cj->dmin) {
for (struct cell *finger = cj; finger != NULL;
finger = finger->parent) {
finger->sorted = 0;
if (finger->requires_sorts == ti_current)
if (finger->requires_sorts == ti_current) {
atomic_or(&finger->sorts->flags, finger->sorted);
scheduler_activate(s, finger->sorts);
}
finger->sorted = 0;
}
}
if (!(cj->sorted & (1 << t->flags))) {
#ifdef SWIFT_DEBUG_CHECKS
if (!(cj->sorts->flags & (1 << t->flags)))
error("bad flags in sort task.");
#endif
atomic_or(&cj->sorts->flags, (1 << t->flags));
scheduler_activate(s, cj->sorts);
if (cj->nodeID == engine_rank) scheduler_activate(s, cj->drift_part);
}
......
......@@ -1876,6 +1876,8 @@ void *runner_main(void *data) {
/* Cleanup only if any of the indices went stale. */
runner_do_sort(r, ci, t->flags,
ci->dx_max_sort_old > space_maxreldx * ci->dmin, 1);
/* Reset the sort flags as our work here is done. */
t->flags = 0;
break;
case task_type_init_grav:
runner_do_init_grav(r, ci, 1);
......
......@@ -651,8 +651,8 @@ static void scheduler_splittask_hydro(struct task *t, struct scheduler *s) {
ci->drift_part = scheduler_addtask(s, task_type_drift_part,
task_subtype_none, 0, 0, ci, NULL);
if (ci->sorts == NULL)
ci->sorts = scheduler_addtask(s, task_type_sort, task_subtype_none,
1 << sid, 0, ci, NULL);
ci->sorts = scheduler_addtask(s, task_type_sort, task_subtype_none, 0,
0, ci, NULL);
else
ci->sorts->flags |= (1 << sid);
lock_unlock_blind(&ci->lock);
......@@ -664,8 +664,8 @@ static void scheduler_splittask_hydro(struct task *t, struct scheduler *s) {
cj->drift_part = scheduler_addtask(s, task_type_drift_part,
task_subtype_none, 0, 0, cj, NULL);
if (cj->sorts == NULL)
cj->sorts = scheduler_addtask(s, task_type_sort, task_subtype_none,
1 << sid, 0, cj, NULL);
cj->sorts = scheduler_addtask(s, task_type_sort, task_subtype_none, 0,
0, cj, NULL);
else
cj->sorts->flags |= (1 << sid);
lock_unlock_blind(&cj->lock);
......
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