From 6fcf793277edf01ecefaebae36a0638ef6427ed2 Mon Sep 17 00:00:00 2001 From: "Peter W. Draper" <p.w.draper@durham.ac.uk> Date: Mon, 30 Oct 2017 18:25:35 +0000 Subject: [PATCH] Also optionally dump the number of active particles with the cell dump Sort out naming of output cell dumps to be based on the step, so they can be compared to other dumps --- src/debug.c | 65 ++++++++++++++++++++++++++++++++++++++--------------- src/debug.h | 3 ++- 2 files changed, 49 insertions(+), 19 deletions(-) diff --git a/src/debug.c b/src/debug.c index 368c5cbb08..4e99108f50 100644 --- a/src/debug.c +++ b/src/debug.c @@ -280,6 +280,7 @@ static void dumpCells_map(struct cell *c, void *data) { FILE *file = (FILE *)ldata[0]; struct engine *e = (struct engine *)ldata[1]; float ntasks = c->nr_tasks; + int pactive = (int)ldata[2]; #if SWIFT_DEBUG_CHECKS /* The c->nr_tasks field does not include all the tasks. So let's check this @@ -301,47 +302,75 @@ static void dumpCells_map(struct cell *c, void *data) { #endif /* Only locally active cells are dumped. */ - if (c->count > 0 || c->gcount > 0 || c->scount > 0) - fprintf(file, - " %6.3f %6.3f %6.3f %6.3f %6.3f %6.3f %6d %6d %6d %6d " - "%6.1f %20lld %6d %6d %6d %6d %6d\n", - c->loc[0], c->loc[1], c->loc[2], c->width[0], c->width[1], - c->width[2], c->count, c->gcount, c->scount, c->depth, ntasks, - c->ti_end_min, get_time_bin(c->ti_end_min), (c->super == c), - cell_is_active(c, e), c->nodeID, c->nodeID == e->nodeID); + if (c->count > 0 || c->gcount > 0 || c->scount > 0) { + + /* If requested we work out how many particles are active in this cell. */ + int pactcount = 0; + if (pactive) { + const struct part *parts = c->parts; + for (int k = 0; k < c->count; k++) + if (part_is_active(&parts[k], e)) pactcount++; + struct gpart *gparts = c->gparts; + for (int k = 0; k < c->gcount; k++) + if (gpart_is_active(&gparts[k], e)) pactcount++; + struct spart *sparts = c->sparts; + for (int k = 0; k < c->scount; k++) + if (spart_is_active(&sparts[k], e)) pactcount++; + } +#if WITH_MPI + int sendto = (c->send_xv != NULL); +#else + int sendto = 0; +#endif + + /* Local cells that are active and are super cells and have MPI tasks. */ + if (c->nodeID == e->nodeID && cell_is_active(c, e) && (c->super == c) && sendto) + fprintf(file, + " %6.3f %6.3f %6.3f %6.3f %6.3f %6.3f %6d %6d %6d %6d %6d %6d " + "%6.1f %20lld %6d %6d %6d %6d %6d\n", + c->loc[0], c->loc[1], c->loc[2], c->width[0], c->width[1], + c->width[2], e->step, c->count, c->gcount, c->scount, pactcount, + c->depth, ntasks, c->ti_end_min, get_time_bin(c->ti_end_min), + (c->super == c), cell_is_active(c, e), c->nodeID, + c->nodeID == e->nodeID); + + } } /** * @brief Dump the location, depth, task counts and timebins and active state, - * for all cells to a simple text file. + * for all cells to a simple text file. A more costly count of the active + * particles in a cell can also be output. * * @param prefix base output filename, result is written to * %prefix%_%rank%_%step%.dat + * @param pactive also output a count of active particles. * @param s the space holding the cells to dump. * @param rank node ID of MPI rank, or 0 if not relevant. * @param step the current engine step, or some unique integer. */ -void dumpCells(const char *prefix, struct space *s, int rank, int step) { +void dumpCells(const char *prefix, int pactive, struct space *s, int rank, + int step) { FILE *file = NULL; /* Name of output file. */ - static int nseq = 0; char fname[200]; - int uniq = atomic_inc(&nseq); - sprintf(fname, "%s_%03d.dat", prefix, uniq); + sprintf(fname, "%s_%03d.dat", prefix, step); file = fopen(fname, "w"); /* Header. */ fprintf(file, - "# %6s %6s %6s %6s %6s %6s %6s %6s %6s %6s %6s %6s " - "%20s %6s %6s %6s %6s\n", - "x", "y", "z", "xw", "yw", "zw", "count", "gcount", "scount", "depth", - "tasks", "ti_end_min", "timebin", "issuper", "active", "rank", "local"); + "# %6s %6s %6s %6s %6s %6s %6s %6s %6s %6s %6s %6s %6s " + "%20s %6s %6s %6s %6s %6s\n", + "x", "y", "z", "xw", "yw", "zw", "step", "count", "gcount", "scount", + "actcount", "depth", "tasks", "ti_end_min", "timebin", + "issuper", "active", "rank", "local"); - uintptr_t data[2]; + uintptr_t data[3]; data[0] = (size_t)file; data[1] = (size_t)s->e; + data[2] = (size_t)pactive; space_map_cells_pre(s, 1, dumpCells_map, &data); fclose(file); } diff --git a/src/debug.h b/src/debug.h index d53fc1b6ea..5e5fb4819e 100644 --- a/src/debug.h +++ b/src/debug.h @@ -36,7 +36,8 @@ void printgParticle_single(struct gpart *gp); int checkSpacehmax(struct space *s); int checkCellhdxmax(const struct cell *c, int *depth); -void dumpCells(const char *prefix, struct space *s, int rank, int step); +void dumpCells(const char *prefix, int pactive, struct space *s, int rank, + int step); #ifdef HAVE_METIS #include "metis.h" -- GitLab