The Gaudi Framework  master (68c8ac5a)
Loading...
Searching...
No Matches
PrecedenceSvc Class Reference

A service to resolve the task execution precedence. More...

#include <GaudiHive/PrecedenceSvc.h>

Inheritance diagram for PrecedenceSvc:
Collaboration diagram for PrecedenceSvc:

Public Member Functions

 PrecedenceSvc (const std::string &name, ISvcLocator *svcLoc)
 Constructor.
StatusCode initialize () override
 Initialize.
StatusCode finalize () override
 Finalize.
StatusCode iterate (EventSlot &, const Cause &) override
 Infer the precedence effect caused by an execution flow event.
StatusCode simulate (EventSlot &) const override
 Simulate execution flow.
bool CFRulesResolved (EventSlot &) const override
 Check if the root CF decision is resolved.
uint getPriority (const std::string &name) const override
 Get priority of an algorithm.
bool isAsynchronous (const std::string &name) const override
 Check if a task is asynchronous.
void dumpControlFlow () const override
 Dump precedence rules.
void dumpDataFlow () const override
const std::string printState (EventSlot &) const override
void dumpPrecedenceRules (const EventSlot &) override
 Dump precedence rules (available only in DEBUG mode, and must be enabled with the corresponding service property).
void dumpPrecedenceTrace (const EventSlot &) override
 Dump precedence trace (available only in DEBUG mode, and must be enabled with the corresponding service property).
const concurrency::PrecedenceRulesGraph * getRules () const
 Precedence rules accessor.
Public Member Functions inherited from extends< Service, IPrecedenceSvc >
void const * i_cast (const InterfaceID &tid) const override
 Implementation of IInterface::i_cast.
StatusCode queryInterface (const InterfaceID &ti, void **pp) override
 Implementation of IInterface::queryInterface.
std::vector< std::string > getInterfaceNames () const override
 Implementation of IInterface::getInterfaceNames.
Public Member Functions inherited from Service
const std::string & name () const override
 Retrieve name of the service.
StatusCode configure () override
StatusCode initialize () override
StatusCode start () override
StatusCode stop () override
StatusCode finalize () override
StatusCode terminate () override
Gaudi::StateMachine::State FSMState () const override
Gaudi::StateMachine::State targetFSMState () const override
StatusCode reinitialize () override
StatusCode restart () override
StatusCode sysInitialize () override
 Initialize Service.
StatusCode sysStart () override
 Initialize Service.
StatusCode sysStop () override
 Initialize Service.
StatusCode sysFinalize () override
 Finalize Service.
StatusCode sysReinitialize () override
 Re-initialize the Service.
StatusCode sysRestart () override
 Re-initialize the Service.
 Service (std::string name, ISvcLocator *svcloc)
 Standard Constructor.
SmartIF< ISvcLocator > & serviceLocator () const override
 Retrieve pointer to service locator.
template<typename IFace = IService>
SmartIF< IFace > service (const std::string &name, bool createIf=true) const
template<class T>
Gaudi::Details::PropertyBase * declareProperty (const std::string &name, ToolHandle< T > &hndl, const std::string &doc="none")
template<class T>
StatusCode declareTool (ToolHandle< T > &handle, bool createIf=true)
template<class T>
StatusCode declareTool (ToolHandle< T > &handle, const std::string &toolTypeAndName, bool createIf=true)
 Declare used tool.
template<class T>
Gaudi::Details::PropertyBase * declareProperty (const std::string &name, ToolHandleArray< T > &hndlArr, const std::string &doc="none")
template<class T>
void addToolsArray (ToolHandleArray< T > &hndlArr)
const std::vector< IAlgTool * > & tools () const
SmartIF< IAuditorSvc > & auditorSvc () const
 The standard auditor service.May not be invoked before sysInitialize() has been invoked.
Public Member Functions inherited from PropertyHolder< CommonMessaging< implements< IService, IProperty, IStateful > > >
StatusCode setProperty (const Gaudi::Details::PropertyBase &p)
 Set the property from a property.
StatusCode setProperty (const std::string &name, const char *v)
 Special case for string literals.
StatusCode setProperty (const std::string &name, const std::string &v)
 Special case for std::string.
StatusCode setProperty (const std::string &name, const TYPE &value)
 set the property form the value
 PropertyHolder ()=default
Gaudi::Details::PropertyBase & declareProperty (Gaudi::Details::PropertyBase &prop)
 Declare a property.
Gaudi::Details::PropertyBase * declareRemoteProperty (const std::string &name, IProperty *rsvc, const std::string &rname="")
 Declare a remote property.
