| The Gaudi Framework v28r2-patches (bc4ad17a)

- Main Page
- Related Pages
- Modules
- Namespaces
- Classes
- Files

- File List
- File Members

ExecutionFlowManager.cpp
Go to the documentation of this file.
1 #include "ExecutionFlowManager.h"
2
3 namespace concurrency {
4
5 //---------------------------------------------------------------------------
6 StatusCode ExecutionFlowManager::initialize(PrecedenceRulesGraph* graph,
7 const std::unordered_map<std::string,unsigned int>& algname_index_map){
8 m_PRGraph = graph;
9 StatusCode sc = graph->initialize(algname_index_map);
10 if (!sc.isSuccess())
11 error() << "Could not initialize the flow graph." << endmsg;
12
13 return sc;
14 }
15
16 //---------------------------------------------------------------------------
17 StatusCode ExecutionFlowManager::initialize(PrecedenceRulesGraph* graph,
18 const std::unordered_map<std::string,unsigned int>& algname_index_map,
19 std::vector<EventSlot>& eventSlots,
20 const std::string& mode){
21 m_PRGraph = graph;
22 StatusCode sc = graph->initialize(algname_index_map, eventSlots);
23 if (!sc.isSuccess()) {
24 error() << "Could not initialize the execution flow graph." << endmsg;
25 return sc;
26 }
27
28 // Rank algorithms if any known optimization mode is supplied
29 if (mode == "PCE") {
30 auto ranker = concurrency::RankerByProductConsumption();
31 m_PRGraph->rankAlgorithms(ranker);
32 } else if (mode == "COD") {
33 auto ranker = concurrency::RankerByCummulativeOutDegree();
34 m_PRGraph->rankAlgorithms(ranker);
35 } else if (mode == "E") {
36 auto ranker = concurrency::RankerByEccentricity();
37 m_PRGraph->rankAlgorithms(ranker);
38 } else if (mode == "T") {
39 auto ranker = concurrency::RankerByTiming();
40 m_PRGraph->rankAlgorithms(ranker);
41 } else if (mode == "DRE") {
42 auto ranker = concurrency::RankerByDataRealmEccentricity();
43 m_PRGraph->rankAlgorithms(ranker);
44 } else if (!mode.empty()){
45 error() << "Requested optimization mode '" << mode << "' is not known." << endmsg;
46 sc = StatusCode::FAILURE;
47 }
48
49 return sc;
50 }
51
52 //---------------------------------------------------------------------------
53 void ExecutionFlowManager::simulateExecutionFlow(IGraphVisitor& visitor) const {
54
55 std::vector<int>& nodeDecisions = m_PRGraph->getNodeDecisions(0);
56
57 std::vector<int> fixedNodeDecisions;
58 int cntr = 0;
59 std::vector<int> counters;
60 while (!rootDecisionResolved(nodeDecisions)) {
61 cntr += 1;
62 int prevAlgosNum = visitor.m_nodesSucceeded;
63 debug() << " Proceeding with iteration #" << cntr << endmsg;
64 fixedNodeDecisions = m_PRGraph->getNodeDecisions(0);
65 m_PRGraph->m_headNode->accept(visitor);
66 if ( fixedNodeDecisions == nodeDecisions) {
67 error() << " No progress on iteration " << cntr << " detected" << endmsg;
68 debug() << nodeDecisions << endmsg;
69 break;
70 }
71 info() << " Iteration #" << cntr << " finished, total algorithms executed: " << visitor.m_nodesSucceeded << endmsg;
72
73 std::stringstream s;
74 s << cntr << ", " << (visitor.m_nodesSucceeded-prevAlgosNum) << "\n";
75
76 std::ofstream myfile;
77 myfile.open("RunSimulation.csv", std::ios::app);
78 myfile << s.str();
79 myfile.close();
80
81
82 if (visitor.m_nodesSucceeded != prevAlgosNum)
83 counters.push_back(visitor.m_nodesSucceeded);
84 }
85
86 info() << "Asymptotical concurrency speedup depth: " << (float) visitor.m_nodesSucceeded / (float) counters.size() << endmsg;
87
88 // Reset algorithm states and node decisions
89 m_PRGraph->getAlgoStates(0).reset();
90 nodeDecisions.assign(nodeDecisions.size(),-1);
91
92 }
93
94 //---------------------------------------------------------------------------
95 void ExecutionFlowManager::updateEventState(AlgsExecutionStates& algo_states,
96 std::vector<int>& node_decisions) const {
97 m_PRGraph->updateEventState(algo_states, node_decisions);
98 }
99
100 //---------------------------------------------------------------------------
101 void ExecutionFlowManager::updateDecision(const std::string& algo_name,
102 const int& slotNum,
103 AlgsExecutionStates& algo_states,
104 std::vector<int>& node_decisions) const {
105 m_PRGraph->updateDecision(algo_name, slotNum, algo_states, node_decisions);
106 }
107
108 //---------------------------------------------------------------------------
109 void ExecutionFlowManager::promoteToControlReadyState(AlgsExecutionStates& algo_states,
110 std::vector<int>& node_decisions,
111 const int& slotNum) const {
112 m_PRGraph->m_headNode->promoteToControlReadyState(slotNum, algo_states, node_decisions);
113 }
114
115 //---------------------------------------------------------------------------
116 bool ExecutionFlowManager::algoDataDependenciesSatisfied(const std::string& algo_name, const int& slotNum) const {
117 return m_PRGraph->getAlgorithmNode(algo_name)->dataDependenciesSatisfied(slotNum);
118 }
119
120 //---------------------------------------------------------------------------
121 bool ExecutionFlowManager::rootDecisionResolved(const std::vector<int>& node_decisions) const {
122
123 return (-1 != node_decisions[m_PRGraph->m_headNode->getNodeIndex()]) ? true : false;
124 }
125
126 //---------------------------------------------------------------------------
127 void ExecutionFlowManager::touchReadyAlgorithms(IGraphVisitor& visitor) const {
128
129 //auto& states = m_PRGraph->getAlgoStates(visitor.m_slotNum);
130 //auto& decisions = m_PRGraph->getNodeDecisions(visitor.m_slotNum);
131
132 //m_PRGraph->m_headNode->promoteToControlReadyState(slotNum,states,decisions);
133
134 m_PRGraph->m_headNode->accept(visitor);
135
136 }
137 }
concurrency::ExecutionFlowManager::simulateExecutionFlow
void simulateExecutionFlow(IGraphVisitor &visitor) const
Definition: ExecutionFlowManager.cpp:53
std::string::empty
T empty(T...args)
std::ofstream::open
T open(T...args)
concurrency::ExecutionFlowManager::updateEventState
void updateEventState(AlgsExecutionStates &algo_states, std::vector< int > &node_decisions) const
Update the state of algorithms to controlready, where possible.
Definition: ExecutionFlowManager.cpp:95
ExecutionFlowManager.h
StatusCode::FAILURE
Definition: StatusCode.h:29
CommonMessagingBase::info
MsgStream & info() const
shortcut for the method msgStream(MSG::INFO)
Definition: CommonMessaging.h:123
concurrency::ExecutionFlowManager::algoDataDependenciesSatisfied
bool algoDataDependenciesSatisfied(const std::string &algo_name, const int &slotNum) const
Check all data dependencies of an algorithm are satisfied.
Definition: ExecutionFlowManager.cpp:116
concurrency::AlgorithmNode::dataDependenciesSatisfied
bool dataDependenciesSatisfied(const int &slotNum) const
Method to check whether the Algorithm has its all data dependency satisfied.
Definition: PrecedenceRulesGraph.cpp:292
concurrency
Definition: ExecutionFlowManager.cpp:3
StatusCode::isSuccess
bool isSuccess() const
Test for a status code of SUCCESS.
Definition: StatusCode.h:74
concurrency::ExecutionFlowManager::touchReadyAlgorithms
void touchReadyAlgorithms(IGraphVisitor &visitor) const
Promote all algorithms, ready to be executed, to DataReady state.
Definition: ExecutionFlowManager.cpp:127
concurrency::ExecutionFlowManager::initialize
StatusCode initialize(PrecedenceRulesGraph *graph, const std::unordered_map< std::string, unsigned int > &algname_index_map)
Initialize the control flow manager It greps the topalg list and the index map for the algo names...
Definition: ExecutionFlowManager.cpp:6
concurrency::PrecedenceRulesGraph::getAlgorithmNode
AlgorithmNode * getAlgorithmNode(const std::string &algoName) const
Get the AlgorithmNode from by algorithm name using graph index.
Definition: PrecedenceRulesGraph.cpp:645
concurrency::PrecedenceRulesGraph::rankAlgorithms
void rankAlgorithms(IGraphVisitor &ranker) const
Rank Algorithm nodes by the number of data outputs.
Definition: PrecedenceRulesGraph.cpp:747
concurrency::PrecedenceRulesGraph::getNodeDecisions
std::vector< int > & getNodeDecisions(const int &slotNum) const
Definition: PrecedenceRulesGraph.h:348
std::stringstream
STL class.
std::string
STL class.
concurrency::DecisionNode::accept
bool accept(IGraphVisitor &visitor) override
Definition: PrecedenceRulesGraph.cpp:192
std::vector::push_back
T push_back(T...args)
concurrency::ExecutionFlowManager::updateDecision
void updateDecision(const std::string &algo_name, const int &slotNum, AlgsExecutionStates &states, std::vector< int > &node_decisions) const
Definition: ExecutionFlowManager.cpp:101
CommonMessagingBase::error
MsgStream & error() const
shortcut for the method msgStream(MSG::ERROR)
Definition: CommonMessaging.h:117
std::ofstream
STL class.
concurrency::RankerByTiming
Definition: PRGraphVisitors.h:145
concurrency::PrecedenceRulesGraph::updateDecision
void updateDecision(const std::string &algo_name, const int &slotNum, AlgsExecutionStates &states, std::vector< int > &node_decisions) const
A method to update algorithm node decision, and propagate it upwards.
Definition: PrecedenceRulesGraph.cpp:738
concurrency::ExecutionFlowManager::rootDecisionResolved
bool rootDecisionResolved(const std::vector< int > &node_decisions) const
Check whether root decision was resolved.
Definition: ExecutionFlowManager.cpp:121
concurrency::RankerByDataRealmEccentricity
Definition: PRGraphVisitors.h:197
AlgsExecutionStates
The AlgsExecutionStates encodes the state machine for the execution of algorithms within a single eve...
Definition: AlgsExecutionStates.h:28
concurrency::ExecutionFlowManager::promoteToControlReadyState
void promoteToControlReadyState(AlgsExecutionStates &algo_states, std::vector< int > &node_decisions, const int &slotNum=-1) const
XXX: CF tests.
Definition: ExecutionFlowManager.cpp:109
concurrency::PrecedenceRulesGraph::m_headNode
DecisionNode * m_headNode
the head node of the control flow graph; may want to have multiple ones once supporting trigger paths...
Definition: PrecedenceRulesGraph.h:358
StatusCode
This class is used for returning status codes from appropriate routines.
Definition: StatusCode.h:26
concurrency::RankerByEccentricity
Definition: PRGraphVisitors.h:171
std::stringstream::str
T str(T...args)
concurrency::IGraphVisitor
Definition: IGraphVisitor.h:9
concurrency::PrecedenceRulesGraph::getAlgoStates
AlgsExecutionStates & getAlgoStates(const int &slotNum) const
Definition: PrecedenceRulesGraph.h:346
plotSpeedupsPyRoot.graph
graph
Definition: plotSpeedupsPyRoot.py:134
concurrency::PrecedenceRulesGraph
Definition: PrecedenceRulesGraph.h:280
std::vector::size
T size(T...args)
concurrency::PrecedenceRulesGraph::initialize
StatusCode initialize(const std::unordered_map< std::string, unsigned int > &algname_index_map)
Initialize graph.
Definition: PrecedenceRulesGraph.cpp:439
std::vector::assign
T assign(T...args)
std::vector< EventSlot >
CommonMessagingBase::debug
MsgStream & debug() const
shortcut for the method msgStream(MSG::DEBUG)
Definition: CommonMessaging.h:126
concurrency::RankerByProductConsumption
Definition: PRGraphVisitors.h:91
concurrency::IGraphVisitor::m_nodesSucceeded
int m_nodesSucceeded
Definition: IGraphVisitor.h:23
AlgsExecutionStates::reset
void reset()
Definition: AlgsExecutionStates.h:52
concurrency::PrecedenceRulesGraph::updateEventState
void updateEventState(AlgsExecutionStates &states, std::vector< int > &node_decisions) const
XXX CF tests. Is needed for older CF implementation.
Definition: PrecedenceRulesGraph.cpp:732
BrunelScenarioForwardScheduler.app
app
Definition: BrunelScenarioForwardScheduler.py:137
gaudirun.s
string s
Definition: gaudirun.py:245
concurrency::DecisionNode::promoteToControlReadyState
bool promoteToControlReadyState(const int &slotNum, AlgsExecutionStates &states, std::vector< int > &node_decisions) const override
XXX: CF tests. Method to set algos to CONTROLREADY, if possible.
Definition: PrecedenceRulesGraph.cpp:170
concurrency::ControlFlowNode::getNodeIndex
const unsigned int & getNodeIndex() const
XXX: CF tests.
Definition: PrecedenceRulesGraph.h:70
concurrency::ExecutionFlowManager::m_PRGraph
PrecedenceRulesGraph * m_PRGraph
the graph of precedence rules
Definition: ExecutionFlowManager.h:73
endmsg
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition: MsgStream.h:244
concurrency::RankerByCummulativeOutDegree
Definition: PRGraphVisitors.h:117
std::unordered_map< std::string, unsigned int >