OpendTect 8.0
Loading...
Searching...
No Matches
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...

#include <paralleltask.h>

Inherits ReportingTask.

Inherited by Convolver3D< float >, 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 >, ArrayNDDataSetter< T >, ArrayUdfValReplacer< T >, ArrayUdfValRestorer< T >, BendPointFinder2DGeomSet, BendPointFinderBase, BodyVolumeCalculator, ColTab::MapperTask< T >, Convolver2D< T >, Convolver3D< T >, DPSDensityCalcND, DPSFromVolumeFiller, DataDistributionExtracter< vT >, DelaunayTriangulator, Density2RGBArray, DensityCalc, EM::EMObjectPosSelector, EM::EMObjectRowColSelRemoval, EM::Expl2ImplBodyExtracter, EM::FaultDataUpdater, EM::FaultStickSetGeometry::GeomGroupUpdater, 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, ObjectSetDeleter< T >, 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, Smoother1D< T >, Stats::ParallelCalc< T >, VDA2DBitMapGenerator [private], ValueSeriesGetAll< T >, Vel::VolumeConverter, 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)
 
od_int64 nrDone () const override
 May be -1, i.e. class does not report nrdone.
 
od_int64 totalNr () const override
 
- Public Member Functions inherited from ReportingTask
 ReportingTask (const ReportingTask &)=delete
 
virtual ~ReportingTask ()
 
void getProgress (const ReportingTask &)
 
ReportingTaskoperator= (const ReportingTask &)=delete
 
void setSimpleMeter (bool yn, int repperc)
 
int simpleMeterStep () const
 
bool useSimpleMeter () const
 
- Public Member Functions inherited from Task
 Task (const Task &)=delete
 
virtual ~Task ()
 
virtual void controlWork (Control)
 
virtual void enableWorkControl (bool=true)
 Must be called before execute()
 
virtual uiRetVal errorWithDetails () const
 
virtual Control getState () const
 
Taskoperator= (const Task &)=delete
 
virtual uiString uiMessage () const
 
virtual uiString uiNrDoneText () const
 
bool workControlEnabled () const
 
- Public Member Functions inherited from NamedCallBacker
 NamedCallBacker (const char *nm=nullptr)
 
 NamedCallBacker (const NamedCallBacker &)=delete
 
 ~NamedCallBacker ()
 
virtual Notifier< NamedCallBacker > & objectToBeDeleted () const
 
NamedCallBackeroperator= (const NamedCallBacker &)=delete
 
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.
 
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.
 
CallBackeroperator= (const CallBacker &)=delete
 
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 ReportingTask
static PtrMan< ProgressMetergetTextProgressMeter (od_ostream &, const IOPar *iop=nullptr)
 
static bool needSimpleLogging (const IOPar &)
 
static const char * sKeySimpleLogging ()
 
static const char * sKeySimpleLoggingStep ()
 
- Static Public Member Functions inherited from Task
static uiString uiStdNrDoneText ()
 
- Static Public Member Functions inherited from CallBacker
static void createReceiverForCurrentThread ()
 
static void removeReceiverForCurrentThread ()
 

Protected Member Functions

 ParallelTask (const char *nm=0)
 
void addToNrDone (od_int64 increment)
 
od_int64 calculateThreadSize (od_int64 totalnr, int nrthreads, int thread) const
 
virtual int maxNrThreads () const
 
virtual int minThreadSize () const
 
virtual od_int64 nrIterations () const =0
 
void quickAddToNrDone (od_int64 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()
 
void updateProgressMeter (bool forced=false, od_int64 *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 (od_int64 start, od_int64 stop, int threadidx)=0
 

Private Attributes

Threads::Atomic< od_int64 > nrdone_
 
od_int64 nrdonebigchunksz_
 
bool parallel_ = true
 
od_int64 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_ = Task::Run
 
Threads::ConditionVarworkcontrolcondvar_ = nullptr
 
- 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 );
addToNrDone( 1 );
}
return true;
}
};
Generalization of a task that can be run in parallel.
Definition paralleltask.h:63

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()

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

Member Function Documentation

◆ addToNrDone()

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

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

◆ doWork()

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

◆ 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 >, and Convolver3D< float >.

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

◆ nrDone()

od_int64 ParallelTask::nrDone ( ) const
overridevirtual

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

Reimplemented from Task.

Reimplemented in RayTracerRunner, and ReflCalcRunner.

◆ nrIterations()

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

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

◆ quickAddToNrDone()

void ParallelTask::quickAddToNrDone ( od_int64 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()

od_int64 ParallelTask::totalNr ( ) const
inlineoverridevirtual

Reimplemented from Task.

Reimplemented in VolProc::StatsCalculatorTask, and VolProc::TutOpCalculatorTask.

Friends And Related Symbol Documentation

◆ ParallelTaskRunner

friend class ParallelTaskRunner
friend

Member Data Documentation

◆ nrdone_

Threads::Atomic<od_int64> ParallelTask::nrdone_
private

◆ nrdonebigchunksz_

od_int64 ParallelTask::nrdonebigchunksz_
private

◆ parallel_

bool ParallelTask::parallel_ = true
private

◆ totalnrcache_

od_int64 ParallelTask::totalnrcache_
private

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