OpendTect  6.3
Public Member Functions | Static Public Member Functions | Protected Member Functions | Private Member Functions | Static Private Member Functions | Private Attributes | Friends | List of all members
ParallelTask Class Referenceabstract

Generalization of a task that can be run in parallel. More...

Inherits Task.

Inherited by AGC< T >, Array1DStacker< fT, ArrT >, Array2DCopier< T >, Array2DInterpol, Array2DReSampler< T, TT >, Array3DCopier< T >, Array3DFloodfill< T >, Array3DUdfTrcRestorer< T >, ArrayMath::ArrOperExec< ArrType, SumType, OperType >, ArrayMath::CumArrOperExec< ArrType, SumType, OperType, RetType >, ArrayNDDataExtracter< T >, ArrayUdfValReplacer< T >, ArrayUdfValRestorer< T >, BendPointFinderBase, BodyVolumeCalculator, Convolver2D< T >, Convolver3D< T >, Convolver3D< float >, DataDistributionExtracter< vT >, DelaunayTriangulator, DensityCalc, DPSDensityCalcND, DPSFromVolumeFiller, EM::EMObjectPosSelector, EM::Expl2ImplBodyExtracter, EM::HorizonMerger, FaultTraceExtractor, Fourier::CC::CC1D, FourierInterpol1D, FourierInterpol2D, FourierInterpol3D, Geometry::ArrayTesselator, ImageResizer, Implicit2MarchingCubes, Line2DInterSectionFinder, LogCubeCreator, MarchingCubes2Implicit, MarchingCubesSurfaceEditor, MemCopier< T >, MemSetter< T >, MemValReplacer< T >, MuteArrayExtracter< T >, Stats::ParallelCalc< float >, ParallelDTetrahedralator, ParallelSorter< T >, PreStack::AngleMuteComputer, PreStack::Processor, RaySynthGenerator, RayTracer1D, RayTracerRunner, ReflectivitySampler, SampledExtremeFinderND< T >, Seis::MultiTraceSynthGenerator, Seis::ParallelFSLoader2D, Seis::ParallelFSLoader3D, SeisZAxisStretcher, Smoother1D< T >, Smoother1D< float >, Stats::ParallelCalc< T >, ValueSeriesGetAll< T >, VDA2DBitMapGenerator [private], Vel::VolumeConverter, visBase::HorizonSectionTilePosSetup, visBase::HorizonTileRenderPreparer, visBase::HorizonTileResolutionTesselator, VolProc::StatsCalculatorTask, VolumeDataPackZAxisTransformer, Well::LogSampler, ZAxisTransformer, and ZAxisTransformPointGenerator.

Public Member Functions

virtual ~ParallelTask ()
 
bool execute ()
 
virtual bool executeParallel (bool parallel)
 
void setProgressMeter (ProgressMeter *)
 Must be called before execute() More...
 
int64_t nrDone () const
 May be -1, i.e. class does not report nrdone. More...
 
int64_t totalNr () const
 
- Public Member Functions inherited from Task
virtual ~Task ()
 
virtual uiString message () const
 
virtual uiString nrDoneText () const
 
virtual uiRetVal errorWithDetails () const
 
virtual void enableWorkControl (bool=true)
 Must be called before execute() More...
 
bool workControlEnabled () const
 
virtual void controlWork (Control)
 
virtual Control getState () const
 
- Public Member Functions inherited from NamedCallBacker
 NamedCallBacker (const char *nm=0)
 
 NamedCallBacker (const NamedCallBacker &)
 
bool operator== (const NamedCallBacker &oth) const
 
bool operator== (const NamedObject &oth) const
 
virtual Notifier< NamedCallBacker > & objectToBeDeleted () const
 
- Public Member Functions inherited from CallBacker
 CallBacker ()
 
 CallBacker (const CallBacker &)
 
virtual ~CallBacker ()
 
bool attachCB (const NotifierAccess &, const CallBack &, bool onlyifnew=false) const
 
bool attachCB (const NotifierAccess *notif, const CallBack &cb, bool onlyifnew=false) const
 
void detachCB (const NotifierAccess &, const CallBack &) const
 
void detachCB (const NotifierAccess *notif, const CallBack &cb) const
 
bool isNotifierAttached (const NotifierAccess *) const
 Only for debugging purposes, don't use. More...
 
virtual bool isCapsule () const
 
void stopReceivingNotifications () const
 
- Public Member Functions inherited from NamedObject
 NamedObject (const char *nm=0)
 
 NamedObject (const NamedObject &oth)
 
virtual ~NamedObject ()
 
NamedObjectoperator= (const NamedObject &)
 
bool operator== (const NamedObject &oth) const
 
virtual const OD::Stringname () const
 
virtual BufferString getName () const
 
virtual void setName (const char *nm)
 
bool getNameFromPar (const IOPar &)
 
void putNameInPar (IOPar &) const
 

Static Public Member Functions

static uiString sPosFinished ()
 
static uiString sTrcFinished ()
 
