28 #ifndef DOXYGEN_SHOULD_SKIP_THIS 35 template <
typename GUM_SCALAR >
38 GUM_CONSTRUCTOR(Schedule);
42 template <
typename GUM_SCALAR >
44 __dag(from.__dag), __operation2node(from.__operation2node),
45 __created_multidims(from.__created_multidims),
46 __operations_with_wrong_parents(from.__operations_with_wrong_parents),
47 __operations_available(from.__operations_available) {
52 for (
const auto& elt : from.__node2operation)
56 for (
const auto& elt : from.__multidim2operations)
61 template <
typename GUM_SCALAR >
77 template <
typename GUM_SCALAR >
82 for (
const auto& elt : __node2operation)
96 __node2operation.
clear();
98 for (
const auto& elt : from.__node2operation)
99 __node2operation.insert(elt.first, elt.second->newFactory());
102 __multidim2operations.clear();
104 for (
const auto& elt : from.__multidim2operations)
105 __multidim2operations.insert(elt.first,
new NodeSet(*elt.second));
112 template <
typename GUM_SCALAR >
116 ScheduleOperation< GUM_SCALAR >*
operation = op.newFactory();
122 __node2operation.insert(node_id, operation);
130 bool operation_available =
true;
132 for (
const auto par : operation->multiDimArgs()) {
133 if (par->isAbstract()) {
135 operation_available =
false;
154 for (
const auto tab : operation->multiDimResults()) {
159 if (!__multidim2operations.exists(table_id)) {
160 involved_ops = __multidim2operations.insert(table_id,
new NodeSet).second;
162 involved_ops = __multidim2operations[table_id];
165 involved_ops->insert(node_id);
170 for (
const auto& par : operation->multiDimArgs()) {
173 if (!__multidim2operations.exists(table_id)) {
174 involved_ops = __multidim2operations.insert(table_id,
new NodeSet).second;
176 involved_ops = __multidim2operations[table_id];
179 involved_ops->insert(node_id);
187 template <
typename GUM_SCALAR >
194 for (
const auto wrong : localWrongs) {
198 const Sequence< const ScheduleMultiDim< GUM_SCALAR >* >& args =
199 __node2operation[wrong]->multiDimArgs();
200 bool still_wrong =
false;
202 for (
const auto arg : args) {
216 for (
const auto arg : args)
217 if (arg->isAbstract()) {
232 template <
typename GUM_SCALAR >
244 template <
typename GUM_SCALAR >
246 const ScheduleOperation< GUM_SCALAR >& op_to_force,
247 const ScheduleOperation< GUM_SCALAR >& op_before) {
254 template <
typename GUM_SCALAR >
257 for (
const auto op : ops_before)
258 if (op != op_to_force)
forceAfter(op_to_force, op);
263 template <
typename GUM_SCALAR >
265 const ScheduleOperation< GUM_SCALAR >& op_to_force,
266 const Set<
const ScheduleOperation< GUM_SCALAR >* >& ops_before) {
267 for (
const auto op : ops_before)
268 if (*op != op_to_force)
forceAfter(op_to_force, *op);
273 template <
typename GUM_SCALAR >
285 template <
typename GUM_SCALAR >
287 const ScheduleOperation< GUM_SCALAR >& op_to_force,
288 const ScheduleOperation< GUM_SCALAR >& op_after) {
295 template <
typename GUM_SCALAR >
298 for (
const auto op : ops_after)
299 if (op != op_to_force)
forceBefore(op_to_force, op);
304 template <
typename GUM_SCALAR >
306 const ScheduleOperation< GUM_SCALAR >& op_to_force,
307 const Set<
const ScheduleOperation< GUM_SCALAR >* >& ops_after) {
308 for (
typename Set<
const ScheduleOperation< GUM_SCALAR >* >::const_iterator
309 iter = ops_after.begin();
310 iter != ops_after.end();
312 if (**iter != op_to_force) {
forceBefore(op_to_force, **iter); }
317 template <
typename GUM_SCALAR >
319 const ScheduleMultiDim< GUM_SCALAR >& table)
const {
320 return *(__multidim2operations[table.id()]);
324 template <
typename GUM_SCALAR >
327 return *(__multidim2operations[table_id]);
331 template <
typename GUM_SCALAR >
340 template <
typename GUM_SCALAR >
341 INLINE
const ScheduleOperation< GUM_SCALAR >&
343 return *(__node2operation[node_id]);
347 template <
typename GUM_SCALAR >
349 const ScheduleOperation< GUM_SCALAR >& op)
const {
354 template <
typename GUM_SCALAR >
355 INLINE
const NodeProperty< const ScheduleOperation< GUM_SCALAR >* >&
357 return reinterpret_cast< 358 NodeProperty< const ScheduleOperation< GUM_SCALAR >*
>& >(
__node2operation);
362 template <
typename GUM_SCALAR >
370 template <
typename GUM_SCALAR >
381 GUM_ERROR(OperationNotAllowed,
"the operation cannot be executed yet");
385 __node2operation[id]->execute();
391 for (
const auto child : children)
399 delete __node2operation[id];
403 __node2operation.erase(
id);
409 template <
typename GUM_SCALAR >
417 template <
typename GUM_SCALAR >
419 return __node2operation[id]->nbOperations();
424 template <
typename GUM_SCALAR >
426 ScheduleOperation< GUM_SCALAR >& op)
const {
427 return op.nbOperations();
431 template <
typename GUM_SCALAR >
432 INLINE std::pair< long, long >
434 return __node2operation[id]->memoryUsage();
438 template <
typename GUM_SCALAR >
440 ScheduleOperation< GUM_SCALAR >& op)
const {
441 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.
Copyright 2005-2019 Pierre-Henri WUILLEMIN et Christophe GONZALES (LIP6) {prenom.nom}_at_lip6.fr.
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