From 9e50d8bdcfee9b33957fdc5351a80e5802705df7 Mon Sep 17 00:00:00 2001 From: csendlinger Date: Wed, 4 Sep 2024 10:59:16 +0200 Subject: [PATCH] bug fix for unbalanced cpu loads --- src/simulation/simulation.cpp | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/src/simulation/simulation.cpp b/src/simulation/simulation.cpp index adfd0f5..96ed7a4 100755 --- a/src/simulation/simulation.cpp +++ b/src/simulation/simulation.cpp @@ -98,7 +98,25 @@ void Simulation::start() { int leftover_events = events_this_cpu; int num_cpu_syncs = 0; - while (leftover_events > 0) { + + bool empty_loop = false; + if(total_simulated_events % MpiCommunication::mpiSize() != 0) { + if((events_this_cpu % event_stride == 0) && + (total_simulated_events % MpiCommunication::mpiSize() + <= MpiCommunication::mpiRank())) { + DEBUG_LEVEL_3("empty loop"); + empty_loop = true; + } + } + + while (leftover_events > 0 || empty_loop) { + // special case of unbalanced cpu load, with a part of the cpus having one cycle + // that has no events, while the rest of the cpus have a single event (questionable if needed) + if(leftover_events == 0 && empty_loop) { + DEBUG_LEVEL_3("empty loop looped"); + empty_loop = false; + } + int events_of_cylcle = eventsOfCycle(event_stride, leftover_events); SIM_INFO("Leftover events on first cpu: " + std::to_string(leftover_events));