- Static Public Member Functions inherited from Task
static uiString stdMessage ()
 
static uiString stdNrDoneText ()
 
- Static Public Member Functions inherited from CallBacker
static void createReceiverForCurrentThread ()
 
static void removeReceiverForCurrentThread ()
 

Protected Member Functions

virtual int64_t nrIterations () const =0
 
virtual int maxNrThreads () const
 
virtual int minThreadSize () const
 
virtual bool stopAllOnFailure () const
 
 ParallelTask (const char *nm=0)
 
 ParallelTask (const ParallelTask &)
 
int64_t calculateThreadSize (int64_t totalnr, int nrthreads, int thread) const
 
void addToNrDone (int64_t increment)
 
void quickAddToNrDone (int64_t loopidx)
 
void resetNrDone ()
 
- Protected Member Functions inherited from Task
 Task (const char *nm=0)
 
virtual bool shouldContinue ()
 
- Protected Member Functions inherited from NamedCallBacker
void sendDelNotif () const
 
- Protected Member Functions inherited from CallBacker
void detachAllNotifiers () const
 Call from the destructor of your inherited object. More...
 

Private Member Functions

virtual bool doWork (int64_t start, int64_t stop, int threadidx)=0
 
virtual bool doPrepare (int nrthreads)
 
virtual bool doFinish (bool success)
 

Static Private Member Functions

static uiString tr (const char *text, const char *disambiguation=0, int pluralnr=-1)
 
static uiString legacyTr (const char *text, const char *disambiguation=0, int pluralnr=-1)
 

Private Attributes

ProgressMeterprogressmeter_
 
Threads::Atomic< int64_t > nrdone_
 
int64_t totalnrcache_
 
int64_t nrdonebigchunksz_
 

Friends

class ParallelTaskRunner
 

Additional Inherited Members

- Public Types inherited from Task
enum  Control { Run, Pause, Stop }
 
- Protected Attributes inherited from Task
Control control_
 
Threads::ConditionVarworkcontrolcondvar_
 
- Protected Attributes inherited from NamedCallBacker
Notifier< NamedCallBackerdelnotif_
 
Threads::Atomic< bool > delalreadytriggered_
 
- Protected Attributes inherited from NamedObject
BufferString name_
 

Detailed Description

Generalization of a task that can be run in parallel.

