IGLib  1.5
The IGLib base library for development of numerical, technical and business applications.
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Events
IG.Num.ParallelJobContainerGen< InputType, ResultType > Class Template Reference

General purpose parallel job container that contains methods for running the job in on the same machine thread. Contains many auxiliary methods for testing and for adaptation of parallel jobs concepts to different tasks. More...

+ Inheritance diagram for IG.Num.ParallelJobContainerGen< InputType, ResultType >:
+ Collaboration diagram for IG.Num.ParallelJobContainerGen< InputType, ResultType >:

Public Member Functions

 ParallelJobContainerGen ()
 Creates a new parallel job container. More...
 
 ParallelJobContainerGen (SimpleFunctionDelegate< InputType, ResultType > evaluationDelegate)
 Creates a new parallel job container with inptu data assigned. More...
 
 ParallelJobContainerGen (SimpleFunctionDelegate< InputType, ResultType > evaluationDelegate, InputType inputData)
 Creates a new parallel job container with inptu data assigned. More...
 
 ParallelJobContainerGen (SimpleFunctionDelegate< InputType, ResultType > evaluationDelegate, InputType inputData, object clientData)
 Creates a new parallel job container with inptu data assigned. More...
 
virtual void RunJob ()
 Performs the job by the data contained in the current job container. More...
 
ResultType RunJob (InputType input)
 Calculates and results of the job corresponding to the current job container, based on the specified intput data. More...
 
override string ToString ()
 Returns a string representation of the current job dispatcher, which contains relevent data about the server state. More...
 
- Public Member Functions inherited from IG.Num.ParallelJobContainerBase
 ParallelJobContainerBase ()
 Constructs a new parallel data container. More...
 
void NotifyJobStarted ()
 Notifies this job data container that its job has started. More...
 
void NotifyJobFinished ()
 Notifies this job data container that its job has finished. More...
 
void NotifyJobAborted ()
 Notifies this job data container that its job has been aborted. More...
 
void WaitJobCompletion ()
 Waits for job completion. More...
 
bool WaitJobCompletion (double timeoutInSeconds)
 Wait until the current job whose data is contained in this object completes, or timeout occurs (timeout specified in seconds), and returns a flag indicating whether the job has actually completed (i.e. stop was not due to timeout). More...
 
override string ToString ()
 Returns a string representation of the current job dispatcher, which contains relevent data about the server state. More...
 

Static Public Member Functions

static
ParallelJobDispatcherGen
< InputType, ResultType > 
CreateDispatcher (int numServers)
 Creates and returns a parallel job dispatcher for job containers of the current typa, with the specified number of servers initialized and added on the dispatcher. More...
 
static
ParallelJobDispatcherGen
< InputType, ResultType > 
CreateDispatcher (int numServers, int sleepTimeMs)
 Creates and returns a parallel job dispatcher for job containers of the current typa, with the specified number of servers initialized and added on the dispatcher, and with specified sleeping time (used for the dispetcher and added servers). More...
 
static ParallelJobServerGen
< InputType, ResultType > 
CreateServer ()
 Creates and returns a new job server for the current job container type. More...
 
static ParallelJobServerGen
< InputType, ResultType > 
CreateServer (int sleeptimeMs)
 Creates and returns a new job server for the current job container type. More...
 
static ParallelJobContainerGen
< InputType, ResultType > 
CreateJobContainer ()
 Creates and returns a new job container of the current type. More...
 
static ResultType[] TestPerformance (InputType[] inputs, SimpleFunctionDelegate< InputType, ResultType > evaluationFunction, int numServers, int maxEnqueued, double delayTimeSeconds, double delayTimeRelativeError, int sleepTimeMs, int clientOutputLevel)
 Test of parallel job execution. More...
 
- Static Public Member Functions inherited from IG.Num.ParallelJobContainerBase
static void TestPerformance (int numPoints, int numServers, int maxEnqueued, double delayTimeSeconds, double delayTimeRelativeError, int sleepTimeMs, int clientOutputLevel)
 Test of parallel job execution by calculating the specified real function of one variable in a number of points. Calculatin is performed in parallel threads by using job dispatcher with parallel servers. More...
 
static void TestPerformance (double from, double to, int numPoints, SimpleFunctionDelegate< double, double > evaluationFunction, int numServers, int maxEnqueued, double delayTimeSeconds, double delayTimeRelativeError, int sleepTimeMs, int clientOutputLevel)
 Test of parallel job execution by calculating the specified real function of one variable in a number of points. Calculatin is performed in parallel threads by using job dispatcher with parallel servers. More...
 

