OpendTect-6_4  6.4
paralleltask.h
Go to the documentation of this file.
1 #ifndef paralleltask_h
2 #define paralleltask_h
3 
4 /*+
5 ________________________________________________________________________
6 
7  (C) dGB Beheer B.V.; (LICENSE) http://opendtect.org/OpendTect_license.txt
8  Author: A.H.Bril/K.Tingdahl
9  Date: 13-10-1999
10  RCS: $Id$
11 ________________________________________________________________________
12 
13 -*/
14 
15 #include "basicmod.h"
16 #include "task.h"
17 #include "atomic.h"
18 
19 class ParallelTaskRunner;
20 
21 
66 mExpClass(Basic) ParallelTask : public Task
68 public:
69  virtual ~ParallelTask();
70 
71  bool execute() { return executeParallel(true); }
77  virtual bool executeParallel(bool parallel);
84  void setProgressMeter(ProgressMeter*);
85  od_int64 nrDone() const;
87 
88  od_int64 totalNr() const { return nrIterations(); }
89  static uiString sPosFinished() { return tr("Positions finished"); }
90  static uiString sTrcFinished() { return tr("Traces finished"); }
91 
92 protected:
93 
94  virtual od_int64 nrIterations() const = 0;
97  virtual int maxNrThreads() const;
98  virtual int minThreadSize() const { return 1; }
103  virtual bool stopAllOnFailure() const { return true; }
109  ParallelTask(const char* nm=0);
110  ParallelTask(const ParallelTask&);
111  od_int64 calculateThreadSize(od_int64 totalnr,int nrthreads,
112  int thread) const;
113 
114  void addToNrDone(od_int64 increment);
119  void quickAddToNrDone(od_int64 loopidx);
123  void resetNrDone();
124 
125 private:
126  virtual bool doWork(od_int64 start,od_int64 stop,int threadidx) = 0;
134  virtual bool doPrepare(int nrthreads) { return true; }
136  virtual bool doFinish(bool success) { return success; }
141  friend class ParallelTaskRunner;
144 
145 private:
146 
149 
150 };
151 
152 
181 #define mDeclareParallelCalcStd(uimsg) \
182  od_int64 sz_; \
183  bool reportprogress_; \
184  void setReport(bool yn) { reportprogress_ = yn; } \
185  od_int64 nrIterations() const { return sz_; } \
186  uiString uiMessage() const { return uimsg; } \
187  uiString uiNrDoneText() const { return sPosFinished(); } \
188 
189 #define mDefParallelCalcNoPars(clss,uimsg) \
190  class clss : public ParallelTask \
191  { mODTextTranslationClass(clss); \
192  public: \
193  mDeclareParallelCalcStd(uimsg); \
194  clss( od_int64 _sz_ ) : sz_(_sz_), reportprogress_(true) {} \
195 
196 #define mDefParallelCalc1Par(clss,uimsg,T1,v1) \
197  class clss : public ParallelTask \
198  { mODTextTranslationClass(clss); \
199  public: \
200  mDeclareParallelCalcStd(uimsg); \
201  T1 v1##_; \
202  clss( od_int64 _sz_, T1 _##v1##_ ) \
203  : sz_(_sz_), reportprogress_(true), v1##_(_##v1##_) {} \
204 
205 #define mDefParallelCalc2Pars(clss,uimsg,T1,v1,T2,v2) \
206  class clss : public ParallelTask \
207  { mODTextTranslationClass(clss); \
208  public: \
209  mDeclareParallelCalcStd(uimsg); \
210  T1 v1##_; T2 v2##_; \
211  clss( od_int64 _sz_, T1 _##v1##_, T2 _##v2##_ ) \
212  : sz_(_sz_), reportprogress_(true) \
213  , v1##_(_##v1##_), v2##_(_##v2##_) {} \
214 
215 #define mDefParallelCalc3Pars(clss,uimsg,T1,v1,T2,v2,T3,v3) \
216  class clss : public ParallelTask \
217  { mODTextTranslationClass(clss); \
218  public: \
219  mDeclareParallelCalcStd(uimsg); \
220  T1 v1##_; T2 v2##_; T3 v3##_; \
221  clss( od_int64 _sz_, \
222  T1 _##v1##_, T2 _##v2##_, T3 _##v3##_ ) \
223  : sz_(_sz_), reportprogress_(true) \
224  , v1##_(_##v1##_), v2##_(_##v2##_) , v3##_(_##v3##_) {} \
225 
226 #define mDefParallelCalc4Pars(clss,uimsg,T1,v1,T2,v2,T3,v3,T4,v4) \
227  class clss : public ParallelTask \
228  { mODTextTranslationClass(clss); \
229  public: \
230  mDeclareParallelCalcStd(uimsg); \
231  T1 v1##_; T2 v2##_; T3 v3##_; T4 v4##_; \
232  clss( od_int64 _sz_, \
233  T1 _##v1##_, T2 _##v2##_, T3 _##v3##_, T4 _##v4##_ ) \
234  : sz_(_sz_), reportprogress_(true) \
235  , v1##_(_##v1##_), v2##_(_##v2##_) \
236  , v3##_(_##v3##_), v4##_(_##v4##_) {} \
237 
238 
239 #define mDefParallelCalc5Pars(clss,uimsg,T1,v1,T2,v2,T3,v3,T4,v4,T5,v5) \
240  class clss : public ParallelTask \
241  { mODTextTranslationClass(clss); \
242  public: \
243  mDeclareParallelCalcStd(uimsg); \
244  T1 v1##_; T2 v2##_; T3 v3##_; T4 v4##_; T5 v5##_;\
245  clss( od_int64 _sz_, T1 _##v1##_, T2 _##v2##_, T3 _##v3##_, \
246  T4 _##v4##_, T5 _##v5##_ ) \
247  : sz_(_sz_), reportprogress_(true) \
248  , v1##_(_##v1##_), v2##_(_##v2##_) \
249  , v3##_(_##v3##_), v4##_(_##v4##_), v5##_(_##v5##_) {} \
250 
251 #define mDefParallelCalc6Pars(clss,uimsg,T1,v1,T2,v2,T3,v3,T4,v4,T5,v5,T6,v6) \
252  class clss : public ParallelTask \
253  { mODTextTranslationClass(clss); \
254  public: \
255  mDeclareParallelCalcStd(uimsg); \
256  T1 v1##_; T2 v2##_; T3 v3##_; T4 v4##_; T5 v5##_; T6 v6##_;\
257  clss( od_int64 _sz_, T1 _##v1##_, T2 _##v2##_, T3 _##v3##_, \
258  T4 _##v4##_, T5 _##v5##_, T6 _##v6##_ ) \
259  : sz_(_sz_), reportprogress_(true) \
260  , v1##_(_##v1##_), v2##_(_##v2##_) \
261  , v3##_(_##v3##_), v4##_(_##v4##_) \
262  , v5##_(_##v5##_), v6##_(_##v6##_) {} \
263 
264 #define mDefParallelCalc7Pars(clss,uimsg,T1,v1,T2,v2,T3,v3,T4,v4,T5,v5, \
265  T6,v6,T7,v7) \
266  class clss : public ParallelTask \
267  { mODTextTranslationClass(clss); \
268  public: \
269  mDeclareParallelCalcStd(uimsg); \
270  T1 v1##_; T2 v2##_; T3 v3##_; T4 v4##_; \
271  T5 v5##_; T6 v6##_; T7 v7##_; \
272  clss( od_int64 _sz_, T1 _##v1##_, T2 _##v2##_, T3 _##v3##_, \
273  T4 _##v4##_, T5 _##v5##_, T6 _##v6##_, T7 _##v7##_ ) \
274  : sz_(_sz_), reportprogress_(true) \
275  , v1##_(_##v1##_), v2##_(_##v2##_) \
276  , v3##_(_##v3##_), v4##_(_##v4##_) \
277  , v5##_(_##v5##_), v6##_(_##v6##_), v7##_(_##v7##_) {} \
278 
279 #define mDefParallelCalcBody(preop,impl,postop) \
280  bool doWork( od_int64 start, od_int64 stop, int ) \
281  { \
282  preop; \
283  for ( od_int64 idx=start; idx<=stop; idx++ ) \
284  { impl; if ( reportprogress_ ) quickAddToNrDone(idx); } \
285  postop; \
286  return true; \
287  } \
288  };
289 
290 #endif
#define mExpClass(module)
Definition: commondefs.h:160
virtual bool stopAllOnFailure() const
Definition: paralleltask.h:103
static uiString sTrcFinished()
Definition: paralleltask.h:90
is an interface where processes can report their progress.
Definition: progressmeter.h:21
#define mODTextTranslationClass(clss)
Definition: uistring.h:38
ProgressMeter * progressmeter_
Definition: paralleltask.h:142
#define od_int64
Definition: plftypes.h:36
Definition: uistring.h:89
Threads::Atomic< int64_t > nrdone_
Definition: paralleltask.h:143
Generalization of a task that can be run in parallel.
Definition: paralleltask.h:66
virtual int minThreadSize() const
Definition: paralleltask.h:98
static uiString sPosFinished()
Definition: paralleltask.h:89
bool execute()
Definition: paralleltask.h:71
virtual bool doFinish(bool success)
Definition: paralleltask.h:136
int64_t totalNr() const
Definition: paralleltask.h:88
int64_t totalnrcache_
Definition: paralleltask.h:147
Definition: atomic.h:33
virtual bool doPrepare(int nrthreads)
Definition: paralleltask.h:134
Generalization of something (e.g. a computation) that needs to be done in multiple steps...
Definition: task.h:28
int64_t nrdonebigchunksz_
Definition: paralleltask.h:148

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