NEURON
corenrn_parameters.cpp
Go to the documentation of this file.
1 /*
2 # =============================================================================
3 # Copyright (c) 2016 - 2022 Blue Brain Project/EPFL
4 #
5 # See top-level LICENSE file for details.
6 # =============================================================================.
7 */
9 
10 #include <CLI/CLI.hpp>
11 
12 namespace coreneuron {
13 
14 extern std::string cnrn_version();
15 
17  : m_app{std::make_unique<CLI::App>("CoreNeuron - Optimised Simulator Engine for NEURON.")} {
18  auto& app = *m_app;
19  app.set_config("--read-config", "", "Read parameters from ini file", false)
20  ->check(CLI::ExistingFile);
21  app.add_option("--write-config",
23  "Write parameters to this file");
24 
25  app.add_flag(
26  "--mpi",
27  this->mpi_enable,
28  "Enable MPI. In order to initialize MPI environment this argument must be specified.");
29  app.add_option("--mpi-lib",
30  this->mpi_lib,
31  "CoreNEURON MPI library to load for dynamic MPI support");
32  app.add_flag("--gpu", this->gpu, "Activate GPU computation.");
33  app.add_option("--dt",
34  this->dt,
35  "Fixed time step. The default value is set by defaults.dat or is 0.025.")
36  ->capture_default_str()
37  ->check(CLI::Range(-1'000., 1e9));
38  app.add_option("-e, --tstop", this->tstop, "Stop Time in ms.")->check(CLI::Range(0., 1e9));
39  app.add_flag("--show");
40  app.add_option("--verbose",
41  this->verbose,
42  "Verbose level: 0 = NONE, 1 = ERROR, 2 = INFO, 3 = DEBUG. Default is INFO")
43  ->check(CLI::IsMember({verbose_level::NONE,
44  verbose_level::ERROR,
45  verbose_level::INFO,
46  verbose_level::DEBUG_INFO}));
47  app.add_flag("--model-stats",
48  this->model_stats,
49  "Print number of instances of each mechanism and detailed memory stats.");
50 
51  auto sub_gpu = app.add_option_group("GPU", "Commands relative to GPU.");
52  sub_gpu
53  ->add_option("-W, --nwarp",
54  this->nwarp,
55  "Number of warps to execute in parallel the Hines solver. Each warp solves a "
56  "group of cells. (Only used with cell permute 2)")
57  ->capture_default_str()
58  ->check(CLI::Range(0, 1'000'000));
59  sub_gpu
60  ->add_option("-R, --cell-permute",
62  "Cell permutation: 0 No permutation; 1 optimise node adjacency; 2 optimize "
63  "parent adjacency.")
64  ->capture_default_str()
65  ->check(CLI::Range(0, 2));
66  sub_gpu->add_flag("--cuda-interface",
67  this->cuda_interface,
68  "Activate CUDA branch of the code.");
69  sub_gpu->add_option("-n, --num-gpus", this->num_gpus, "Number of gpus to use per node.");
70 
71  auto sub_input = app.add_option_group("input", "Input dataset options.");
72  sub_input->add_option("-d, --datpath", this->datpath, "Path containing CoreNeuron data files.")
73  ->check(CLI::ExistingDirectory);
74  sub_input->add_option("-f, --filesdat", this->filesdat, "Name for the distribution file.")
75  ->capture_default_str()
76  ->check(CLI::ExistingFile);
77  sub_input
78  ->add_option("-p, --pattern",
79  this->patternstim,
80  "Apply patternstim using the specified spike file.")
81  ->check(CLI::ExistingFile);
82  sub_input
83  ->add_option("-s, --seed", this->seed, "Initialization seed for random number generator.")
84  ->check(CLI::Range(0, 100'000'000));
85  sub_input
86  ->add_option("-v, --voltage",
87  this->voltage,
88  "Initial voltage used for nrn_finitialize(1, v_init). If 1000, then "
89  "nrn_finitialize(0,...).")
90  ->check(CLI::Range(-1e9, 1e9));
91  sub_input->add_option("--report-conf", this->reportfilepath, "Reports configuration file.")
92  ->check(CLI::ExistingFile);
93  sub_input
94  ->add_option("--restore",
95  this->restorepath,
96  "Restore simulation from provided checkpoint directory.")
97  ->check(CLI::ExistingDirectory);
98 
99  auto sub_parallel = app.add_option_group("parallel", "Parallel processing options.");
100  sub_parallel->add_flag("-c, --threading",
101  this->threading,
102  "Parallel threads. The default is serial threads.");
103  sub_parallel->add_flag("--skip-mpi-finalize",
104  this->skip_mpi_finalize,
105  "Do not call mpi finalize.");
106 
107  auto sub_spike = app.add_option_group("spike", "Spike exchange options.");
108  sub_spike->add_option("--ms-phases", this->ms_phases, "Number of multisend phases, 1 or 2.")
109  ->capture_default_str()
110  ->check(CLI::Range(1, 2));
111  sub_spike
112  ->add_option("--ms-subintervals",
113  this->ms_subint,
114  "Number of multisend subintervals, 1 or 2.")
115  ->capture_default_str()
116  ->check(CLI::Range(1, 2));
117  sub_spike->add_flag("--multisend",
118  this->multisend,
119  "Use Multisend spike exchange instead of Allgather.");
120  sub_spike
121  ->add_option("--spkcompress",
122  this->spkcompress,
123  "Spike compression. Up to ARG are exchanged during MPI_Allgather.")
124  ->capture_default_str()
125  ->check(CLI::Range(0, 100'000));
126  sub_spike->add_flag("--binqueue", this->binqueue, "Use bin queue.");
127 
128  auto sub_config = app.add_option_group("config", "Config options.");
129  sub_config->add_option("-b, --spikebuf", this->spikebuf, "Spike buffer size.")
130  ->capture_default_str()
131  ->check(CLI::Range(0, 2'000'000'000));
132  sub_config
133  ->add_option("-g, --prcellgid",
134  this->prcellgid,
135  "Output prcellstate information for the gid NUMBER.")
136  ->check(CLI::Range(-1, 2'000'000'000));
137  sub_config->add_option("-k, --forwardskip", this->forwardskip, "Forwardskip to TIME")
138  ->check(CLI::Range(0., 1e9));
139  sub_config
140  ->add_option(
141  "-l, --celsius",
142  this->celsius,
143  "Temperature in degC. The default value is set in defaults.dat or else is 34.0.")
144  ->capture_default_str()
145  ->check(CLI::Range(-1000., 1000.));
146  sub_config
147  ->add_option("--mindelay",
148  this->mindelay,
149  "Maximum integration interval (likely reduced by minimum NetCon delay).")
150  ->capture_default_str()
151  ->check(CLI::Range(0., 1e9));
152  sub_config
153  ->add_option("--report-buffer-size",
154  this->report_buff_size,
155  "Size in MB of the report buffer.")
156  ->check(CLI::Range(1, 128));
157 
158  auto sub_output = app.add_option_group("output", "Output configuration.");
159  sub_output->add_option("-i, --dt_io", this->dt_io, "Dt of I/O.")
160  ->capture_default_str()
161  ->check(CLI::Range(-1000., 1e9));
162  sub_output->add_option("-o, --outpath", this->outpath, "Path to place output data files.")
163  ->capture_default_str();
164  sub_output->add_option("--checkpoint",
165  this->checkpointpath,
166  "Enable checkpoint and specify directory to store related files.");
167 
168  app.add_flag("-v, --version", this->show_version, "Show version information and quit.");
169 
170  CLI::retire_option(app, "--show");
171 }
172 
173 // Implementation in .cpp file where CLI types are complete.
175 
176 std::string corenrn_parameters::config_to_str(bool default_also, bool write_description) const {
177  return m_app->config_to_str(default_also, write_description);
178 }
179 
181  static_cast<corenrn_parameters_data&>(*this) = corenrn_parameters_data{};
182  m_app->clear();
183 }
184 
186  try {
187  m_app->parse(argc, argv);
188  if (verbose == verbose_level::NONE) {
189  nrn_nobanner_ = 1;
190  }
191  } catch (const CLI::ExtrasError& e) {
192  // in case of parsing errors, show message with exception
193  std::cerr << "CLI parsing error, see nrniv-core --help for more information. \n"
194  << std::endl;
195  m_app->exit(e);
196  throw e;
197  } catch (const CLI::ParseError& e) {
198  // use --help is also ParseError; in this case exit by showing all options
199  m_app->exit(e);
200  exit(0);
201  }
202 
203 #ifndef CORENEURON_ENABLE_GPU
204  if (gpu) {
205  std::cerr
206  << "Error: GPU support was not enabled at build time but GPU execution was requested."
207  << std::endl;
208  exit(42);
209  }
210 #endif
211 
212  // is user has asked for version info, print it and exit
213  if (show_version) {
214  std::cout << "CoreNEURON Version : " << cnrn_version() << std::endl;
215  exit(0);
216  }
217 };
218 
219 std::ostream& operator<<(std::ostream& os, const corenrn_parameters& corenrn_param) {
220  os << "GENERAL PARAMETERS" << std::endl
221  << "--mpi=" << (corenrn_param.mpi_enable ? "true" : "false") << std::endl
222  << "--mpi-lib=" << corenrn_param.mpi_lib << std::endl
223  << "--gpu=" << (corenrn_param.gpu ? "true" : "false") << std::endl
224  << "--dt=" << corenrn_param.dt << std::endl
225  << "--tstop=" << corenrn_param.tstop << std::endl
226  << std::endl
227  << "GPU" << std::endl
228  << "--nwarp=" << corenrn_param.nwarp << std::endl
229  << "--cell-permute=" << corenrn_param.cell_interleave_permute << std::endl
230  << "--cuda-interface=" << (corenrn_param.cuda_interface ? "true" : "false") << std::endl
231  << std::endl
232  << "INPUT PARAMETERS" << std::endl
233  << "--voltage=" << corenrn_param.voltage << std::endl
234  << "--seed=" << corenrn_param.seed << std::endl
235  << "--datpath=" << corenrn_param.datpath << std::endl
236  << "--filesdat=" << corenrn_param.filesdat << std::endl
237  << "--pattern=" << corenrn_param.patternstim << std::endl
238  << "--report-conf=" << corenrn_param.reportfilepath << std::endl
239  << std::left << std::setw(15) << "--restore=" << corenrn_param.restorepath << std::endl
240  << std::endl
241  << "PARALLEL COMPUTATION PARAMETERS" << std::endl
242  << "--threading=" << (corenrn_param.threading ? "true" : "false") << std::endl
243  << "--skip_mpi_finalize=" << (corenrn_param.skip_mpi_finalize ? "true" : "false")
244  << std::endl
245  << std::endl
246  << "SPIKE EXCHANGE" << std::endl
247  << "--ms_phases=" << corenrn_param.ms_phases << std::endl
248  << "--ms_subintervals=" << corenrn_param.ms_subint << std::endl
249  << "--multisend=" << (corenrn_param.multisend ? "true" : "false") << std::endl
250  << "--spk_compress=" << corenrn_param.spkcompress << std::endl
251  << "--binqueue=" << (corenrn_param.binqueue ? "true" : "false") << std::endl
252  << std::endl
253  << "CONFIGURATION" << std::endl
254  << "--spikebuf=" << corenrn_param.spikebuf << std::endl
255  << "--prcellgid=" << corenrn_param.prcellgid << std::endl
256  << "--forwardskip=" << corenrn_param.forwardskip << std::endl
257  << "--celsius=" << corenrn_param.celsius << std::endl
258  << "--mindelay=" << corenrn_param.mindelay << std::endl
259  << "--report-buffer-size=" << corenrn_param.report_buff_size << std::endl
260  << std::endl
261  << "OUTPUT PARAMETERS" << std::endl
262  << "--dt_io=" << corenrn_param.dt_io << std::endl
263  << "--outpath=" << corenrn_param.outpath << std::endl
264  << "--checkpoint=" << corenrn_param.checkpointpath << std::endl;
265 
266  return os;
267 }
268 
271 
272 } // namespace coreneuron
static int argc
Definition: inithoc.cpp:45
static char ** argv
Definition: inithoc.cpp:46
THIS FILE IS AUTO GENERATED DONT MODIFY IT.
int nrn_nobanner_
Declaring global corenrn_parameters object for this instance of CoreNeuron.
std::string cnrn_version()
Definition: main1.cpp:382
corenrn_parameters corenrn_param
Printing method.
std::ostream & operator<<(std::ostream &os, const corenrn_parameters &corenrn_param)
bool threading
Use Multisend spike exchange instead of Allgather.
double mindelay
Forward skip to TIME.
std::string restorepath
Name of file containing list of gids dat files read in.
double voltage
Temperature in degC.
std::string reportfilepath
Restore simulation from provided checkpoint directory.
std::string filesdat
Directory where spikes will be written.
int seed
Size in MB of the report buffer.
std::string outpath
Directory path where .dat files.
bool binqueue
Enable CUDA interface (default is the OpenACC interface).
unsigned ms_subint
Number of multisend phases, 1 or 2.
bool model_stats
Print version and exit.
double forwardskip
Initial voltage used for nrn_finitialize(1, v_init).
unsigned cell_interleave_permute
Spike Compression.
verbose_level verbose
Print mechanism counts and model size after initialization.
bool cuda_interface
Enable GPU computation.
int prcellgid
Internal buffer used on every rank for spikes.
bool mpi_enable
Initialization seed for random number generator (int)
std::string datpath
Apply patternstim using the specified spike file.
unsigned nwarp
Cell interleaving permutation.
bool multisend
Skip MPI finalization.
unsigned spkcompress
Number of multisend interval. 1 or 2.
double dt
Stop time of simulation in msec.
std::string patternstim
Maximum integration interval (likely reduced by minimum NetCon delay).
unsigned report_buff_size
Number of gpus to use per node.
double dt_io
Timestep to use in msec.
unsigned ms_phases
Gid of cell for prcellstate.
unsigned num_gpus
Number of warps to balance for cell_interleave_permute == 2.
double celsius
I/O timestep to use in msec for reports.
std::string mpi_lib
Write parameters to this file.
std::string writeParametersFilepath
Enable checkpoint and specify directory to store related files.
std::string checkpointpath
Reports configuration file.
void parse(int argc, char *argv[])
Destructor defined in .cpp where CLI11 types are complete.
std::string config_to_str(bool default_also=false, bool write_description=false) const
Return a string summarising the current parameter values.
~corenrn_parameters()
Constructor that initializes the CLI11 app.
void reset()
Runs the CLI11_PARSE macro.
std::unique_ptr< CLI::App > m_app