The Gaudi Framework  v31r0 (aeb156f0)
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. More...
 
StatusCode initialize () override
 Initialize. More...
 
StatusCode finalize () override
 Finalize. More...
 
StatusCode iterate (EventSlot &, const Cause &) override
 Infer the precedence effect caused by an execution flow event. More...
 
StatusCode simulate (EventSlot &) const override
 Simulate execution flow. More...
 
bool CFRulesResolved (EventSlot &) const override
 Check if the root CF decision is resolved. More...
 
uint getPriority (const std::string &name) const override
 Get priority of an algorithm. More...
 
bool isBlocking (const std::string &name) const override
 Check if a task is CPU-blocking. More...
 
void dumpControlFlow () const override
 Dump precedence rules. More...
 
void dumpDataFlow () const override
 
const std::string printState (EventSlot &) const override
 
void dumpPrecedenceRules (EventSlot &) override
 Dump precedence rules (available only in DEBUG mode, and must be enabled with the corresponding service property) More...
 
void dumpPrecedenceTrace (EventSlot &) override
 Dump precedence trace (available only in DEBUG mode, and must be enabled with the corresponding service property) More...
 
const concurrency::PrecedenceRulesGraphgetRules () const
 Precedence rules accessor. More...
 
- Public Member Functions inherited from extends< Service, IPrecedenceSvc >
void * i_cast (const InterfaceID &tid) const override
 Implementation of IInterface::i_cast. More...
 
StatusCode queryInterface (const InterfaceID &ti, void **pp) override
 Implementation of IInterface::queryInterface. More...
 
std::vector< std::stringgetInterfaceNames () const override
 Implementation of IInterface::getInterfaceNames. More...
 
- Public Member Functions inherited from Service
const std::stringname () const override
 Retrieve name of the service. More...
 
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. More...
 
StatusCode sysStart () override
 Initialize Service. More...
 
StatusCode sysStop () override
 Initialize Service. More...
 
StatusCode sysFinalize () override
 Finalize Service. More...
 
StatusCode sysReinitialize () override
 Re-initialize the Service. More...
 
StatusCode sysRestart () override
 Re-initialize the Service. More...
 
 Service (std::string name, ISvcLocator *svcloc)
 Standard Constructor. More...
 
SmartIF< ISvcLocator > & serviceLocator () const override
 Retrieve pointer to service locator. More...
 
StatusCode setProperties ()
 Method for setting declared properties to the values specified for the job. More...
 
template<class T >
StatusCode service (const std::string &name, const T *&psvc, bool createIf=true) const
 Access a service by name, creating it if it doesn't already exist. More...
 
template<class T >
StatusCode service (const std::string &name, T *&psvc, bool createIf=true) const
 
template<typename IFace = IService>
SmartIF< IFace > service (const std::string &name, bool createIf=true) const
 
template<class T >
StatusCode service (const std::string &svcType, const std::string &svcName, T *&psvc) const
 Access a service by name and type, creating it if it doesn't already exist. More...
 
template<class T >
StatusCode declareTool (ToolHandle< T > &handle, std::string toolTypeAndName, bool createIf=true)
 Declare used tool. More...
 
SmartIF< IAuditorSvc > & auditorSvc () const
 The standard auditor service.May not be invoked before sysInitialize() has been invoked. More...
 
- Public Member Functions inherited from PropertyHolder< CommonMessaging< implements< IService, IProperty, IStateful > > >
 PropertyHolder ()=default
 
Gaudi::Details::PropertyBasedeclareProperty (Gaudi::Details::PropertyBase &prop)
 Declare a property. More...
 
Gaudi::Details::PropertyBasedeclareProperty (const std::string &name, TYPE &value, const std::string &doc="none")
 Helper to wrap a regular data member and use it as a regular property. More...
 
Gaudi::Details::PropertyBasedeclareProperty (const std::string &name, Gaudi::Property< TYPE, VERIFIER, HANDLERS > &prop, const std::string &doc="none")
 Declare a PropertyBase instance setting name and documentation. More...
 
Gaudi::Details::PropertyBasedeclareRemoteProperty (const std::string &name, IProperty *rsvc, const std::string &rname="")
 Declare a remote property. More...
 
StatusCode setProperty (const Gaudi::Details::PropertyBase &p) override
 set the property form another property More...
 
StatusCode setProperty (const std::string &s) override
 set the property from the formatted string More...
 
StatusCode setProperty (const std::string &n, const std::string &v) override
 set the property from name and the value More...
 
StatusCode setProperty (const std::string &name, const TYPE &value)
 set the property form the value More...
 
StatusCode getProperty (Gaudi::Details::PropertyBase *p) const override
 get the property More...
 
