Skip to content
Snippets Groups Projects
Commit 06f2338b authored by Matthieu Schaller's avatar Matthieu Schaller
Browse files

Code style fixes.

parent 45ba0cda
Branches
Tags
No related merge requests found
...@@ -529,9 +529,9 @@ int main(int argc, char *argv[]) { ...@@ -529,9 +529,9 @@ int main(int argc, char *argv[]) {
if (myrank == 0) { if (myrank == 0) {
#if defined(HAVE_PARMETIS) #if defined(HAVE_PARMETIS)
if (reparttype.usemetis) if (reparttype.usemetis)
message("Using METIS serial partitioning:"); message("Using METIS serial partitioning:");
else else
message("Using ParMETIS partitioning:"); message("Using ParMETIS partitioning:");
#else #else
message("Using METIS serial partitioning:"); message("Using METIS serial partitioning:");
#endif #endif
......
...@@ -29,8 +29,8 @@ ...@@ -29,8 +29,8 @@
#include "../config.h" #include "../config.h"
/* Standard headers. */ /* Standard headers. */
#include <stdio.h>
#include <limits.h> #include <limits.h>
#include <stdio.h>
#include <unistd.h> #include <unistd.h>
/* Local headers. */ /* Local headers. */
...@@ -294,10 +294,10 @@ double clocks_get_cputime_used(void) { ...@@ -294,10 +294,10 @@ double clocks_get_cputime_used(void) {
*/ */
int clocks_random_seed(void) { int clocks_random_seed(void) {
#ifdef HAVE_CLOCK_GETTIME #ifdef HAVE_CLOCK_GETTIME
struct timespec timespec; struct timespec timespec;
clock_gettime(CLOCK_REALTIME, &timespec); clock_gettime(CLOCK_REALTIME, &timespec);
return (timespec.tv_nsec % INT_MAX); return (timespec.tv_nsec % INT_MAX);
#else #else
return (getticks() % INT_MAX); return (getticks() % INT_MAX);
#endif #endif
} }
...@@ -356,8 +356,7 @@ void io_write_code_description(hid_t h_file) { ...@@ -356,8 +356,7 @@ void io_write_code_description(hid_t h_file) {
#ifdef WITH_MPI #ifdef WITH_MPI
io_write_attribute_s(h_grpcode, "MPI library", mpi_version()); io_write_attribute_s(h_grpcode, "MPI library", mpi_version());
#ifdef HAVE_METIS #ifdef HAVE_METIS
io_write_attribute_s(h_grpcode, "METIS library version", io_write_attribute_s(h_grpcode, "METIS library version", metis_version());
metis_version());
#endif #endif
#ifdef HAVE_PARMETIS #ifdef HAVE_PARMETIS
io_write_attribute_s(h_grpcode, "ParMETIS library version", io_write_attribute_s(h_grpcode, "ParMETIS library version",
......
...@@ -39,7 +39,7 @@ int checkCellhdxmax(const struct cell *c, int *depth); ...@@ -39,7 +39,7 @@ int checkCellhdxmax(const struct cell *c, int *depth);
void dumpCells(const char *prefix, int super, int active, int mpiactive, void dumpCells(const char *prefix, int super, int active, int mpiactive,
int pactive, struct space *s, int rank, int step); int pactive, struct space *s, int rank, int step);
#if defined(WITH_MPI) && (defined(HAVE_METIS) ||defined(HAVE_PARMETIS)) #if defined(WITH_MPI) && (defined(HAVE_METIS) || defined(HAVE_PARMETIS))
#include "metis.h" #include "metis.h"
void dumpMETISGraph(const char *prefix, idx_t nvtxs, idx_t ncon, idx_t *xadj, void dumpMETISGraph(const char *prefix, idx_t nvtxs, idx_t ncon, idx_t *xadj,
idx_t *adjncy, idx_t *vwgt, idx_t *vsize, idx_t *adjwgt); idx_t *adjncy, idx_t *vwgt, idx_t *vsize, idx_t *adjwgt);
......
...@@ -60,19 +60,15 @@ ...@@ -60,19 +60,15 @@
/* Simple descriptions of initial partition types for reports. */ /* Simple descriptions of initial partition types for reports. */
const char *initial_partition_name[] = { const char *initial_partition_name[] = {
"axis aligned grids of cells", "axis aligned grids of cells", "vectorized point associated cells",
"vectorized point associated cells",
"memory balanced, using particle weighted cells", "memory balanced, using particle weighted cells",
"similar sized regions, using unweighted cells"}; "similar sized regions, using unweighted cells"};
/* Simple descriptions of repartition types for reports. */ /* Simple descriptions of repartition types for reports. */
const char *repartition_name[] = { const char *repartition_name[] = {
"none", "none", "edge and vertex task cost weights", "task cost edge weights",
"edge and vertex task cost weights",
"task cost edge weights",
"task cost vertex weights", "task cost vertex weights",
"vertex task costs and edge delta timebin weights" "vertex task costs and edge delta timebin weights"};
};
/* Local functions, if needed. */ /* Local functions, if needed. */
static int check_complete(struct space *s, int verbose, int nregions); static int check_complete(struct space *s, int verbose, int nregions);
...@@ -155,17 +151,17 @@ static void split_vector(struct space *s, int nregions, int *samplecells) { ...@@ -155,17 +151,17 @@ static void split_vector(struct space *s, int nregions, int *samplecells) {
} }
#endif #endif
/* METIS/ParMETIS support (optional) /* METIS/ParMETIS support (optional)
* ================================= * =================================
* *
* METIS/ParMETIS partitions using a multi-level k-way scheme. We support * METIS/ParMETIS partitions using a multi-level k-way scheme. We support
* using this in a unweighted scheme, which works well and seems to be * using this in a unweighted scheme, which works well and seems to be
* guaranteed, and a weighted by the number of particles scheme. * guaranteed, and a weighted by the number of particles scheme.
* *
* Repartitioning is based on ParMETIS and uses weights determined from the * Repartitioning is based on ParMETIS and uses weights determined from the
* estimated costs that a cells tasks will take or the relative time bins of * estimated costs that a cells tasks will take or the relative time bins of
* the cells next updates. * the cells next updates.
*/ */
#if defined(WITH_MPI) && (defined(HAVE_METIS) || defined(HAVE_PARMETIS)) #if defined(WITH_MPI) && (defined(HAVE_METIS) || defined(HAVE_PARMETIS))
/** /**
...@@ -625,7 +621,6 @@ static void pick_parmetis(int nodeID, struct space *s, int nregions, ...@@ -625,7 +621,6 @@ static void pick_parmetis(int nodeID, struct space *s, int nregions,
if (refine) if (refine)
for (int i = 0; i < nvt; i++) full_regionid[j3 + i] = celllist[j3 + i]; for (int i = 0; i < nvt; i++) full_regionid[j3 + i] = celllist[j3 + i];
if (rank == 0) { if (rank == 0) {
memcpy(xadj, &full_xadj[j1], sizeof(idx_t) * (nvt + 1)); memcpy(xadj, &full_xadj[j1], sizeof(idx_t) * (nvt + 1));
memcpy(adjncy, &full_adjncy[j2], sizeof(idx_t) * nvt * 26); memcpy(adjncy, &full_adjncy[j2], sizeof(idx_t) * nvt * 26);
...@@ -737,19 +732,19 @@ static void pick_parmetis(int nodeID, struct space *s, int nregions, ...@@ -737,19 +732,19 @@ static void pick_parmetis(int nodeID, struct space *s, int nregions,
* refinement. */ * refinement. */
if (adaptive) { if (adaptive) {
/* Balance between cuts and movement. */ /* Balance between cuts and movement. */
real_t itr_real_t = itr; real_t itr_real_t = itr;
if (ParMETIS_V3_AdaptiveRepart(vtxdist, xadj, adjncy, weights_v, NULL, if (ParMETIS_V3_AdaptiveRepart(
weights_e, &wgtflag, &numflag, &ncon, vtxdist, xadj, adjncy, weights_v, NULL, weights_e, &wgtflag,
&nparts, tpwgts, ubvec, &itr_real_t, options, &numflag, &ncon, &nparts, tpwgts, ubvec, &itr_real_t, options,
&edgecut, regionid, &comm) != METIS_OK) &edgecut, regionid, &comm) != METIS_OK)
error("Call to ParMETIS_V3_AdaptiveRepart failed."); error("Call to ParMETIS_V3_AdaptiveRepart failed.");
} else { } else {
if (ParMETIS_V3_RefineKway(vtxdist, xadj, adjncy, weights_v, weights_e, if (ParMETIS_V3_RefineKway(vtxdist, xadj, adjncy, weights_v, weights_e,
&wgtflag, &numflag, &ncon, &nparts, tpwgts, &wgtflag, &numflag, &ncon, &nparts, tpwgts,
ubvec, options, &edgecut, regionid, ubvec, options, &edgecut, regionid,
&comm) != METIS_OK) &comm) != METIS_OK)
error("Call to ParMETIS_V3_RefineKway failed."); error("Call to ParMETIS_V3_RefineKway failed.");
} }
} else { } else {
...@@ -765,8 +760,9 @@ static void pick_parmetis(int nodeID, struct space *s, int nregions, ...@@ -765,8 +760,9 @@ static void pick_parmetis(int nodeID, struct space *s, int nregions,
options[2] = clocks_random_seed(); options[2] = clocks_random_seed();
if (ParMETIS_V3_PartKway(vtxdist, xadj, adjncy, weights_v, weights_e, if (ParMETIS_V3_PartKway(vtxdist, xadj, adjncy, weights_v, weights_e,
&wgtflag, &numflag, &ncon, &nparts, tpwgts, ubvec, &wgtflag, &numflag, &ncon, &nparts, tpwgts,
options, &edgecut, regionid, &comm) != METIS_OK) ubvec, options, &edgecut, regionid,
&comm) != METIS_OK)
error("Call to ParMETIS_V3_PartKway failed."); error("Call to ParMETIS_V3_PartKway failed.");
if (i == 0 || (best_edgecut > edgecut)) { if (i == 0 || (best_edgecut > edgecut)) {
...@@ -1072,8 +1068,8 @@ static void pick_metis(int nodeID, struct space *s, int nregions, ...@@ -1072,8 +1068,8 @@ static void pick_metis(int nodeID, struct space *s, int nregions,
*/ */
static void repart_edge_metis(int vweights, int eweights, int timebins, static void repart_edge_metis(int vweights, int eweights, int timebins,
struct repartition *repartition, int nodeID, struct repartition *repartition, int nodeID,
int nr_nodes, struct space *s, int nr_nodes, struct space *s, struct task *tasks,
struct task *tasks, int nr_tasks) { int nr_tasks) {
/* Create weight arrays using task ticks for vertices and edges (edges /* Create weight arrays using task ticks for vertices and edges (edges
* assume the same graph structure as used in the part_ calls). */ * assume the same graph structure as used in the part_ calls). */
...@@ -1220,7 +1216,8 @@ static void repart_edge_metis(int vweights, int eweights, int timebins, ...@@ -1220,7 +1216,8 @@ static void repart_edge_metis(int vweights, int eweights, int timebins,
if (vweights) { if (vweights) {
res = MPI_Allreduce(MPI_IN_PLACE, weights_v, nr_cells, MPI_DOUBLE, MPI_SUM, res = MPI_Allreduce(MPI_IN_PLACE, weights_v, nr_cells, MPI_DOUBLE, MPI_SUM,
MPI_COMM_WORLD); MPI_COMM_WORLD);
if (res != MPI_SUCCESS) mpi_error(res, "Failed to allreduce vertex weights."); if (res != MPI_SUCCESS)
mpi_error(res, "Failed to allreduce vertex weights.");
} }
if (eweights) { if (eweights) {
...@@ -1229,7 +1226,7 @@ static void repart_edge_metis(int vweights, int eweights, int timebins, ...@@ -1229,7 +1226,7 @@ static void repart_edge_metis(int vweights, int eweights, int timebins,
if (res != MPI_SUCCESS) mpi_error(res, "Failed to allreduce edge weights."); if (res != MPI_SUCCESS) mpi_error(res, "Failed to allreduce edge weights.");
} }
/* Allocate cell list for the partition. If not already done. */ /* Allocate cell list for the partition. If not already done. */
#ifdef HAVE_PARMETIS #ifdef HAVE_PARMETIS
int refine = 1; int refine = 1;
#endif #endif
...@@ -1239,21 +1236,22 @@ static void repart_edge_metis(int vweights, int eweights, int timebins, ...@@ -1239,21 +1236,22 @@ static void repart_edge_metis(int vweights, int eweights, int timebins,
#endif #endif
free(repartition->celllist); free(repartition->celllist);
repartition->ncelllist = 0; repartition->ncelllist = 0;
if ((repartition->celllist = (int *)malloc(sizeof(int) * nr_cells)) == if ((repartition->celllist = (int *)malloc(sizeof(int) * nr_cells)) == NULL)
NULL)
error("Failed to allocate celllist"); error("Failed to allocate celllist");
repartition->ncelllist = nr_cells; repartition->ncelllist = nr_cells;
} }
/* We need to rescale the sum of the weights so that the sums of the two /* We need to rescale the sum of the weights so that the sums of the two
* types of weights are less than IDX_MAX, that is the range of idx_t. Also * types of weights are less than IDX_MAX, that is the range of idx_t. Also
* we would like to balance edges and vertices when the edge weights are * we would like to balance edges and vertices when the edge weights are
* timebins, as these have no reason to have equivalent scales, so we use an * timebins, as these have no reason to have equivalent scales, so we use an
* equipartition. */ * equipartition. */
double vsum = 0.0; double vsum = 0.0;
if (vweights) for (int k = 0; k < nr_cells; k++) vsum += weights_v[k]; if (vweights)
for (int k = 0; k < nr_cells; k++) vsum += weights_v[k];
double esum = 0.0; double esum = 0.0;
if (eweights) for (int k = 0; k < 26 * nr_cells; k++) esum += weights_e[k]; if (eweights)
for (int k = 0; k < 26 * nr_cells; k++) esum += weights_e[k];
double vscale = 1.0; double vscale = 1.0;
double escale = 1.0; double escale = 1.0;
...@@ -1282,19 +1280,21 @@ static void repart_edge_metis(int vweights, int eweights, int timebins, ...@@ -1282,19 +1280,21 @@ static void repart_edge_metis(int vweights, int eweights, int timebins,
} }
} }
} }
if (vscale != 1.0) for (int k = 0; k < nr_cells; k++) weights_v[k] *= vscale; if (vscale != 1.0)
for (int k = 0; k < nr_cells; k++) weights_v[k] *= vscale;
} }
if (eweights) { if (eweights) {
if (esum > (double)IDX_MAX) if (esum > (double)IDX_MAX) escale = (double)(IDX_MAX - 1000) / esum;
escale = (double)(IDX_MAX - 1000) / esum; if (escale != 1.0)
if (escale != 1.0) for (int k = 0; k < 26 * nr_cells; k++) weights_e[k] *= escale; for (int k = 0; k < 26 * nr_cells; k++) weights_e[k] *= escale;
} }
/* And repartition/ partition, using both weights or not as requested. */ /* And repartition/ partition, using both weights or not as requested. */
#ifdef HAVE_PARMETIS #ifdef HAVE_PARMETIS
if (repartition->usemetis) { if (repartition->usemetis) {
pick_metis(nodeID, s, nr_nodes, weights_v, weights_e, repartition->celllist); pick_metis(nodeID, s, nr_nodes, weights_v, weights_e,
repartition->celllist);
} else { } else {
pick_parmetis(nodeID, s, nr_nodes, weights_v, weights_e, refine, pick_parmetis(nodeID, s, nr_nodes, weights_v, weights_e, refine,
repartition->adaptive, repartition->itr, repartition->adaptive, repartition->itr,
...@@ -1366,20 +1366,20 @@ void partition_repartition(struct repartition *reparttype, int nodeID, ...@@ -1366,20 +1366,20 @@ void partition_repartition(struct repartition *reparttype, int nodeID,
ticks tic = getticks(); ticks tic = getticks();
if (reparttype->type == REPART_METIS_VERTEX_EDGE_COSTS) { if (reparttype->type == REPART_METIS_VERTEX_EDGE_COSTS) {
repart_edge_metis(1, 1, 0, reparttype, nodeID, nr_nodes, s, tasks, repart_edge_metis(1, 1, 0, reparttype, nodeID, nr_nodes, s, tasks,
nr_tasks); nr_tasks);
} else if (reparttype->type == REPART_METIS_EDGE_COSTS) { } else if (reparttype->type == REPART_METIS_EDGE_COSTS) {
repart_edge_metis(0, 1, 0, reparttype, nodeID, nr_nodes, s, tasks, repart_edge_metis(0, 1, 0, reparttype, nodeID, nr_nodes, s, tasks,
nr_tasks); nr_tasks);
} else if (reparttype->type == REPART_METIS_VERTEX_COSTS) { } else if (reparttype->type == REPART_METIS_VERTEX_COSTS) {
repart_edge_metis(1, 0, 0, reparttype, nodeID, nr_nodes, s, tasks, repart_edge_metis(1, 0, 0, reparttype, nodeID, nr_nodes, s, tasks,
nr_tasks); nr_tasks);
} else if (reparttype->type == REPART_METIS_VERTEX_COSTS_TIMEBINS) { } else if (reparttype->type == REPART_METIS_VERTEX_COSTS_TIMEBINS) {
repart_edge_metis(1, 1, 1, reparttype, nodeID, nr_nodes, s, tasks, repart_edge_metis(1, 1, 1, reparttype, nodeID, nr_nodes, s, tasks,
nr_tasks); nr_tasks);
} else if (reparttype->type == REPART_NONE) { } else if (reparttype->type == REPART_NONE) {
/* Doing nothing. */ /* Doing nothing. */
...@@ -1467,8 +1467,8 @@ void partition_initial_partition(struct partition *initial_partition, ...@@ -1467,8 +1467,8 @@ void partition_initial_partition(struct partition *initial_partition,
accumulate_counts(s, weights); accumulate_counts(s, weights);
/* Get all the counts from all the nodes. */ /* Get all the counts from all the nodes. */
if (MPI_Allreduce(MPI_IN_PLACE, weights, s->nr_cells, MPI_DOUBLE, if (MPI_Allreduce(MPI_IN_PLACE, weights, s->nr_cells, MPI_DOUBLE, MPI_SUM,
MPI_SUM, MPI_COMM_WORLD) != MPI_SUCCESS) MPI_COMM_WORLD) != MPI_SUCCESS)
error("Failed to allreduce particle cell weights."); error("Failed to allreduce particle cell weights.");
} }
...@@ -1628,8 +1628,9 @@ void partition_init(struct partition *partition, ...@@ -1628,8 +1628,9 @@ void partition_init(struct partition *partition,
#else #else
} else { } else {
message("Invalid choice of re-partition type '%s'.", part_type); message("Invalid choice of re-partition type '%s'.", part_type);
error("Permitted values are: 'none/none' when compiled without " error(
"METIS or ParMETIS."); "Permitted values are: 'none/none' when compiled without "
"METIS or ParMETIS.");
#endif #endif
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment