From 09563fa4ed546e02957a1f277b28d50ed03925e4 Mon Sep 17 00:00:00 2001 From: Pedro Gonnet Date: Wed, 17 Apr 2019 00:02:54 +0200 Subject: [PATCH 01/18] add an enum with the different cell flags (basically whatever was a char type and looked like a binary flag). will start replacing the cell values in the following commits. --- src/cell.h | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/src/cell.h b/src/cell.h index fdac39dfb..ee9bc5a30 100644 --- a/src/cell.h +++ b/src/cell.h @@ -220,6 +220,23 @@ struct pcell_step_black_holes { float dx_max_part; }; +/** Bitmasks for the cell flags. */ +enum cell_flags { + cell_flag_split = (1UL << 0), + cell_flag_do_hydro_drift = (1UL << 1), + cell_flag_do_hydro_sub_drift = (1UL << 2), + cell_flag_do_hydro_sub_sort = (1UL << 3), + cell_flag_do_limiter = (1UL << 4), + cell_flag_do_sub_limiter = (1UL << 5), + cell_flag_do_grav_drift = (1UL << 6), + cell_flag_do_grav_sub_drift = (1UL << 7), + cell_flag_do_stars_sub_sort = (1UL << 8), + cell_flag_do_stars_drift = (1UL << 9), + cell_flag_do_stars_sub_drift = (1UL << 10), + cell_flag_do_bh_drift = (1UL << 11), + cell_flag_do_bh_sub_drift = (1UL << 12) +}; + /** * @brief Cell within the tree structure. * @@ -247,6 +264,9 @@ struct cell { /*! Super cell, i.e. the highest-level parent cell with *any* task */ struct cell *super; + + /*! Cell flags bit-mask. */ + unsigned int flags; /*! Hydro variables */ struct { @@ -1300,4 +1320,17 @@ __attribute__((always_inline)) INLINE static void cell_free_stars_sorts( /* } */ } +/** Set the given flag for the given cell. */ +__attribute__((always_inline)) INLINE static void cell_set_flag( + struct cell *c, enum cell_flags flag) { + c->flags |= flag; + } + +/** Get the given flag for the given cell. */ +__attribute__((always_inline)) INLINE static int cell_get_flag( + struct cell *c, enum cell_flags flag) { + return (c->flags & flag) > 0; + } + + #endif /* SWIFT_CELL_H */ -- GitLab From 35872089ce82f8c1b16677b2f6619eb080bdf623 Mon Sep 17 00:00:00 2001 From: Pedro Gonnet Date: Thu, 18 Apr 2019 23:47:50 +0200 Subject: [PATCH 02/18] replace c->hydro.do_drift with cell_flag_do_hydro_drift. one down, 12 more to go. --- src/cell.c | 12 ++++++------ src/cell.h | 20 +++++++++++--------- 2 files changed, 17 insertions(+), 15 deletions(-) diff --git a/src/cell.c b/src/cell.c index 9e05d555c..e8a5313dd 100644 --- a/src/cell.c +++ b/src/cell.c @@ -2127,7 +2127,7 @@ void cell_clean(struct cell *c) { * @brief Clear the drift flags on the given cell. */ void cell_clear_drift_flags(struct cell *c, void *data) { - c->hydro.do_drift = 0; + cell_clear_flag(c, cell_flag_do_hydro_drift); c->hydro.do_sub_drift = 0; c->grav.do_drift = 0; c->grav.do_sub_drift = 0; @@ -2175,10 +2175,10 @@ void cell_activate_super_spart_drifts(struct cell *c, struct scheduler *s) { void cell_activate_drift_part(struct cell *c, struct scheduler *s) { /* If this cell is already marked for drift, quit early. */ - if (c->hydro.do_drift) return; + if (cell_get_flag(c, cell_flag_do_hydro_drift)) return; /* Mark this cell for drifting. */ - c->hydro.do_drift = 1; + cell_set_flag(c, cell_flag_do_hydro_drift); /* Set the do_sub_drifts all the way up and activate the super drift if this has not yet been done. */ @@ -4097,7 +4097,7 @@ void cell_drift_part(struct cell *c, const struct engine *e, int force) { float cell_h_max = 0.f; /* Drift irrespective of cell flags? */ - force |= c->hydro.do_drift; + force |= cell_get_flag(c, cell_flag_do_hydro_drift); #ifdef SWIFT_DEBUG_CHECKS /* Check that we only drift local cells. */ @@ -4111,7 +4111,7 @@ void cell_drift_part(struct cell *c, const struct engine *e, int force) { if (c->hydro.count == 0) { /* Clear the drift flags. */ - c->hydro.do_drift = 0; + cell_clear_flag(c, cell_flag_do_hydro_drift); c->hydro.do_sub_drift = 0; /* Update the time of the last drift */ @@ -4260,7 +4260,7 @@ void cell_drift_part(struct cell *c, const struct engine *e, int force) { } /* Clear the drift flags. */ - c->hydro.do_drift = 0; + cell_clear_flag(c, cell_flag_do_hydro_drift); c->hydro.do_sub_drift = 0; } diff --git a/src/cell.h b/src/cell.h index ee9bc5a30..fd9965ee9 100644 --- a/src/cell.h +++ b/src/cell.h @@ -264,7 +264,7 @@ struct cell { /*! Super cell, i.e. the highest-level parent cell with *any* task */ struct cell *super; - + /*! Cell flags bit-mask. */ unsigned int flags; @@ -382,9 +382,6 @@ struct cell { /*! Bit-mask indicating the sorted directions */ unsigned int sorted; - /*! Does this cell need to be drifted (hydro)? */ - char do_drift; - /*! Do any of this cell's sub-cells need to be drifted (hydro)? */ char do_sub_drift; @@ -1323,14 +1320,19 @@ __attribute__((always_inline)) INLINE static void cell_free_stars_sorts( /** Set the given flag for the given cell. */ __attribute__((always_inline)) INLINE static void cell_set_flag( struct cell *c, enum cell_flags flag) { - c->flags |= flag; - } + c->flags |= flag; +} + +/** Clear the given flag for the given cell. */ +__attribute__((always_inline)) INLINE static void cell_clear_flag( + struct cell *c, enum cell_flags flag) { + c->flags &= ~flag; +} /** Get the given flag for the given cell. */ __attribute__((always_inline)) INLINE static int cell_get_flag( struct cell *c, enum cell_flags flag) { - return (c->flags & flag) > 0; - } - + return (c->flags & flag) > 0; +} #endif /* SWIFT_CELL_H */ -- GitLab From 4e9a03d97786b8ad0ce813432685122c5461dbc4 Mon Sep 17 00:00:00 2001 From: Pedro Gonnet Date: Thu, 18 Apr 2019 23:58:41 +0200 Subject: [PATCH 03/18] replace c->hydro.do_sub_drift with cell_flag_do_hydro_sub_drift. --- src/cell.c | 15 ++++++--------- src/cell.h | 3 --- src/space.c | 4 ++-- 3 files changed, 8 insertions(+), 14 deletions(-) diff --git a/src/cell.c b/src/cell.c index e8a5313dd..5b0cde57d 100644 --- a/src/cell.c +++ b/src/cell.c @@ -2127,8 +2127,7 @@ void cell_clean(struct cell *c) { * @brief Clear the drift flags on the given cell. */ void cell_clear_drift_flags(struct cell *c, void *data) { - cell_clear_flag(c, cell_flag_do_hydro_drift); - c->hydro.do_sub_drift = 0; + cell_clear_flag(c, cell_flag_do_hydro_drift & cell_flag_do_hydro_sub_drift); c->grav.do_drift = 0; c->grav.do_sub_drift = 0; c->stars.do_drift = 0; @@ -2190,11 +2189,11 @@ void cell_activate_drift_part(struct cell *c, struct scheduler *s) { scheduler_activate(s, c->hydro.drift); } else { for (struct cell *parent = c->parent; - parent != NULL && !parent->hydro.do_sub_drift; + parent != NULL && !cell_get_flag(parent, cell_flag_do_hydro_sub_drift); parent = parent->parent) { /* Mark this cell for drifting */ - parent->hydro.do_sub_drift = 1; + cell_set_flag(parent, cell_flag_do_hydro_sub_drift); if (parent == c->hydro.super) { #ifdef SWIFT_DEBUG_CHECKS @@ -4111,8 +4110,7 @@ void cell_drift_part(struct cell *c, const struct engine *e, int force) { if (c->hydro.count == 0) { /* Clear the drift flags. */ - cell_clear_flag(c, cell_flag_do_hydro_drift); - c->hydro.do_sub_drift = 0; + cell_clear_flag(c, cell_flag_do_hydro_drift & cell_flag_do_hydro_sub_drift); /* Update the time of the last drift */ c->hydro.ti_old_part = ti_current; @@ -4123,7 +4121,7 @@ void cell_drift_part(struct cell *c, const struct engine *e, int force) { /* Ok, we have some particles somewhere in the hierarchy to drift */ /* Are we not in a leaf ? */ - if (c->split && (force || c->hydro.do_sub_drift)) { + if (c->split && (force || cell_get_flag(c, cell_flag_do_hydro_sub_drift))) { /* Loop over the progeny and collect their data. */ for (int k = 0; k < 8; k++) { @@ -4260,8 +4258,7 @@ void cell_drift_part(struct cell *c, const struct engine *e, int force) { } /* Clear the drift flags. */ - cell_clear_flag(c, cell_flag_do_hydro_drift); - c->hydro.do_sub_drift = 0; + cell_clear_flag(c, cell_flag_do_hydro_drift & cell_flag_do_hydro_sub_drift); } /** diff --git a/src/cell.h b/src/cell.h index fd9965ee9..218d3d451 100644 --- a/src/cell.h +++ b/src/cell.h @@ -382,9 +382,6 @@ struct cell { /*! Bit-mask indicating the sorted directions */ unsigned int sorted; - /*! Do any of this cell's sub-cells need to be drifted (hydro)? */ - char do_sub_drift; - /*! Do any of this cell's sub-cells need to be sorted? */ char do_sub_sort; diff --git a/src/space.c b/src/space.c index ea1d45384..660a6a42a 100644 --- a/src/space.c +++ b/src/space.c @@ -259,7 +259,7 @@ void space_rebuild_recycle_mapper(void *map_data, int num_elements, c->black_holes.parts = NULL; c->hydro.do_sub_sort = 0; c->stars.do_sub_sort = 0; - c->hydro.do_sub_drift = 0; + c->flags = 0; c->grav.do_sub_drift = 0; c->stars.do_sub_drift = 0; c->black_holes.do_sub_drift = 0; @@ -3326,7 +3326,7 @@ void space_split_recursive(struct space *s, struct cell *c, cp->hydro.do_sub_sort = 0; cp->stars.do_sub_sort = 0; cp->grav.do_sub_drift = 0; - cp->hydro.do_sub_drift = 0; + cp->flags = 0; cp->stars.do_sub_drift = 0; cp->black_holes.do_sub_drift = 0; cp->hydro.do_sub_limiter = 0; -- GitLab From 635b7e8d2254279414ff3965eb9e74d8ca17f0b6 Mon Sep 17 00:00:00 2001 From: Pedro Gonnet Date: Fri, 19 Apr 2019 00:03:06 +0200 Subject: [PATCH 04/18] replace c->hydro.do_sub_sort with cell_flag_do_hydro_sub_sort. --- src/cell.c | 4 ++-- src/cell.h | 3 --- src/runner.c | 4 ++-- src/space.c | 2 -- 4 files changed, 4 insertions(+), 9 deletions(-) diff --git a/src/cell.c b/src/cell.c index 5b0cde57d..ec456bb64 100644 --- a/src/cell.c +++ b/src/cell.c @@ -2343,9 +2343,9 @@ void cell_activate_hydro_sorts_up(struct cell *c, struct scheduler *s) { } else { for (struct cell *parent = c->parent; - parent != NULL && !parent->hydro.do_sub_sort; + parent != NULL && !cell_get_flag(parent, cell_flag_dohydro_sub_sort); parent = parent->parent) { - parent->hydro.do_sub_sort = 1; + cell_set_flag(parent, cell_flag_do_hydro_sub_sort); if (parent == c->hydro.super) { #ifdef SWIFT_DEBUG_CHECKS if (parent->hydro.sorts == NULL) diff --git a/src/cell.h b/src/cell.h index 218d3d451..3f351ffda 100644 --- a/src/cell.h +++ b/src/cell.h @@ -382,9 +382,6 @@ struct cell { /*! Bit-mask indicating the sorted directions */ unsigned int sorted; - /*! Do any of this cell's sub-cells need to be sorted? */ - char do_sub_sort; - /*! Does this cell need to be limited? */ char do_limiter; diff --git a/src/runner.c b/src/runner.c index 13a2d9c0f..4a3019e02 100644 --- a/src/runner.c +++ b/src/runner.c @@ -836,7 +836,7 @@ void runner_do_hydro_sort(struct runner *r, struct cell *c, int flags, } else { flags &= ~c->hydro.sorted; } - if (flags == 0 && !c->hydro.do_sub_sort) return; + if (flags == 0 && !cell_get_flag(c, cell_flag_do_hydro_sub_sort)) return; /* Check that the particles have been moved to the current time */ if (flags && !cell_are_part_drifted(c, r->e)) @@ -1019,7 +1019,7 @@ void runner_do_hydro_sort(struct runner *r, struct cell *c, int flags, /* Clear the cell's sort flags. */ c->hydro.do_sort = 0; - c->hydro.do_sub_sort = 0; + cell_clear_flag(c, cell_flag_do_hydro_sub_sort); c->hydro.requires_sorts = 0; if (clock) TIMER_TOC(timer_dosort); diff --git a/src/space.c b/src/space.c index 660a6a42a..64630008b 100644 --- a/src/space.c +++ b/src/space.c @@ -257,7 +257,6 @@ void space_rebuild_recycle_mapper(void *map_data, int num_elements, c->grav.parts = NULL; c->stars.parts = NULL; c->black_holes.parts = NULL; - c->hydro.do_sub_sort = 0; c->stars.do_sub_sort = 0; c->flags = 0; c->grav.do_sub_drift = 0; @@ -3323,7 +3322,6 @@ void space_split_recursive(struct space *s, struct cell *c, cp->super = NULL; cp->hydro.super = NULL; cp->grav.super = NULL; - cp->hydro.do_sub_sort = 0; cp->stars.do_sub_sort = 0; cp->grav.do_sub_drift = 0; cp->flags = 0; -- GitLab From 6213bf368cef869cc5270e4abeed69c4ea00896d Mon Sep 17 00:00:00 2001 From: Pedro Gonnet Date: Fri, 19 Apr 2019 00:07:35 +0200 Subject: [PATCH 05/18] typo. --- src/cell.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/cell.c b/src/cell.c index ec456bb64..77b46f2ca 100644 --- a/src/cell.c +++ b/src/cell.c @@ -2343,7 +2343,7 @@ void cell_activate_hydro_sorts_up(struct cell *c, struct scheduler *s) { } else { for (struct cell *parent = c->parent; - parent != NULL && !cell_get_flag(parent, cell_flag_dohydro_sub_sort); + parent != NULL && !cell_get_flag(parent, cell_flag_do_hydro_sub_sort); parent = parent->parent) { cell_set_flag(parent, cell_flag_do_hydro_sub_sort); if (parent == c->hydro.super) { -- GitLab From 47dcf288d9f0b12d39b6dc772fb3dd5e77607ccc Mon Sep 17 00:00:00 2001 From: Pedro Gonnet Date: Fri, 19 Apr 2019 00:15:30 +0200 Subject: [PATCH 06/18] replace c->hydro.do_limiter with cell_flag_do_hydro_limiter. --- src/cell.c | 6 +++--- src/cell.h | 7 ++----- src/runner.c | 6 +++--- src/space.c | 2 -- 4 files changed, 8 insertions(+), 13 deletions(-) diff --git a/src/cell.c b/src/cell.c index 77b46f2ca..eed219e0c 100644 --- a/src/cell.c +++ b/src/cell.c @@ -2138,7 +2138,7 @@ void cell_clear_drift_flags(struct cell *c, void *data) { * @brief Clear the limiter flags on the given cell. */ void cell_clear_limiter_flags(struct cell *c, void *data) { - c->hydro.do_limiter = 0; + cell_clear_flag(c, cell_flag_do_hydro_limiter); c->hydro.do_sub_limiter = 0; } @@ -2295,10 +2295,10 @@ void cell_activate_drift_spart(struct cell *c, struct scheduler *s) { void cell_activate_limiter(struct cell *c, struct scheduler *s) { /* If this cell is already marked for limiting, quit early. */ - if (c->hydro.do_limiter) return; + if (cell_get_flag(c, cell_flag_do_hydro_limiter)) return; /* Mark this cell for limiting. */ - c->hydro.do_limiter = 1; + cell_set_flag(c, cell_flag_do_hydro_limiter); /* Set the do_sub_limiter all the way up and activate the super limiter if this has not yet been done. */ diff --git a/src/cell.h b/src/cell.h index 3f351ffda..de624e204 100644 --- a/src/cell.h +++ b/src/cell.h @@ -226,8 +226,8 @@ enum cell_flags { cell_flag_do_hydro_drift = (1UL << 1), cell_flag_do_hydro_sub_drift = (1UL << 2), cell_flag_do_hydro_sub_sort = (1UL << 3), - cell_flag_do_limiter = (1UL << 4), - cell_flag_do_sub_limiter = (1UL << 5), + cell_flag_do_hydro_limiter = (1UL << 4), + cell_flag_do_hydro_sub_limiter = (1UL << 5), cell_flag_do_grav_drift = (1UL << 6), cell_flag_do_grav_sub_drift = (1UL << 7), cell_flag_do_stars_sub_sort = (1UL << 8), @@ -382,9 +382,6 @@ struct cell { /*! Bit-mask indicating the sorted directions */ unsigned int sorted; - /*! Does this cell need to be limited? */ - char do_limiter; - /*! Do any of this cell's sub-cells need to be limited? */ char do_sub_limiter; diff --git a/src/runner.c b/src/runner.c index 4a3019e02..113aa4753 100644 --- a/src/runner.c +++ b/src/runner.c @@ -2865,13 +2865,13 @@ void runner_do_limiter(struct runner *r, struct cell *c, int force, int timer) { ti_gravity_beg_max = 0; /* Limit irrespective of cell flags? */ - force |= c->hydro.do_limiter; + force |= cell_get_flag(c, cell_flag_do_hydro_limiter); /* Early abort? */ if (c->hydro.count == 0) { /* Clear the limiter flags. */ - c->hydro.do_limiter = 0; + cell_clear_flag(c, cell_flag_do_hydro_limiter); c->hydro.do_sub_limiter = 0; return; } @@ -2967,7 +2967,7 @@ void runner_do_limiter(struct runner *r, struct cell *c, int force, int timer) { } /* Clear the limiter flags. */ - c->hydro.do_limiter = 0; + cell_clear_flag(c, cell_flag_do_hydro_limiter); c->hydro.do_sub_limiter = 0; if (timer) TIMER_TOC(timer_do_limiter); diff --git a/src/space.c b/src/space.c index 64630008b..c31d2dfbd 100644 --- a/src/space.c +++ b/src/space.c @@ -263,7 +263,6 @@ void space_rebuild_recycle_mapper(void *map_data, int num_elements, c->stars.do_sub_drift = 0; c->black_holes.do_sub_drift = 0; c->hydro.do_sub_limiter = 0; - c->hydro.do_limiter = 0; c->hydro.ti_end_min = -1; c->hydro.ti_end_max = -1; c->grav.ti_end_min = -1; @@ -3328,7 +3327,6 @@ void space_split_recursive(struct space *s, struct cell *c, cp->stars.do_sub_drift = 0; cp->black_holes.do_sub_drift = 0; cp->hydro.do_sub_limiter = 0; - cp->hydro.do_limiter = 0; #ifdef WITH_MPI cp->mpi.tag = -1; #endif // WITH_MPI -- GitLab From c66f6f88264d27fc8e234a53ed2fb5ba2ca53b67 Mon Sep 17 00:00:00 2001 From: Pedro Gonnet Date: Fri, 19 Apr 2019 00:31:56 +0200 Subject: [PATCH 07/18] replace c->hydro.do_sub_limiter with cell_flag_do_hydro_sub_limiter. also use uint16_t for the sort masks. --- src/cell.c | 9 +++++---- src/cell.h | 20 +++++++++----------- src/runner.c | 10 +++++----- src/space.c | 2 -- 4 files changed, 19 insertions(+), 22 deletions(-) diff --git a/src/cell.c b/src/cell.c index eed219e0c..8c25b17f9 100644 --- a/src/cell.c +++ b/src/cell.c @@ -2138,8 +2138,8 @@ void cell_clear_drift_flags(struct cell *c, void *data) { * @brief Clear the limiter flags on the given cell. */ void cell_clear_limiter_flags(struct cell *c, void *data) { - cell_clear_flag(c, cell_flag_do_hydro_limiter); - c->hydro.do_sub_limiter = 0; + cell_clear_flag(c, + cell_flag_do_hydro_limiter & cell_flag_do_hydro_sub_limiter); } /** @@ -2310,11 +2310,12 @@ void cell_activate_limiter(struct cell *c, struct scheduler *s) { scheduler_activate(s, c->timestep_limiter); } else { for (struct cell *parent = c->parent; - parent != NULL && !parent->hydro.do_sub_limiter; + parent != NULL && + !cell_get_flag(parent, cell_flag_do_hydro_sub_limiter); parent = parent->parent) { /* Mark this cell for limiting */ - parent->hydro.do_sub_limiter = 1; + cell_set_flag(parent, cell_flag_do_hydro_sub_limiter); if (parent == c->super) { #ifdef SWIFT_DEBUG_CHECKS diff --git a/src/cell.h b/src/cell.h index de624e204..b31a229dc 100644 --- a/src/cell.h +++ b/src/cell.h @@ -28,6 +28,7 @@ /* Includes. */ #include +#include /* Local includes. */ #include "align.h" @@ -374,16 +375,13 @@ struct cell { int hold; /*! Bit mask of sort directions that will be needed in the next timestep. */ - unsigned int requires_sorts; + uint16_t requires_sorts; /*! Bit mask of sorts that need to be computed for this cell. */ - unsigned int do_sort; + uint16_t do_sort; /*! Bit-mask indicating the sorted directions */ - unsigned int sorted; - - /*! Do any of this cell's sub-cells need to be limited? */ - char do_sub_limiter; + uint16_t sorted; #ifdef SWIFT_DEBUG_CHECKS @@ -552,18 +550,18 @@ struct cell { /*! Values of dx_max_sort before the drifts, used for sub-cell tasks. */ float dx_max_sort_old; - /*! Bit mask of sort directions that will be needed in the next timestep. */ - unsigned int requires_sorts; - /*! Pointer for the sorted indices. */ struct entry *sort[13]; struct entry *sortptr; + /*! Bit mask of sort directions that will be needed in the next timestep. */ + uint16_t requires_sorts; + /*! Bit-mask indicating the sorted directions */ - unsigned int sorted; + uint16_t sorted; /*! Bit mask of sorts that need to be computed for this cell. */ - unsigned int do_sort; + uint16_t do_sort; /*! Do any of this cell's sub-cells need to be sorted? */ char do_sub_sort; diff --git a/src/runner.c b/src/runner.c index 113aa4753..b9c6f1519 100644 --- a/src/runner.c +++ b/src/runner.c @@ -2871,13 +2871,13 @@ void runner_do_limiter(struct runner *r, struct cell *c, int force, int timer) { if (c->hydro.count == 0) { /* Clear the limiter flags. */ - cell_clear_flag(c, cell_flag_do_hydro_limiter); - c->hydro.do_sub_limiter = 0; + cell_clear_flag( + c, cell_flag_do_hydro_limiter & cell_flag_do_hydro_sub_limiter); return; } /* Loop over the progeny ? */ - if (c->split && (force || c->hydro.do_sub_limiter)) { + if (c->split && (force || cell_get_flag(c, cell_flag_do_hydro_sub_limiter))) { for (int k = 0; k < 8; k++) { if (c->progeny[k] != NULL) { struct cell *restrict cp = c->progeny[k]; @@ -2967,8 +2967,8 @@ void runner_do_limiter(struct runner *r, struct cell *c, int force, int timer) { } /* Clear the limiter flags. */ - cell_clear_flag(c, cell_flag_do_hydro_limiter); - c->hydro.do_sub_limiter = 0; + cell_clear_flag(c, + cell_flag_do_hydro_limiter & cell_flag_do_hydro_sub_limiter); if (timer) TIMER_TOC(timer_do_limiter); } diff --git a/src/space.c b/src/space.c index c31d2dfbd..5dfbab9ac 100644 --- a/src/space.c +++ b/src/space.c @@ -262,7 +262,6 @@ void space_rebuild_recycle_mapper(void *map_data, int num_elements, c->grav.do_sub_drift = 0; c->stars.do_sub_drift = 0; c->black_holes.do_sub_drift = 0; - c->hydro.do_sub_limiter = 0; c->hydro.ti_end_min = -1; c->hydro.ti_end_max = -1; c->grav.ti_end_min = -1; @@ -3326,7 +3325,6 @@ void space_split_recursive(struct space *s, struct cell *c, cp->flags = 0; cp->stars.do_sub_drift = 0; cp->black_holes.do_sub_drift = 0; - cp->hydro.do_sub_limiter = 0; #ifdef WITH_MPI cp->mpi.tag = -1; #endif // WITH_MPI -- GitLab From 186d76abfbd8e7b8711be0637b4d91e9037c2c73 Mon Sep 17 00:00:00 2001 From: Pedro Gonnet Date: Mon, 22 Apr 2019 23:01:32 +0200 Subject: [PATCH 08/18] replace c->grav.do_drift and do_sub_drift with cell_flag_do_grav_drift and do_grav_sub_drift. --- src/cell.c | 23 ++++++++++------------- src/cell.h | 6 ------ src/space.c | 2 -- 3 files changed, 10 insertions(+), 21 deletions(-) diff --git a/src/cell.c b/src/cell.c index 8c25b17f9..427dee32a 100644 --- a/src/cell.c +++ b/src/cell.c @@ -2127,9 +2127,8 @@ void cell_clean(struct cell *c) { * @brief Clear the drift flags on the given cell. */ void cell_clear_drift_flags(struct cell *c, void *data) { - cell_clear_flag(c, cell_flag_do_hydro_drift & cell_flag_do_hydro_sub_drift); - c->grav.do_drift = 0; - c->grav.do_sub_drift = 0; + cell_clear_flag(c, cell_flag_do_hydro_drift & cell_flag_do_hydro_sub_drift & + cell_flag_do_grav_drift & cell_flag_do_grav_sub_drift); c->stars.do_drift = 0; c->stars.do_sub_drift = 0; } @@ -2213,10 +2212,10 @@ void cell_activate_drift_part(struct cell *c, struct scheduler *s) { void cell_activate_drift_gpart(struct cell *c, struct scheduler *s) { /* If this cell is already marked for drift, quit early. */ - if (c->grav.do_drift) return; + if (cell_get_flag(c, cell_flag_do_grav_drift)) return; /* Mark this cell for drifting. */ - c->grav.do_drift = 1; + cell_set_flag(c, cell_flag_do_grav_drift); if (c->grav.drift_out != NULL) scheduler_activate(s, c->grav.drift_out); @@ -2230,9 +2229,9 @@ void cell_activate_drift_gpart(struct cell *c, struct scheduler *s) { scheduler_activate(s, c->grav.drift); } else { for (struct cell *parent = c->parent; - parent != NULL && !parent->grav.do_sub_drift; + parent != NULL && !cell_get_flag(parent, cell_flag_do_grav_sub_drift); parent = parent->parent) { - parent->grav.do_sub_drift = 1; + cell_set_flag(parent, cell_flag_do_grav_sub_drift); if (parent->grav.drift_out) { scheduler_activate(s, parent->grav.drift_out); @@ -4279,7 +4278,7 @@ void cell_drift_gpart(struct cell *c, const struct engine *e, int force) { struct gpart *const gparts = c->grav.parts; /* Drift irrespective of cell flags? */ - force |= c->grav.do_drift; + force |= cell_get_flag(c, cell_flag_do_grav_drift); #ifdef SWIFT_DEBUG_CHECKS /* Check that we only drift local cells. */ @@ -4293,8 +4292,7 @@ void cell_drift_gpart(struct cell *c, const struct engine *e, int force) { if (c->grav.count == 0) { /* Clear the drift flags. */ - c->grav.do_drift = 0; - c->grav.do_sub_drift = 0; + cell_clear_flag(c, cell_flag_do_grav_drift & cell_flag_do_grav_sub_drift); /* Update the time of the last drift */ c->grav.ti_old_part = ti_current; @@ -4305,7 +4303,7 @@ void cell_drift_gpart(struct cell *c, const struct engine *e, int force) { /* Ok, we have some particles somewhere in the hierarchy to drift */ /* Are we not in a leaf ? */ - if (c->split && (force || c->grav.do_sub_drift)) { + if (c->split && (force || cell_get_flag(c, cell_flag_do_grav_sub_drift))) { /* Loop over the progeny and collect their data. */ for (int k = 0; k < 8; k++) { @@ -4379,8 +4377,7 @@ void cell_drift_gpart(struct cell *c, const struct engine *e, int force) { } /* Clear the drift flags. */ - c->grav.do_drift = 0; - c->grav.do_sub_drift = 0; + cell_clear_flag(c, cell_flag_do_grav_drift & cell_flag_do_grav_sub_drift); } /** diff --git a/src/cell.h b/src/cell.h index b31a229dc..7e2abf253 100644 --- a/src/cell.h +++ b/src/cell.h @@ -481,12 +481,6 @@ struct cell { /*! Number of M-M tasks that are associated with this cell. */ short int nr_mm_tasks; - /*! Does this cell need to be drifted (gravity)? */ - char do_drift; - - /*! Do any of this cell's sub-cells need to be drifted (gravity)? */ - char do_sub_drift; - } grav; /*! Stars variables */ diff --git a/src/space.c b/src/space.c index 5dfbab9ac..5904208fe 100644 --- a/src/space.c +++ b/src/space.c @@ -259,7 +259,6 @@ void space_rebuild_recycle_mapper(void *map_data, int num_elements, c->black_holes.parts = NULL; c->stars.do_sub_sort = 0; c->flags = 0; - c->grav.do_sub_drift = 0; c->stars.do_sub_drift = 0; c->black_holes.do_sub_drift = 0; c->hydro.ti_end_min = -1; @@ -3321,7 +3320,6 @@ void space_split_recursive(struct space *s, struct cell *c, cp->hydro.super = NULL; cp->grav.super = NULL; cp->stars.do_sub_sort = 0; - cp->grav.do_sub_drift = 0; cp->flags = 0; cp->stars.do_sub_drift = 0; cp->black_holes.do_sub_drift = 0; -- GitLab From a3b399365143511cd3c7cb075cbb047a382a7e02 Mon Sep 17 00:00:00 2001 From: Pedro Gonnet Date: Mon, 22 Apr 2019 23:45:24 +0200 Subject: [PATCH 09/18] replace c->stars.do_stars_sub_sort, do_drift and do_sub_drift with cell_flag_do_stars_sub_sort, do_grav_drift and do_grav_sub_drift, respectively. --- src/cell.c | 28 +++++++++++++--------------- src/cell.h | 14 +++++--------- src/runner.c | 4 ++-- src/space.c | 4 ---- 4 files changed, 20 insertions(+), 30 deletions(-) diff --git a/src/cell.c b/src/cell.c index 427dee32a..aa067e213 100644 --- a/src/cell.c +++ b/src/cell.c @@ -2128,9 +2128,9 @@ void cell_clean(struct cell *c) { */ void cell_clear_drift_flags(struct cell *c, void *data) { cell_clear_flag(c, cell_flag_do_hydro_drift & cell_flag_do_hydro_sub_drift & - cell_flag_do_grav_drift & cell_flag_do_grav_sub_drift); - c->stars.do_drift = 0; - c->stars.do_sub_drift = 0; + cell_flag_do_grav_drift & cell_flag_do_grav_sub_drift & + cell_flag_do_stars_drift & + cell_flag_do_stars_sub_drift); } /** @@ -2255,10 +2255,10 @@ void cell_activate_drift_gpart(struct cell *c, struct scheduler *s) { void cell_activate_drift_spart(struct cell *c, struct scheduler *s) { /* If this cell is already marked for drift, quit early. */ - if (c->stars.do_drift) return; + if (cell_get_flag(c, cell_flag_do_stars_drift)) return; /* Mark this cell for drifting. */ - c->stars.do_drift = 1; + cell_set_flag(c, cell_flag_do_stars_drift); /* Set the do_stars_sub_drifts all the way up and activate the super drift if this has not yet been done. */ @@ -2270,11 +2270,11 @@ void cell_activate_drift_spart(struct cell *c, struct scheduler *s) { scheduler_activate(s, c->stars.drift); } else { for (struct cell *parent = c->parent; - parent != NULL && !parent->stars.do_sub_drift; + parent != NULL && !cell_get_flag(parent, cell_flag_do_stars_sub_drift); parent = parent->parent) { /* Mark this cell for drifting */ - parent->stars.do_sub_drift = 1; + cell_set_flag(parent, cell_flag_do_stars_sub_drift); if (parent == c->hydro.super) { #ifdef SWIFT_DEBUG_CHECKS @@ -2403,9 +2403,9 @@ void cell_activate_stars_sorts_up(struct cell *c, struct scheduler *s) { } else { for (struct cell *parent = c->parent; - parent != NULL && !parent->stars.do_sub_sort; + parent != NULL && !cell_get_flag(parent, cell_flag_do_stars_sub_sort); parent = parent->parent) { - parent->stars.do_sub_sort = 1; + cell_set_flag(parent, cell_flag_do_stars_sub_sort); if (parent == c->hydro.super) { #ifdef SWIFT_DEBUG_CHECKS if (parent->stars.sorts == NULL) @@ -4403,7 +4403,7 @@ void cell_drift_spart(struct cell *c, const struct engine *e, int force) { float cell_h_max = 0.f; /* Drift irrespective of cell flags? */ - force |= c->stars.do_drift; + force |= cell_get_flag(c, cell_flag_do_stars_drift); #ifdef SWIFT_DEBUG_CHECKS /* Check that we only drift local cells. */ @@ -4417,8 +4417,7 @@ void cell_drift_spart(struct cell *c, const struct engine *e, int force) { if (c->stars.count == 0) { /* Clear the drift flags. */ - c->stars.do_drift = 0; - c->stars.do_sub_drift = 0; + cell_clear_flag(c, cell_flag_do_stars_drift & cell_flag_do_stars_sub_drift); /* Update the time of the last drift */ c->stars.ti_old_part = ti_current; @@ -4429,7 +4428,7 @@ void cell_drift_spart(struct cell *c, const struct engine *e, int force) { /* Ok, we have some particles somewhere in the hierarchy to drift */ /* Are we not in a leaf ? */ - if (c->split && (force || c->stars.do_sub_drift)) { + if (c->split && (force || cell_get_flag(c, cell_flag_do_stars_sub_drift))) { /* Loop over the progeny and collect their data. */ for (int k = 0; k < 8; k++) { @@ -4545,8 +4544,7 @@ void cell_drift_spart(struct cell *c, const struct engine *e, int force) { } /* Clear the drift flags. */ - c->stars.do_drift = 0; - c->stars.do_sub_drift = 0; + cell_clear_flag(c, cell_flag_do_stars_drift & cell_flag_do_stars_sub_drift); } /** diff --git a/src/cell.h b/src/cell.h index 7e2abf253..8d13a2257 100644 --- a/src/cell.h +++ b/src/cell.h @@ -557,9 +557,6 @@ struct cell { /*! Bit mask of sorts that need to be computed for this cell. */ uint16_t do_sort; - /*! Do any of this cell's sub-cells need to be sorted? */ - char do_sub_sort; - /*! Maximum end of (integer) time step in this cell for star tasks. */ integertime_t ti_end_min; @@ -579,12 +576,6 @@ struct cell { /*! Is the #spart data of this cell being used in a sub-cell? */ int hold; - /*! Does this cell need to be drifted (stars)? */ - char do_drift; - - /*! Do any of this cell's sub-cells need to be drifted (stars)? */ - char do_sub_drift; - #ifdef SWIFT_DEBUG_CHECKS /*! Last (integer) time the cell's sort arrays were updated. */ integertime_t ti_sort; @@ -1306,6 +1297,11 @@ __attribute__((always_inline)) INLINE static void cell_set_flag( c->flags |= flag; } +__attribute__((always_inline)) INLINE static void cell_set_flag_threadsafe( + struct cell *c, enum cell_flags flag) { + atomic_or(&c->flags, flag); +} + /** Clear the given flag for the given cell. */ __attribute__((always_inline)) INLINE static void cell_clear_flag( struct cell *c, enum cell_flags flag) { diff --git a/src/runner.c b/src/runner.c index b9c6f1519..fadea44e4 100644 --- a/src/runner.c +++ b/src/runner.c @@ -1058,7 +1058,7 @@ void runner_do_stars_sort(struct runner *r, struct cell *c, int flags, } else { flags &= ~c->stars.sorted; } - if (flags == 0 && !c->stars.do_sub_sort) return; + if (flags == 0 && !cell_get_flag(c, cell_flag_do_stars_sub_sort)) return; /* Check that the particles have been moved to the current time */ if (flags && !cell_are_spart_drifted(c, r->e)) { @@ -1236,7 +1236,7 @@ void runner_do_stars_sort(struct runner *r, struct cell *c, int flags, /* Clear the cell's sort flags. */ c->stars.do_sort = 0; - c->stars.do_sub_sort = 0; + cell_clear_flag(c, cell_flag_do_stars_sub_sort); c->stars.requires_sorts = 0; if (clock) TIMER_TOC(timer_do_stars_sort); diff --git a/src/space.c b/src/space.c index 5904208fe..166c8b426 100644 --- a/src/space.c +++ b/src/space.c @@ -257,9 +257,7 @@ void space_rebuild_recycle_mapper(void *map_data, int num_elements, c->grav.parts = NULL; c->stars.parts = NULL; c->black_holes.parts = NULL; - c->stars.do_sub_sort = 0; c->flags = 0; - c->stars.do_sub_drift = 0; c->black_holes.do_sub_drift = 0; c->hydro.ti_end_min = -1; c->hydro.ti_end_max = -1; @@ -3319,9 +3317,7 @@ void space_split_recursive(struct space *s, struct cell *c, cp->super = NULL; cp->hydro.super = NULL; cp->grav.super = NULL; - cp->stars.do_sub_sort = 0; cp->flags = 0; - cp->stars.do_sub_drift = 0; cp->black_holes.do_sub_drift = 0; #ifdef WITH_MPI cp->mpi.tag = -1; -- GitLab From 81181f5fb185ad33a19e7d86a296136d2da0afc1 Mon Sep 17 00:00:00 2001 From: Pedro Gonnet Date: Mon, 22 Apr 2019 23:52:36 +0200 Subject: [PATCH 10/18] replace c->black_holes.do_drift and do_sub_drift with cell_flag_do_bh_drift and do_bh_sub_drift. --- src/cell.c | 10 ++++------ src/cell.h | 11 ----------- src/space.c | 2 -- 3 files changed, 4 insertions(+), 19 deletions(-) diff --git a/src/cell.c b/src/cell.c index aa067e213..f6eb88b53 100644 --- a/src/cell.c +++ b/src/cell.c @@ -4569,7 +4569,7 @@ void cell_drift_bpart(struct cell *c, const struct engine *e, int force) { float cell_h_max = 0.f; /* Drift irrespective of cell flags? */ - force |= c->black_holes.do_drift; + force |= cell_get_flag(c, cell_flag_do_bh_drift); #ifdef SWIFT_DEBUG_CHECKS /* Check that we only drift local cells. */ @@ -4583,8 +4583,7 @@ void cell_drift_bpart(struct cell *c, const struct engine *e, int force) { if (c->black_holes.count == 0) { /* Clear the drift flags. */ - c->black_holes.do_drift = 0; - c->black_holes.do_sub_drift = 0; + cell_clear_flag(c, cell_flag_do_bh_drift & cell_flag_do_bh_sub_drift); /* Update the time of the last drift */ c->black_holes.ti_old_part = ti_current; @@ -4595,7 +4594,7 @@ void cell_drift_bpart(struct cell *c, const struct engine *e, int force) { /* Ok, we have some particles somewhere in the hierarchy to drift */ /* Are we not in a leaf ? */ - if (c->split && (force || c->black_holes.do_sub_drift)) { + if (c->split && (force || cell_get_flag(c, cell_flag_do_bh_sub_drift))) { /* Loop over the progeny and collect their data. */ for (int k = 0; k < 8; k++) { @@ -4701,8 +4700,7 @@ void cell_drift_bpart(struct cell *c, const struct engine *e, int force) { } /* Clear the drift flags. */ - c->black_holes.do_drift = 0; - c->black_holes.do_sub_drift = 0; + cell_clear_flag(c, cell_flag_do_bh_drift & cell_flag_do_bh_sub_drift); } /** diff --git a/src/cell.h b/src/cell.h index 8d13a2257..8e3f460b3 100644 --- a/src/cell.h +++ b/src/cell.h @@ -633,12 +633,6 @@ struct cell { /*! Is the #bpart data of this cell being used in a sub-cell? */ int hold; - /*! Does this cell need to be drifted (black holes)? */ - char do_drift; - - /*! Do any of this cell's sub-cells need to be drifted (black holes)? */ - char do_sub_drift; - } black_holes; #ifdef WITH_MPI @@ -1297,11 +1291,6 @@ __attribute__((always_inline)) INLINE static void cell_set_flag( c->flags |= flag; } -__attribute__((always_inline)) INLINE static void cell_set_flag_threadsafe( - struct cell *c, enum cell_flags flag) { - atomic_or(&c->flags, flag); -} - /** Clear the given flag for the given cell. */ __attribute__((always_inline)) INLINE static void cell_clear_flag( struct cell *c, enum cell_flags flag) { diff --git a/src/space.c b/src/space.c index 166c8b426..ae3fdcb1e 100644 --- a/src/space.c +++ b/src/space.c @@ -258,7 +258,6 @@ void space_rebuild_recycle_mapper(void *map_data, int num_elements, c->stars.parts = NULL; c->black_holes.parts = NULL; c->flags = 0; - c->black_holes.do_sub_drift = 0; c->hydro.ti_end_min = -1; c->hydro.ti_end_max = -1; c->grav.ti_end_min = -1; @@ -3318,7 +3317,6 @@ void space_split_recursive(struct space *s, struct cell *c, cp->hydro.super = NULL; cp->grav.super = NULL; cp->flags = 0; - cp->black_holes.do_sub_drift = 0; #ifdef WITH_MPI cp->mpi.tag = -1; #endif // WITH_MPI -- GitLab From cf5dfa548fa35aa0b0adf9b513602d8bc134a452 Mon Sep 17 00:00:00 2001 From: Pedro Gonnet Date: Tue, 23 Apr 2019 09:41:53 +0100 Subject: [PATCH 11/18] Fix calls to `cell_clear_flag` to use `|` instead of `&` to combine flags. --- src/cell.c | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/src/cell.c b/src/cell.c index 1405e5db3..392e5bb44 100644 --- a/src/cell.c +++ b/src/cell.c @@ -2128,9 +2128,9 @@ void cell_clean(struct cell *c) { * @brief Clear the drift flags on the given cell. */ void cell_clear_drift_flags(struct cell *c, void *data) { - cell_clear_flag(c, cell_flag_do_hydro_drift & cell_flag_do_hydro_sub_drift & - cell_flag_do_grav_drift & cell_flag_do_grav_sub_drift & - cell_flag_do_stars_drift & + cell_clear_flag(c, cell_flag_do_hydro_drift | cell_flag_do_hydro_sub_drift | + cell_flag_do_grav_drift | cell_flag_do_grav_sub_drift | + cell_flag_do_stars_drift | cell_flag_do_stars_sub_drift); } @@ -2139,7 +2139,7 @@ void cell_clear_drift_flags(struct cell *c, void *data) { */ void cell_clear_limiter_flags(struct cell *c, void *data) { cell_clear_flag(c, - cell_flag_do_hydro_limiter & cell_flag_do_hydro_sub_limiter); + cell_flag_do_hydro_limiter | cell_flag_do_hydro_sub_limiter); } /** @@ -4111,7 +4111,7 @@ void cell_drift_part(struct cell *c, const struct engine *e, int force) { if (c->hydro.count == 0) { /* Clear the drift flags. */ - cell_clear_flag(c, cell_flag_do_hydro_drift & cell_flag_do_hydro_sub_drift); + cell_clear_flag(c, cell_flag_do_hydro_drift | cell_flag_do_hydro_sub_drift); /* Update the time of the last drift */ c->hydro.ti_old_part = ti_current; @@ -4259,7 +4259,7 @@ void cell_drift_part(struct cell *c, const struct engine *e, int force) { } /* Clear the drift flags. */ - cell_clear_flag(c, cell_flag_do_hydro_drift & cell_flag_do_hydro_sub_drift); + cell_clear_flag(c, cell_flag_do_hydro_drift | cell_flag_do_hydro_sub_drift); } /** @@ -4293,7 +4293,7 @@ void cell_drift_gpart(struct cell *c, const struct engine *e, int force) { if (c->grav.count == 0) { /* Clear the drift flags. */ - cell_clear_flag(c, cell_flag_do_grav_drift & cell_flag_do_grav_sub_drift); + cell_clear_flag(c, cell_flag_do_grav_drift | cell_flag_do_grav_sub_drift); /* Update the time of the last drift */ c->grav.ti_old_part = ti_current; @@ -4381,7 +4381,7 @@ void cell_drift_gpart(struct cell *c, const struct engine *e, int force) { } /* Clear the drift flags. */ - cell_clear_flag(c, cell_flag_do_grav_drift & cell_flag_do_grav_sub_drift); + cell_clear_flag(c, cell_flag_do_grav_drift | cell_flag_do_grav_sub_drift); } /** @@ -4421,7 +4421,7 @@ void cell_drift_spart(struct cell *c, const struct engine *e, int force) { if (c->stars.count == 0) { /* Clear the drift flags. */ - cell_clear_flag(c, cell_flag_do_stars_drift & cell_flag_do_stars_sub_drift); + cell_clear_flag(c, cell_flag_do_stars_drift | cell_flag_do_stars_sub_drift); /* Update the time of the last drift */ c->stars.ti_old_part = ti_current; @@ -4549,7 +4549,7 @@ void cell_drift_spart(struct cell *c, const struct engine *e, int force) { } /* Clear the drift flags. */ - cell_clear_flag(c, cell_flag_do_stars_drift & cell_flag_do_stars_sub_drift); + cell_clear_flag(c, cell_flag_do_stars_drift | cell_flag_do_stars_sub_drift); } /** @@ -4588,7 +4588,7 @@ void cell_drift_bpart(struct cell *c, const struct engine *e, int force) { if (c->black_holes.count == 0) { /* Clear the drift flags. */ - cell_clear_flag(c, cell_flag_do_bh_drift & cell_flag_do_bh_sub_drift); + cell_clear_flag(c, cell_flag_do_bh_drift | cell_flag_do_bh_sub_drift); /* Update the time of the last drift */ c->black_holes.ti_old_part = ti_current; @@ -4705,7 +4705,7 @@ void cell_drift_bpart(struct cell *c, const struct engine *e, int force) { } /* Clear the drift flags. */ - cell_clear_flag(c, cell_flag_do_bh_drift & cell_flag_do_bh_sub_drift); + cell_clear_flag(c, cell_flag_do_bh_drift | cell_flag_do_bh_sub_drift); } /** -- GitLab From 649cd738cbe46bfc3997a76511985f6df490b5e2 Mon Sep 17 00:00:00 2001 From: Pedro Gonnet Date: Tue, 23 Apr 2019 09:45:05 +0100 Subject: [PATCH 12/18] Fixes suggested by Matthieu. --- src/cell.h | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/cell.h b/src/cell.h index 7a220aad4..c39050461 100644 --- a/src/cell.h +++ b/src/cell.h @@ -222,7 +222,8 @@ struct pcell_step_black_holes { float dx_max_part; }; -/** Bitmasks for the cell flags. */ +/** Bitmasks for the cell flags. Beware when adding flags that you don't exceed + the size of the flags variable in the struct cell. */ enum cell_flags { cell_flag_split = (1UL << 0), cell_flag_do_hydro_drift = (1UL << 1), @@ -268,7 +269,7 @@ struct cell { struct cell *super; /*! Cell flags bit-mask. */ - unsigned int flags; + uint16_t flags; /*! Hydro variables */ struct { @@ -1303,7 +1304,7 @@ __attribute__((always_inline)) INLINE static void cell_clear_flag( /** Get the given flag for the given cell. */ __attribute__((always_inline)) INLINE static int cell_get_flag( - struct cell *c, enum cell_flags flag) { + const struct cell *c, enum cell_flags flag) { return (c->flags & flag) > 0; } -- GitLab From 944900c48bfb2488d443a621d4a34e1ca3ad842d Mon Sep 17 00:00:00 2001 From: Pedro Gonnet Date: Fri, 26 Apr 2019 11:28:57 +0100 Subject: [PATCH 13/18] Don't pass enums in the `cell_*_flag` functions, but rather use the type of the `flags` value itself. Using the enum causes problems when passing the union of more than one flag. --- src/cell.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/cell.h b/src/cell.h index c39050461..87392644b 100644 --- a/src/cell.h +++ b/src/cell.h @@ -1292,19 +1292,19 @@ __attribute__((always_inline)) INLINE static void cell_free_stars_sorts( /** Set the given flag for the given cell. */ __attribute__((always_inline)) INLINE static void cell_set_flag( - struct cell *c, enum cell_flags flag) { + struct cell *c, uint16_t cell_flags flag) { c->flags |= flag; } /** Clear the given flag for the given cell. */ __attribute__((always_inline)) INLINE static void cell_clear_flag( - struct cell *c, enum cell_flags flag) { + struct cell *c, uint16_t cell_flags flag) { c->flags &= ~flag; } /** Get the given flag for the given cell. */ __attribute__((always_inline)) INLINE static int cell_get_flag( - const struct cell *c, enum cell_flags flag) { + const struct cell *c, uint16_t cell_flags flag) { return (c->flags & flag) > 0; } -- GitLab From 899e94e2673905347854bfea05db4e5116e8e23d Mon Sep 17 00:00:00 2001 From: Pedro Gonnet Date: Fri, 26 Apr 2019 11:30:49 +0100 Subject: [PATCH 14/18] Use logical "or" to group flags instead of "&". --- src/runner.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/runner.c b/src/runner.c index e1524758b..b6878935b 100644 --- a/src/runner.c +++ b/src/runner.c @@ -2945,7 +2945,7 @@ void runner_do_limiter(struct runner *r, struct cell *c, int force, int timer) { /* Clear the limiter flags. */ cell_clear_flag( - c, cell_flag_do_hydro_limiter & cell_flag_do_hydro_sub_limiter); + c, cell_flag_do_hydro_limiter | cell_flag_do_hydro_sub_limiter); return; } @@ -3041,7 +3041,7 @@ void runner_do_limiter(struct runner *r, struct cell *c, int force, int timer) { /* Clear the limiter flags. */ cell_clear_flag(c, - cell_flag_do_hydro_limiter & cell_flag_do_hydro_sub_limiter); + cell_flag_do_hydro_limiter | cell_flag_do_hydro_sub_limiter); if (timer) TIMER_TOC(timer_do_limiter); } -- GitLab From c988df86cb5f318701e992cbc6f205a2cd416d84 Mon Sep 17 00:00:00 2001 From: Pedro Gonnet Date: Fri, 26 Apr 2019 11:40:37 +0100 Subject: [PATCH 15/18] Oops. --- src/cell.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/cell.h b/src/cell.h index 87392644b..84f2833bf 100644 --- a/src/cell.h +++ b/src/cell.h @@ -1292,19 +1292,19 @@ __attribute__((always_inline)) INLINE static void cell_free_stars_sorts( /** Set the given flag for the given cell. */ __attribute__((always_inline)) INLINE static void cell_set_flag( - struct cell *c, uint16_t cell_flags flag) { + struct cell *c, uint16_t flag) { c->flags |= flag; } /** Clear the given flag for the given cell. */ __attribute__((always_inline)) INLINE static void cell_clear_flag( - struct cell *c, uint16_t cell_flags flag) { + struct cell *c, uint16_t flag) { c->flags &= ~flag; } /** Get the given flag for the given cell. */ __attribute__((always_inline)) INLINE static int cell_get_flag( - const struct cell *c, uint16_t cell_flags flag) { + const struct cell *c, uint16_t flag) { return (c->flags & flag) > 0; } -- GitLab From 25a3c23f807ed88843ba63a46068bc8e68ea83d3 Mon Sep 17 00:00:00 2001 From: "Peter W. Draper" Date: Fri, 26 Apr 2019 12:56:43 +0100 Subject: [PATCH 16/18] Formatting --- src/cell.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/cell.h b/src/cell.h index 84f2833bf..e53b02036 100644 --- a/src/cell.h +++ b/src/cell.h @@ -1291,8 +1291,8 @@ __attribute__((always_inline)) INLINE static void cell_free_stars_sorts( } /** Set the given flag for the given cell. */ -__attribute__((always_inline)) INLINE static void cell_set_flag( - struct cell *c, uint16_t flag) { +__attribute__((always_inline)) INLINE static void cell_set_flag(struct cell *c, + uint16_t flag) { c->flags |= flag; } -- GitLab From b4c6cb9a86789f8cbb49e62d1042df00f6e142ef Mon Sep 17 00:00:00 2001 From: Pedro Gonnet Date: Fri, 26 Apr 2019 22:13:58 +0200 Subject: [PATCH 17/18] switch to using a 32-bit flag field and atomics, replace '|=' with '= ( ... || ... )', which should do short-circuit evaluation, and is easier to read. --- src/atomic.h | 1 + src/cell.c | 8 ++++---- src/cell.h | 12 ++++++------ src/runner.c | 2 +- 4 files changed, 12 insertions(+), 11 deletions(-) diff --git a/src/atomic.h b/src/atomic.h index 97e0935f5..43da98234 100644 --- a/src/atomic.h +++ b/src/atomic.h @@ -29,6 +29,7 @@ #define atomic_add(v, i) __sync_fetch_and_add(v, i) #define atomic_sub(v, i) __sync_fetch_and_sub(v, i) #define atomic_or(v, i) __sync_fetch_and_or(v, i) +#define atomic_and(v, i) __sync_fetch_and_and(v, i) #define atomic_inc(v) atomic_add(v, 1) #define atomic_dec(v) atomic_sub(v, 1) #define atomic_cas(v, o, n) __sync_val_compare_and_swap(v, o, n) diff --git a/src/cell.c b/src/cell.c index 392e5bb44..f14fcb711 100644 --- a/src/cell.c +++ b/src/cell.c @@ -4097,7 +4097,7 @@ void cell_drift_part(struct cell *c, const struct engine *e, int force) { float cell_h_max = 0.f; /* Drift irrespective of cell flags? */ - force |= cell_get_flag(c, cell_flag_do_hydro_drift); + force = (force || cell_get_flag(c, cell_flag_do_hydro_drift)); #ifdef SWIFT_DEBUG_CHECKS /* Check that we only drift local cells. */ @@ -4279,7 +4279,7 @@ void cell_drift_gpart(struct cell *c, const struct engine *e, int force) { struct gpart *const gparts = c->grav.parts; /* Drift irrespective of cell flags? */ - force |= cell_get_flag(c, cell_flag_do_grav_drift); + force = (force || cell_get_flag(c, cell_flag_do_grav_drift)); #ifdef SWIFT_DEBUG_CHECKS /* Check that we only drift local cells. */ @@ -4407,7 +4407,7 @@ void cell_drift_spart(struct cell *c, const struct engine *e, int force) { float cell_h_max = 0.f; /* Drift irrespective of cell flags? */ - force |= cell_get_flag(c, cell_flag_do_stars_drift); + force = (force || cell_get_flag(c, cell_flag_do_stars_drift)); #ifdef SWIFT_DEBUG_CHECKS /* Check that we only drift local cells. */ @@ -4574,7 +4574,7 @@ void cell_drift_bpart(struct cell *c, const struct engine *e, int force) { float cell_h_max = 0.f; /* Drift irrespective of cell flags? */ - force |= cell_get_flag(c, cell_flag_do_bh_drift); + force = (force || cell_get_flag(c, cell_flag_do_bh_drift)); #ifdef SWIFT_DEBUG_CHECKS /* Check that we only drift local cells. */ diff --git a/src/cell.h b/src/cell.h index e53b02036..117eb708f 100644 --- a/src/cell.h +++ b/src/cell.h @@ -269,7 +269,7 @@ struct cell { struct cell *super; /*! Cell flags bit-mask. */ - uint16_t flags; + uint32_t flags; /*! Hydro variables */ struct { @@ -1292,19 +1292,19 @@ __attribute__((always_inline)) INLINE static void cell_free_stars_sorts( /** Set the given flag for the given cell. */ __attribute__((always_inline)) INLINE static void cell_set_flag(struct cell *c, - uint16_t flag) { - c->flags |= flag; + uint32_t flag) { + atomic_or(&c->flags, flag); } /** Clear the given flag for the given cell. */ __attribute__((always_inline)) INLINE static void cell_clear_flag( - struct cell *c, uint16_t flag) { - c->flags &= ~flag; + struct cell *c, uint32_t flag) { + atomic_and(&c->flags, ~flag); } /** Get the given flag for the given cell. */ __attribute__((always_inline)) INLINE static int cell_get_flag( - const struct cell *c, uint16_t flag) { + const struct cell *c, uint32_t flag) { return (c->flags & flag) > 0; } diff --git a/src/runner.c b/src/runner.c index b6878935b..1a15ce537 100644 --- a/src/runner.c +++ b/src/runner.c @@ -2938,7 +2938,7 @@ void runner_do_limiter(struct runner *r, struct cell *c, int force, int timer) { ti_gravity_beg_max = 0; /* Limit irrespective of cell flags? */ - force |= cell_get_flag(c, cell_flag_do_hydro_limiter); + force = (force || cell_get_flag(c, cell_flag_do_hydro_limiter)); /* Early abort? */ if (c->hydro.count == 0) { -- GitLab From 9a65983acaba77fdaa286e19349c110bd031aa99 Mon Sep 17 00:00:00 2001 From: Pedro Gonnet Date: Tue, 30 Apr 2019 12:26:42 +0100 Subject: [PATCH 18/18] Mark the flags `volatile`, just to be safe. This is not a problem now, but I would hate it to become one later. --- src/cell.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/cell.h b/src/cell.h index 117eb708f..0824f71d0 100644 --- a/src/cell.h +++ b/src/cell.h @@ -269,7 +269,7 @@ struct cell { struct cell *super; /*! Cell flags bit-mask. */ - uint32_t flags; + volatile uint32_t flags; /*! Hydro variables */ struct { -- GitLab