const Gaudi::Details::PropertyBasegetProperty (const std::string &name) const override
 get the property by name More...
 
StatusCode getProperty (const std::string &n, std::string &v) const override
 convert the property to the string More...
 
const std::vector< Gaudi::Details::PropertyBase * > & getProperties () const override
 get all properties More...
 
bool hasProperty (const std::string &name) const override
 Return true if we have a property with the given name. More...
 
 PropertyHolder (const PropertyHolder &)=delete
 
PropertyHolderoperator= (const PropertyHolder &)=delete
 
- Public Member Functions inherited from CommonMessaging< implements< IService, IProperty, IStateful > >
MSG::Level msgLevel () const
 get the cached level (originally extracted from the embedded MsgStream) More...
 
bool msgLevel (MSG::Level lvl) const
 get the output level from the embedded MsgStream More...
 
MSG::Level outputLevel () const
 Backward compatibility function for getting the output level. More...
 
- Public Member Functions inherited from CommonMessagingBase
virtual ~CommonMessagingBase ()=default
 Virtual destructor. More...
 
const SmartIF< IMessageSvc > & msgSvc () const
 The standard message service. More...
 
MsgStreammsgStream () const
 Return an uninitialized MsgStream. More...
 
MsgStreammsgStream (const MSG::Level level) const
 Predefined configurable message stream for the efficient printouts. More...
 
MsgStreamalways () const
 shortcut for the method msgStream(MSG::ALWAYS) More...
 
MsgStreamfatal () const
 shortcut for the method msgStream(MSG::FATAL) More...
 
MsgStreamerr () const
 shortcut for the method msgStream(MSG::ERROR) More...
 
MsgStreamerror () const
 shortcut for the method msgStream(MSG::ERROR) More...
 
MsgStreamwarning () const
 shortcut for the method msgStream(MSG::WARNING) More...
 
MsgStreaminfo () const
 shortcut for the method msgStream(MSG::INFO) More...
 
MsgStreamdebug () const
 shortcut for the method msgStream(MSG::DEBUG) More...
 
MsgStreamverbose () const
 shortcut for the method msgStream(MSG::VERBOSE) More...
 
MsgStreammsg () const
 shortcut for the method msgStream(MSG::INFO) More...
 

Private Member Functions

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

Private Attributes

SmartIF< IAlgResourcePoolm_algResourcePool
 A shortcut to the algorithm resource pool. More...
 
concurrency::PrecedenceRulesGraph m_PRGraph {"PrecedenceRulesGraph", serviceLocator()}
 Graph of precedence rules. More...
 
Gaudi::Property< std::stringm_mode {this, "TaskPriorityRule", "", "Task avalanche induction strategy."}
 Scheduling strategy. More...
 
Gaudi::Property< bool > m_ignoreDFRules {this, "IgnoreDFRules", false, "Ignore the data flow rules."}
 Scheduling strategy. More...
 
boost::filesystem::path m_dumpDirName
 Precedence analysis facilities. More...
 
Gaudi::Property< bool > m_dumpPrecTrace
 
Gaudi::Property< std::stringm_dumpPrecTraceFile
 
Gaudi::Property< bool > m_dumpPrecRules {this, "DumpPrecedenceRules", false, "Dump task precedence rules."}
 
Gaudi::Property< std::stringm_dumpPrecRulesFile
 

Additional Inherited Members

- Public Types inherited from extends< Service, IPrecedenceSvc >
using base_class = extends
 Typedef to this class. More...
 
using extend_interfaces_base = extend_interfaces< Interfaces... >
 Typedef to the base of this class. More...
 
- 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 = PropertyHolder< CommonMessaging< implements< IService, IProperty, IStateful > > >
 Typedef used to refer to this class from derived classes, as in. More...
 
- Public Types inherited from CommonMessaging< implements< IService, IProperty, IStateful > >
using base_class = CommonMessaging
 
- Public Types inherited from extend_interfaces< Interfaces... >
using ext_iids = typename Gaudi::interface_list_cat< typename Interfaces::ext_iids... >::type
 take union of the ext_iids of all Interfaces... More...
 
- Protected Member Functions inherited from Service
 ~Service () override
 Standard Destructor. More...
 
int outputLevel () const
 get the Service's output level More...
 
- Protected Member Functions inherited from PropertyHolder< CommonMessaging< implements< IService, IProperty, IStateful > > >
Gaudi::Details::PropertyBaseproperty (const std::string &name) const
 
- Protected Member Functions inherited from CommonMessaging< implements< IService, IProperty, IStateful > >
MSG::Level setUpMessaging () const
 Set up local caches. More...
 
MSG::Level resetMessaging ()
 Reinitialize internal states. More...
 
void updateMsgStreamOutputLevel (int level)
 Update the output level of the cached MsgStream. More...
 
