14#include "arcane/utils/ArcanePrecomp.h"
16#include "arcane/core/EntryPoint.h"
17#include "arcane/core/ISubDomain.h"
18#include "arcane/core/IParallelMng.h"
19#include "arcane/core/ModuleFactory.h"
20#include "arcane/core/IMeshPartitioner.h"
21#include "arcane/core/ServiceUtils.h"
22#include "arcane/core/CommonVariables.h"
23#include "arcane/core/ITimeStats.h"
24#include "arcane/core/ITimeLoopMng.h"
25#include "arcane/core/ITimeHistoryMng.h"
26#include "arcane/core/IMesh.h"
27#include "arcane/core/IMeshModifier.h"
28#include "arcane/core/ItemPrinter.h"
29#include "arcane/core/IItemFamily.h"
31#include "arcane/std/ArcaneLoadBalance_axl.h"
39#define OLD_LOADBALANCE
47class ArcaneLoadBalanceModule
48:
public ArcaneArcaneLoadBalanceObject
53 ~ArcaneLoadBalanceModule();
62 void loadBalanceInit();
79 Real _computeImbalance();
93ArcaneLoadBalanceModule::
96, m_elapsed_computation_time(
VariableBuildInfo(this,
"ArcaneLoadBalanceElapsedComputationTime",
98, m_computation_time(0.0)
108ArcaneLoadBalanceModule::
109~ArcaneLoadBalanceModule()
116void ArcaneLoadBalanceModule::
119 m_elapsed_computation_time = 0;
126void ArcaneLoadBalanceModule::
130 info() <<
"Load balance deactivated.";
135 info() <<
"Load balance required but inactive during serial execution";
139 info() <<
"Load balance active with maximum unbalance: "
153 int period =
options()->period();
156 if (global_iteration == 0)
158 if ((global_iteration % period) != 0)
161 Real imbalance = _computeImbalance();
165 if (imbalance <
options()->maxImbalance())
172 info() <<
"Program a mesh repartitioning";
173#ifdef OLD_LOADBALANCE
184#ifdef OLD_LOADBALANCE
198 Integer nb_weight = m_nb_weight;
207 bool has_compute_time = compute_times.
size() != 0;
208 bool has_cell_time = compute_times.
size() == 2;
210 max_compute_time = 1.0;
211 Real compute_times0 = 1.0;
212 Real compute_times1 = 0.0;
213 if (has_compute_time) {
214 compute_times0 = compute_times[0];
216 compute_times1 = compute_times[1];
219 bool dump_info =
true;
221 Real time_ratio = compute_times0 / max_compute_time;
222 Real time_ratio2 = compute_times1 / max_compute_time;
225 info() <<
" MAX_COMPUTE=" << max_compute_time;
226 info() <<
" COMPUTE 0=" << compute_times0;
227 info() <<
" COMPUTE 1=" << compute_times1;
228 info() <<
" TIME RATIO 0=" << time_ratio;
229 info() <<
" TIME RATIO 2=" << time_ratio2;
231 Real proportional_time = compute_times0 / (nb_own_cell + 1);
234 info() <<
" PROPORTIONAL TIME=" << proportional_time;
237 Real max_weight = 0.0;
239 m_cells_weight.resize(cell_family->
maxLocalId() * nb_weight);
241 const Cell& cell = *iitem;
242 Real v0 = proportional_time;
244 if (dump_info && iitem.index() < 10) {
250 for (
Integer i = 0; i < nb_weight; ++i) {
251 m_cells_weight[(nb_weight * iitem->localId()) + i] = (float)(w * ((
Real)(i + 1)));
259 total_max_weight = 1.0;
262 info() <<
" TOTAL MAX WEIGHT=" << total_max_weight;
266 for (
Integer i = 0; i < nb_weight; ++i) {
267 Integer idx = (nb_weight * iitem->localId()) + i;
268 m_cells_weight[idx] = (float)(m_cells_weight[idx] / total_max_weight);
277Real ArcaneLoadBalanceModule::
285 Real elapsed_computation_time = time_stats->
elapsedTime(TP_Computation);
286 Real computation_time = elapsed_computation_time - m_elapsed_computation_time();
288 m_elapsed_computation_time = elapsed_computation_time;
296 Real my_time = computation_time;
300 thm->
addValue(
"SubDomainComputeTime", compute_times);
303 Real reduce_times[2];
304 reduce_times[0] = computation_time;
305 reduce_times[1] = -computation_time;
310 Real min_computation_time = reduce_times[0];
311 Real max_computation_time = -reduce_times[1];
313 max_computation_time = 1.;
315 min_computation_time = 1.;
317 computation_times[0] = computation_time;
321 Real ratio = computation_time / max_computation_time;
322 Real imbalance = (max_computation_time - min_computation_time) / min_computation_time;
323 info() <<
"Computing time used (" << pm->
commRank() <<
") :"
325 <<
" current=" << computation_time
326 <<
" min=" << min_computation_time
327 <<
" max=" << max_computation_time
328 <<
" ratio=" << ratio
329 <<
" imbalance=" << imbalance
332 IMeshPartitioner* p =
options()->partitioner();
333 p->setMaximumComputationTime(max_computation_time);
334 p->setComputationTimes(computation_times);
335 p->setImbalance(imbalance);
336 p->setMaxImbalance(
options()->maxImbalance());
ISubDomain * subDomain() const override
Sub-domain associated with the module.
IMesh * defaultMesh() const override
Default mesh for this module.
IParallelMng * parallelMng() const override
Message passing parallelism manager.
Generation de la classe de base du Module.
CaseOptionsArcaneLoadBalance * options() const
Options du jeu de données du module.
void _computeWeights(RealConstArrayView compute_times, Real max_compute_time)
Calculates the weight of each mesh cell and stores it in m_cells_weight.
void checkLoadBalance()
points d'entrée
Real m_computation_time
Computation time since the last balancing Note: this value must be synchronized.
virtual VersionInfo versionInfo() const
Module version.
Int32 globalIteration() const
Current iteration number.
constexpr Integer size() const noexcept
Number of elements in the array.
Interface of an entity family.
virtual Int32 maxLocalId() const =0
virtual void setDynamic(bool v)=0
Sets the property indicating whether the mesh can evolve.
Interface of a mesh partitioner.
virtual ARCANE_DEPRECATED_116 void setCellsWeight(ArrayView< float > weights, Integer nb_weight)=0
Allows defining the weights of objects to be partitioned: ILoadBalanceMng must now be used.
virtual IMeshModifier * modifier()=0
Associated modifier interface.
Interface of the parallelism manager for a subdomain.
virtual Int32 commRank() const =0
Rank of this instance in the communicator.
virtual Int32 commSize() const =0
Number of instances in the communicator.
virtual void allGather(ConstArrayView< char > send_buf, ArrayView< char > recv_buf)=0
Performs an all-gather operation across all processors. This is a collective operation....
virtual char reduce(eReduceType rt, char v)=0
Performs a reduction of type rt on the real v and returns the value.
Interface of the subdomain manager.
virtual const CommonVariables & commonVariables() const =0
Information on standard variables.
virtual ITimeStats * timeStats() const =0
Execution time statistics.
virtual IParallelMng * parallelMng()=0
Returns the parallelism manager.
virtual ITimeLoopMng * timeLoopMng()=0
Returns the time loop manager.
virtual ITimeHistoryMng * timeHistoryMng()=0
Returns the history manager.
virtual IParallelMng * allReplicaParallelMng() const =0
Returns the parallelism manager for all replicas.
Class managing a history of values.
virtual void addValue(const String &name, Real value, bool end_time=true, bool is_local=false)=0
Adds the value value to the history name.
virtual void registerActionMeshPartition(IMeshPartitionerBase *mesh_partitioner)=0
Schedules a mesh partitioning using the partition tool mesh_partitioner.
Interface managing execution time statistics.
virtual Real elapsedTime(eTimePhase phase)=0
Real elapsed time for phase phase.
Integer size() const
Number of elements in the group.
Utility class for printing information about an entity.
CellGroup ownCells() const
Returns the group containing all cells specific to this domain.
Information for building a module.
TraceMessage info() const
Flow for an information message.
1D data vector with value semantics (STL style).
Parameters necessary for building a variable.
Information about a version.
ItemGroupT< Cell > CellGroup
Group of cells.
VariableRefScalarT< Real > VariableScalarReal
Scalar variable of real type.
@ ReduceMin
Minimum of values.
@ ReduceMax
Maximum of values.
bool isZero(const BuiltInProxy< _Type > &a)
Tests if a value is exactly equal to zero.
-- tab-width: 2; indent-tabs-mode: nil; coding: utf-8-with-signature --
Int32 Integer
Type representing an integer.
UniqueArray< Real > RealUniqueArray
Dynamic 1D array of reals.
double Real
Type representing a real number.
UniqueArray< Integer > IntegerUniqueArray
Dynamic 1D array of integers.
ConstArrayView< Integer > IntegerConstArrayView
C equivalent of a 1D array of integers.
ArrayView< Real > RealArrayView
C equivalent of a 1D array of reals.
std::int32_t Int32
Signed integer type of 32 bits.
ConstArrayView< Real > RealConstArrayView
C equivalent of a 1D array of reals.