The Gaudi Framework  master (9f3f8895)
Loading...
Searching...
No Matches
concurrency::PrecedenceRulesGraph Class Reference

#include </builds/gaudi/Gaudi/GaudiHive/src/PRGraph/PrecedenceRulesGraph.h>

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

Public Member Functions

 PrecedenceRulesGraph (const std::string &name, SmartIF< ISvcLocator > svc)
 Constructor.
StatusCode initialize ()
 Initialize graph.
void accept (IGraphVisitor &visitor) const
 An entry point to visit all graph nodes.
StatusCode addDataNode (const DataObjID &dataPath)
 Add DataNode that represents DataObject.
DataNode * getDataNode (const DataObjID &dataPath) const
 Get DataNode by DataObject path using graph index.
void registerIODataObjects (const Gaudi::Algorithm *algo)
 Register algorithm in the Data Dependency index.
StatusCode buildDataDependenciesRealm ()
 Build data dependency realm WITH data object nodes participating.
void addHeadNode (const std::string &headName, concurrency::Concurrent, concurrency::PromptDecision, concurrency::ModeOr, concurrency::AllPass, concurrency::Inverted)
 Add a node, which has no parents.
DecisionNode * getHeadNode () const
 Get head node.
StatusCode addAlgorithmNode (Gaudi::Algorithm *daughterAlgo, const std::string &parentName)
 Add algorithm node.
AlgorithmNode * getAlgorithmNode (const std::string &algoName) const
 Get the AlgorithmNode from by algorithm name using graph index.
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.
unsigned int getControlFlowNodeCounter () const
 Get total number of control flow graph nodes.
void rankAlgorithms (IGraphVisitor &ranker) const
 Rank Algorithm nodes by the number of data outputs.
const std::string & name () const override
 Retrieve name of the service.
SmartIF< ISvcLocator > & serviceLocator () const override
 Retrieve pointer to service locator.
void printState (std::stringstream &output, EventSlot &slot, const unsigned int &recursionLevel) const
 Print a string representing the control flow state.
void enableAnalysis ()
 BGL-based facilities.
PRVertexDesc node (const std::string &) const
std::string dumpDataFlow () const
 Print out all data origins and destinations, as reflected in the EF graph.
std::string dumpControlFlow () const
 Print out control flow of Algorithms and Sequences.
void dumpPrecRules (const std::filesystem::path &, const EventSlot &slot)
 dump to file the precedence rules
void dumpPrecTrace (const std::filesystem::path &, const EventSlot &slot)
 dump to file the precedence trace
void addEdgeToPrecTrace (const AlgorithmNode *u, const AlgorithmNode *v)
 set cause-effect connection between two algorithms in the precedence trace
void dumpControlFlow (std::ostringstream &, ControlFlowNode *, const int &) const
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 Attributes

DecisionNode * m_headNode = nullptr
 the head node of the control flow graph
std::unordered_map< std::string, std::unique_ptr< AlgorithmNode > > m_algoNameToAlgoNodeMap
 Index: map of algorithm's name to AlgorithmNode.
std::unordered_map< std::string, std::unique_ptr< DecisionNode > > m_decisionNameToDecisionHubMap
 Index: map of decision's name to DecisionHub.
std::unordered_map< DataObjID, std::unique_ptr< DataNode >, DataObjID_Hasher > m_dataPathToDataNodeMap
 Index: map of data path to DataNode.
std::unordered_map< std::string, DataObjIDColl > m_algoNameToAlgoInputsMap
 Indexes: maps of algorithm's name to algorithm's inputs/outputs.
std::unordered_map< std::string, DataObjIDColl > m_algoNameToAlgoOutputsMap
unsigned int m_nodeCounter = 0
 Total number of nodes in the graph.
unsigned int m_algoCounter = 0
 Total number of algorithm nodes in the graph.
SmartIF< ISvcLocator > m_svcLocator
 Service locator (needed to access the MessageSvc).
const std::string m_name
precedence::PrecTrace m_precTrace
 facilities for algorithm precedence tracing
std::map< std::string, precedence::AlgoTraceVertex > m_prec_trace_map
bool m_enableAnalysis { false }
precedence::PRGraph m_PRGraph
 BGL-based graph of precedence rules.
bool m_conditionsRealmEnabled { false }
 Enable conditions realm of precedence rules.

Additional Inherited Members

Public Types inherited from CommonMessaging< IPrecedenceRulesGraph >
using base_class
Protected Member Functions inherited from CommonMessaging< IPrecedenceRulesGraph >
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.

Detailed Description

Definition at line 630 of file PrecedenceRulesGraph.h.

Constructor & Destructor Documentation

◆ PrecedenceRulesGraph()

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

Constructor.

Definition at line 633 of file PrecedenceRulesGraph.h.

633 : m_svcLocator( svc ), m_name( name ) {
634 // make sure that CommonMessaging is initialized
636 }
MSG::Level setUpMessaging() const override final
SmartIF< ISvcLocator > m_svcLocator
Service locator (needed to access the MessageSvc).
const std::string & name() const override
Retrieve name of the service.

Member Function Documentation

◆ accept()

void concurrency::PrecedenceRulesGraph::accept ( IGraphVisitor & visitor) const

