nmodl
nmodl copied to clipboard
Handling code generation when vectorise = false in NEURON/MOD2C code generation
Some of the constructs in MOD file are non-thread safe (e.g. LINEAR, NON-LINEAR, DISCRETE, PARTIAL). In this case, MOD2C/NEURON generate code with :
/* Created by Language version: 7.5.0 */
/* NOT VECTORIZED */
#define NRN_VECTORIZED 0
#include <stdio.h>
#define _threadargscomma_ /**/
#define _threadargsprotocomma_ /**/
#define _threadargs_ /**/
#define _threadargsproto_ /**/
This also affects the number of float variables used in the data array. For example, NaV.mod file from mousify circuit generates :
#define DI5 _p[60*_STRIDE]
#define DO _p[61*_STRIDE]
#define DI6 _p[62*_STRIDE]
#define _g _p[63*_STRIDE]
#define _ion_ena _nt_data[_ppvar[0*_STRIDE]]
#define _ion_ina _nt_data[_ppvar[1*_STRIDE]]
#define _ion_dinadv _nt_data[_ppvar[2*_STRIDE]]
#define _ion_ttxo _nt_data[_ppvar[3*_STRIDE]]
#define _ion_ttxi _nt_data[_ppvar[4*_STRIDE]]
But NMODL was generating :
inst->DI5 = ml->data+60*pnodecount;
inst->DO = ml->data+61*pnodecount;
inst->DI6 = ml->data+62*pnodecount;
inst->v_unused = ml->data+63*pnodecount;
inst->g_unused = ml->data+64*pnodecount;
the second last v_unused shouldn't be generated. Making vectorise false removes v_unused but code uses global variable NaV_global.v :
static inline double nrn_current(int id, int pnodecount, NaV_Instance* inst, IonCurVar& ionvar, double* data, const Datum* indexes, ThreadDatum* thread, NrnThread* nt, double v) {
double current = 0.0;
if (inst->ion_ttxi[indexes[4*pnodecount+id]] == 0.015625 && inst->ion_ttxo[indexes[3*pnodecount+id]] > 1e-12) {
inst->ttx_O[id] = 0.0;
} else {
inst->ttx_O[id] = inst->O[id];
}
inst->g[id] = inst->gbar[id] * inst->ttx_O[id];
ionvar.ina = inst->g[id] * (NaV_global.v - inst->ion_ena[indexes[0*pnodecount+id]]);
current += ionvar.ina;
return current;
}
In the new NMODL, as everything is vectorised for execution, I believe we should just use v everywhere.