OpendTect  7.0
Public Member Functions | Static Public Member Functions | Protected Member Functions | 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 ReportingTask.

Inherited by Smoother1D< float >, Stats::ParallelCalc< float >, AGC< T >, Array1DStacker< fT, ArrT >, Array2DConverter, Array2DCopier< T >, Array2DInterpol, Array2DReSampler< T, TT >, Array3DCopier< T >, Array3DFloodfill< T >, Array3DUdfTrcRestorer< T >, ArrayMath::ArrOperExec< OperType, ArrType >, ArrayMath::CumArrOperExec< RT, AT >, ArrayMath::CumSumExec< T >, ArrayNDDataExtracter< T >, ArrayUdfValReplacer< T >, ArrayUdfValRestorer< T >, BendPointFinderBase, BodyVolumeCalculator, ColTab::MapperTask< T >, Convolver2D< T >, Convolver3D< T >, DPSDensityCalcND, DPSFromVolumeFiller, DataDistributionExtracter< vT >, DelaunayTriangulator, Density2RGBArray, DensityCalc, EM::EMObjectPosSelector, EM::EMObjectRowColSelRemoval, 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 >, NearestCoordFinder, ParallelDTetrahedralator, ParallelSorter< T >, PreStack::AngleMuteComputer, PreStack::Processor, RayTracer1D, RayTracerRunner, ReflCalc1D, ReflCalcRunner, ReflectivitySampler, SampledExtremeFinderND< T >, Seis::MultiTraceSynthGenerator, Seis::ParallelReader, Seis::ParallelReader2D, Seis::RaySynthGenerator, SeisDataPackFromDPS, SeisDataPackZAxisTransformer, SeisZAxisStretcher, SeisZAxisStretcherNew, Smoother1D< T >, Stats::ParallelCalc< T >, VDA2DBitMapGenerator [private], ValueSeriesGetAll< T >, Vel::VolumeConverter, Vel::VolumeConverterNew, VolProc::StatsCalculatorTask, VolProc::TutOpCalculatorTask, Well::LogSampler, ZAxisTransformPointGenerator, ZAxisTransformer, visBase::HorizonSectionTilePosSetup, visBase::HorizonTileRenderPreparer, and visBase::HorizonTileResolutionTesselator.

Public Member Functions

virtual ~ParallelTask ()
 
void doParallel (bool yn)
 
bool execute () override
 
virtual bool executeParallel (bool parallel)
 
std::int64_t nrDone () const override
 May be -1, i.e. class does not report nrdone. More...
 
std::int64_t totalNr () const override
 
- Public Member Functions inherited from ReportingTask
virtual ~ReportingTask ()
 
void getProgress (const ReportingTask &)
 
- Public Member Functions inherited from Task
virtual ~Task ()
 
virtual void controlWork (Control)
 
virtual void enableWorkControl (bool=true)
 Must be called before execute() More...
 
virtual uiRetVal errorWithDetails () const
 
virtual Control getState () const
 
virtual uiString uiMessage () const
 will be message() again in 7.x More...
 
virtual uiString uiNrDoneText () const
 will be nrDoneText() in 7.x More...
 
bool workControlEnabled () const
 
- Public Member Functions inherited from NamedCallBacker
 NamedCallBacker (const char *nm=0)
 
 NamedCallBacker (const NamedCallBacker &)
 
virtual Notifier< NamedCallBacker > & objectToBeDeleted () const
 
bool operator== (const NamedCallBacker &oth) const
 
bool operator== (const NamedObject &oth) 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 detachAllNotifiers () const
 Call from the destructor of your inherited object. More...
 
void detachCB (const NotifierAccess &, const CallBack &) const
 
void detachCB (const NotifierAccess *notif, const CallBack &cb) const
 
virtual bool isCapsule () const
 
bool isNotifierAttached (const NotifierAccess *) const
 Only for debugging purposes, don't use. More...
 
void stopReceivingNotifications () const
 
virtual CallBackertrueCaller ()
 
