1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148
|
/* -----------------------------------------------------------------
* Programmer(s): David J. Gardner @ LLNL
* -----------------------------------------------------------------
* LLNS Copyright Start
* Copyright (c) 2014, Lawrence Livermore National Security
* This work was performed under the auspices of the U.S. Department
* of Energy by Lawrence Livermore National Laboratory in part under
* Contract W-7405-Eng-48 and in part under Contract DE-AC52-07NA27344.
* Produced at the Lawrence Livermore National Laboratory.
* All rights reserved.
* For details, see the LICENSE file.
* LLNS Copyright End
* -----------------------------------------------------------------
* This is the testing routine to check the NVECTOR Serial module
* implementation.
* -----------------------------------------------------------------*/
#include <stdio.h>
#include <stdlib.h>
#include <sundials/sundials_types.h>
#include <nvector/nvector_serial.h>
#include <sundials/sundials_math.h>
#include "test_nvector.h"
/* ----------------------------------------------------------------------
* Main NVector Testing Routine
* --------------------------------------------------------------------*/
int main(int argc, char *argv[])
{
int fails = 0; /* counter for test failures */
sunindextype veclen; /* vector length */
N_Vector W, X, Y, Z; /* test vectors */
int print_timing;
/* check input and set vector length */
if (argc < 3){
printf("ERROR: TWO (2) Inputs required: vector length, print timing \n");
return(-1);
}
veclen = atol(argv[1]);
if (veclen <= 0) {
printf("ERROR: length of vector must be a positive integer \n");
return(-1);
}
print_timing = atoi(argv[2]);
SetTiming(print_timing);
printf("\nRunning with vector length %ld \n \n", (long int) veclen);
/* Create vectors */
W = N_VNewEmpty_Serial(veclen);
X = N_VNew_Serial(veclen);
Y = N_VNew_Serial(veclen);
Z = N_VNew_Serial(veclen);
if(N_VGetVectorID(W) == SUNDIALS_NVEC_SERIAL) {
/*printf("Testing serial variant of N_Vector...\n");*/
}
/* NVector Tests */
fails += Test_N_VSetArrayPointer(W, veclen, 0);
fails += Test_N_VGetArrayPointer(X, veclen, 0);
fails += Test_N_VLinearSum(X, Y, Z, veclen, 0);
fails += Test_N_VConst(X, veclen, 0);
fails += Test_N_VProd(X, Y, Z, veclen, 0);
fails += Test_N_VDiv(X, Y, Z, veclen, 0);
fails += Test_N_VScale(X, Z, veclen, 0);
fails += Test_N_VAbs(X, Z, veclen, 0);
fails += Test_N_VInv(X, Z, veclen, 0);
fails += Test_N_VAddConst(X, Z, veclen, 0);
fails += Test_N_VDotProd(X, Y, veclen, veclen, 0);
fails += Test_N_VMaxNorm(X, veclen, 0);
fails += Test_N_VWrmsNorm(X, Y, veclen, 0);
fails += Test_N_VWrmsNormMask(X, Y, Z, veclen, veclen, 0);
fails += Test_N_VMin(X, veclen, 0);
fails += Test_N_VWL2Norm(X, Y, veclen, veclen, 0);
fails += Test_N_VL1Norm(X, veclen, veclen, 0);
fails += Test_N_VCompare(X, Z, veclen, 0);
fails += Test_N_VInvTest(X, Z, veclen, 0);
fails += Test_N_VConstrMask(X, Y, Z, veclen, 0);
fails += Test_N_VMinQuotient(X, Y, veclen, 0);
fails += Test_N_VCloneVectorArray(5, X, veclen, 0);
fails += Test_N_VCloneEmptyVectorArray(5, X, 0);
fails += Test_N_VCloneEmpty(X, 0);
fails += Test_N_VClone(X, veclen, 0);
/* Free vectors */
N_VDestroy_Serial(W);
N_VDestroy_Serial(X);
N_VDestroy_Serial(Y);
N_VDestroy_Serial(Z);
/* Print result */
if (fails) {
printf("FAIL: NVector module failed %i tests \n \n", fails);
} else {
printf("SUCCESS: NVector module passed all tests \n \n");
}
return(fails);
}
/* ----------------------------------------------------------------------
* Check vector
* --------------------------------------------------------------------*/
int check_ans(realtype ans, N_Vector X, sunindextype local_length)
{
int failure = 0;
sunindextype i;
realtype *Xdata;
Xdata = N_VGetArrayPointer(X);
/* check vector data */
for(i=0; i < local_length; i++){
failure += FNEQ(Xdata[i], ans);
}
if (failure > ZERO)
return(1);
else
return(0);
}
booleantype has_data(N_Vector X)
{
realtype *Xdata = N_VGetArrayPointer(X);
if (Xdata == NULL)
return SUNFALSE;
else
return SUNTRUE;
}
void set_element(N_Vector X, sunindextype i, realtype val)
{
NV_Ith_S(X,i) = val;
}
realtype get_element(N_Vector X, sunindextype i)
{
return NV_Ith_S(X,i);
}
|