An entry point to visit all graph nodes.

Definition at line 544 of file PrecedenceRulesGraph.cpp.

544 {
545 // iterate through Algorithm nodes
546 for ( auto& pr : m_algoNameToAlgoNodeMap ) pr.second->accept( visitor );
547
548 // iterate through DecisionHub nodes
549 for ( auto& pr : m_decisionNameToDecisionHubMap ) pr.second->accept( visitor );
550
551 // iterate through Data [and Conditions] nodes
552 for ( auto& pr : m_dataPathToDataNodeMap ) pr.second->accept( visitor );
553 }
std::unordered_map< std::string, std::unique_ptr< DecisionNode > > m_decisionNameToDecisionHubMap
Index: map of decision's name to DecisionHub.
std::unordered_map< DataObjID, std::unique_ptr< DataNode >, DataObjID_Hasher > m_dataPathToDataNodeMap
Index: map of data path to DataNode.
std::unordered_map< std::string, std::unique_ptr< AlgorithmNode > > m_algoNameToAlgoNodeMap
Index: map of algorithm's name to AlgorithmNode.

◆ addAlgorithmNode()

StatusCode concurrency::PrecedenceRulesGraph::addAlgorithmNode ( Gaudi::Algorithm * daughterAlgo,
const std::string & parentName )

Add algorithm node.

Create new, or fetch existent, AlgorithmNode

Attach AlgorithmNode to its parent DecisionNode

Definition at line 378 of file PrecedenceRulesGraph.cpp.

378 {
379
380 StatusCode sc = StatusCode::SUCCESS;
381
383
384 auto& algoName = algo->name();
385
386 concurrency::AlgorithmNode* algoNode;
387
388 auto itA = m_algoNameToAlgoNodeMap.find( algoName );
389 if ( itA != m_algoNameToAlgoNodeMap.end() ) {
390 algoNode = itA->second.get();
391 } else {
392 auto r = m_algoNameToAlgoNodeMap.emplace(
393 algoName, std::make_unique<concurrency::AlgorithmNode>( *this, algo, m_nodeCounter, m_algoCounter ) );
394 algoNode = r.first->second.get();
395
396 // Mirror AlgorithmNode in the BGL-based graph
397 if ( m_enableAnalysis ) { boost::add_vertex( AlgoProps( algo, m_nodeCounter, m_algoCounter ), m_PRGraph ); }
400 ON_VERBOSE verbose() << "AlgorithmNode '" << algoName << "' added @ " << algoNode << endmsg;
401
402 registerIODataObjects( algo );
403 }
404
406 auto itP = m_decisionNameToDecisionHubMap.find( parentName );
407 if ( itP != m_decisionNameToDecisionHubMap.end() ) {
408 auto parentNode = itP->second.get();
409
410 parentNode->addDaughterNode( algoNode );
411 algoNode->addParentNode( parentNode );
412
413 // Mirror algorithm to CF parent relationship in the BGL-based graph
414 if ( m_enableAnalysis ) boost::add_edge( node( algo->name() ), node( parentName ), m_PRGraph );
415
416 ON_VERBOSE verbose() << "Attached AlgorithmNode '" << algo->name() << "' to parent DecisionNode '" << parentName
417 << "'" << endmsg;
418 } else {
420 error() << "Parent DecisionNode '" << parentName << "' was not found" << endmsg;
421 }
422
423 return sc;
424 }
#define ON_VERBOSE
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition MsgStream.h:198
MsgStream & error() const
shortcut for the method msgStream(MSG::ERROR)
MsgStream & verbose() const
shortcut for the method msgStream(MSG::VERBOSE)
constexpr static const auto SUCCESS
Definition StatusCode.h:99
constexpr static const auto FAILURE
Definition StatusCode.h:100
void addParentNode(DecisionNode *node)
Add a parent node.
void registerIODataObjects(const Gaudi::Algorithm *algo)
Register algorithm in the Data Dependency index.
precedence::PRGraph m_PRGraph
BGL-based graph of precedence rules.
PRVertexDesc node(const std::string &) const
unsigned int m_algoCounter
Total number of algorithm nodes in the graph.
unsigned int m_nodeCounter
Total number of nodes in the graph.

◆ addDataNode()

StatusCode concurrency::PrecedenceRulesGraph::addDataNode ( const DataObjID & dataPath)

Add DataNode that represents DataObject.

Definition at line 427 of file PrecedenceRulesGraph.cpp.

