diff --git a/src/cell.c b/src/cell.c index 25d5f21832132e31420d55f687024602a6cf262e..fd15cf25ef4782ecbcfc389c98778321a830d72e 100644 --- a/src/cell.c +++ b/src/cell.c @@ -1316,85 +1316,6 @@ int cell_is_drift_needed(struct cell *c, const struct engine *e) { return 0; } -/** - * @brief Can a sub-pair hydro task recurse to a lower level based - * on the status of the particles in the cell. - * - * @param c The #cell. - */ -int cell_can_recurse_in_pair_task(const struct cell *c) { - - /* Is the cell split ? */ - /* If so, is the cut-off radius plus the max distance the parts have moved */ - /* smaller than the sub-cell sizes ? */ - /* Note: We use the _old values as these might have been updated by a drift */ - return c->split && - ((kernel_gamma * c->h_max_old + c->dx_max_old) < 0.5f * c->dmin); -} - -/** - * @brief Can a sub-self hydro task recurse to a lower level based - * on the status of the particles in the cell. - * - * @param c The #cell. - */ -int cell_can_recurse_in_self_task(const struct cell *c) { - - /* Is the cell split ? */ - /* Note: No need for more checks here as all the sub-pairs and sub-self */ - /* operations will be executed. So no need for the particle to be at exactly - */ - /* the right place. */ - return c->split; -} - -/** - * @brief Can a pair task associated with a cell be split into smaller - * sub-tasks. - * - * @param c The #cell. - */ -int cell_can_split_pair_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 that since tasks are create after a rebuild no need to take */ - /* into account any part motion (i.e. dx_max == 0 here) */ - return c->split && (space_stretch * kernel_gamma * c->h_max < 0.5f * c->dmin); -} - -/** - * @brief Can a self task associated with a cell be split into smaller - * sub-tasks. - * - * @param c The #cell. - */ -int cell_can_split_self_task(const struct cell *c) { - - /* Is the cell split ? */ - /* 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; -} - -/** - * @brief Have particles in a pair of cells moved too much and require a rebuild - * ? - * - * @param ci The first #cell. - * @param cj The second #cell. - */ -int cell_need_rebuild_for_pair(const struct cell *ci, const struct cell *cj) { - - /* Is the cut-off radius plus the max distance the parts in both cells have */ - /* moved larger than the cell size ? */ - /* Note ci->dmin == cj->dmin */ - return (kernel_gamma * max(ci->h_max, cj->h_max) + ci->dx_max_part + - cj->dx_max_part > - cj->dmin); -} - /** * @brief Traverse a sub-cell task and activate the sort tasks along the way. */ diff --git a/src/cell.h b/src/cell.h index b13e8f65b09a8d7f9cbbfc097dd488f10bd52cc2..39b46dabfd2d2ff0eff6812e1b03e44694409225 100644 --- a/src/cell.h +++ b/src/cell.h @@ -31,15 +31,16 @@ /* Local includes. */ #include "align.h" +#include "kernel_hydro.h" #include "lock.h" #include "multipole.h" #include "part.h" +#include "space.h" #include "task.h" #include "timeline.h" /* Avoid cyclic inclusions */ struct engine; -struct space; struct scheduler; /* Max tag size set to 2^29 to take into account some MPI implementations @@ -388,10 +389,91 @@ void cell_check_timesteps(struct cell *c); void cell_store_pre_drift_values(struct cell *c); void cell_activate_subcell_tasks(struct cell *ci, struct cell *cj, struct scheduler *s); -int cell_can_recurse_in_pair_task(const struct cell *c); -int cell_can_recurse_in_self_task(const struct cell *c); -int cell_can_split_pair_task(const struct cell *c); -int cell_can_split_self_task(const struct cell *c); -int cell_need_rebuild_for_pair(const struct cell *ci, const struct cell *cj); + +/* Inlined functions (for speed). */ + +/** + * @brief Can a sub-pair hydro task recurse to a lower level based + * on the status of the particles in the cell. + * + * @param c The #cell. + */ +__attribute__((always_inline)) INLINE static int cell_can_recurse_in_pair_task( + const struct cell *c) { + + /* Is the cell split ? */ + /* If so, is the cut-off radius plus the max distance the parts have moved */ + /* smaller than the sub-cell sizes ? */ + /* Note: We use the _old values as these might have been updated by a drift */ + return c->split && + ((kernel_gamma * c->h_max_old + c->dx_max_old) < 0.5f * c->dmin); +} + +/** + * @brief Can a sub-self hydro task recurse to a lower level based + * on the status of the particles in the cell. + * + * @param c The #cell. + */ +__attribute__((always_inline)) INLINE static int cell_can_recurse_in_self_task( + const struct cell *c) { + + /* Is the cell split ? */ + /* Note: No need for more checks here as all the sub-pairs and sub-self */ + /* operations will be executed. So no need for the particle to be at exactly + */ + /* the right place. */ + return c->split; +} + +/** + * @brief Can a pair 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_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 that since tasks are create after a rebuild no need to take */ + /* into account any part motion (i.e. dx_max == 0 here) */ + return c->split && (space_stretch * kernel_gamma * c->h_max < 0.5f * c->dmin); +} + +/** + * @brief Can a self 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_task( + const struct cell *c) { + + /* Is the cell split ? */ + /* 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; +} + +/** + * @brief Have particles in a pair of cells moved too much and require a rebuild + * ? + * + * @param ci The first #cell. + * @param cj The second #cell. + */ +__attribute__((always_inline)) INLINE static int cell_need_rebuild_for_pair( + const struct cell *ci, const struct cell *cj) { + + /* Is the cut-off radius plus the max distance the parts in both cells have */ + /* moved larger than the cell size ? */ + /* Note ci->dmin == cj->dmin */ + return (kernel_gamma * max(ci->h_max, cj->h_max) + ci->dx_max_part + + cj->dx_max_part > + cj->dmin); +} #endif /* SWIFT_CELL_H */ diff --git a/src/space.h b/src/space.h index e8e8600349c97ff8a60f0fcf2964d6ec514a7589..6df85702644787e7ce9327af106820006c039c69 100644 --- a/src/space.h +++ b/src/space.h @@ -30,13 +30,15 @@ #include <stddef.h> /* Includes. */ -#include "cell.h" #include "hydro_space.h" #include "lock.h" #include "parser.h" #include "part.h" #include "space.h" +/* Avoid cyclic inclusions */ +struct cell; + /* Some constants. */ #define space_cellallocchunk 1000 #define space_splitsize_default 400