Go to the documentation of this file.
23 #define ON_DEBUG if ( msgLevel( MSG::DEBUG ) )
24 #define ON_VERBOSE if ( msgLevel( MSG::VERBOSE ) )
35 if ( sc.isFailure() ) {
36 fatal() <<
"Base class failed to initialize" <<
endmsg;
41 if ( m_dumpPrecTrace || m_dumpPrecRules ) {
42 if ( !boost::filesystem::create_directory( m_dumpDirName ) ) {
43 error() <<
"Could not create directory " << m_dumpDirName
45 "for task precedence tracing"
51 if ( m_dumpPrecRules ) m_PRGraph.enableAnalysis();
54 m_algResourcePool = serviceLocator()->service(
"AlgResourcePool" );
55 if ( !m_algResourcePool.isValid() ) {
56 fatal() <<
"Error retrieving AlgoResourcePool" <<
endmsg;
60 info() <<
"Assembling CF and DF task precedence rules" <<
endmsg;
67 for (
const auto& ialgoPtr : m_algResourcePool->getTopAlgList() ) {
69 if ( !algorithm ) fatal() <<
"Conversion from IAlgorithm to Gaudi::Algorithm failed" <<
endmsg;
70 sc = assembleCFRules( algorithm,
"RootDecisionHub" );
71 if ( sc.isFailure() ) {
72 fatal() <<
"Could not assemble the CF precedence realm" <<
endmsg;
77 if ( m_ignoreDFRules ) {
78 warning() <<
"Ignoring DF precedence rules, disabling all associated features" <<
endmsg;
83 sc = m_PRGraph.initialize();
84 if ( sc.isFailure() ) {
85 fatal() <<
"Could not assemble the DF precedence realm" <<
endmsg;
90 if ( m_mode ==
"PCE" ) {
92 m_PRGraph.rankAlgorithms( ranker );
93 }
else if ( m_mode ==
"COD" ) {
95 m_PRGraph.rankAlgorithms( ranker );
96 }
else if ( m_mode ==
"E" ) {
98 m_PRGraph.rankAlgorithms( ranker );
99 }
else if ( m_mode ==
"T" ) {
101 m_PRGraph.rankAlgorithms( ranker );
102 }
else if ( m_mode ==
"DRE" ) {
104 m_PRGraph.rankAlgorithms( ranker );
105 }
else if ( !m_mode.empty() ) {
106 error() <<
"Requested prioritization rule '" << m_mode <<
"' is unknown" <<
endmsg;
110 if ( m_showDataFlow ) { debug() << m_PRGraph.dumpDataFlow() <<
endmsg; }
112 if ( m_verifyRules ) {
117 m_PRGraph.accept( propValidator );
118 if ( !propValidator.passed() )
119 warning() << propValidator.reply() <<
endmsg;
125 m_PRGraph.accept( prodValidator );
126 if ( !prodValidator.passed() ) {
127 error() << prodValidator.reply() <<
endmsg;
134 m_PRGraph.accept( sccFinder );
135 if ( !sccFinder.passed() ) {
136 error() << sccFinder.reply() <<
endmsg;
143 if ( sc.isSuccess() ) info() <<
"PrecedenceSvc initialized successfully" <<
endmsg;
150 unsigned int recursionDepth ) {
157 bool isGaudiSequencer(
false );
158 bool isAthSequencer(
false );
166 isGaudiSequencer =
true;
168 isAthSequencer =
true;
173 error() <<
"Algorithm " << algo->
name() <<
" has isSequence==true, but unable to dcast to Sequence" <<
endmsg;
177 auto subAlgorithms =
seq->subAlgorithms();
183 bool allPass =
false;
184 bool promptDecision =
false;
185 bool isSequential =
false;
186 bool isInverted =
false;
188 if ( isGaudiSequencer ) {
189 modeOr = ( algo->
getProperty(
"ModeOR" ).toString() ==
"True" );
190 allPass = ( algo->
getProperty(
"IgnoreFilterPassed" ).toString() ==
"True" );
191 promptDecision = ( algo->
getProperty(
"ShortCircuit" ).toString() ==
"True" );
192 isInverted = ( algo->
getProperty(
"Invert" ).toString() ==
"True" );
193 if ( allPass ) promptDecision =
false;
194 isSequential = ( algo->
hasProperty(
"Sequential" ) && ( algo->
getProperty(
"Sequential" ).toString() ==
"True" ) );
195 }
else if ( isAthSequencer ) {
196 modeOr = ( algo->
getProperty(
"ModeOR" ).toString() ==
"True" );
197 allPass = ( algo->
getProperty(
"IgnoreFilterPassed" ).toString() ==
"True" );
198 promptDecision = ( algo->
getProperty(
"StopOverride" ).toString() ==
"False" );
199 isSequential = ( algo->
hasProperty(
"Sequential" ) && ( algo->
getProperty(
"Sequential" ).toString() ==
"True" ) );
204 error() <<
"Failed to add DecisionHub " << algo->
name() <<
" to graph of precedence rules" <<
endmsg;
208 for (
auto subalgo : *subAlgorithms ) {
211 error() <<
"Algorithm " << subalgo->name() <<
" could not be flattened" <<
endmsg;
256 int prevAlgosNum = visitor.m_nodesSucceeded;
257 ON_DEBUG debug() <<
" Proceeding with iteration #" << cntr <<
endmsg;
260 if ( prevNodeDecisions == nodeDecisions ) {
261 error() <<
" No progress on iteration " << cntr <<
" detected, node decisions are:" << nodeDecisions <<
endmsg;
264 info() <<
" Iteration #" << cntr <<
" finished, total algorithms executed: " << visitor.m_nodesSucceeded
268 s << cntr <<
", " << ( visitor.m_nodesSucceeded - prevAlgosNum ) <<
"\n";
275 if ( visitor.m_nodesSucceeded != prevAlgosNum ) counters.
push_back( visitor.m_nodesSucceeded );
278 info() <<
"Asymptotical intra-event speedup: " << (float)visitor.m_nodesSucceeded / (
float)counters.
size() <<
endmsg;
282 nodeDecisions.assign( nodeDecisions.size(), -1 );
300 info() <<
std::endl <<
"===================== Data Flow Configuration ====================" <<
std::endl;
316 warning() <<
"To trace temporal and topological aspects of execution flow, "
317 <<
"set DumpPrecedenceRules property to True " <<
endmsg;
321 ON_DEBUG debug() <<
"Dumping temporal precedence rules" <<
endmsg;
326 fileName =
"rules_evt-" +
std::to_string( eventID.event_number() ) +
"_slot-" +
334 pth.append( fileName );
343 warning() <<
"To trace task precedence patterns, set DumpPrecedenceTrace "
344 <<
"property to True " <<
endmsg;
348 ON_DEBUG debug() <<
"Dumping temporal precedence trace" <<
endmsg;
353 fileName =
"trace_evt-" +
std::to_string( eventID.event_number() ) +
"_slot-" +
361 pth.append( fileName );
std::unique_ptr< EventContext > eventContext
Cache for the eventContext.
A service to resolve the task execution precedence.
Gaudi::Property< bool > m_dumpPrecRules
void dumpPrecedenceTrace(const EventSlot &) override
Dump precedence trace (available only in DEBUG mode, and must be enabled with the corresponding servi...
StatusCode initialize() override
void printState(std::stringstream &output, EventSlot &slot, const unsigned int &recursionLevel) const
Print a string representing the control flow state.
void dumpPrecTrace(const boost::filesystem::path &, const EventSlot &slot)
dump to file the precedence trace
void dumpPrecedenceRules(const EventSlot &) override
Dump precedence rules (available only in DEBUG mode, and must be enabled with the corresponding servi...
concurrency::PrecedenceRulesGraph m_PRGraph
Graph of precedence rules.
const std::string & name() const override
The identifying name of the algorithm object.
Gaudi::Property< std::string > m_dumpPrecTraceFile
const EventIDBase & eventID() const
StatusCode assembleCFRules(Gaudi::Algorithm *, const std::string &, unsigned int recursionDepth=0)
Class representing an event slot.
void dumpPrecRules(const boost::filesystem::path &, const EventSlot &slot)
dump to file the precedence rules
StatusCode getProperty(Gaudi::Details::PropertyBase *p) const override
get the property
const std::string printState(EventSlot &) const override
StatusCode finalize() override
bool accept(IGraphVisitor &visitor) override
Visitor entry point.
StatusCode simulate(EventSlot &) const override
Simulate execution flow.
void dumpDataFlow() const override
boost::filesystem::path m_dumpDirName
Precedence analysis facilities.
EventSlot * parentSlot
Pointer to parent slot (null for top level)
Base class from which all concrete algorithm classes should be derived.
bool CFRulesResolved(EventSlot &) const override
Check if the root CF decision is resolved.
Gaudi::Property< bool > m_dumpPrecTrace
StatusCode addDecisionHubNode(Gaudi::Algorithm *daughterAlgo, const std::string &parentName, concurrency::Concurrent, concurrency::PromptDecision, concurrency::ModeOr, concurrency::AllPass, concurrency::Inverted)
Add a node, which aggregates decisions of direct daughter nodes.
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
std::string dumpControlFlow() const
Print out control flow of Algorithms and Sequences.
StatusCode iterate(EventSlot &, const Cause &) override
Infer the precedence effect caused by an execution flow event.
AlgorithmNode * getAlgorithmNode(const std::string &algoName) const
Get the AlgorithmNode from by algorithm name using graph index.
std::string dumpDataFlow() const
Print out all data origins and destinations, as reflected in the EF graph.
constexpr static const auto SUCCESS
#define DECLARE_COMPONENT(type)
StatusCode addAlgorithmNode(Gaudi::Algorithm *daughterAlgo, const std::string &parentName)
Add algorithm node.
Gaudi::Property< std::string > m_dumpPrecRulesFile
void dumpControlFlow() const override
Dump precedence rules.
std::vector< int > controlFlowState
State of the control flow.
bool accept(IGraphVisitor &visitor) override
Visitor entry point.
constexpr static const auto FAILURE
DecisionNode * getHeadNode() const
Get head node.
AlgsExecutionStates algsStates
Vector of algorithms states.
bool isSequence() const override
Are we a Sequence?
const unsigned int & getNodeIndex() const
Get node index.
StatusCode finalize() override
Finalize.
bool hasProperty(std::string_view name) const override
Return true if we have a property with the given name.