Protected Member Functions

override void RunOnStarted ()
 Called when 'started' notification is triggered (within the method NotifyJobStarted). More...
 
override void RunOnFinished ()
 Called when 'finished' notification is triggered (within the method NotifyJobFinished). More...
 
override void RunOnAborted ()
 Called when 'aborted' notification is triggered (within the method NotifyJobAborted). More...
 

Protected Attributes

InputType _input
 
ResultType _result
 
ParallelJobCallbackGen
< InputType, ResultType > 
_onStartedGeneric = null
 
ParallelJobCallbackGen
< InputType, ResultType > 
_onFinishedGeneric = null
 
ParallelJobCallbackGen
< InputType, ResultType > 
_onAbortedGeneric = null
 
SimpleFunctionDelegate
< InputType, ResultType > 
_evaluationDelegate = null
 
bool _doesNotContainJobDefinition = false
 
- Protected Attributes inherited from IG.Num.ParallelJobContainerBase
ParallelJobState _state = ParallelJobState.Uninitialized
 
int _dispatcherJobId = -1
 
int _clientJobId = -1
 
object _clientData
 
int _sleepTimeMs = DefaultSleepTimeMs
 
ParallelJobDispatcherBase _dispatcher
 
int _outputLevel = DefaultOutputLevel
 Output level for objects of this class. More...
 
bool _isTestMode = DefaultIsTestMode
 
volatile int _numTestDelays = 1
 
double _testDelayInSeconds = 1.0
 
double _testDelayRelativeError = 0.0
 
ParallelJobCallback _onStarted = null
 
ParallelJobCallback _onFinished = null
 
ParallelJobCallback _onAborted = null
 

Properties

InputType Input [get, set]
 Input for the current job. More...
 
ResultType Result [get, set]
 Result of the current job. More...
 
ParallelJobCallbackGen
< InputType, ResultType > 
OnStartedGeneric [get, set]
 Delegate that is executed on started event. More...
 
ParallelJobCallbackGen
< InputType, ResultType > 
OnFinishedGeneric [get, set]
 Delegate that is executed on started event. More...
 
ParallelJobCallbackGen
< InputType, ResultType > 
OnAbortedGeneric [get, set]
 Delegate that is executed on started event. More...
 
SimpleFunctionDelegate
< InputType, ResultType > 
EvaluationDelegate [protected get, set]
 Evaluation delegate that is by default used for calculation of results from input data of the parallel job. More...
 
virtual bool IsJobDefined [get, set]
 Indicates whether the curren job container can itself execute a job by calling either variant of the RunJob method. More...
 
- Properties inherited from IG.Num.ParallelJobContainerBase
object Lock [get]
 This object's central lock object to be used by other object. Do not use this object for locking in class' methods, for this you should use InternalLock. More...
 
ParallelJobState State [get, set]
 State of the parallel job whose data is contained in the current object. More...
 
bool IsJobCompleted [get]
 Flag indicating whether a job has finished. More...
 
static object LockId [get]
 Lock used for acquiring IDs. More...
 
virtual int Id [get]
 Unique ID for objects of the currnet and derived classes. More...
 
int DispatcherJobId [get, protected set]
 Dispatcher's Id of the job contained in the current job data container. More...
 
int ClientJobId [get, set]
 Client's Id of the job contained in the current job data container. More...
 
object ClientData [get, protected set]
 Client's data for the job contained in the current job data container. More...
 
static int DefaultSleepTimeMs [get, set]
 Default sleeping time, in milliseconds, used by parallel job data objects when waiting for fulfillment of some condition in a loop that includes sleeping when condition is not met. More...
 
int SleepTimeMs [get, set]
 Sleeping time, in milliseconds, used by the current object when waiting for fulfillment of some condition in a loop that includes sleeping when condition is not met. More...
 
int OutputLevel [get, set]
 Output level for the current object. More...
 
bool IsTestMode [get, set]
 Whether the current job data conntainer is in test mode. In this mode, delays specified by internal variables are automatically added in job execution. More...
 
int NumTestDelays [get, set]
 Number of time intervals into which the total delay interval (property TestDelayInSeconds) is divided. More...
 
double TestDelayInSeconds [get, set]
 Delay time in the testing mode (in seconds), which is caused by calling sleep for the Thread.Sleep method. More...
 
