@@ -170,13 +170,13 @@ std::vector<int*> nrnthreads_netcon_srcgid;
170
170
std::vector<std::vector<int >> nrnthreads_netcon_negsrcgid_tid;
171
171
172
172
/* read files.dat file and distribute cellgroups to all mpi ranks */
173
- void nrn_read_filesdat (int & ngrp, int *& grp, const char * filesdat) {
173
+ std::vector<int > nrn_read_filesdat (const char * filesdat) {
174
+ std::vector<int > rank_dat_files;
174
175
patstimtype = nrn_get_mechtype (" PatternStim" );
175
176
if (corenrn_embedded && !corenrn_file_mode) {
176
- ngrp = corenrn_embedded_nthread;
177
- grp = new int [ngrp + 1 ];
178
- (*nrn2core_group_ids_)(grp);
179
- return ;
177
+ rank_dat_files.resize (corenrn_embedded_nthread);
178
+ (*nrn2core_group_ids_)(rank_dat_files.data ());
179
+ return rank_dat_files;
180
180
}
181
181
182
182
FILE* fp = fopen (filesdat, " r" );
@@ -207,21 +207,18 @@ void nrn_read_filesdat(int& ngrp, int*& grp, const char* filesdat) {
207
207
" Info : The number of input datasets are less than ranks, some ranks will be idle!\n " );
208
208
}
209
209
210
- ngrp = 0 ;
211
- grp = new int [iNumFiles / nrnmpi_numprocs + 1 ];
212
-
213
210
// irerate over gids in files.dat
214
211
for (int iNum = 0 ; iNum < iNumFiles; ++iNum) {
215
212
int iFile;
216
213
217
214
nrn_assert (fscanf (fp, " %d\n " , &iFile) == 1 );
218
215
if ((iNum % nrnmpi_numprocs) == nrnmpi_myid) {
219
- grp[ngrp] = iFile;
220
- ngrp++;
216
+ rank_dat_files.push_back (iFile);
221
217
}
222
218
}
223
219
224
220
fclose (fp);
221
+ return rank_dat_files;
225
222
}
226
223
227
224
void netpar_tid_gid2ps (int tid, int gid, PreSyn** ps, InputPreSyn** psi) {
@@ -409,22 +406,22 @@ void nrn_setup(const char* filesdat,
409
406
double * mindelay) {
410
407
double time = nrn_wtime ();
411
408
412
- int ngroup;
413
- int * gidgroups;
414
- nrn_read_filesdat (ngroup, gidgroups, filesdat);
415
- UserParams userParams (ngroup,
416
- gidgroups,
417
- datpath,
418
- strlen (restore_path) == 0 ? datpath : restore_path,
419
- checkPoints);
420
-
409
+ UserParams userParams (
410
+ nrn_read_filesdat (filesdat),
411
+ datpath,
412
+ strlen (restore_path) == 0 ? datpath : restore_path,
413
+ checkPoints
414
+ );
421
415
422
416
// temporary bug work around. If any process has multiple threads, no
423
417
// process can have a single thread. So, for now, if one thread, make two.
424
418
// Fortunately, empty threads work fine.
425
419
// Allocate NrnThread* nrn_threads of size ngroup (minimum 2)
426
420
// Note that rank with 0 dataset/cellgroup works fine
427
- nrn_threads_create (userParams.ngroup <= 1 ? 2 : userParams.ngroup );
421
+ int n_cell_groups = userParams.cell_groups .size ();
422
+ int n_threads = n_cell_groups <= 1 ? 2 : n_cell_groups;
423
+ userParams.cell_groups .reserve (n_threads);
424
+ nrn_threads_create (n_threads);
428
425
429
426
// from nrn_has_net_event create pnttype2presyn for use in phase2.
430
427
auto & memb_func = corenrn.get_memb_funcs ();
@@ -451,7 +448,7 @@ void nrn_setup(const char* filesdat,
451
448
452
449
// / Reserve vector of maps of size ngroup for negative gid-s
453
450
// / std::vector< std::map<int, PreSyn*> > neg_gid2out;
454
- neg_gid2out.resize (userParams. ngroup );
451
+ neg_gid2out.resize (n_cell_groups );
455
452
456
453
// bug fix. gid2out is cumulative over all threads and so do not
457
454
// know how many there are til after phase1
@@ -503,13 +500,13 @@ void nrn_setup(const char* filesdat,
503
500
nrn_partrans::setup_info_ = new SetupTransferInfo[nrn_nthread];
504
501
coreneuron::phase_wrapper<coreneuron::gap>(userParams);
505
502
} else {
506
- nrn_partrans::setup_info_ = (*nrn2core_get_partrans_setup_info_)(userParams. ngroup ,
503
+ nrn_partrans::setup_info_ = (*nrn2core_get_partrans_setup_info_)(n_cell_groups ,
507
504
nrn_nthread,
508
505
sizeof (sgid_t ));
509
506
}
510
507
511
508
nrn_multithread_job (nrn_partrans::gap_data_indices_setup);
512
- nrn_partrans::gap_mpi_setup (userParams. ngroup );
509
+ nrn_partrans::gap_mpi_setup (n_cell_groups );
513
510
514
511
// Whether allocated in NEURON or here, delete here.
515
512
delete[] nrn_partrans::setup_info_;
@@ -564,8 +561,6 @@ void nrn_setup(const char* filesdat,
564
561
printf (" Model size : %.2lf GB\n " , model_size_bytes / (1024 . * 1024 . * 1024 .));
565
562
}
566
563
}
567
-
568
- delete[] userParams.gidgroups ;
569
564
}
570
565
571
566
void setup_ThreadData (NrnThread& nt) {
0 commit comments