427 {
428
429 auto itD = m_dataPathToDataNodeMap.find( dataPath );
430 if ( itD != m_dataPathToDataNodeMap.end() ) return StatusCode::SUCCESS;
431
432 std::unique_ptr<concurrency::DataNode> dataNode;
434 dataNode = std::make_unique<concurrency::DataNode>( *this, dataPath );
435 ON_VERBOSE verbose() << " DataNode " << dataPath << " added @ " << dataNode.get() << endmsg;
436 // Mirror the action above in the BGL-based graph
437 if ( m_enableAnalysis ) boost::add_vertex( DataProps( dataPath ), m_PRGraph );
438 } else {
439 SmartIF<ICondSvc> condSvc{ serviceLocator()->service( "CondSvc", false ) };
440 if ( condSvc->isRegistered( dataPath ) ) {
441 dataNode = std::make_unique<concurrency::ConditionNode>( *this, dataPath, condSvc );
442 ON_VERBOSE verbose() << " ConditionNode " << dataPath << " added @ " << dataNode.get() << endmsg;
443 // Mirror the action above in the BGL-based graph
444 if ( m_enableAnalysis ) boost::add_vertex( CondDataProps( dataPath ), m_PRGraph );
445 } else {
446 dataNode = std::make_unique<concurrency::DataNode>( *this, dataPath );
447 ON_VERBOSE verbose() << " DataNode " << dataPath << " added @ " << dataNode.get() << endmsg;
448 // Mirror the action above in the BGL-based graph
449 if ( m_enableAnalysis ) boost::add_vertex( DataProps( dataPath ), m_PRGraph );
450 }
451 }
452 m_dataPathToDataNodeMap.emplace( dataPath, std::move( dataNode ) );
453 return StatusCode::SUCCESS;
454 }
virtual SmartIF< IService > & service(const Gaudi::Utils::TypeNameString &typeName, const bool createIf=true)=0
Returns a smart pointer to a service.
bool m_conditionsRealmEnabled
Enable conditions realm of precedence rules.
SmartIF< ISvcLocator > & serviceLocator() const override
Retrieve pointer to service locator.

◆ addDecisionHubNode()

