From 3cf6715d40fb33cd0ab72bf256d30ded90e61c7f Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Tue, 2 Aug 2016 16:53:12 -0400 Subject: [PATCH] be a bit more paranoid about initializing data structures (cherry picked from commit bda51f2bacca022111aa3611ab1d28e80b423449) --- src/balance.cpp | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/src/balance.cpp b/src/balance.cpp index 15b57a6cb6..8273a78e85 100644 --- a/src/balance.cpp +++ b/src/balance.cpp @@ -103,7 +103,7 @@ void Balance::command(int narg, char **arg) if (domain->box_exist == 0) error->all(FLERR,"Balance command before simulation box is defined"); - if (comm->me == 0 && screen) fprintf(screen,"Balancing ...\n"); + if (me == 0 && screen) fprintf(screen,"Balancing ...\n"); // parse arguments @@ -480,7 +480,7 @@ double Balance::imbalance_clock(double factor, double last_cost) cost += timer->get_wall(Timer::KSPACE); double *clock_cost = new double[nprocs+1]; - for (int i = 0; i <= nprocs; ++i) clock_cost[i] = 0.0; + for (int i = 0; i <= nprocs; ++i) clock_imbalance[i] = clock_cost[i] = 0.0; clock_cost[me] = cost; clock_cost[nprocs] = cost; MPI_Allreduce(clock_cost,clock_imbalance,nprocs+1,MPI_DOUBLE,MPI_SUM,world); @@ -525,15 +525,16 @@ double Balance::imbalance_nlocal(int &maxcost) } if (clock_imbalance) cost *= clock_imbalance[me]; - double imbalance = 1.0; int intcost = (int)cost; - int sumcost; + int sumcost = maxcost = 0; MPI_Allreduce(&intcost,&maxcost,1,MPI_INT,MPI_MAX,world); MPI_Allreduce(&intcost,&sumcost,1,MPI_INT,MPI_SUM,world); - if (maxcost && sumcost > 0) + double imbalance = 1.0; + if (maxcost > 0 && sumcost > 0) imbalance = maxcost / (static_cast(sumcost)/nprocs); + return imbalance; }