Workspace 6.21.5
Public Member Functions | Protected Types | Protected Member Functions | Protected Attributes | List of all members
ParallelIteratingOperation< Derived > Class Template Referenceabstract

Interface for iterating over a workflow in parallel using the Workspace scheduling infrastructure. More...

#include <Workspace/DataExecution/Operations/Builtin/paralleliteratingoperation.h>

Inheritance diagram for ParallelIteratingOperation< Derived >:
[legend]

Public Member Functions

void onIterationAborted (Workspace &) override
 
void onIterationFinished (Workspace &) override
 
void onIterationSuccess (Workspace &) override
 
- Public Member Functions inherited from ParallelIteratingOperationBase
virtual void onIterationAborted (Workspace &)=0
 
virtual void onIterationFinished (Workspace &)=0
 
virtual void onIterationSuccess (Workspace &)=0
 
void processAbortedIteration (Workspace &)
 
- Public Member Functions inherited from IteratingOperationBase
 IteratingOperationBase ()
 
virtual ~IteratingOperationBase ()=default
 

Protected Types

using IterationObservers = std::map< Workspace *, IterationObserver * >
 
typedef std::map< Workspace *, bool > WorkspacePool
 

Protected Member Functions

 ParallelIteratingOperation ()
 
bool atEndCondition () override
 
IteratingOperationBase::ExecutionResult executeIteration (Workspace *workspaceToExecute) override
 
virtual IteratingOperationBase::ExecutionResult executeIterationInSerial (Workspace *workspaceToExecute, int iterationCounter) noexcept(false)=0
 
bool isIterationControlInput (const Input &input) const override
 
bool isLoopConditionValid () const override
 
void performCleanup (Workspace *workspaceToExecute, bool forceStop) override
 
bool performInitialisation (Workspace *workspaceToExecute) override
 
bool postIterationExecute () override
 
bool preIterations () override
 
virtual WorkspaceselectIterationForOutputAssignment (const WorkspacePool &iterations) const
 
void setNonIterationControlInputsNotUpToDate () override
 
void updateProgress () override
 
- Protected Member Functions inherited from ParallelIteratingOperationBase
 ParallelIteratingOperationBase ()
 
virtual ~ParallelIteratingOperationBase ()=default
 
int calcProgress (int startValue, int endValue, int counterValue)
 
virtual IterationControlParams getIterationControlParams () const =0
 
int getIterationCount ()
 
void setMethodDispatcher (ParallelIteratingOperationMethodDispatcher *dispatcher)
 
void sleep (int msec)
 
- Protected Member Functions inherited from IteratingOperation< Derived >
 IteratingOperation ()
 
 ~IteratingOperation () override
 
virtual bool bringInputsUpToDateImpl ()
 
virtual bool executeImpl ()
 
virtual bool isIterationControlInput (const Input &input) const
 
void performCleanup (Workspace *workspaceToExecute, bool forceStop) override
 
bool performInitialisation (Workspace *workspaceToExecute) override
 
bool preIterations () override
 
virtual void setInputNotUpToDateImpl (InputScalar &input)
 
void setNonIterationControlInputsNotUpToDate () override
 
void terminateExecution ()
 
bool updateInputsForIteration () override
 
- Protected Member Functions inherited from IteratingOperationBase
virtual bool atEndCondition ()=0
 
virtual ExecutionResult executeIteration (Workspace *workspaceToExecute) noexcept(false)=0
 
WorkspacegetWorkspaceToExecute ()
 
bool isExecuting () const
 
virtual bool isLoopConditionValid () const =0
 
virtual void performCleanup (Workspace *workspaceToExecute, bool forceStop) noexcept(false)=0
 
virtual bool performInitialisation (Workspace *workspaceToExecute) noexcept(false)=0
 
virtual bool postIterationExecute ()
 
virtual bool preIterations ()=0
 
virtual void setNonIterationControlInputsNotUpToDate ()
 
void setWorkspaceToExecute (Workspace *workspace)
 
virtual bool updateInputsForIteration ()=0
 
virtual void updateProgress ()=0
 

Protected Attributes

SimpleInput< bool > enableParallelLooping_
 
IterationObservers iterationObservers_
 
WorkspacePool iterationPool_
 
QAtomicInt remainingIterations_
 
QAtomicInt runningIterations_
 
- Protected Attributes inherited from ParallelIteratingOperationBase
int counterValue_
 
int endValue_
 
bool overflowed_
 
int startValue_
 
int stepValue_
 
- Protected Attributes inherited from IteratingOperation< Derived >
SimpleInput< bool > enableLoop_
 
SimpleInput< bool > wrap_
 
- Protected Attributes inherited from IteratingOperationBase
bool executing_
 
bool reset_
 

Additional Inherited Members

- Public Types inherited from IteratingOperationBase
enum  ExecutionResult { Abort , Success , Retry }
 Result of an iteration's execution. More...
 

Detailed Description

template<typename Derived>
class CSIRO::DataExecution::ParallelIteratingOperation< Derived >

Concrete implementations should extend either Operation or Workspace as well as this interface, and declare this class to be a friend.

Note
that this class must necessarily be a template because many of the methods invoked on the derived class are protected methods. This class should be thought of as a decorator for an operation.

Member Typedef Documentation

◆ IterationObservers

using IterationObservers = std::map<Workspace*, IterationObserver*>
protected

◆ WorkspacePool

typedef std::map<Workspace*, bool> WorkspacePool
protected

