Peano
Loading...
Searching...
No Matches
WaitForCellTaskActionSet.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
5from .SpawnCellTaskActionSet import SpawnCellTaskActionSet
6
7
9 """!
10
11 Consumer-side cousin of a @ref peano4.api.taskgraph.compiler.SpawnCellTaskActionSet.SpawnCellTaskActionSet
12
13 The cousin realises the following events:
14
15 - touchCellFirstTime() checks if the cell's task label holds a valid
16 task number. If so, it waits for this task, returns the number to
17 the task enumerator, and resets the label to
18 tarch::multicore::TaskEnumerator::NoNumber.
19 - createCell() initialises the task label with NoNumber.
20
21 All other events are empty. The task enumerator is a static attribute of
22 the task labels, i.e. the cousin returns the number to the enumerator
23 from which the producer took it.
24
25 """
26
28 self,
29 producer_action_set: SpawnCellTaskActionSet,
30 ):
31 """!
32
33 @param producer_action_set: peano4.api.taskgraph.compiler.SpawnCellTaskActionSet.SpawnCellTaskActionSet
34 The producer-side action set this cousin belongs to.
35
36 """
37 super().__init__(
38 descend_invocation_order=producer_action_set.descend_invocation_order,
39 parallel=producer_action_set.parallel,
40 )
41 self._producer_action_set = producer_action_set
42
43 def _task_label_accessor(self) -> tuple:
44 attribute_name = self._producer_action_set._task_number_attribute_name
45 return (
46 f"fineGridCell{self._producer_action_set._task_labels_name}",
47 attribute_name[0].capitalize() + attribute_name[1:],
48 )
49
51 return ""
52
54 return ""
55
57 return " return std::vector< peano4::grid::GridControlEvent >();\n"
58
60 return "\n"
61
63 return "\n"
64
65 def get_body_of_operation(self, operation_name):
66 # Not used, as get_implementation_of_operation() is overwritten
67 return ""
68
69 def get_implementation_of_operation(self, operation_name):
70 task_label, accessor = self._task_label_accessor()
71 if operation_name == ActionSet.OPERATION_CREATE_CELL:
72 return f"\n {task_label}.set{accessor}( tarch::multicore::TaskEnumerator::NoNumber );\n"
73 elif operation_name == ActionSet.OPERATION_TOUCH_CELL_FIRST_TIME:
74 return f"""
75 if ( {task_label}.get{accessor}()>=0 ) {{
76 tarch::multicore::waitForTask( {task_label}.get{accessor}() );
77 {task_label}.getTaskEnumerator().releaseNumber( {task_label}.get{accessor}() );
78 {task_label}.set{accessor}( tarch::multicore::TaskEnumerator::NoNumber );
79 }}
80"""
81 else:
82 return ""
83
85 return self._producer_action_set.get_action_set_name() + "_WaitForTask"
86
88 return False
89
90 def get_attributes(self):
91 return ""
92
93 def get_includes(self):
94 return """
95#include "tarch/multicore/multicore.h"
96#include "tarch/multicore/TaskEnumerator.h"
97"""
Action set (reactions to events)
Definition ActionSet.py:6
Consumer-side cousin of a peano4.api.taskgraph.compiler.SpawnCellTaskActionSet.SpawnCellTaskActionSet...
get_body_of_operation(self, operation_name)
Return actual C++ code snippets to be inserted into C++ code.
get_implementation_of_operation(self, operation_name)
Return the C++ implementation of an operation.
get_body_of_createGridControlEventsForNextTraversal(self)
Return the grid control events that this action set wants to trigger.
get_attributes(self)
Return attributes as copied and pasted into the generated class.