Skip to content

Commit 86d6c29

Browse files
committed
compute balance on cpus, but show warning only on gpus
1 parent ac820e0 commit 86d6c29

1 file changed

Lines changed: 28 additions & 29 deletions

File tree

src/timeIntegrator.cpp

Lines changed: 28 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -197,34 +197,33 @@ double TimeIntegrator::ComputeBalance() {
197197
// Check MPI imbalance
198198
double imbalance = 0;
199199
#ifdef WITH_MPI
200-
// only do this on GPUs
201-
#if defined(KOKKOS_ENABLE_CUDA) || defined(KOKKOS_ENABLE_HIP) || defined(KOKKOS_ENABLE_SYCL)
202-
const double allowedImbalance = 20.0;
203-
std::vector<double> computeLogPerCore(idfx::psize);
204-
MPI_Gather(&computeLastLog, 1, MPI_DOUBLE, computeLogPerCore.data(), 1, MPI_DOUBLE, 0,
205-
MPI_COMM_WORLD);
206-
computeLastLog = 0; // reset timer for all cores
207-
if(idfx::prank==0) {
208-
// Compute the average, the min and the max
209-
double computeMin = computeLogPerCore[0];
210-
double computeMax = computeLogPerCore[0];
211-
double computeMean = 0;
212-
213-
for(int i = 0 ; i < idfx::psize ; i++) {
214-
computeMean += computeLogPerCore[i];
215-
if(computeLogPerCore[i]>computeMax) {
216-
computeMax = computeLogPerCore[i];
217-
}
218-
if(computeLogPerCore[i]<computeMin) {
219-
computeMin = computeLogPerCore[i];
220-
}
200+
const double allowedImbalance = 20.0;
201+
std::vector<double> computeLogPerCore(idfx::psize);
202+
MPI_Gather(&computeLastLog, 1, MPI_DOUBLE, computeLogPerCore.data(), 1, MPI_DOUBLE, 0,
203+
MPI_COMM_WORLD);
204+
computeLastLog = 0; // reset timer for all cores
205+
if(idfx::prank==0) {
206+
// Compute the average, the min and the max
207+
double computeMin = computeLogPerCore[0];
208+
double computeMax = computeLogPerCore[0];
209+
double computeMean = 0;
210+
211+
for(int i = 0 ; i < idfx::psize ; i++) {
212+
computeMean += computeLogPerCore[i];
213+
if(computeLogPerCore[i]>computeMax) {
214+
computeMax = computeLogPerCore[i];
221215
}
222-
computeMean /= idfx::psize;
223-
imbalance = (computeMax-computeMin)/computeMean*100;
224-
216+
if(computeLogPerCore[i]<computeMin) {
217+
computeMin = computeLogPerCore[i];
218+
}
219+
}
220+
computeMean /= idfx::psize;
221+
imbalance = (computeMax-computeMin)/computeMean*100;
222+
// only show warnings if the imbalance is higher than 20%on GPUs
223+
#if defined(KOKKOS_ENABLE_CUDA) || defined(KOKKOS_ENABLE_HIP) || defined(KOKKOS_ENABLE_SYCL)
225224
if(imbalance>allowedImbalance ) {
226225
idfx::cout << "-------------------------------------------------------------"
227-
<< std::endl;
226+
<< std::endl;
228227
idfx::cout << "Warning: MPI imbalance found in this run " << std::endl;
229228
idfx::cout << std::fixed;
230229
for(int i = 0 ; i < idfx::psize ; i++) {
@@ -238,12 +237,12 @@ double TimeIntegrator::ComputeBalance() {
238237
}
239238
}
240239
idfx::cout << "You should probably check these nodes are running properly."
241-
<< std::endl;
240+
<< std::endl;
242241
idfx::cout << "-------------------------------------------------------------"
243-
<< std::endl;
242+
<< std::endl;
244243
}
245-
}
246-
#endif
244+
#endif
245+
}
247246
#endif
248247
return(imbalance);
249248
}

0 commit comments

Comments
 (0)