From 5ad98d9d7190718eb99178b29b4bbdd3ffb428e3 Mon Sep 17 00:00:00 2001
From: Matthieu Schaller <schaller@strw.leidenuniv.nl>
Date: Sun, 22 Jul 2018 20:50:45 +0100
Subject: [PATCH] Added functions to decide whether a gravity task associated
 to a given cell can be split.

---
 src/cell.c          |  6 +++---
 src/cell.h          | 37 +++++++++++++++++++++++++++++++++----
 src/runner_doiact.h | 14 +++++++-------
 src/scheduler.c     |  4 ++--
 4 files changed, 45 insertions(+), 16 deletions(-)

diff --git a/src/cell.c b/src/cell.c
index 8c4dafd960..e07d8612f2 100644
--- a/src/cell.c
+++ b/src/cell.c
@@ -1522,7 +1522,7 @@ void cell_activate_subcell_hydro_tasks(struct cell *ci, struct cell *cj,
     if (ci->count == 0 || !cell_is_active_hydro(ci, e)) return;
 
     /* Recurse? */
-    if (cell_can_recurse_in_self_task(ci)) {
+    if (cell_can_recurse_in_self_hydro_task(ci)) {
 
       /* Loop over all progenies and pairs of progenies */
       for (int j = 0; j < 8; j++) {
@@ -1553,8 +1553,8 @@ void cell_activate_subcell_hydro_tasks(struct cell *ci, struct cell *cj,
     int sid = space_getsid(s->space, &ci, &cj, shift);
 
     /* recurse? */
-    if (cell_can_recurse_in_pair_task(ci) &&
-        cell_can_recurse_in_pair_task(cj)) {
+    if (cell_can_recurse_in_pair_hydro_task(ci) &&
+        cell_can_recurse_in_pair_hydro_task(cj)) {
 
       /* Different types of flags. */
       switch (sid) {
diff --git a/src/cell.h b/src/cell.h
index d7e1a35beb..844b47b86f 100644
--- a/src/cell.h
+++ b/src/cell.h
@@ -538,7 +538,7 @@ int cell_can_use_pair_mm(const struct cell *ci, const struct cell *cj,
  *
  * @param c The #cell.
  */
-__attribute__((always_inline)) INLINE static int cell_can_recurse_in_pair_task(
+__attribute__((always_inline)) INLINE static int cell_can_recurse_in_pair_hydro_task(
     const struct cell *c) {
 
   /* Is the cell split ? */
@@ -555,7 +555,7 @@ __attribute__((always_inline)) INLINE static int cell_can_recurse_in_pair_task(
  *
  * @param c The #cell.
  */
-__attribute__((always_inline)) INLINE static int cell_can_recurse_in_self_task(
+__attribute__((always_inline)) INLINE static int cell_can_recurse_in_self_hydro_task(
     const struct cell *c) {
 
   /* Is the cell split and not smaller than the smoothing length? */
@@ -563,7 +563,7 @@ __attribute__((always_inline)) INLINE static int cell_can_recurse_in_self_task(
 }
 
 /**
- * @brief Can a pair task associated with a cell be split into smaller
+ * @brief Can a pair hydro task associated with a cell be split into smaller
  * sub-tasks.
  *
  * @param c The #cell.
@@ -580,7 +580,7 @@ __attribute__((always_inline)) INLINE static int cell_can_split_pair_hydro_task(
 }
 
 /**
- * @brief Can a self task associated with a cell be split into smaller
+ * @brief Can a self hydro task associated with a cell be split into smaller
  * sub-tasks.
  *
  * @param c The #cell.
@@ -589,11 +589,40 @@ __attribute__((always_inline)) INLINE static int cell_can_split_self_hydro_task(
     const struct cell *c) {
 
   /* Is the cell split ? */
+  /* If so, is the cut-off radius with some leeway smaller than */
+  /* the sub-cell sizes ? */
   /* Note: No need for more checks here as all the sub-pairs and sub-self */
   /* tasks will be created. So no need to check for h_max */
   return c->split && (space_stretch * kernel_gamma * c->h_max < 0.5f * c->dmin);
 }
 
+
+/**
+ * @brief Can a pair gravity task associated with a cell be split into smaller
+ * sub-tasks.
+ *
+ * @param c The #cell.
+ */
+__attribute__((always_inline)) INLINE static int cell_can_split_pair_gravity_task(
+    const struct cell *c) {
+
+  /* Is the cell split ? */
+  return c->split;
+}
+
+/**
+ * @brief Can a self gravity task associated with a cell be split into smaller
+ * sub-tasks.
+ *
+ * @param c The #cell.
+ */
+__attribute__((always_inline)) INLINE static int cell_can_split_self_gravity_task(
+    const struct cell *c) {
+
+  /* Is the cell split ? */
+  return c->split;
+}
+
 /**
  * @brief Have particles in a pair of cells moved too much and require a rebuild
  * ?
diff --git a/src/runner_doiact.h b/src/runner_doiact.h
index 2987d205e5..80f661502d 100644
--- a/src/runner_doiact.h
+++ b/src/runner_doiact.h
@@ -2086,7 +2086,7 @@ void DOSUB_PAIR1(struct runner *r, struct cell *ci, struct cell *cj, int sid,
   sid = space_getsid(s, &ci, &cj, shift);
 
   /* Recurse? */
-  if (cell_can_recurse_in_pair_task(ci) && cell_can_recurse_in_pair_task(cj)) {
+  if (cell_can_recurse_in_pair_hydro_task(ci) && cell_can_recurse_in_pair_hydro_task(cj)) {
 
     /* Different types of flags. */
     switch (sid) {
@@ -2323,7 +2323,7 @@ void DOSUB_SELF1(struct runner *r, struct cell *ci, int gettimer) {
   if (ci->count == 0 || !cell_is_active_hydro(ci, r->e)) return;
 
   /* Recurse? */
-  if (cell_can_recurse_in_self_task(ci)) {
+  if (cell_can_recurse_in_self_hydro_task(ci)) {
 
     /* Loop over all progeny. */
     for (int k = 0; k < 8; k++)
@@ -2376,7 +2376,7 @@ void DOSUB_PAIR2(struct runner *r, struct cell *ci, struct cell *cj, int sid,
   sid = space_getsid(s, &ci, &cj, shift);
 
   /* Recurse? */
-  if (cell_can_recurse_in_pair_task(ci) && cell_can_recurse_in_pair_task(cj)) {
+  if (cell_can_recurse_in_pair_hydro_task(ci) && cell_can_recurse_in_pair_hydro_task(cj)) {
 
     /* Different types of flags. */
     switch (sid) {
@@ -2613,7 +2613,7 @@ void DOSUB_SELF2(struct runner *r, struct cell *ci, int gettimer) {
   if (ci->count == 0 || !cell_is_active_hydro(ci, r->e)) return;
 
   /* Recurse? */
-  if (cell_can_recurse_in_self_task(ci)) {
+  if (cell_can_recurse_in_self_hydro_task(ci)) {
 
     /* Loop over all progeny. */
     for (int k = 0; k < 8; k++)
@@ -2665,7 +2665,7 @@ void DOSUB_SUBSET(struct runner *r, struct cell *ci, struct part *parts,
   if (cj == NULL) {
 
     /* Recurse? */
-    if (cell_can_recurse_in_self_task(ci)) {
+    if (cell_can_recurse_in_self_hydro_task(ci)) {
 
       /* Loop over all progeny. */
       DOSUB_SUBSET(r, sub, parts, ind, count, NULL, -1, 0);
@@ -2684,8 +2684,8 @@ void DOSUB_SUBSET(struct runner *r, struct cell *ci, struct part *parts,
   else {
 
     /* Recurse? */
-    if (cell_can_recurse_in_pair_task(ci) &&
-        cell_can_recurse_in_pair_task(cj)) {
+    if (cell_can_recurse_in_pair_hydro_task(ci) &&
+        cell_can_recurse_in_pair_hydro_task(cj)) {
 
       /* Get the type of pair if not specified explicitly. */
       double shift[3] = {0.0, 0.0, 0.0};
diff --git a/src/scheduler.c b/src/scheduler.c
index 8a21624aba..be3790beed 100644
--- a/src/scheduler.c
+++ b/src/scheduler.c
@@ -841,7 +841,7 @@ static void scheduler_splittask_gravity(struct task *t, struct scheduler *s) {
 #ifndef WITH_MPI
 
       /* Should we split this task? */
-      if (ci->split) {
+      if (cell_can_split_self_gravity_task(ci)) {
 
         if (scheduler_dosub && ci->gcount < space_subsize_self_grav) {
 
@@ -906,7 +906,7 @@ static void scheduler_splittask_gravity(struct task *t, struct scheduler *s) {
       }
 
       /* Should this task be split-up? */
-      if (ci->split && cj->split) {
+      if (cell_can_split_pair_gravity_task(ci) && cell_can_split_pair_gravity_task(cj)) {
 
         /* Replace by a single sub-task? */
         if (scheduler_dosub && /* Use division to avoid integer overflow. */
-- 
GitLab