double TestDelayRelativeError [get, set]
 Interval of random errors added to the test delay time, relative to unnoisy delay time. More...
 
int TestDelaySingleMs [get]
 Single test delay interval in milliseconds. More...
 
ParallelJobCallback OnStarted [get, set]
 Delegate that is executed on started event. More...
 
ParallelJobCallback OnFinished [get, set]
 Delegate that is executed on started event. More...
 
ParallelJobCallback OnAborted [get, set]
 Delegate that is executed on started event. More...
 
- Properties inherited from IG.Lib.ILockable
object Lock [get]
 
- Properties inherited from IG.Lib.IIdentifiable
int Id [get]
 Returns unique ID (in the scope of a given type) of the current object. More...
 

Additional Inherited Members

- Static Public Attributes inherited from IG.Num.ParallelJobContainerBase
static volatile int DefaultOutputLevel = -1
 Default output level for objects of this and derived types. More...
 
static volatile bool DefaultIsTestMode = false
 Default value of the testmode flag. More...
 
- Static Protected Member Functions inherited from IG.Num.ParallelJobContainerBase
static int GetNextId ()
 Returns another ID that is unique for objects of the containing class its and derived classes. More...
 

Detailed Description

General purpose parallel job container that contains methods for running the job in on the same machine thread. Contains many auxiliary methods for testing and for adaptation of parallel jobs concepts to different tasks.

Contains input data and results of a parallel job to be executed, oropertied indicating the state of the job, and methods for interaction with job performer and dispatcher.

This class interacts with parallel job dispatcher that sends a job to the specific server, and with the parallel server that executes the job.

$A Igor Aug08;

Constructor & Destructor Documentation

IG.Num.ParallelJobContainerGen< InputType, ResultType >.ParallelJobContainerGen ( )
inline

Creates a new parallel job container.

IG.Num.ParallelJobContainerGen< InputType, ResultType >.ParallelJobContainerGen ( SimpleFunctionDelegate< InputType, ResultType >  evaluationDelegate)
inline

Creates a new parallel job container with inptu data assigned.

Parameters
evaluationDelegateDellegate that performs calculation.
IG.Num.ParallelJobContainerGen< InputType, ResultType >.ParallelJobContainerGen ( SimpleFunctionDelegate< InputType, ResultType >  evaluationDelegate,
InputType  inputData 
)
inline

Creates a new parallel job container with inptu data assigned.

Parameters
EvaluationDelegateDellegate that performs calculation.
inputDataInpt data for the job.
IG.Num.ParallelJobContainerGen< InputType, ResultType >.ParallelJobContainerGen ( SimpleFunctionDelegate< InputType, ResultType >  evaluationDelegate,
InputType  inputData,
object  clientData 
)
inline

Creates a new parallel job container with inptu data assigned.

Parameters
EvaluationDelegateDellegate that performs calculation.
inputDataInpt data for the job.

Member Function Documentation

override void IG.Num.ParallelJobContainerGen< InputType, ResultType >.RunOnStarted ( )
inlineprotectedvirtual

Called when 'started' notification is triggered (within the method NotifyJobStarted).

Reimplemented from IG.Num.ParallelJobContainerBase.

override void IG.Num.ParallelJobContainerGen< InputType, ResultType >.RunOnFinished ( )
inlineprotectedvirtual

Called when 'finished' notification is triggered (within the method NotifyJobFinished).

Reimplemented from IG.Num.ParallelJobContainerBase.

override void IG.Num.ParallelJobContainerGen< InputType, ResultType >.RunOnAborted ( )
inlineprotectedvirtual

Called when 'aborted' notification is triggered (within the method NotifyJobAborted).

Reimplemented from IG.Num.ParallelJobContainerBase.

virtual void IG.Num.ParallelJobContainerGen< InputType, ResultType >.RunJob ( )
inlinevirtual

Performs the job by the data contained in the current job container.

Warning: only works when the IsJobDefined flag is true.

Warning: This method should only be called if the flag is true. Otherwise, the job container itself does not know how to execute the job, an this must be done by the appropriate parallel job server object (base type ParallelJobServerBase).

When overriding this method, it must be checked that consistency with the IsJobDefined flag is preserved (one may also need to override the flag).

Parallel jobs by data contained job container objects are normally run by the job server objects that know how to execute teh job. Im this type of job containers, it can be defined by the job container how to run the job in a parallel thread, and this can be done by calling this method. This method can also be used by job servers to execute the job.

