From f953bc15dba3ff6dd28d88a539a1210635f43a88 Mon Sep 17 00:00:00 2001 From: Pedro Gonnet <gonnet@google.com> Date: Thu, 16 Aug 2018 21:26:06 +0200 Subject: [PATCH] add a function to tag a cell, avoids code duplication. --- src/cell.h | 12 ++++++++++++ src/engine.c | 9 +++------ 2 files changed, 15 insertions(+), 6 deletions(-) diff --git a/src/cell.h b/src/cell.h index 0b5196ed1d..1457e236a5 100644 --- a/src/cell.h +++ b/src/cell.h @@ -606,4 +606,16 @@ __attribute__((always_inline)) INLINE static int cell_need_rebuild_for_pair( cj->dmin); } +/** + * @brief Add a unique tag to a cell. + */ +__attribute((always_inline)) INLINE static void cell_tag(struct cell *c) { +#ifdef WITH_MPI + if (c->tag < 0 && (c->tag = atomic_inc(&cell_next_tag)) > cell_max_tag) + error("Ran out of cell tags."); +#else + error("SWIFT was not compiled with MPI enabled."); +#endif // WITH_MPI +} + #endif /* SWIFT_CELL_H */ diff --git a/src/engine.c b/src/engine.c index 590a96f2e5..024b8e7a57 100644 --- a/src/engine.c +++ b/src/engine.c @@ -1293,8 +1293,7 @@ void engine_addtasks_send_hydro(struct engine *e, struct cell *ci, if (t_xv == NULL) { /* Create a tag for this cell. */ - if (ci->tag < 0 && (ci->tag = atomic_inc(&cell_next_tag)) > cell_max_tag) - error("Ran out of cell tags."); + cell_tag(ci); t_xv = scheduler_addtask( s, task_type_send, task_subtype_xv, @@ -1389,8 +1388,7 @@ void engine_addtasks_send_gravity(struct engine *e, struct cell *ci, if (t_grav == NULL) { /* Create a tag for this cell. */ - if (ci->tag < 0 && (ci->tag = atomic_inc(&cell_next_tag)) > cell_max_tag) - error("Ran out of cell tags."); + cell_tag(ci); t_grav = scheduler_addtask( s, task_type_send, task_subtype_gpart, @@ -1454,8 +1452,7 @@ void engine_addtasks_send_timestep(struct engine *e, struct cell *ci, if (t_ti == NULL) { /* Create a tag for this cell. */ - if (ci->tag < 0 && (ci->tag = atomic_inc(&cell_next_tag)) > cell_max_tag) - error("Ran out of cell tags."); + cell_tag(ci); t_ti = scheduler_addtask( s, task_type_send, task_subtype_tend, -- GitLab