StatusCode concurrency::PrecedenceRulesGraph::addDecisionHubNode ( Gaudi::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.

Create new, or fetch existent, DecisionNode

Attach DecisionNode to its parent DecisionNode

Definition at line 457 of file PrecedenceRulesGraph.cpp.

459 {
460
461 StatusCode sc = StatusCode::SUCCESS;
462
464
465 auto& decisionHubName = decisionHubAlgo->name();
466
467 auto itA = m_decisionNameToDecisionHubMap.find( decisionHubName );
468 concurrency::DecisionNode* decisionHubNode;
469 if ( itA != m_decisionNameToDecisionHubMap.end() ) {
470 decisionHubNode = itA->second.get();
471 } else {
472 auto r = m_decisionNameToDecisionHubMap.emplace(
473 decisionHubName,
474 std::make_unique<concurrency::DecisionNode>( *this, m_nodeCounter, decisionHubName, modeConcurrent,
475 modePromptDecision, modeOR, allPass, isInverted ) );
476 decisionHubNode = r.first->second.get();
477 // Mirror DecisionNode in the BGL-based graph
478 if ( m_enableAnalysis ) {
479 boost::add_vertex( DecisionHubProps( decisionHubName, m_nodeCounter, modeConcurrent, modePromptDecision, modeOR,
480 allPass, isInverted ),
481 m_PRGraph );
482 }
483
485
486 ON_VERBOSE verbose() << "DecisionNode '" << decisionHubName << "' added @ " << decisionHubNode << endmsg;
487 }
488
490 auto itP = m_decisionNameToDecisionHubMap.find( parentName );
491 if ( itP != m_decisionNameToDecisionHubMap.end() ) {
492 auto parentNode = itP->second.get();
493 parentNode->addDaughterNode( decisionHubNode );
494 decisionHubNode->addParentNode( parentNode );
495
496 // Mirror DecisionNode-to-DecisionNode relationship in the BGL-based graph
497 if ( m_enableAnalysis ) boost::add_edge( node( decisionHubName ), node( parentName ), m_PRGraph );
498
499 ON_VERBOSE verbose() << "Attached DecisionNode '" << decisionHubName << "' to parent DecisionNode '" << parentName
500 << "'" << endmsg;
501 } else {
503 error() << "Parent DecisionNode '" << parentName << "' was not found" << endmsg;
504 }
505
506 return sc;
507 }
void addParentNode(DecisionNode *node)
Add a parent node.

◆ addEdgeToPrecTrace()

void concurrency::PrecedenceRulesGraph::addEdgeToPrecTrace ( const AlgorithmNode * u,
const AlgorithmNode * v )

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

Definition at line 729 of file PrecedenceRulesGraph.cpp.

729 {
730
731 std::string u_name = u == nullptr ? "ENTRY" : u->name();
732 std::string v_name = v->name();
733
735
736 if ( !u ) {
737 auto itT = m_prec_trace_map.find( "ENTRY" );
738 if ( itT != m_prec_trace_map.end() ) {
739 source = itT->second;
740 } else {
741 source = boost::add_vertex( precedence::AlgoTraceProps( "ENTRY" ), m_precTrace );
742 m_prec_trace_map["ENTRY"] = source;
743 }
744 } else {
745 auto itS = m_prec_trace_map.find( u_name );
746 if ( itS != m_prec_trace_map.end() ) {
747 source = itS->second;
748 } else {
749
750 source =
751 boost::add_vertex( precedence::AlgoTraceProps( u_name, u->getAlgoIndex(), u->getRank() ), m_precTrace );
752 m_prec_trace_map[u_name] = source;
753 }
754 }
755
757
758 auto itP = m_prec_trace_map.find( v_name );
759 if ( itP != m_prec_trace_map.end() ) {
760 target = itP->second;
761 } else {
762
763 target = boost::add_vertex( precedence::AlgoTraceProps( v_name, v->getAlgoIndex(), v->getRank() ), m_precTrace );
764 m_prec_trace_map[v_name] = target;
765 }
766
767 boost::add_edge( source, target, m_precTrace );
768
769 ON_DEBUG debug() << u_name << "-->" << v_name << " precedence trait added" << endmsg;
770 }
#define ON_DEBUG
MsgStream & debug() const
shortcut for the method msgStream(MSG::DEBUG)
std::map< std::string, precedence::AlgoTraceVertex > m_prec_trace_map
precedence::PrecTrace m_precTrace
facilities for algorithm precedence tracing
boost::graph_traits< PrecTrace >::vertex_descriptor AlgoTraceVertex

◆ addHeadNode()

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 510 of file PrecedenceRulesGraph.cpp.

512 {
513
514 auto itH = m_decisionNameToDecisionHubMap.find( headName );
515 if ( itH != m_decisionNameToDecisionHubMap.end() ) {
516 m_headNode = itH->second.get();
517 } else {
518 auto r = m_decisionNameToDecisionHubMap.emplace(
519 headName, std::make_unique<concurrency::DecisionNode>( *this, m_nodeCounter, headName, modeConcurrent,
520 modePromptDecision, modeOR, allPass, isInverted ) );
521 m_headNode = r.first->second.get();
522
523 // Mirror the action above in the BGL-based graph
524 if ( m_enableAnalysis ) {
525 boost::add_vertex( DecisionHubProps( headName, m_nodeCounter, modeConcurrent, modePromptDecision, modeOR,
526 allPass, isInverted ),
527 m_PRGraph );
528 }
529
531 }
532 }
DecisionNode * m_headNode
the head node of the control flow graph

◆ buildDataDependenciesRealm()

StatusCode concurrency::PrecedenceRulesGraph::buildDataDependenciesRealm ( )

Build data dependency realm WITH data object nodes participating.

Definition at line 324 of file PrecedenceRulesGraph.cpp.

324 {
325
326 StatusCode global_sc = StatusCode::SUCCESS;
327
328 // Production of DataNodes by AlgorithmNodes (DataNodes are created here)
329 std::vector<decltype( m_algoNameToAlgoNodeMap )::value_type*> sortedAlgs;
330 for ( auto& algo : m_algoNameToAlgoNodeMap ) { sortedAlgs.push_back( &algo ); }
331 std::sort( sortedAlgs.begin(), sortedAlgs.end(),
332 []( const auto* a, const auto* b ) { return a->first < b->first; } );
333 for ( auto* algo : sortedAlgs ) {
334
335 auto& outputs = m_algoNameToAlgoOutputsMap[algo->first];
336 for ( auto output : outputs ) {
337 const auto sc = addDataNode( output );
338 if ( !sc.isSuccess() ) {
339 error() << "Extra producer (" << algo->first << ") for DataObject @ " << output
340 << " has been detected: this is not allowed." << endmsg;
341 global_sc = sc;
342 }
343 auto dataNode = getDataNode( output );
344 dataNode->addProducerNode( algo->second.get() );
345 algo->second->addOutputDataNode( dataNode );
346
347 // Mirror the action above in the BGL-based graph
348 if ( m_enableAnalysis ) boost::add_edge( node( algo->second->name() ), node( output.fullKey() ), m_PRGraph );
349 }
350 }
351
352 // Consumption of DataNodes by AlgorithmNodes
353 sortedAlgs.clear();
354 for ( auto& algo : m_algoNameToAlgoNodeMap ) { sortedAlgs.push_back( &algo ); }
355 std::sort( sortedAlgs.begin(), sortedAlgs.end(),
356 []( const auto* a, const auto* b ) { return a->first < b->first; } );
357 for ( auto* algo : sortedAlgs ) {
358
359 for ( auto input : m_algoNameToAlgoInputsMap[algo->first] ) {
360
361 auto itP = m_dataPathToDataNodeMap.find( input );
362
363 DataNode* dataNode = ( itP != m_dataPathToDataNodeMap.end() ? getDataNode( input ) : nullptr );
364 if ( dataNode ) {
365 dataNode->addConsumerNode( algo->second.get() );
366 algo->second->addInputDataNode( dataNode );
367
368 // Mirror the action above in the BGL-based graph
369 if ( m_enableAnalysis ) boost::add_edge( node( input.fullKey() ), node( algo->second->name() ), m_PRGraph );
370 }
371 }
372 }
373
374 return global_sc;
375 }
StatusCode addDataNode(const DataObjID &dataPath)
Add DataNode that represents DataObject.
DataNode * getDataNode(const DataObjID &dataPath) const
Get DataNode by DataObject path using graph index.
std::unordered_map< std::string, DataObjIDColl > m_algoNameToAlgoInputsMap
Indexes: maps of algorithm's name to algorithm's inputs/outputs.
std::unordered_map< std::string, DataObjIDColl > m_algoNameToAlgoOutputsMap

◆ dumpControlFlow() [1/2]

std::string concurrency::PrecedenceRulesGraph::dumpControlFlow ( ) const

Print out control flow of Algorithms and Sequences.

Definition at line 566 of file PrecedenceRulesGraph.cpp.

566 {
567 std::ostringstream ost;
568 dumpControlFlow( ost, m_headNode, 0 );
569 return ost.str();
570 }
std::string dumpControlFlow() const
Print out control flow of Algorithms and Sequences.

◆ dumpControlFlow() [2/2]

void concurrency::PrecedenceRulesGraph::dumpControlFlow ( std::ostringstream & ost,
ControlFlowNode * node,
const int & indent ) const

Definition at line 572 of file PrecedenceRulesGraph.cpp.

573 {
574 ost << std::string( indent * 2, ' ' );
575 DecisionNode* dn = dynamic_cast<DecisionNode*>( node );
576 AlgorithmNode* an = dynamic_cast<AlgorithmNode*>( node );
577 if ( dn != 0 ) {
578 if ( node != m_headNode ) {
579 ost << node->name() << " [Seq] ";
580 ost << ( ( dn->m_modeConcurrent ) ? " [Concurrent] " : " [Sequential] " );
581 ost << ( ( dn->m_modePromptDecision ) ? " [Prompt] " : "" );
582 ost << ( ( dn->m_modeOR ) ? " [OR] " : "" );
583 ost << ( ( dn->m_allPass ) ? " [PASS] " : "" );
584 ost << "\n";
585 }
586 for ( const auto& i : dn->getDaughters() ) dumpControlFlow( ost, i, indent + 1 );
587 } else if ( an != 0 ) {
588 ost << node->name() << " [Alg] ";
589 auto ar = an->getAlgorithm();
590 ost << " [n= " << ar->cardinality() << "]";
591 ost << ( ( !ar->isClonable() ) ? " [unclonable] " : "" );
592 ost << "\n";
593 }
594 }

◆ dumpDataFlow()

std::string concurrency::PrecedenceRulesGraph::dumpDataFlow ( ) const

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

Definition at line 597 of file PrecedenceRulesGraph.cpp.

597 {
598
599 const char idt[] = " ";
600 std::ostringstream ost;
601
602 ost << "\n" << idt << "====================================\n";
603 ost << idt << "Data origins and destinations:\n";
604 ost << idt << "====================================\n";
605
606 std::vector<const DataObjID*> vec;
607 vec.reserve( m_dataPathToDataNodeMap.size() );
608 for ( auto& pair : m_dataPathToDataNodeMap ) { vec.push_back( &pair.first ); }
609 std::sort( vec.begin(), vec.end(),
610 []( const DataObjID* a, const DataObjID* b ) { return a->fullKey() < b->fullKey(); } );
611
612 for ( const DataObjID* id : vec ) {
613 const DataNode& node = *m_dataPathToDataNodeMap.find( *id )->second;
614
615 for ( auto algoNode : node.getProducers() ) ost << idt << " " << algoNode->name() << "\n";
616
617 ost << idt << " V\n";
618 ost << idt << " o " << id << "\n";
619 ost << idt << " V\n";
620
621 for ( auto algoNode : node.getConsumers() ) ost << idt << " " << algoNode->name() << "\n";
622
623 ost << idt << "====================================\n";
624 }
625
626 return ost.str();
627 }

◆ dumpPrecRules()

void concurrency::PrecedenceRulesGraph::dumpPrecRules ( const std::filesystem::path & fileName,
const EventSlot & slot )

dump to file the precedence rules

Definition at line 631 of file PrecedenceRulesGraph.cpp.

631 {
632 std::ofstream myfile;
633 myfile.open( fileName.c_str(), std::ios::app );
634
635 // Declare properties to dump
636 boost::dynamic_properties dp;
637
638 dp.property( "Entity",
639 boost::make_transform_value_property_map(
640 []( const VariantVertexProps& v ) {
641 return std::visit( []( const auto& w ) { return boost::lexical_cast<std::string>( w ); }, v );
642 },
643 boost::get( boost::vertex_bundle, m_PRGraph ) ) );
644
645 auto add_prop = [&]( auto name, auto&& vis ) {
646 dp.property( name, boost::make_transform_value_property_map(
647 [vis = std::forward<decltype( vis )>( vis )]( const VariantVertexProps& v ) {
648 return std::visit( vis, v );
649 },
650 boost::get( boost::vertex_bundle, m_PRGraph ) ) );
651 };
652
653 add_prop( "Name", precedence::VertexName() );
654 add_prop( "Mode", precedence::GroupMode() );
655 add_prop( "Logic", precedence::GroupLogic() );
656 add_prop( "Decision Negation", precedence::DecisionNegation() );
657 add_prop( "Negative Decision Inversion", precedence::AllPass() );
658 add_prop( "Exit Policy", precedence::GroupExit() );
659 add_prop( "Operations", precedence::Operations() );
660 add_prop( "CF Decision", precedence::CFDecision( slot ) );
661 add_prop( "State", precedence::EntityState( slot, serviceLocator(), m_conditionsRealmEnabled ) );
662 add_prop( "Start Time (Epoch ns)", precedence::StartTime( slot, serviceLocator() ) );
663 add_prop( "End Time (Epoch ns)", precedence::EndTime( slot, serviceLocator() ) );
664 add_prop( "Runtime (ns)", precedence::Duration( slot, serviceLocator() ) );
665
666 boost::write_graphml( myfile, m_PRGraph, dp );
667
668 myfile.close();
669 }
std::variant< AlgoProps, DecisionHubProps, DataProps, CondDataProps > VariantVertexProps

◆ dumpPrecTrace()

void concurrency::PrecedenceRulesGraph::dumpPrecTrace ( const std::filesystem::path & fileName,
const EventSlot & slot )

dump to file the precedence trace

Definition at line 672 of file PrecedenceRulesGraph.cpp.

672 {
673 std::ofstream myfile;
674 myfile.open( fileName.c_str(), std::ios::app );
675
676 // Fill runtimes (as this could not be done on the fly during trace assembling)
677 SmartIF<ITimelineSvc> timelineSvc = m_svcLocator->service<ITimelineSvc>( "TimelineSvc", false );
678 if ( !timelineSvc.isValid() ) {
679 warning() << "Failed to get the TimelineSvc, timing will not be added to "
680 << "the task precedence trace dump" << endmsg;
681 } else {
682
683 std::vector<long long int> start_times;
684
685 for ( auto vp = vertices( m_precTrace ); vp.first != vp.second; ++vp.first ) {
686 TimelineEvent te{};
687 te.algorithm = m_precTrace[*vp.first].m_name;
688 te.slot = slot.eventContext->slot();
689 te.event = slot.eventContext->evt();
690 // This calculates duration that is the difference between stop and start time which for asynchronous algorithms
691 // is not the same as the time spent in the algorithm itself. Perhaps it should be changed to elapsed time.
692 timelineSvc->getFirstMatching( te );
693 auto start_point = te.start;
694 timelineSvc->getLastMatching( te );
695 auto end_point = te.end;
696 long int runtime{ std::chrono::duration_cast<std::chrono::microseconds>( end_point - start_point ).count() };
697 m_precTrace[*vp.first].m_runtime = runtime;
698
699 long long int start{
700 std::chrono::duration_cast<std::chrono::nanoseconds>( start_point.time_since_epoch() ).count() };
701 m_precTrace[*vp.first].m_start = start;
702 if ( start != 0 ) start_times.push_back( start );
703 }
704
705 auto min = std::min_element( start_times.begin(), start_times.end() );
706
707 for ( auto vp = vertices( m_precTrace ); vp.first != vp.second; ++vp.first ) {
708
709 auto& oldValue = m_precTrace[*vp.first].m_start;
710
711 if ( oldValue != 0 ) oldValue = oldValue - *min;
712 }
713 }
714
715 // Declare properties to dump
716 boost::dynamic_properties dp;
717 using boost::get;
718 using precedence::AlgoTraceProps;
719 dp.property( "Name", get( &AlgoTraceProps::m_name, m_precTrace ) );
720 dp.property( "Rank", get( &AlgoTraceProps::m_rank, m_precTrace ) );
721 dp.property( "Run Time (us)", get( &AlgoTraceProps::m_runtime, m_precTrace ) );
722 dp.property( "Start Time (ns)", get( &AlgoTraceProps::m_start, m_precTrace ) );
723
724 boost::write_graphml( myfile, m_precTrace, dp );
725
726 myfile.close();
727 }
MsgStream & warning() const
shortcut for the method msgStream(MSG::WARNING)
ContextEvt_t evt() const
ContextID_t slot() const
bool isValid() const
Allow for check if smart pointer is valid.
Definition SmartIF.h:69
get
decorate the vector of properties
Definition decorators.py:94
std::unique_ptr< EventContext > eventContext
Cache for the eventContext.
Definition EventSlot.h:82
time_point start
time_point end
std::string algorithm

◆ enableAnalysis()

void concurrency::PrecedenceRulesGraph::enableAnalysis ( )
inline

BGL-based facilities.

Definition at line 683 of file PrecedenceRulesGraph.h.

683{ m_enableAnalysis = true; }

◆ getAlgorithmNode()

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

Get the AlgorithmNode from by algorithm name using graph index.

Definition at line 661 of file PrecedenceRulesGraph.h.

661 {
662 return m_algoNameToAlgoNodeMap.at( algoName ).get();
663 }

◆ getControlFlowNodeCounter()

unsigned int concurrency::PrecedenceRulesGraph::getControlFlowNodeCounter ( ) const
inline

Get total number of control flow graph nodes.

Definition at line 669 of file PrecedenceRulesGraph.h.

669{ return m_nodeCounter; }

◆ getDataNode()

DataNode * concurrency::PrecedenceRulesGraph::getDataNode ( const DataObjID & dataPath) const
inline

Get DataNode by DataObject path using graph index.

Definition at line 647 of file PrecedenceRulesGraph.h.

647{ return m_dataPathToDataNodeMap.at( dataPath ).get(); }

◆ getHeadNode()

DecisionNode * concurrency::PrecedenceRulesGraph::getHeadNode ( ) const
inline

Get head node.

Definition at line 657 of file PrecedenceRulesGraph.h.

657{ return m_headNode; }

◆ initialize()

StatusCode concurrency::PrecedenceRulesGraph::initialize ( )

Initialize graph.

Definition at line 226 of file PrecedenceRulesGraph.cpp.

226 {
227 if ( serviceLocator()->existsService( "CondSvc" ) ) {
228 SmartIF<ICondSvc> condSvc{ serviceLocator()->service( "CondSvc" ) };
229 if ( condSvc.isValid() ) {
230 info() << "CondSvc found. DF precedence rules will be augmented with 'Conditions'" << endmsg;
232 }
233 }
234
235 // Detach condition algorithms from the CF realm
237 SmartIF<ICondSvc> condSvc{ serviceLocator()->service( "CondSvc", false ) };
238 auto& condAlgs = condSvc->condAlgs();
239 for ( const auto algo : condAlgs ) {
240 auto itA = m_algoNameToAlgoNodeMap.find( algo->name() );
241 if ( itA != m_algoNameToAlgoNodeMap.end() ) {
242 concurrency::AlgorithmNode* algoNode = itA->second.get();
243 debug() << "Detaching condition algorithm '" << algo->name() << "' from the CF realm.." << endmsg;
244 for ( auto parent : algoNode->getParentDecisionHubs() ) {
245 parent->m_children.erase( std::remove( parent->m_children.begin(), parent->m_children.end(), algoNode ),
246 parent->m_children.end() );
247 // clean up also auxiliary BGL-based graph of precedence rules
248 if ( m_enableAnalysis ) boost::remove_edge( node( algoNode->name() ), node( parent->name() ), m_PRGraph );
249 }
250 algoNode->m_parents.clear();
251
252 } else {
253 warning() << "Algorithm '" << algo->name() << "' is not registered in the graph" << endmsg;
254 }
255 }
256 }
257
258 StatusCode sc = buildDataDependenciesRealm();
259
260 if ( !sc.isSuccess() ) error() << "Could not build the data dependency realm." << endmsg;
261
262 return sc;
263 }
MsgStream & info() const
shortcut for the method msgStream(MSG::INFO)
bool isSuccess() const
Definition StatusCode.h:302
std::vector< DecisionNode * > m_parents
Control flow parents of an AlgorithmNode (DecisionNodes).
const std::vector< DecisionNode * > & getParentDecisionHubs() const
Get all parent decision hubs.
const std::string & name() const
Get node name.
StatusCode buildDataDependenciesRealm()
Build data dependency realm WITH data object nodes participating.

