The Gaudi Framework  v31r0 (aeb156f0)
concurrency::Supervisor Class Reference

#include <src/PRGraphVisitors.h>

Inheritance diagram for concurrency::Supervisor:
Collaboration diagram for concurrency::Supervisor:

Public Member Functions

 Supervisor (EventSlot &slot, const Cause &cause, bool ifTrace=false)
 Constructor. More...
 
bool visitEnter (DecisionNode &) const override
 
bool visit (DecisionNode &) override
 
bool visitEnter (AlgorithmNode &) const override
 
bool visit (AlgorithmNode &) override
 
- Public Member Functions inherited from concurrency::IGraphVisitor
virtual ~IGraphVisitor ()=default
 
virtual bool visitEnter (DataNode &) const
 
virtual bool visit (DataNode &)
 
virtual bool visitEnter (ConditionNode &) const
 
virtual bool visit (ConditionNode &)
 
virtual void reset ()
 

Public Attributes

EventSlotm_slot
 
Cause m_cause
 
bool m_trace
 

Detailed Description

Definition at line 51 of file PRGraphVisitors.h.

Constructor & Destructor Documentation

concurrency::Supervisor::Supervisor ( EventSlot slot,
const Cause cause,
bool  ifTrace = false 
)
inline

Constructor.

Definition at line 54 of file PRGraphVisitors.h.

55  : m_slot( &slot ), m_cause( cause ), m_trace( ifTrace ){};

Member Function Documentation

bool concurrency::Supervisor::visit ( DecisionNode node)
overridevirtual

Reimplemented from concurrency::IGraphVisitor.

Definition at line 168 of file PRGraphVisitors.cpp.

168  {
169 
170  bool foundNonResolvedChild = false;
171  bool foundNegativeChild = false;
172  bool foundPositiveChild = false;
173  int decision = -1;
174 
175  // Leave a sub-slot if this is the exit node
176  EventSlot* oldSlot = nullptr;
177  if ( m_slot->parentSlot && m_slot->entryPoint == node.getNodeName() ) {
178  oldSlot = m_slot;
180  }
181 
182  // If children are in sub-slots, loop over all
183  auto searchResult = m_slot->subSlotsByNode.find( node.getNodeName() );
184  if ( searchResult != m_slot->subSlotsByNode.end() ) {
185  bool breakout = false;
186  for ( unsigned int slotIndex : searchResult->second ) {
187 
188  // Enter the sub-slot
189  m_slot = &( m_slot->allSubSlots[slotIndex] );
190 
191  for ( auto child : node.getDaughters() ) {
192 
193  int& childDecision = m_slot->controlFlowState[child->getNodeIndex()];
194 
195  if ( childDecision == -1 )
196  foundNonResolvedChild = true;
197  else if ( childDecision == 1 )
198  foundPositiveChild = true;
199  else
200  foundNegativeChild = true;
201 
202  if ( node.m_modePromptDecision ) {
203  if ( node.m_modeOR && foundPositiveChild ) {
204  decision = 1;
205  breakout = true;
206  break;
207  } else if ( !node.m_modeOR && foundNegativeChild ) {
208  decision = 0;
209  breakout = true;
210  break;
211  }
212  } else {
213  if ( foundNonResolvedChild ) {
214  breakout = true;
215  break;
216  }
217  }
218  }
219 
220  // Leave the sub-slot
222  if ( breakout ) break;
223  }
224  } else {
225  for ( auto child : node.getDaughters() ) {
226  int& childDecision = m_slot->controlFlowState[child->getNodeIndex()];
227 
228  if ( childDecision == -1 )
229  foundNonResolvedChild = true;
230  else if ( childDecision == 1 )
231  foundPositiveChild = true;
232  else
233  foundNegativeChild = true;
234 
235  if ( node.m_modePromptDecision ) {
236  if ( node.m_modeOR && foundPositiveChild ) {
237  decision = 1;
238  break;
239  } else if ( !node.m_modeOR && foundNegativeChild ) {
240  decision = 0;
241  break;
242  }
243  } else {
244  if ( foundNonResolvedChild ) break;
245  }
246  }
247  } // end monitoring children
248 
249  if ( !foundNonResolvedChild && decision == -1 ) {
250  if ( node.m_modeOR ) { // OR
251  if ( foundPositiveChild )
252  decision = 1;
253  else
254  decision = 0;
255  } else { // AND
256  if ( foundNegativeChild )
257  decision = 0;
258  else
259  decision = 1;
260  }
261  }
262 
263  if ( node.m_inverted && decision == 1 )
264  decision = 0;
265  else if ( node.m_inverted && decision == 0 )
266  decision = 1;
267 
268  if ( node.m_allPass && !foundNonResolvedChild ) decision = 1;
269 
270  if ( decision != -1 ) {
271  m_slot->controlFlowState[node.getNodeIndex()] = decision;
272 
273  // if a decision was made for this node, propagate the result upwards
274  for ( auto parent : node.m_parents ) { parent->accept( *this ); }
275 
276  if ( oldSlot ) m_slot = oldSlot;
277  return true;
278  }
279 
280  // if no decision can be made yet, request further information downwards
281  // Enter subslots for children if needed
282  if ( searchResult != m_slot->subSlotsByNode.end() ) {
283  for ( unsigned int slotIndex : searchResult->second ) {
284 
285  // Enter sub-slot
286  m_slot = &( m_slot->allSubSlots[slotIndex] );
287 
288  for ( auto child : node.getDaughters() ) {
289  bool result = child->accept( *this );
290  if ( !node.m_modeConcurrent )
291  if ( result ) break; // stop on first unresolved child if its decision hub is sequential
292  }
293 
294  // Leave sub-slot
296  }
297  } else {
298  for ( auto child : node.getDaughters() ) {
299  bool result = child->accept( *this );
300  if ( !node.m_modeConcurrent )
301  if ( result ) break; // stop on first unresolved child if its decision hub is sequential
302  }
303  }
304 
305  if ( oldSlot ) m_slot = oldSlot;
306  return false;
307  }
std::string entryPoint
Event Views bookkeeping (TODO: optimize view bookkeeping)
Definition: EventSlot.h:84
Class representing an event slot.
Definition: EventSlot.h:14
std::vector< int > controlFlowState
State of the control flow.
Definition: EventSlot.h:77
std::vector< EventSlot > allSubSlots
Actual sub-slot instances.
Definition: EventSlot.h:90
T find(T...args)
EventSlot * parentSlot
Pointer to parent slot (null for top level)
Definition: EventSlot.h:86
std::unordered_map< std::string, std::vector< unsigned int > > subSlotsByNode
Listing of sub-slots by the node (name) they are attached to.
Definition: EventSlot.h:88
bool concurrency::Supervisor::visit ( AlgorithmNode node)
overridevirtual

