Commit 0bed8898 authored by Pedro Gonnet's avatar Pedro Gonnet
Browse files

add functions to pack/unpack arrays of tags.

parent e2664bf2
......@@ -210,6 +210,40 @@ int cell_pack(struct cell *restrict c, struct pcell *restrict pc) {
#endif
}
/**
* @brief Pack the tag of the given cell and all it's sub-cells.
*
* @param c The #cell.
* @param tags Pointer to an array of packed tags.
*
* @return The number of packed tags.
*/
int cell_pack_tags(const struct cell *c, int *tags) {
#ifdef WITH_MPI
/* Start by packing the data of the current cell. */
tags[0] = c->tag;
/* Fill in the progeny, depth-first recursion. */
int count = 1;
for (int k = 0; k < 8; k++)
if (c->progeny[k] != NULL)
count += cell_pack_tags(c->progeny[k], &tags[count]);
#ifdef SWIFT_DEBUG_CHECKS
if (c->pcell_size != count) error("Inconsistent tag and pcell count!");
#endif // SWIFT_DEBUG_CHECKS
/* Return the number of packed tags used. */
return count;
#else
error("SWIFT was not compiled with MPI support.");
return 0;
#endif
}
/**
* @brief Unpack the data of a given cell and its sub-cells.
*
......@@ -283,6 +317,43 @@ int cell_unpack(struct pcell *restrict pc, struct cell *restrict c,
#endif
}
/**
* @brief Unpack the tags of a given cell and its sub-cells.
*
* @param tags An array of tags.
* @param c The #cell in which to unpack the tags.
*
* @return The number of tags created.
*/
int cell_unpack_tags(const int *tags, struct cell *restrict c) {
#ifdef WITH_MPI
/* Unpack the current pcell. */
c->tag = tags[0];
/* Number of new cells created. */
int count = 1;
/* Fill the progeny recursively, depth-first. */
for (int k = 0; k < 8; k++)
if (c->progeny[k] != NULL) {
count += cell_unpack_tags(&tags[count], c->progeny[k]);
}
#ifdef SWIFT_DEBUG_CHECKS
if (c->pcell_size != count) error("Inconsistent tag and pcell count!");
#endif // SWIFT_DEBUG_CHECKS
/* Return the total number of unpacked tags. */
return count;
#else
error("SWIFT was not compiled with MPI support.");
return 0;
#endif
}
/**
* @brief Pack the time information of the given cell and all it's sub-cells.
*
......
......@@ -484,6 +484,8 @@ int cell_slocktree(struct cell *c);
void cell_sunlocktree(struct cell *c);
int cell_pack(struct cell *c, struct pcell *pc);
int cell_unpack(struct pcell *pc, struct cell *c, struct space *s);
int cell_pack_tags(const struct cell *c, int *tags);
int cell_unpack_tags(const int *tags, struct cell *c);
int cell_pack_end_step(struct cell *c, struct pcell_step *pcell);
int cell_unpack_end_step(struct cell *c, struct pcell_step *pcell);
int cell_pack_multipoles(struct cell *c, struct gravity_tensors *m);
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment