diff --git a/src/engine.c b/src/engine.c index 961e50dfba84b9ec6c08cb0774fd58fbd78bd86d..a1a4c2e1c8d263c17bf28138e72adcd3dad9016c 100644 --- a/src/engine.c +++ b/src/engine.c @@ -317,7 +317,7 @@ void engine_redistribute(struct engine *e) { MPI_COMM_WORLD) != MPI_SUCCESS) error("Failed to allreduce particle transfer counts."); - /* Report how many particles have been moved. */ + /* Report how many particles will be moved. */ if (e->verbose) { if (e->nodeID == 0) { size_t total = 0; @@ -329,8 +329,8 @@ void engine_redistribute(struct engine *e) { r++; } } - message("of %ld particles %ld are not transferred (%.2f%%)", total, - unmoved, 100.0 * (double)unmoved / (double)total); + message("%ld of %ld (%.2f%%) of particles moved", total - unmoved, + total, 100.0 * (double)(total - unmoved) / (double)total); } } diff --git a/src/partition.c b/src/partition.c index 14de6dea021ab604e61a668ca1f0526d4ec0cddc..85745d880e3ab0f6beaf918a5c226730b6b82a7c 100644 --- a/src/partition.c +++ b/src/partition.c @@ -396,17 +396,18 @@ static void pick_metis(struct space *s, int nregions, int *vertexw, int *edgew, /* We want a solution in which the current regions of the space are * preserved when possible, to avoid unneccesary particle movement. - * So try mapping the current regions to the new regions and reassigning - * those with the greatest number of common cells... */ - int keymax = nregions * nregions; - struct indexval *ivs = malloc(sizeof(struct indexval) * keymax); - bzero(ivs, sizeof(struct indexval) * keymax); + * So create a 2d-array of cells counts that are common to all pairs + * of old and new ranks. Each element of the array has a cell count and + * an unique index so we can sort into decreasing counts. */ + int indmax = nregions * nregions; + struct indexval *ivs = malloc(sizeof(struct indexval) * indmax); + bzero(ivs, sizeof(struct indexval) * indmax); for (int k = 0; k < ncells; k++) { int index = regionid[k] + nregions * s->cells_top[k].nodeID; ivs[index].count++; ivs[index].index = index; } - qsort(ivs, keymax, sizeof(struct indexval), indexvalcmp); + qsort(ivs, indmax, sizeof(struct indexval), indexvalcmp); /* Go through the ivs using the largest counts first, these are the * regions with the most cells in common, old partition to new. */ @@ -416,7 +417,7 @@ static void pick_metis(struct space *s, int nregions, int *vertexw, int *edgew, oldmap[k] = -1; newmap[k] = -1; } - for (int k = 0; k < keymax; k++) { + for (int k = 0; k < indmax; k++) { /* Stop when all regions with common cells have been considered. */ if (ivs[k].count == 0) break;