◆ name()

const std::string & concurrency::PrecedenceRulesGraph::name ( ) const
inlineoverride

Retrieve name of the service.

Definition at line 675 of file PrecedenceRulesGraph.h.

675{ return m_name; }

◆ node()

PRVertexDesc concurrency::PrecedenceRulesGraph::node ( const std::string & name) const

Definition at line 535 of file PrecedenceRulesGraph.cpp.

535 {
536 auto vp = vertices( m_PRGraph );
537 auto i = std::find_if( vp.first, vp.second, [&]( const PRVertexDesc& v ) {
538 return std::visit( precedence::VertexName(), m_PRGraph[v] ) == name;
539 } );
540 return i != vp.second ? *i : PRVertexDesc{};
541 }
boost::graph_traits< PRGraph >::vertex_descriptor PRVertexDesc

◆ printState()

void concurrency::PrecedenceRulesGraph::printState ( std::stringstream & output,
EventSlot & slot,
const unsigned int & recursionLevel ) const

Print a string representing the control flow state.

Definition at line 266 of file PrecedenceRulesGraph.cpp.

267 {
268 if ( slot.parentSlot ) {
269 // Start at sub-slot entry point
270 m_decisionNameToDecisionHubMap.at( slot.entryPoint )->printState( output, slot, recursionLevel );
271 } else {
272 // Start at the head node for whole-event slots
273 m_headNode->printState( output, slot, recursionLevel );
274 }
275
276 // Find detached conditions algs in interesting states
278 bool firstPrint = true;
279 SmartIF<ICondSvc> condSvc{ serviceLocator()->service( "CondSvc", false ) };
280 auto& condAlgs = condSvc->condAlgs();
281 for ( const auto algo : condAlgs ) {
282 auto itA = m_algoNameToAlgoNodeMap.find( algo->name() );
283 if ( itA != m_algoNameToAlgoNodeMap.end() ) {
284
285 concurrency::AlgorithmNode* algoNode = itA->second.get();
286
287 // Ignore boring states (reduces verbosity)
288 auto& thisState = slot.algsStates[algoNode->getAlgoIndex()];
289 if ( thisState == AlgsExecutionStates::State::INITIAL ||
291 continue;
292
293 // Make output
294 if ( firstPrint ) {
295 firstPrint = false;
296 output << std::endl << "Detached algorithms:" << std::endl;
297 }
298 algoNode->printState( output, slot, recursionLevel );
299 }
300 }
301 }
302 }
unsigned int getAlgoIndex() const
Get algorithm index.
void printState(std::stringstream &output, EventSlot &slot, const unsigned int &recursionLevel) const override
Print a string representing the control flow state.
EventSlot * parentSlot
Pointer to parent slot (null for top level).
Definition EventSlot.h:95
std::string entryPoint
Event Views bookkeeping (TODO: optimize view bookkeeping).
Definition EventSlot.h:93
AlgsExecutionStates algsStates
Vector of algorithms states.
Definition EventSlot.h:84