StatusCode setPropertyRepr (const std::string &n, const std::string &r) override
 set the property from name and value string representation
StatusCode getProperty (Gaudi::Details::PropertyBase *p) const override
 get the property
const std::vector< Gaudi::Details::PropertyBase * > & getProperties () const override
 get all properties
bool hasProperty (std::string_view name) const override
 Return true if we have a property with the given name.
Gaudi::Details::PropertyBase * property (std::string_view name) const
 \fixme property and bindPropertiesTo should be protected
void bindPropertiesTo (Gaudi::Interfaces::IOptionsSvc &optsSvc)
PropertyHolder & operator= (const PropertyHolder &)=delete
Public Member Functions inherited from CommonMessagingBase
virtual ~CommonMessagingBase ()=default
 Virtual destructor.
const SmartIF< IMessageSvc > & msgSvc () const
 The standard message service.
MsgStream & msgStream () const
 Return an uninitialized MsgStream.
MsgStream & msgStream (const MSG::Level level) const
 Predefined configurable message stream for the efficient printouts.
MsgStream & always () const
 shortcut for the method msgStream(MSG::ALWAYS)
MsgStream & fatal () const
 shortcut for the method msgStream(MSG::FATAL)
MsgStream & err () const
 shortcut for the method msgStream(MSG::ERROR)
MsgStream & error () const
 shortcut for the method msgStream(MSG::ERROR)
MsgStream & warning () const
 shortcut for the method msgStream(MSG::WARNING)
MsgStream & info () const
 shortcut for the method msgStream(MSG::INFO)
MsgStream & debug () const
 shortcut for the method msgStream(MSG::DEBUG)
MsgStream & verbose () const
 shortcut for the method msgStream(MSG::VERBOSE)
MsgStream & msg () const
 shortcut for the method msgStream(MSG::INFO)
MSG::Level msgLevel () const
 get the cached level (originally extracted from the embedded MsgStream)
bool msgLevel (MSG::Level lvl) const
 get the output level from the embedded MsgStream

Private Member Functions

StatusCode assembleCFRules (Gaudi::Algorithm *, const std::string &, unsigned int recursionDepth=0)

Private Attributes

SmartIF< IAlgResourcePool > m_algResourcePool
 A shortcut to the algorithm resource pool.
concurrency::PrecedenceRulesGraph m_PRGraph { "PrecedenceRulesGraph", serviceLocator() }
 Graph of precedence rules.
Gaudi::Property< std::string > m_mode { this, "TaskPriorityRule", "", "Task avalanche induction strategy." }
 Scheduling strategy.
Gaudi::Property< bool > m_ignoreDFRules { this, "IgnoreDFRules", false, "Ignore the data flow rules." }
 Scheduling strategy.
std::filesystem::path m_dumpDirName
 Precedence analysis facilities.
Gaudi::Property< bool > m_dumpPrecTrace
Gaudi::Property< std::string > m_dumpPrecTraceFile
Gaudi::Property< bool > m_dumpPrecRules { this, "DumpPrecedenceRules", false, "Dump task precedence rules." }
Gaudi::Property< std::string > m_dumpPrecRulesFile
Gaudi::Property< bool > m_verifyRules
Gaudi::Property< bool > m_showDataFlow

Additional Inherited Members

Public Types inherited from extends< Service, IPrecedenceSvc >
using base_class
 Typedef to this class.
using extend_interfaces_base
 Typedef to the base of this class.
Public Types inherited from Service
using Factory = Gaudi::PluginService::Factory<IService*( const std::string&, ISvcLocator* )>
Public Types inherited from PropertyHolder< CommonMessaging< implements< IService, IProperty, IStateful > > >
using PropertyHolderImpl
 Typedef used to refer to this class from derived classes, as in.
Public Types inherited from CommonMessaging< implements< IService, IProperty, IStateful > >
using base_class
Public Types inherited from extend_interfaces< Interfaces... >
using ext_iids
 take union of the ext_iids of all Interfaces...
Protected Member Functions inherited from Service
std::vector< IAlgTool * > & tools ()
 ~Service () override
int outputLevel () const
 get the Service's output level
Protected Member Functions inherited from CommonMessaging< implements< IService, IProperty, IStateful > >
MSG::Level setUpMessaging () const override final
 Set up local caches.
MSG::Level resetMessaging ()
 Reinitialize internal states.
void updateMsgStreamOutputLevel (int level)
 Update the output level of the cached MsgStream.
