25 #ifndef DOXYGEN_SHOULD_SKIP_THIS 32 template <
typename GUM_SCALAR >
35 GUM_CONSTRUCTOR(Schedule);
39 template <
typename GUM_SCALAR >
41 __dag(from.__dag), __operation2node(from.__operation2node),
42 __created_multidims(from.__created_multidims),
43 __operations_with_wrong_parents(from.__operations_with_wrong_parents),
44 __operations_available(from.__operations_available) {
49 for (
const auto& elt : from.__node2operation)
53 for (
const auto& elt : from.__multidim2operations)
58 template <
typename GUM_SCALAR >
74 template <
typename GUM_SCALAR >
79 for (
const auto& elt : __node2operation)
93 __node2operation.
clear();
95 for (
const auto& elt : from.__node2operation)
96 __node2operation.insert(elt.first, elt.second->newFactory());
99 __multidim2operations.clear();
101 for (
const auto& elt : from.__multidim2operations)
102 __multidim2operations.insert(elt.first,
new NodeSet(*elt.second));
109 template <
typename GUM_SCALAR >
113 ScheduleOperation< GUM_SCALAR >*
operation = op.newFactory();
119 __node2operation.insert(node_id, operation);
127 bool operation_available =
true;
129 for (
const auto par : operation->multiDimArgs()) {
130 if (par->isAbstract()) {
132 operation_available =
false;
151 for (
const auto tab : operation->multiDimResults()) {
156 if (!__multidim2operations.exists(table_id)) {
157 involved_ops = __multidim2operations.insert(table_id,
new NodeSet).second;
159 involved_ops = __multidim2operations[table_id];
162 involved_ops->insert(node_id);
167 for (
const auto& par : operation->multiDimArgs()) {
170 if (!__multidim2operations.exists(table_id)) {
171 involved_ops = __multidim2operations.insert(table_id,
new NodeSet).second;
173 involved_ops = __multidim2operations[table_id];
176 involved_ops->insert(node_id);
184 template <
typename GUM_SCALAR >
191 for (
const auto wrong : localWrongs) {
195 const Sequence< const ScheduleMultiDim< GUM_SCALAR >* >& args =
196 __node2operation[wrong]->multiDimArgs();
197 bool still_wrong =
false;
199 for (
const auto arg : args) {
213 for (
const auto arg : args)
214 if (arg->isAbstract()) {
229 template <
typename GUM_SCALAR >
241 template <
typename GUM_SCALAR >
243 const ScheduleOperation< GUM_SCALAR >& op_to_force,
244 const ScheduleOperation< GUM_SCALAR >& op_before) {
251 template <
typename GUM_SCALAR >
254 for (
const auto op : ops_before)
255 if (op != op_to_force)
forceAfter(op_to_force, op);
260 template <
typename GUM_SCALAR >
262 const ScheduleOperation< GUM_SCALAR >& op_to_force,
263 const Set<
const ScheduleOperation< GUM_SCALAR >* >& ops_before) {
264 for (
const auto op : ops_before)
265 if (*op != op_to_force)
forceAfter(op_to_force, *op);
270 template <
typename GUM_SCALAR >
282 template <
typename GUM_SCALAR >
284 const ScheduleOperation< GUM_SCALAR >& op_to_force,
285 const ScheduleOperation< GUM_SCALAR >& op_after) {
292 template <
typename GUM_SCALAR >
295 for (
const auto op : ops_after)
296 if (op != op_to_force)
forceBefore(op_to_force, op);
301 template <
typename GUM_SCALAR >
303 const ScheduleOperation< GUM_SCALAR >& op_to_force,
304 const Set<
const ScheduleOperation< GUM_SCALAR >* >& ops_after) {
305 for (
typename Set<
const ScheduleOperation< GUM_SCALAR >* >::const_iterator
306 iter = ops_after.begin();
307 iter != ops_after.end();
309 if (**iter != op_to_force) {
forceBefore(op_to_force, **iter); }
314 template <
typename GUM_SCALAR >
316 const ScheduleMultiDim< GUM_SCALAR >& table)
const {
317 return *(__multidim2operations[table.id()]);
321 template <
typename GUM_SCALAR >
324 return *(__multidim2operations[table_id]);
328 template <
typename GUM_SCALAR >
337 template <
typename GUM_SCALAR >
338 INLINE
const ScheduleOperation< GUM_SCALAR >&
340 return *(__node2operation[node_id]);
344 template <
typename GUM_SCALAR >
346 const ScheduleOperation< GUM_SCALAR >& op)
const {
351 template <
typename GUM_SCALAR >
352 INLINE
const NodeProperty< const ScheduleOperation< GUM_SCALAR >* >&
354 return reinterpret_cast< 355 NodeProperty< const ScheduleOperation< GUM_SCALAR >*
>& >(
__node2operation);
359 template <
typename GUM_SCALAR >
367 template <
typename GUM_SCALAR >
378 GUM_ERROR(OperationNotAllowed,
"the operation cannot be executed yet");
382 __node2operation[id]->execute();
388 for (
const auto child : children)
396 delete __node2operation[id];
400 __node2operation.erase(
id);
406 template <
typename GUM_SCALAR >
414 template <
typename GUM_SCALAR >
416 return __node2operation[id]->nbOperations();
421 template <
typename GUM_SCALAR >
423 ScheduleOperation< GUM_SCALAR >& op)
const {
424 return op.nbOperations();
428 template <
typename GUM_SCALAR >
429 INLINE std::pair< long, long >
431 return __node2operation[id]->memoryUsage();
435 template <
typename GUM_SCALAR >
437 ScheduleOperation< GUM_SCALAR >& op)
const {
438 return op.memoryUsage();
NodeSet __operations_available
the set of operations that can be executed at once
void execute(NodeId)
executes a given operation (if this one is available)
NodeProperty< ScheduleOperation< GUM_SCALAR > *> __node2operation
a hashtable assigning to each node of the DAG an operation
Set< NodeId > NodeSet
Some typdefs and define for shortcuts ...
void erase(const Key &key)
Removes a given element from the hash table.
DAG __dag
the DAG of the operations to perform
Idx MultiDimId
to identify correctly the ids that correspond to ScheduleMultiDim ids
NodeId nodeId(const ScheduleOperation< GUM_SCALAR > &) const
returns the id of the node corresponding to a given ScheduleOperation
bool exists(const Key &key) const
Checks whether there exists an element with a given key in the hashtable.
NodeSet __operations_with_wrong_parents
a list of operations whose parents are not properly set
void erase(const Key &k)
Erases an element from the set.
gum is the global namespace for all aGrUM entities
void forceAfter(const ScheduleOperation< GUM_SCALAR > &op_to_force, const ScheduleOperation< GUM_SCALAR > &op_before)
adds a constraint indicating that an operation cannot be performed before another one ...
virtual NodeId addNode()
insert a new node and return its id
NodeId insert(const ScheduleOperation< GUM_SCALAR > &)
inserts an operation to be scheduled
const NodeSet & operationsInvolving(const ScheduleMultiDim< GUM_SCALAR > &table) const
returns the set of operations involving a given multidim table
const DAG & scheduling_dag() const
returns a DAG indicating in which order the operations can be performed
const NodeSet & availableOperations() const
returns the set of ScheduleOperations that can be executed at once
Schedule< GUM_SCALAR > & operator=(const Schedule< GUM_SCALAR > &)
copy operator
const NodeSet & parents(const NodeId id) const
returns the set of nodes with arc ingoing to a given node
virtual void addArc(const NodeId tail, const NodeId head)
insert a new arc into the directed graph
void eraseChildren(const NodeId id)
removes all the children of a given node
std::pair< long, long > memoryUsage(NodeId) const
returns the memory consumption used during the execution of an operation
const NodeSet & children(const NodeId id) const
returns the set of nodes with arc outgoing from a given node
void forceBefore(const ScheduleOperation< GUM_SCALAR > &op_to_force, const ScheduleOperation< GUM_SCALAR > &op_after)
adds a constraint indicating that an operation must be performed before another one ...
const ScheduleOperation< GUM_SCALAR > & operation(NodeId) const
returns the scheduleOperation corresponding to an id in the DAG
Schedule()
default constructor (construct an empty sequence)
void clear()
Removes all the elements, if any, from the set.
std::size_t Size
In aGrUM, hashed values are unsigned long int.
Size size() const noexcept
Returns the number of elements in the set.
HashTable< OperationId, NodeId > __operation2node
a hashtable assigning to each operation id a node id in the DAG
value_type & insert(const Key &key, const Val &val)
Adds a new element (actually a copy of this element) into the hash table.
void __updateWrongParents() const
updates the set of parents for the nodes whoses parents are not correct yet and update accordingly th...
HashTable< MultiDimId, NodeId > __created_multidims
a hashtable assigning to each ScheduleMultiDim resulting from a computation the MultiDimOperation nod...
virtual void eraseNode(const NodeId id)
remove a node and its adjacent arcs from the graph
float nbOperations(NodeId) const
returns an estimation of the number of elementary operations needed to perform a given ScheduleOperat...
Size NodeId
Type for node ids.
void insert(const Key &k)
Inserts a new element into the set.
const NodeProperty< const ScheduleOperation< GUM_SCALAR > *> & operations() const
resturns the association between operations anf nodeIds
#define GUM_ERROR(type, msg)
HashTable< MultiDimId, NodeSet *> __multidim2operations
for each multidim, store the set of operations involving it