diff --git a/src/cell.h b/src/cell.h index 0b5196ed1dadbd5d37ba8ada88d1a4bad185e49b..1457e236a57e66af773a977f70e720d0b056c700 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 590a96f2e5b4db95c84e89a601250a454f312e37..024b8e7a57a5aff969195f576deadf21b0c55f09 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,