◆ rankAlgorithms()

void concurrency::PrecedenceRulesGraph::rankAlgorithms ( IGraphVisitor & ranker) const

Rank Algorithm nodes by the number of data outputs.

Definition at line 556 of file PrecedenceRulesGraph.cpp.

556 {
557
558 info() << "Starting ranking by data outputs .. " << endmsg;
559 for ( auto& pair : m_algoNameToAlgoNodeMap ) {
560 ON_DEBUG debug() << " Ranking " << pair.first << "... " << endmsg;
561 pair.second->accept( ranker );
562 ON_DEBUG debug() << " ... rank of " << pair.first << ": " << pair.second->getRank() << endmsg;
563 }
564 }

◆ registerIODataObjects()

void concurrency::PrecedenceRulesGraph::registerIODataObjects ( const Gaudi::Algorithm * algo)

Register algorithm in the Data Dependency index.

Definition at line 305 of file PrecedenceRulesGraph.cpp.

305 {
306
307 const std::string& algoName = algo->name();
308
309 m_algoNameToAlgoInputsMap[algoName] = algo->inputDataObjs();
310 m_algoNameToAlgoOutputsMap[algoName] = algo->outputDataObjs();
311
312 ON_VERBOSE {
313 verbose() << " Inputs of " << algoName << ": ";
314 for ( auto tag : algo->inputDataObjs() ) verbose() << tag << " | ";
315 verbose() << endmsg;
316
317 verbose() << " Outputs of " << algoName << ": ";
318 for ( auto tag : algo->outputDataObjs() ) verbose() << tag << " | ";
319 verbose() << endmsg;
320 }
321 }
const DataObjIDColl & outputDataObjs() const override
const DataObjIDColl & inputDataObjs() const override
const std::string & name() const override
The identifying name of the algorithm object.

