19 #define USELONGDOUBLE 1 21 #include <../../nrnconf.h> 28 #include <nrnmpiuse.h> 29 #if NRNMPI_DYNAMICLOAD 30 extern "C" void nrnmpi_dbl_allreduce_vec(
double* src,
double* dest,
int cnt,
int type);
31 extern "C" void nrnmpi_longdbl_allreduce_vec(
long double* src,
long double* dest,
int cnt,
int type);
32 extern "C" void nrnmpi_long_allreduce_vec(
long* src,
long* dest,
int cnt,
int type);
37 #if NRNMPI_DYNAMICLOAD 41 #include "sundialsmath.h" 42 #include "sundialstypes.h" 44 #define ZERO RCONST(0.0) 45 #define HALF RCONST(0.5) 46 #define ONE RCONST(1.0) 47 #define ONEPT5 RCONST(1.5) 50 #define ldrealtype long double 52 #define ldrealtype realtype 58 #define BAD_N1 "N_VNew_NrnParallelLD -- Sum of local vector lengths differs from " 59 #define BAD_N2 "input global length. \n\n" 60 #define BAD_N BAD_N1 BAD_N2 70 #define VAllReduce_long_NrnParallelLD VAllReduce_NrnParallelLD 104 long int local_length,
105 long int global_length)
114 #if NRNMPI_DYNAMICLOAD 115 nrnmpi_long_allreduce_vec(&n, &Nsum, 1, 1);
120 if (Nsum != global_length) {
126 v = (N_Vector) malloc(
sizeof *v);
130 ops = (N_Vector_Ops) malloc(
sizeof(
struct _generic_N_Vector_Ops));
131 if (ops ==
NULL) { free(v);
return(
NULL); }
160 if (content ==
NULL) { free(ops); free(v);
return(
NULL); }
165 content->
comm = comm;
170 v->content = content;
181 long int local_length,
182 long int global_length)
191 if(local_length > 0) {
194 data = (realtype *) malloc(local_length *
sizeof(realtype));
219 v = (N_Vector) malloc(
sizeof *v);
223 ops = (N_Vector_Ops) malloc(
sizeof(
struct _generic_N_Vector_Ops));
224 if (ops ==
NULL) { free(v);
return(
NULL); }
226 ops->nvclone = w->ops->nvclone;
227 ops->nvdestroy = w->ops->nvdestroy;
228 ops->nvspace = w->ops->nvspace;
229 ops->nvgetarraypointer = w->ops->nvgetarraypointer;
230 ops->nvsetarraypointer = w->ops->nvsetarraypointer;
231 ops->nvlinearsum = w->ops->nvlinearsum;
232 ops->nvconst = w->ops->nvconst;
233 ops->nvprod = w->ops->nvprod;
234 ops->nvdiv = w->ops->nvdiv;
235 ops->nvscale = w->ops->nvscale;
236 ops->nvabs = w->ops->nvabs;
237 ops->nvinv = w->ops->nvinv;
238 ops->nvaddconst = w->ops->nvaddconst;
239 ops->nvdotprod = w->ops->nvdotprod;
240 ops->nvmaxnorm = w->ops->nvmaxnorm;
241 ops->nvwrmsnormmask = w->ops->nvwrmsnormmask;
242 ops->nvwrmsnorm = w->ops->nvwrmsnorm;
243 ops->nvmin = w->ops->nvmin;
244 ops->nvwl2norm = w->ops->nvwl2norm;
245 ops->nvl1norm = w->ops->nvl1norm;
246 ops->nvcompare = w->ops->nvcompare;
247 ops->nvinvtest = w->ops->nvinvtest;
248 ops->nvconstrmask = w->ops->nvconstrmask;
249 ops->nvminquotient = w->ops->nvminquotient;
253 if (content ==
NULL) { free(ops); free(v);
return(
NULL); }
263 v->content = content;
274 long int local_length,
275 long int global_length,
283 if (local_length > 0) {
298 long int local_length,
299 long int global_length)
304 if (count <= 0)
return(
NULL);
306 vs = (N_Vector *) malloc(count *
sizeof(N_Vector));
309 for (j=0; j<count; j++) {
327 long int local_length,
328 long int global_length)
333 if (count <= 0)
return(
NULL);
335 vs = (N_Vector *) malloc(count *
sizeof(N_Vector));
338 for (j=0; j<count; j++) {
374 for (i=0; i < N; i++) {
375 #if defined(SUNDIALS_EXTENDED_PRECISION) 377 #elif defined(SUNDIALS_DOUBLE_PRECISION) 396 long int local_length;
404 if(local_length > 0) {
407 data = (realtype *) malloc(local_length *
sizeof(realtype));
433 #if NRNMPI_DYNAMICLOAD 436 MPI_Comm_size(comm, &npes);
460 realtype
c, *xd, *yd, *zd;
464 if ((b ==
ONE) && (z == y)) {
469 if ((a ==
ONE) && (z == x)) {
476 if ((a ==
ONE) && (b ==
ONE)) {
483 if ((test = ((a ==
ONE) && (b == -
ONE))) || ((a == -
ONE) && (b ==
ONE))) {
493 if ((test = (a ==
ONE)) || (b ==
ONE)) {
503 if ((test = (a == -
ONE)) || (b == -
ONE)) {
536 for (i=0; i < N; i++)
537 *zd++ = a * (*xd++) + b * (*yd++);
548 for (i=0; i < N; i++)
555 realtype *xd, *yd, *zd;
562 for (i=0; i < N; i++)
563 *zd++ = (*xd++) * (*yd++);
569 realtype *xd, *yd, *zd;
576 for (i=0; i < N; i++)
577 *zd++ = (*xd++) / (*yd++);
592 }
else if (c == -
ONE) {
598 for (i=0; i < N; i++)
612 for (i=0; i < N; i++, xd++, zd++)
625 for (i=0; i < N; i++)
626 *zd++ =
ONE / (*xd++);
638 for (i=0; i < N; i++) *zd++ = (*xd++) + b;
644 realtype sum =
ZERO, *xd, *yd, gsum;
652 for (i=0; i < N; i++) sum += xd[i] * yd[i];
661 realtype
max, *xd, gmax;
670 for (i=0; i < N; i++, xd++) {
671 if (
ABS(*xd) > max) max =
ABS(*xd);
680 long int i, N, N_global;
681 realtype prodi, *xd, *wd;
691 for (i=0; i < N; i++) {
692 prodi = (*xd++) * (*wd++);
693 sum += prodi * prodi;
697 return(RSqrt((realtype)gsum / N_global));
702 long int i, N, N_global;
703 realtype prodi, *xd, *wd, *idd;
714 for (i=0; i < N; i++) {
716 prodi = xd[
i] * wd[
i];
717 sum += prodi * prodi;
722 return(RSqrt((realtype)gsum / N_global));
728 realtype
min, *xd, gmin;
743 for (i=1; i < N; i++, xd++) {
744 if ((*xd) < min) min = *xd;
756 realtype prodi, *xd, *wd;
765 for (i=0; i < N; i++) {
766 prodi = (*xd++) * (*wd++);
767 sum += prodi * prodi;
771 return(RSqrt((realtype)gsum));
785 for (i=0; i<N; i++,xd++)
801 for (i=0; i < N; i++, xd++, zd++) {
809 realtype *xd, *zd,
val, gval;
818 for (i=0; i < N; i++) {
822 *zd++ =
ONE / (*xd++);
836 realtype *cd, *xd, *md;
847 for (i=0; i<N; i++, cd++, xd++, md++) {
849 if (*cd ==
ZERO)
continue;
854 if ( (*cd) >
HALF || (*cd) < -
HALF) {
864 booleantype notEvenOnce;
866 realtype *
nd, *dd,
min=0.0;
876 for (i = 0; i < N; i++, nd++, dd++) {
877 if (*dd ==
ZERO)
continue;
883 else min =
MIN(min, (*nd) / (*dd));
887 if (notEvenOnce || (N == 0)) min = BIG_REAL;
910 #if NRNMPI_DYNAMICLOAD 911 nrnmpi_dbl_allreduce_vec(&d, &out, 1, op);
914 case 1: MPI_Allreduce(&d, &out, 1, PVEC_REAL_MPI_TYPE, MPI_SUM, comm);
917 case 2: MPI_Allreduce(&d, &out, 1, PVEC_REAL_MPI_TYPE, MPI_MAX, comm);
920 case 3: MPI_Allreduce(&d, &out, 1, PVEC_REAL_MPI_TYPE, MPI_MIN, comm);
944 #if NRNMPI_DYNAMICLOAD 945 nrnmpi_longdbl_allreduce_vec(&d, &out, 1, op);
947 MPI_Allreduce(&d, &out, 1, MPI_LONG_DOUBLE, MPI_SUM, comm);
963 for (i=0; i < N; i++)
970 realtype *xd, *yd, *zd;
977 for (i=0; i < N; i++)
978 *zd++ = (*xd++) + (*yd++);
984 realtype *xd, *yd, *zd;
991 for (i=0; i < N; i++)
992 *zd++ = (*xd++) - (*yd++);
1004 for (i=0; i < N; i++)
1011 realtype *xd, *yd, *zd;
1018 for (i=0; i < N; i++)
1019 *zd++ = c * ((*xd++) + (*yd++));
1025 realtype *xd, *yd, *zd;
1032 for (i=0; i < N; i++)
1033 *zd++ = c * ((*xd++) - (*yd++));
1039 realtype *xd, *yd, *zd;
1046 for (i=0; i < N; i++)
1047 *zd++ = a * (*xd++) + (*yd++);
1053 realtype *xd, *yd, *zd;
1060 for (i=0; i < N; i++)
1061 *zd++ = a * (*xd++) - (*yd++);
1074 for (i=0; i < N; i++)
1080 for (i=0; i < N; i++)
1085 for (i=0; i < N; i++)
1086 *yd++ += a * (*xd++);
1097 for (i=0; i < N; i++)
void N_VAbs_NrnParallelLD(N_Vector x, N_Vector z)
static ldrealtype VAllReduce_long_NrnParallelLD(ldrealtype d, int op, MPI_Comm comm)
void N_VDiv_NrnParallelLD(N_Vector x, N_Vector y, N_Vector z)
double max(double a, double b)
N_Vector N_VMake_NrnParallelLD(MPI_Comm comm, long int local_length, long int global_length, realtype *v_data)
static void VScaleBy_NrnParallelLD(realtype a, N_Vector x)
void N_VDestroyVectorArray_NrnParallelLD(N_Vector *vs, int count)
void N_VCompare_NrnParallelLD(realtype c, N_Vector x, N_Vector z)
N_Vector N_VNewEmpty_NrnParallelLD(MPI_Comm comm, long int local_length, long int global_length)
void N_VPrint_NrnParallelLD(N_Vector x)
realtype N_VMaxNorm_NrnParallelLD(N_Vector x)
void N_VProd_NrnParallelLD(N_Vector x, N_Vector y, N_Vector z)
realtype N_VL1Norm_NrnParallelLD(N_Vector x)
void N_VScale_NrnParallelLD(realtype c, N_Vector x, N_Vector z)
void N_VAddConst_NrnParallelLD(N_Vector x, realtype b, N_Vector z)
N_Vector N_VClone_NrnParallelLD(N_Vector w)
void N_VSetArrayPointer_NrnParallelLD(realtype *v_data, N_Vector v)
realtype N_VWrmsNormMask_NrnParallelLD(N_Vector x, N_Vector w, N_Vector id)
realtype N_VWL2Norm_NrnParallelLD(N_Vector x, N_Vector w)
booleantype N_VInvTest_NrnParallelLD(N_Vector x, N_Vector z)
void N_VLinearSum_NrnParallelLD(realtype a, N_Vector x, realtype b, N_Vector y, N_Vector z)
void N_VInv_NrnParallelLD(N_Vector x, N_Vector z)
static realtype VAllReduce_NrnParallelLD(realtype d, int op, MPI_Comm comm)
#define PVEC_INTEGER_MPI_TYPE
struct _N_VectorContent_NrnParallelLD * N_VectorContent_NrnParallelLD
static void Vaxpy_NrnParallelLD(realtype a, N_Vector x, N_Vector y)
int const size_t const size_t n
static void VScaleDiff_NrnParallelLD(realtype c, N_Vector x, N_Vector y, N_Vector z)
N_Vector * N_VNewVectorArrayEmpty_NrnParallelLD(int count, MPI_Comm comm, long int local_length, long int global_length)
N_Vector N_VCloneEmpty_NrnParallelLD(N_Vector w)
static void VCopy_NrnParallelLD(N_Vector x, N_Vector z)
static void VLin2_NrnParallelLD(realtype a, N_Vector x, N_Vector y, N_Vector z)
void N_VConst_NrnParallelLD(realtype c, N_Vector z)
static void VNeg_NrnParallelLD(N_Vector x, N_Vector z)
static void VScaleSum_NrnParallelLD(realtype c, N_Vector x, N_Vector y, N_Vector z)
static void VLin1_NrnParallelLD(realtype a, N_Vector x, N_Vector y, N_Vector z)
void N_VDestroy_NrnParallelLD(N_Vector v)
#define NV_OWN_DATA_P_LD(v)
#define NV_LOCLENGTH_P_LD(v)
realtype N_VMin_NrnParallelLD(N_Vector x)
void N_VSpace_NrnParallelLD(N_Vector v, long int *lrw, long int *liw)
booleantype N_VConstrMask_NrnParallelLD(N_Vector c, N_Vector x, N_Vector m)
N_Vector N_VNew_NrnParallelLD(MPI_Comm comm, long int local_length, long int global_length)
static void VSum_NrnParallelLD(N_Vector x, N_Vector y, N_Vector z)
#define NV_GLOBLENGTH_P_LD(v)
realtype * N_VGetArrayPointer_NrnParallelLD(N_Vector v)
N_Vector * N_VNewVectorArray_NrnParallelLD(int count, MPI_Comm comm, long int local_length, long int global_length)
static void VDiff_NrnParallelLD(N_Vector x, N_Vector y, N_Vector z)
realtype N_VDotProd_NrnParallelLD(N_Vector x, N_Vector y)
realtype N_VWrmsNorm_NrnParallelLD(N_Vector x, N_Vector w)
realtype N_VMinQuotient_NrnParallelLD(N_Vector num, N_Vector denom)