Protected Attributes inherited from Service
Gaudi::StateMachine::State m_state = Gaudi::StateMachine::OFFLINE
 Service state.
Gaudi::StateMachine::State m_targetState = Gaudi::StateMachine::OFFLINE
 Service state.
Gaudi::Property< int > m_outputLevel { this, "OutputLevel", MSG::NIL, "output level" }
 flag indicating whether ToolHandle tools have been added to m_tools
Gaudi::Property< bool > m_auditorInitialize { this, "AuditInitialize", false, "trigger auditor on initialize()" }
Gaudi::Property< bool > m_auditorStart { this, "AuditStart", false, "trigger auditor on start()" }
Gaudi::Property< bool > m_auditorStop { this, "AuditStop", false, "trigger auditor on stop()" }
Gaudi::Property< bool > m_auditorFinalize { this, "AuditFinalize", false, "trigger auditor on finalize()" }
Gaudi::Property< bool > m_auditorReinitialize { this, "AuditReinitialize", false, "trigger auditor on reinitialize()" }
Gaudi::Property< bool > m_auditorRestart { this, "AuditRestart", false, "trigger auditor on restart()" }
Gaudi::Property< bool > m_autoRetrieveTools
Gaudi::Property< bool > m_checkToolDeps
SmartIF< IAuditorSvc > m_pAuditorSvc
 Auditor Service.

Detailed Description

A service to resolve the task execution precedence.

Author
Illya Shapoval @created Aug 7, 2017

Definition at line 34 of file PrecedenceSvc.h.

Constructor & Destructor Documentation

◆ PrecedenceSvc()

PrecedenceSvc::PrecedenceSvc ( const std::string & name,
ISvcLocator * svcLoc )
inline

Constructor.

Definition at line 38 of file PrecedenceSvc.h.

38: base_class( name, svcLoc ) {}
const std::string & name() const override
Retrieve name of the service.
Definition Service.cpp:333

Member Function Documentation

◆ assembleCFRules()

StatusCode PrecedenceSvc::assembleCFRules ( Gaudi::Algorithm * algo,
const std::string & parentName,
unsigned int recursionDepth = 0 )
private

Definition at line 155 of file PrecedenceSvc.cpp.

