Peano
Loading...
Searching...
No Matches
LoadBalancing.py
Go to the documentation of this file.
1# This file is part of the Peano project. For conditions of distribution and
2# use, please see the copyright notice at www.peano-framework.org
3from peano4.api.solversteps.ActionSet import ActionSet
4
5
7 """!
8
9 Inform the load balancing about the end of a grid sweep
10
11 Add this action set to every solver step that should drive the load
12 balancing. Its unprepareTraversal() calls finishStep() on the strategy
13 that is currently installed in
14 toolbox::loadbalancing::LoadBalancingService. As unprepareTraversal()
15 is invoked once per traversal per rank (and not per tree), the strategy
16 is informed exactly once after each grid sweep.
17
18 The action set does not install a strategy itself. Some other code, the
19 main routine typically, hands one over via
20 toolbox::loadbalancing::LoadBalancingService::setLoadBalancing(). If
21 no strategy is installed, i.e. getLoadBalancing() returns nullptr, the
22 action set does nothing.
23
24 If constructed with enable_load_balancing=True, the action set first
25 switches the strategy on (enable(true)) and then calls finishStep(). The
26 time stepping schemes use this variant in their last mesh sweep, as they
27 switch the load balancing off throughout the time step
28 (toolbox.loadbalancing.api.actionsets.ToggleLoadBalancing).
29
30 """
31
32 def __init__(self, enable_load_balancing: bool = False):
33 """!
34
35 @param enable_load_balancing: bool
36 Switch the load balancing on right before finishStep() is called.
37
38 """
39 super(LoadBalancing, self).__init__(descend_invocation_order=0, parallel=False)
40 self.enable_load_balancing = enable_load_balancing
41
43 return ""
44
46 return ""
47
49 return "\n"
50
52 enable = (
53 " ::toolbox::loadbalancing::LoadBalancingService::getInstance().getLoadBalancing()->enable(true);\n"
55 else ""
56 )
57 return f"""
58 if (::toolbox::loadbalancing::LoadBalancingService::getInstance().getLoadBalancing() != nullptr) {{
59{enable} ::toolbox::loadbalancing::LoadBalancingService::getInstance().getLoadBalancing()->finishStep();
60 }}
61"""
62
63 def get_body_of_operation(self, operation_name):
64 return "\n"
65
67 return __name__.replace(".py", "").replace(".", "_")
68
70 return False
71
72 def get_attributes(self):
73 return ""
74
75 def get_includes(self):
76 return """
77#include "toolbox/loadbalancing/AbstractLoadBalancing.h"
78#include "toolbox/loadbalancing/LoadBalancingService.h"
79"""
Inform the load balancing about the end of a grid sweep.
get_action_set_name(self)
Return unique action set name.
get_body_of_operation(self, operation_name)
Return actual C++ code snippets to be inserted into C++ code.
__init__(self, bool enable_load_balancing=False)
get_includes(self)
Return include statements that you need.
get_constructor_body(self)
Define a tailored constructor body.
user_should_modify_template(self)
Is the user allowed to modify the output.
get_attributes(self)
Return attributes as copied and pasted into the generated class.
Action set (reactions to events)
Definition ActionSet.py:6