Peano
Loading...
Searching...
No Matches
SynchroniseActionSets.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 typing import List
4
5from .ActionSet import ActionSet
6
7
9 """!
10
11 Marker which ends a group of action sets that run in parallel
12
13 The generated observer invokes the action sets of a step one by one.
14 Consecutive action sets with parallel=True form a task group instead:
15 Per event, their code is spawned as one task per action set, and the
16 observer waits for all of these tasks before it continues
17 (@ref peano4.api.solversteps.SynchroniseActionSets.get_task_groups()).
18 An action set with parallel=False ends a group, too, but it is then
19 invoked itself.
20
21 This marker ends a group without invoking anything. Use it to separate
22 two task groups which follow each other directly. Without the marker,
23 they would merge into one group, i.e. action sets of the second group
24 might run concurrently to the ones of the first group although they
25 depend on them. @ref peano4.api.taskgraph.compiler.FuseSteps inserts
26 such markers.
27
28 The marker is ignored when we generate the C++ code: It yields neither
29 an action set class nor any code in the observer. Append it directly to
30 a step's action_sets. Do not use
31 @ref peano4.api.solversteps.Step.Step.add_action_set(), as this routine
32 sorts the action sets according to their descend_invocation_order, i.e.
33 it might move the marker.
34
35 """
36
37 def __init__(self):
38 super().__init__(descend_invocation_order=0, parallel=False)
39
41 return ""
42
44 return ""
45
47 return ""
48
50 return ""
51
52 def get_body_of_operation(self, operation_name):
53 return ""
54
56 return "SynchroniseActionSets"
57
59 return False
60
61 def get_attributes(self):
62 return ""
63
64 def get_includes(self):
65 return ""
66
67
68def get_task_groups(action_sets: List[ActionSet]) -> List[List[ActionSet]]:
69 """!
70
71 Split a sequence of action sets into groups which are invoked one after
72 the other
73
74 We run through the action sets in their order. Consecutive action sets
75 with parallel=True form one group, i.e. they may run in parallel. An
76 action set with parallel=False forms a group of its own and ends the
77 current group. A
78 @ref peano4.api.solversteps.SynchroniseActionSets.SynchroniseActionSets
79 ends the current group, too, but does not show up in any group.
80
81 For the sequence V1, V2, V3, V4, V5 with V1, V2, V4 and V5 being
82 parallel, we get the groups [V1, V2], [V3] and [V4, V5]: The observer
83 spawns V1 and V2 as tasks and waits for them, then invokes V3, and
84 finally spawns V4 and V5 and waits for them.
85
86 @param action_sets: [peano4.api.solversteps.ActionSet]
87 Action sets in the order in which they are invoked.
88
89 @return [[peano4.api.solversteps.ActionSet]]
90 Groups in invocation order. No group is empty.
91
92 """
93 groups = []
94 current_group = None
95 for action_set in action_sets:
96 if isinstance(action_set, SynchroniseActionSets):
97 current_group = None
98 elif action_set.parallel and current_group is not None:
99 current_group.append(action_set)
100 else:
101 current_group = [action_set]
102 groups.append(current_group)
103 if not action_set.parallel:
104 current_group = None
105 return groups
Action set (reactions to events)
Definition ActionSet.py:6
Marker which ends a group of action sets that run in parallel.
get_body_of_operation(self, operation_name)
Return actual C++ code snippets to be inserted into C++ code.
get_attributes(self)
Return attributes as copied and pasted into the generated class.
user_should_modify_template(self)
Is the user allowed to modify the output.