156 {
157 using namespace concurrency;
158
159 StatusCode sc = StatusCode::SUCCESS;
160
161 ++recursionDepth;
162
163 bool isGaudiSequencer( false );
164 bool isAthSequencer( false );
165
166 if ( !algo->isSequence() ) {
167 ON_DEBUG debug() << std::string( recursionDepth, ' ' ) << "Algorithm '" << algo->name() << "' discovered" << endmsg;
168 sc = m_PRGraph.addAlgorithmNode( algo, parentName );
169 return sc;
170 } else {
171 if ( algo->hasProperty( "ShortCircuit" ) )
172 isGaudiSequencer = true;
173 else if ( algo->hasProperty( "StopOverride" ) )
174 isAthSequencer = true;
175 }
176
177 auto seq = dynamic_cast<Gaudi::Sequence*>( algo );
178 if ( seq == 0 ) {
179 error() << "Algorithm " << algo->name() << " has isSequence==true, but unable to dcast to Sequence" << endmsg;
180 return StatusCode::FAILURE;
181 }
182
183 auto subAlgorithms = seq->subAlgorithms();
184
185 // Recursively unroll
186 ON_DEBUG debug() << std::string( recursionDepth, ' ' ) << "Decision hub '" << algo->name() << "' discovered"
187 << endmsg;
188 bool modeOr = false;
189 bool allPass = false;
190 bool promptDecision = false;
191 bool isSequential = false;
192 bool isInverted = false;
193
194 if ( isGaudiSequencer ) {
195 modeOr = ( algo->getProperty( "ModeOR" ).toString() == "True" );
196 allPass = ( algo->getProperty( "IgnoreFilterPassed" ).toString() == "True" );
197 promptDecision = ( algo->getProperty( "ShortCircuit" ).toString() == "True" );
198 isInverted = ( algo->getProperty( "Invert" ).toString() == "True" );
199 if ( allPass ) promptDecision = false; // standard Gaudi::Sequencer behavior on all pass is to execute everything
200 isSequential = ( algo->hasProperty( "Sequential" ) && ( algo->getProperty( "Sequential" ).toString() == "True" ) );
201 } else if ( isAthSequencer ) {
202 modeOr = ( algo->getProperty( "ModeOR" ).toString() == "True" );
203 allPass = ( algo->getProperty( "IgnoreFilterPassed" ).toString() == "True" );
204 promptDecision = ( algo->getProperty( "StopOverride" ).toString() == "False" );
205 isSequential = ( algo->hasProperty( "Sequential" ) && ( algo->getProperty( "Sequential" ).toString() == "True" ) );
206 }
207 sc = m_PRGraph.addDecisionHubNode( algo, parentName, Concurrent{ !isSequential }, PromptDecision{ promptDecision },
208 ModeOr{ modeOr }, AllPass{ allPass }, Inverted{ isInverted } );
209 if ( sc.isFailure() ) {
210 error() << "Failed to add DecisionHub " << algo->name() << " to graph of precedence rules" << endmsg;
211 return sc;
212 }
213
214 for ( auto subalgo : *subAlgorithms ) {
215 sc = assembleCFRules( subalgo, algo->name(), recursionDepth );
216 if ( sc.isFailure() ) {
217 error() << "Algorithm " << subalgo->name() << " could not be flattened" << endmsg;
218 return sc;
219 }
220 }
221 return sc;
222}
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition MsgStream.h:198
#define ON_DEBUG
MsgStream & error() const
shortcut for the method msgStream(MSG::ERROR)
MsgStream & debug() const
shortcut for the method msgStream(MSG::DEBUG)
const std::string & name() const override
The identifying name of the algorithm object.
bool isSequence() const override
Are we a Sequence?
Definition Algorithm.h:195
concurrency::PrecedenceRulesGraph m_PRGraph
Graph of precedence rules.
StatusCode assembleCFRules(Gaudi::Algorithm *, const std::string &, unsigned int recursionDepth=0)
StatusCode getProperty(Gaudi::Details::PropertyBase *p) const override
get the property
bool hasProperty(std::string_view name) const override
Return true if we have a property with the given name.
bool isFailure() const
Definition StatusCode.h:118
constexpr static const auto SUCCESS
Definition StatusCode.h:99
constexpr static const auto FAILURE
Definition StatusCode.h:100
std::string toString(const TYPE &obj)
the generic implementation of the type conversion to the string
Definition ToStream.h:329
Gaudi::tagged_bool< class AllPass_tag > AllPass
Gaudi::tagged_bool< class ModeOr_tag > ModeOr
Gaudi::tagged_bool< class PromptDecision_tag > PromptDecision
Gaudi::tagged_bool< class Inverted_tag > Inverted

◆ CFRulesResolved()

bool PrecedenceSvc::CFRulesResolved ( EventSlot & slot) const
override

Check if the root CF decision is resolved.

Definition at line 294 of file PrecedenceSvc.cpp.

294 {
295 return ( -1 != slot.controlFlowState[m_PRGraph.getHeadNode()->getNodeIndex()] ? true : false );
296}
std::vector< int > controlFlowState
State of the control flow.
Definition EventSlot.h:91

◆ dumpControlFlow()

void PrecedenceSvc::dumpControlFlow ( ) const
override

Dump precedence rules.

Definition at line 299 of file PrecedenceSvc.cpp.

299 {
300
301 info() << std::endl << "==================== Control Flow Configuration ==================" << std::endl << std::endl;
302 info() << m_PRGraph.dumpControlFlow() << endmsg;
303}
MsgStream & info() const
shortcut for the method msgStream(MSG::INFO)

◆ dumpDataFlow()

void PrecedenceSvc::dumpDataFlow ( ) const
override

Definition at line 305 of file PrecedenceSvc.cpp.

305 {
306 info() << std::endl << "===================== Data Flow Configuration ====================" << std::endl;
307 info() << m_PRGraph.dumpDataFlow() << endmsg;
308}

◆ dumpPrecedenceRules()

void PrecedenceSvc::dumpPrecedenceRules ( const EventSlot & slot)
override

Dump precedence rules (available only in DEBUG mode, and must be enabled with the corresponding service property).

Definition at line 319 of file PrecedenceSvc.cpp.

