Peano
Loading...
Searching...
No Matches
ToggleLoadBalancing.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 Switch the load balancing on or off
10
11 Calls enable(true) or enable(false) on the strategy that is currently
12 installed in toolbox::loadbalancing::LoadBalancingService, either in
13 prepareTraversal(), i.e. before the grid sweep, or in
14 unprepareTraversal(), i.e. after the grid sweep. Both routines are
15 invoked once per traversal per rank (and not per tree).
16
17 The action set does not install a strategy itself. If no strategy is
18 installed, i.e. getLoadBalancing() returns nullptr, the action set does
19 nothing.
20
21 """
22
23 def __init__(self, enable_load_balancing: bool, plug_into_prepare_traversal: bool):
24 """!
25
26 @param enable_load_balancing: bool
27 Switch the load balancing on (True) or off (False).
28
29 @param plug_into_prepare_traversal: bool
30 Toggle the load balancing in prepareTraversal() (True), i.e.
31 before the grid sweep, or in unprepareTraversal() (False), i.e.
32 after the grid sweep.
33
34 """
35 super(ToggleLoadBalancing, self).__init__(descend_invocation_order=0, parallel=False)
36 self.enable_load_balancing = enable_load_balancing
37 self.plug_into_prepare_traversal = plug_into_prepare_traversal
38
39 def _toggle(self):
40 return f"""
41 if (::toolbox::loadbalancing::LoadBalancingService::getInstance().getLoadBalancing() != nullptr) {{
42 ::toolbox::loadbalancing::LoadBalancingService::getInstance().getLoadBalancing()->enable({"true" if self.enable_load_balancing else "false"});
43 }}
44"""
45
47 return ""
48
50 return ""
51
53 return self._toggle() if self.plug_into_prepare_traversal else "\n"
54
56 return "\n" if self.plug_into_prepare_traversal else self._toggle()
57
58 def get_body_of_operation(self, operation_name):
59 return "\n"
60
62 return __name__.replace(".py", "").replace(".", "_")
63
65 return False
66
67 def get_attributes(self):
68 return ""
69
70 def get_includes(self):
71 return """
72#include "toolbox/loadbalancing/AbstractLoadBalancing.h"
73#include "toolbox/loadbalancing/LoadBalancingService.h"
74"""
get_constructor_body(self)
Define a tailored constructor body.
get_attributes(self)
Return attributes as copied and pasted into the generated class.
get_body_of_operation(self, operation_name)
Return actual C++ code snippets to be inserted into C++ code.
get_includes(self)
Return include statements that you need.
__init__(self, bool enable_load_balancing, bool plug_into_prepare_traversal)
user_should_modify_template(self)
Is the user allowed to modify the output.
get_action_set_name(self)
Return unique action set name.
Action set (reactions to events)
Definition ActionSet.py:6