◆ serviceLocator()

SmartIF< ISvcLocator > & concurrency::PrecedenceRulesGraph::serviceLocator ( ) const
inlineoverride

Retrieve pointer to service locator.

Definition at line 677 of file PrecedenceRulesGraph.h.

677{ return m_svcLocator; }

Member Data Documentation

◆ m_algoCounter

unsigned int concurrency::PrecedenceRulesGraph::m_algoCounter = 0
private

Total number of algorithm nodes in the graph.

Definition at line 715 of file PrecedenceRulesGraph.h.

◆ m_algoNameToAlgoInputsMap

std::unordered_map<std::string, DataObjIDColl> concurrency::PrecedenceRulesGraph::m_algoNameToAlgoInputsMap
private

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

Definition at line 709 of file PrecedenceRulesGraph.h.

◆ m_algoNameToAlgoNodeMap

std::unordered_map<std::string, std::unique_ptr<AlgorithmNode> > concurrency::PrecedenceRulesGraph::m_algoNameToAlgoNodeMap
private

Index: map of algorithm's name to AlgorithmNode.

Definition at line 703 of file PrecedenceRulesGraph.h.

◆ m_algoNameToAlgoOutputsMap

std::unordered_map<std::string, DataObjIDColl> concurrency::PrecedenceRulesGraph::m_algoNameToAlgoOutputsMap
private

