The Gaudi Framework  v30r2 (9eca68f7)
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 54 of file PRGraphVisitors.h.

Constructor & Destructor Documentation

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

Constructor.

Definition at line 58 of file PRGraphVisitors.h.

59  : 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 185 of file PRGraphVisitors.cpp.

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

Reimplemented from concurrency::IGraphVisitor.

Definition at line 338 of file PRGraphVisitors.cpp.

339  {
340 
341  bool result = false;
342 
343  auto& states = m_slot->algsStates;
344  auto& state = states[node.getAlgoIndex()];
345 
346  // Promote with INITIAL->CR
347  if ( State::INITIAL == state ) states.updateState( node.getAlgoIndex(), State::CONTROLREADY ).ignore();
348 
349  // Try to promote with CR->DR
350  if ( State::CONTROLREADY == state ) {
351  auto promoter = DataReadyPromoter( *m_slot, m_cause, m_trace );
352  result = promoter.visit( node );
353  } else {
354  result = true;
355  }
356 
357  // return true only when an algorithm is not lower than DR in its FSM
358  // i.e., the visitor has done everything it could with this algorithm
359  return result;
360  }
AlgsExecutionStates algsStates
Vector of algorithms states.
Definition: EventSlot.h:50
bool concurrency::Supervisor::visitEnter ( DecisionNode node) const
overridevirtual

Reimplemented from concurrency::IGraphVisitor.

Definition at line 147 of file PRGraphVisitors.cpp.

148  {
149  // Protect against graph traversal escaping from sub-slots
150  if ( m_slot->parentSlot ) {
151  // Examine the ancestry of this node, looking for sub-slot entry point
152  bool canFindExit = false;
153  std::queue<DecisionNode*> allAncestors;
154  allAncestors.push( &node );
155  while ( allAncestors.size() ) {
156 
157  DecisionNode* thisAncestor = allAncestors.front();
158  allAncestors.pop();
159 
160  if ( thisAncestor->getNodeName() == m_slot->entryPoint ) {
161 
162  // This ancestor is the sub-slot exit
163  canFindExit = true;
164  break;
165 
166  } else {
167 
168  // Go further up the node ancestry
169  for ( auto& evenOlder : thisAncestor->m_parents ) {
170 
171  allAncestors.push( evenOlder );
172  }
173  }
174  }
175 
176  // If the sub-slot entry point is not in this node's ancestry, don't visit the node
177  if ( !canFindExit ) return false;
178  }
179 
180  if ( m_slot->controlFlowState[node.getNodeIndex()] != -1 ) return false;
181  return true;
182  }
T front(T...args)
T pop(T...args)
std::string entryPoint
Name of the node this slot is attached to ("" for top level)
Definition: EventSlot.h:58
T push(T...args)
std::vector< int > controlFlowState
State of the control flow.
Definition: EventSlot.h:54
EventSlot * parentSlot
Pointer to parent slot (null for top level)
Definition: EventSlot.h:60
T size(T...args)
STL class.
bool concurrency::Supervisor::visitEnter ( AlgorithmNode node) const
overridevirtual

Reimplemented from concurrency::IGraphVisitor.

Definition at line 330 of file PRGraphVisitors.cpp.

331  {
332 
333  if ( m_slot->controlFlowState[node.getNodeIndex()] != -1 ) return false;
334  return true;
335  }
std::vector< int > controlFlowState
State of the control flow.
Definition: EventSlot.h:54

Member Data Documentation

Cause concurrency::Supervisor::m_cause

Definition at line 73 of file PRGraphVisitors.h.

EventSlot* concurrency::Supervisor::m_slot

Definition at line 72 of file PRGraphVisitors.h.

bool concurrency::Supervisor::m_trace

Definition at line 74 of file PRGraphVisitors.h.


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