17 #include <boost/property_map/transform_value_property_map.hpp>
20 #define ON_DEBUG if ( msgLevel( MSG::DEBUG ) )
21 #define ON_VERBOSE if ( msgLevel( MSG::VERBOSE ) )
26 const char* stateToString(
const int& stateId ) {
54 const unsigned int& recursionLevel )
const {
61 for (
auto daughter :
m_children ) daughter->printState(
output, slot, recursionLevel + 2 );
69 bool result = visitor.
visit( *
this );
78 const unsigned int& recursionLevel )
const {
82 std::string indent( recursionLevel,
' ' );
86 <<
", in state: " << states[
m_algoIndex] << std::endl;
89 if ( states[
m_algoIndex] == AlgsExecutionStates::State::CONTROLREADY ) {
92 output << indent <<
"========" << std::endl;
98 bool wasProduced =
false;
99 if ( conditionNode ) {
102 wasProduced = !visitor.
visitEnter( *conditionNode );
105 wasProduced = visitor.visit( *dataNode );
109 if ( !wasProduced ) {
113 output << indent <<
"missing conditions data: " << dataNode->name() << std::endl;
115 output << indent <<
"missing data: " << dataNode->name() << std::endl;
121 output << indent <<
"required by tool:";
122 for (
auto const& holderName : finder.
holderNames() ) {
123 if ( holderName != this->
name() ) output <<
" " << holderName;
128 if ( conditionNode ) {
131 std::vector<EventIDRange> validRanges;
132 conditionNode->
m_condSvc->validRanges( validRanges, dataNode->name() )
134 for (
auto&
range : validRanges ) {
output << indent <<
"interval of validity: " <<
range << std::endl; }
135 if ( validRanges.empty() )
output << indent <<
"no interval(s) of validity" << std::endl;
138 output << indent <<
"can be produced by alg(s): ";
139 for (
auto algoNode : dataNode->getProducers() ) {
140 output <<
"( " << algoNode->name() <<
" in state: " << states[algoNode->getAlgoIndex()] <<
" ) ";
146 if ( !conditionNode ) {
147 std::vector<EventSlot>* testSubSlots = &slot.
allSubSlots;
155 if ( visitor.visit( *dataNode ) ) {
156 output << indent <<
"data is available at whole-event level" << std::endl;
161 for (
auto& pair : *subSlotMap ) {
162 if ( pair.second.size() > 0 ) {
163 bool madeLine =
false;
166 for (
int slotIndex : pair.second ) {
168 EventSlot* subSlot = &testSubSlots->at( slotIndex );
169 visitor.m_slot = subSlot;
170 if ( visitor.visit( *dataNode ) ) {
174 output << indent <<
"data is available in sub-slot(s) ";
177 output << slotIndex <<
", ";
180 if ( madeLine ) {
output <<
"entered from " << pair.first << std::endl; }
186 output << indent <<
"========" << std::endl;
194 visitor.
visit( *
this );
224 info() <<
"CondSvc found. DF precedence rules will be augmented with 'Conditions'" <<
endmsg;
232 auto& condAlgs =
condSvc->condAlgs();
233 for (
const auto algo : condAlgs ) {
237 debug() <<
"Detaching condition algorithm '" << algo->
name() <<
"' from the CF realm.." <<
endmsg;
239 parent->m_children.erase( std::remove( parent->m_children.begin(), parent->m_children.end(), algoNode ),
240 parent->m_children.end() );
247 warning() <<
"Algorithm '" << algo->name() <<
"' is not registered in the graph" <<
endmsg;
254 if ( !sc.
isSuccess() ) error() <<
"Could not build the data dependency realm." <<
endmsg;
261 const unsigned int& recursionLevel )
const {
272 bool firstPrint =
true;
274 auto& condAlgs =
condSvc->condAlgs();
275 for (
const auto algo : condAlgs ) {
283 if ( thisState == AlgsExecutionStates::State::INITIAL ||
284 thisState == AlgsExecutionStates::State::EVTACCEPTED )
290 output << std::endl <<
"Detached algorithms:" << std::endl;
301 const std::string& algoName = algo->
name();
307 verbose() <<
" Inputs of " << algoName <<
": ";
311 verbose() <<
" Outputs of " << algoName <<
": ";
325 std::sort( sortedAlgs.begin(), sortedAlgs.end(),
326 [](
const auto* a,
const auto* b ) { return a->first < b->first; } );
327 for (
auto* algo : sortedAlgs ) {
330 for (
auto output : outputs ) {
332 if ( !sc.isSuccess() ) {
333 error() <<
"Extra producer (" << algo->first <<
") for DataObject @ " <<
output
334 <<
" has been detected: this is not allowed." <<
endmsg;
338 dataNode->addProducerNode( algo->second.get() );
339 algo->second->addOutputDataNode( dataNode );
349 std::sort( sortedAlgs.begin(), sortedAlgs.end(),
350 [](
const auto* a,
const auto* b ) { return a->first < b->first; } );
351 for (
auto* algo : sortedAlgs ) {
360 algo->second->addInputDataNode( dataNode );
378 auto& algoName = algo->
name();
384 algoNode = itA->second.get();
388 algoNode = r.first->second.get();
402 auto parentNode = itP->second.get();
404 parentNode->addDaughterNode( algoNode );
410 ON_VERBOSE verbose() <<
"Attached AlgorithmNode '" << algo->
name() <<
"' to parent DecisionNode '" << parentName
414 error() <<
"Parent DecisionNode '" << parentName <<
"' was not found" <<
endmsg;
426 std::unique_ptr<concurrency::DataNode> dataNode;
428 dataNode = std::make_unique<concurrency::DataNode>( *
this, dataPath );
434 if (
condSvc->isRegistered( dataPath ) ) {
435 dataNode = std::make_unique<concurrency::ConditionNode>( *
this, dataPath,
condSvc );
440 dataNode = std::make_unique<concurrency::DataNode>( *
this, dataPath );
459 auto& decisionHubName = decisionHubAlgo->
name();
464 decisionHubNode = itA->second.get();
468 std::make_unique<concurrency::DecisionNode>( *
this,
m_nodeCounter, decisionHubName, modeConcurrent,
469 modePromptDecision, modeOR, allPass, isInverted ) );
470 decisionHubNode = r.first->second.get();
474 allPass, isInverted ),
486 auto parentNode = itP->second.get();
487 parentNode->addDaughterNode( decisionHubNode );
493 ON_VERBOSE verbose() <<
"Attached DecisionNode '" << decisionHubName <<
"' to parent DecisionNode '" << parentName
497 error() <<
"Parent DecisionNode '" << parentName <<
"' was not found" <<
endmsg;
513 headName, std::make_unique<concurrency::DecisionNode>( *
this,
m_nodeCounter, headName, modeConcurrent,
514 modePromptDecision, modeOR, allPass, isInverted ) );
520 allPass, isInverted ),
531 auto i = std::find_if( vp.first, vp.second, [&](
const PRVertexDesc&
v ) {
532 return std::visit( precedence::VertexName(), m_PRGraph[v] ) == name;
552 info() <<
"Starting ranking by data outputs .. " <<
endmsg;
554 ON_DEBUG debug() <<
" Ranking " << pair.first <<
"... " <<
endmsg;
555 pair.second->accept( ranker );
556 ON_DEBUG debug() <<
" ... rank of " << pair.first <<
": " << pair.second->getRank() <<
endmsg;
561 std::ostringstream ost;
567 const int& indent )
const {
568 ost << std::string( indent * 2,
' ' );
573 ost <<
node->name() <<
" [Seq] ";
576 ost << ( ( dn->
m_modeOR ) ?
" [OR] " :
"" );
577 ost << ( ( dn->
m_allPass ) ?
" [PASS] " :
"" );
581 }
else if ( an != 0 ) {
582 ost <<
node->name() <<
" [Alg] ";
585 ost << ( ( !ar->isClonable() ) ?
" [unclonable] " :
"" );
593 const char idt[] =
" ";
594 std::ostringstream ost;
596 ost <<
"\n" << idt <<
"====================================\n";
597 ost << idt <<
"Data origins and destinations:\n";
598 ost << idt <<
"====================================\n";
600 std::vector<const DataObjID*> vec;
603 std::sort( vec.begin(), vec.end(),
604 [](
const DataObjID* a,
const DataObjID* b ) { return a->fullKey() < b->fullKey(); } );
609 for (
auto algoNode :
node.getProducers() ) ost << idt <<
" " << algoNode->name() <<
"\n";
611 ost << idt <<
" V\n";
612 ost << idt <<
" o " <<
id <<
"\n";
613 ost << idt <<
" V\n";
615 for (
auto algoNode :
node.getConsumers() ) ost << idt <<
" " << algoNode->name() <<
"\n";
617 ost << idt <<
"====================================\n";
626 std::ofstream myfile;
630 boost::dynamic_properties dp;
632 dp.property(
"Entity",
633 boost::make_transform_value_property_map(
635 return std::visit( [](
const auto& w ) {
return boost::lexical_cast<std::string>( w ); },
v );
639 auto add_prop = [&](
auto name,
auto&& vis ) {
640 dp.property(
name, boost::make_transform_value_property_map(
642 return std::visit( vis,
v );
660 boost::write_graphml( myfile,
m_PRGraph, dp );
667 std::ofstream myfile;
672 if ( !timelineSvc.
isValid() ) {
673 warning() <<
"Failed to get the TimelineSvc, timing will not be added to "
674 <<
"the task precedence trace dump" <<
endmsg;
677 std::vector<long long int> start_times;
679 for (
auto vp = vertices(
m_precTrace ); vp.first != vp.second; ++vp.first ) {
684 timelineSvc->getTimelineEvent( te );
686 long int runtime{ std::chrono::duration_cast<std::chrono::microseconds>( te.end - te.start ).count() };
690 std::chrono::duration_cast<std::chrono::nanoseconds>( te.start.time_since_epoch() ).count() };
692 if (
start != 0 ) start_times.push_back(
start );
695 auto min = std::min_element( start_times.begin(), start_times.end() );
697 for (
auto vp = vertices(
m_precTrace ); vp.first != vp.second; ++vp.first ) {
701 if ( oldValue != 0 ) oldValue = oldValue - *min;
706 boost::dynamic_properties dp;
709 dp.property(
"Name",
get( &AlgoTraceProps::m_name,
m_precTrace ) );
710 dp.property(
"Rank",
get( &AlgoTraceProps::m_rank,
m_precTrace ) );
711 dp.property(
"Run Time (us)",
get( &AlgoTraceProps::m_runtime,
m_precTrace ) );
712 dp.property(
"Start Time (ns)",
get( &AlgoTraceProps::m_start,
m_precTrace ) );
721 std::string u_name = u ==
nullptr ?
"ENTRY" : u->
name();
722 std::string v_name =
v->name();
729 source = itT->second;
737 source = itS->second;
759 ON_DEBUG debug() << u_name <<
"-->" << v_name <<
" precedence trait added" <<
endmsg;