- Protected Attributes inherited from Service
Gaudi::StateMachine::State m_state = Gaudi::StateMachine::OFFLINE
 Service state. More...
 
Gaudi::StateMachine::State m_targetState = Gaudi::StateMachine::OFFLINE
 Service state. More...
 
Gaudi::Property< int > m_outputLevel {this, "OutputLevel", MSG::NIL, "output level"}
 
Gaudi::Property< bool > m_auditInit {this, "AuditServices", false, "[[deprecated]] unused"}
 
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()"}
 
SmartIF< IAuditorSvcm_pAuditorSvc
 Auditor Service. More...
 

Detailed Description

A service to resolve the task execution precedence.

Author
Illya Shapoval Aug 7, 2017

Definition at line 21 of file PrecedenceSvc.h.

Constructor & Destructor Documentation

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

Constructor.

Definition at line 25 of file PrecedenceSvc.h.

25 : base_class( name, svcLoc ) {}
extends base_class
Typedef to this class.
Definition: extends.h:14

Member Function Documentation

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

Definition at line 103 of file PrecedenceSvc.cpp.

104  {
105  using namespace concurrency;
106 
108 
109  ++recursionDepth;
110 
111  bool isGaudiSequencer( false );
112  bool isAthSequencer( false );
113 
114  if ( !algo->isSequence() ) {
115  ON_DEBUG debug() << std::string( recursionDepth, ' ' ) << "Algorithm '" << algo->name() << "' discovered" << endmsg;
116  sc = m_PRGraph.addAlgorithmNode( algo, parentName, false, false );
117  return sc;
118  } else {
119  if ( algo->hasProperty( "ShortCircuit" ) )
120  isGaudiSequencer = true;
121  else if ( algo->hasProperty( "StopOverride" ) )
122  isAthSequencer = true;
123  }
124 
125  auto seq = dynamic_cast<Gaudi::Sequence*>( algo );
126  if ( seq == 0 ) {
127  error() << "Algorithm " << algo->name() << " has isSequence==true, but unable to dcast to Sequence" << endmsg;
128  return StatusCode::FAILURE;
129  }
130 
131  auto subAlgorithms = seq->subAlgorithms();
132 
133  // Recursively unroll
134  ON_DEBUG debug() << std::string( recursionDepth, ' ' ) << "Decision hub '" << algo->name() << "' discovered"
135  << endmsg;
136  bool modeOr = false;
137  bool allPass = false;
138  bool promptDecision = false;
139  bool isSequential = false;
140  bool isInverted = false;
141 
142  if ( isGaudiSequencer ) {
143  modeOr = ( algo->getProperty( "ModeOR" ).toString() == "True" );
144  allPass = ( algo->getProperty( "IgnoreFilterPassed" ).toString() == "True" );
145  promptDecision = ( algo->getProperty( "ShortCircuit" ).toString() == "True" );
146  isInverted = ( algo->getProperty( "Invert" ).toString() == "True" );
147  if ( allPass ) promptDecision = false; // standard GaudiSequencer behavior on all pass is to execute everything
148  isSequential = ( algo->hasProperty( "Sequential" ) && ( algo->getProperty( "Sequential" ).toString() == "True" ) );
149  } else if ( isAthSequencer ) {
150  modeOr = ( algo->getProperty( "ModeOR" ).toString() == "True" );
151  allPass = ( algo->getProperty( "IgnoreFilterPassed" ).toString() == "True" );
152  promptDecision = ( algo->getProperty( "StopOverride" ).toString() == "False" );
153  isSequential = ( algo->hasProperty( "Sequential" ) && ( algo->getProperty( "Sequential" ).toString() == "True" ) );
154  }
155  sc = m_PRGraph.addDecisionHubNode( algo, parentName, Concurrent{!isSequential}, PromptDecision{promptDecision},
156  ModeOr{modeOr}, AllPass{allPass}, Inverted{isInverted} );
157  if ( sc.isFailure() ) {
158  error() << "Failed to add DecisionHub " << algo->name() << " to graph of precedence rules" << endmsg;
159  return sc;
160  }
161 
162  for ( auto subalgo : *subAlgorithms ) {
163  sc = assembleCFRules( subalgo, algo->name(), recursionDepth );
164  if ( sc.isFailure() ) {
165  error() << "Algorithm " << subalgo->name() << " could not be flattened" << endmsg;
166  return sc;
167  }
168  }
169  return sc;
170 }
StatusCode getProperty(Gaudi::Details::PropertyBase *p) const override
get the property
concurrency::PrecedenceRulesGraph m_PRGraph
Graph of precedence rules.
Definition: PrecedenceSvc.h:72
StatusCode assembleCFRules(Gaudi::Algorithm *, const std::string &, unsigned int recursionDepth=0)
const std::string & name() const override
The identifying name of the algorithm object.
Definition: Algorithm.cpp:635
StatusCode addAlgorithmNode(Gaudi::Algorithm *daughterAlgo, const std::string &parentName, bool inverted, bool allPass)
Add algorithm node.
bool isSequence() const override
Are we a Sequence?
Definition: Algorithm.h:208
bool hasProperty(const std::string &name) const override
Return true if we have a property with the given name.
constexpr static const auto SUCCESS
Definition: StatusCode.h:85
#define ON_DEBUG
bool isFailure() const
Definition: StatusCode.h:130
Gaudi::tagged_bool< class ModeOr_tag > ModeOr
STL class.
MsgStream & error() const
shortcut for the method msgStream(MSG::ERROR)
Gaudi::tagged_bool< class Inverted_tag > Inverted
This class is used for returning status codes from appropriate routines.
Definition: StatusCode.h:50
Gaudi::tagged_bool< class Concurrent_tag > Concurrent
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.
Gaudi::tagged_bool< class PromptDecision_tag > PromptDecision
MsgStream & debug() const
shortcut for the method msgStream(MSG::DEBUG)
Gaudi::tagged_bool< class AllPass_tag > AllPass
constexpr static const auto FAILURE
Definition: StatusCode.h:86
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition: MsgStream.h:192
bool PrecedenceSvc::CFRulesResolved ( EventSlot slot) const
override

