Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -69,3 +69,4 @@ libtorch*.zip*
__pycache__/
lib/
bin/
.vscode/
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ loadbalancing
{
active true;
log false;
algorithm allAverage;//headTail;
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ loadbalancing
{
active true;
log false;
algorithm allAverage;//headTail;
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ loadbalancing
{
active true;
log false;
algorithm allAverage;//headTail;
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ loadbalancing
{
active true;
log false;
algorithm allAverage;//headTail;
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ loadbalancing
{
active true;
log false;
algorithm allAverage;//headTail;
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ loadbalancing
{
active true;
log false;
algorithm allAverage;//headTail;
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ loadbalancing
{
active true;
log false;
algorithm allAverage;//headTail;
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ loadbalancing
{
active true;
log false;
algorithm allAverage;//headTail;
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ loadbalancing
{
active true;
log false;
algorithm allAverage;//headTail;
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ loadbalancing
{
active true;
log false;
algorithm allAverage;//headTail;
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ loadbalancing
{
active true;
log false;
algorithm allAverage;//headTail;
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ loadbalancing
{
active true;
log false;
algorithm allAverage;//headTail;
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ loadbalancing
{
active true;
log false;
algorithm allAverage;//headTail;
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ loadbalancing
{
active true;
log false;
algorithm allAverage;//headTail;
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ loadbalancing
{
active true;
log false;
algorithm allAverage;//headTail;
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ loadbalancing
{
active true;
log false;
algorithm allAverage;//headTail;
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ loadbalancing
{
active true;
log false;
algorithm allAverage;//headTail;
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ loadbalancing
{
active true;
log false;
algorithm allAverage;//headTail;
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ loadbalancing
{
active true;
log false;
algorithm allAverage;//headTail;
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ loadbalancing
{
active true;
log false;
algorithm allAverage;//headTail;
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ loadbalancing
{
active true;
log false;
algorithm allAverage;//headTail;
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ loadbalancing
{
active true;
log false;
algorithm allAverage;//headTail;
}


Expand Down
70 changes: 69 additions & 1 deletion src/dfChemistryModel/loadBalancing/LoadBalancer.C
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,23 @@ Foam::LoadBalancer::updateState(
if (Pstream::myProcNo(comm) == -1) return;
auto myLoad = computeLoad(problems, comm);
auto allLoads = allGather(myLoad, comm);
auto operations = getOperations(allLoads, myLoad);
std::vector<Foam::LoadBalancer::Operation> operations;
if (algorithm_ == "allAverage")
{
operations = getOperations(allLoads, myLoad);
if (log_)
{
Info << "now perform load balance with allAverage (DLB) algorithm" << endl;
}
}
else
{
operations = getOperationsRedezVous(allLoads, myLoad);
if (log_)
{
Info << "now perform load balance with headTail (RedezVous) algorithm" << endl;
}
}
auto info = operationsToInfo(operations, problems, myLoad);

setState(info);
Expand Down Expand Up @@ -163,6 +179,58 @@ Foam::LoadBalancer::getOperations(
return large;
}

//perform load balance with Redez-vous algorithm
std::vector<Foam::LoadBalancer::Operation>
Foam::LoadBalancer::getOperationsRedezVous(
DynamicList<ChemistryLoad>& loads, const ChemistryLoad& myLoad)
{
double globalMean = getMean(loads); //calculate the mean load

std::vector<Operation> operations;

std::sort(loads.begin(), loads.end()); //sort the loads

auto sender = loads.end() - 1; //the last load greater than the mean load
auto receiver = loads.begin();

for (int i = 0; i < int(loads.size()/2); ++i)
{
//std::cout << "sender: " << sender->rank << " receiver: " << receiver->rank << std::endl;

double send_value = (sender->value - receiver->value) / 2; // calculate the send value

Operation operation{sender->rank, receiver->rank, send_value};
if(sender->rank == myLoad.rank || receiver->rank == myLoad.rank)
{
operations.push_back(operation); // if send or recv rank related to my rank, add to operations
}
sender->value -= send_value; // update the load
receiver->value += send_value; // update the load

sender--;
receiver++;
}

// explicitly filter very small operations
std::vector<Operation> large;
for(const auto& op:operations)
{
if(op.value > 0.01 * globalMean) //if send value is larger than 1% of global mean
{
large.push_back(op); // add to large operations
}
}
runtime_assert(
!((isSender(operations, myLoad.rank) &&
isReceiver(operations, myLoad.rank))),
"Only sender or receiver should be possible.");

runtime_assert(
std::abs(getMean(loads) - globalMean) < 1E-7, "Vanishing load");

return large; //return large operations
}

bool
Foam::LoadBalancer::isSender(
const std::vector<Operation>& operations, int rank)
Expand Down
19 changes: 18 additions & 1 deletion src/dfChemistryModel/loadBalancing/LoadBalancer.H
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,17 @@ public:
: LoadBalancerBase(), dict_(dict),
coeffsDict_(dict.subDict("loadbalancing")),
active_(coeffsDict_.lookupOrDefault<Switch>("active", true)),
log_(coeffsDict_.lookupOrDefault<Switch>("log", false))
log_(coeffsDict_.lookupOrDefault<Switch>("log", false)),
algorithm_(coeffsDict_.lookup("algorithm"))
{
if ((algorithm_ != "allAverage") && (algorithm_ != "headTail"))
{
FatalError
<< "in loadBalancing Settings, unknown algorithm type "
<< algorithm_ << nl
<< " Valid types are: allAverage or headTail."
<< exit(FatalError);
}
}

// Destructor
Expand Down Expand Up @@ -103,6 +112,11 @@ protected:
static std::vector<LoadBalancer::Operation> getOperations(
DynamicList<ChemistryLoad>& loads, const ChemistryLoad& myLoad);

//- Get the operations for this rank that would minimize the load to
// global mean with Redez-vous algorithm
static std::vector<LoadBalancer::Operation> getOperationsRedezVous(
DynamicList<ChemistryLoad>& loads, const ChemistryLoad& myLoad);

//- Convert the operations to send and receive info to handle balancing
static BalancerState operationsToInfo(
const std::vector<Operation>& operations,
Expand All @@ -128,6 +142,9 @@ private:
// Is load balancing logged?
Switch log_;

// chose the appropriate load balancing algorithm
const word algorithm_;

//- Check if the rank is a sender
static bool isSender(const std::vector<Operation>& operations, int rank);

Expand Down
21 changes: 0 additions & 21 deletions src/dfCombustionModels/Make/options
Original file line number Diff line number Diff line change
Expand Up @@ -11,21 +11,9 @@ EXE_INC = -std=c++14 \
-I$(LIB_SRC)/TurbulenceModels/compressible/lnInclude \
-I$(LIB_SRC)/finiteVolume/lnInclude \
-I$(LIB_SRC)/meshTools/lnInclude \
-I$(LIB_SRC)/lagrangian/basic/lnInclude \
-I$(DF_SRC)/lagrangian/intermediate/lnInclude \
-I$(LIB_SRC)/lagrangian/intermediate/lnInclude \
-I$(DF_SRC)/lagrangian/spray/lnInclude \
-I$(LIB_SRC)/lagrangian/spray/lnInclude \
-I$(LIB_SRC)/thermophysicalModels/basic/lnInclude \
-I$(DF_SRC)/thermophysicalModels/thermophysicalProperties/lnInclude \
-I$(DF_SRC)/thermophysicalModels/SLGThermo/lnInclude \
-I$(LIB_SRC)/regionModels/regionModel/lnInclude \
-I$(LIB_SRC)/regionModels/surfaceFilmModels/lnInclude \
-I$(DF_SRC)/dfCanteraMixture/lnInclude \
-I$(DF_SRC)/dfChemistryModel/lnInclude \
-I$(LIB_SRC)/Pstream/mpi \
-I$(LIB_SRC)/ODE/lnInclude \
-I$(LIB_SRC)/functionObjects/field/lnInclude \
-I$(CANTERA_ROOT)/include \
$(if $(LIBTORCH_ROOT),-I$(LIBTORCH_ROOT)/include,) \
$(if $(LIBTORCH_ROOT),-I$(LIBTORCH_ROOT)/include/torch/csrc/api/include,) \
Expand All @@ -39,17 +27,8 @@ LIB_LIBS = \
-lmeshTools \
-L$(DF_LIBBIN) \
-ldfCompressibleTurbulenceModels \
-ldfLagrangianIntermediate \
-ldfLagrangianTurbulence \
-ldfLagrangianSpray \
-ldfFluidThermophysicalModels \
-ldfThermophysicalProperties \
-ldfSLGThermo \
-lregionModels \
-lsurfaceFilmModels \
-ldfCanteraMixture \
-ldfChemistryModel \
-lODE \
$(CANTERA_ROOT)/lib/libcantera.so \
$(if $(LIBTORCH_ROOT),$(LIBTORCH_ROOT)/lib/libtorch.so,) \
$(if $(LIBTORCH_ROOT),$(LIBTORCH_ROOT)/lib/libc10.so,) \
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,5 +44,6 @@ loadbalancing
{
active false;
//log true;
algorithm allAverage;
}
// ************************************************************************* //