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.
|
| virtual bool | doFinish (bool success) |
| |
| virtual bool | doPrepare (int nrthreads) |
| |
| virtual bool | doWork (od_int64 start, od_int64 stop, int threadidx)=0 |
| |
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:
{
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();
<>
◆ ~ParallelTask()
| virtual ParallelTask::~ParallelTask |
( |
| ) |
|
|
virtual |
◆ ParallelTask()
| ParallelTask::ParallelTask |
( |
const char * | nm = 0 | ) |
|
|
protected |
◆ 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 |
Called after all doWork have finished.
- Parameters
-
| success | indicates whether all doWork returned true. |
Reimplemented in ArrayMath::CumArrOperExec< RT, AT >, ArrayMath::CumSumExec< T >, ObjectSetDeleter< T >, NearestCoordFinder, EM::Horizon3DMerger, ZAxisTransformPointGenerator, Line2DInterSectionFinder, PreStack::AngleMuteComputer, SeisDataPackZAxisTransformer, ParallelSorter< T >, Stats::ParallelCalc< T >, Stats::ParallelCalc< float >, BendPointFinderBase, FourierInterpol1D, FourierInterpol2D, FourierInterpol3D, RayTracer1D, ReflCalc1D, ReflectivitySampler, ImageResizer, Stats::ParallelCalc< T >, Stats::ParallelCalc< float >, EM::FaultDataUpdater, FaultTraceExtractor, FaultTraceExtractor2D, RayTracerRunner, ReflCalcRunner, BendPointFinder2DGeomSet, MarchingCubesSurfaceEditor, Seis::ParallelReader, Seis::ParallelReader2D, SeisZAxisStretcher, Seis::MultiTraceSynthGenerator, Seis::RaySynthGenerator, Vel::VolumeConverter, visBase::HorizonSectionTilePosSetup, LogCubeCreator, and GMTArray2DInterpol.
◆ 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
-
| start | first index |
| stop | last index |
| threadidx | gives 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 |
◆ nrDone()
| od_int64 ParallelTask::nrDone |
( |
| ) |
const |
|
overridevirtual |
◆ 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 |
◆ ParallelTaskRunner
| friend class ParallelTaskRunner |
|
friend |
◆ nrdone_
◆ nrdonebigchunksz_
| od_int64 ParallelTask::nrdonebigchunksz_ |
|
private |
◆ parallel_
| bool ParallelTask::parallel_ = true |
|
private |
◆ totalnrcache_
| od_int64 ParallelTask::totalnrcache_ |
|
private |