Commit 111fdbf9 authored by Matthieu Schaller's avatar Matthieu Schaller
Browse files

Set the locking and unlocking of cells for gravity tasks

parent 487a1f08
...@@ -58,7 +58,6 @@ const char *subtaskID_names[task_type_count] = {"none", "density", "force", ...@@ -58,7 +58,6 @@ const char *subtaskID_names[task_type_count] = {"none", "density", "force",
/** /**
* @brief Computes the overlap between the parts array of two given cells. * @brief Computes the overlap between the parts array of two given cells.
*/ */
size_t task_cell_overlap(const struct cell *ci, const struct cell *cj) { size_t task_cell_overlap(const struct cell *ci, const struct cell *cj) {
if (ci == NULL || cj == NULL) return 0; if (ci == NULL || cj == NULL) return 0;
if (ci->parts <= cj->parts && if (ci->parts <= cj->parts &&
...@@ -78,7 +77,6 @@ size_t task_cell_overlap(const struct cell *ci, const struct cell *cj) { ...@@ -78,7 +77,6 @@ size_t task_cell_overlap(const struct cell *ci, const struct cell *cj) {
* @param ta The first #task. * @param ta The first #task.
* @param tb The second #task. * @param tb The second #task.
*/ */
float task_overlap(const struct task *ta, const struct task *tb) { float task_overlap(const struct task *ta, const struct task *tb) {
/* First check if any of the two tasks are of a type that don't /* First check if any of the two tasks are of a type that don't
use cells. */ use cells. */
...@@ -110,25 +108,50 @@ float task_overlap(const struct task *ta, const struct task *tb) { ...@@ -110,25 +108,50 @@ float task_overlap(const struct task *ta, const struct task *tb) {
* *
* @param t The #task. * @param t The #task.
*/ */
void task_unlock(struct task *t) { void task_unlock(struct task *t) {
const int type = t->type;
const int subtype = t->subtype;
struct cell *ci = t->ci, *cj = t->cj;
/* Act based on task type. */ /* Act based on task type. */
switch (t->type) { switch (type) {
case task_type_self:
case task_type_sort: case task_type_sort:
cell_unlocktree(t->ci); cell_unlocktree(ci);
break;
case task_type_self:
if (subtype == task_subtype_grav) {
cell_gunlocktree(ci);
} else {
cell_unlocktree(ci);
}
break; break;
case task_type_pair: case task_type_pair:
if (subtype == task_subtype_grav) {
cell_gunlocktree(ci);
cell_gunlocktree(cj);
} else {
cell_unlocktree(ci);
cell_unlocktree(cj);
}
break;
case task_type_sub: case task_type_sub:
cell_unlocktree(t->ci); if (subtype == task_subtype_grav) {
if (t->cj != NULL) cell_unlocktree(t->cj); cell_gunlocktree(ci);
if (cj != NULL) cell_gunlocktree(cj);
} else {
cell_unlocktree(ci);
if (cj != NULL) cell_unlocktree(cj);
}
break; break;
// case task_type_grav_pp:
case task_type_grav_mm: case task_type_grav_mm:
// case task_type_grav_down: cell_gunlocktree(ci);
cell_gunlocktree(t->ci); cell_gunlocktree(cj);
if (t->cj != NULL) cell_gunlocktree(t->cj);
break; break;
default: default:
break; break;
...@@ -140,58 +163,104 @@ void task_unlock(struct task *t) { ...@@ -140,58 +163,104 @@ void task_unlock(struct task *t) {
* *
* @param t the #task. * @param t the #task.
*/ */
int task_lock(struct task *t) { int task_lock(struct task *t) {
int type = t->type; const int type = t->type;
const int subtype = t->subtype;
struct cell *ci = t->ci, *cj = t->cj; struct cell *ci = t->ci, *cj = t->cj;
#ifdef WITH_MPI
int res = 0, err = 0;
MPI_Status stat;
#endif
/* Communication task? */ switch (type) {
if (type == task_type_recv || type == task_type_send) {
/* Communication task? */
case task_type_recv:
case task_type_send:
#ifdef WITH_MPI #ifdef WITH_MPI
/* Check the status of the MPI request. */ /* Check the status of the MPI request. */
int res = 0, err = 0; if ((err = MPI_Test(&t->req, &res, &stat)) != MPI_SUCCESS) {
MPI_Status stat; char buff[MPI_MAX_ERROR_STRING];
if ((err = MPI_Test(&t->req, &res, &stat)) != MPI_SUCCESS) { int len;
char buff[MPI_MAX_ERROR_STRING]; MPI_Error_string(err, buff, &len);
int len; error("Failed to test request on send/recv task (tag=%i, %s).",
MPI_Error_string(err, buff, &len); t->flags, buff);
error("Failed to test request on send/recv task (tag=%i, %s).", t->flags, }
buff); return res;
}
return res;
#else #else
error("SWIFT was not compiled with MPI support."); error("SWIFT was not compiled with MPI support.");
#endif #endif
break;
} case task_type_sort:
if (cell_locktree(ci) != 0) return 0;
break;
/* Unary lock? */ case task_type_self:
else if (type == task_type_self || type == task_type_sort || if (subtype == task_subtype_grav) {
(type == task_type_sub && cj == NULL)) { if (cell_glocktree(ci) != 0) return 0;
if (cell_locktree(ci) != 0) return 0; } else {
} if (cell_locktree(ci) != 0) return 0;
}
break;
/* Otherwise, binary lock. */ case task_type_pair:
else if (type == task_type_pair || (type == task_type_sub && cj != NULL)) { if (subtype == task_subtype_grav) {
if (ci->hold || cj->hold) return 0; if (ci->ghold || cj->ghold) return 0;
if (cell_locktree(ci) != 0) return 0; if (cell_glocktree(ci) != 0) return 0;
if (cell_locktree(cj) != 0) { if (cell_glocktree(cj) != 0) {
cell_unlocktree(ci); cell_gunlocktree(ci);
return 0; return 0;
} }
} } else {
if (ci->hold || cj->hold) return 0;
if (cell_locktree(ci) != 0) return 0;
if (cell_locktree(cj) != 0) {
cell_unlocktree(ci);
return 0;
}
}
break;
/* Gravity tasks? */ case task_type_sub:
else if (type == task_type_grav_mm) { if (cj == NULL) { /* sub-self */
//|| type == task_type_grav_pp || type == task_type_grav_down) {
if (ci->ghold || (cj != NULL && cj->ghold)) return 0; if (subtype == task_subtype_grav) {
if (cell_glocktree(ci) != 0) return 0; if (cell_glocktree(ci) != 0) return 0;
if (cj != NULL && cell_glocktree(cj) != 0) { } else {
cell_gunlocktree(ci); if (cell_locktree(ci) != 0) return 0;
return 0; }
}
} else { /* Sub-pair */
if (subtype == task_subtype_grav) {
if (ci->ghold || cj->ghold) return 0;
if (cell_glocktree(ci) != 0) return 0;
if (cell_glocktree(cj) != 0) {
cell_gunlocktree(ci);
return 0;
}
} else {
if (ci->hold || cj->hold) return 0;
if (cell_locktree(ci) != 0) return 0;
if (cell_locktree(cj) != 0) {
cell_unlocktree(ci);
return 0;
}
}
}
break;
case task_type_grav_mm:
if (ci->ghold || cj->ghold) return 0;
if (cell_glocktree(ci) != 0) return 0;
if (cell_glocktree(cj) != 0) {
cell_gunlocktree(ci);
return 0;
}
default:
break;
} }
/* If we made it this far, we've got a lock. */ /* If we made it this far, we've got a lock. */
...@@ -204,7 +273,6 @@ int task_lock(struct task *t) { ...@@ -204,7 +273,6 @@ int task_lock(struct task *t) {
* @param t The #task. * @param t The #task.
* @param type The task type ID to remove. * @param type The task type ID to remove.
*/ */
void task_cleanunlock(struct task *t, int type) { void task_cleanunlock(struct task *t, int type) {
int k; int k;
...@@ -226,7 +294,6 @@ void task_cleanunlock(struct task *t, int type) { ...@@ -226,7 +294,6 @@ void task_cleanunlock(struct task *t, int type) {
* @param ta The unlocking #task. * @param ta The unlocking #task.
* @param tb The #task that will be unlocked. * @param tb The #task that will be unlocked.
*/ */
void task_rmunlock(struct task *ta, struct task *tb) { void task_rmunlock(struct task *ta, struct task *tb) {
int k; int k;
...@@ -252,7 +319,6 @@ void task_rmunlock(struct task *ta, struct task *tb) { ...@@ -252,7 +319,6 @@ void task_rmunlock(struct task *ta, struct task *tb) {
* Differs from #task_rmunlock in that it will not fail if * Differs from #task_rmunlock in that it will not fail if
* the task @c tb is not in the unlocks of @c ta. * the task @c tb is not in the unlocks of @c ta.
*/ */
void task_rmunlock_blind(struct task *ta, struct task *tb) { void task_rmunlock_blind(struct task *ta, struct task *tb) {
int k; int k;
...@@ -275,7 +341,6 @@ void task_rmunlock_blind(struct task *ta, struct task *tb) { ...@@ -275,7 +341,6 @@ void task_rmunlock_blind(struct task *ta, struct task *tb) {
* @param ta The unlocking #task. * @param ta The unlocking #task.
* @param tb The #task that will be unlocked. * @param tb The #task that will be unlocked.
*/ */
void task_addunlock(struct task *ta, struct task *tb) { void task_addunlock(struct task *ta, struct task *tb) {
error("Use sched_addunlock instead."); error("Use sched_addunlock instead.");
......
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