diff --git a/src/debug.c b/src/debug.c index ee19c26f03bf4d05086b27c3e5872448edb11b2f..0489c248f8b3e493cd9a35ad4db62e5310f58790 100644 --- a/src/debug.c +++ b/src/debug.c @@ -420,9 +420,9 @@ void dumpCells(const char *prefix, int active, int mpiactive, int pactive, * @param edgeweights weights of edges */ void dumpParMETISGraph(const char *prefix, idx_t nvertices, - idx_t nvertexweights, idx_t *cellconruns, - idx_t *cellcon, idx_t *vertexweights, - idx_t *vertexsizes, idx_t *edgeweights) { + idx_t nvertexweights, idx_t *cellconruns, idx_t *cellcon, + idx_t *vertexweights, idx_t *vertexsizes, + idx_t *edgeweights) { FILE *stdfile = NULL; FILE *simplefile = NULL; FILE *weightfile = NULL; diff --git a/src/debug.h b/src/debug.h index 8d2748944013e99cc3f22d25855ac60baa7fb3f7..fbc63c748ba616fcee233fb31c87907cd4762818 100644 --- a/src/debug.h +++ b/src/debug.h @@ -41,9 +41,8 @@ void dumpCells(const char *prefix, int active, int mpiactive, int pactive, #if defined(WITH_MPI) && defined(HAVE_PARMETIS) #include "parmetis.h" -void dumpParMETISGraph(const char *prefix, idx_t nvtxs, idx_t ncon, - idx_t *xadj, idx_t *adjncy, idx_t *vwgt, idx_t *vsize, - idx_t *adjwgt); +void dumpParMETISGraph(const char *prefix, idx_t nvtxs, idx_t ncon, idx_t *xadj, + idx_t *adjncy, idx_t *vwgt, idx_t *vsize, idx_t *adjwgt); #endif #ifdef HAVE_MPI diff --git a/src/engine.c b/src/engine.c index 79b4d63f928cfff6480c215af6d8bcd10ddc900a..c9689b627a618cdb0e05b13ebb42087694b4b1ff 100644 --- a/src/engine.c +++ b/src/engine.c @@ -791,34 +791,32 @@ void engine_redistribute(struct engine *e) { error("Failed to allreduce sparticle transfer counts."); /* Report how many particles will be moved. */ - //if (e->verbose) { + // if (e->verbose) { if (e->nodeID == 0) { - size_t total = 0, g_total = 0, s_total = 0; - size_t unmoved = 0, g_unmoved = 0, s_unmoved = 0; - for (int p = 0, r = 0; p < nr_nodes; p++) { - for (int n = 0; n < nr_nodes; n++) { - total += counts[r]; - g_total += g_counts[r]; - s_total += s_counts[r]; - if (p == n) { - unmoved += counts[r]; - g_unmoved += g_counts[r]; - s_unmoved += s_counts[r]; - } - r++; + size_t total = 0, g_total = 0, s_total = 0; + size_t unmoved = 0, g_unmoved = 0, s_unmoved = 0; + for (int p = 0, r = 0; p < nr_nodes; p++) { + for (int n = 0; n < nr_nodes; n++) { + total += counts[r]; + g_total += g_counts[r]; + s_total += s_counts[r]; + if (p == n) { + unmoved += counts[r]; + g_unmoved += g_counts[r]; + s_unmoved += s_counts[r]; } + r++; } - if (total > 0) - message("%ld of %ld (%.2f%%) of particles moved", total - unmoved, - total, 100.0 * (double)(total - unmoved) / (double)total); - if (g_total > 0) - message("%ld of %ld (%.2f%%) of g-particles moved", g_total - g_unmoved, - g_total, - 100.0 * (double)(g_total - g_unmoved) / (double)g_total); - if (s_total > 0) - message("%ld of %ld (%.2f%%) of s-particles moved", s_total - s_unmoved, - s_total, - 100.0 * (double)(s_total - s_unmoved) / (double)s_total); + } + if (total > 0) + message("%ld of %ld (%.2f%%) of particles moved", total - unmoved, total, + 100.0 * (double)(total - unmoved) / (double)total); + if (g_total > 0) + message("%ld of %ld (%.2f%%) of g-particles moved", g_total - g_unmoved, + g_total, 100.0 * (double)(g_total - g_unmoved) / (double)g_total); + if (s_total > 0) + message("%ld of %ld (%.2f%%) of s-particles moved", s_total - s_unmoved, + s_total, 100.0 * (double)(s_total - s_unmoved) / (double)s_total); } //} diff --git a/src/partition.c b/src/partition.c index 8aeefb11008cba9c6851e521f157023a115dd84a..25f696f0e5d5c03445bb17f5d48f2e80706e154a 100644 --- a/src/partition.c +++ b/src/partition.c @@ -347,13 +347,11 @@ static void pick_parmetis(int nodeID, struct space *s, int nregions, k -= l; } res = MPI_Bcast((void *)vtxdist, nregions + 1, IDX_T, 0, comm); - if (res != MPI_SUCCESS) - mpi_error(res, "Failed to broadcast vtxdist."); + if (res != MPI_SUCCESS) mpi_error(res, "Failed to broadcast vtxdist."); } else { res = MPI_Bcast((void *)vtxdist, nregions + 1, IDX_T, 0, comm); - if (res != MPI_SUCCESS) - mpi_error(res, "Failed to broadcast vtxdist."); + if (res != MPI_SUCCESS) mpi_error(res, "Failed to broadcast vtxdist."); } /* Number of cells on this node and space for the expected arrays. */ @@ -386,7 +384,8 @@ static void pick_parmetis(int nodeID, struct space *s, int nregions, /* Space for largest lists. */ idx_t *full_xadj = NULL; - if ((full_xadj = (idx_t *)malloc(sizeof(idx_t) * (ncells + nregions + 1))) == NULL) + if ((full_xadj = + (idx_t *)malloc(sizeof(idx_t) * (ncells + nregions + 1))) == NULL) error("Failed to allocate xadj buffer."); idx_t *full_adjncy = NULL; if ((full_adjncy = (idx_t *)malloc(sizeof(idx_t) * 26 * ncells)) == NULL) @@ -397,7 +396,8 @@ static void pick_parmetis(int nodeID, struct space *s, int nregions, error("Failed to allocate vertex weights array"); idx_t *full_weights_e = NULL; if (weights_e != NULL) - if ((full_weights_e = (idx_t *)malloc(26 * sizeof(idx_t) * ncells)) == NULL) + if ((full_weights_e = (idx_t *)malloc(26 * sizeof(idx_t) * ncells)) == + NULL) error("Failed to allocate edge weights array"); idx_t *full_regionid = NULL; @@ -443,7 +443,8 @@ static void pick_parmetis(int nodeID, struct space *s, int nregions, failed++; } if (full_weights_v[k] < 1) { - message("Used vertex weight out of range: %" PRIDX, full_weights_v[k]); + message("Used vertex weight out of range: %" PRIDX, + full_weights_v[k]); failed++; } } @@ -493,8 +494,7 @@ static void pick_parmetis(int nodeID, struct space *s, int nregions, memcpy(weights_e, &full_weights_e[j2], sizeof(idx_t) * nvt * 26); if (weights_v != NULL) memcpy(weights_v, &full_weights_v[j3], sizeof(idx_t) * nvt); - if (refine) - memcpy(regionid, full_regionid, sizeof(idx_t) * nvt); + if (refine) memcpy(regionid, full_regionid, sizeof(idx_t) * nvt); } else { res = MPI_Send(&full_xadj[j1], nvt + 1, IDX_T, rank, 0, comm); @@ -506,8 +506,7 @@ static void pick_parmetis(int nodeID, struct space *s, int nregions, res = MPI_Send(&full_weights_v[j3], nvt, IDX_T, rank, 3, comm); if (refine && res == MPI_SUCCESS) res = MPI_Send(full_regionid, nvt, IDX_T, rank, 4, comm); - if (res != MPI_SUCCESS) - mpi_error(res, "Failed to send graph data"); + if (res != MPI_SUCCESS) mpi_error(res, "Failed to send graph data"); } j1 += nvt + 1; j2 += nvt * 26; @@ -532,9 +531,8 @@ static void pick_parmetis(int nodeID, struct space *s, int nregions, if (res == MPI_SUCCESS && weights_v != NULL) res = MPI_Recv(weights_v, nverts, IDX_T, 0, 3, comm, &status); if (refine && res == MPI_SUCCESS) - res +=MPI_Recv((void *)regionid, nverts, IDX_T, 0, 4, comm, &status); - if (res != MPI_SUCCESS) - mpi_error(res, "Failed to receive graph data"); + res += MPI_Recv((void *)regionid, nverts, IDX_T, 0, 4, comm, &status); + if (res != MPI_SUCCESS) mpi_error(res, "Failed to receive graph data"); } /* Set up the tpwgts array. This is just 1/nregions. */ @@ -579,7 +577,6 @@ static void pick_parmetis(int nodeID, struct space *s, int nregions, &wgtflag, &numflag, &ncon, &nparts, tpwgts, ubvec, options, &edgecut, regionid, &comm) != METIS_OK) error("Call to ParMETIS_V3_PartKway failed."); - } /* Gather the regionids from the other ranks. XXX async version XXX */ @@ -589,18 +586,17 @@ static void pick_parmetis(int nodeID, struct space *s, int nregions, int nvt = vtxdist[rank + 1] - vtxdist[rank]; if (rank == 0) { - /* Locals. */ - remoteids = regionid; + /* Locals. */ + remoteids = regionid; } else { - remoteids = (idx_t *)malloc(sizeof(idx_t) * nvt); - res = MPI_Recv((void *)remoteids, nvt, IDX_T, rank, 1, comm, - &status); - if (res != MPI_SUCCESS) - mpi_error(res, "Failed to receive new regionids"); + remoteids = (idx_t *)malloc(sizeof(idx_t) * nvt); + res = MPI_Recv((void *)remoteids, nvt, IDX_T, rank, 1, comm, &status); + if (res != MPI_SUCCESS) + mpi_error(res, "Failed to receive new regionids"); } for (int k = 0; k < nvt; k++) { - celllist[j + k] = remoteids[k]; + celllist[j + k] = remoteids[k]; } j += nvt; if (rank != 0) free(remoteids); @@ -612,15 +608,13 @@ static void pick_parmetis(int nodeID, struct space *s, int nregions, error("Got bad nodeID %" PRIDX " for cell %i.", celllist[k], k); } else { - res = MPI_Send(regionid, vtxdist[nodeID + 1] - vtxdist[nodeID], IDX_T, 0, - 1, comm); - if (res != MPI_SUCCESS) - mpi_error(res, "Failed to send new regionids"); + res = MPI_Send(regionid, vtxdist[nodeID + 1] - vtxdist[nodeID], IDX_T, 0, 1, + comm); + if (res != MPI_SUCCESS) mpi_error(res, "Failed to send new regionids"); } /* And everyone gets a copy? */ res = MPI_Bcast(celllist, s->nr_cells, MPI_INT, 0, MPI_COMM_WORLD); - if (res != MPI_SUCCESS) - mpi_error(res, "Failed to broadcast new celllist"); + if (res != MPI_SUCCESS) mpi_error(res, "Failed to broadcast new celllist"); /* Clean up. */ if (weights_v != NULL) free(weights_v); @@ -796,20 +790,18 @@ static void repart_edge_parmetis(int bothweights, int timebins, } res = MPI_Reduce((nodeID == 0) ? MPI_IN_PLACE : weights_e, weights_e, - 26 * nr_cells, MPI_DOUBLE, MPI_SUM, 0, - MPI_COMM_WORLD); - if (res != MPI_SUCCESS) - mpi_error(res, "Failed to allreduce edge weights."); + 26 * nr_cells, MPI_DOUBLE, MPI_SUM, 0, MPI_COMM_WORLD); + if (res != MPI_SUCCESS) mpi_error(res, "Failed to allreduce edge weights."); /* Allocate cell list for the partition. If not already done. */ int refine = 1; if (repartition->ncelllist != s->nr_cells) { - refine = 0; - free(repartition->celllist); - repartition->ncelllist = 0; - repartition->celllist = (int *)malloc(sizeof(int) * s->nr_cells); - if (repartition->celllist == NULL) error("Failed to allocate celllist"); - repartition->ncelllist = s->nr_cells; + refine = 0; + free(repartition->celllist); + repartition->ncelllist = 0; + repartition->celllist = (int *)malloc(sizeof(int) * s->nr_cells); + if (repartition->celllist == NULL) error("Failed to allocate celllist"); + repartition->ncelllist = s->nr_cells; } /* We need to rescale the weights into the range of an integer for @@ -908,9 +900,11 @@ static void repart_edge_parmetis(int bothweights, int timebins, /* If partition failed continue with the current one, but make this clear. */ if (failed) { - if (nodeID == 0) message("WARNING: ParMETIS repartition has failed, " - "continuing with the current partition, " - "load balance will not be optimal"); + if (nodeID == 0) + message( + "WARNING: ParMETIS repartition has failed, " + "continuing with the current partition, " + "load balance will not be optimal"); for (int k = 0; k < nr_cells; k++) repartition->celllist[k] = cells[k].nodeID; } @@ -1145,13 +1139,15 @@ void partition_init(struct partition *partition, break; default: message("Invalid choice of initial partition type '%s'.", part_type); - error( "Permitted values are: 'grid', 'regions', 'balanced' or " - "'vectorized'"); + error( + "Permitted values are: 'grid', 'regions', 'balanced' or " + "'vectorized'"); #else default: message("Invalid choice of initial partition type '%s'.", part_type); - error( "Permitted values are: 'grid' or 'vectorized' when compiled " - "without ParMETIS."); + error( + "Permitted values are: 'grid' or 'vectorized' when compiled " + "without ParMETIS."); #endif } @@ -1348,9 +1344,11 @@ void partition_restore_celllist(struct space *s, error("Not all ranks are present in the restored partition"); } } else { - error("Cannot apply the saved partition celllist as the " - "number of top-level cells (%d) is different to the " - "saved number (%d)", s->nr_cells, reparttype->ncelllist); + error( + "Cannot apply the saved partition celllist as the " + "number of top-level cells (%d) is different to the " + "saved number (%d)", + s->nr_cells, reparttype->ncelllist); } } } diff --git a/src/restart.c b/src/restart.c index a507555fe62277f2bec117299f9bc12d87985153..4f4d2b9fba2b40c21f767894cc20d79c8c748aea 100644 --- a/src/restart.c +++ b/src/restart.c @@ -142,8 +142,8 @@ void restart_write(struct engine *e, const char *filename) { /* Just an END statement to spot truncated files. */ restart_write_blocks(SWIFT_RESTART_END_SIGNATURE, - strlen(SWIFT_RESTART_END_SIGNATURE), - 1, stream, "endsignature", "SWIFT end signature"); + strlen(SWIFT_RESTART_END_SIGNATURE), 1, stream, + "endsignature", "SWIFT end signature"); fclose(stream); }