319 {
320
321 if ( !m_dumpPrecRules ) {
322 warning() << "To trace temporal and topological aspects of execution flow, "
323 << "set DumpPrecedenceRules property to True " << endmsg;
324 return;
325 }
326
327 ON_DEBUG debug() << "Dumping temporal precedence rules" << endmsg;
328
329 std::string fileName;
330 if ( m_dumpPrecRulesFile.empty() ) {
331 const auto& eventID = slot.eventContext->eventID();
332 fileName = "rules_evt-" + std::to_string( eventID.event_number() ) + "_slot-" +
333 std::to_string( slot.eventContext->slot() ) + "_run-" + std::to_string( eventID.run_number() ) +
334 ".graphml";
335 } else {
336 fileName = m_dumpPrecRulesFile;
337 }
338
339 std::filesystem::path pth{ m_dumpDirName };
340 pth /= fileName;
341
342 m_PRGraph.dumpPrecRules( pth, slot );
343}
MsgStream & warning() const
shortcut for the method msgStream(MSG::WARNING)
const EventIDBase & eventID() const
ContextID_t slot() const
Gaudi::Property< bool > m_dumpPrecRules
Gaudi::Property< std::string > m_dumpPrecRulesFile
std::filesystem::path m_dumpDirName
Precedence analysis facilities.
std::unique_ptr< EventContext > eventContext
Cache for the eventContext.
Definition EventSlot.h:87

◆ dumpPrecedenceTrace()

void PrecedenceSvc::dumpPrecedenceTrace ( const EventSlot & slot)
override

Dump precedence trace (available only in DEBUG mode, and must be enabled with the corresponding service property).

Definition at line 346 of file PrecedenceSvc.cpp.

346 {
347
348 if ( !m_dumpPrecTrace ) {
349 warning() << "To trace task precedence patterns, set DumpPrecedenceTrace "
350 << "property to True " << endmsg;
351 return;
352 }
353
354 ON_DEBUG debug() << "Dumping temporal precedence trace" << endmsg;
355
356 std::string fileName;
357 if ( m_dumpPrecTraceFile.empty() ) {
358 const auto& eventID = slot.eventContext->eventID();
359 fileName = "trace_evt-" + std::to_string( eventID.event_number() ) + "_slot-" +
360 std::to_string( slot.eventContext->slot() ) + "_run-" + std::to_string( eventID.run_number() ) +
361 ".graphml";
362 } else {
363 fileName = m_dumpPrecTraceFile;
364 }
365
366 std::filesystem::path pth{ m_dumpDirName };
367 pth /= fileName;
368
369 m_PRGraph.dumpPrecTrace( pth, slot );
370}
Gaudi::Property< bool > m_dumpPrecTrace
Gaudi::Property< std::string > m_dumpPrecTraceFile

◆ finalize()

StatusCode PrecedenceSvc::finalize ( )
override

Finalize.

Definition at line 375 of file PrecedenceSvc.cpp.

375{ return Service::finalize(); }
StatusCode finalize() override
Definition Service.cpp:223

◆ getPriority()

uint PrecedenceSvc::getPriority ( const std::string & name) const
inlineoverride

Get priority of an algorithm.

Definition at line 56 of file PrecedenceSvc.h.

56 {
57 return (int)m_PRGraph.getAlgorithmNode( name )->getRank();
58 }

◆ getRules()

const concurrency::PrecedenceRulesGraph * PrecedenceSvc::getRules ( ) const
inline

Precedence rules accessor.

Definition at line 78 of file PrecedenceSvc.h.

78{ return &m_PRGraph; }

◆ initialize()

StatusCode PrecedenceSvc::initialize ( )
override

Initialize.

Definition at line 37 of file PrecedenceSvc.cpp.

