@@ -128,6 +128,28 @@ int (*nrn2core_get_dat2_vecplay_inst_)(int tid,
128128 double *& yvec,
129129 double *& tvec);
130130
131+ void (*nrn2core_get_trajectory_requests_)(int tid,
132+ int & bsize,
133+ int & n_pr,
134+ void **& vpr,
135+ int & n_trajec,
136+ int *& types,
137+ int *& indices,
138+ double **& pvars,
139+ double **& varrays);
140+
141+ void (*nrn2core_trajectory_values_)(int tid,
142+ int n_pr,
143+ void ** vpr,
144+ double t);
145+
146+ void (*nrn2core_trajectory_return_)(int tid,
147+ int n_pr,
148+ int vecsz,
149+ void ** vpr,
150+ double t);
151+
152+
131153// file format defined in cooperation with nrncore/src/nrniv/nrnbbcore_write.cpp
132154// single integers are ascii one per line. arrays are binary int or double
133155// Note that regardless of the gid contents of a group, since all gids are
@@ -312,7 +334,7 @@ void nrn_read_filesdat(int& ngrp, int*& grp, int multiple, int*& imult, const ch
312334 }
313335
314336 char version[256 ];
315- fscanf (fp, " %s\n " , version);
337+ nrn_assert ( fscanf (fp, " %s\n " , version) == 1 );
316338 check_bbcore_write_version (version);
317339
318340 int iNumFiles = 0 ;
@@ -350,8 +372,8 @@ void nrn_read_filesdat(int& ngrp, int*& grp, int multiple, int*& imult, const ch
350372 if ((iNum + 1 ) % iNumFiles == 0 ) {
351373 // re-read file for each multiple (skipping the two header lines)
352374 rewind (fp);
353- fscanf (fp, " %*s\n " );
354- fscanf (fp, " %*d\n " );
375+ nrn_assert ( fscanf (fp, " %*s\n " ) == 0 );
376+ nrn_assert ( fscanf (fp, " %*d\n " ) == 0 );
355377 }
356378 }
357379
@@ -681,7 +703,9 @@ void nrn_setup(const char* filesdat,
681703 maxgid = 0x7fffffff / nrn_setup_multiple;
682704 nrn_read_filesdat (ngroup, gidgroups, nrn_setup_multiple, imult, filesdat);
683705
684- MUTCONSTRUCT (1 )
706+ if (!MUTCONSTRUCTED) {
707+ MUTCONSTRUCT (1 )
708+ }
685709 // temporary bug work around. If any process has multiple threads, no
686710 // process can have a single thread. So, for now, if one thread, make two.
687711 // Fortunately, empty threads work fine.
@@ -795,7 +819,12 @@ void nrn_setup(const char* filesdat,
795819 delete[] file_reader;
796820
797821 model_size ();
798- delete[] gidgroups;
822+ delete [] gidgroups;
823+ delete [] imult;
824+ if (nrnthread_chkpnt) {
825+ delete [] nrnthread_chkpnt;
826+ nrnthread_chkpnt = NULL ;
827+ }
799828
800829 if (nrnmpi_myid == 0 ) {
801830 printf (" Setup Done : %.2lf seconds \n " , nrn_wtime () - time);
@@ -900,6 +929,34 @@ int nrn_i_layout(int icnt, int cnt, int isz, int sz, int layout) {
900929 return 0 ;
901930}
902931
932+ // take into account alignment, layout, permutation
933+ // only voltage or mechanism data index allowed. (mtype 0 means time)
934+ double * stdindex2ptr (int mtype, int index, NrnThread& nt) {
935+ if (mtype == -5 ) { // voltage
936+ int v0 = nt._actual_v - nt._data ;
937+ int ix = index; // relative to _actual_v
938+ nrn_assert ((ix >= 0 ) && (ix < nt.end ));
939+ if (nt._permute ) {
940+ node_permute (&ix, 1 , nt._permute );
941+ }
942+ return nt._data + (v0 + ix); // relative to nt._data
943+ }else if (mtype > 0 && mtype < n_memb_func) { //
944+ Memb_list* ml = nt._ml_list [mtype];
945+ nrn_assert (ml);
946+ int ix = nrn_param_layout (index, mtype, ml);
947+ if (ml->_permute ) {
948+ ix = nrn_index_permute (ix, mtype, ml);
949+ }
950+ return ml->data + ix;
951+ }else if (mtype == 0 ) { // time
952+ return &nt._t ;
953+ }else {
954+ printf (" stdindex2ptr does not handle mtype=%d\n " , mtype);
955+ nrn_assert (0 );
956+ }
957+ return NULL ;
958+ }
959+
903960// from i to (icnt, isz)
904961void nrn_inverse_i_layout (int i, int & icnt, int cnt, int & isz, int sz, int layout) {
905962 if (layout == 1 ) {
@@ -948,6 +1005,7 @@ inline void mech_layout(FileHandler& F, T* data, int cnt, int sz, int layout) {
9481005 * things up first. */
9491006
9501007void nrn_cleanup (bool clean_ion_global_map) {
1008+ clear_event_queue (); // delete left-over TQItem
9511009 gid2in.clear ();
9521010 gid2out.clear ();
9531011
@@ -967,6 +1025,7 @@ void nrn_cleanup(bool clean_ion_global_map) {
9671025 for (int it = 0 ; it < nrn_nthread; ++it) {
9681026 NrnThread* nt = nrn_threads + it;
9691027 NrnThreadMembList* next_tml = NULL ;
1028+ delete_trajectory_requests (*nt);
9701029 for (NrnThreadMembList* tml = nt->tml ; tml; tml = next_tml) {
9711030 Memb_list* ml = tml->ml ;
9721031
@@ -1114,9 +1173,24 @@ void nrn_cleanup(bool clean_ion_global_map) {
11141173
11151174 if (pnttype2presyn) {
11161175 free (pnttype2presyn);
1176+ pnttype2presyn = NULL ;
11171177 }
11181178}
11191179
1180+ void delete_trajectory_requests (NrnThread& nt) {
1181+ if (nt.trajec_requests ) {
1182+ TrajectoryRequests* tr = nt.trajec_requests ;
1183+ if (tr->n_trajec ) {
1184+ delete [] tr->vpr ;
1185+ if (tr->scatter ) {delete [] tr->scatter ;}
1186+ if (tr->varrays ) {delete [] tr->varrays ;}
1187+ delete [] tr->gather ;
1188+ }
1189+ delete nt.trajec_requests ;
1190+ nt.trajec_requests = NULL ;
1191+ }
1192+ }
1193+
11201194void read_phase2 (FileHandler& F, int imult, NrnThread& nt) {
11211195 bool direct = corenrn_embedded ? true : false ;
11221196 if (!direct) {
@@ -1178,7 +1252,9 @@ void read_phase2(FileHandler& F, int imult, NrnThread& nt) {
11781252 ntc.n_outputgids = n_outputgid;
11791253 ntc.nmech = nmech;
11801254#endif
1181- nrn_assert (n_outputgid > 0 ); // avoid n_outputgid unused warning
1255+ if (!direct) {
1256+ nrn_assert (n_outputgid > 0 ); // avoid n_outputgid unused warning
1257+ }
11821258
11831259 // / Checkpoint in coreneuron is defined for both phase 1 and phase 2 since they are written
11841260 // / together
0 commit comments