Calculation is performed by calling the CalculateResultsPlain method. In its original form, that method just calls the EvaluationDelegate delegate and throws exception if the delegate is not defined. The behavior can be changed either by overriding the CalculateResultsPlain method (recommendable) or by overriding this method (not recommended, but still left as choice).

ResultType IG.Num.ParallelJobContainerGen< InputType, ResultType >.RunJob ( InputType  input)
inline

Calculates and results of the job corresponding to the current job container, based on the specified intput data.

Calculation is performed by setting input data and calling the RunJob() method.

Parameters
inputInput data for the job that is executed when calling this function.
Returns
Results of execution of the job.

Warning: This method should only be called if the flag is true. Otherwise, the job container itself does not know how to execute the job, an this must be done by the appropriate parallel job server object (base type ParallelJobServerBase).

This function locks the current job container object's lock. It is therefore thread safe, but may not be called in the context where locking the job container could cause delays or deadlocks.

static ParallelJobDispatcherGen<InputType, ResultType> IG.Num.ParallelJobContainerGen< InputType, ResultType >.CreateDispatcher ( int  numServers)
inlinestatic

Creates and returns a parallel job dispatcher for job containers of the current typa, with the specified number of servers initialized and added on the dispatcher.

Parameters
numServersNumber of servers created and added to the created dispatcher.
static ParallelJobDispatcherGen<InputType, ResultType> IG.Num.ParallelJobContainerGen< InputType, ResultType >.CreateDispatcher ( int  numServers,
int  sleepTimeMs 
)
inlinestatic

Creates and returns a parallel job dispatcher for job containers of the current typa, with the specified number of servers initialized and added on the dispatcher, and with specified sleeping time (used for the dispetcher and added servers).

Parameters
numServersNumber of servers created and added to the created dispatcher.
sleepTimeMsSleeping time (in milliseconds) for dospatcher's server thread and for servers' threads.

References IG.Num.ParallelJobDispatcherBase< JobContainerType >.AddServer(), and IG.Num.ParallelJobDispatcherBase.SleepTimeMs.

static ParallelJobServerGen<InputType, ResultType> IG.Num.ParallelJobContainerGen< InputType, ResultType >.CreateServer ( )
inlinestatic

Creates and returns a new job server for the current job container type.

static ParallelJobServerGen<InputType, ResultType> IG.Num.ParallelJobContainerGen< InputType, ResultType >.CreateServer ( int  sleeptimeMs)
inlinestatic

Creates and returns a new job server for the current job container type.

Parameters
sleeptimeMsSleeping time for the server's serving thread, in milliseconds.

References IG.Num.ParallelJobServerBase< JobContainerType >.SleepTimeMs.

static ParallelJobContainerGen<InputType, ResultType> IG.Num.ParallelJobContainerGen< InputType, ResultType >.CreateJobContainer ( )
inlinestatic

Creates and returns a new job container of the current type.

static ResultType [] IG.Num.ParallelJobContainerGen< InputType, ResultType >.TestPerformance ( InputType[]  inputs,
SimpleFunctionDelegate< InputType, ResultType >  evaluationFunction,
int  numServers,
int  maxEnqueued,
double  delayTimeSeconds,
double  delayTimeRelativeError,
int  sleepTimeMs,
int  clientOutputLevel 
)
inlinestatic

Test of parallel job execution.

Parameters
inputsArray of job inputs.
evaluationFunctionDelegate that is used to evaluate functions.
numServersNumber of servers to be used.
maxEnqueuedMaximal allowed number of jobs enquied.
delayTimeSecondsDelay tie iin seconds.
delayTimeRelativeError
sleepTimeMsSleep time of server threads, in milliseconds.
clientOutputLevelLevel of output on dispatching activity within the method.
Returns
Array of calculated results.

