aGrUM 2.3.2
a C++ library for (probabilistic) graphical models
gum::Schedule Class Reference

Class containing a schedule of operations to perform on multidims. More...

#include <agrum/base/graphicalModels/inference/scheduler/schedule.h>

Collaboration diagram for gum::Schedule:

Public Member Functions

Constructors / Destructors
 Schedule (const Size nb_ops=256)
 default constructor (construct an empty sequence)
 Schedule (const Schedule &from)
 copy constructor
 Schedule (Schedule &&from)
 move constructor
virtual Scheduleclone () const
 virtual copy constructor
virtual ~Schedule ()
 destructor
Operators
Scheduleoperator= (const Schedule &)
 copy operator
Scheduleoperator= (Schedule &&)
 move operator
bool operator== (const Schedule &) const
 operator ==
bool operator!= (const Schedule &) const
 operator !=
Accessors/Modifiers
template<typename TABLE>
const IScheduleMultiDiminsertTable (const TABLE &table, const bool copy, const Idx id=0)
 inserts a new table as a source operation's input, i.e., this table is not computed by any ScheduleOperator
const IScheduleMultiDiminsertScheduleMultiDim (const IScheduleMultiDim &multidim)
 inserts a copy of a table as a source operation's input, i.e., this table is not computed by any ScheduleOperator
void emplaceScheduleMultiDim (const IScheduleMultiDim &multidim)
 inserts without copying it a table as a source operation's input, i.e., this table is not computed by any ScheduleOperator
const ScheduleOperatorinsertOperation (const ScheduleOperator &op, const bool are_results_persistent=false)
 inserts an operation into the schedule
template<typename TABLE1, typename TABLE2, typename TABLE_RES>
const ScheduleOperatoremplaceBinaryCombination (const ScheduleMultiDim< TABLE1 > &table1, const ScheduleMultiDim< TABLE2 > &table2, TABLE_RES(*combine)(const TABLE1 &, const TABLE2 &), const bool is_result_persistent=false)
 emplace a new schedule binary combination operation
template<typename TABLE>
const ScheduleOperatoremplaceProjection (const ScheduleMultiDim< TABLE > &table, const gum::VariableSet &del_vars, TABLE(*project)(const TABLE &, const gum::VariableSet &), const bool is_result_persistent=false)
 emplace a new schedule projection operation
template<typename TABLE>
const ScheduleOperatoremplaceDeletion (const ScheduleMultiDim< TABLE > &table)
 emplace a new schedule deletion operation
template<typename TABLE, template< typename... > class CONTAINER>
const ScheduleOperatoremplaceStorage (const IScheduleMultiDim &table, CONTAINER< TABLE > &container)
 emplace a new schedule storage operation
const DAGdag () const
 returns a DAG indicating in which order the operations can be performed
const ScheduleOperatoroperation (const NodeId id) const
 returns the scheduleOperation corresponding to an id in the DAG
NodeId nodeId (const ScheduleOperator &) const
 returns the id of the node corresponding to a given ScheduleOperator
NodeSet availableOperations () const
 returns the set of ScheduleOperations that are ready to be executed
void updateAfterExecution (const NodeId exec_node, std::vector< NodeId > &new_available_nodes, const bool check=false)
 updates the schedule after a given operation has been executed
void updateAfterExecution (const ScheduleOperator &exec_op, std::vector< NodeId > &new_available_nodes, const bool check=false)
 updates the schedule after executing a given operation
const IScheduleMultiDimscheduleMultiDim (const NodeId id) const
 returns the ScheduleMultiDim corresponding to a given id
bool existsScheduleMultiDim (const NodeId id) const
 indicates whether the schedule contains a given ScheduleMultiDim
NodeId scheduleMultiDimId (const IScheduleMultiDim *multidim) const
 returns the id of a given IScheduleMultiDim
const ScheduleOperatorscheduleMultiDimCreator (const NodeId id) const
 returns the operation, if any, that created a given scheduleMultiDim
const ScheduleOperatorscheduleMultiDimCreator (const IScheduleMultiDim *multidim) const
 returns the operation, if any, that created a given scheduleMultiDim
Idx versionNumber () const
 returns the version number of the schedule
void clear ()
 empty the schedule, i.e., remove its content

Private Member Functions

void _copy_ (const Schedule &from)
 a function to copy the content of a schedule into another one
void _destroy_ ()
 a function to delete from memory the content of a schedule
DAG _fullDAG_ () const
 returns the graph that would obtain when no operation is performed

Static Private Member Functions