37 {
38 using namespace concurrency;
39
40 auto sc = Service::initialize(); // parent class must be initialized first
41 if ( sc.isFailure() ) {
42 fatal() << "Base class failed to initialize" << endmsg;
43 return sc;
44 }
45
46 // prepare a directory to dump precedence analysis files to.
48 std::string pattern = "precedence.analysis.XXXXXX";
49 if ( !mkdtemp( pattern.data() ) ) {
50 error() << "Could not create directory \"precedence.analysis.XXXXXX\" required for task precedence tracing"
51 << endmsg;
53 }
54 m_dumpDirName = pattern; // Save the generated path
55 }
56
57 if ( m_dumpPrecRules ) m_PRGraph.enableAnalysis();
58
59 // Get the algo resource pool
60 m_algResourcePool = serviceLocator()->service( "AlgResourcePool" );
61 if ( !m_algResourcePool.isValid() ) {
62 fatal() << "Error retrieving AlgoResourcePool" << endmsg;
64 }
65
66 info() << "Assembling CF and DF task precedence rules" << endmsg;
67
68 ON_DEBUG debug() << "Assembling CF precedence realm:" << endmsg;
69 // create the root CF node
70 m_PRGraph.addHeadNode( "RootDecisionHub", Concurrent{ true }, PromptDecision{ false }, ModeOr{ true },
71 AllPass{ true }, Inverted{ false } );
72 // assemble the CF rules
73 for ( const auto& ialgoPtr : m_algResourcePool->getTopAlgList() ) {
74 auto algorithm = dynamic_cast<Gaudi::Algorithm*>( ialgoPtr );
75 if ( !algorithm ) fatal() << "Conversion from IAlgorithm to Gaudi::Algorithm failed" << endmsg;
76 sc = assembleCFRules( algorithm, "RootDecisionHub" );
77 if ( sc.isFailure() ) {
78 fatal() << "Could not assemble the CF precedence realm" << endmsg;
79 return sc;
80 }
81 }
82
83 if ( m_ignoreDFRules ) {
84 warning() << "Ignoring DF precedence rules, disabling all associated features" << endmsg;
86 }
87
88 ON_DEBUG debug() << "Assembling DF precedence realm:" << endmsg;
89 sc = m_PRGraph.initialize();
90 if ( sc.isFailure() ) {
91 fatal() << "Could not assemble the DF precedence realm" << endmsg;
92 return sc;
93 }
94
95 // Rank algorithms if a prioritization rule is supplied
96 if ( m_mode == "PCE" ) {
97 auto ranker = concurrency::RankerByProductConsumption();
98 m_PRGraph.rankAlgorithms( ranker );
99 } else if ( m_mode == "COD" ) {
100 auto ranker = concurrency::RankerByCummulativeOutDegree();
101 m_PRGraph.rankAlgorithms( ranker );
102 } else if ( m_mode == "E" ) {
103 auto ranker = concurrency::RankerByEccentricity();
104 m_PRGraph.rankAlgorithms( ranker );
105 } else if ( m_mode == "T" ) {
106 auto ranker = concurrency::RankerByTiming();
107 m_PRGraph.rankAlgorithms( ranker );
108 } else if ( m_mode == "DRE" ) {
109 auto ranker = concurrency::RankerByDataRealmEccentricity();
110 m_PRGraph.rankAlgorithms( ranker );
111 } else if ( !m_mode.empty() ) {
112 error() << "Requested prioritization rule '" << m_mode << "' is unknown" << endmsg;
113 return StatusCode::FAILURE;
114 }
115
116 if ( m_showDataFlow ) { debug() << m_PRGraph.dumpDataFlow() << endmsg; }
117
118 if ( m_verifyRules ) {
119 ON_DEBUG debug() << "Verifying task precedence rules" << endmsg;
120
121 // Check if CF properties are self-consistent
122 auto propValidator = concurrency::NodePropertiesValidator();
123 m_PRGraph.accept( propValidator );
124 if ( !propValidator.passed() )
125 warning() << propValidator.reply() << endmsg;
126 else
127 ON_DEBUG debug() << propValidator.reply() << endmsg;
128
129 // Check for violations in the DF topology
130 auto prodValidator = concurrency::ProductionAmbiguityFinder();
131 m_PRGraph.accept( prodValidator );
132 if ( !prodValidator.passed() ) {
133 error() << prodValidator.reply() << endmsg;
134 return StatusCode::FAILURE;
135 } else {
136 ON_DEBUG debug() << prodValidator.reply() << endmsg;
137 }
138
139 auto sccFinder = concurrency::TarjanSCCFinder();
140 m_PRGraph.accept( sccFinder );
141 if ( !sccFinder.passed() ) {
142 error() << sccFinder.reply() << endmsg;
143 return StatusCode::FAILURE;
144 } else {
145 ON_DEBUG debug() << sccFinder.reply() << endmsg;
146 }
147 }
148
149 if ( sc.isSuccess() ) info() << "PrecedenceSvc initialized successfully" << endmsg;
150
151 return sc;
152}
MsgStream & fatal() const
shortcut for the method msgStream(MSG::FATAL)
virtual SmartIF< IService > & service(const Gaudi::Utils::TypeNameString &typeName, const bool createIf=true)=0
Returns a smart pointer to a service.
Gaudi::Property< bool > m_showDataFlow
Gaudi::Property< bool > m_ignoreDFRules
Scheduling strategy.
Gaudi::Property< bool > m_verifyRules
SmartIF< IAlgResourcePool > m_algResourcePool
A shortcut to the algorithm resource pool.
Gaudi::Property< std::string > m_mode
Scheduling strategy.
SmartIF< ISvcLocator > & serviceLocator() const override
Retrieve pointer to service locator.
Definition Service.cpp:336
StatusCode initialize() override
Definition Service.cpp:118

