19 #define USELONGDOUBLE 0 24 #include "shared/nvector_serial.h" 26 #include "shared/sundialsmath.h" 27 #include "shared/sundialstypes.h" 31 #define ZERO RCONST(0.0) 32 #define HALF RCONST(0.5) 33 #define ONE RCONST(1.0) 34 #define ONEPT5 RCONST(1.5) 37 #define mydebug(a) printf(a) 38 #define mydebug2(a,b) printf(a,b) 45 #define ldrealtype long double 47 #define ldrealtype realtype 71 #define idpass id_ = id; 75 #define xarg(i) NV_SUBVEC_NT(x_, i) 76 #define yarg(i) NV_SUBVEC_NT(y_, i) 77 #define zarg(i) NV_SUBVEC_NT(z_, i) 78 #define warg(i) NV_SUBVEC_NT(w_, i) 79 #define idarg(i) NV_SUBVEC_NT(id_, i) 84 #define unlock MUTUNLOCK 85 #define lockadd(arg) lock; retval += arg; unlock; 87 #define locklongdadd(arg) lock; longdretval += arg; unlock; 89 #define locklongdadd(arg) lockadd(arg) 91 #define lockmax(arg) lock; if (retval < arg) { retval = arg; }; unlock; 92 #define lockmin(arg) lock; if (retval > arg) { retval = arg; }; unlock; 93 #define lockfalse lock; bretval = FALSE; unlock; 115 v = (N_Vector) malloc(
sizeof *v);
119 ops = (N_Vector_Ops) malloc(
sizeof(
struct _generic_N_Vector_Ops));
120 if (ops ==
NULL) {free(v);
return(
NULL);}
149 if (content ==
NULL) {free(ops);free(v);
return(
NULL);}
152 content->
nt = nthread;
154 content->
data = (N_Vector*) malloc(
sizeof(N_Vector)*nthread);
155 if (content->
data ==
NULL) { free(ops); free(v); free(content);
return(
NULL);}
156 for (i=0; i < nthread; ++
i) {
160 v->content = content;
185 for (i=0; i < nthread; ++
i) {
186 data = N_VNew_Serial(sizes[i]);
210 v = (N_Vector) malloc(
sizeof *v);
214 ops = (N_Vector_Ops) malloc(
sizeof(
struct _generic_N_Vector_Ops));
215 if (ops ==
NULL) {free(v);
return(
NULL);}
217 ops->nvclone = w->ops->nvclone;
218 ops->nvdestroy = w->ops->nvdestroy;
219 ops->nvspace = w->ops->nvspace;
220 ops->nvgetarraypointer = w->ops->nvgetarraypointer;
221 ops->nvsetarraypointer = w->ops->nvsetarraypointer;
222 ops->nvlinearsum = w->ops->nvlinearsum;
223 ops->nvconst = w->ops->nvconst;
224 ops->nvprod = w->ops->nvprod;
225 ops->nvdiv = w->ops->nvdiv;
226 ops->nvscale = w->ops->nvscale;
227 ops->nvabs = w->ops->nvabs;
228 ops->nvinv = w->ops->nvinv;
229 ops->nvaddconst = w->ops->nvaddconst;
230 ops->nvdotprod = w->ops->nvdotprod;
231 ops->nvmaxnorm = w->ops->nvmaxnorm;
232 ops->nvwrmsnormmask = w->ops->nvwrmsnormmask;
233 ops->nvwrmsnorm = w->ops->nvwrmsnorm;
234 ops->nvmin = w->ops->nvmin;
235 ops->nvwl2norm = w->ops->nvwl2norm;
236 ops->nvl1norm = w->ops->nvl1norm;
237 ops->nvcompare = w->ops->nvcompare;
238 ops->nvinvtest = w->ops->nvinvtest;
239 ops->nvconstrmask = w->ops->nvconstrmask;
240 ops->nvminquotient = w->ops->nvminquotient;
244 if (content ==
NULL) {free(ops);free(v);
return(
NULL);}
249 content->
nt = wcontent->
nt;
250 content->
data = (N_Vector*) malloc(
sizeof(N_Vector) * content->
nt);
251 if (content->
data ==
NULL) { free(ops); free(v); free(content);
return(
NULL);}
252 for (i=0; i < content->
nt; ++
i) {
257 v->content = content;
295 if (count <= 0)
return(
NULL);
297 vs = (N_Vector *) malloc(count *
sizeof(N_Vector));
300 for (j=0; j<count; j++) {
320 if (count <= 0)
return(
NULL);
322 vs = (N_Vector *) malloc(count *
sizeof(N_Vector));
325 for (j=0; j<count; j++) {
360 for (i=0; i < nt; i++) {
390 for (i=0; i < nt; ++
i) {
392 data = N_VClone(wdata);
410 for (i = 0; i < nt; ++
i) {
412 if (data) { N_VDestroy(data); }
437 return((realtype*)v_data);
549 s = N_VDotProd_Serial(
xarg(i),
yarg(i));
565 max = N_VMaxNorm_Serial(
xarg(i));
583 realtype prodi, *xd, *wd;
589 for (i=0; i < N; i++) {
590 prodi = (*xd++) * (*wd++);
591 sum += prodi * prodi;
618 return(RSqrt(
retval / N));
624 realtype sum =
ZERO, prodi, *xd, *wd, *idd;
631 for (i=0; i < N; i++) {
633 prodi = xd[
i] * wd[
i];
634 sum += prodi * prodi;
655 return(RSqrt(
retval / N));
661 if (NV_LENGTH_S(
xarg(i))) {
662 min = N_VMin_Serial(
xarg(i));
679 realtype sum =
ZERO, prodi, *xd, *wd;
685 for (i=0; i < N; i++) {
686 prodi = (*xd++) * (*wd++);
687 sum += prodi * prodi;
713 sum = N_VL1Norm_Serial(
xarg(i));
752 b = N_VInvTest_Serial(
xarg(i),
zarg(i));
784 min = N_VMinQuotient_Serial(
xarg(i),
yarg(i));
void N_VLinearSum_NrnThread(realtype a, N_Vector x, realtype b, N_Vector y, N_Vector z)
void N_VDestroy_NrnThread(N_Vector v)
double max(double a, double b)
realtype N_VMinQuotient_NrnThread(N_Vector x, N_Vector y)
static void * vmin(NrnThread *nt)
void nrn_multithread_job(void *(*job)(NrnThread *))
static void * vmaxnorm(NrnThread *nt)
static void * vconst(NrnThread *nt)
void N_VSetArrayPointer_NrnThread(realtype *v_data, N_Vector v)
#define NV_OWN_DATA_NT(v)
void N_VConst_NrnThread(realtype c, N_Vector z)
void N_VProd_NrnThread(N_Vector x, N_Vector y, N_Vector z)
#define NV_SUBVEC_NT(v, i)
N_Vector N_VMake_NrnThread(long int length, realtype *v_data)
realtype N_VMaxNorm_NrnThread(N_Vector x)
Represent main neuron object computed by single thread.
void N_VPrint_NrnThread(N_Vector x)
static void * vaddconst(NrnThread *nt)
void N_VSpace_NrnThread(N_Vector v, long int *lrw, long int *liw)
N_Vector N_VClone_NrnThread(N_Vector w)
static void pr(N_Vector x)
booleantype N_VInvTest_NrnThread(N_Vector x, N_Vector z)
N_Vector N_VNewEmpty_NrnThread(long int length, int nthread, long int *sizes)
static void * vabs(NrnThread *nt)
void N_VOneMask_NrnThread(N_Vector x)
realtype N_VWrmsNorm_NrnThread(N_Vector x, N_Vector w)
#define locklongdadd(arg)
realtype * N_VGetArrayPointer_NrnThread(N_Vector v)
void N_VInv_NrnThread(N_Vector x, N_Vector z)
realtype N_VMin_NrnThread(N_Vector x)
booleantype N_VConstrMask_NrnThread(N_Vector y, N_Vector x, N_Vector z)
static void * vcompare(NrnThread *nt)
static void * vlinearsum(NrnThread *nt)
static void * vwrmsnormmask(NrnThread *nt)
static long double longdretval
void N_VScale_NrnThread(realtype c, N_Vector x, N_Vector z)
N_Vector * N_VNewVectorArrayEmpty_NrnThread(int count, long int length, int nthread, long int *sizes)
static void * vwrmsnorm(NrnThread *nt)
static realtype N_VWL2Norm_helper(N_Vector x, N_Vector w)
static void * vconstrmask(NrnThread *nt)
static void * vprod(NrnThread *nt)
static void * vscale(NrnThread *nt)
realtype N_VDotProd_NrnThread(N_Vector x, N_Vector y)
static void * v1mask(NrnThread *nt)
N_Vector * N_VNewVectorArray_NrnThread(int count, long int length, int nthread, long int *sizes)
static void * vinv(NrnThread *nt)
#define MUTCONSTRUCT(mkmut)
static realtype vwrmsnormmask_help(N_Vector x, N_Vector w, N_Vector id)
static void * vminquotient(NrnThread *nt)
void N_VOneMask_Serial(N_Vector x)
static void * vwl2norm(NrnThread *nt)
static void * vdotprod(NrnThread *nt)
static ldrealtype vwrmsnorm_help(N_Vector x, N_Vector w)
static void * vl1norm(NrnThread *nt)
static void * vdiv(NrnThread *nt)
static void * vinvtest(NrnThread *nt)
realtype N_VWrmsNormMask_NrnThread(N_Vector x, N_Vector w, N_Vector id)
struct _N_VectorContent_NrnThread * N_VectorContent_NrnThread
void N_VAddConst_NrnThread(N_Vector x, realtype b, N_Vector z)
static booleantype bretval
void N_VDiv_NrnThread(N_Vector x, N_Vector y, N_Vector z)
realtype N_VWL2Norm_NrnThread(N_Vector x, N_Vector w)
void N_VAbs_NrnThread(N_Vector x, N_Vector z)
N_Vector N_VCloneEmpty_NrnThread(N_Vector w)
void N_VCompare_NrnThread(realtype c, N_Vector x, N_Vector z)
void N_VDestroyVectorArray_NrnThread(N_Vector *vs, int count)
N_Vector N_VNew_NrnThread(long int length, int nthread, long int *sizes)
realtype N_VL1Norm_NrnThread(N_Vector x)