- Public Member Functions inherited from NamedObject
 NamedObject (const char *nm=nullptr)
 
 NamedObject (const NamedObject &oth)
 
virtual ~NamedObject ()
 
virtual BufferString getName () const
 
bool getNameFromPar (const IOPar &)
 
const name_typename () const override
 
NamedObjectoperator= (const NamedObject &)
 
bool operator== (const NamedObject &oth) const
 
virtual void setName (const char *nm)
 
- Public Member Functions inherited from ObjectWithName
virtual ~ObjectWithName ()
 
bool hasName (const char *nm) const
 
bool hasName (const name_type &nm) const
 
void putNameInPar (IOPar &) const
 

Static Public Member Functions

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

Protected Member Functions

 ParallelTask (const char *nm=0)
 
 ParallelTask (const ParallelTask &)
 
void addToNrDone (std::int64_t increment)
 
std::int64_t calculateThreadSize (std::int64_t totalnr, int nrthreads, int thread) const
 
virtual int maxNrThreads () const
 
virtual int minThreadSize () const
 
virtual std::int64_t nrIterations () const =0
 
void quickAddToNrDone (std::int64_t loopidx)
 
void resetNrDone ()
 
virtual bool stopAllOnFailure () const
 
- Protected Member Functions inherited from ReportingTask
 ReportingTask (const char *nm=nullptr)
 
void incrementProgress ()
 
ProgressMeterprogressMeter () const
 
void reportProgressFinished ()
 
void reportProgressStarted ()
 
void resetProgress ()
 
void setProgressMeter (ProgressMeter *) override
 Must be called before execute() More...
 
void updateProgressMeter (bool forced=false, std::int64_t *totalnr=0)
 
void updateReportedName ()
 
- Protected Member Functions inherited from Task
 Task (const char *nm=nullptr)
 
virtual bool shouldContinue ()
 
- Protected Member Functions inherited from NamedCallBacker
void sendDelNotif () const
 

Private Member Functions

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

Private Attributes

Threads::Atomic< std::int64_t > nrdone_
 
std::int64_t nrdonebigchunksz_
 
bool parallel_ = true
 
std::int64_t totalnrcache_
 

Friends

class ParallelTaskRunner
 

Additional Inherited Members

- Public Types inherited from Task
enum  Control { Run , Pause , Stop }
 
- Public Types inherited from ObjectWithName
typedef OD::String name_type
 
- Public Attributes inherited from ReportingTask
Notifier< ReportingTaskprogressUpdated
 
- Protected Attributes inherited from Task
Control control_
 
Threads::ConditionVarworkcontrolcondvar_
 
- Protected Attributes inherited from NamedCallBacker
Threads::Atomic< bool > delalreadytriggered_
 
Notifier< NamedCallBackerdelnotif_
 
- 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;
}
};
Generalization of a task that can be run in parallel.
Definition: paralleltask.h:63
virtual std::int64_t nrIterations() const =0
void addToNrDone(std::int64_t increment)
virtual bool doWork(std::int64_t start, std::int64_t stop, int threadidx)=0
virtual bool shouldContinue()

and in use that instead of the for-loop:

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

<>

Constructor & Destructor Documentation

◆ ~ParallelTask()

virtual ParallelTask::~ParallelTask ( )
virtual

◆ ParallelTask() [1/2]

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

◆ ParallelTask() [2/2]

ParallelTask::ParallelTask ( const ParallelTask )
protected

Member Function Documentation

◆ addToNrDone()