static std::string _paramString_ (Idx i)
 returns the adjective corresponding to a parameter index (1st, 2nd, etc.)
static Idx _newVersionNumber_ ()
 returns a new distinct version for each schedule

Private Attributes

DAG _dag_
 the DAG of the operations to perform
NodeId _newId_ {NodeId(0)}
 the highest node id in the graph
Bijection< NodeId, ScheduleOperator * > _node2op_
 a mapping between the ids of the operations and their pointer
HashTable< const IScheduleMultiDim *, std::pair< ScheduleOperator *, Idx > > _multidim_location_
 a structure to indicate precisely where a ScheduleMultiDim comes from
Bijection< const IScheduleMultiDim *, Idx_multidim2id_
 a bijection between pointers to IScheduleMultiDim and their Ids
Set< const IScheduleMultiDim * > _emplaced_multidims_
 indicates which ScheduleMultiDims were emplaced
HashTable< const IScheduleMultiDim *, NodeSet_multidim2nodes_
 maps the multidims to the set of operations that use them
Bijection< const IScheduleMultiDim *, NodeId_deleted_multidim2node_
 A bijection mapping ScheduleMultiDims to be deleted with the operations that will delete them.
Idx _version_number_
 a number that identifies the current version of the schedule

Static Private Attributes

static std::atomic< Idx_overall_version_number_

Detailed Description

Class containing a schedule of operations to perform on multidims.

A Schedule class contains a set of operations to be scheduled. It is able to indicate which operations can currently be performed (because all their arguments have already been computed). In addition, it is possible to insert new operations into the schedule (at a specific location) and to remove some operations.

Definition at line 80 of file schedule.h.

Constructor & Destructor Documentation

◆ Schedule() [1/3]

gum::Schedule::Schedule ( const Size nb_ops = 256)
explicit

default constructor (construct an empty sequence)

Referenced by Schedule(), Schedule(), _copy_(), clone(), operator!=(), operator=(), operator=(), and operator==().

Here is the caller graph for this function:

◆ Schedule() [2/3]

gum::Schedule::Schedule ( const Schedule & from)

copy constructor

References Schedule().

Here is the call graph for this function:

◆ Schedule() [3/3]

gum::Schedule::Schedule ( Schedule && from)

move constructor

References Schedule().

Here is the call graph for this function:

◆ ~Schedule()

virtual gum::Schedule::~Schedule ( )
virtual

destructor

Member Function Documentation

◆ _copy_()

void gum::Schedule::_copy_ ( const Schedule & from)
private

a function to copy the content of a schedule into another one

Warning
this method assumes that "this" is an empty schedule. If this is not the case, then we should first remove everything from "this"

References Schedule().

Here is the call graph for this function:

◆ _destroy_()

void gum::Schedule::_destroy_ ( )
private

a function to delete from memory the content of a schedule

◆ _fullDAG_()

DAG gum::Schedule::_fullDAG_ ( ) const
private

returns the graph that would obtain when no operation is performed

◆ _newVersionNumber_()

Idx gum::Schedule::_newVersionNumber_ ( )
staticprivate

returns a new distinct version for each schedule

◆ _paramString_()

std::string gum::Schedule::_paramString_ ( Idx i)
staticprivate

returns the adjective corresponding to a parameter index (1st, 2nd, etc.)

◆ availableOperations()

NodeSet gum::Schedule::availableOperations ( ) const

returns the set of ScheduleOperations that are ready to be executed

The operations that can be executed at once are those that have no parent or whose parents have already been executed.

◆ clear()

void gum::Schedule::clear ( )

empty the schedule, i.e., remove its content

◆ clone()

virtual Schedule * gum::Schedule::clone ( ) const
virtual

virtual copy constructor

References Schedule().

Here is the call graph for this function:

◆ dag()

const DAG & gum::Schedule::dag ( ) const

returns a DAG indicating in which order the operations can be performed

In this DAG, each node corresponds to an operation and an operation can be performed only if its ancestors have all been performed.

◆ emplaceBinaryCombination()

template<typename TABLE1, typename TABLE2, typename TABLE_RES>
const ScheduleOperator & gum::Schedule::emplaceBinaryCombination ( const ScheduleMultiDim< TABLE1 > & table1,
const ScheduleMultiDim< TABLE2 > & table2,
TABLE_RES(* combine )(const TABLE1 &, const TABLE2 &),
const bool is_result_persistent = false )

emplace a new schedule binary combination operation