Check if the root CF decision is resolved.

Definition at line 242 of file PrecedenceSvc.cpp.

242  {
243  return ( -1 != slot.controlFlowState[m_PRGraph.getHeadNode()->getNodeIndex()] ? true : false );
244 }
concurrency::PrecedenceRulesGraph m_PRGraph
Graph of precedence rules.
Definition: PrecedenceSvc.h:72
std::vector< int > controlFlowState
State of the control flow.
Definition: EventSlot.h:77
const unsigned int & getNodeIndex() const
Get node index.
DecisionNode * getHeadNode() const
Get head node.
void PrecedenceSvc::dumpControlFlow ( ) const
override

Dump precedence rules.

Definition at line 247 of file PrecedenceSvc.cpp.

247  {
248 
249  info() << std::endl << "==================== Control Flow Configuration ==================" << std::endl << std::endl;
251 }
concurrency::PrecedenceRulesGraph m_PRGraph
Graph of precedence rules.
Definition: PrecedenceSvc.h:72
MsgStream & info() const
shortcut for the method msgStream(MSG::INFO)
T endl(T...args)
std::string dumpControlFlow() const
Print out control flow of Algorithms and Sequences.
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition: MsgStream.h:192
void PrecedenceSvc::dumpDataFlow ( ) const
override

Definition at line 253 of file PrecedenceSvc.cpp.

253  {
254  info() << std::endl << "===================== Data Flow Configuration ====================" << std::endl;
255  info() << m_PRGraph.dumpDataFlow() << endmsg;
256 }
concurrency::PrecedenceRulesGraph m_PRGraph
Graph of precedence rules.
Definition: PrecedenceSvc.h:72
MsgStream & info() const
shortcut for the method msgStream(MSG::INFO)
T endl(T...args)
std::string dumpDataFlow() const
Print out all data origins and destinations, as reflected in the EF graph.
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition: MsgStream.h:192
void PrecedenceSvc::dumpPrecedenceRules ( EventSlot slot)
override

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

Definition at line 267 of file PrecedenceSvc.cpp.

267  {
268 
269  if ( !m_dumpPrecRules ) {
270  warning() << "To trace temporal and topological aspects of execution flow, "
271  << "set DumpPrecedenceRules property to True " << endmsg;
272  return;
273  }
274 
275  ON_DEBUG debug() << "Dumping temporal precedence rules" << endmsg;
276 
277  std::string fileName;
278  if ( m_dumpPrecRulesFile.empty() ) {
279  const auto& eventID = slot.eventContext->eventID();
280  fileName = "rules.evt-" + std::to_string( eventID.event_number() ) + "." + "run-" +
281  std::to_string( eventID.run_number() ) + ".graphml";
282  } else {
283  fileName = m_dumpPrecRulesFile;
284  }
285 
287  pth.append( fileName );
288 
289  m_PRGraph.dumpPrecRules( pth, slot );
290 }
concurrency::PrecedenceRulesGraph m_PRGraph
Graph of precedence rules.
Definition: PrecedenceSvc.h:72
void dumpPrecRules(const boost::filesystem::path &, const EventSlot &slot)
dump to file the precedence rules
T to_string(T...args)
boost::filesystem::path m_dumpDirName
Precedence analysis facilities.
Definition: PrecedenceSvc.h:78
#define ON_DEBUG
STL class.
Gaudi::Property< std::string > m_dumpPrecRulesFile
Definition: PrecedenceSvc.h:88
MsgStream & warning() const
shortcut for the method msgStream(MSG::WARNING)
MsgStream & debug() const
shortcut for the method msgStream(MSG::DEBUG)
Gaudi::Property< bool > m_dumpPrecRules
Definition: PrecedenceSvc.h:87
const EventIDBase & eventID() const
Definition: EventContext.h:52
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition: MsgStream.h:192
std::unique_ptr< EventContext > eventContext
Cache for the eventContext.
Definition: EventSlot.h:73
void PrecedenceSvc::dumpPrecedenceTrace ( EventSlot slot)
override

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

Definition at line 293 of file PrecedenceSvc.cpp.

293  {
294 
295  if ( !m_dumpPrecTrace ) {
296  warning() << "To trace task precedence patterns, set DumpPrecedenceTrace "
297  << "property to True " << endmsg;
298  return;
299  }
300 
301  ON_DEBUG debug() << "Dumping temporal precedence trace" << endmsg;
302 
303  std::string fileName;
304  if ( m_dumpPrecTraceFile.empty() ) {
305  const auto& eventID = slot.eventContext->eventID();
306  fileName = "trace.evt-" + std::to_string( eventID.event_number() ) + "." + "run-" +
307  std::to_string( eventID.run_number() ) + ".graphml";
308  } else {
309  fileName = m_dumpPrecTraceFile;
310  }
311 
313  pth.append( fileName );
314 
315  m_PRGraph.dumpPrecTrace( pth );
316 }
Gaudi::Property< bool > m_dumpPrecTrace
Definition: PrecedenceSvc.h:80
concurrency::PrecedenceRulesGraph m_PRGraph
Graph of precedence rules.
Definition: PrecedenceSvc.h:72
T to_string(T...args)
boost::filesystem::path m_dumpDirName
Precedence analysis facilities.
Definition: PrecedenceSvc.h:78
#define ON_DEBUG
STL class.
void dumpPrecTrace(const boost::filesystem::path &)
dump to file the precedence trace
MsgStream & warning() const
shortcut for the method msgStream(MSG::WARNING)
MsgStream & debug() const
shortcut for the method msgStream(MSG::DEBUG)
Gaudi::Property< std::string > m_dumpPrecTraceFile
Definition: PrecedenceSvc.h:82
const EventIDBase & eventID() const
Definition: EventContext.h:52
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition: MsgStream.h:192
std::unique_ptr< EventContext > eventContext
Cache for the eventContext.
Definition: EventSlot.h:73
StatusCode PrecedenceSvc::finalize ( )
override

Finalize.

Definition at line 321 of file PrecedenceSvc.cpp.

321 { return Service::finalize(); }
StatusCode finalize() override
Definition: Service.cpp:164
uint PrecedenceSvc::getPriority ( const std::string name) const
inlineoverride

Get priority of an algorithm.

Definition at line 43 of file PrecedenceSvc.h.

43  {
44  return (int)m_PRGraph.getAlgorithmNode( name )->getRank();
45  }
concurrency::PrecedenceRulesGraph m_PRGraph
Graph of precedence rules.
Definition: PrecedenceSvc.h:72
const float & getRank() const
Get Algorithm rank.
AlgorithmNode * getAlgorithmNode(const std::string &algoName) const
Get the AlgorithmNode from by algorithm name using graph index.
const concurrency::PrecedenceRulesGraph* PrecedenceSvc::getRules ( ) const
inline

Precedence rules accessor.

Definition at line 63 of file PrecedenceSvc.h.

63 { return &m_PRGraph; };
concurrency::PrecedenceRulesGraph m_PRGraph
Graph of precedence rules.
Definition: PrecedenceSvc.h:72
StatusCode PrecedenceSvc::initialize ( )
override

Initialize.

Definition at line 16 of file PrecedenceSvc.cpp.

16  {
17  using namespace concurrency;
18 
19  auto sc = Service::initialize(); // parent class must be initialized first
20  if ( sc.isFailure() ) {
21  fatal() << "Base class failed to initialize" << endmsg;
22  return sc;
23  }
24 
25  // prepare a directory to dump precedence analysis files to.
27  if ( !boost::filesystem::create_directory( m_dumpDirName ) ) {
28  error() << "Could not create directory " << m_dumpDirName
29  << "required "
30  "for task precedence tracing"
31  << endmsg;
32  return StatusCode::FAILURE;
33  }
34  }
35 
37 
38  // Get the algo resource pool
39  m_algResourcePool = serviceLocator()->service( "AlgResourcePool" );
40  if ( !m_algResourcePool.isValid() ) {
41  fatal() << "Error retrieving AlgoResourcePool" << endmsg;
42  return StatusCode::FAILURE;
43  }
44 
45  info() << "Assembling CF and DF task precedence rules" << endmsg;
46 
47  ON_DEBUG debug() << "Assembling CF precedence realm:" << endmsg;
48  // create the root CF node
49  m_PRGraph.addHeadNode( "RootDecisionHub", Concurrent{true}, PromptDecision{false}, ModeOr{true}, AllPass{true},
50  Inverted{false} );
51  // assemble the CF rules
52  for ( const auto& ialgoPtr : m_algResourcePool->getTopAlgList() ) {
53  auto algorithm = dynamic_cast<Gaudi::Algorithm*>( ialgoPtr );
54  if ( !algorithm ) fatal() << "Conversion from IAlgorithm to Gaudi::Algorithm failed" << endmsg;
55  sc = assembleCFRules( algorithm, "RootDecisionHub" );
56  if ( sc.isFailure() ) {
57  fatal() << "Could not assemble the CF precedence realm" << endmsg;
58  return sc;
59  }
60  }
61 
62  if ( m_ignoreDFRules ) {
63  warning() << "Ignoring DF precedence rules, disabling all associated features" << endmsg;
64  return StatusCode::SUCCESS;
65  }
66 
67  ON_DEBUG debug() << "Assembling DF precedence realm:" << endmsg;
68  sc = m_PRGraph.initialize();
69  if ( sc.isFailure() ) {
70  fatal() << "Could not assemble the DF precedence realm" << endmsg;
71  return sc;
72  }
73 
74  // Rank algorithms if a prioritization rule is supplied
75  if ( m_mode == "PCE" ) {
77  m_PRGraph.rankAlgorithms( ranker );
78  } else if ( m_mode == "COD" ) {
80  m_PRGraph.rankAlgorithms( ranker );
81  } else if ( m_mode == "E" ) {
82  auto ranker = concurrency::RankerByEccentricity();
83  m_PRGraph.rankAlgorithms( ranker );
84  } else if ( m_mode == "T" ) {
85  auto ranker = concurrency::RankerByTiming();
86  m_PRGraph.rankAlgorithms( ranker );
87  } else if ( m_mode == "DRE" ) {
89  m_PRGraph.rankAlgorithms( ranker );
90  } else if ( !m_mode.empty() ) {
91  error() << "Requested prioritization rule '" << m_mode << "' is unknown" << endmsg;
92  return StatusCode::FAILURE;
93  }
94 
96 
97  if ( sc.isSuccess() ) info() << "PrecedenceSvc initialized successfully" << endmsg;
98 
99  return sc;
100 }
Gaudi::Property< bool > m_dumpPrecTrace
Definition: PrecedenceSvc.h:80
concurrency::PrecedenceRulesGraph m_PRGraph
Graph of precedence rules.
Definition: PrecedenceSvc.h:72
StatusCode initialize() override
Definition: Service.cpp:60
StatusCode assembleCFRules(Gaudi::Algorithm *, const std::string &, unsigned int recursionDepth=0)
MsgStream & info() const
shortcut for the method msgStream(MSG::INFO)
constexpr static const auto SUCCESS
Definition: StatusCode.h:85
boost::filesystem::path m_dumpDirName
Precedence analysis facilities.
Definition: PrecedenceSvc.h:78
#define ON_DEBUG
void rankAlgorithms(IGraphVisitor &ranker) const
Rank Algorithm nodes by the number of data outputs.
Gaudi::tagged_bool< class ModeOr_tag > ModeOr
Gaudi::Property< bool > m_ignoreDFRules
Scheduling strategy.
Definition: PrecedenceSvc.h:76
StatusCode service(const Gaudi::Utils::TypeNameString &name, T *&svc, bool createIf=true)
Templated method to access a service by name.
Definition: ISvcLocator.h:76
StatusCode initialize()
Initialize graph.
MsgStream & error() const
shortcut for the method msgStream(MSG::ERROR)
SmartIF< IAlgResourcePool > m_algResourcePool
A shortcut to the algorithm resource pool.
Definition: PrecedenceSvc.h:70
virtual std::list< IAlgorithm * > getTopAlgList()=0
Get top list of algorithms.
MsgStream & warning() const
shortcut for the method msgStream(MSG::WARNING)
Gaudi::tagged_bool< class Inverted_tag > Inverted
void enableAnalysis()
BGL-based facilities.
std::string dumpDataFlow() const
Print out all data origins and destinations, as reflected in the EF graph.
Gaudi::Property< std::string > m_mode
Scheduling strategy.
Definition: PrecedenceSvc.h:74
Gaudi::tagged_bool< class Concurrent_tag > Concurrent
Gaudi::tagged_bool< class PromptDecision_tag > PromptDecision
MsgStream & debug() const
shortcut for the method msgStream(MSG::DEBUG)
bool isValid() const
Allow for check if smart pointer is valid.
Definition: SmartIF.h:62
Gaudi::Property< bool > m_dumpPrecRules
Definition: PrecedenceSvc.h:87
Base class from which all concrete algorithm classes should be derived.
Definition: Algorithm.h:79
Gaudi::tagged_bool< class AllPass_tag > AllPass
constexpr static const auto FAILURE
Definition: StatusCode.h:86
MsgStream & fatal() const
shortcut for the method msgStream(MSG::FATAL)
SmartIF< ISvcLocator > & serviceLocator() const override
Retrieve pointer to service locator.
Definition: Service.cpp:277
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition: MsgStream.h:192
void addHeadNode(const std::string &headName, concurrency::Concurrent, concurrency::PromptDecision, concurrency::ModeOr, concurrency::AllPass, concurrency::Inverted)
Add a node, which has no parents.
bool PrecedenceSvc::isBlocking ( const std::string name) const
inlineoverride

