10 #include "nrnran123.h"
33 hoc_execerror(path.c_str(),
"directory did not exist and makePath for it failed");
44 std::string path(
".");
51 std::string
get_filename(
const std::string& path, std::string file_name) {
52 std::string fname(path +
'/' + file_name);
62 std::ofstream fs(fname);
64 hoc_execerror(
"nrncore_write write_mem_mech_types could not open for writing: %s\n", fname);
79 FILE* f = fopen(fname,
"w");
81 hoc_execerror(
"nrncore_write write_globals could not open for writing: %s\n", fname);
90 for (
void* sp =
NULL;;) {
94 fprintf(f,
"%s[%d]\n",
name, size);
95 for (
int i = 0;
i < size; ++
i) {
96 fprintf(f,
"%.20g\n", val[
i]);
99 fprintf(f,
"%s %.20g\n",
name, val[0]);
123 FILE* f = fopen(fname,
"wb");
125 hoc_execerror(
"nrncore_write write_nrnthread could not open for writing:", fname);
130 fprintf(f,
"%d npresyn\n", cg.
n_presyn);
131 fprintf(f,
"%d nnetcon\n", cg.
n_netcon);
143 f = fopen(fname,
"w");
145 hoc_execerror(
"nrncore_write write_nrnthread could not open for writing:", fname);
151 int ncell, ngid, n_real_gid, nnode, ndiam, nmech;
152 int *tml_index, *ml_nodecount, nidata, nvdata, nweight;
166 fprintf(f,
"%d n_real_cell\n",
ncell);
167 fprintf(f,
"%d ngid\n", ngid);
168 fprintf(f,
"%d n_real_gid\n", n_real_gid);
169 fprintf(f,
"%d nnode\n", nnode);
170 fprintf(f,
"%d ndiam\n", ndiam);
171 fprintf(f,
"%d nmech\n", nmech);
173 for (
int i = 0;
i < nmech; ++
i) {
174 fprintf(f,
"%d\n", tml_index[
i]);
175 fprintf(f,
"%d\n", ml_nodecount[
i]);
178 delete[] ml_nodecount;
180 fprintf(f,
"%d nidata\n", 0);
181 fprintf(f,
"%d nvdata\n", nvdata);
182 fprintf(f,
"%d nweight\n", nweight);
185 int* v_parent_index =
NULL;
204 for (
size_t i = 0;
i < mla.size(); ++
i) {
205 int type = mla[
i].first;
208 std::vector<int> pointer2type;
209 std::vector<uint32_t> nmodlrandom;
227 sz = pointer2type.size();
228 fprintf(f,
"%d npointer\n",
int(sz));
233 fprintf(f,
"%d nmodlrandom\n",
int(nmodlrandom.size()));
234 if (nmodlrandom.size()) {
240 int *output_vindex, *netcon_pnttype, *netcon_pntindex;
241 double *output_threshold, *
weights, *delays;
251 delete[] output_vindex;
253 delete[] output_threshold;
259 delete[] netcon_pnttype;
261 delete[] netcon_pntindex;
270 fprintf(f,
"%d bbcorepointer\n",
n);
273 for (
size_t i = 0;
i < mla.size(); ++
i) {
274 int type = mla[
i].first;
276 int icnt, dcnt, *iArray;
279 fprintf(f,
"%d\n",
type);
280 fprintf(f,
"%d\n%d\n", icnt, dcnt);
299 fprintf(f,
"chkpnt %d\n",
chkpnt++);
300 size_t n = fwrite(
p,
sizeof(
int), size, f);
305 fprintf(f,
"chkpnt %d\n",
chkpnt++);
306 size_t n = fwrite(
p,
sizeof(
double), size, f);
311 fprintf(f,
"chkpnt %d\n",
chkpnt++);
312 size_t n = fwrite(vec.data(),
sizeof(uint32_t), vec.size(), f);
316 #define writeint(p, size) writeint_(p, size, f)
317 #define writedbl(p, size) writedbl_(p, size, f)
322 std::vector<int> indices;
324 fprintf(f,
"%d VecPlay instances\n",
int(indices.size()));
325 for (
auto i: indices) {
326 int vptype, mtype, ix, sz;
331 nt.
id,
i, vptype, mtype, ix, sz, yvec, tvec, unused, unused, unused)) {
332 fprintf(f,
"%d\n", vptype);
333 fprintf(f,
"%d\n", mtype);
334 fprintf(f,
"%d\n", ix);
335 fprintf(f,
"%d\n", sz);
344 if (fgets(
s, size, f) ==
NULL) {
346 hoc_execerror(
"Error reading line in files.dat", strerror(errno));
349 if (
n &&
s[
n - 1] ==
'\n') {
368 std::vector<int> iSend;
372 if (cgs[iInt].group_id >= 0) {
373 iSend.push_back(cgs[iInt].group_id);
378 std::vector<int> iRecv, iDispl;
386 int num_datasets = iSend.size();
391 nrnmpi_int_gather(&num_datasets,
begin_ptr(iRecv), 1, 0);
393 iRecv[0] = num_datasets;
396 iRecv[0] = num_datasets;
405 iDispl[iInt] = iSumThread;
406 iSumThread += iRecv[iInt];
411 std::vector<int> iRecvVec(iSumThread);
423 for (
int iInt = 0; iInt < num_datasets; ++iInt) {
424 iRecvVec[iInt] = iSend[iInt];
428 for (
int iInt = 0; iInt < num_datasets; ++iInt) {
429 iRecvVec[iInt] = iSend[iInt];
442 std::stringstream ss;
443 ss << path <<
"/files.dat";
445 std::string filename = ss.str();
449 fp = fopen(filename.c_str(),
"w");
451 hoc_execerror(
"nrncore_write: could not open for writing:", filename.c_str());
454 fp = fopen(filename.c_str(),
"r+");
456 hoc_execerror(
"nrncore_write append: could not open for modifying:",
461 constexpr
int max_line_len = 20;
462 char line[max_line_len];
471 hoc_execerror(
"nrncore_write append: existing files.dat has inconsisten version:",
482 if (strcmp(line,
"-1") != 0) {
485 "nrncore_write append: existing files.dat does not have a gap junction "
497 long pos = ftell(
fp);
500 if (sscanf(line,
"%d", &oldval) != 1) {
507 "nrncore_write append: existing files.dat has gap junction indicator where we "
508 "expected a groupgid count.",
511 iSumThread += oldval;
512 fseek(
fp, pos, SEEK_SET);
514 fprintf(
fp,
"%10d\n", iSumThread);
518 fseek(
fp, 0, SEEK_END);
522 for (
int i = 0;
i < iRecvVec.size(); ++
i) {
523 fprintf(
fp,
"%d\n", iRecvVec[
i]);
532 if (minfo.
size() <= 0) {
537 std::stringstream ss;
538 ss << path <<
"/" << gid <<
"_3.dat";
540 std::string fname(ss.str());
541 FILE* f = fopen(fname.c_str(),
"w");
544 hoc_execerror(
"nrnbbcore_write could not open for writing:", fname.c_str());
552 fprintf(f,
"%d\n", count);
555 for (
size_t i = 0;
i < count;
i++) {
562 fprintf(f,
"%d %d %d %d\n", cgid, t_sec, t_seg, n_seclist);
564 for (
size_t j = 0;
j < n_seclist;
j++) {
569 size_t total_lfp_factors;
570 std::vector<int> data_sec;
571 std::vector<int> data_seg;
572 std::vector<double> data_lfp;
594 writeint(&(data_sec.front()), nseg);
595 writeint(&(data_seg.front()), nseg);
596 if (total_lfp_factors) {
597 writedbl(&(data_lfp.front()), total_lfp_factors);
static void nrnmpi_barrier()
std::vector< MlWithArtItem > MlWithArt
std::vector< int > output_gid
void append(Item *ql, Item *q)
void hoc_execerror(const char *s1, const char *s2)
uint32_t nrnran123_get_globalindex()
icycle< ncycle;++icycle) { int istride=stride[icycle];nrn_pragma_acc(loop vector) nrn_pragma_omp(loop bind(parallel)) for(int icore=0;icore< warpsize;++icore) { int i=ii+icore;if(icore< istride) { int ip=GPU_PARENT(i);GPU_RHS(i) -=GPU_B(i) *GPU_RHS(ip);GPU_RHS(i)/=GPU_D(i);} i+=istride;} ii+=istride;} }}void solve_interleaved2(int ith) { NrnThread *nt=nrn_threads+ith;InterleaveInfo &ii=interleave_info[ith];int nwarp=ii.nwarp;if(nwarp==0) return;int ncore=nwarp *warpsize;int *ncycles=ii.cellsize;int *stridedispl=ii.stridedispl;int *strides=ii.stride;int *rootbegin=ii.firstnode;int *nodebegin=ii.lastnode;if(0) { nrn_pragma_acc(parallel loop gang present(nt[0:1], strides[0:nstride], ncycles[0:nwarp], stridedispl[0:nwarp+1], rootbegin[0:nwarp+1], nodebegin[0:nwarp+1]) async(nt->stream_id)) nrn_pragma_omp(target teams loop map(present, alloc:nt[:1], strides[:nstride], ncycles[:nwarp], stridedispl[:nwarp+1], rootbegin[:nwarp+1], nodebegin[:nwarp+1])) for(int icore=0;icore< ncore;icore+=warpsize) { solve_interleaved2_loop_body(nt, icore, ncycles, strides, stridedispl, rootbegin, nodebegin);} nrn_pragma_acc(wait(nt->stream_id)) } else { for(int icore=0;icore< ncore;icore+=warpsize) { solve_interleaved2_loop_body(nt, icore, ncycles, strides, stridedispl, rootbegin, nodebegin);} }}void solve_interleaved1(int ith) { NrnThread *nt=nrn_threads+ith;int ncell=nt-> ncell
neuron::model_sorted_token nrn_ensure_model_data_are_sorted()
Ensure neuron::container::* data are sorted.
#define nrn_assert(x)
assert()-like macro, independent of NDEBUG status
void nrnthread_dat3_cell_count(int &cell_count)
int nrnthread_dat2_corepointer_mech(int tid, int type, int &icnt, int &dcnt, int *&iArray, double *&dArray)
int nrnthread_dat2_3(int tid, int nweight, int *&output_vindex, double *&output_threshold, int *&netcon_pnttype, int *&netcon_pntindex, double *&weights, double *&delays)
void nrnthread_dat3_cellmapping(int i, int &gid, int &nsec, int &nseg, int &n_seclist)
void * get_global_dbl_item(void *p, const char *&name, int &size, double *&val)
int nrnthread_dat2_1(int tid, int &ncell, int &ngid, int &n_real_gid, int &nnode, int &ndiam, int &nmech, int *&tml_index, int *&ml_nodecount, int &nidata, int &nvdata, int &nweight)
int nrnthread_dat2_vecplay(int tid, std::vector< int > &indices)
void nrnthread_dat3_secmapping(int i_c, int i_sec, std::string &sclname, int &nsec, int &nseg, size_t &total_lfp_factors, int &n_electrodes, std::vector< int > &data_sec, std::vector< int > &data_seg, std::vector< double > &data_lfp)
int nrnthread_dat2_vecplay_inst(int tid, int i, int &vptype, int &mtype, int &ix, int &sz, double *&yvec, double *&tvec, int &last_index, int &discon_index, int &ubound_index)
void write_memb_mech_types_direct(std::ostream &s)
int nrnthread_dat2_corepointer(int tid, int &n)
int nrnthread_dat2_2(int tid, int *&v_parent_index, double *&a, double *&b, double *&area, double *&v, double *&diamvec)
int nrnthread_dat2_mech(int tid, size_t i, int dsz_inst, int *&nodeindices, double *&data, int *&pdata, std::vector< uint32_t > &nmodlrandom, std::vector< int > &pointer2type)
void write_uint32vec(std::vector< uint32_t > &vec, FILE *f)
short * nrn_is_artificial_
void(* nrnthread_v_transfer_)(NrnThread *)
void write_memb_mech_types(const char *fname)
#define writeint(p, size)
void create_dir_path(const std::string &path)
create directory with given path
std::string get_filename(const std::string &path, std::string file_name)
void write_globals(const char *fname)
void writeint_(int *p, size_t size, FILE *f)
void nrn_write_mapping_info(const char *path, int gid, NrnMappingInfo &minfo)
dump mapping information to gid_3.dat file
static void fgets_no_newline(char *s, int size, FILE *f)
void write_nrnthread_task(const char *path, CellGroup *cgs, bool append)
Write all dataset ids to files.dat.
bbcore_write_t * nrn_bbcore_write_
void write_nrnthread(const char *path, NrnThread &nt, CellGroup &cg)
NetCvode * net_cvode_instance
void writedbl_(double *p, size_t size, FILE *f)
#define writedbl(p, size)
void nrnbbcore_vecplay_write(FILE *f, NrnThread &nt)
std::string get_write_path()
const char * bbcore_write_version
void(*)(double *, int *, int *, int *, Memb_list *, std::size_t, Datum *, Datum *, double *, NrnThread *) bbcore_write_t
T * begin_ptr(std::vector< T > &v)
int const size_t const size_t n
int * nrn_prop_param_size_
bool makePath(const std::string &path)
bool isDirExist(const std::string &path)
A view into a set of mechanism instances.
Compartment mapping information for NrnThread.
size_t size()
number of cells
Represent main neuron object computed by single thread.
double * node_a_storage()
double * node_area_storage()
double * node_voltage_storage()
double * node_b_storage()