Parameters
table1the first ScheduleMultiDim to combine with the other table
table2the second table involved in the combination
combinea function taking two (real) tables in argument and returning the result of their combination
is_result_persistentthis boolean indicates whether the result of the binary combination is persistent, i.e., whether it should be kept in memory when the operation itself is deleted from memory.
Exceptions
UnknownScheduleMultiDimif some of the arguments of op do not already belong to the schedule. Such arguments would indeed prevent the schedule to be performed.
OperationNotAllowedif the operation deletes its arguments and either another operation also deletes some of them or the operation has already been performed but other operations use some of these arguments and they have not been executed yet.

◆ emplaceDeletion()

template<typename TABLE>
const ScheduleOperator & gum::Schedule::emplaceDeletion ( const ScheduleMultiDim< TABLE > & table)

emplace a new schedule deletion operation

Exceptions
UnknownScheduleMultiDimif some of the arguments of op do not already belong to the schedule. Such arguments would indeed prevent the schedule to be performed.
OperationNotAllowedif the operation deletes its arguments and either another operation also deletes some of them or the operation has already been performed but other operations use some of these arguments and they have not been executed yet.

◆ emplaceProjection()

template<typename TABLE>
const ScheduleOperator & gum::Schedule::emplaceProjection ( const ScheduleMultiDim< TABLE > & table,
const gum::VariableSet & del_vars,
TABLE(* project )(const TABLE &, const gum::VariableSet &),
const bool is_result_persistent = false )

emplace a new schedule projection operation

Parameters
tablethe ScheduleMultiDim containing the table that will be projected
del_varsthe set of variables that will be removed from table. Note that variables in del_vars that do not belong to table are simply not taken into account. They do not raise any exception.
projectthe function that will actually perform the projection
is_result_persistentthis boolean indicates whether the result of the projection is persistent, i.e., whether it should be kept in memory when the operation itself is deleted from memory.
Exceptions
UnknownScheduleMultiDimif some of the arguments of op do not already belong to the schedule. Such arguments would indeed prevent the schedule to be performed.
OperationNotAllowedif the operation deletes its arguments and either another operation also deletes some of them or the operation has already been performed but other operations use some of these arguments and they have not been executed yet.

◆ emplaceScheduleMultiDim()

void gum::Schedule::emplaceScheduleMultiDim ( const IScheduleMultiDim & multidim)

inserts without copying it a table as a source operation's input, i.e., this table is not computed by any ScheduleOperator

ScheduleOperations produce new tables that can be passed as arguments to other ScheduleOperations. However source operations, i.e., those that are the sources of the DAG (they are the first to be computed), need arguments/tables that have been created before the Schedule. These tables can be inserted as is (without copy) into the schedule using this emplace method

Parameters
multidimthe ScheduleMultiDim inserted into the schedule without copying it.
Exceptions
AbstractScheduleMultiDimis thrown if the ScheduleMultiDim is abstract, i.e., it does not contain a true table. The tables we insert with method insertTable are not computed by any schedule operations, hence they should never be abstract, else the schedule may not be executable.
DuplicateScheduleMultiDimis thrown if the schedule already contains a table with the same id

◆ emplaceStorage()

template<typename TABLE, template< typename... > class CONTAINER>
const ScheduleOperator & gum::Schedule::emplaceStorage ( const IScheduleMultiDim & table,
CONTAINER< TABLE > & container )

emplace a new schedule storage operation

Exceptions
UnknownScheduleMultiDimif some of the arguments of op do not already belong to the schedule. Such arguments would indeed prevent the schedule to be performed.
OperationNotAllowedif the operation deletes its arguments and either another operation also deletes some of them or the operation has already been performed but other operations use some of these arguments and they have not been executed yet.

◆ existsScheduleMultiDim()

bool gum::Schedule::existsScheduleMultiDim ( const NodeId id) const

indicates whether the schedule contains a given ScheduleMultiDim

◆ insertOperation()

const ScheduleOperator & gum::Schedule::insertOperation ( const ScheduleOperator & op,
const bool are_results_persistent = false )

inserts an operation into the schedule

The Schedule class is able to determine by itself when the operation can be performed.

Parameters
opthe operation that will be copied into the schedule
are_results_persistentthis boolean indicates whether the results of the operation are persistent, i.e., whether they should be kept in memory when the operation itself is deleted from memory.
Exceptions
UnknownScheduleMultiDimif some of the arguments of op do not already belong to the schedule. Such arguments would indeed prevent the schedule to be performed.
OperationNotAllowedif the operation deletes its arguments and either another operation also deletes some of them or the operation has already been performed but other operations use some of these arguments and they have not been executed yet.
Warning
operations are inserted by cloning

◆ insertScheduleMultiDim()

