1 #include <../../nmodlconf.h>
12 #define P(arg) fputs(arg, fcout)
38 extern Symbol* cvode_nrn_cur_solve_;
39 extern Symbol* cvode_nrn_current_solve_;
40 extern List* state_discon_list_;
47 static List* vectorize_replacements;
48 extern char* cray_pragma();
53 #if __TURBOC__ || SYSV || VMS
65 P(
"#if EXTRACELLULAR\n");
66 P(
" _nd = _ml->_nodelist[_iml];\n");
67 P(
" if (_nd->_extnode) {\n");
68 P(
" _v = NODEV(_nd) +_nd->_extnode->_v[0];\n");
73 P(
" _v = NODEV(_nd);\n");
76 P(
" if (use_cachevec) {\n");
77 P(
" _v = VEC_V(_ni[_iml]);\n");
81 P(
" _nd = _ml->_nodelist[_iml];\n");
82 P(
" _v = NODEV(_nd);\n");
89 P(
" _nd = _ml->_nodelist[_iml];\n");
90 P(
" _v = NODEV(_nd);\n");
93 P(
" if (use_cachevec) {\n");
94 P(
" _v = VEC_V(_ni[_iml]);\n");
98 P(
" _nd = _ml->_nodelist[_iml];\n");
99 P(
" _v = NODEV(_nd);\n");
124 P(
"/* NOT VECTORIZED */\n#define NRN_VECTORIZED 0\n");
129 P(
"#include <stdio.h>\n#include <stdlib.h>\n#include <math.h>\n#include \"mathlib.h\"\n");
130 P(
"#include \"common.h\"\n#include \"softbus.h\"\n");
131 P(
"#include \"sbtypes.h\"\n#include \"Solver.h\"\n");
133 P(
"#include <stdio.h>\n#include <stdlib.h>\n#include <math.h>\n#include \"mech_api.h\"\n");
135 P(
"#define nil 0\n");
136 P(
"#include \"md1redef.h\"\n");
137 P(
"#include \"section.h\"\n");
138 P(
"#include \"nrniv_mf.h\"\n");
139 P(
"#include \"md2redef.h\"\n");
144 P(
"static int _reset;\n");
155 P(
"static int error;\n");
159 P(
"int _ninits = 0;\n");
160 P(
"static int _match_recurse=1;\n");
164 P(
"_modl_cleanup(){ _match_recurse=1;}\n");
173 #if SIMSYS || HMODL || NMODL
175 P(
"static double *_p;\n\n");
189 P(
"\nstatic void initmodel() {\n int _i; double _save;");
192 P(
"\ninitmodel() {\n int _i; double _save;");
194 #if (!(SIMSYS || HMODL || NMODL))
195 P(
"\ninitmodel(_pp) double _pp[]; {\n int _i; double _save; _p = _pp;");
198 P(
"_initlists();\n");
206 P(
"\n_init_match(_save);");
214 P(
"\nstatic void nrn_init(NrnThread* _nt, _Memb_list* _ml, int _type){\n");
215 P(
"Node *_nd; double _v; int* _ni; int _iml, _cntml;\n");
217 P(
" _ni = _ml->_nodeindices;\n");
219 P(
"_cntml = _ml->_nodecount;\n");
220 P(
"for (_iml = 0; _iml < _cntml; ++_iml) {\n");
221 P(
" _p = _ml->_data[_iml]; _ppvar = _ml->_pdata[_iml];\n");
223 P(
"\nstatic nrn_init(_prop, _v) Prop *_prop; double _v; {\n");
224 P(
" _p = _prop->param; _ppvar = _prop->dparam;\n");
227 P(
" _tsav = -1e20;\n");
236 P(
" initmodel();\n");
245 P(
"\nstatic double _nrn_current(double _v){double _current=0.;v=_v;");
247 if (cvode_nrn_current_solve_) {
248 fprintf(
fcout,
"if (cvode_active_) { %s(); }\n", cvode_nrn_current_solve_->
name);
259 P(
"\n} return _current;\n}\n");
265 P(
"\nstatic void nrn_cur(NrnThread* _nt, _Memb_list* _ml, int _type){\n");
266 P(
"Node *_nd; int* _ni; double _rhs, _v; int _iml, _cntml;\n");
268 P(
" _ni = _ml->_nodeindices;\n");
270 P(
"_cntml = _ml->_nodecount;\n");
271 P(
"for (_iml = 0; _iml < _cntml; ++_iml) {\n");
272 P(
" _p = _ml->_data[_iml]; _ppvar = _ml->_pdata[_iml];\n");
280 if (cvode_nrn_cur_solve_) {
281 fprintf(
fcout,
"if (cvode_active_) { %s(); }\n", cvode_nrn_cur_solve_->
name);
285 P(
" _g = _nrn_current(_v + .001);\n");
287 if (state_discon_list_) {
288 P(
" state_discon_flag_ = 1; _rhs = _nrn_current(_v); state_discon_flag_ = 0;\n");
290 P(
" _rhs = _nrn_current(_v);\n");
293 P(
" _g = (_g - _rhs)/.001;\n");
297 P(
" _g *= 1.e2/(_nd_area);\n");
298 P(
" _rhs *= 1.e2/(_nd_area);\n");
302 P(
" NODERHS(_nd) += _rhs;\n");
305 P(
" if (use_cachevec) {\n");
306 P(
" VEC_RHS(_ni[_iml]) += _rhs;\n");
310 P(
" NODERHS(_nd) += _rhs;\n");
312 P(
" if (_nt->_nrn_fast_imem) { _nt->_nrn_fast_imem->_nrn_sav_rhs[_ni[_iml]] += "
315 P(
"#if EXTRACELLULAR\n");
316 P(
" if (_nd->_extnode) {\n");
317 P(
" *_nd->_extnode->_rhs[0] += _rhs;\n");
322 P(
" NODERHS(_nd) -= _rhs;\n");
325 P(
" if (use_cachevec) {\n");
326 P(
" VEC_RHS(_ni[_iml]) -= _rhs;\n");
330 P(
" NODERHS(_nd) -= _rhs;\n");
339 P(
"\nstatic void nrn_jacob(NrnThread* _nt, _Memb_list* _ml, int _type){\n");
340 P(
"Node *_nd; int* _ni; int _iml, _cntml;\n");
342 P(
" _ni = _ml->_nodeindices;\n");
344 P(
"_cntml = _ml->_nodecount;\n");
345 P(
"for (_iml = 0; _iml < _cntml; ++_iml) {\n");
346 P(
" _p = _ml->_data[_iml];\n");
348 P(
" _nd = _ml->_nodelist[_iml];\n");
350 P(
" NODED(_nd) -= _g;\n");
353 P(
" if (use_cachevec) {\n");
354 P(
" VEC_D(_ni[_iml]) -= _g;\n");
358 P(
" NODED(_nd) -= _g;\n");
360 P(
" if (_nt->_nrn_fast_imem) { _nt->_nrn_fast_imem->_nrn_sav_d[_ni[_iml]] -= _g; }\n");
362 P(
"#if EXTRACELLULAR\n");
363 P(
" if (_nd->_extnode) {\n");
364 P(
" *_nd->_extnode->_d[0] += _g;\n");
369 P(
" NODED(_nd) += _g;\n");
372 P(
" if (use_cachevec) {\n");
373 P(
" VEC_D(_ni[_iml]) += _g;\n");
377 P(
" _nd = _ml->_nodelist[_iml];\n");
378 P(
" NODED(_nd) += _g;\n");
388 P(
"\nstatic void nrn_state(NrnThread* _nt, _Memb_list* _ml, int _type){\n");
390 P(
"\nstatic nrn_state(_prop, _v) Prop *_prop; double _v; {\n");
394 P(
"Node *_nd; double _v = 0.0; int* _ni; int _iml, _cntml;\n");
396 P(
"double _dtsav = dt;\n"
397 "if (secondorder) { dt *= 0.5; }\n");
400 P(
" _ni = _ml->_nodeindices;\n");
402 P(
"_cntml = _ml->_nodecount;\n");
403 P(
"for (_iml = 0; _iml < _cntml; ++_iml) {\n");
404 P(
" _p = _ml->_data[_iml]; _ppvar = _ml->_pdata[_iml];\n");
405 P(
" _nd = _ml->_nodelist[_iml];\n");
408 P(
" _p = _prop->param; _ppvar = _prop->dparam;\n");
433 P(
"double _break, _save;\n{\n");
435 P(
"\nmodel(_pp, _indepindex) double _pp[]; int _indepindex; {\n");
436 P(
"double _break, _save;");
449 P(
"\nstatic void terminal(){}\n");
456 P(
"\nterminal(_pp) double _pp[];{");
465 #if NMODL || SIMSYS || HMODL
466 P(
"\nstatic void _initlists() {\n");
468 P(
"\n_initlists() {\n");
470 P(
" int _i; static int _first = 1;\n");
471 P(
" if (!_first) return;\n");
473 P(
"_first = 0;\n}\n");
490 #define IONCONC 010000
504 " for (_i=0; _i<%d; _i++) %s[_i] = %s0;\n",
540 }
else if (
q->itemtype == VERBATIM) {
542 }
else if (
q->itemtype ==
ITEM) {
552 }
else if (
q->itemtype == VERBATIM) {
554 }
else if (
q->itemtype ==
ITEM) {
566 for (
q = q1;
q != q2;
q =
q->next) {
567 if (
buf[0] !=
'\0') {
572 }
else if (
q->itemtype ==
STRING) {
615 #if GLOBFUNCT && NMODL
652 P(
"/* VECTORIZED */\n#define NRN_VECTORIZED 1\n");
653 P(
"#include <stdio.h>\n#include <stdlib.h>\n#include <math.h>\n#include \"mech_api.h\"\n");
655 P(
"#define nil 0\n");
656 P(
"#include \"md1redef.h\"\n");
657 P(
"#include \"section.h\"\n");
658 P(
"#include \"nrniv_mf.h\"\n");
659 P(
"#include \"md2redef.h\"\n");
662 P(
"static int _reset;\n");
670 P(
"static int error;\n");
671 P(
"static int _ninits = 0;\n");
672 P(
"static int _match_recurse=1;\n");
673 P(
"static void _modl_cleanup(){ _match_recurse=1;}\n");
687 P(
"\nstatic void initmodel(double* _p, Datum* _ppvar, Datum* _thread, NrnThread* _nt) {\n int "
688 "_i; double _save;");
694 P(
"\n_init_match(_save);");
700 P(
"\nstatic void nrn_init(NrnThread* _nt, _Memb_list* _ml, int _type){\n");
701 P(
"double* _p; Datum* _ppvar; Datum* _thread;\n");
702 P(
"Node *_nd; double _v; int* _ni; int _iml, _cntml;\n");
704 P(
" _ni = _ml->_nodeindices;\n");
706 P(
"_cntml = _ml->_nodecount;\n");
707 P(
"_thread = _ml->_thread;\n");
709 P(
"for (_iml = 0; _iml < _cntml; ++_iml) {\n");
710 P(
" _p = _ml->_data[_iml]; _ppvar = _ml->_pdata[_iml];\n");
713 P(
" _tsav = -1e20;\n");
722 P(
" initmodel(_p, _ppvar, _thread, _nt);\n");
729 P(
"\nstatic double _nrn_current(double* _p, Datum* _ppvar, Datum* _thread, NrnThread* _nt, "
730 "double _v){double _current=0.;v=_v;");
732 if (cvode_nrn_current_solve_) {
734 "if (cvode_active_) { %s(_p, _ppvar, _thread, _nt); }\n",
735 cvode_nrn_current_solve_->
name);
745 "current can only be LOCAL in a BREAKPOINT if CONDUCTANCE statements are "
752 P(
"\n} return _current;\n}\n");
759 P(
"\nstatic void nrn_cur(NrnThread* _nt, _Memb_list* _ml, int _type) {\n");
760 P(
"double* _p; Datum* _ppvar; Datum* _thread;\n");
761 P(
"Node *_nd; int* _ni; double _rhs, _v; int _iml, _cntml;\n");
763 P(
" _ni = _ml->_nodeindices;\n");
765 P(
"_cntml = _ml->_nodecount;\n");
766 P(
"_thread = _ml->_thread;\n");
767 P(
"for (_iml = 0; _iml < _cntml; ++_iml) {\n");
768 P(
" _p = _ml->_data[_iml]; _ppvar = _ml->_pdata[_iml];\n");
776 if (cvode_nrn_cur_solve_) {
778 "if (cvode_active_) { %s(_p, _ppvar, _thread, _nt); }\n",
779 cvode_nrn_cur_solve_->
name);
789 P(
" _g = _nrn_current(_p, _ppvar, _thread, _nt, _v + .001);\n");
791 if (state_discon_list_) {
792 P(
" state_discon_flag_ = 1; _rhs = _nrn_current(_v); state_discon_flag_ = "
795 P(
" _rhs = _nrn_current(_p, _ppvar, _thread, _nt, _v);\n");
798 P(
" _g = (_g - _rhs)/.001;\n");
803 P(
" _g *= 1.e2/(_nd_area);\n");
804 P(
" _rhs *= 1.e2/(_nd_area);\n");
808 P(
" NODERHS(_nd) += _rhs;\n");
811 P(
" if (use_cachevec) {\n");
812 P(
" VEC_RHS(_ni[_iml]) += _rhs;\n");
816 P(
" NODERHS(_nd) += _rhs;\n");
818 P(
" if (_nt->_nrn_fast_imem) { _nt->_nrn_fast_imem->_nrn_sav_rhs[_ni[_iml]] += "
821 P(
"#if EXTRACELLULAR\n");
822 P(
" if (_nd->_extnode) {\n");
823 P(
" *_nd->_extnode->_rhs[0] += _rhs;\n");
828 P(
" NODERHS(_nd) -= _rhs;\n");
831 P(
" if (use_cachevec) {\n");
832 P(
" VEC_RHS(_ni[_iml]) -= _rhs;\n");
836 P(
" NODERHS(_nd) -= _rhs;\n");
845 P(
"\nstatic void nrn_jacob(NrnThread* _nt, _Memb_list* _ml, int _type) {\n");
846 P(
"double* _p; Datum* _ppvar; Datum* _thread;\n");
847 P(
"Node *_nd; int* _ni; int _iml, _cntml;\n");
849 P(
" _ni = _ml->_nodeindices;\n");
851 P(
"_cntml = _ml->_nodecount;\n");
852 P(
"_thread = _ml->_thread;\n");
853 P(
"for (_iml = 0; _iml < _cntml; ++_iml) {\n");
854 P(
" _p = _ml->_data[_iml];\n");
856 P(
" _nd = _ml->_nodelist[_iml];\n");
858 P(
" NODED(_nd) -= _g;\n");
861 P(
" if (use_cachevec) {\n");
862 P(
" VEC_D(_ni[_iml]) -= _g;\n");
866 P(
" NODED(_nd) -= _g;\n");
868 P(
" if (_nt->_nrn_fast_imem) { _nt->_nrn_fast_imem->_nrn_sav_d[_ni[_iml]] -= _g; }\n");
870 P(
"#if EXTRACELLULAR\n");
871 P(
" if (_nd->_extnode) {\n");
872 P(
" *_nd->_extnode->_d[0] += _g;\n");
877 P(
" NODED(_nd) += _g;\n");
880 P(
" if (use_cachevec) {\n");
881 P(
" VEC_D(_ni[_iml]) += _g;\n");
885 P(
" _nd = _ml->_nodelist[_iml];\n");
886 P(
" NODED(_nd) += _g;\n");
896 P(
"\nstatic void nrn_state(NrnThread* _nt, _Memb_list* _ml, int _type) {\n");
898 P(
"double* _p; Datum* _ppvar; Datum* _thread;\n");
899 P(
"Node *_nd; double _v = 0.0; int* _ni; int _iml, _cntml;\n");
901 P(
"double _dtsav = dt;\n"
902 "if (secondorder) { dt *= 0.5; }\n");
905 P(
" _ni = _ml->_nodeindices;\n");
907 P(
"_cntml = _ml->_nodecount;\n");
908 P(
"_thread = _ml->_thread;\n");
909 P(
"for (_iml = 0; _iml < _cntml; ++_iml) {\n");
910 P(
" _p = _ml->_data[_iml]; _ppvar = _ml->_pdata[_iml];\n");
911 P(
" _nd = _ml->_nodelist[_iml];\n");
929 P(
"\nstatic void terminal(){}\n");
937 P(
"\nstatic void _initlists(){\n");
938 P(
" double _x; double* _p = &_x;\n");
939 P(
" int _i; static int _first = 1;\n");
940 P(
" if (!_first) return;\n");
942 P(
"_first = 0;\n}\n");
943 P(
"\n#if defined(__cplusplus)\n} /* extern \"C\" */\n#endif\n");
947 if (!vectorize_replacements) {
948 vectorize_replacements =
newlist();
956 if (vectorize_replacements) {
957 ITERATE(q1, vectorize_replacements) {
968 if (vectorize_replacements) {
969 ITERATE(
q, vectorize_replacements) {
977 char* cray_pragma() {
981 \n#pragma _CRI ivdep\
998 if (strcmp(
SYM(
q)->
name,
"v") == 0) {
1003 }
else if (
q->itemtype ==
STRING) {
1006 diag(
"modelfunc contains item which is not a SYMBOL or STRING", (
char*) 0);
1012 if (strcmp(
SYM(
q)->
name,
"{") == 0) {
1019 for (
q = m->
prev;
q != m;
q =
q->prev) {
1021 if (strcmp(
SYM(
q)->
name,
"}") == 0) {
1063 P(
"* 1.e2/(_nd_area)");
sprintf(buf, " if (secondorder) {\n" " int _i;\n" " for (_i = 0; _i < %d; ++_i) {\n" " _p[_slist%d[_i]] += dt*_p[_dlist%d[_i]];\n" " }}\n", numeqn, listnum, listnum)
void verbatim_adjust(char *q)
#define ITERATE(itm, lst)
NMODL parser global flags / functions.
Item * lappendstr(List *list, char *str)
void replacstr(Item *q, char *s)
Item * lappenditem(List *list, Item *item)
Item * lappendsym(List *list, Symbol *sym)
void c_out_vectorize(const char *)
void vectorize_substitute(Item *q, char *str)
Symbol * breakpoint_current(Symbol *s)
void vectorize_do_substitute()
void cvode_rw_cur(char *)
static void conductance_cout()
void debugprintitem(Item *q)
char * items_as_string(Item *q1, Item *q2)
List * get_ion_variables(int)
List * set_ion_variables(int)
List * end_dion_stmt(char *strdel)
static double remove(void *v)
Item * vectorize_replacement_item(Item *)