@@ -32,6 +32,8 @@ THE POSSIBILITY OF SUCH DAMAGE.
3232 * @brief File containing main driver routine for CoreNeuron
3333 */
3434
35+ #include < vector>
36+ #include < string.h>
3537#include " coreneuron/utils/randoms/nrnran123.h"
3638#include " coreneuron/nrnconf.h"
3739#include " coreneuron/nrnoc/multicore.h"
@@ -52,6 +54,7 @@ THE POSSIBILITY OF SUCH DAMAGE.
5254#include " coreneuron/nrniv/multisend.h"
5355#include " coreneuron/utils/file_utils.h"
5456#include < string.h>
57+ #include < climits>
5558
5659#if 0
5760#include <fenv.h>
@@ -66,6 +69,7 @@ int main1(int argc, char* argv[], char** env);
6669void call_prcellstate_for_prcellgid (int prcellgid, int compute_gpu, int is_init);
6770void nrn_init_and_load_data (int argc,
6871 char * argv[],
72+ bool is_mapping_needed = false ,
6973 bool nrnmpi_under_nrncontrol = true ,
7074 bool run_setup_cleanup = true ) {
7175#if defined(NRN_FEEXCEPT)
@@ -90,9 +94,6 @@ void nrn_init_and_load_data(int argc,
9094 // create mutex for nrn123, protect instance_count_
9195 nrnran123_mutconstruct ();
9296
93- // read command line parameters and parameter config files
94- nrnopt_parse (argc, (const char **)argv);
95-
9697 // set global variables
9798 // precedence is: set by user, globals.dat, 34.0
9899 celsius = nrnopt_get_dbl (" --celsius" );
@@ -158,8 +159,8 @@ void nrn_init_and_load_data(int argc,
158159 use_interleave_permute = nrnopt_get_int (" --cell-permute" );
159160 cellorder_nwarp = nrnopt_get_int (" --nwarp" );
160161 use_solve_interleave = nrnopt_get_int (" --cell-permute" );
161- #if LAYOUT== 1
162- // permuting not allowed for AoS
162+ #if LAYOUT == 1
163+ // permuting not allowed for AoS
163164 use_interleave_permute = 0 ;
164165 use_solve_interleave = 0 ;
165166#endif
@@ -174,7 +175,7 @@ void nrn_init_and_load_data(int argc,
174175 use_phase2_ = (nrnopt_get_int (" --ms-phases" ) == 2 ) ? 1 : 0 ;
175176
176177 // reading *.dat files and setting up the data structures, setting mindelay
177- nrn_setup (filesdat.c_str (), nrn_need_byteswap, run_setup_cleanup);
178+ nrn_setup (filesdat.c_str (), is_mapping_needed, nrn_need_byteswap, run_setup_cleanup);
178179
179180 // Allgather spike compression and bin queuing.
180181 nrn_use_bin_queue_ = nrnopt_get_flag (" --binqueue" );
@@ -242,8 +243,28 @@ void call_prcellstate_for_prcellgid(int prcellgid, int compute_gpu, int is_init)
242243int main1 (int argc, char ** argv, char ** env) {
243244 (void )env; /* unused */
244245
246+ #if NRNMPI
247+ nrnmpi_init (1 , &argc, &argv);
248+ #endif
249+
250+ // read command line parameters and parameter config files
251+ nrnopt_parse (argc, (const char **)argv);
252+ std::vector<ReportConfiguration> configs;
253+ bool reports_needs_finalize = false ;
254+
255+ if (nrnopt_get_str (" --report-conf" ).size ()) {
256+ if (nrnopt_get_int (" --multiple" ) > 1 ) {
257+ if (nrnmpi_myid == 0 )
258+ printf (" \n WARNING! : Can't enable reports with model duplications feature! \n " );
259+ } else {
260+ configs = create_report_configurations (nrnopt_get_str (" --report-conf" ).c_str (),
261+ nrnopt_get_str (" --outpath" ).c_str ());
262+ reports_needs_finalize = configs.size ();
263+ }
264+ }
265+
245266 // initializationa and loading functions moved to separate
246- nrn_init_and_load_data (argc, argv);
267+ nrn_init_and_load_data (argc, argv, configs. size () > 0 );
247268 std::string checkpoint_path = nrnopt_get_str (" --checkpoint" );
248269 if (strlen (checkpoint_path.c_str ())) {
249270 nrn_checkpoint_arg_exists = true ;
@@ -264,35 +285,34 @@ int main1(int argc, char** argv, char** env) {
264285 {
265286 double v = nrnopt_get_dbl (" --voltage" );
266287
267- // finitialize is not called if running in checkpoint-restore mode
288+ // TODO : if some ranks are empty then restore will go in deadlock
289+ // phase (as some ranks won't have restored anything and hence return
290+ // false in checkpoint_initialize
268291 if (!checkpoint_initialize ()) {
269292 nrn_finitialize (v != 1000 ., v);
270293 }
271294
272295 report_mem_usage (" After nrn_finitialize" );
296+ double dt = nrnopt_get_dbl (" --dt" );
297+ double delay = nrnopt_get_dbl (" --mindelay" );
298+ double tstop = nrnopt_get_dbl (" --tstop" );
299+
300+ if (tstop < t && nrnmpi_myid == 0 ) {
301+ printf (" Error: Stop time (%lf) < Start time (%lf), restoring from checkpoint? \n " ,
302+ tstop, t);
303+ abort ();
304+ }
273305
274- #ifdef ENABLE_REPORTING
275- ReportGenerator* r = NULL ;
276- #endif
277-
278- // if reports are enabled using ReportingLib
279- if (nrnopt_get_flag (" --report" )) {
280- #ifdef ENABLE_REPORTING
281- if (nrnopt_get_int (" --multiple" ) > 1 ) {
282- if (nrnmpi_myid == 0 )
283- printf (
284- " \n WARNING! : Can't enable reports with model duplications feature! \n " );
285- } else {
286- r = new ReportGenerator (nrnopt_get_int (" --report" ), t, nrnopt_get_dbl (" --tstop" ),
287- nrnopt_get_dbl (" --dt" ), nrnopt_get_dbl (" --mindelay" ),
288- nrnopt_get_dbl (" --dt_report" ), nrnopt_get_str (" --outpath" ));
289- r->register_report ();
306+ // register all reports into reportinglib
307+ double min_report_dt = INT_MAX;
308+ for (int i = 0 ; i < configs.size (); i++) {
309+ register_report (dt, tstop, delay, configs[i]);
310+ if (configs[i].report_dt < min_report_dt) {
311+ min_report_dt = configs[i].report_dt ;
290312 }
291- #else
292- if (nrnmpi_myid == 0 )
293- printf (" \n WARNING! : Can't enable reports, recompile with ReportingLib! \n " );
294- #endif
295313 }
314+ setup_report_engine (min_report_dt, delay);
315+ configs.clear ();
296316
297317 // call prcellstate for prcellgid
298318 call_prcellstate_for_prcellgid (nrnopt_get_int (" --prcellgid" ), compute_gpu, 0 );
@@ -311,24 +331,24 @@ int main1(int argc, char** argv, char** env) {
311331 // Report global cell statistics
312332 report_cell_stats ();
313333
314- #ifdef ENABLE_SELECTIVE_PROFILING
315- stop_profile ();
316- #endif
317-
318334 // prcellstate after end of solver
319335 call_prcellstate_for_prcellgid (nrnopt_get_int (" --prcellgid" ), compute_gpu, 0 );
320-
321- #ifdef ENABLE_REPORTING
322- if (nrnopt_get_int (" --report" ) && r)
323- delete r;
324- #endif
325336 }
326337
327- write_checkpoint (nrn_threads, nrn_nthread, checkpoint_path.c_str (), nrn_need_byteswap);
328-
329338 // write spike information to outpath
330339 output_spikes (output_dir.c_str ());
331340
341+ write_checkpoint (nrn_threads, nrn_nthread, checkpoint_path.c_str (), nrn_need_byteswap);
342+
343+ #ifdef ENABLE_SELECTIVE_PROFILING
344+ stop_profile ();
345+ #endif
346+
347+ // must be done after checkpoint (to avoid deleting events)
348+ if (reports_needs_finalize) {
349+ finalize_report ();
350+ }
351+
332352 // Cleaning the memory
333353 nrn_cleanup ();
334354
0 commit comments