1 #ifndef TEST_H
2 #define TEST_H
3 
4 #include "../config.h"
5 #include "config.h"
6 
7 #if BLAS_UNDERSCORE
8 #define BLAS(routine) routine ## _
9 #else
10 #define BLAS(routine) routine
11 #endif
12 
13 #if LAPACK_UNDERSCORE
14 #define LAPACK(routine) routine ## _
15 #else
16 #define LAPACK(routine) routine
17 #endif
18 
19 #include "../inc/relapack.h"
20 #include "lapack.h"
21 #include "util.h"
22 #include <stdlib.h>
23 #include <stdio.h>
24 #include <string.h>
25 
26 // some name mangling macros
27 #define CAT(A, B) A ## B
28 #define XCAT(A, B) CAT(A, B)
29 #define XLAPACK(X) LAPACK(X)
30 #define XRELAPACK(X) XCAT(RELAPACK_, X)
31 #define STR(X) #X
32 #define XSTR(X) STR(X)
33 
34 // default setup and error computation names: pre() and post()
35 #define PRE pre
36 #define POST post
37 
38 // TEST macro:
39 // run setup (pre()), ReLAPACK routine (i = 0), LAPACK routine (i = 1), compute
40 // error (post()), check error bound, and  print setup and error
41 #define TEST(...) \
42     PRE(); \
43     i = 0; \
44     XRELAPACK(ROUTINE)(__VA_ARGS__); \
45     i = 1; \
46     XLAPACK(ROUTINE)(__VA_ARGS__); \
47     POST(); \
48     fail |= error > ERR_BOUND; \
49     printf("%s(%s)\t%g\n", XSTR(ROUTINE), #__VA_ARGS__, error);
50 
51 // generalized datatype treatment: DT_PREFIX determines the type s, d, c, or z
52 #define XPREF(A) XCAT(DT_PREFIX, A)
53 
54 // matrix generation and error computation routines
55 #define x2matgen XPREF(2matgen)
56 #define x2vecerr XPREF(2vecerr)
57 
58 // error bounds
59 #define ERR_BOUND XPREF(ERR_BOUND_)
60 #define sERR_BOUND_ SINGLE_ERR_BOUND
61 #define dERR_BOUND_ DOUBLE_ERR_BOUND
62 #define cERR_BOUND_ SINGLE_ERR_BOUND
63 #define zERR_BOUND_ DOUBLE_ERR_BOUND
64 
65 // C datatypes
66 #define datatype XPREF(datatype_)
67 #define sdatatype_ float
68 #define ddatatype_ double
69 #define cdatatype_ float
70 #define zdatatype_ double
71 
72 // number of C datatype elements per element
73 #define x1 XPREF(DT_MULT)
74 #define sDT_MULT 1
75 #define dDT_MULT 1
76 #define cDT_MULT 2
77 #define zDT_MULT 2
78 
79 // typed allocations
80 #define xmalloc XPREF(malloc)
81 #define imalloc(S) malloc((S) * sizeof(int))
82 #define smalloc(S) malloc((S) * sizeof(float))
83 #define dmalloc(S) malloc((S) * sizeof(double))
84 #define cmalloc(S) malloc((S) * 2 * sizeof(float))
85 #define zmalloc(S) malloc((S) * 2 * sizeof(double))
86 
87 // transpositions
88 #define xCTRANS XPREF(CTRANS)
89 #define sCTRANS "T"
90 #define dCTRANS "T"
91 #define cCTRANS "C"
92 #define zCTRANS "C"
93 
94 // some constants
95 #define MONE XPREF(MONE)
96 const float  sMONE[] = { -1. };
97 const double dMONE[] = { -1. };
98 const float  cMONE[] = { -1., 0. };
99 const double zMONE[] = { -1., 0. };
100 
101 #define ZERO XPREF(ZERO)
102 const float  sZERO[] = { 0. };
103 const double dZERO[] = { 0. };
104 const float  cZERO[] = { 0., 0. };
105 const double zZERO[] = { 0., 0. };
106 
107 #define ONE  XPREF(ONE)
108 const float  sONE[]  = { 1. };
109 const double dONE[]  = { 1. };
110 const float  cONE[]  = { 1., 0. };
111 const double zONE[]  = { 1., 0. };
112 
113 const int iMONE[]  = { -1 };
114 const int iZERO[]  = { 0 };
115 const int iONE[]   = { 1 };
116 const int iTWO[]   = { 2 };
117 const int iTHREE[] = { 3 };
118 const int iFOUR[]  = { 4 };
119 
120 void tests();
121 
122 // global variables (used in tests(), pre(), and post())
123 int i, n, n2, fail;
124 double error;
125 
main(int argc,char * argv[])126 int main(int argc, char* argv[]) {
127     n = TEST_SIZE;
128     n2 = (3 * n) / 4;
129     fail = 0;
130 
131     tests();
132 
133     return fail;
134 }
135 
136 #endif /* TEST_H */
137