◆ isAsynchronous()

bool PrecedenceSvc::isAsynchronous ( const std::string & name) const
inlineoverride

Check if a task is asynchronous.

Definition at line 61 of file PrecedenceSvc.h.

61 {
62 return m_PRGraph.getAlgorithmNode( name )->isAsynchronous();
63 }

◆ iterate()

StatusCode PrecedenceSvc::iterate ( EventSlot & slot,
const Cause & cause )
override

Infer the precedence effect caused by an execution flow event.

Definition at line 225 of file PrecedenceSvc.cpp.

225 {
226
227 if ( Cause::source::Task == cause.m_source ) {
228 ON_VERBOSE verbose() << "Triggering bottom-up traversal at node '" << cause.m_sourceName << "'" << endmsg;
229 auto visitor = concurrency::DecisionUpdater( slot, cause, m_dumpPrecTrace );
230 m_PRGraph.getAlgorithmNode( cause.m_sourceName )->accept( visitor );
231 } else {
232 ON_VERBOSE verbose() << "Triggering top-down traversal at the root node" << endmsg;
233 auto visitor = concurrency::Supervisor( slot, cause, m_dumpPrecTrace );
234 m_PRGraph.getHeadNode()->accept( visitor );
235 }
236
237 if ( m_dumpPrecTrace )
238 if ( CFRulesResolved( slot.parentSlot ? *slot.parentSlot : slot ) )
239 dumpPrecedenceTrace( slot.parentSlot ? *slot.parentSlot : slot );
240
241 if ( m_dumpPrecRules )
242 if ( CFRulesResolved( slot.parentSlot ? *slot.parentSlot : slot ) )
243 dumpPrecedenceRules( slot.parentSlot ? *slot.parentSlot : slot );
244
245 return StatusCode::SUCCESS;
246}
#define ON_VERBOSE
MsgStream & verbose() const
shortcut for the method msgStream(MSG::VERBOSE)
void dumpPrecedenceRules(const EventSlot &) override
Dump precedence rules (available only in DEBUG mode, and must be enabled with the corresponding servi...
bool CFRulesResolved(EventSlot &) const override
Check if the root CF decision is resolved.
void dumpPrecedenceTrace(const EventSlot &) override
Dump precedence trace (available only in DEBUG mode, and must be enabled with the corresponding servi...
std::string m_sourceName
EventSlot * parentSlot
Pointer to parent slot (null for top level).
Definition EventSlot.h:100

◆ printState()

const std::string PrecedenceSvc::printState ( EventSlot & slot) const
override

Definition at line 311 of file PrecedenceSvc.cpp.

311 {
312
313 std::stringstream ss;
314 m_PRGraph.printState( ss, slot, 0 );
315 return ss.str();
316}

◆ simulate()

StatusCode PrecedenceSvc::simulate ( EventSlot & slot) const
override

Simulate execution flow.

Definition at line 249 of file PrecedenceSvc.cpp.

249 {
250
251 Cause cs = { Cause::source::Root, "RootDecisionHub" };
252 auto visitor = concurrency::RunSimulator( slot, cs );
253
254 auto& nodeDecisions = slot.controlFlowState;
255
256 std::vector<int> prevNodeDecisions;
257 int cntr = 0;
258 std::vector<int> counters;
259
260 while ( !CFRulesResolved( slot ) ) {
261 cntr += 1;
262 int prevAlgosNum = visitor.m_nodesSucceeded;
263 ON_DEBUG debug() << " Proceeding with iteration #" << cntr << endmsg;
264 prevNodeDecisions = slot.controlFlowState;
265 m_PRGraph.getHeadNode()->accept( visitor );
266 if ( prevNodeDecisions == nodeDecisions ) {
267 error() << " No progress on iteration " << cntr << " detected, node decisions are:" << nodeDecisions << endmsg;
268 return StatusCode::FAILURE;
269 }
270 info() << " Iteration #" << cntr << " finished, total algorithms executed: " << visitor.m_nodesSucceeded
271 << endmsg;
272
273 std::stringstream s;
274 s << cntr << ", " << ( visitor.m_nodesSucceeded - prevAlgosNum ) << "\n";
275
276 std::ofstream myfile;
277 myfile.open( "RunSimulation.csv", std::ios::app );
278 myfile << s.str();
279 myfile.close();
280
281 if ( visitor.m_nodesSucceeded != prevAlgosNum ) counters.push_back( visitor.m_nodesSucceeded );
282 }
283
284 info() << "Asymptotical intra-event speedup: " << (float)visitor.m_nodesSucceeded / (float)counters.size() << endmsg;
285
286 // Reset algorithm states and node decisions
287 slot.algsStates.reset();
288 nodeDecisions.assign( nodeDecisions.size(), -1 );
289
290 return StatusCode::SUCCESS;
291}
AlgsExecutionStates algsStates
Vector of algorithms states.
Definition EventSlot.h:89

Member Data Documentation

◆ m_algResourcePool

SmartIF<IAlgResourcePool> PrecedenceSvc::m_algResourcePool
private

A shortcut to the algorithm resource pool.

Definition at line 85 of file PrecedenceSvc.h.

◆ m_dumpDirName

std::filesystem::path PrecedenceSvc::m_dumpDirName
private

Precedence analysis facilities.

Definition at line 93 of file PrecedenceSvc.h.

◆ m_dumpPrecRules

Gaudi::Property<bool> PrecedenceSvc::m_dumpPrecRules { this, "DumpPrecedenceRules", false, "Dump task precedence rules." }
private

Definition at line 101 of file PrecedenceSvc.h.

101{ this, "DumpPrecedenceRules", false, "Dump task precedence rules." };

◆ m_dumpPrecRulesFile

Gaudi::Property<std::string> PrecedenceSvc::m_dumpPrecRulesFile
private
Initial value:
{ this, "PrecedenceRulesFile", "",
"Override default name of the GRAPHML precedence rules file." }

Definition at line 102 of file PrecedenceSvc.h.

102 { this, "PrecedenceRulesFile", "",
103 "Override default name of the GRAPHML precedence rules file." };

◆ m_dumpPrecTrace

Gaudi::Property<bool> PrecedenceSvc::m_dumpPrecTrace
private
Initial value:
{ this, "DumpPrecedenceTrace", false,
"Dump task precedence traces for each event." }

Definition at line 94 of file PrecedenceSvc.h.

94 { this, "DumpPrecedenceTrace", false,
95 "Dump task precedence traces for each event." };

◆ m_dumpPrecTraceFile

Gaudi::Property<std::string> PrecedenceSvc::m_dumpPrecTraceFile
private
Initial value:
{
this, "PrecedenceTraceFile", "",
"Override default name of the GRAPHML trace file. NOTE: if more than "
"1 event is processed, the setting forces creation of a single file "
"with cumulative precedence trace." }

Definition at line 96 of file PrecedenceSvc.h.

96 {
97 this, "PrecedenceTraceFile", "",
98 "Override default name of the GRAPHML trace file. NOTE: if more than "
99 "1 event is processed, the setting forces creation of a single file "
100 "with cumulative precedence trace." };

◆ m_ignoreDFRules

Gaudi::Property<bool> PrecedenceSvc::m_ignoreDFRules { this, "IgnoreDFRules", false, "Ignore the data flow rules." }
private

Scheduling strategy.

Definition at line 91 of file PrecedenceSvc.h.

91{ this, "IgnoreDFRules", false, "Ignore the data flow rules." };

◆ m_mode

Gaudi::Property<std::string> PrecedenceSvc::m_mode { this, "TaskPriorityRule", "", "Task avalanche induction strategy." }
private

Scheduling strategy.

Definition at line 89 of file PrecedenceSvc.h.

89{ this, "TaskPriorityRule", "", "Task avalanche induction strategy." };

◆ m_PRGraph

concurrency::PrecedenceRulesGraph PrecedenceSvc::m_PRGraph { "PrecedenceRulesGraph", serviceLocator() }
private

Graph of precedence rules.

Definition at line 87 of file PrecedenceSvc.h.

87{ "PrecedenceRulesGraph", serviceLocator() };

◆ m_showDataFlow

Gaudi::Property<bool> PrecedenceSvc::m_showDataFlow
private
Initial value:
{ this, "ShowDataFlow", false,
"Show the configuration of DataFlow between Algorithms" }

Definition at line 106 of file PrecedenceSvc.h.

106 { this, "ShowDataFlow", false,
107 "Show the configuration of DataFlow between Algorithms" };

◆ m_verifyRules

Gaudi::Property<bool> PrecedenceSvc::m_verifyRules
private
Initial value:
{ this, "VerifyTaskPrecedenceRules", true,
"Verify task precedence rules for common errors." }

Definition at line 104 of file PrecedenceSvc.h.

104 { this, "VerifyTaskPrecedenceRules", true,
105 "Verify task precedence rules for common errors." };

The documentation for this class was generated from the following files: