The Gaudi Framework  v30r1 (5d4f4ae2)
concurrency::PrecedenceRulesGraph Class Reference

#include <src/PrecedenceRulesGraph.h>

Inheritance diagram for concurrency::PrecedenceRulesGraph:
Collaboration diagram for concurrency::PrecedenceRulesGraph:

Public Member Functions

 PrecedenceRulesGraph (const std::string &name, SmartIF< ISvcLocator > svc)
 Constructor. More...
 
 ~PrecedenceRulesGraph () override
 Destructor. More...
 
StatusCode initialize ()
 Initialize graph. More...
 
void accept (const std::string &algo_name, IGraphVisitor &visitor) const
 A method to update algorithm node decision, and propagate it upwards. More...
 
StatusCode addDataNode (const DataObjID &dataPath)
 Add DataNode that represents DataObject. More...
 
DataNodegetDataNode (const DataObjID &dataPath) const
 Get DataNode by DataObject path using graph index. More...
 
void registerIODataObjects (const Algorithm *algo)
 Register algorithm in the Data Dependency index. More...
 
StatusCode buildDataDependenciesRealm ()
 Build data dependency realm WITH data object nodes participating. More...
 
void addHeadNode (const std::string &headName, concurrency::Concurrent, concurrency::PromptDecision, concurrency::ModeOr, concurrency::AllPass, concurrency::Inverted)
 Add a node, which has no parents. More...
 
DecisionNodegetHeadNode () const
 Get head node. More...
 
StatusCode addAlgorithmNode (Algorithm *daughterAlgo, const std::string &parentName, bool inverted, bool allPass)
 Add algorithm node. More...
 
AlgorithmNodegetAlgorithmNode (const std::string &algoName) const
 Get the AlgorithmNode from by algorithm name using graph index. More...
 
StatusCode addDecisionHubNode (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. More...
 
unsigned int getControlFlowNodeCounter () const
 Get total number of control flow graph nodes. More...
 
void rankAlgorithms (IGraphVisitor &ranker) const
 Rank Algorithm nodes by the number of data outputs. More...
 
const std::stringname () const override
 Retrieve name of the service. More...
 
SmartIF< ISvcLocator > & serviceLocator () const override
 Retrieve pointer to service locator. More...
 
const std::chrono::system_clock::time_point getInitTime () const
 
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. More...
 
void enableAnalysis ()
 BGL-based facilities. More...
 
PRVertexDesc node (const std::string &) const
 
std::string dumpDataFlow () const
 Print out all data origins and destinations, as reflected in the EF graph. More...
 
std::string dumpControlFlow () const
 Print out control flow of Algorithms and Sequences. More...
 
void dumpPrecRules (const boost::filesystem::path &, const EventSlot &slot)
 dump to file the precedence rules More...
 
void dumpPrecTrace (const boost::filesystem::path &)
 dump to file the precedence trace More...
 
void addEdgeToPrecTrace (const AlgorithmNode *u, const AlgorithmNode *v)
 set cause-effect connection between two algorithms in the precedence trace More...
 
void dumpControlFlow (std::ostringstream &, ControlFlowNode *, const int &) const
 
- 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...
 
MSG::Level msgLevel () const
 get the cached level (originally extracted from the embedded MsgStream) More...
 
MSG::Level outputLevel () const __attribute__((deprecated))
 Backward compatibility function for getting the output level. More...
 
bool msgLevel (MSG::Level lvl) const
 get the output level from the embedded MsgStream More...
 

Private Attributes

DecisionNodem_headNode
 the head node of the control flow graph More...
 
AlgoNodesMap m_algoNameToAlgoNodeMap
 Index: map of algorithm's name to AlgorithmNode. More...
 
DecisionHubsMap m_decisionNameToDecisionHubMap
 Index: map of decision's name to DecisionHub. More...
 
DataNodesMap m_dataPathToDataNodeMap
 Index: map of data path to DataNode. More...
 
AlgoInputsMap m_algoNameToAlgoInputsMap
 Indexes: maps of algorithm's name to algorithm's inputs/outputs. More...
 
AlgoOutputsMap m_algoNameToAlgoOutputsMap
 
unsigned int m_nodeCounter
 Total number of nodes in the graph. More...
 
unsigned int m_algoCounter
 Total number of algorithm nodes in the graph. More...
 
SmartIF< ISvcLocatorm_svcLocator
 Service locator (needed to access the MessageSvc) More...
 
const std::string m_name
 
const std::chrono::system_clock::time_point m_initTime
 
precedence::PrecTrace m_precTrace
 facilities for algorithm precedence tracing More...
 
std::map< std::string, precedence::AlgoTraceVertexm_prec_trace_map
 
bool m_enableAnalysis {false}
 
precedence::PRGraph m_PRGraph
 BGL-based graph of precedence rules. More...
 
bool m_conditionsRealmEnabled {false}
 Enable conditions realm of precedence rules. More...
 

Additional Inherited Members

- Public Types inherited from CommonMessaging< IPrecedenceRulesGraph >
using base_class = CommonMessaging
 
- Protected Member Functions inherited from CommonMessaging< IPrecedenceRulesGraph >
MSG::Level setUpMessaging ()
 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...
 

Detailed Description

Definition at line 694 of file PrecedenceRulesGraph.h.

Constructor & Destructor Documentation

concurrency::PrecedenceRulesGraph::PrecedenceRulesGraph ( const std::string name,
SmartIF< ISvcLocator svc 
)
inline

Constructor.

Definition at line 698 of file PrecedenceRulesGraph.h.

699  : m_headNode( 0 )
700  , m_nodeCounter( 0 )
701  , m_algoCounter( 0 )
702  , m_svcLocator( svc )
703  , m_name( name )
705  {
706  // make sure that CommonMessaging is initialized
707  setUpMessaging();
708  }
const std::chrono::system_clock::time_point m_initTime
unsigned int m_algoCounter
Total number of algorithm nodes in the graph.
DecisionNode * m_headNode
the head node of the control flow graph
unsigned int m_nodeCounter
Total number of nodes in the graph.
MSG::Level setUpMessaging()
Set up local caches.
SmartIF< ISvcLocator > m_svcLocator
Service locator (needed to access the MessageSvc)
concurrency::PrecedenceRulesGraph::~PrecedenceRulesGraph ( )
inlineoverride

Destructor.

Definition at line 710 of file PrecedenceRulesGraph.h.

711  {
712  if ( m_headNode != 0 ) delete m_headNode;
713  }
DecisionNode * m_headNode
the head node of the control flow graph

Member Function Documentation

void concurrency::PrecedenceRulesGraph::accept ( const std::string algo_name,
IGraphVisitor visitor 
) const

A method to update algorithm node decision, and propagate it upwards.

Definition at line 440 of file PrecedenceRulesGraph.cpp.

441  {
442  getAlgorithmNode( algo_name )->accept( visitor );
443  }
AlgorithmNode * getAlgorithmNode(const std::string &algoName) const
Get the AlgorithmNode from by algorithm name using graph index.
bool accept(IGraphVisitor &visitor) override
Visitor entry point.
StatusCode concurrency::PrecedenceRulesGraph::addAlgorithmNode ( Algorithm daughterAlgo,
const std::string parentName,
bool  inverted,
bool  allPass 
)

Add algorithm node.

Definition at line 253 of file PrecedenceRulesGraph.cpp.

255  {
256 
258 
259  // Create new, or fetch existent, AlgorithmNode
260  auto& algoName = algo->name();
261  auto itA = m_algoNameToAlgoNodeMap.find( algoName );
262  concurrency::AlgorithmNode* algoNode;
263  if ( itA != m_algoNameToAlgoNodeMap.end() ) {
264  algoNode = itA->second;
265  } else {
266  algoNode = new concurrency::AlgorithmNode( *this, algo, m_nodeCounter, m_algoCounter, inverted, allPass );
267  // Mirror the action above in the BGL-based graph
268  if ( m_enableAnalysis ) {
269  auto source =
270  boost::add_vertex( AlgoProps( algo, m_nodeCounter, m_algoCounter, inverted, allPass ), m_PRGraph );
271  boost::add_edge( source, node( parentName ), m_PRGraph );
272  }
273  ++m_nodeCounter;
274  ++m_algoCounter;
275  m_algoNameToAlgoNodeMap[algoName] = algoNode;
276  ON_VERBOSE verbose() << "AlgoNode " << algoName << " added @ " << algoNode << endmsg;
277  registerIODataObjects( algo );
278  }
279 
280  // Attach AlgorithmNode to its CF decision hub
281  auto itP = m_decisionNameToDecisionHubMap.find( parentName );
282  if ( itP != m_decisionNameToDecisionHubMap.end() ) {
283  auto parentNode = itP->second;
284  ON_VERBOSE verbose() << "Attaching AlgorithmNode '" << algo->name() << "' to DecisionNode '" << parentName << "'"
285  << endmsg;
286 
287  parentNode->addDaughterNode( algoNode );
288  algoNode->addParentNode( parentNode );
289  } else {
290  sc = StatusCode::FAILURE;
291  error() << "Requested DecisionNode '" << parentName << "' was not found" << endmsg;
292  }
293 
294  return sc;
295  }
PRVertexDesc node(const std::string &) const
AlgoNodesMap m_algoNameToAlgoNodeMap
Index: map of algorithm&#39;s name to AlgorithmNode.
MsgStream & verbose() const
shortcut for the method msgStream(MSG::VERBOSE)
unsigned int m_algoCounter
Total number of algorithm nodes in the graph.
MsgStream & error() const
shortcut for the method msgStream(MSG::ERROR)
precedence::PRGraph m_PRGraph
BGL-based graph of precedence rules.
This class is used for returning status codes from appropriate routines.
Definition: StatusCode.h:26
T find(T...args)
void registerIODataObjects(const Algorithm *algo)
Register algorithm in the Data Dependency index.
unsigned int m_nodeCounter
Total number of nodes in the graph.
void addParentNode(DecisionNode *node)
Add a parent node.
#define ON_VERBOSE
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition: MsgStream.h:209
DecisionHubsMap m_decisionNameToDecisionHubMap
Index: map of decision&#39;s name to DecisionHub.
StatusCode concurrency::PrecedenceRulesGraph::addDataNode ( const DataObjID dataPath)

Add DataNode that represents DataObject.

Definition at line 305 of file PrecedenceRulesGraph.cpp.

306  {
307 
308  StatusCode sc;
309 
310  auto itD = m_dataPathToDataNodeMap.find( dataPath );
311  concurrency::DataNode* dataNode;
312  if ( itD != m_dataPathToDataNodeMap.end() ) {
313  dataNode = itD->second;
314  sc = StatusCode::SUCCESS;
315  } else {
316  if ( !m_conditionsRealmEnabled ) {
317  dataNode = new concurrency::DataNode( *this, dataPath );
318  ON_VERBOSE verbose() << " DataNode for " << dataPath << " added @ " << dataNode << endmsg;
319  // Mirror the action above in the BGL-based graph
320  if ( m_enableAnalysis ) boost::add_vertex( DataProps( dataPath ), m_PRGraph );
321  } else {
322  SmartIF<ICondSvc> condSvc{serviceLocator()->service( "CondSvc", false )};
323  if ( condSvc->isRegistered( dataPath ) ) {
324  dataNode = new concurrency::ConditionNode( *this, dataPath, condSvc );
325  ON_VERBOSE verbose() << " ConditionNode for " << dataPath << " added @ " << dataNode << endmsg;
326  // Mirror the action above in the BGL-based graph
327  if ( m_enableAnalysis ) boost::add_vertex( CondDataProps( dataPath ), m_PRGraph );
328  } else {
329  dataNode = new concurrency::DataNode( *this, dataPath );
330  ON_VERBOSE verbose() << " DataNode for " << dataPath << " added @ " << dataNode << endmsg;
331  // Mirror the action above in the BGL-based graph
332  if ( m_enableAnalysis ) boost::add_vertex( DataProps( dataPath ), m_PRGraph );
333  }
334  }
335 
336  m_dataPathToDataNodeMap[dataPath] = dataNode;
337 
338  sc = StatusCode::SUCCESS;
339  }
340 
341  return sc;
342  }
SmartIF< ISvcLocator > & serviceLocator() const override
Retrieve pointer to service locator.
MsgStream & verbose() const
shortcut for the method msgStream(MSG::VERBOSE)
StatusCode service(const Gaudi::Utils::TypeNameString &name, T *&svc, bool createIf=true)
Templated method to access a service by name.
Definition: ISvcLocator.h:79
bool m_conditionsRealmEnabled
Enable conditions realm of precedence rules.
precedence::PRGraph m_PRGraph
BGL-based graph of precedence rules.
This class is used for returning status codes from appropriate routines.
Definition: StatusCode.h:26
T find(T...args)
#define ON_VERBOSE
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition: MsgStream.h:209
DataNodesMap m_dataPathToDataNodeMap
Index: map of data path to DataNode.
StatusCode concurrency::PrecedenceRulesGraph::addDecisionHubNode ( Algorithm daughterAlgo,
const std::string parentName,
concurrency::Concurrent  modeConcurrent,
concurrency::PromptDecision  modePromptDecision,
concurrency::ModeOr  modeOR,
concurrency::AllPass  allPass,
concurrency::Inverted  isInverted 
)

Add a node, which aggregates decisions of direct daughter nodes.

Definition at line 352 of file PrecedenceRulesGraph.cpp.

355  {
356 
358 
359  auto& decisionHubName = decisionHubAlgo->name();
360 
361  auto itP = m_decisionNameToDecisionHubMap.find( parentName );
362  concurrency::DecisionNode* parentNode;
363  if ( itP != m_decisionNameToDecisionHubMap.end() ) {
364  parentNode = itP->second;
365  auto itA = m_decisionNameToDecisionHubMap.find( decisionHubName );
366  concurrency::DecisionNode* decisionHubNode;
367  if ( itA != m_decisionNameToDecisionHubMap.end() ) {
368  decisionHubNode = itA->second;
369  } else {
370  decisionHubNode = new concurrency::DecisionNode( *this, m_nodeCounter, decisionHubName, modeConcurrent,
371  modePromptDecision, modeOR, allPass, isInverted );
372  m_decisionNameToDecisionHubMap[decisionHubName] = decisionHubNode;
373 
374  // Mirror the action above in the BGL-based graph
375  if ( m_enableAnalysis ) {
376  auto source = boost::add_vertex( DecisionHubProps( decisionHubName, m_nodeCounter, modeConcurrent,
377  modePromptDecision, modeOR, allPass, isInverted ),
378  m_PRGraph );
379  boost::add_edge( source, node( parentName ), m_PRGraph );
380  }
381 
382  ++m_nodeCounter;
383 
384  ON_VERBOSE verbose() << "Decision hub node " << decisionHubName << " added @ " << decisionHubNode << endmsg;
385  }
386 
387  parentNode->addDaughterNode( decisionHubNode );
388  decisionHubNode->addParentNode( parentNode );
389  } else {
390  sc = StatusCode::FAILURE;
391  error() << "Decision hub node " << parentName << ", requested to be parent, is not registered." << endmsg;
392  }
393 
394  return sc;
395  }
PRVertexDesc node(const std::string &) const
void addDaughterNode(ControlFlowNode *node)
Add a daughter node.
MsgStream & verbose() const
shortcut for the method msgStream(MSG::VERBOSE)
MsgStream & error() const
shortcut for the method msgStream(MSG::ERROR)
precedence::PRGraph m_PRGraph
BGL-based graph of precedence rules.
This class is used for returning status codes from appropriate routines.
Definition: StatusCode.h:26
T find(T...args)
void addParentNode(DecisionNode *node)
Add a parent node.
unsigned int m_nodeCounter
Total number of nodes in the graph.
#define ON_VERBOSE
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition: MsgStream.h:209
DecisionHubsMap m_decisionNameToDecisionHubMap
Index: map of decision&#39;s name to DecisionHub.
void concurrency::PrecedenceRulesGraph::addEdgeToPrecTrace ( const AlgorithmNode u,
const AlgorithmNode v 
)

set cause-effect connection between two algorithms in the precedence trace

Definition at line 644 of file PrecedenceRulesGraph.cpp.

645  {
646 
647  std::string u_name = u == nullptr ? "ENTRY" : u->getNodeName();
648  std::string v_name = v->getNodeName();
649 
651 
652  if ( u == nullptr ) {
653  auto itT = m_prec_trace_map.find( "ENTRY" );
654  if ( itT != m_prec_trace_map.end() ) {
655  source = itT->second;
656  } else {
657  source = boost::add_vertex( precedence::AlgoTraceProps( "ENTRY", -1, -1, -1.0 ), m_precTrace );
658  m_prec_trace_map["ENTRY"] = source;
659  }
660  } else {
661  auto itS = m_prec_trace_map.find( u_name );
662  if ( itS != m_prec_trace_map.end() ) {
663  source = itS->second;
664  } else {
665 
666  source =
667  boost::add_vertex( precedence::AlgoTraceProps( u_name, u->getAlgoIndex(), u->getRank(), -1 ), m_precTrace );
668  m_prec_trace_map[u_name] = source;
669  }
670  }
671 
673 
674  auto itP = m_prec_trace_map.find( v_name );
675  if ( itP != m_prec_trace_map.end() ) {
676  target = itP->second;
677  } else {
678 
679  target =
680  boost::add_vertex( precedence::AlgoTraceProps( v_name, v->getAlgoIndex(), v->getRank(), -1 ), m_precTrace );
681  m_prec_trace_map[v_name] = target;
682  }
683 
684  boost::add_edge( source, target, m_precTrace );
685 
686  ON_DEBUG debug() << u_name << "-->" << v_name << " precedence trait added" << endmsg;
687  }
precedence::PrecTrace m_precTrace
facilities for algorithm precedence tracing
boost::graph_traits< PrecTrace >::vertex_descriptor AlgoTraceVertex
std::map< std::string, precedence::AlgoTraceVertex > m_prec_trace_map
T end(T...args)
#define ON_DEBUG
STL class.
T find(T...args)
MsgStream & debug() const
shortcut for the method msgStream(MSG::DEBUG)
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition: MsgStream.h:209
void concurrency::PrecedenceRulesGraph::addHeadNode ( const std::string headName,
concurrency::Concurrent  modeConcurrent,
concurrency::PromptDecision  modePromptDecision,
concurrency::ModeOr  modeOR,
concurrency::AllPass  allPass,
concurrency::Inverted  isInverted 
)

Add a node, which has no parents.

Definition at line 398 of file PrecedenceRulesGraph.cpp.

401  {
402 
403  auto itH = m_decisionNameToDecisionHubMap.find( headName );
404  if ( itH != m_decisionNameToDecisionHubMap.end() ) {
405  m_headNode = itH->second;
406  } else {
407  m_headNode = new concurrency::DecisionNode( *this, m_nodeCounter, headName, modeConcurrent, modePromptDecision,
408  modeOR, allPass, isInverted );
410 
411  // Mirror the action above in the BGL-based graph
412  if ( m_enableAnalysis ) {
413  boost::add_vertex( DecisionHubProps( headName, m_nodeCounter, modeConcurrent, modePromptDecision, modeOR,
414  allPass, isInverted ),
415  m_PRGraph );
416  }
417 
418  ++m_nodeCounter;
419  }
420  }
precedence::PRGraph m_PRGraph
BGL-based graph of precedence rules.
DecisionNode * m_headNode
the head node of the control flow graph
T find(T...args)
unsigned int m_nodeCounter
Total number of nodes in the graph.
DecisionHubsMap m_decisionNameToDecisionHubMap
Index: map of decision&#39;s name to DecisionHub.
StatusCode concurrency::PrecedenceRulesGraph::buildDataDependenciesRealm ( )

Build data dependency realm WITH data object nodes participating.

Definition at line 201 of file PrecedenceRulesGraph.cpp.

202  {
203 
204  StatusCode global_sc( StatusCode::SUCCESS, true );
205 
206  // Production of DataNodes by AlgorithmNodes (DataNodes are created here)
207  for ( auto algo : m_algoNameToAlgoNodeMap ) {
208 
209  auto& outputs = m_algoNameToAlgoOutputsMap[algo.first];
210  for ( auto output : outputs ) {
211  const auto sc = addDataNode( output );
212  if ( !sc.isSuccess() ) {
213  error() << "Extra producer (" << algo.first << ") for DataObject @ " << output
214  << " has been detected: this is not allowed." << endmsg;
215  global_sc = sc;
216  }
217  auto dataNode = getDataNode( output );
218  dataNode->addProducerNode( algo.second );
219  algo.second->addOutputDataNode( dataNode );
220 
221  // Mirror the action above in the BGL-based graph
222  if ( m_enableAnalysis )
223  boost::add_edge( node( algo.second->getNodeName() ), node( output.fullKey() ), m_PRGraph );
224  }
225  }
226 
227  // Consumption of DataNodes by AlgorithmNodes
228  for ( auto algo : m_algoNameToAlgoNodeMap ) {
229 
230  for ( auto input : m_algoNameToAlgoInputsMap[algo.first] ) {
231 
232  DataNode* dataNode = nullptr;
233 
234  auto itP = m_dataPathToDataNodeMap.find( input );
235 
236  if ( itP != m_dataPathToDataNodeMap.end() ) dataNode = getDataNode( input );
237 
238  if ( dataNode ) {
239  dataNode->addConsumerNode( algo.second );
240  algo.second->addInputDataNode( dataNode );
241 
242  // Mirror the action above in the BGL-based graph
243  if ( m_enableAnalysis )
244  boost::add_edge( node( input.fullKey() ), node( algo.second->getNodeName() ), m_PRGraph );
245  }
246  }
247  }
248 
249  return global_sc;
250  }
PRVertexDesc node(const std::string &) const
AlgoNodesMap m_algoNameToAlgoNodeMap
Index: map of algorithm&#39;s name to AlgorithmNode.
StatusCode addDataNode(const DataObjID &dataPath)
Add DataNode that represents DataObject.
MsgStream & error() const
shortcut for the method msgStream(MSG::ERROR)
precedence::PRGraph m_PRGraph
BGL-based graph of precedence rules.
This class is used for returning status codes from appropriate routines.
Definition: StatusCode.h:26
DataNode * getDataNode(const DataObjID &dataPath) const
Get DataNode by DataObject path using graph index.
T find(T...args)
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition: MsgStream.h:209
AlgoInputsMap m_algoNameToAlgoInputsMap
Indexes: maps of algorithm&#39;s name to algorithm&#39;s inputs/outputs.
DataNodesMap m_dataPathToDataNodeMap
Index: map of data path to DataNode.
void addConsumerNode(AlgorithmNode *node)
Add relationship to consumer AlgorithmNode.
std::string concurrency::PrecedenceRulesGraph::dumpControlFlow ( ) const

Print out control flow of Algorithms and Sequences.

Definition at line 457 of file PrecedenceRulesGraph.cpp.

458  {
459  std::ostringstream ost;
460  dumpControlFlow( ost, m_headNode, 0 );
461  return ost.str();
462  }
DecisionNode * m_headNode
the head node of the control flow graph
std::string dumpControlFlow() const
Print out control flow of Algorithms and Sequences.
void concurrency::PrecedenceRulesGraph::dumpControlFlow ( std::ostringstream ost,
ControlFlowNode node,
const int &  indent 
) const

Definition at line 464 of file PrecedenceRulesGraph.cpp.

465  {
466  ost << std::string( indent * 2, ' ' );
467  DecisionNode* dn = dynamic_cast<DecisionNode*>( node );
468  AlgorithmNode* an = dynamic_cast<AlgorithmNode*>( node );
469  if ( dn != 0 ) {
470  if ( node != m_headNode ) {
471  ost << node->getNodeName() << " [Seq] ";
472  ost << ( ( dn->m_modeConcurrent ) ? " [Concurrent] " : " [Sequential] " );
473  ost << ( ( dn->m_modePromptDecision ) ? " [Prompt] " : "" );
474  ost << ( ( dn->m_modeOR ) ? " [OR] " : "" );
475  ost << ( ( dn->m_allPass ) ? " [PASS] " : "" );
476  ost << "\n";
477  }
478  const std::vector<ControlFlowNode*>& dth = dn->getDaughters();
479  for ( std::vector<ControlFlowNode*>::const_iterator itr = dth.begin(); itr != dth.end(); ++itr ) {
480  dumpControlFlow( ost, *itr, indent + 1 );
481  }
482  } else if ( an != 0 ) {
483  ost << node->getNodeName() << " [Alg] ";
484  if ( an != 0 ) {
485  auto ar = an->getAlgorithm();
486  ost << " [n= " << ar->cardinality() << "]";
487  ost << ( ( !ar->isClonable() ) ? " [unclonable] " : "" );
488  }
489  ost << "\n";
490  }
491  }
PRVertexDesc node(const std::string &) const
T end(T...args)
STL class.
DecisionNode * m_headNode
the head node of the control flow graph
STL class.
T begin(T...args)
std::string dumpControlFlow() const
Print out control flow of Algorithms and Sequences.
std::string concurrency::PrecedenceRulesGraph::dumpDataFlow ( ) const

Print out all data origins and destinations, as reflected in the EF graph.

Definition at line 494 of file PrecedenceRulesGraph.cpp.

495  {
496 
497  const char idt[] = " ";
498  std::ostringstream ost;
499 
500  ost << "\n" << idt << "====================================\n";
501  ost << idt << "Data origins and destinations:\n";
502  ost << idt << "====================================\n";
503 
504  for ( auto& pair : m_dataPathToDataNodeMap ) {
505 
506  for ( auto algoNode : pair.second->getProducers() ) ost << idt << " " << algoNode->getNodeName() << "\n";
507 
508  ost << idt << " V\n";
509  ost << idt << " o " << pair.first << "\n";
510  ost << idt << " V\n";
511 
512  for ( auto algoNode : pair.second->getConsumers() ) ost << idt << " " << algoNode->getNodeName() << "\n";
513 
514  ost << idt << "====================================\n";
515  }
516 
517  return ost.str();
518  }
DataNodesMap m_dataPathToDataNodeMap
Index: map of data path to DataNode.
void concurrency::PrecedenceRulesGraph::dumpPrecRules ( const boost::filesystem::path &  fileName,
const EventSlot slot 
)

dump to file the precedence rules

Definition at line 522 of file PrecedenceRulesGraph.cpp.

523  {
524  boost::filesystem::ofstream myfile;
525  myfile.open( fileName, std::ios::app );
526 
527  // Declare properties to dump
528  boost::dynamic_properties dp;
529 
530  using boost::make_transform_value_property_map;
531  using boost::apply_visitor;
532  using boost::get;
533  using boost::vertex_bundle;
534 
535  dp.property( "Entity", make_transform_value_property_map(
536  []( const VariantVertexProps& v ) { return boost::lexical_cast<std::string>( v ); },
537  get( vertex_bundle, m_PRGraph ) ) );
538 
539  auto nameVis = precedence::VertexName();
540  dp.property( "Name", make_transform_value_property_map(
541  [&nameVis]( const VariantVertexProps& v ) { return apply_visitor( nameVis, v ); },
542  get( vertex_bundle, m_PRGraph ) ) );
543 
544  auto gMVis = precedence::GroupMode();
545  dp.property( "Mode", make_transform_value_property_map(
546  [&gMVis]( const VariantVertexProps& v ) { return apply_visitor( gMVis, v ); },
547  get( vertex_bundle, m_PRGraph ) ) );
548 
549  auto gLVis = precedence::GroupLogic();
550  dp.property( "Logic", make_transform_value_property_map(
551  [&gLVis]( const VariantVertexProps& v ) { return apply_visitor( gLVis, v ); },
552  get( vertex_bundle, m_PRGraph ) ) );
553 
554  auto dNVis = precedence::DecisionNegation();
555  dp.property( "Decision Negation", make_transform_value_property_map(
556  [&dNVis]( const VariantVertexProps& v ) { return apply_visitor( dNVis, v ); },
557  get( vertex_bundle, m_PRGraph ) ) );
558 
559  auto aPVis = precedence::AllPass();
560  dp.property( "Negative Decision Inversion",
561  make_transform_value_property_map(
562  [&aPVis]( const VariantVertexProps& v ) { return apply_visitor( aPVis, v ); },
563  get( vertex_bundle, m_PRGraph ) ) );
564 
565  auto gEVis = precedence::GroupExit();
566  dp.property( "Exit Policy", make_transform_value_property_map(
567  [&gEVis]( const VariantVertexProps& v ) { return apply_visitor( gEVis, v ); },
568  get( vertex_bundle, m_PRGraph ) ) );
569 
570  auto opVis = precedence::Operations();
571  dp.property( "Operations", make_transform_value_property_map(
572  [&opVis]( const VariantVertexProps& v ) { return apply_visitor( opVis, v ); },
573  get( vertex_bundle, m_PRGraph ) ) );
574 
575  auto cFDVis = precedence::CFDecision( slot );
576  dp.property( "CF Decision", make_transform_value_property_map(
577  [&cFDVis]( const VariantVertexProps& v ) { return apply_visitor( cFDVis, v ); },
578  get( vertex_bundle, m_PRGraph ) ) );
579 
581  dp.property( "State", make_transform_value_property_map(
582  [&stVis]( const VariantVertexProps& v ) { return apply_visitor( stVis, v ); },
583  get( vertex_bundle, m_PRGraph ) ) );
584 
585  auto sTVis = precedence::StartTime( slot, serviceLocator() );
586  dp.property( "Start Time (Epoch ns)",
587  make_transform_value_property_map(
588  [&sTVis]( const VariantVertexProps& v ) { return apply_visitor( sTVis, v ); },
589  get( vertex_bundle, m_PRGraph ) ) );
590 
591  auto eTVis = precedence::EndTime( slot, serviceLocator() );
592  dp.property( "End Time (Epoch ns)",
593  make_transform_value_property_map(
594  [&eTVis]( const VariantVertexProps& v ) { return apply_visitor( eTVis, v ); },
595  get( vertex_bundle, m_PRGraph ) ) );
596 
597  auto durVis = precedence::Duration( slot, serviceLocator() );
598  dp.property( "Runtime (ns)", make_transform_value_property_map(
599  [&durVis]( const VariantVertexProps& v ) { return apply_visitor( durVis, v ); },
600  get( vertex_bundle, m_PRGraph ) ) );
601 
602  boost::write_graphml( myfile, m_PRGraph, dp );
603 
604  myfile.close();
605  }
SmartIF< ISvcLocator > & serviceLocator() const override
Retrieve pointer to service locator.
STL class.
bool m_conditionsRealmEnabled
Enable conditions realm of precedence rules.
precedence::PRGraph m_PRGraph
BGL-based graph of precedence rules.
Gaudi::tagged_bool< class AllPass_tag > AllPass
boost::variant< AlgoProps, DecisionHubProps, DataProps, CondDataProps > VariantVertexProps
void concurrency::PrecedenceRulesGraph::dumpPrecTrace ( const boost::filesystem::path &  fileName)

dump to file the precedence trace

Definition at line 608 of file PrecedenceRulesGraph.cpp.

609  {
610  boost::filesystem::ofstream myfile;
611  myfile.open( fileName, std::ios::app );
612 
613  // Fill runtimes (as this could not be done on the fly during trace assembling)
614  SmartIF<ITimelineSvc> timelineSvc = m_svcLocator->service<ITimelineSvc>( "TimelineSvc", false );
615  if ( !timelineSvc.isValid() ) {
616  warning() << "Failed to get the TimelineSvc, timing will not be added to "
617  << "the task precedence trace dump" << endmsg;
618  } else {
619 
620  typedef boost::graph_traits<precedence::PRGraph>::vertex_iterator vertex_iter;
622  for ( vp = vertices( m_precTrace ); vp.first != vp.second; ++vp.first ) {
623  TimelineEvent te{};
624  te.algorithm = m_precTrace[*vp.first].m_name;
625  timelineSvc->getTimelineEvent( te );
626  int runtime = std::chrono::duration_cast<std::chrono::nanoseconds>( te.end - te.start ).count();
627  m_precTrace[*vp.first].m_runtime = runtime;
628  }
629  }
630 
631  // Declare properties to dump
632  boost::dynamic_properties dp;
633  using boost::get;
635  dp.property( "Name", get( &AlgoTraceProps::m_name, m_precTrace ) );
636  dp.property( "Rank", get( &AlgoTraceProps::m_rank, m_precTrace ) );
637  dp.property( "Runtime", get( &AlgoTraceProps::m_runtime, m_precTrace ) );
638 
639  boost::write_graphml( myfile, m_precTrace, dp );
640 
641  myfile.close();
642  }
precedence::PrecTrace m_precTrace
facilities for algorithm precedence tracing
std::string algorithm
Definition: ITimelineSvc.h:18
T duration_cast(T...args)
virtual void getTimelineEvent(TimelineEvent &) const =0
StatusCode service(const Gaudi::Utils::TypeNameString &name, T *&svc, bool createIf=true)
Templated method to access a service by name.
Definition: ISvcLocator.h:79
MsgStream & warning() const
shortcut for the method msgStream(MSG::WARNING)
T count(T...args)
bool isValid() const
Allow for check if smart pointer is valid.
Definition: SmartIF.h:68
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition: MsgStream.h:209
SmartIF< ISvcLocator > m_svcLocator
Service locator (needed to access the MessageSvc)
void concurrency::PrecedenceRulesGraph::enableAnalysis ( )
inline

BGL-based facilities.

Definition at line 764 of file PrecedenceRulesGraph.h.

AlgorithmNode * concurrency::PrecedenceRulesGraph::getAlgorithmNode ( const std::string algoName) const

Get the AlgorithmNode from by algorithm name using graph index.

Definition at line 298 of file PrecedenceRulesGraph.cpp.

299  {
300 
301  return m_algoNameToAlgoNodeMap.at( algoName );
302  }
AlgoNodesMap m_algoNameToAlgoNodeMap
Index: map of algorithm&#39;s name to AlgorithmNode.
unsigned int concurrency::PrecedenceRulesGraph::getControlFlowNodeCounter ( ) const
inline

Get total number of control flow graph nodes.

Definition at line 744 of file PrecedenceRulesGraph.h.

744 { return m_nodeCounter; }
unsigned int m_nodeCounter
Total number of nodes in the graph.
DataNode * concurrency::PrecedenceRulesGraph::getDataNode ( const DataObjID dataPath) const

Get DataNode by DataObject path using graph index.

Definition at line 345 of file PrecedenceRulesGraph.cpp.

346  {
347 
348  return m_dataPathToDataNodeMap.at( dataPath );
349  }
DataNodesMap m_dataPathToDataNodeMap
Index: map of data path to DataNode.
DecisionNode* concurrency::PrecedenceRulesGraph::getHeadNode ( ) const
inline

Get head node.

Definition at line 734 of file PrecedenceRulesGraph.h.

734 { return m_headNode; };
DecisionNode * m_headNode
the head node of the control flow graph
const std::chrono::system_clock::time_point concurrency::PrecedenceRulesGraph::getInitTime ( ) const
inline

Definition at line 754 of file PrecedenceRulesGraph.h.

754 { return m_initTime; }
const std::chrono::system_clock::time_point m_initTime
StatusCode concurrency::PrecedenceRulesGraph::initialize ( )

Initialize graph.

Definition at line 135 of file PrecedenceRulesGraph.cpp.

136  {
137  if ( serviceLocator()->existsService( "CondSvc" ) ) {
138  SmartIF<ICondSvc> condSvc{serviceLocator()->service( "CondSvc" )};
139  if ( condSvc.isValid() ) {
140  info() << "CondSvc found. DF precedence rules will be augmented with 'Conditions'" << endmsg;
142  }
143  }
144 
145  // Detach condition algorithms from the CF realm
146  if ( m_conditionsRealmEnabled ) {
147  SmartIF<ICondSvc> condSvc{serviceLocator()->service( "CondSvc", false )};
148  auto& condAlgs = condSvc->condAlgs();
149  for ( const auto algo : condAlgs ) {
150  auto itA = m_algoNameToAlgoNodeMap.find( algo->name() );
151  concurrency::AlgorithmNode* algoNode;
152  if ( itA != m_algoNameToAlgoNodeMap.end() ) {
153  algoNode = itA->second;
154  debug() << "Detaching condition algorithm '" << algo->name() << "' from the CF realm.." << endmsg;
155  for ( auto parent : algoNode->getParentDecisionHubs() ) {
156  parent->m_children.erase( std::remove( parent->m_children.begin(), parent->m_children.end(), algoNode ),
157  parent->m_children.end() );
158  // clean up also auxiliary BGL-based graph of precedence rules
159  if ( m_enableAnalysis )
160  boost::remove_edge( node( algoNode->getNodeName() ), node( parent->getNodeName() ), m_PRGraph );
161  }
162  algoNode->m_parents.clear();
163 
164  } else {
165  warning() << "Algorithm '" << algo->name() << "' is not registered in the graph" << endmsg;
166  }
167  }
168  }
169 
171 
172  if ( !sc.isSuccess() ) error() << "Could not build the data dependency realm." << endmsg;
173 
174  ON_DEBUG debug() << dumpDataFlow() << endmsg;
175 
176  return sc;
177  }
PRVertexDesc node(const std::string &) const
MsgStream & info() const
shortcut for the method msgStream(MSG::INFO)
bool isSuccess() const
Test for a status code of SUCCESS.
Definition: StatusCode.h:50
SmartIF< ISvcLocator > & serviceLocator() const override
Retrieve pointer to service locator.
AlgoNodesMap m_algoNameToAlgoNodeMap
Index: map of algorithm&#39;s name to AlgorithmNode.
std::vector< DecisionNode * > m_parents
Control flow parents of an AlgorithmNode (DecisionNodes)
#define ON_DEBUG
const std::vector< DecisionNode * > & getParentDecisionHubs() const
Get all parent decision hubs.
T remove(T...args)
StatusCode service(const Gaudi::Utils::TypeNameString &name, T *&svc, bool createIf=true)
Templated method to access a service by name.
Definition: ISvcLocator.h:79
MsgStream & error() const
shortcut for the method msgStream(MSG::ERROR)
bool m_conditionsRealmEnabled
Enable conditions realm of precedence rules.
precedence::PRGraph m_PRGraph
BGL-based graph of precedence rules.
MsgStream & warning() const
shortcut for the method msgStream(MSG::WARNING)
This class is used for returning status codes from appropriate routines.
Definition: StatusCode.h:26
std::string dumpDataFlow() const
Print out all data origins and destinations, as reflected in the EF graph.
T find(T...args)
MsgStream & debug() const
shortcut for the method msgStream(MSG::DEBUG)
const std::string & getNodeName() const
Get node name.
StatusCode buildDataDependenciesRealm()
Build data dependency realm WITH data object nodes participating.
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition: MsgStream.h:209
const std::string& concurrency::PrecedenceRulesGraph::name ( ) const
inlineoverride

Retrieve name of the service.

Definition at line 750 of file PrecedenceRulesGraph.h.

750 { return m_name; }
PRVertexDesc concurrency::PrecedenceRulesGraph::node ( const std::string name) const

Definition at line 423 of file PrecedenceRulesGraph.cpp.

424  {
425 
426  PRVertexDesc target{};
427 
428  for ( auto vp = vertices( m_PRGraph ); vp.first != vp.second; ++vp.first ) {
429  PRVertexDesc v = *vp.first;
430  if ( boost::apply_visitor( precedence::VertexName(), m_PRGraph[v] ) == name ) {
431  target = v;
432  break;
433  }
434  }
435 
436  return target;
437  }
boost::graph_traits< PRGraph >::vertex_descriptor PRVertexDesc
precedence::PRGraph m_PRGraph
BGL-based graph of precedence rules.
void concurrency::PrecedenceRulesGraph::printState ( std::stringstream output,
AlgsExecutionStates states,
const std::vector< int > &  node_decisions,
const unsigned int &  recursionLevel 
) const
inline

Print a string representing the control flow state.

Definition at line 757 of file PrecedenceRulesGraph.h.

759  {
760  m_headNode->printState( output, states, node_decisions, recursionLevel );
761  }
DecisionNode * m_headNode
the head node of the control flow graph
void printState(std::stringstream &output, AlgsExecutionStates &states, const std::vector< int > &node_decisions, const unsigned int &recursionLevel) const override
Print a string representing the control flow state.
void concurrency::PrecedenceRulesGraph::rankAlgorithms ( IGraphVisitor ranker) const

Rank Algorithm nodes by the number of data outputs.

Definition at line 446 of file PrecedenceRulesGraph.cpp.

447  {
448 
449  info() << "Starting ranking by data outputs .. " << endmsg;
450  for ( auto& pair : m_algoNameToAlgoNodeMap ) {
451  ON_DEBUG debug() << " Ranking " << pair.first << "... " << endmsg;
452  pair.second->accept( ranker );
453  ON_DEBUG debug() << " ... rank of " << pair.first << ": " << pair.second->getRank() << endmsg;
454  }
455  }
MsgStream & info() const
shortcut for the method msgStream(MSG::INFO)
AlgoNodesMap m_algoNameToAlgoNodeMap
Index: map of algorithm&#39;s name to AlgorithmNode.
#define ON_DEBUG
MsgStream & debug() const
shortcut for the method msgStream(MSG::DEBUG)
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition: MsgStream.h:209
void concurrency::PrecedenceRulesGraph::registerIODataObjects ( const Algorithm algo)

Register algorithm in the Data Dependency index.

Definition at line 180 of file PrecedenceRulesGraph.cpp.

181  {
182 
183  const std::string& algoName = algo->name();
184 
185  m_algoNameToAlgoInputsMap[algoName] = algo->inputDataObjs();
186  m_algoNameToAlgoOutputsMap[algoName] = algo->outputDataObjs();
187 
188  ON_VERBOSE
189  {
190  verbose() << " Inputs of " << algoName << ": ";
191  for ( auto tag : algo->inputDataObjs() ) verbose() << tag << " | ";
192  verbose() << endmsg;
193 
194  verbose() << " Outputs of " << algoName << ": ";
195  for ( auto tag : algo->outputDataObjs() ) verbose() << tag << " | ";
196  verbose() << endmsg;
197  }
198  }
const std::string & name() const override
The identifying name of the algorithm object.
Definition: Algorithm.cpp:737
const DataObjIDColl & outputDataObjs() const override
MsgStream & verbose() const
shortcut for the method msgStream(MSG::VERBOSE)
STL class.
const DataObjIDColl & inputDataObjs() const override
#define ON_VERBOSE
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition: MsgStream.h:209
AlgoInputsMap m_algoNameToAlgoInputsMap
Indexes: maps of algorithm&#39;s name to algorithm&#39;s inputs/outputs.
SmartIF<ISvcLocator>& concurrency::PrecedenceRulesGraph::serviceLocator ( ) const
inlineoverride

Retrieve pointer to service locator.

Definition at line 752 of file PrecedenceRulesGraph.h.

752 { return m_svcLocator; }
SmartIF< ISvcLocator > m_svcLocator
Service locator (needed to access the MessageSvc)

Member Data Documentation

unsigned int concurrency::PrecedenceRulesGraph::m_algoCounter
private

Total number of algorithm nodes in the graph.

Definition at line 796 of file PrecedenceRulesGraph.h.

AlgoInputsMap concurrency::PrecedenceRulesGraph::m_algoNameToAlgoInputsMap
private

Indexes: maps of algorithm's name to algorithm's inputs/outputs.

Definition at line 790 of file PrecedenceRulesGraph.h.

AlgoNodesMap concurrency::PrecedenceRulesGraph::m_algoNameToAlgoNodeMap
private

Index: map of algorithm's name to AlgorithmNode.

Definition at line 784 of file PrecedenceRulesGraph.h.

AlgoOutputsMap concurrency::PrecedenceRulesGraph::m_algoNameToAlgoOutputsMap
private

Definition at line 791 of file PrecedenceRulesGraph.h.

bool concurrency::PrecedenceRulesGraph::m_conditionsRealmEnabled {false}
private

Enable conditions realm of precedence rules.

Definition at line 812 of file PrecedenceRulesGraph.h.

DataNodesMap concurrency::PrecedenceRulesGraph::m_dataPathToDataNodeMap
private

Index: map of data path to DataNode.

Definition at line 788 of file PrecedenceRulesGraph.h.

DecisionHubsMap concurrency::PrecedenceRulesGraph::m_decisionNameToDecisionHubMap
private

Index: map of decision's name to DecisionHub.

Definition at line 786 of file PrecedenceRulesGraph.h.

bool concurrency::PrecedenceRulesGraph::m_enableAnalysis {false}
private

Definition at line 807 of file PrecedenceRulesGraph.h.

DecisionNode* concurrency::PrecedenceRulesGraph::m_headNode
private

the head node of the control flow graph

Definition at line 782 of file PrecedenceRulesGraph.h.

const std::chrono::system_clock::time_point concurrency::PrecedenceRulesGraph::m_initTime
private

Definition at line 802 of file PrecedenceRulesGraph.h.

const std::string concurrency::PrecedenceRulesGraph::m_name
private

Definition at line 800 of file PrecedenceRulesGraph.h.

unsigned int concurrency::PrecedenceRulesGraph::m_nodeCounter
private

Total number of nodes in the graph.

Definition at line 794 of file PrecedenceRulesGraph.h.

std::map<std::string, precedence::AlgoTraceVertex> concurrency::PrecedenceRulesGraph::m_prec_trace_map
private

Definition at line 806 of file PrecedenceRulesGraph.h.

precedence::PrecTrace concurrency::PrecedenceRulesGraph::m_precTrace
private

facilities for algorithm precedence tracing

Definition at line 805 of file PrecedenceRulesGraph.h.

precedence::PRGraph concurrency::PrecedenceRulesGraph::m_PRGraph
private

BGL-based graph of precedence rules.

Definition at line 809 of file PrecedenceRulesGraph.h.

SmartIF<ISvcLocator> concurrency::PrecedenceRulesGraph::m_svcLocator
mutableprivate

Service locator (needed to access the MessageSvc)

Definition at line 799 of file PrecedenceRulesGraph.h.


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