const IScheduleMultiDim * gum::Schedule::insertScheduleMultiDim ( const IScheduleMultiDim & multidim)

inserts a copy of a table as a source operation's input, i.e., this table is not computed by any ScheduleOperator

ScheduleOperations produce new tables that can be passed as arguments to other ScheduleOperations. However source operations, i.e., those that are the sources of the DAG (they are the first to be computed), need arguments/tables that have been created before the Schedule. These tables can be inserted into the schedule using this insert method

Parameters
multidimthe ScheduleMultiDim inserted into the schedule. Note that this clones the ScheduleMultiDim passed in argument if it does not already belong to the schedule, or it returns it otherwise.
Exceptions
AbstractScheduleMultiDimis thrown if the ScheduleMultiDim is abstract, i.e., it does not contain a true table. The tables we insert with method insertTable are not computed by any schedule operations, hence they should never be abstract, else the schedule may not be executable.
DuplicateScheduleMultiDimis thrown if the schedule already contains a table with the same id

◆ insertTable()

template<typename TABLE>
const IScheduleMultiDim * gum::Schedule::insertTable ( const TABLE & table,
const bool copy,
const Idx id = 0 )

inserts a new table as a source operation's input, i.e., this table is not computed by any ScheduleOperator

ScheduleOperations produce new tables that can be passed as arguments to other ScheduleOperations. However source operations, i.e., those that are the sources of the DAG (they are the first to be computed), need arguments/tables that have been created before the Schedule. These tables should be inserted into the schedule using this insert method

Parameters
tablethe table to be inserted into the schedule. Note that this creates a ScheduleMultiDim that references this table (the latter is not copied).
Exceptions
DuplicateScheduleMultiDimis thrown if the schedule already contains a table with the same id

◆ nodeId()

NodeId gum::Schedule::nodeId ( const ScheduleOperator & ) const

returns the id of the node corresponding to a given ScheduleOperator

Exceptions
NotFoundexception is raised the operation does not belong to the Schedule

◆ operation()

const ScheduleOperator & gum::Schedule::operation ( const NodeId id) const

returns the scheduleOperation corresponding to an id in the DAG

Exceptions
NotFoundexception is raised if the DAG does not contain the id

◆ operator!=()

bool gum::Schedule::operator!= ( const Schedule & ) const

operator !=

References Schedule().

Here is the call graph for this function:

◆ operator=() [1/2]

Schedule & gum::Schedule::operator= ( const Schedule & )

copy operator

References Schedule().

Here is the call graph for this function:

◆ operator=() [2/2]

Schedule & gum::Schedule::operator= ( Schedule && )

move operator

References Schedule().

Here is the call graph for this function:

◆ operator==()

bool gum::Schedule::operator== ( const Schedule & ) const

operator ==

References Schedule().

Here is the call graph for this function:

◆ scheduleMultiDim()

const IScheduleMultiDim * gum::Schedule::scheduleMultiDim ( const NodeId id) const

returns the ScheduleMultiDim corresponding to a given id

◆ scheduleMultiDimCreator() [1/2]

const ScheduleOperator * gum::Schedule::scheduleMultiDimCreator ( const IScheduleMultiDim * multidim) const

returns the operation, if any, that created a given scheduleMultiDim

Returns
a pointer to the ScheduleOperator that created (as a result) a given ScheduleMultiDim. If no operation created it, the method returns nullptr.

◆ scheduleMultiDimCreator() [2/2]

const ScheduleOperator * gum::Schedule::scheduleMultiDimCreator ( const NodeId id) const

returns the operation, if any, that created a given scheduleMultiDim

Returns
a pointer to the ScheduleOperator that created (as a result) a given ScheduleMultiDim. If no operation created it, the method returns nullptr.

◆ scheduleMultiDimId()

NodeId gum::Schedule::scheduleMultiDimId ( const IScheduleMultiDim * multidim) const

returns the id of a given IScheduleMultiDim

◆ updateAfterExecution() [1/2]

void gum::Schedule::updateAfterExecution ( const NodeId exec_node,
std::vector< NodeId > & new_available_nodes,
const bool check = false )

updates the schedule after a given operation has been executed

Warning
Parallel schedulers should use this method only in critical section because it updates the schedule's DAG.
Parameters
exec_nodeThe node id of the operation that has just been executed
new_available_nodesa vector that will be filled with all the new operations becoming available due to exec_node being executed.
checkif true, we check that the operation could be executed and has actually been executed.
Exceptions
UnavailableScheduleOperationexception is thrown in check mode if the operation was not available and, hence, should not have been executed. This should never happen.
UnknownScheduleOperationexception is thrown in check mode if the DAG does not contain the node of the executed operation. This should never happen.
UnexecutedScheduleOperationexception is thrown in check mode if the operation has not yet been executed. This should never happen.

