34 hoc_execerror(path.c_str(),
"directory did not exist and makePath for it failed");
45 std::string path(
".");
47 path = hoc_gargstr(1);
52 std::string
get_filename(
const std::string& path, std::string file_name) {
53 std::string
fname(path +
'/' + file_name);
63 std::ofstream fs(
fname);
65 hoc_execerror(
"nrncore_write write_mem_mech_types could not open for writing: %s\n",
fname);
91 for (
void* sp =
NULL;;) {
96 for (
int i = 0;
i < size; ++
i) {
156 int ngid, n_real_gid, nnode, ndiam, nmech, *tml_index, *ml_nodecount, nidata, nvdata, nweight;
170 fprintf(f,
"%d n_real_gid\n", n_real_gid);
171 fprintf(f,
"%d nnode\n", nnode);
172 fprintf(f,
"%d ndiam\n", ndiam);
173 fprintf(f,
"%d nmech\n", nmech);
175 for (
int i = 0;
i < nmech; ++
i) {
177 fprintf(f,
"%d\n", ml_nodecount[
i]);
180 delete[] ml_nodecount;
183 fprintf(f,
"%d nvdata\n", nvdata);
184 fprintf(f,
"%d nweight\n", nweight);
187 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;
225 sz = pointer2type.size();
226 fprintf(f,
"%d npointer\n",
int(sz));
233 int *output_vindex, *netcon_pnttype, *netcon_pntindex;
234 double *output_threshold, *weights, *delays;
244 delete[] output_vindex;
246 delete[] output_threshold;
252 delete[] netcon_pnttype;
254 delete[] netcon_pntindex;
263 fprintf(f,
"%d bbcorepointer\n",
n);
266 for (
size_t i = 0;
i < mla.size(); ++
i) {
267 int type = mla[
i].first;
269 int icnt, dcnt, *iArray;
273 fprintf(f,
"%d\n%d\n", icnt, dcnt);
293 size_t n = fwrite(
p,
sizeof(
int), size, f);
299 size_t n = fwrite(
p,
sizeof(
double), size, f);
303 #define writeint(p, size) writeint_(p, size, f)
304 #define writedbl(p, size) writedbl_(p, size, f)
310 for (
int i = 0;
i < nitem; ++
i) {
311 size_t n = fwrite(
data[
i],
sizeof(
double), szitem, f);
317 double* d1 =
new double[nitem * szitem];
319 for (
int i = 0;
i < nitem; ++
i) {
320 for (
int j = 0;
j < szitem; ++
j) {
331 std::vector<int> indices;
333 fprintf(f,
"%d VecPlay instances\n",
int(indices.size()));
334 for (
auto i: indices) {
335 int vptype, mtype, ix, sz;
340 nt.
id,
i, vptype, mtype, ix, sz, yvec, tvec, unused, unused, unused)) {
353 if (fgets(s, size, f) ==
NULL) {
355 hoc_execerror(
"Error reading line in files.dat", strerror(errno));
358 if (
n && s[
n - 1] ==
'\n') {
377 std::vector<int> iSend;
381 if (
cgs[iInt].group_id >= 0) {
382 iSend.push_back(
cgs[iInt].group_id);
387 std::vector<int> iRecv, iDispl;
395 int num_datasets = iSend.size();
400 nrnmpi_int_gather(&num_datasets,
begin_ptr(iRecv), 1, 0);
402 iRecv[0] = num_datasets;
405 iRecv[0] = num_datasets;
414 iDispl[iInt] = iSumThread;
415 iSumThread += iRecv[iInt];
420 std::vector<int> iRecvVec(iSumThread);
432 for (
int iInt = 0; iInt < num_datasets; ++iInt) {
433 iRecvVec[iInt] = iSend[iInt];
437 for (
int iInt = 0; iInt < num_datasets; ++iInt) {
438 iRecvVec[iInt] = iSend[iInt];
451 std::stringstream ss;
452 ss << path <<
"/files.dat";
454 std::string filename = ss.str();
458 fp =
fopen(filename.c_str(),
"w");
460 hoc_execerror(
"nrncore_write: could not open for writing:", filename.c_str());
463 fp =
fopen(filename.c_str(),
"r+");
465 hoc_execerror(
"nrncore_write append: could not open for modifying:",
470 constexpr
int max_line_len = 20;
471 char line[max_line_len];
480 hoc_execerror(
"nrncore_write append: existing files.dat has inconsisten version:",
491 if (strcmp(
line,
"-1") != 0) {
494 "nrncore_write append: existing files.dat does not have a gap junction "
506 long pos = ftell(
fp);
509 if (sscanf(
line,
"%d", &oldval) != 1) {
516 "nrncore_write append: existing files.dat has gap junction indicator where we "
517 "expected a groupgid count.",
520 iSumThread += oldval;
521 fseek(
fp, pos, SEEK_SET);
527 fseek(
fp, 0, SEEK_END);
531 for (
int i = 0;
i < iRecvVec.size(); ++
i) {
542 std::stringstream ss;
543 ss << path <<
"/" << gid <<
"_3.dat";
545 std::string
fname(ss.str());
558 for (
size_t i = 0;
i < minfo.
size();
i++) {
562 fprintf(f,
"%d %d %d %zd\n",
c->gid,
c->num_sections(),
c->num_segments(),
c->size());
564 for (
size_t j = 0;
j <
c->size();
j++) {
static void nrnmpi_barrier()
std::vector< MlWithArtItem > MlWithArt
VEC * cgs(MTX_FN A, void *A_params, VEC *b, VEC *r0, double tol, VEC *x)
void hoc_execerror(const char *, const char *)
static char line[MAXLINE]
void append(Item *ql, Item *q)
int * nrn_prop_param_size_
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 * get_global_dbl_item(void *p, const char *&name, int &size, double *&val)
int nrnthread_dat2_1(int tid, 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)
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_mech(int tid, size_t i, int dsz_inst, int *&nodeindices, double *&data, int *&pdata, std::vector< int > &pointer2type)
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)
short * nrn_is_artificial_
void write_contiguous_art_data(double **data, int nitem, int szitem, FILE *f)
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)
double * contiguous_art_data(double **data, int nitem, int szitem)
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
T * begin_ptr(std::vector< T > &v)
int const size_t const size_t n
void(*)(double *, int *, int *, int *, double *, Datum *, Datum *, NrnThread *) bbcore_write_t
static philox4x32_key_t k
uint32_t nrnran123_get_globalindex()
bool makePath(const std::string &path)
bool isDirExist(const std::string &path)
Compartment mapping information for a cell.
Compartment mapping information for NrnThread.
size_t size()
number of cells
std::vector< CellMapping * > mapping
list of cells mapping
Represent main neuron object computed by single thread.
Section to segment mapping.
std::string name
name of section list
std::vector< int > segments
list of segments
int nsec
number of sections in section list
std::vector< int > sections
list sections associated with each segment
static const char * fname(const char *name)