EGSnrc C++ class library  Report PIRS-898 (2021)
Iwan Kawrakow, Ernesto Mainegra-Hing, Frederic Tessier, Reid Townson and Blake Walters
egs_run_control.h
Go to the documentation of this file.
1 /*
2 ###############################################################################
3 #
4 # EGSnrc egs++ run control headers
5 # Copyright (C) 2015 National Research Council Canada
6 #
7 # This file is part of EGSnrc.
8 #
9 # EGSnrc is free software: you can redistribute it and/or modify it under
10 # the terms of the GNU Affero General Public License as published by the
11 # Free Software Foundation, either version 3 of the License, or (at your
12 # option) any later version.
13 #
14 # EGSnrc is distributed in the hope that it will be useful, but WITHOUT ANY
15 # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
16 # FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for
17 # more details.
18 #
19 # You should have received a copy of the GNU Affero General Public License
20 # along with EGSnrc. If not, see <http://www.gnu.org/licenses/>.
21 #
22 ###############################################################################
23 #
24 # Author: Iwan Kawrakow, 2005
25 #
26 # Contributors: Frederic Tessier
27 # Ernesto Mainegra-Hing
28 # Blake Walters
29 # Reid Townson
30 #
31 ###############################################################################
32 */
33 
34 
40 #ifndef EGS_RUN_CONTROL_
41 #define EGS_RUN_CONTROL_
42 
43 #include "egs_libconfig.h"
44 #include "egs_timer.h"
45 
46 #include <iostream>
47 using namespace std;
48 
49 class EGS_Application;
50 class EGS_Input;
51 
97 
98 public:
99 
107 
109  virtual ~EGS_RunControl();
110 
112  void setNcase(EGS_I64 n) {
113  if (n > 0) {
114  ncase = n;
115  }
116  };
117 
119  void setNbatch(int n) {
120  if (n > 0) {
121  nbatch = n;
122  }
123  };
124 
126  void setMaxTime(EGS_Float t) {
127  maxt = t;
128  };
129 
131  void setRequiredUncertainty(EGS_Float a) {
132  accu = a;
133  };
134 
136  EGS_I64 getNcase() const {
137  return ncase;
138  };
139 
141  int getNbatch() const {
142  return nbatch;
143  };
144 
146  int getNchunk() const {
147  return nchunk;
148  };
149 
157  virtual int startSimulation();
158 
168  virtual EGS_I64 getNextChunk() {
169  return getNcase() - ndone;
170  };
171 
182  virtual int finishSimulation();
183 
190  virtual bool startBatch(int,EGS_I64);
191 
198  virtual bool finishBatch();
199 
200  virtual void describeRCO();
201  virtual bool storeState(ostream &data);
202  virtual bool setState(istream &data);
203  virtual bool addState(istream &data);
204  virtual void resetCounter();
205  virtual bool getCombinedResult(double &, double &) const {
206  return false;
207  };
208 
209  virtual EGS_I64 getNdone() const {
210  return ndone;
211  };
212 
213  virtual void setNdone(EGS_I64 Ndone) {
214  ndone = Ndone;
215  };
216 
217  virtual void incrementNdone() {
218  ++ndone;
219  };
220 
221  virtual EGS_Float getCPUTime() const {
222  return cpu_time+previous_cpu_time;
223  };
224 
226  enum RCOType {
229  balanced
230  };
231 
232  static EGS_RunControl *getRunControlObject(EGS_Application *);
233 
234  int geomErrorCount, geomErrorMax;
235 
236 protected:
237 
238  EGS_Application *app;
239  EGS_Input *input;
240 
241  EGS_I64 ncase; // number of histories.
242  EGS_I64 ndone; // histories done so far.
243  EGS_Float maxt; // maximum time to run in hours.
244  EGS_Float accu; // statistical uncertainty sought.
245  int nbatch; // number of batches.
246  int restart;// =0 => fresh calculation
247  // =1 => restart calculation
248  // =2 => analyze results
249  // =3 => combine parallel run
250  int nchunk; // number of simulation "chunks"
251 
253 
254  EGS_Timer timer;
255  EGS_Float cpu_time;
256  EGS_Float previous_cpu_time;
257 
258 };
259 
260 class EGS_FileLocking;
261 
280 
281 public:
282 
283  EGS_JCFControl(EGS_Application *, int Nbuf=1024);
284  ~EGS_JCFControl();
285  void setNchunkForParallel(int n) {
286  if (n > 0) {
287  nchunk = n;
288  }
289  };
290  int startSimulation();
291  EGS_I64 getNextChunk();
292  int finishSimulation();
293  bool getCombinedResult(double &, double &) const;
294 
295 protected:
296 
297  EGS_I64 nleft, ntot;
298  double tsum, tsum2, tcount, norm;
299  double last_sum, last_sum2, last_count;
300  unsigned long start_time;
301  int njob;
302  int npar;
303  int ipar;
304  int ifirst;
305  bool first_time;
306  bool removed_jcf;
307  int nbuf;
308  char *buf;
309 
310  EGS_FileLocking *p;
311 
312  bool createControlFile();
313  bool openControlFile();
314  bool closeControlFile();
315  bool lockControlFile();
316  bool unlockControlFile();
317  bool rewindControlFile();
318  bool readControlFile();
319  bool writeControlFile();
320  virtual bool writeControlString();
321  virtual bool readControlString();
322 
323 };
324 
368 
369 public:
370 
372  ~EGS_UniformRunControl() {};
373 
374  void describeRCO();
375 
376  int startSimulation();
377 
386  int finishSimulation();
387 
388 protected:
389 
390  int milliseconds; // time interval for checking
391  // if all jobs finished (default 1000 ms)
392 
393  int check_intervals;// Number of intervals to check
394  // if all jobs done (default 5)
395 
396  int njob;
397  int npar;
398  int ipar;
399  int ifirst;
400  bool check_egsdat;// If true, and a 'watcher' job, produce intermediate results
401  bool watcher_job; // If true, job is a 'watcher'
402 };
403 
404 #endif
Base class for advanced EGSnrc C++ applications.
A class for storing information in a tree-like structure of key-value pairs. This class is used throu...
Definition: egs_input.h:182
A 'job control file' (JCF) RCO.
A simple run control object for advanced EGSnrc C++ applications.
RCOType rco_type
RCO type to use.
RCOType
Define RCO types.
@ uniform
parallel jobs with same numbe of histories
@ simple
single job or multiple independent jobs
void setNbatch(int n)
Set the number of batches to n.
void setMaxTime(EGS_Float t)
Set the maximum CPU time for the simulation to t.
virtual EGS_I64 getNextChunk()
Returns the number of histories to run in the next simulation chunk.
int getNchunk() const
Returns the number of simulation chunks.
void setRequiredUncertainty(EGS_Float a)
Set the required statistical uncertainty to a.
int getNbatch() const
Returns the number of batches per simulation chunk.
void setNcase(EGS_I64 n)
Set the number of particles to be simulated to n.
EGS_I64 getNcase() const
Returns the total number of particles to be simulated.
A simple class for measuring CPU time.
Definition: egs_timer.h:57
A job control object for homogeneous computing environments (HCE).
Defines the EGS_EXPORT and EGS_LOCAL macros.
#define EGS_EXPORT
Export symbols from the egspp library.
Definition: egs_libconfig.h:90
EGS_Timer class header file.