Any task that has a fixed number of computations that are independent (i.e. they don't need to be done in a certain order) can inherit ParallelTask and be executed in parallel by calling the ParallelTask::execute().

Example of usage:

float result[N];
for ( int idx=0; idx<N; idx++ )
result[idx] = input1[idx]* function( idx, other, variables );

Could be made parallel by adding the class:

class CalcClass : public ParallelTask
{
public:
od_int64 nrIterations() const { return N; }
int doWork( od_int64 start, od_int64 stop, int threadid )
{
for ( int idx=start;idx<=stop &&shouldContinue();idx++ )
{
result[idx] = input1[idx] *
function( idx, other, variables );
}
return true;
}
};

and in use that instead of the for-loop:

CalcClass myclass( N, my, parameters );
myclass.exectute();

Constructor & Destructor Documentation

virtual ParallelTask::~ParallelTask ( )
virtual
ParallelTask::ParallelTask ( const char *  nm = 0)
protected
ParallelTask::ParallelTask ( const ParallelTask )
protected

Member Function Documentation

void ParallelTask::addToNrDone ( int64_t  increment)
protected

Call this from within your thread to say that you have done something. Do NOT call in very fast loops at every idx since it can impact negatively performance

int64_t ParallelTask::calculateThreadSize ( int64_t  totalnr,
int  nrthreads,
int  thread 
) const
protected
virtual bool ParallelTask::doFinish ( bool  success)
inlineprivatevirtual
virtual bool ParallelTask::doPrepare ( int  nrthreads)
inlineprivatevirtual
virtual bool ParallelTask::doWork ( int64_t  start,
int64_t  stop,
int  threadidx 
)
privatepure virtual

The functions that does the job. The function will be called with all intervals from 0 to ParallelTask::nrIterations()-1. The function must be designed to be able to run in parallel.

Parameters
threadidgives an identifier (between 0 and nr of threads -1) that is unique to each call to doWork.

Implemented in ArrayNDDataExtracter< T >, MemValReplacer< T >, MemCopier< T >, ValueSeriesGetAll< T >, and MemSetter< T >.

bool ParallelTask::execute ( )
inlinevirtual

Runs the process the desired number of times.

Note
that the function has static threads (normally the same number as there are processors on the machine), and these static threads will be shared by all instances of ParallelTask::execute.

Implements Task.

virtual bool ParallelTask::executeParallel ( bool  parallel)
virtual

Runs the process the desired number of times.

Note
that the function has static threads (normally the same number as there are processors on the machine), and these static threads will be shared by all instances of ParallelTask::execute.

Reimplemented in Convolver3D< T >, Convolver3D< float >, and RayTracerRunner.

static uiString ParallelTask::legacyTr ( const char *  text,
const char *  disambiguation = 0,
int  pluralnr = -1 
)
inlinestaticprivate
virtual int ParallelTask::maxNrThreads ( ) const
protectedvirtual
virtual int ParallelTask::minThreadSize ( ) const
inlineprotectedvirtual
Returns
the minimum number of computations that effectively can be run in a separate thread. A small number will give a large overhead for when each step is quick and nrIterations is not big.

Reimplemented in TriangulationArray2DInterpol, MemValReplacer< T >, ParallelSorter< T >, MemCopier< T >, MemSetter< T >, and AGC< T >.

int64_t ParallelTask::nrDone ( ) const
virtual

May be -1, i.e. class does not report nrdone.

Reimplemented from Task.

Reimplemented in MarchingCubes2Implicit, ParallelSorter< T >, RaySynthGenerator, DPSDensityCalcND, DensityCalc, and RayTracerRunner.

virtual int64_t ParallelTask::nrIterations ( ) const
protectedpure virtual
Returns
the number of times the process should be run.

Implemented in MuteArrayExtracter< T >, Array3DUdfTrcRestorer< T >, ArrayUdfValRestorer< T >, ArrayUdfValReplacer< T >, Array3DCopier< T >, Array2DCopier< T >, ArrayNDDataExtracter< T >, Well::LogSampler, DPSFromVolumeFiller, ArrayMath::ArrOperExec< ArrType, SumType, OperType >, ExtensionArray2DInterpol, Seis::MultiTraceSynthGenerator, MarchingCubes2Implicit, FaultTraceExtractor, FourierInterpol3D, TriangulationArray2DInterpol, DelaunayTriangulator, ParallelDTetrahedralator, MemValReplacer< T >, Seis::ParallelFSLoader2D, Implicit2MarchingCubes, VDA2DBitMapGenerator, ParallelSorter< T >, visBase::HorizonSectionTilePosSetup, FourierInterpol2D, EM::Expl2ImplBodyExtracter, Line2DInterSectionFinder, PreStack::AngleMute, MemCopier< T >, Seis::ParallelFSLoader3D, ArrayMath::CumArrOperExec< ArrType, SumType, OperType, RetType >, Array1DStacker< fT, ArrT >, RayTracer1D, VolProc::StatsCalculatorTask, LogCubeCreator, Convolver2D< T >, InverseDistanceArray2DInterpol, Fourier::CC::CC1D, ValueSeriesGetAll< T >, MarchingCubesSurfaceEditor, visBase::HorizonTileRenderPreparer, PreStack::TrimStatics, Array2DReSampler< T, TT >, FourierInterpol1D, PreStack::Mute, RaySynthGenerator, Array3DFloodfill< T >, DataDistributionExtracter< vT >, PreStack::Processor, MemSetter< T >, PreStack::LateralStack, EM::Horizon3DMerger, SeisZAxisStretcher, Smoother1D< T >, Smoother1D< float >, Convolver3D< T >, Stats::ParallelCalc< T >, Convolver3D< float >, Stats::ParallelCalc< float >, ZAxisTransformer, Convolver2D< T >, PreStack::AngleMuteComputer, Vel::VolumeConverter, PreStack::Stack, AGC< T >, visBase::HorizonTileResolutionTesselator, VolumeDataPackZAxisTransformer, RayTracerRunner, ReflectivitySampler, SampledExtremeFinderND< T >, ZAxisTransformPointGenerator, EM::EMObjectPosSelector, DensityCalc, BodyVolumeCalculator, ContinuousCurvatureArray2DInterpol, DPSDensityCalcND, Geometry::ArrayTesselator, BendPointFinderBase, and ImageResizer.

void ParallelTask::quickAddToNrDone ( int64_t  loopidx)
protected

Call this from within your thread to say that you have done something, but not very often

void ParallelTask::resetNrDone ( )
protected
void ParallelTask::setProgressMeter ( ProgressMeter )
virtual

Must be called before execute()

Reimplemented from Task.

static uiString ParallelTask::sPosFinished ( )
inlinestatic
virtual bool ParallelTask::stopAllOnFailure ( ) const
inlineprotectedvirtual

If one thread fails, should an attempt be made to stop the others? If true, enableWorkControl will be enabled, and threads should call shouldContinue() regularly.

Reimplemented in LogCubeCreator.

static uiString ParallelTask::sTrcFinished ( )
inlinestatic
int64_t ParallelTask::totalNr ( ) const
inlinevirtual
static uiString ParallelTask::tr ( const char *  text,
const char *  disambiguation = 0,
int  pluralnr = -1 
)
inlinestaticprivate

Friends And Related Function Documentation

friend class ParallelTaskRunner
friend

Member Data Documentation

Threads::Atomic< int64_t > ParallelTask::nrdone_
private
int64_t ParallelTask::nrdonebigchunksz_
private
ProgressMeter* ParallelTask::progressmeter_
private
int64_t ParallelTask::totalnrcache_
private

Generated at for the OpendTect seismic interpretation project. Copyright (C): dGB Beheer B. V. 2017