Skip to content

Commit c30f255

Browse files
committed
nrn_setup use array for cell_groups
1 parent 2abbd25 commit c30f255

File tree

4 files changed

+28
-37
lines changed

4 files changed

+28
-37
lines changed

src/coreneuron/io/nrn_setup.cpp

Lines changed: 20 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -170,13 +170,13 @@ std::vector<int*> nrnthreads_netcon_srcgid;
170170
std::vector<std::vector<int>> nrnthreads_netcon_negsrcgid_tid;
171171

172172
/* 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;
174175
patstimtype = nrn_get_mechtype("PatternStim");
175176
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;
180180
}
181181

182182
FILE* fp = fopen(filesdat, "r");
@@ -207,21 +207,18 @@ void nrn_read_filesdat(int& ngrp, int*& grp, const char* filesdat) {
207207
"Info : The number of input datasets are less than ranks, some ranks will be idle!\n");
208208
}
209209

210-
ngrp = 0;
211-
grp = new int[iNumFiles / nrnmpi_numprocs + 1];
212-
213210
// irerate over gids in files.dat
214211
for (int iNum = 0; iNum < iNumFiles; ++iNum) {
215212
int iFile;
216213

217214
nrn_assert(fscanf(fp, "%d\n", &iFile) == 1);
218215
if ((iNum % nrnmpi_numprocs) == nrnmpi_myid) {
219-
grp[ngrp] = iFile;
220-
ngrp++;
216+
rank_dat_files.push_back(iFile);
221217
}
222218
}
223219

224220
fclose(fp);
221+
return rank_dat_files;
225222
}
226223

227224
void netpar_tid_gid2ps(int tid, int gid, PreSyn** ps, InputPreSyn** psi) {
@@ -409,22 +406,22 @@ void nrn_setup(const char* filesdat,
409406
double* mindelay) {
410407
double time = nrn_wtime();
411408

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+
);
421415

422416
// temporary bug work around. If any process has multiple threads, no
423417
// process can have a single thread. So, for now, if one thread, make two.
424418
// Fortunately, empty threads work fine.
425419
// Allocate NrnThread* nrn_threads of size ngroup (minimum 2)
426420
// 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);
428425

429426
// from nrn_has_net_event create pnttype2presyn for use in phase2.
430427
auto& memb_func = corenrn.get_memb_funcs();
@@ -451,7 +448,7 @@ void nrn_setup(const char* filesdat,
451448

452449
/// Reserve vector of maps of size ngroup for negative gid-s
453450
/// std::vector< std::map<int, PreSyn*> > neg_gid2out;
454-
neg_gid2out.resize(userParams.ngroup);
451+
neg_gid2out.resize(n_cell_groups);
455452

456453
// bug fix. gid2out is cumulative over all threads and so do not
457454
// know how many there are til after phase1
@@ -503,13 +500,13 @@ void nrn_setup(const char* filesdat,
503500
nrn_partrans::setup_info_ = new SetupTransferInfo[nrn_nthread];
504501
coreneuron::phase_wrapper<coreneuron::gap>(userParams);
505502
} 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,
507504
nrn_nthread,
508505
sizeof(sgid_t));
509506
}
510507

511508
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);
513510

514511
// Whether allocated in NEURON or here, delete here.
515512
delete[] nrn_partrans::setup_info_;
@@ -564,8 +561,6 @@ void nrn_setup(const char* filesdat,
564561
printf(" Model size : %.2lf GB\n", model_size_bytes / (1024. * 1024. * 1024.));
565562
}
566563
}
567-
568-
delete[] userParams.gidgroups;
569564
}
570565

571566
void setup_ThreadData(NrnThread& nt) {

src/coreneuron/io/nrn_setup.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ inline void read_phase_aux<gap>(NrnThread& nt, UserParams& userParams) {
104104
template <phase P>
105105
inline void* phase_wrapper_w(NrnThread* nt, UserParams& userParams, bool in_memory_transfer) {
106106
int i = nt->id;
107-
if (i < userParams.ngroup) {
107+
if (i < userParams.cell_groups.size()) {
108108
if (!in_memory_transfer) {
109109
const char* data_dir = userParams.path;
110110
// directory to read could be different for phase 2 if we are restoring
@@ -115,7 +115,7 @@ inline void* phase_wrapper_w(NrnThread* nt, UserParams& userParams, bool in_memo
115115
}
116116

117117
std::string fname = std::string(data_dir) + "/" +
118-
std::to_string(userParams.gidgroups[i]) + "_" + getPhaseName<P>() +
118+
std::to_string(userParams.cell_groups[i]) + "_" + getPhaseName<P>() +
119119
".dat";
120120

121121
// Avoid trying to open the gid_gap.dat file if it doesn't exist when there are no

src/coreneuron/io/phase2.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -962,7 +962,7 @@ void Phase2::set_vec_play(NrnThread& nt, NrnThreadChkpnt& ntc) {
962962

963963
void Phase2::populate(NrnThread& nt, const UserParams& userParams) {
964964
NrnThreadChkpnt& ntc = nrnthread_chkpnt[nt.id];
965-
ntc.file_id = userParams.gidgroups[nt.id];
965+
ntc.file_id = userParams.cell_groups[nt.id];
966966

967967
nt.ncell = n_real_cell;
968968
nt.end = n_node;

src/coreneuron/io/user_params.hpp

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -16,23 +16,19 @@ class CheckPoints;
1616
/// Before it was globals variables, group them to give them as a single argument.
1717
/// They have for the most part, nothing related to each other.
1818
struct UserParams {
19-
UserParams(int ngroup_,
20-
int* gidgroups_,
19+
UserParams(std::vector<int>&& cell_groups_,
2120
const char* path_,
2221
const char* restore_path_,
2322
CheckPoints& checkPoints_)
24-
: ngroup(ngroup_)
25-
, gidgroups(gidgroups_)
23+
: cell_groups(std::move(cell_groups_))
2624
, path(path_)
2725
, restore_path(restore_path_)
28-
, file_reader(ngroup_)
26+
, file_reader(cell_groups_.size())
2927
, checkPoints(checkPoints_) {}
3028

3129
/// direct memory mode with neuron, do not open files
32-
/// Number of local cell groups
33-
const int ngroup;
34-
/// Array of cell group numbers (indices)
35-
const int* const gidgroups;
30+
/// Vector of cell group numbers (indices)
31+
std::vector<int> cell_groups;
3632
/// path to dataset file
3733
const char* const path;
3834
/// Dataset path from where simulation is being restored

0 commit comments

Comments
 (0)