Definition at line 710 of file PrecedenceRulesGraph.h.

◆ m_conditionsRealmEnabled

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

Enable conditions realm of precedence rules.

Definition at line 729 of file PrecedenceRulesGraph.h.

729{ false };

◆ m_dataPathToDataNodeMap

std::unordered_map<DataObjID, std::unique_ptr<DataNode>, DataObjID_Hasher> concurrency::PrecedenceRulesGraph::m_dataPathToDataNodeMap
private

Index: map of data path to DataNode.

Definition at line 707 of file PrecedenceRulesGraph.h.

◆ m_decisionNameToDecisionHubMap

std::unordered_map<std::string, std::unique_ptr<DecisionNode> > concurrency::PrecedenceRulesGraph::m_decisionNameToDecisionHubMap
private

Index: map of decision's name to DecisionHub.

Definition at line 705 of file PrecedenceRulesGraph.h.

◆ m_enableAnalysis

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

Definition at line 724 of file PrecedenceRulesGraph.h.

724{ false };

◆ m_headNode

DecisionNode* concurrency::PrecedenceRulesGraph::m_headNode = nullptr
private

the head node of the control flow graph

Definition at line 701 of file PrecedenceRulesGraph.h.

◆ m_name

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

Definition at line 719 of file PrecedenceRulesGraph.h.

◆ m_nodeCounter

unsigned int concurrency::PrecedenceRulesGraph::m_nodeCounter = 0
private

Total number of nodes in the graph.

Definition at line 713 of file PrecedenceRulesGraph.h.

◆ m_prec_trace_map

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

Definition at line 723 of file PrecedenceRulesGraph.h.

◆ m_precTrace

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

facilities for algorithm precedence tracing

Definition at line 722 of file PrecedenceRulesGraph.h.

◆ m_PRGraph

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

BGL-based graph of precedence rules.

Definition at line 726 of file PrecedenceRulesGraph.h.

◆ m_svcLocator

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

Service locator (needed to access the MessageSvc).

Definition at line 718 of file PrecedenceRulesGraph.h.


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