void ParallelTask::addToNrDone ( std::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

◆ calculateThreadSize()

std::int64_t ParallelTask::calculateThreadSize ( std::int64_t  totalnr,
int  nrthreads,
int  thread 
) const
protected

◆ doFinish()

virtual bool ParallelTask::doFinish ( bool  success)
inlineprivatevirtual

◆ doParallel()

void ParallelTask::doParallel ( bool  yn)
inline

◆ doPrepare()

virtual bool ParallelTask::doPrepare ( int  nrthreads)
inlineprivatevirtual

Called once, before any doWork is called.

Reimplemented in Density2RGBArray, GMTArray2DInterpol, LogCubeCreator, Well::LogSampler, visBase::HorizonTileRenderPreparer, visBase::HorizonTileResolutionTesselator, Vel::VolumeConverter, Vel::VolumeConverterNew, Seis::RaySynthGenerator, Seis::MultiTraceSynthGenerator, SeisZAxisStretcher, SeisZAxisStretcherNew, PreStack::AngleMuteComputer, MarchingCubesSurfaceEditor, MarchingCubes2Implicit, ReflCalcRunner, RayTracerRunner, FaultTraceExtractor2D, FaultTraceExtractor3D, FaultTraceExtractor, EM::EMObjectPosSelector, MemValReplacer< T >, MemCopier< T >, MemSetter< T >, ZAxisTransformer, Stats::ParallelCalc< T >, Stats::ParallelCalc< float >, Smoother1D< T >, Smoother1D< float >, ImageResizer, ReflectivitySampler, ReflCalc1D, RayTracer1D, FourierInterpol3D, FourierInterpol2D, FourierInterpol1D, Fourier::CC::CC1D, ParallelDTetrahedralator, DelaunayTriangulator, DataDistributionExtracter< vT >, Convolver2D< T >, ContinuousCurvatureArray2DInterpol, BendPointFinderBase, MuteArrayExtracter< T >, ArrayUdfValReplacer< T >, ArrayMath::ArrOperExec< OperType, ArrType >, Array3DCopier< T >, Array2DCopier< T >, TriangulationArray2DInterpol, InverseDistanceArray2DInterpol, Array2DInterpol, EM::EMObjectRowColSelRemoval, ParallelSorter< T >, Seis::ParallelReader2D, Seis::ParallelReader, SeisDataPackZAxisTransformer, SeisDataPackFromDPS, PreStack::AngleMute, ZAxisTransformPointGenerator, EM::Expl2ImplBodyExtracter, NearestCoordFinder, Array1DStacker< fT, ArrT >, ArrayMath::CumSumExec< T >, ArrayMath::CumArrOperExec< RT, AT >, Array2DFromXYConverter, and AGC< T >.

◆ doWork()

virtual bool ParallelTask::doWork ( std::int64_t  start,
std::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
startfirst index
stoplast index
threadidxgives an identifier (between 0 and nr of threads -1) that is unique to each call to doWork.

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

◆ execute()

bool ParallelTask::execute ( )
inlineoverridevirtual

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.

◆ executeParallel()

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 >.

◆ maxNrThreads()

virtual int ParallelTask::maxNrThreads ( ) const
protectedvirtual

◆ minThreadSize()

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 MemValReplacer< T >, MemCopier< T >, MemSetter< T >, TriangulationArray2DInterpol, AGC< T >, and ParallelSorter< T >.

◆ nrDone()

std::int64_t ParallelTask::nrDone ( ) const
overridevirtual

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

Reimplemented from Task.

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

◆ nrIterations()

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

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

◆ quickAddToNrDone()

void ParallelTask::quickAddToNrDone ( std::int64_t  loopidx)
protected

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

◆ resetNrDone()

void ParallelTask::resetNrDone ( )
protected

◆ sPosFinished()

static uiString ParallelTask::sPosFinished ( )
inlinestatic

◆ stopAllOnFailure()

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.

◆ sTrcFinished()

static uiString ParallelTask::sTrcFinished ( )
inlinestatic

◆ totalNr()

std::int64_t ParallelTask::totalNr ( ) const
inlineoverridevirtual

Friends And Related Function Documentation

◆ ParallelTaskRunner

friend class ParallelTaskRunner
friend

Member Data Documentation

◆ nrdone_

Threads::Atomic< std::int64_t > ParallelTask::nrdone_
private

◆ nrdonebigchunksz_

std::int64_t ParallelTask::nrdonebigchunksz_
private

◆ parallel_

bool ParallelTask::parallel_ = true
private

◆ totalnrcache_

std::int64_t ParallelTask::totalnrcache_
private

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