From 856b9ea54c6ecc8f0f84726edd2c6fc2a29dbd8c Mon Sep 17 00:00:00 2001
From: "Peter W. Draper" <p.w.draper@durham.ac.uk>
Date: Fri, 1 Dec 2017 15:34:35 +0000
Subject: [PATCH] Protect against zero range of the repartitioning weights
---
src/partition.c | 20 ++++++++++++++++----
1 file changed, 16 insertions(+), 4 deletions(-)
diff --git a/src/partition.c b/src/partition.c
index 63eee1a006..51231b5c01 100644
--- a/src/partition.c
+++ b/src/partition.c
@@ -703,7 +703,10 @@ static void repart_edge_metis(int partweights, int bothweights, int timebins,
/* Make range the same in both weights systems. */
if ((wmaxv - wminv) > (wmaxe - wmine)) {
- double wscale = (wmaxv - wminv) / (wmaxe - wmine);
+ double wscale = 1.0;
+ if ((wmaxe - wmine) > 0.0) {
+ wscale = (wmaxv - wminv) / (wmaxe - wmine);
+ }
for (int k = 0; k < 26 * nr_cells; k++) {
weights_e[k] = (weights_e[k] - wmine) * wscale + wminv;
}
@@ -711,7 +714,10 @@ static void repart_edge_metis(int partweights, int bothweights, int timebins,
wmaxe = wmaxv;
} else {
- double wscale = (wmaxe - wmine) / (wmaxv - wminv);
+ double wscale = 1.0;
+ if ((wmaxv - wminv) > 0.0) {
+ wscale = (wmaxe - wmine) / (wmaxv - wminv);
+ }
for (int k = 0; k < nr_cells; k++) {
weights_v[k] = (weights_v[k] - wminv) * wscale + wmine;
}
@@ -720,14 +726,20 @@ static void repart_edge_metis(int partweights, int bothweights, int timebins,
}
/* Scale to the METIS range. */
- double wscale = (metis_maxweight - 1.0) / (wmaxv - wminv);
+ double wscale = 1.0;
+ if ((wmaxv - wminv) > 0.0) {
+ wscale = (metis_maxweight - 1.0) / (wmaxv - wminv);
+ }
for (int k = 0; k < nr_cells; k++) {
weights_v[k] = (weights_v[k] - wminv) * wscale + 1.0;
}
}
/* Scale to the METIS range. */
- double wscale = (metis_maxweight - 1.0) / (wmaxe - wmine);
+ double wscale = 1.0;
+ if ((wmaxe - wmine) > 0.0) {
+ wscale = (metis_maxweight - 1.0) / (wmaxe - wmine);
+ }
for (int k = 0; k < 26 * nr_cells; k++) {
weights_e[k] = (weights_e[k] - wmine) * wscale + 1.0;
}
--
GitLab