Check if a task is CPU-blocking.

Definition at line 48 of file PrecedenceSvc.h.

48 { return m_PRGraph.getAlgorithmNode( name )->isIOBound(); }
concurrency::PrecedenceRulesGraph m_PRGraph
Graph of precedence rules.
Definition: PrecedenceSvc.h:72
bool isIOBound() const
Check if algorithm is I/O-bound.
AlgorithmNode * getAlgorithmNode(const std::string &algoName) const
Get the AlgorithmNode from by algorithm name using graph index.
StatusCode PrecedenceSvc::iterate ( EventSlot slot,
const Cause cause 
)
override

Infer the precedence effect caused by an execution flow event.

Definition at line 173 of file PrecedenceSvc.cpp.

173  {
174 
175  if ( LIKELY( Cause::source::Task == cause.m_source ) ) {
176  ON_VERBOSE verbose() << "Triggering bottom-up traversal at node '" << cause.m_sourceName << "'" << endmsg;
177  auto visitor = concurrency::DecisionUpdater( slot, cause, m_dumpPrecTrace );
178  m_PRGraph.getAlgorithmNode( cause.m_sourceName )->accept( visitor );
179  } else {
180  ON_VERBOSE verbose() << "Triggering top-down traversal at the root node" << endmsg;
181  auto visitor = concurrency::Supervisor( slot, cause, m_dumpPrecTrace );
182  m_PRGraph.getHeadNode()->accept( visitor );
183  }
184 
185  if ( UNLIKELY( m_dumpPrecTrace ) )
186  if ( UNLIKELY( CFRulesResolved( slot.parentSlot ? *slot.parentSlot : slot ) ) )
187  dumpPrecedenceTrace( slot.parentSlot ? *slot.parentSlot : slot );
188 
189  if ( UNLIKELY( m_dumpPrecRules ) )
190  if ( UNLIKELY( CFRulesResolved( slot.parentSlot ? *slot.parentSlot : slot ) ) )
191  dumpPrecedenceRules( slot.parentSlot ? *slot.parentSlot : slot );
192 
193  return StatusCode::SUCCESS;
194 }
#define UNLIKELY(x)
Definition: Kernel.h:89
Gaudi::Property< bool > m_dumpPrecTrace
Definition: PrecedenceSvc.h:80
concurrency::PrecedenceRulesGraph m_PRGraph
Graph of precedence rules.
Definition: PrecedenceSvc.h:72
void dumpPrecedenceRules(EventSlot &) override
Dump precedence rules (available only in DEBUG mode, and must be enabled with the corresponding servi...
MsgStream & verbose() const
shortcut for the method msgStream(MSG::VERBOSE)
constexpr static const auto SUCCESS
Definition: StatusCode.h:85
bool accept(IGraphVisitor &visitor) override
Visitor entry point.
#define ON_VERBOSE
void dumpPrecedenceTrace(EventSlot &) override
Dump precedence trace (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.
#define LIKELY(x)
Definition: Kernel.h:88
Gaudi::Property< bool > m_dumpPrecRules
Definition: PrecedenceSvc.h:87
EventSlot * parentSlot
Pointer to parent slot (null for top level)
Definition: EventSlot.h:86
bool accept(IGraphVisitor &visitor) override
Visitor entry point.
AlgorithmNode * getAlgorithmNode(const std::string &algoName) const
Get the AlgorithmNode from by algorithm name using graph index.
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition: MsgStream.h:192
std::string m_sourceName
DecisionNode * getHeadNode() const
Get head node.
const std::string PrecedenceSvc::printState ( EventSlot slot) const
override

Definition at line 259 of file PrecedenceSvc.cpp.

259  {
260 
262  m_PRGraph.printState( ss, slot.algsStates, slot.controlFlowState, 0 );
263  return ss.str();
264 }
concurrency::PrecedenceRulesGraph m_PRGraph
Graph of precedence rules.
Definition: PrecedenceSvc.h:72
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< int > controlFlowState
State of the control flow.
Definition: EventSlot.h:77
T str(T...args)
AlgsExecutionStates algsStates
Vector of algorithms states.
Definition: EventSlot.h:75
StatusCode PrecedenceSvc::simulate ( EventSlot slot) const
override

Simulate execution flow.

Definition at line 197 of file PrecedenceSvc.cpp.

197  {
198 
199  Cause cs = {Cause::source::Root, "RootDecisionHub"};
200  auto visitor = concurrency::RunSimulator( slot, cs );
201 
202  auto& nodeDecisions = slot.controlFlowState;
203 
204  std::vector<int> prevNodeDecisions;
205  int cntr = 0;
206  std::vector<int> counters;
207 
208  while ( !CFRulesResolved( slot ) ) {
209  cntr += 1;
210  int prevAlgosNum = visitor.m_nodesSucceeded;
211  ON_DEBUG debug() << " Proceeding with iteration #" << cntr << endmsg;
212  prevNodeDecisions = slot.controlFlowState;
213  m_PRGraph.getHeadNode()->accept( visitor );
214  if ( prevNodeDecisions == nodeDecisions ) {
215  error() << " No progress on iteration " << cntr << " detected, node decisions are:" << nodeDecisions << endmsg;
216  return StatusCode::FAILURE;
217  }
218  info() << " Iteration #" << cntr << " finished, total algorithms executed: " << visitor.m_nodesSucceeded
219  << endmsg;
220 
222  s << cntr << ", " << ( visitor.m_nodesSucceeded - prevAlgosNum ) << "\n";
223 
224  std::ofstream myfile;
225  myfile.open( "RunSimulation.csv", std::ios::app );
226  myfile << s.str();
227  myfile.close();
228 
229  if ( visitor.m_nodesSucceeded != prevAlgosNum ) counters.push_back( visitor.m_nodesSucceeded );
230  }
231 
232  info() << "Asymptotical intra-event speedup: " << (float)visitor.m_nodesSucceeded / (float)counters.size() << endmsg;
233 
234  // Reset algorithm states and node decisions
235  slot.algsStates.reset();
236  nodeDecisions.assign( nodeDecisions.size(), -1 );
237 
238  return StatusCode::SUCCESS;
239 }
concurrency::PrecedenceRulesGraph m_PRGraph
Graph of precedence rules.
Definition: PrecedenceSvc.h:72
T open(T...args)
MsgStream & info() const
shortcut for the method msgStream(MSG::INFO)
constexpr static const auto SUCCESS
Definition: StatusCode.h:85
std::vector< int > controlFlowState
State of the control flow.
Definition: EventSlot.h:77
#define ON_DEBUG
bool accept(IGraphVisitor &visitor) override
Visitor entry point.
T push_back(T...args)
MsgStream & error() const
shortcut for the method msgStream(MSG::ERROR)
STL class.
T str(T...args)
bool CFRulesResolved(EventSlot &) const override
Check if the root CF decision is resolved.
T size(T...args)
MsgStream & debug() const
shortcut for the method msgStream(MSG::DEBUG)
string s
Definition: gaudirun.py:312
constexpr static const auto FAILURE
Definition: StatusCode.h:86
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition: MsgStream.h:192
AlgsExecutionStates algsStates
Vector of algorithms states.
Definition: EventSlot.h:75
DecisionNode * getHeadNode() const
Get head node.

Member Data Documentation

SmartIF<IAlgResourcePool> PrecedenceSvc::m_algResourcePool
private

A shortcut to the algorithm resource pool.

Definition at line 70 of file PrecedenceSvc.h.

boost::filesystem::path PrecedenceSvc::m_dumpDirName
private
Initial value:
{
boost::filesystem::unique_path( boost::filesystem::path( "precedence.analysis.%%%%" ) )}

Precedence analysis facilities.

Definition at line 78 of file PrecedenceSvc.h.

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

Definition at line 87 of file PrecedenceSvc.h.

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

Definition at line 88 of file PrecedenceSvc.h.

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

Definition at line 80 of file PrecedenceSvc.h.

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 82 of file PrecedenceSvc.h.

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

Scheduling strategy.

Definition at line 76 of file PrecedenceSvc.h.

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

Scheduling strategy.

Definition at line 74 of file PrecedenceSvc.h.

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

Graph of precedence rules.

Definition at line 72 of file PrecedenceSvc.h.


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