Constructor & Destructor Documentation

◆ ParallelIteratingOperation()

Member Function Documentation

◆ atEndCondition()

bool atEndCondition ( )
overrideprotectedvirtual

Invoked to test the end condition after each loop iteration.

Returns
true if the loop is at its end condition, false otherwise. Returning true will cause the loop to terminate without completing any further iterations.

Implements IteratingOperationBase.

◆ executeIteration()

IteratingOperationBase::ExecutionResult executeIteration ( Workspace workspaceToExecute)
overrideprotectedvirtual
Parameters
workspaceToExecuteThe workspace of which to execute an iteration. This will be provided as 'null' if the derived class does not ensure that setWorkspaceToExecute() is invoked prior to execution. It's up to derived classes whether or not this is an error.

Invoked for each iteration of the workspace under execution. Derived classes can override this to control exactly how this execution occurs. For example, it could execute immediately, or it could be scheduled for future execution.

Returns
true if the execution succeeded, false otherwise.

Implements IteratingOperationBase.

◆ executeIterationInSerial()

virtual IteratingOperationBase::ExecutionResult executeIterationInSerial ( Workspace workspaceToExecute,
int  iterationCounter 
)
protectedpure virtual
Parameters
workspaceToExecuteThe workspace to execute. May be provided as null if the derived class does not invoke setWorkspaceToExecute() prior to execution. It is up to the derived class whether or not this is an error.
iterationCounterThe counter of the iteration to execute.

Derived classes must provide a way to execute in serial as well as parallel.

Returns
The result of the execution. ABORT if an unrecoverable error occurs, SUCCESS if successful and RETRY if execution needs to be retried for any reason.

◆ isIterationControlInput()

bool isIterationControlInput ( const Input input) const
overrideprotectedvirtual

◆ isLoopConditionValid()

bool isLoopConditionValid ( ) const
overrideprotectedvirtual

Derived classes must override this method to specify when a loop termination condition is infinite. Workspace can then terminate the loop with an error if this is achieved. To allow infinite loops, simply return false from this method always.

Returns
true if the loop condition is infinite, false otherwise.

Implements IteratingOperationBase.

◆ onIterationAborted()

void onIterationAborted ( Workspace workspace)
overridevirtual

◆ onIterationFinished()

void onIterationFinished ( Workspace workspace)
overridevirtual

◆ onIterationSuccess()

void onIterationSuccess ( Workspace workspace)
overridevirtual

◆ performCleanup()

void performCleanup ( Workspace workspaceToExecute,
bool  forceStop 
)
overrideprotectedvirtual
Parameters
workspaceToExecuteThe workspace to execute
forceStopWhether or not to force the execution to stop when cleaning up.

Cleanup opportunity following the attempted execution of iterations. Regardless of how the execution terminates (aborted or successful), this method is invoked.

Reimplemented from IteratingOperation< Derived >.

◆ performInitialisation()

bool performInitialisation ( Workspace workspaceToExecute)
overrideprotectedvirtual

Initialisation opportunity prior to executing the iterations. This method is invoked using RAII, so its return value cannot be inspected. Therefore if errors occur, exceptions should be thrown.

Reimplemented from IteratingOperation< Derived >.

◆ postIterationExecute()

bool postIterationExecute
overrideprotectedvirtual
Returns
true if the method executed successfully, false otherwise.

Invoked immediately following the successful execution of an iteration. Default implementation does nothing, returning true.

Reimplemented from IteratingOperationBase.

◆ preIterations()

bool preIterations ( )
overrideprotectedvirtual

Invoked immediately prior to the commencement of any iterations. If 'wrap' is enabled, this will be invoked prior to each set of iterations.

Returns
false if an error occurs and the loop should be terminated, true otherwise.

Reimplemented from IteratingOperation< Derived >.

◆ selectIterationForOutputAssignment()

Workspace * selectIterationForOutputAssignment ( const WorkspacePool finalIterations) const
protectedvirtual
Parameters
finalIterationsIteration pool containing the set of iterations completed in the last run.

Selects an iteration from the provided iteration pool from which to assign output values. By default, it simply selects the first iteration it can find. Derived classes can override this to provide some logic, such as finding an iteration that matches some specific criteria.

Alternatively, derived classes may wish to override executeImpl altogether in order to assign some alternative data to the outputs.

Returns
The iteration selected for final output assignment.

◆ setNonIterationControlInputsNotUpToDate()

void setNonIterationControlInputsNotUpToDate
overrideprotectedvirtual

Sets the non-iteration-control inputs to not-up-to-date at the beginning of each iteration. Derived classes must override this and may choose to not avail of the functionality or perform it differently depending on the need of the specific derived class.

Invoked immediately following preIterations(). Default implementation does nothing. Override if needed.

Reimplemented from IteratingOperation< Derived >.

◆ updateProgress()

void updateProgress ( )
overrideprotectedvirtual

Updates its parent operation's progress at the start of each iteration. Derived classes must override this to specify how progress is indicated, as it will change depending on how iteration is computed.

Implements IteratingOperationBase.

Member Data Documentation

◆ enableParallelLooping_

SimpleInput<bool> enableParallelLooping_
protected

◆ iterationObservers_

IterationObservers iterationObservers_
protected

◆ iterationPool_

WorkspacePool iterationPool_
protected

◆ remainingIterations_

QAtomicInt remainingIterations_
protected

◆ runningIterations_

QAtomicInt runningIterations_
protected