1 #ifndef GAUDIHIVE_PRECEDENCERULESGRAPH_H 2 #define GAUDIHIVE_PRECEDENCERULESGRAPH_H 7 #include <unordered_map> 12 #include <boost/graph/adjacency_list.hpp> 13 #include <boost/graph/graphml.hpp> 37 typedef boost::adjacency_list<boost::vecS, boost::vecS, boost::bidirectionalS, AlgoNodeStruct>
ExecPlan;
38 typedef graph_traits<ExecPlan>::vertex_descriptor
AlgoVertex;
50 m_graph(&graph), m_nodeIndex(nodeIndex), m_nodeName(name) {}
58 virtual bool promoteToControlReadyState(
const int& slotNum,
68 const unsigned int& recursionLevel)
const = 0;
72 virtual void updateDecision(
const int& slotNum,
80 std::string stateToString(
const int& stateId)
const;
91 m_modeConcurrent(modeConcurrent), m_modePromptDecision(modePromptDecision), m_modeOR(modeOR), m_allPass(allPass), m_children()
99 bool promoteToControlReadyState(
const int& slotNum,
103 void updateDecision(
const int& slotNum,
120 const unsigned int& recursionLevel)
const override;
145 m_algoIndex(0),m_algoName(algoName),m_inverted(inverted),m_allPass(allPass),
m_rank(-1),m_isIOBound(IOBound)
170 void addOutputDataNode(
DataNode* node);
172 void addInputDataNode(
DataNode* node);
189 bool dataDependenciesSatisfied(
const int& slotNum)
const;
195 bool promoteToControlReadyState(
const int& slotNum,
199 bool promoteToDataReadyState(
const int& slotNum,
const AlgorithmNode* requestor =
nullptr)
const;
201 void updateDecision(
const int& slotNum,
209 const unsigned int& recursionLevel)
const override;
250 if (
std::find(m_producers.begin(),m_producers.end(),node) == m_producers.end())
251 m_producers.push_back(node);
255 if (
std::find(m_consumers.begin(),m_consumers.end(),node) == m_consumers.end())
256 m_consumers.push_back(node);
285 m_headNode(0), m_nodeCounter(0), m_svcLocator(svc),
m_name(name), m_initTime(
std::chrono::system_clock::now()),
286 m_eventSlots(nullptr) {}
289 if (m_headNode != 0)
delete m_headNode;
296 void registerIODataObjects(
const Algorithm* algo);
300 StatusCode buildAugmentedDataDependenciesRealm();
302 void addHeadNode(
const std::string& headName,
bool modeConcurrent,
bool modePromptDecision,
bool modeOR,
bool allPass);
308 auto node = getAlgorithmNode(algo_name);
309 for (
auto ialgoIt = container.unsafe_begin(); ialgoIt != container.unsafe_end(); ++ialgoIt)
310 node->attachAlgorithm(*ialgoIt);
319 StatusCode addDecisionHubNode(
Algorithm* daughterAlgo,
const std::string& parentName,
bool modeConcurrent,
bool modePromptDecision,
bool modeOR,
bool allPass);
336 const unsigned int& recursionLevel)
const {m_headNode->printState(output,states,node_decisions,recursionLevel);}
352 void dumpExecutionPlan();
std::vector< DataNode * > m_outputs
Vectors, used in augmented data dependencies realm Outputs of the algorithm, represented as DataNode'...
const unsigned int & getAlgoIndex() const
XXX: CF tests.
std::vector< DecisionNode * > m_parents
XXX: CF tests. All direct parent nodes in the tree.
ControlFlowNode(PrecedenceRulesGraph &graph, unsigned int nodeIndex, const std::string &name)
Constructor.
std::unordered_map< std::string, DataObjIDColl > AlgoOutputsMap
unsigned int m_algoIndex
The index of the algorithm.
const std::chrono::system_clock::time_point getInitTime() const
DecisionNode(PrecedenceRulesGraph &graph, unsigned int nodeIndex, const std::string &name, bool modeConcurrent, bool modePromptDecision, bool modeOR, bool allPass)
Constructor.
AlgoNodeStruct(const std::string &name, const int index=-1, const int &rank=-1, const double &runtime=-1, const double &eccentricity=-1.0)
The namespace threadpool contains a thread pool and related utility classes.
void setIOBound(bool value)
Set the I/O-boundness flag.
void attachAlgorithmsToNodes(const std::string &algo_name, const T &container)
Attach pointers to real Algorithms (and their clones) to Algorithm nodes of the graph.
friend ExecutionFlowManager
const std::chrono::system_clock::time_point m_initTime
std::string m_algoName
The name of the algorithm.
boost::adjacency_list< boost::vecS, boost::vecS, boost::bidirectionalS, AlgoNodeStruct > ExecPlan
const std::vector< DataNode * > & getInputDataNodes() const
Get all consumer nodes.
std::vector< AlgorithmNode * > m_consumers
AlgorithmNodes that represent algorithms which need the output of the algorithm.
SmartIF< ISvcLocator > & serviceLocator() const override
Retrieve pointer to service locator.
AlgoNodesMap m_algoNameToAlgoNodeMap
Index: map of algorithm's name to AlgorithmNode.
void setRank(float &rank)
Set Algorithm rank.
std::vector< ControlFlowNode * > m_children
All direct daughter nodes in the tree.
std::unordered_map< std::string, DecisionNode * > DecisionHubsMap
const std::vector< IAlgorithm * > & getAlgorithmRepresentatives() const
get Algorithm representatives
void printState(std::stringstream &output, AlgsExecutionStates &states, const std::vector< int > &node_decisions, const unsigned int &recursionLevel) const
Print a string representing the control flow state.
std::vector< DecisionNode * > m_parents
XXX: CF tests.
const std::vector< DataNode * > & getOutputDataNodes() const
Get all supplier nodes.
bool m_inverted
Whether the selection result is negated or not.
bool m_allPass
Whether always passing regardless of daughter results.
std::vector< int > & getNodeDecisions(const int &slotNum) const
bool isIOBound() const
Check if algorithm is I/O-bound.
~PrecedenceRulesGraph() override
Destructor.
AlgorithmNode(PrecedenceRulesGraph &graph, unsigned int nodeIndex, const std::string &algoName, bool inverted, bool allPass, bool IOBound)
Constructor.
virtual ~ControlFlowNode()
Destructor.
bool m_modeOR
Whether acting as "and" (false) or "or" node (true)
const float & getRank() const
Get Algorithm rank.
std::vector< EventSlot > * m_eventSlots
The AlgsExecutionStates encodes the state machine for the execution of algorithms within a single eve...
Manage the execution flow using a graph of task precedence rules Once initialized, the graph is const and can be shared across events.
PrecedenceRulesGraph * m_graph
const DataObjID & getPath()
DecisionNode * m_headNode
the head node of the control flow graph; may want to have multiple ones once supporting trigger paths...
std::vector< AlgorithmNode * > m_consumers
This class is used for returning status codes from appropriate routines.
std::unordered_map< DataObjID, DataNode *, DataObjID_Hasher > DataNodesMap
const std::vector< ControlFlowNode * > & getDaughters() const
graph_traits< ExecPlan >::vertex_descriptor AlgoVertex
std::unordered_map< std::string, DataObjIDColl > AlgoInputsMap
std::map< std::string, boost::AlgoVertex > m_exec_plan_map
const std::vector< AlgorithmNode * > & getConsumers() const
Get all data object consumers.
const std::vector< AlgorithmNode * > & getConsumerNodes() const
Get all consumer nodes.
void addConsumerNode(AlgorithmNode *node)
Associate an AlgorithmNode, which is a data consumer of this one.
AlgoOutputsMap m_algoNameToAlgoOutputsMap
void attachAlgorithm(IAlgorithm *ialgo)
Attach Algorithm representative.
The IAlgorithm is the interface implemented by the Algorithm base class.
PrecedenceRulesGraph(const std::string &name, SmartIF< ISvcLocator > svc)
Constructor.
bool m_modePromptDecision
Whether to evaluate the hub decision ASA its child decisions allow to do that.
DataObjID m_data_object_path
AlgsExecutionStates & getAlgoStates(const int &slotNum) const
float m_rank
Algorithm rank of any kind.
std::vector< IAlgorithm * > m_representatives
Representatives (including clones) of the node.
std::unordered_map< std::string, AlgorithmNode * > AlgoNodesMap
Base class from which all concrete algorithm classes should be derived.
void addSupplierNode(AlgorithmNode *node)
Associate an AlgorithmNode, which is a data supplier for this one.
std::vector< InputHandle_t< In > > m_inputs
const std::vector< AlgorithmNode * > & getSupplierNodes() const
Get all supplier nodes.
std::vector< DataNode * > m_inputs
Inputs of the algorithm, represented as DataNode's.
bool m_modeConcurrent
Whether all daughters will be evaluated concurrently or sequentially.
Clock::time_point time_point
std::vector< AlgorithmNode * > m_producers
boost::ExecPlan m_ExecPlan
temporary items to experiment with execution planning
DataNode(PrecedenceRulesGraph &, const DataObjID &path)
Constructor.
unsigned int m_nodeCounter
Total number of nodes in the graph.
const std::string & getNodeName() const
const unsigned int & getNodeIndex() const
XXX: CF tests.
std::vector< AlgorithmNode * > m_suppliers
Vectors, used in data dependencies realm AlgorithmNodes that represent algorithms producing an input ...
State
Execution states of the algorithms.
const std::string & name() const override
Retrieve name of the service.
bool m_isIOBound
If an algorithm is I/O-bound (in the broad sense of Von Neumann bottleneck)
bool m_allPass
Whether the selection result is relevant or always "pass".
AlgoInputsMap m_algoNameToAlgoInputsMap
Indexes: maps of algorithm's name to algorithm's inputs/outputs.
void addProducerNode(AlgorithmNode *node)
Associate an AlgorithmNode, which is a data supplier for this one.
const std::vector< AlgorithmNode * > & getProducers() const
Get all data object producers.
DataNodesMap m_dataPathToDataNodeMap
Index: map of data path to DataNode.
unsigned int getControlFlowNodeCounter() const
Get total number of graph nodes.
SmartIF< ISvcLocator > m_svcLocator
Service locator (needed to access the MessageSvc)
AlgsExecutionStates::State State
void addConsumerNode(AlgorithmNode *node)
Associate an AlgorithmNode, which is a data consumer of this one.
DecisionHubsMap m_decisionNameToDecisionHubMap
Index: map of decision's name to DecisionHub.