References IG.Num.ParallelJobContainerBase.ClientJobId, IG.Num.ParallelJobContainerBase.Id, IG.Num.ParallelJobContainerBase.IsTestMode, IG.Num.ParallelJobDispatcherBase.NumAbortedJobs, IG.Num.ParallelJobDispatcherBase< JobContainerType >.NumEnqueuedJobs, IG.Num.ParallelJobDispatcherBase< JobContainerType >.NumExecutingJobs, IG.Num.ParallelJobDispatcherBase.NumFinishedJobs, IG.Num.ParallelJobDispatcherBase.NumIdleJobServers, IG.Num.ParallelJobDispatcherBase.NumSentJobs, IG.Num.ParallelJobDispatcherBase.NumStartedJobs, IG.Num.ParallelJobContainerBase.NumTestDelays, IG.Num.ParallelJobDispatcherBase.NumUncompletedJobs, IG.Num.ParallelJobContainerGen< InputType, ResultType >.OnAbortedGeneric, IG.Num.ParallelJobContainerGen< InputType, ResultType >.OnFinishedGeneric, IG.Num.ParallelJobContainerGen< InputType, ResultType >.Result, IG.Num.ParallelJobDispatcherBase< JobContainerType >.SendJob(), IG.Num.ParallelJobDispatcherBase< JobContainerType >.SetServersIsServer(), IG.Lib.StopWatch.Start(), IG.Num.ParallelJobDispatcherBase< JobContainerType >.StopServerWhenAllJobsDone(), IG.Num.ParallelJobContainerBase.TestDelayInSeconds, IG.Num.ParallelJobContainerBase.TestDelayRelativeError, IG.Lib.StopWatch.Time, IG.Num.ParallelJobDispatcherBase< JobContainerType >.ToString(), and IG.Num.ParallelJobDispatcherBase< JobContainerType >.WaitAllJobsCompleted().

override string IG.Num.ParallelJobContainerGen< InputType, ResultType >.ToString ( )
inline

Returns a string representation of the current job dispatcher, which contains relevent data about the server state.

Member Data Documentation

InputType IG.Num.ParallelJobContainerGen< InputType, ResultType >._input
protected
ResultType IG.Num.ParallelJobContainerGen< InputType, ResultType >._result
protected
ParallelJobCallbackGen<InputType, ResultType> IG.Num.ParallelJobContainerGen< InputType, ResultType >._onStartedGeneric = null
protected
ParallelJobCallbackGen<InputType, ResultType> IG.Num.ParallelJobContainerGen< InputType, ResultType >._onFinishedGeneric = null
protected
ParallelJobCallbackGen<InputType, ResultType> IG.Num.ParallelJobContainerGen< InputType, ResultType >._onAbortedGeneric = null
protected
SimpleFunctionDelegate<InputType, ResultType> IG.Num.ParallelJobContainerGen< InputType, ResultType >._evaluationDelegate = null
protected
bool IG.Num.ParallelJobContainerGen< InputType, ResultType >._doesNotContainJobDefinition = false
protected

Property Documentation

InputType IG.Num.ParallelJobContainerGen< InputType, ResultType >.Input
getset

Input for the current job.

ResultType IG.Num.ParallelJobContainerGen< InputType, ResultType >.Result
getset
ParallelJobCallbackGen<InputType, ResultType> IG.Num.ParallelJobContainerGen< InputType, ResultType >.OnStartedGeneric
getset

Delegate that is executed on started event.

When executing, job container is locked.

ParallelJobCallbackGen<InputType, ResultType> IG.Num.ParallelJobContainerGen< InputType, ResultType >.OnFinishedGeneric
getset

Delegate that is executed on started event.

When executing, job container is locked.

Referenced by IG.Num.ParallelJobContainerGen< InputType, ResultType >.TestPerformance().

ParallelJobCallbackGen<InputType, ResultType> IG.Num.ParallelJobContainerGen< InputType, ResultType >.OnAbortedGeneric
getset

Delegate that is executed on started event.

When executing, job container is locked.

Referenced by IG.Num.ParallelJobContainerGen< InputType, ResultType >.TestPerformance().

SimpleFunctionDelegate<InputType, ResultType> IG.Num.ParallelJobContainerGen< InputType, ResultType >.EvaluationDelegate
protected getset

Evaluation delegate that is by default used for calculation of results from input data of the parallel job.

This delegate can be specified by the user of the job container object in order to specify means of how job is performed. The delegate is called on input data in order to calculate and provide job results via returned value.

Normally, job is perfomed by the job server object that knows how to perfom the job. However, some job server objects will use this delegate in order toperform the job. The delegate should be accessed through calling the CalculateResultsPlain method.

virtual bool IG.Num.ParallelJobContainerGen< InputType, ResultType >.IsJobDefined
getset

Indicates whether the curren job container can itself execute a job by calling either variant of the RunJob method.

This flag must be consistent with the CalculateResultsPlain and RunJob methods. If any of these method is overridden, consistency must be preserved, which may require overriding the property, too.


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