kspaceFirstOrder3D-OMP  1.2
The C++ implementation of the k-wave toolbox for the time-domain simulation of acoustic wave fields in 3D
CommandLineParameters.h
Go to the documentation of this file.
1 /**
2  * @file CommandLineParameters.h
3  *
4  * @author Jiri Jaros \n
5  * Faculty of Information Technology \n
6  * Brno University of Technology \n
7  * jarosjir@fit.vutbr.cz
8  *
9  * @brief The header file containing the command line parameters.
10  *
11  * @version kspaceFirstOrder3D 2.16
12  *
13  * @date 29 August 2012, 11:25 (created) \n
14  * 04 September 2017, 10:47 (revised)
15  *
16  * @section Params Command Line Parameters
17  *
18  * The C++ code requires two mandatory parameters and accepts a few optional parameters and flags. Ill parameters,
19  * bad simulation files, and runtime errors such as out-of-memory problems, lead to an exception followed by an error
20  * message shown and execution termination.
21  *
22  * The mandatory parameters <tt>-i</tt> and <tt>-o</tt> specify the input and output file. The file names respect the
23  * path conventions for particular operating system. If any of the files is not specified, cannot be found or created,
24  * an error message is shown and the code terminates.
25  *
26  * The <tt>-t</tt> parameter sets the number of threads used, which defaults the system maximum. If the system support
27  * hyperthreading, it is recommended to use only a half of the threads to prevent cache overloading. If possible enable
28  * tread binding and placement using export OMP_PROC_BIND=true.
29  *
30  *
31  * The <tt>-r</tt> parameter specifies how often information about the simulation progress is printed out to the command
32  * line. By default, the C++ code prints out the progress of the simulation, the elapsed time, and the estimated
33  * time of completion in intervals corresponding to 5% of the total number of times steps.
34  *
35  * The <tt>-c</tt> parameter specifies the compression level used by the ZIP library to reduce the size of the output
36  * file. The actual compression rate is highly dependent on the shape of the sensor mask and the range of stored
37  * quantities and may be computationally expensive. In general, the output data is very hard to compress, and using
38  * higher compression levels can greatly increase the time to save data while not having a large impact on the final
39  * file size. That's why we decided to disable compression in default settings.
40  *
41  * The <tt>\--benchmark</tt> parameter enables the total length of simulation (i.e., the number of time steps) to be
42  * overridden by setting a new number of time steps to simulate. This is particularly useful for performance evaluation
43  * and benchmarking. As the code performance is relatively stable, 50-100 time steps is usually enough to predict the
44  * simulation duration. This parameter can also be used to quickly check the simulation is set up correctly.
45  *
46  * The <tt>\--verbose</tt> parameter enables to select between three levels of verbosity. For routine simulations, the
47  * verbose level of 0 (the default one) is usually sufficient. For more information about the simulation, checking the
48  * parameters of the simulation, code version, GPU used, file paths, and debugging running scripts, verbose levels
49  * 1 and 2 may be very useful.
50  *
51  * The <tt>-h</tt> and <tt>\--help</tt> parameters print all the parameters of the C++ code. The <tt>\--version </tt>
52  * parameter reports detail information about the code useful for debugging and bug reports. It prints out the internal
53  * version, the build date and time, the git hash allowing us to track the version of the source code, the operating
54  * system, the compiler name and version and the instruction set used.
55  *
56  * For jobs that are expected to run for a very long time, it may be useful to checkpoint and restart the execution.
57  * One motivation is the wall clock limit per task on clusters where jobs must fit within a given time span (e.g. 24
58  * hours). The second motivation is a level of fault-tolerance, where you can back up the state of the simulation after
59  * a predefined period. To enable checkpoint-restart, the user is asked to specify a file to store the actual state of
60  * the simulation by <tt>\--checkpoint_file</tt> and the period in seconds after which the simulation will be
61  * interrupted by <tt>\--checkpoint_interval</tt>. When running on a cluster, please allocate enough time for the
62  * checkpoint procedure that can take a non-negligible amount of time (7 matrices have to be stored in the
63  * checkpoint file and all aggregated quantities are flushed into the output file). Please note, that the checkpoint
64  * file name and path is not checked at the beginning of the simulation, but at the time the code starts
65  * checkpointing. Thus make sure the file path was correctly specified (otherwise you will not find out the simulation
66  * crashed until the first leg of the simulation finishes). The rationale behind this is that to keep as high level of
67  * fault tolerance as possible, the checkpoint file should be touched even when really necessary.
68  *
69  * When controlling a multi-leg simulation by a script loop, the parameters of the code remains the same in all legs.
70  * The first leg of the simulation creates a checkpoint file while the last one deletes it. If the checkpoint file is
71  * not found the simulation starts from the beginning. In order to find out how many steps have been finished, please
72  * open the output file and read the variable <tt>t_index</tt> and compare it with <tt>Nt</tt> (e.g. by the h5dump
73  * command).
74  *
75  *
76  * The remaining flags specify the output quantities to be recorded during the simulation and stored on disk analogous
77  * to the sensor.record input. If the <tt>-p</tt> or <tt>\--p\_raw</tt> flags are set (these are equivalent), a time
78  * series of the acoustic pressure at the grid points specified by the sensor mask is recorded. If the
79  * <tt>\--p_rms</tt>, <tt>\--p_max</tt>, <tt>\--p_min</tt> flags are set, the root mean square and/or maximum and/or
80  * minimum values of the pressure at the grid points specified by the sensor mask are recorded. If the
81  * <tt>\--p_final</tt> flag is set, the values for the entire acoustic pressure field in the final time step of the
82  * simulation is stored (this will always include the PML, regardless of the setting for <tt> 'PMLInside'</tt>).
83  * The flags <tt>\--p_max_all</tt> and <tt>\--p_min_all</tt> allow to calculate the maximum and minimum values over the
84  * entire acoustic pressure field, regardless on the shape of the sensor mask. Flags to record the acoustic particle
85  * velocity are defined in an analogous fashion. For proper calculation of acoustic intensity, the particle velocity
86  * has to be shifted onto the same grid as the acoustic pressure. This can be done by setting
87  * <tt>\--u_non_staggered_raw</tt> flag, that first shifts the particle velocity and then samples the grid points
88  * specified by the sensor mask. Since the shift operation requires additional FFTs, the impact on the simulation time
89  * may be significant.
90  *
91  * Any combination of <tt>p</tt> and <tt>u</tt> flags is admissible. If no output flag is set, a time-series for the
92  * acoustic pressure is recorded. If it is not necessary to collect the output quantities over the entire simulation,
93  * the starting time step when the collection begins can be specified using the -s parameter. Note, the index for the
94  * first time step is 1 (this follows the MATLAB indexing convention).
95  *
96  * The <tt>\--copy_sensor_mask</tt> will copy the sensor from the input file to the output one at the end of the
97  * simulation. This helps in post-processing and visualisation of the outputs.
98  *
99  *
100  *
101 \verbatim
102 ┌───────────────────────────────────────────────────────────────┐
103 │ kspaceFirstOrder3D-OMP v1.2 │
104 ├───────────────────────────────────────────────────────────────┤
105 │ Usage │
106 ├───────────────────────────────────────────────────────────────┤
107 │ Mandatory parameters │
108 ├───────────────────────────────────────────────────────────────┤
109 │ -i <file_name> │ HDF5 input file │
110 │ -o <file_name> │ HDF5 output file │
111 ├───────────────────────────────┴───────────────────────────────┤
112 │ Optional parameters │
113 ├───────────────────────────────┬───────────────────────────────┤
114 │ -t <num_threads> │ Number of CPU threads │
115 │ │ (default = 4) │
116 │ -g <device_number> │ GPU device to run on │
117 │ │ (default = the first free) │
118 │ -r <interval_in_%> │ Progress print interval │
119 │ │ (default = 5%) │
120 │ -c <compression_level> │ Compression level <0,9> │
121 │ │ (default = 0) │
122 │ --benchmark <time_steps> │ Run only a specified number │
123 │ │ of time steps │
124 │ --verbose <level> │ Level of verbosity <0,2> │
125 │ │ 0 - basic, 1 - advanced, │
126 │ │ 2 - full │
127 │ │ (default = basic) │
128 │ -h, --help │ Print help │
129 │ --version │ Print version and build info │
130 ├───────────────────────────────┼───────────────────────────────┤
131 │ --checkpoint_file <file_name> │ HDF5 Checkpoint file │
132 │ --checkpoint_interval <sec> │ Checkpoint after a given │
133 │ │ number of seconds │
134 ├───────────────────────────────┴───────────────────────────────┤
135 │ Output flags │
136 ├───────────────────────────────┬───────────────────────────────┤
137 │ -p │ Store acoustic pressure │
138 │ │ (default output flag) │
139 │ │ (the same as --p_raw) │
140 │ --p_raw │ Store raw time series of p │
141 │ --p_rms │ Store rms of p │
142 │ --p_max │ Store max of p │
143 │ --p_min │ Store min of p │
144 │ --p_max_all │ Store max of p (whole domain) │
145 │ --p_min_all │ Store min of p (whole domain) │
146 │ --p_final │ Store final pressure field │
147 ├───────────────────────────────┼───────────────────────────────┤
148 │ -u │ Store ux, uy, uz │
149 │ │ (the same as --u_raw) │
150 │ --u_raw │ Store raw time series of │
151 │ │ ux, uy, uz │
152 │ --u_non_staggered_raw │ Store non-staggered raw time │
153 │ │ series of ux, uy, uz │
154 │ --u_rms │ Store rms of ux, uy, uz │
155 │ --u_max │ Store max of ux, uy, uz │
156 │ --u_min │ Store min of ux, uy, uz │
157 │ --u_max_all │ Store max of ux, uy, uz │
158 │ │ (whole domain) │
159 │ --u_min_all │ Store min of ux, uy, uz │
160 │ │ (whole domain) │
161 │ --u_final │ Store final acoustic velocity │
162 ├───────────────────────────────┼───────────────────────────────┤
163 │ -s <time_step> │ When data collection begins │
164 │ │ (default = 1) │
165 └───────────────────────────────┴───────────────────────────────┘
166 \endverbatim
167  *
168  *
169  * @copyright Copyright (C) 2017 Jiri Jaros and Bradley Treeby.
170  *
171  * This file is part of the C++ extension of the [k-Wave Toolbox](http://www.k-wave.org).
172  *
173  * This file is part of the k-Wave. k-Wave is free software: you can redistribute it and/or modify it under the terms
174  * of the GNU Lesser General Public License as published by the Free Software Foundation, either version 3 of the
175  * License, or (at your option) any later version.
176  *
177  * k-Wave is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied
178  * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for
179  * more details.
180  *
181  * You should have received a copy of the GNU Lesser General Public License along with k-Wave.
182  * If not, see [http://www.gnu.org/licenses/](http://www.gnu.org/licenses/).
183  */
184 
185 
186 #ifndef COMMAND_LINE_PARAMETERS_H
187 #define COMMAND_LINE_PARAMETERS_H
188 
189 #include <string>
190 
191 
192 /**
193  * @class CommandLineParameters
194  * @brief The class to parse and store command line parameters.
195  * @details The class to parse and store command line parameters.
196  */
198 {
199  public:
200  /// Only Parameters can create this class.
201  friend class Parameters;
202 
203  /// Copy constructor not allowed.
205 
206  /// Destructor.
208 
209  /// operator= not allowed.
211 
212  /**
213  * @brief Get input file name.
214  * @return Input file name.
215  */
216  const std::string& getInputFileName() const { return mInputFileName; };
217  /**
218  * @brief Get output file name.
219  * @return Output file name.
220  */
221  const std::string& getOutputFileName() const { return mOutputFileName; };
222  /**
223  * @brief Get Checkpoint file name.
224  * @return Checkpoint file name.
225  */
226  const std::string& getCheckpointFileName() const { return mCheckpointFileName; };
227 
228  /**
229  * @brief Get number of threads.
230  * @return Number of CPU threads value.
231  */
232  size_t getNumberOfThreads() const { return mNumberOfThreads; };
233 
234  /**
235  * @brief Get progress print interval.
236  * @return How often to print progress.
237  */
239 
240  /**
241  * @brief Get compression level.
242  * @return Compression level value for output and checkpoint files.
243  */
244  size_t getCompressionLevel() const { return mCompressionLevel; };
245 
246  /**
247  * @brief Is --benchmark set?
248  * @return true if the flag is set.
249  */
250  bool isBenchmarkEnabled() const { return mBenchmarkFlag; };
251 
252  /**
253  * @brief Get benchmark time step count.
254  * @return Number of time steps used to benchmark the code.
255  */
257 
258  /**
259  * @brief Is checkpoint enabled?
260  * @return true if checkpointing is enabled.
261  */
262  bool isCheckpointEnabled() const { return (mCheckpointInterval > 0); };
263 
264  /**
265  * @brief Get checkpoint interval.
266  * @return Checkpoint interval in seconds.
267  */
268  size_t getCheckpointInterval() const { return mCheckpointInterval; };
269 
270  /**
271  * @brief Is --version set?
272  * @return true if the flag is set.
273  */
274  bool isPrintVersionOnly() const { return mPrintVersionFlag; };
275 
276 
277  //------------------------------------------------ Output flags --------------------------------------------------//
278  /**
279  * @brief Is --p_raw set?
280  * @return true if the flag is set.
281  */
283  /**
284  * @brief Is --p_rms set?
285  * @return true if the flag is set.
286  */
288  /**
289  * @brief Is --p_max set?
290  * @return true if the flag is set.
291  */
293  /**
294  * @brief Is --p_min set?
295  * @return true if the flag is set.
296  */
298  /**
299  * @brief Is --p_max_all set?
300  * @return true if the flag is set.
301  */
303  /**
304  * @brief Is --p_min_all set?
305  * @return true if the flag is set.
306  */
308  /**
309  * @brief Is --p_final set?
310  * @return true if the flag is set.
311  */
313 
314 
315  /**
316  * @brief Is --u_raw set?
317  * @return true if the flag is set.
318  */
320  /**
321  * @brief Is --u_non_staggered_raw set?
322  * @return true if the flag is set.
323  */
325  /**
326  * @brief Is --u_rms set?
327  * @return true if the flag is set.
328  */
330  /**
331  * @brief Is --u_max set?
332  * @return true if the flag is set.
333  */
335  /**
336  * @brief Is --u_min set?
337  * @return true if the flag is set.
338  */
340  /**
341  * @brief Is --u_max_all set?
342  * @return true if the flag is set.
343  */
345  /**
346  * @brief Is --u_min set?
347  * @return true if the flag is set.
348  */
350  /**
351  * @brief Is --u_final set?
352  * @return true if the flag is set.
353  */
355  /**
356  * @brief Is --copy_mask set set?
357  * @return true if the flag is set.
358  */
359  bool getCopySensorMaskFlag() const { return mCopySensorMaskFlag; };
360 
361  /**
362  * @brief Get start time index when sensor data collection begins.
363  * @return When to start sampling data.
364  */
366 
367 
368  /// Print usage of the code
369  void printUsage();
370  /// Print setup commandline parameters.
372 
373  /**
374  * @brief Parse commandline parameters.
375  * @param [in, out] argc - number of commandline parameters.
376  * @param [in, out] argv - commandline parameters.
377  *
378  * @throw call exit when error in commandline.
379  */
380  void parseCommandLine(int argc, char** argv);
381  protected:
382  /// Default constructor - only friend class can create an instance.
384 
385  private:
386  /// Input file name.
387  std::string mInputFileName;
388  /// Output file name.
389  std::string mOutputFileName;
390  /// Checkpoint file name.
391  std::string mCheckpointFileName;
392 
393  /// Number of CPU threads value.
395  /// Progress interval value.
397  /// Compression level value for output and checkpoint files.
399 
400  /// BenchmarkFlag value.
402  /// Number of time steps used to benchmark the code
404  /// Checkpoint interval in seconds
406 
407  /// Print version of the code and exit.
409 
410 
411  /// Store raw time-series of pressure over the sensor mask?
413  /// Store RMS of pressure over the the sensor mask?
415  /// Store maximum of pressure over the sensor mask?
417  /// Store minimum of pressure over the sensor mask?
419  /// Store maximum of pressure over the whole domain?
421  /// Store minimum of pressure over the whole domain?
423  /// Store pressure in the final time step over the whole domain?
425 
426  /// Store raw time-series of velocity over the sensor mask?
428  /// Store un staggered raw time-series of velocity over the sensor mask?
430  /// Store RMS of velocity over the the sensor mask?
432  /// Store maximum of velocity over the sensor mask?
434  /// Store minimum of velocity over the sensor mask?
436  /// Store maximum of velocity over the whole domain?
438  /// Store minimum of velocity over the whole domain?
440  /// Store velocity in the final time step over the whole domain?
442 
443  /// Copy sensor mask to the output file.
445  /// StartTimeStep value.
447 
448  /// Default compression level.
449  static constexpr size_t kDefaultCompressionLevel = 0;
450  /// Default progress print interval.
451  static constexpr size_t kDefaultProgressPrintInterval = 5;
452 };// end of class CommandLineParameters
453 //----------------------------------------------------------------------------------------------------------------------
454 
455 #endif /* COMMAND_LINE_PARAMETERS_H */
456 
bool mStoreVelocityRmsFlag
Store RMS of velocity over the the sensor mask?
bool isPrintVersionOnly() const
Is –version set?
bool getStoreVelocityRmsFlag() const
Is –u_rms set?
static constexpr size_t kDefaultCompressionLevel
Default compression level.
bool mCopySensorMaskFlag
Copy sensor mask to the output file.
bool mStorePressureMinAllFlag
Store minimum of pressure over the whole domain?
The class to parse and store command line parameters.
bool mStorePressureMinFlag
Store minimum of pressure over the sensor mask?
bool getStoreVelocityMaxFlag() const
Is –u_max set?
size_t mProgressPrintInterval
Progress interval value.
bool getStorePressureMinAllFlag() const
Is –p_min_all set?
bool getStoreVelocityNonStaggeredRawFlag() const
Is –u_non_staggered_raw set?
Class storing all parameters of the simulation.
Definition: Parameters.h:50
bool isBenchmarkEnabled() const
Is –benchmark set?
size_t getNumberOfThreads() const
Get number of threads.
const std::string & getOutputFileName() const
Get output file name.
std::string mCheckpointFileName
Checkpoint file name.
void printUsage()
Print usage of the code.
size_t mCheckpointInterval
Checkpoint interval in seconds.
std::string mInputFileName
Input file name.
bool mStoreVelocityMinAllFlag
Store minimum of velocity over the whole domain?
bool mStorePressureRawFlag
Store raw time-series of pressure over the sensor mask?
bool mStorePressureRmsFlag
Store RMS of pressure over the the sensor mask?
bool mStorePressureFinalAllFlag
Store pressure in the final time step over the whole domain?
bool getStorePressureFinalAllFlag() const
Is –p_final set?
bool getStoreVelocityRawFlag() const
Is –u_raw set?
bool mPrintVersionFlag
Print version of the code and exit.
bool getStoreVelocityMinAllFlag() const
Is –u_min set?
bool mStoreVelocityMaxFlag
Store maximum of velocity over the sensor mask?
CommandLineParameters()
Default constructor - only friend class can create an instance.
bool getStoreVelocityFinalAllFlag() const
Is –u_final set?
size_t getSamplingStartTimeIndex() const
Get start time index when sensor data collection begins.
bool getStoreVelocityMaxAllFlag() const
Is –u_max_all set?
bool isCheckpointEnabled() const
Is checkpoint enabled?
std::string mOutputFileName
Output file name.
bool mStoreVelocityNonStaggeredRawFlag
Store un staggered raw time-series of velocity over the sensor mask?
const std::string & getInputFileName() const
Get input file name.
bool getStorePressureMinFlag() const
Is –p_min set?
const std::string & getCheckpointFileName() const
Get Checkpoint file name.
CommandLineParameters & operator=(const CommandLineParameters &)=delete
operator= not allowed.
bool mStoreVelocityMinFlag
Store minimum of velocity over the sensor mask?
size_t getCompressionLevel() const
Get compression level.
void printComandlineParamers()
Print setup commandline parameters.
bool mStorePressureMaxFlag
Store maximum of pressure over the sensor mask?
size_t mCompressionLevel
Compression level value for output and checkpoint files.
bool mStoreVelocityMaxAllFlag
Store maximum of velocity over the whole domain?
bool mStorePressureMaxAllFlag
Store maximum of pressure over the whole domain?
size_t mNumberOfThreads
Number of CPU threads value.
size_t getBenchmarkTimeStepsCount() const
Get benchmark time step count.
bool mStoreVelocityFinalAllFlag
Store velocity in the final time step over the whole domain?
bool getStorePressureMaxFlag() const
Is –p_max set?
size_t getCheckpointInterval() const
Get checkpoint interval.
bool getStorePressureMaxAllFlag() const
Is –p_max_all set?
size_t mBenchmarkTimeStepCount
Number of time steps used to benchmark the code.
size_t mSamplingStartTimeStep
StartTimeStep value.
void parseCommandLine(int argc, char **argv)
Parse commandline parameters.
bool mStoreVelocityRawFlag
Store raw time-series of velocity over the sensor mask?
bool getStoreVelocityMinFlag() const
Is –u_min set?
bool getCopySensorMaskFlag() const
Is –copy_mask set set?
bool mBenchmarkFlag
BenchmarkFlag value.
size_t getProgressPrintInterval() const
Get progress print interval.
static constexpr size_t kDefaultProgressPrintInterval
Default progress print interval.
bool getStorePressureRmsFlag() const
Is –p_rms set?
virtual ~CommandLineParameters()
Destructor.
bool getStorePressureRawFlag() const
Is –p_raw set?