Reimplemented from concurrency::IGraphVisitor.

Definition at line 317 of file PRGraphVisitors.cpp.

317  {
318 
319  bool result = false;
320 
321  auto& states = m_slot->algsStates;
322  auto& state = states[node.getAlgoIndex()];
323 
324  // Promote with INITIAL->CR
325  if ( AState::INITIAL == state ) states.set( node.getAlgoIndex(), AState::CONTROLREADY ).ignore();
326 
327  // Try to promote with CR->DR
328  if ( AState::CONTROLREADY == state ) {
329  auto promoter = DataReadyPromoter( *m_slot, m_cause, m_trace );
330  result = promoter.visit( node );
331  } else {
332  result = true;
333  }
334 
335  // return true only when an algorithm is not lower than DR in its FSM
336  // i.e., the visitor has done everything it could with this algorithm
337  return result;
338  }
AlgsExecutionStates algsStates
Vector of algorithms states.
Definition: EventSlot.h:75
bool concurrency::Supervisor::visitEnter ( DecisionNode node) const
overridevirtual

Reimplemented from concurrency::IGraphVisitor.

Definition at line 134 of file PRGraphVisitors.cpp.

134  {
135  // Protect against graph traversal escaping from sub-slots
136  if ( m_slot->parentSlot ) {
137  // Examine the ancestry of this node, looking for sub-slot entry point
138  bool canFindExit = false;
139  std::queue<DecisionNode*> allAncestors;
140  allAncestors.push( &node );
141  while ( allAncestors.size() ) {
142 
143  DecisionNode* thisAncestor = allAncestors.front();
144  allAncestors.pop();
145 
146  if ( thisAncestor->getNodeName() == m_slot->entryPoint ) {
147 
148  // This ancestor is the sub-slot exit
149  canFindExit = true;
150  break;
151 
152  } else {
153 
154  // Go further up the node ancestry
155  for ( auto& evenOlder : thisAncestor->m_parents ) { allAncestors.push( evenOlder ); }
156  }
157  }
158 
159  // If the sub-slot entry point is not in this node's ancestry, don't visit the node
160  if ( !canFindExit ) return false;
161  }
162 
163  if ( m_slot->controlFlowState[node.getNodeIndex()] != -1 ) return false;
164  return true;
165  }
std::string entryPoint
Event Views bookkeeping (TODO: optimize view bookkeeping)
Definition: EventSlot.h:84
T front(T...args)
T pop(T...args)
std::vector< int > controlFlowState
State of the control flow.
Definition: EventSlot.h:77
T push(T...args)
T size(T...args)
STL class.
EventSlot * parentSlot
Pointer to parent slot (null for top level)
Definition: EventSlot.h:86
bool concurrency::Supervisor::visitEnter ( AlgorithmNode node) const
overridevirtual

Reimplemented from concurrency::IGraphVisitor.

Definition at line 310 of file PRGraphVisitors.cpp.

310  {
311 
312  if ( m_slot->controlFlowState[node.getNodeIndex()] != -1 ) return false;
313  return true;
314  }
std::vector< int > controlFlowState
State of the control flow.
Definition: EventSlot.h:77

Member Data Documentation

Cause concurrency::Supervisor::m_cause

Definition at line 69 of file PRGraphVisitors.h.

EventSlot* concurrency::Supervisor::m_slot

Definition at line 68 of file PRGraphVisitors.h.

bool concurrency::Supervisor::m_trace

Definition at line 70 of file PRGraphVisitors.h.


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