1 /*
2  * -----------------------------------------------------------------
3  * Programmer(s): David J. Gardner, Cody J. Balos @ LLNL
4  *                Daniel R. Reynolds @ SMU
5  * -----------------------------------------------------------------
6  * SUNDIALS Copyright Start
7  * Copyright (c) 2002-2020, Lawrence Livermore National Security
8  * and Southern Methodist University.
9  * All rights reserved.
10  *
11  * See the top-level LICENSE and NOTICE files for details.
12  *
13  * SPDX-License-Identifier: BSD-3-Clause
14  * SUNDIALS Copyright End
15  * -----------------------------------------------------------------
16  * This is the header file contains the prototypes for functions to
17  * test SUNMatrix module implementation.
18  * -----------------------------------------------------------------
19  */
20 
21 #include <math.h>
22 
23 /* define constatnts */
24 #define NEG_TWO  RCONST(-2.0)
25 #define NEG_ONE  RCONST(-1.0)
26 #define NEG_HALF RCONST(-0.5)
27 #define ZERO     RCONST(0.0)
28 #define HALF     RCONST(0.5)
29 #define ONE      RCONST(1.0)
30 #define TWO      RCONST(2.0)
31 #define THREE    RCONST(3.0)
32 
33 /* NAN and floating point "equality" check, failure update macro */
34 #if __STDC_VERSION__ >= 199901L
35 #define FNEQ(a,b,tol) (isnan(a) ? 1 : ( SUNRabs((a)-(b))/SUNRabs(b) > tol ))
36 #else
37 #define FNEQ(a,b,tol) (( SUNRabs((a)-(b))/SUNRabs(b) > tol ))
38 #endif
39 
40 /* Helpers for printing out test status information */
41 #define TEST_STATUS(fmt, myrank)                     \
42   if (print_all_ranks == 0 && myrank == 0) {         \
43     printf(fmt);                                     \
44   } else if (print_all_ranks) {                      \
45     printf("process %06d: ", myrank);                \
46     printf(fmt);                                     \
47   }
48 #define TEST_STATUS2(fmt, retval, myrank)            \
49   if (print_all_ranks == 0 && myrank == 0) {         \
50     printf(fmt, retval);                             \
51   } else if (print_all_ranks) {                      \
52     printf("process %06d: ", myrank);                \
53     printf(fmt, retval);                             \
54   }
55 #define TEST_STATUS3(fmt, val1, val2, myrank)        \
56   if (print_all_ranks == 0 && myrank == 0) {         \
57     printf(fmt, val1, val2);                         \
58   } else if (print_all_ranks) {                      \
59     printf("process %06d: ", myrank);                \
60     printf(fmt, val1, val2);                         \
61   }
62 
63 #ifdef __cplusplus  /* wrapper to enable C++ usage */
64 extern "C" {
65 #endif
66   /* Forward declarations for implementation specific utility functions */
67   int check_matrix(SUNMatrix A, SUNMatrix B, realtype tol);
68   int check_matrix_entry(SUNMatrix A, realtype val, realtype tol);
69   int check_vector(N_Vector expected, N_Vector computed, realtype tol);
70   booleantype has_data(SUNMatrix A);
71   booleantype is_square(SUNMatrix A);
72 
73   /* Test function declarations */
74   int Test_SUNMatGetID(SUNMatrix A, SUNMatrix_ID sunid, int myid);
75   int Test_SUNMatClone(SUNMatrix A, int myid);
76   int Test_SUNMatZero(SUNMatrix A, int myid);
77   int Test_SUNMatCopy(SUNMatrix A, int myid);
78   int Test_SUNMatScaleAdd(SUNMatrix A, SUNMatrix I, int myid);
79   int Test_SUNMatScaleAddI(SUNMatrix A, SUNMatrix I, int myid);
80   int Test_SUNMatMatvecSetup(SUNMatrix A, int myid);
81   int Test_SUNMatMatvec(SUNMatrix A, N_Vector x, N_Vector y, int myid);
82   int Test_SUNMatSpace(SUNMatrix A, int myid);
83 
84   /* Timing function */
85   void SetTiming(int onoff);
86 
87   /* Function to set print_all_ranks */
88   void SetPrintAllRanks(int onoff);
89 #ifdef __cplusplus
90 }
91 #endif
92