◆ updateAfterExecution() [2/2]

void gum::Schedule::updateAfterExecution ( const ScheduleOperator & exec_op,
std::vector< NodeId > & new_available_nodes,
const bool check = false )

updates the schedule after executing a given operation

Warning
Parallel schedulers should use this method only in critical section because it updates the schedule's DAG.
Parameters
exec_opThe operation that has just been executed
new_available_nodesa vector that will be filled with all the new operations becoming available due to exec_op being executed.
checkif true, we check that the operation could be executed and has actually been executed.
Exceptions
UnavailableScheduleOperationexception is thrown in check mode if the operation was not available and, hence, should not have been executed. This should never happen.
UnknownScheduleOperationexception is thrown in check mode if the DAG does not contain the node of the executed operation. This should never happen.
UnexecutedScheduleOperationexception is thrown in check mode if the operation has not yet been executed. This should never happen.

◆ versionNumber()

Idx gum::Schedule::versionNumber ( ) const

returns the version number of the schedule

Member Data Documentation

◆ _dag_

DAG gum::Schedule::_dag_
private

the DAG of the operations to perform

Operations can be scheduled as a DAG: nodes without parents can be executed directly. The other nodes need their parents to be executed to get all their arguments constructed.

Definition at line 378 of file schedule.h.

◆ _deleted_multidim2node_

Bijection< const IScheduleMultiDim*, NodeId > gum::Schedule::_deleted_multidim2node_
private

A bijection mapping ScheduleMultiDims to be deleted with the operations that will delete them.

This information is of interest because, to limit the memory consumption, a scheduler should consider executing the operations stored into this bijection as soon as possible

Warning
only the ScheduleMultiDim that will be eventually deleted are included into this hashtable
at most one operation is allowed to delete a ScheduleMultiDim (else, we would free it several times from memory, which is bad, very bad)

Definition at line 421 of file schedule.h.

◆ _emplaced_multidims_

Set< const IScheduleMultiDim* > gum::Schedule::_emplaced_multidims_
private

indicates which ScheduleMultiDims were emplaced

Definition at line 405 of file schedule.h.

◆ _multidim2id_

Bijection< const IScheduleMultiDim*, Idx > gum::Schedule::_multidim2id_
private

a bijection between pointers to IScheduleMultiDim and their Ids

Definition at line 402 of file schedule.h.

◆ _multidim2nodes_

HashTable< const IScheduleMultiDim*, NodeSet > gum::Schedule::_multidim2nodes_
private

maps the multidims to the set of operations that use them

Definition at line 408 of file schedule.h.

◆ _multidim_location_

HashTable< const IScheduleMultiDim*, std::pair< ScheduleOperator*, Idx > > gum::Schedule::_multidim_location_
private

a structure to indicate precisely where a ScheduleMultiDim comes from

ScheduleMultiDims can either result from the execution of some operation or reference a MultiDim created outside of the schedule. This structure enables to discriminate these situations:

  • if the first element of the std::pair is nullptr, this means that the ScheduleMultiDim has been created outside of the schedule, i.e., that it references an outside MultiDim.
  • if the first element of the std::pair is different from nullptr, then the ScheduleMultiDim results from a ScheduleOperator and the pointer of this operation is this first argument. The second argument of the std::pair indicates the index of the ScheduleMultiDim in the sequence of results of the ScheduleOperator.

Definition at line 399 of file schedule.h.

◆ _newId_

NodeId gum::Schedule::_newId_ {NodeId(0)}
private

the highest node id in the graph

Definition at line 381 of file schedule.h.

381{NodeId(0)};
Size NodeId
Type for node ids.

◆ _node2op_

Bijection< NodeId, ScheduleOperator* > gum::Schedule::_node2op_
private

a mapping between the ids of the operations and their pointer

Definition at line 384 of file schedule.h.

◆ _overall_version_number_

std::atomic< Idx > gum::Schedule::_overall_version_number_
staticprivate

Definition at line 446 of file schedule.h.

◆ _version_number_

Idx gum::Schedule::_version_number_
private

a number that identifies the current version of the schedule

schedules' versions change whenever new ScheduleMultiDims or ScheduleOperations are inserted

Definition at line 426 of file schedule.h.


The documentation for this class was generated from the following file:
  • agrum/base/graphicalModels/inference/scheduler/schedule.h