Loading [MathJax]/extensions/TeX/AMSsymbols.js
LAL 7.7.0.1-5e288d3
All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
VectorMathTest.c
Go to the documentation of this file.
1/*
2* Copyright (C) 2015 Reinhard Prix, Karl Wette
3*
4* This program is free software; you can redistribute it and/or modify
5* it under the terms of the GNU General Public License as published by
6* the Free Software Foundation; either version 2 of the License, or
7* (at your option) any later version.
8*
9* This program is distributed in the hope that it will be useful,
10* but WITHOUT ANY WARRANTY; without even the implied warranty of
11* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12* GNU General Public License for more details.
13*
14* You should have received a copy of the GNU General Public License
15* along with with program; see the file COPYING. If not, write to the
16* Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
17* MA 02110-1301 USA
18*/
19#include <math.h>
20#include <stdlib.h>
21
22#include <config.h>
23
24#include <lal/LALVCSInfo.h>
25#include <lal/LALConstants.h>
26#include <lal/XLALError.h>
27#include <lal/AVFactories.h>
28#include <lal/LogPrintf.h> // for timing function XLALGetCPUTime()
29#include <lal/UserInput.h>
30
31#include <lal/VectorMath.h>
32
33/* for access to internal prototypes for generic (GEN) functions, for reference results */
34#include <vectorops/VectorMath_internal.h>
35
36// ---------- Macros ----------
37#define frand() (rand() / (REAL4)RAND_MAX)
38#define Relerr(dx,x) (fabsf(x)>0 ? fabsf((dx)/(x)) : fabsf(dx) )
39#define Relerrd(dx,x) (fabs(x)>0 ? fabs((dx)/(x)) : fabs(dx) )
40#define cRelerr(dx,x) (cabsf(x)>0 ? cabsf((dx)/(x)) : fabsf(dx) )
41
42// ----- test and benchmark operators with 1 REAL4 vector input and 1 INT4 vector output (S2I) ----------
43#define TESTBENCH_VECTORMATH_S2I(name,in) \
44 { \
45 XLAL_CHECK ( XLALVector##name##REAL4_GEN( xOutRefI4->data, in, Ntrials ) == XLAL_SUCCESS, XLAL_EFUNC ); \
46 tic = XLALGetCPUTime(); \
47 for (UINT4 l=0; l < Nruns; l ++ ) { \
48 XLAL_CHECK ( XLALVector##name##REAL4( xOutI4->data, in, Ntrials ) == XLAL_SUCCESS, XLAL_EFUNC ); \
49 } \
50 toc = XLALGetCPUTime(); \
51 for ( UINT4 i = 0; i < Ntrials; i ++ ) \
52 { \
53 XLAL_CHECK ( xOutI4->data[i] == xOutRefI4->data[i], XLAL_ETOL, "%s: found element #%u (%i) differs from reference (%i)", #name, i, xOutI4->data[i], xOutRefI4->data[i] ); \
54 } \
55 XLALPrintInfo ( "%-32s: %4.0f Mops/sec\n", XLALVector##name##REAL4_name, (REAL8)Ntrials * Nruns / (toc - tic)/1e6 ); \
56 }
57
58// ----- test and benchmark operators with 1 REAL4 vector input and 1 REAL4 scalar output (S2s) ----------
59#define TESTBENCH_VECTORMATH_S2s(name,in) \
60 { \
61 REAL4 sOutRef, sOut; \
62 XLAL_CHECK ( XLALVector##name##REAL4_GEN( &sOutRef, in, Ntrials ) == XLAL_SUCCESS, XLAL_EFUNC ); \
63 tic = XLALGetCPUTime(); \
64 for (UINT4 l=0; l < Nruns; l ++ ) { \
65 XLAL_CHECK ( XLALVector##name##REAL4( &sOut, in, Ntrials ) == XLAL_SUCCESS, XLAL_EFUNC ); \
66 } \
67 toc = XLALGetCPUTime(); \
68 maxErr = fabsf( sOut - sOutRef ); \
69 maxRelerr = Relerr( maxErr, sOutRef ); \
70 XLALPrintInfo ( "%-32s: %4.0f Mops/sec [maxErr = %7.2g (tol=%7.2g), maxRelerr = %7.2g (tol=%7.2g)]\n", \
71 XLALVector##name##REAL4_name, (REAL8)Ntrials * Nruns / (toc - tic)/1e6, maxErr, (abstol), maxRelerr, (reltol) ); \
72 XLAL_CHECK ( (maxErr <= (abstol)), XLAL_ETOL, "%s: absolute error (%g) exceeds tolerance (%g)\n", #name "REAL4", maxErr, abstol ); \
73 XLAL_CHECK ( (maxRelerr <= (reltol)), XLAL_ETOL, "%s: relative error (%g) exceeds tolerance (%g)\n", #name "REAL4", maxRelerr, reltol ); \
74 }
75
76// ----- test and benchmark operators with 1 REAL4 vector input and 1 REAL4 vector output (S2S) ----------
77#define TESTBENCH_VECTORMATH_S2S(name,in) \
78 { \
79 XLAL_CHECK ( XLALVector##name##REAL4_GEN( xOutRef, in, Ntrials ) == XLAL_SUCCESS, XLAL_EFUNC ); \
80 tic = XLALGetCPUTime(); \
81 for (UINT4 l=0; l < Nruns; l ++ ) { \
82 XLAL_CHECK ( XLALVector##name##REAL4( xOut, in, Ntrials ) == XLAL_SUCCESS, XLAL_EFUNC ); \
83 } \
84 toc = XLALGetCPUTime(); \
85 maxErr = maxRelerr = 0; \
86 for ( UINT4 i = 0; i < Ntrials; i ++ ) \
87 { \
88 REAL4 err = fabsf ( xOut[i] - xOutRef[i] ); \
89 REAL4 relerr = Relerr ( err, xOutRef[i] ); \
90 maxErr = fmaxf ( err, maxErr ); \
91 maxRelerr = fmaxf ( relerr, maxRelerr ); \
92 } \
93 XLALPrintInfo ( "%-32s: %4.0f Mops/sec [maxErr = %7.2g (tol=%7.2g), maxRelerr = %7.2g (tol=%7.2g)]\n", \
94 XLALVector##name##REAL4_name, (REAL8)Ntrials * Nruns / (toc - tic)/1e6, maxErr, (abstol), maxRelerr, (reltol) ); \
95 XLAL_CHECK ( (maxErr <= (abstol)), XLAL_ETOL, "%s: absolute error (%g) exceeds tolerance (%g)\n", #name "REAL4", maxErr, abstol ); \
96 XLAL_CHECK ( (maxRelerr <= (reltol)), XLAL_ETOL, "%s: relative error (%g) exceeds tolerance (%g)\n", #name "REAL4", maxRelerr, reltol ); \
97 }
98
99// ----- test and benchmark operators with 1 REAL4 vector input to 2 REAL4 vector outputs (S2SS) ----------
100#define TESTBENCH_VECTORMATH_S2SS(name,in) \
101 { \
102 XLAL_CHECK ( XLALVector##name##REAL4_GEN( xOutRef, xOutRef2, xIn, Ntrials ) == XLAL_SUCCESS, XLAL_EFUNC ); \
103 tic = XLALGetCPUTime(); \
104 for (UINT4 l=0; l < Nruns; l ++ ) { \
105 XLAL_CHECK ( XLALVector##name##REAL4( xOut, xOut2, xIn, Ntrials ) == XLAL_SUCCESS, XLAL_EFUNC ); \
106 } \
107 toc = XLALGetCPUTime(); \
108 maxErr = maxRelerr = 0; \
109 for ( UINT4 i = 0; i < Ntrials; i ++ ) { \
110 REAL4 err1 = fabsf ( xOut[i] - xOutRef[i] ); \
111 REAL4 err2 = fabsf ( xOut2[i] - xOutRef2[i] ); \
112 REAL4 relerr1 = Relerr ( err1, xOutRef[i] ); \
113 REAL4 relerr2 = Relerr ( err2, xOutRef2[i] ); \
114 maxErr = fmaxf ( err1, maxErr ); \
115 maxErr = fmaxf ( err2, maxErr ); \
116 maxRelerr = fmaxf ( relerr1, maxRelerr ); \
117 maxRelerr = fmaxf ( relerr2, maxRelerr ); \
118 } \
119 XLALPrintInfo ( "%-32s: %4.0f Mops/sec [maxErr = %7.2g (tol=%7.2g), maxRelerr = %7.2g (tol=%7.2g)]\n", \
120 XLALVector##name##REAL4_name, (REAL8)Ntrials * Nruns / (toc - tic)/1e6, maxErr, (abstol), maxRelerr, reltol ); \
121 XLAL_CHECK ( (maxErr <= (abstol)), XLAL_ETOL, "%s: absolute error (%g) exceeds tolerance (%g)\n", #name "REAL4", maxErr, abstol ); \
122 XLAL_CHECK ( (maxRelerr <= (reltol)), XLAL_ETOL, "%s: relative error (%g) exceeds tolerance (%g)\n", #name "REAL4", maxRelerr, reltol ); \
123 }
124
125// ----- test and benchmark operators with 2 REAL4 vector inputs to 1 REAL4 vector output (SS2S) ----------
126#define TESTBENCH_VECTORMATH_SS2S(name,in1,in2) \
127 { \
128 XLAL_CHECK ( XLALVector##name##REAL4_GEN( xOutRef, in1, in2, Ntrials ) == XLAL_SUCCESS, XLAL_EFUNC ); \
129 tic = XLALGetCPUTime(); \
130 for (UINT4 l=0; l < Nruns; l ++ ) { \
131 XLAL_CHECK ( XLALVector##name##REAL4( xOut, in1, in2, Ntrials ) == XLAL_SUCCESS, XLAL_EFUNC ); \
132 } \
133 toc = XLALGetCPUTime(); \
134 maxErr = maxRelerr = 0; \
135 for ( UINT4 i = 0; i < Ntrials; i ++ ) \
136 { \
137 REAL4 err = fabsf ( xOut[i] - xOutRef[i] ); \
138 REAL4 relerr = Relerr ( err, xOutRef[i] ); \
139 maxErr = fmaxf ( err, maxErr ); \
140 maxRelerr = fmaxf ( relerr, maxRelerr ); \
141 } \
142 XLALPrintInfo ( "%-32s: %4.0f Mops/sec [maxErr = %7.2g (tol=%7.2g), maxRelerr = %7.2g (tol=%7.2g)]\n", \
143 XLALVector##name##REAL4_name, (REAL8)Ntrials * Nruns / (toc - tic)/1e6, maxErr, (abstol), maxRelerr, (reltol) ); \
144 XLAL_CHECK ( (maxErr <= (abstol)), XLAL_ETOL, "%s: absolute error (%g) exceeds tolerance (%g)\n", #name "REAL4", maxErr, abstol ); \
145 XLAL_CHECK ( (maxRelerr <= (reltol)), XLAL_ETOL, "%s: relative error (%g) exceeds tolerance (%g)\n", #name "REAL4", maxRelerr, reltol ); \
146 }
147
148// ----- test and benchmark operators with 3 REAL4 vector inputs to 1 REAL4 vector output (SS2S) ----------
149#define TESTBENCH_VECTORMATH_SSS2S(name,in1,in2,in3) \
150 { \
151 XLAL_CHECK ( XLALVector##name##REAL4_GEN( xOutRef, in1, in2, in3, Ntrials ) == XLAL_SUCCESS, XLAL_EFUNC ); \
152 tic = XLALGetCPUTime(); \
153 for (UINT4 l=0; l < Nruns; l ++ ) { \
154 XLAL_CHECK ( XLALVector##name##REAL4( xOut, in1, in2, in3, Ntrials ) == XLAL_SUCCESS, XLAL_EFUNC ); \
155 } \
156 toc = XLALGetCPUTime(); \
157 maxErr = maxRelerr = 0; \
158 for ( UINT4 i = 0; i < Ntrials; i ++ ) \
159 { \
160 REAL4 err = fabsf ( xOut[i] - xOutRef[i] ); \
161 REAL4 relerr = Relerr ( err, xOutRef[i] ); \
162 maxErr = fmaxf ( err, maxErr ); \
163 maxRelerr = fmaxf ( relerr, maxRelerr ); \
164 } \
165 XLALPrintInfo ( "%-32s: %4.0f Mops/sec [maxErr = %7.2g (tol=%7.2g), maxRelerr = %7.2g (tol=%7.2g)]\n", \
166 XLALVector##name##REAL4_name, (REAL8)Ntrials * Nruns / (toc - tic)/1e6, maxErr, (abstol), maxRelerr, (reltol) ); \
167 XLAL_CHECK ( (maxErr <= (abstol)), XLAL_ETOL, "%s: absolute error (%g) exceeds tolerance (%g)\n", #name "REAL4", maxErr, abstol ); \
168 XLAL_CHECK ( (maxRelerr <= (reltol)), XLAL_ETOL, "%s: relative error (%g) exceeds tolerance (%g)\n", #name "REAL4", maxRelerr, reltol ); \
169 }
170
171// ----- test and benchmark operators with 2 REAL4 vector inputs to 1 UINT4 scalar and 1 UINT4 vector output (SS2uU) ----------
172#define TESTBENCH_VECTORMATH_SS2uU(name,in1,in2) \
173 { \
174 UINT4 xCount = 0, xCountRef = 0; \
175 XLAL_CHECK ( XLALVector##name##REAL4_GEN( &xCountRef, xOutRefU4->data, in1, in2, Ntrials ) == XLAL_SUCCESS, XLAL_EFUNC ); \
176 tic = XLALGetCPUTime(); \
177 for (UINT4 l=0; l < Nruns; l ++ ) { \
178 XLAL_CHECK ( XLALVector##name##REAL4( &xCount, xOutU4->data, in1, in2, Ntrials ) == XLAL_SUCCESS, XLAL_EFUNC ); \
179 XLAL_CHECK ( xCount == xCountRef, XLAL_ETOL, "%s: count of found elements (%u) differs from reference (%u)", #name, xCount, xCountRef ); \
180 } \
181 toc = XLALGetCPUTime(); \
182 for ( UINT4 i = 0; i < xCount; i ++ ) \
183 { \
184 XLAL_CHECK ( xOutU4->data[i] == xOutRefU4->data[i], XLAL_ETOL, "%s: found element #%u (%u) differs from reference (%u)", #name, i, xOutU4->data[i], xOutRefU4->data[i] ); \
185 } \
186 XLALPrintInfo ( "%-32s: %4.0f Mops/sec\n", XLALVector##name##REAL4_name, (REAL8)Ntrials * Nruns / (toc - tic)/1e6 ); \
187 }
188
189// ----- test and benchmark operators with 1 REAL8 vector input and 1 REAL8 scalar output (D2d) ----------
190#define TESTBENCH_VECTORMATH_D2d(name,in) \
191 { \
192 REAL8 sOutRef, sOut; \
193 XLAL_CHECK ( XLALVector##name##REAL8_GEN( &sOutRef, in, Ntrials ) == XLAL_SUCCESS, XLAL_EFUNC ); \
194 tic = XLALGetCPUTime(); \
195 for (UINT4 l=0; l < Nruns; l ++ ) { \
196 XLAL_CHECK ( XLALVector##name##REAL8( &sOut, in, Ntrials ) == XLAL_SUCCESS, XLAL_EFUNC ); \
197 } \
198 toc = XLALGetCPUTime(); \
199 maxErr = fabs( sOut - sOutRef ); \
200 maxRelerr = Relerrd( maxErr, sOutRef ); \
201 XLALPrintInfo ( "%-32s: %4.0f Mops/sec [maxErr = %7.2g (tol=%7.2g), maxRelerr = %7.2g (tol=%7.2g)]\n", \
202 XLALVector##name##REAL8_name, (REAL8)Ntrials * Nruns / (toc - tic)/1e6, maxErr, (abstol), maxRelerr, (reltol) ); \
203 XLAL_CHECK ( (maxErr <= (abstol)), XLAL_ETOL, "%s: absolute error (%g) exceeds tolerance (%g)\n", #name "REAL8", maxErr, abstol ); \
204 XLAL_CHECK ( (maxRelerr <= (reltol)), XLAL_ETOL, "%s: relative error (%g) exceeds tolerance (%g)\n", #name "REAL8", maxRelerr, reltol ); \
205 }
206
207// ----- test and benchmark operators with 2 REAL8 vector inputs to 1 REAL8 vector output (DD2D) ----------
208#define TESTBENCH_VECTORMATH_DD2D(name,in1,in2) \
209 { \
210 XLAL_CHECK ( XLALVector##name##REAL8_GEN( xOutRefD, in1, in2, Ntrials ) == XLAL_SUCCESS, XLAL_EFUNC ); \
211 tic = XLALGetCPUTime(); \
212 for (UINT4 l=0; l < Nruns; l ++ ) { \
213 XLAL_CHECK ( XLALVector##name##REAL8( xOutD, in1, in2, Ntrials ) == XLAL_SUCCESS, XLAL_EFUNC ); \
214 } \
215 toc = XLALGetCPUTime(); \
216 maxErr = maxRelerr = 0; \
217 for ( UINT4 i = 0; i < Ntrials; i ++ ) \
218 { \
219 REAL8 err = fabs ( xOutD[i] - xOutRefD[i] ); \
220 REAL8 relerr = Relerrd ( err, xOutRefD[i] ); \
221 maxErr = fmax ( err, maxErr ); \
222 maxRelerr = fmax ( relerr, maxRelerr ); \
223 } \
224 XLALPrintInfo ( "%-32s: %4.0f Mops/sec [maxErr = %7.2g (tol=%7.2g), maxRelerr = %7.2g (tol=%7.2g)]\n", \
225 XLALVector##name##REAL8_name, (REAL8)Ntrials * Nruns / (toc - tic)/1e6, maxErr, (abstol), maxRelerr, (reltol) ); \
226 XLAL_CHECK ( (maxErr <= (abstol)), XLAL_ETOL, "%s: absolute error (%g) exceeds tolerance (%g)\n", #name "REAL8", maxErr, abstol ); \
227 XLAL_CHECK ( (maxRelerr <= (reltol)), XLAL_ETOL, "%s: relative error (%g) exceeds tolerance (%g)\n", #name "REAL8", maxRelerr, reltol ); \
228 }
229
230// ----- test and benchmark operators with 3 REAL8 vector inputs to 1 REAL8 vector output (DD2D) ----------
231#define TESTBENCH_VECTORMATH_DDD2D(name,in1,in2,in3) \
232 { \
233 XLAL_CHECK ( XLALVector##name##REAL8_GEN( xOutRefD, in1, in2, in3, Ntrials ) == XLAL_SUCCESS, XLAL_EFUNC ); \
234 tic = XLALGetCPUTime(); \
235 for (UINT4 l=0; l < Nruns; l ++ ) { \
236 XLAL_CHECK ( XLALVector##name##REAL8( xOutD, in1, in2, in3, Ntrials ) == XLAL_SUCCESS, XLAL_EFUNC ); \
237 } \
238 toc = XLALGetCPUTime(); \
239 maxErr = maxRelerr = 0; \
240 for ( UINT4 i = 0; i < Ntrials; i ++ ) \
241 { \
242 REAL8 err = fabs ( xOutD[i] - xOutRefD[i] ); \
243 REAL8 relerr = Relerrd ( err, xOutRefD[i] ); \
244 maxErr = fmax ( err, maxErr ); \
245 maxRelerr = fmax ( relerr, maxRelerr ); \
246 } \
247 XLALPrintInfo ( "%-32s: %4.0f Mops/sec [maxErr = %7.2g (tol=%7.2g), maxRelerr = %7.2g (tol=%7.2g)]\n", \
248 XLALVector##name##REAL8_name, (REAL8)Ntrials * Nruns / (toc - tic)/1e6, maxErr, (abstol), maxRelerr, (reltol) ); \
249 XLAL_CHECK ( (maxErr <= (abstol)), XLAL_ETOL, "%s: absolute error (%g) exceeds tolerance (%g)\n", #name "REAL8", maxErr, abstol ); \
250 XLAL_CHECK ( (maxRelerr <= (reltol)), XLAL_ETOL, "%s: relative error (%g) exceeds tolerance (%g)\n", #name "REAL8", maxRelerr, reltol ); \
251 }
252
253// ----- test and benchmark operators with 2 COMPLEX8 vector inputs to 1 COMPLEX8 vector output (CC2C) ----------
254#define TESTBENCH_VECTORMATH_CC2C(name,in1,in2) \
255 { \
256 XLAL_CHECK ( XLALVector##name##COMPLEX8_GEN( xOutRefC, in1, in2, Ntrials ) == XLAL_SUCCESS, XLAL_EFUNC ); \
257 tic = XLALGetCPUTime(); \
258 for (UINT4 l=0; l < Nruns; l ++ ) { \
259 XLAL_CHECK ( XLALVector##name##COMPLEX8( xOutC, in1, in2, Ntrials ) == XLAL_SUCCESS, XLAL_EFUNC ); \
260 } \
261 toc = XLALGetCPUTime(); \
262 maxErr = maxRelerr = 0; \
263 for ( UINT4 i = 0; i < Ntrials; i ++ ) \
264 { \
265 REAL4 err = cabsf ( xOutC[i] - xOutRefC[i] ); \
266 REAL4 relerr = cRelerr ( err, xOutRefC[i] ); \
267 maxErr = fmaxf ( err, maxErr ); \
268 maxRelerr = fmaxf ( relerr, maxRelerr ); \
269 } \
270 XLALPrintInfo ( "%-32s: %4.0f Mops/sec [maxErr = %7.2g (tol=%7.2g), maxRelerr = %7.2g (tol=%7.2g)]\n", \
271 XLALVector##name##COMPLEX8_name, (REAL8)Ntrials * Nruns / (toc - tic)/1e6, maxErr, (abstol), maxRelerr, (reltol) ); \
272 XLAL_CHECK ( (maxErr <= (abstol)), XLAL_ETOL, "%s: absolute error (%g) exceeds tolerance (%g)\n", #name "COMPLEX8", maxErr, abstol ); \
273 XLAL_CHECK ( (maxRelerr <= (reltol)), XLAL_ETOL, "%s: relative error (%g) exceeds tolerance (%g)\n", #name "COMPLEX8", maxRelerr, reltol ); \
274 }
275
276// ----- test and benchmark operators with 3 COMPLEX8 vector inputs to 1 COMPLEX8 vector output (CC2C) ----------
277#define TESTBENCH_VECTORMATH_CCC2C(name,in1,in2,in3) \
278 { \
279 XLAL_CHECK ( XLALVector##name##COMPLEX8_GEN( xOutRefC, in1, in2, in3, Ntrials ) == XLAL_SUCCESS, XLAL_EFUNC ); \
280 tic = XLALGetCPUTime(); \
281 for (UINT4 l=0; l < Nruns; l ++ ) { \
282 XLAL_CHECK ( XLALVector##name##COMPLEX8( xOutC, in1, in2, in3, Ntrials ) == XLAL_SUCCESS, XLAL_EFUNC ); \
283 } \
284 toc = XLALGetCPUTime(); \
285 maxErr = maxRelerr = 0; \
286 for ( UINT4 i = 0; i < Ntrials; i ++ ) \
287 { \
288 REAL4 err = cabsf ( xOutC[i] - xOutRefC[i] ); \
289 REAL4 relerr = cRelerr ( err, xOutRefC[i] ); \
290 maxErr = fmaxf ( err, maxErr ); \
291 maxRelerr = fmaxf ( relerr, maxRelerr ); \
292 } \
293 XLALPrintInfo ( "%-32s: %4.0f Mops/sec [maxErr = %7.2g (tol=%7.2g), maxRelerr = %7.2g (tol=%7.2g)]\n", \
294 XLALVector##name##COMPLEX8_name, (REAL8)Ntrials * Nruns / (toc - tic)/1e6, maxErr, (abstol), maxRelerr, (reltol) ); \
295 XLAL_CHECK ( (maxErr <= (abstol)), XLAL_ETOL, "%s: absolute error (%g) exceeds tolerance (%g)\n", #name "COMPLEX8", maxErr, abstol ); \
296 XLAL_CHECK ( (maxRelerr <= (reltol)), XLAL_ETOL, "%s: relative error (%g) exceeds tolerance (%g)\n", #name "COMPLEX8", maxRelerr, reltol ); \
297 }
298
299// ----- test and benchmark operators with 1 REAL8 vector input and 1 REAL8 vector output (D2D) ----------
300#define TESTBENCH_VECTORMATH_D2D(name,in) \
301 { \
302 XLAL_CHECK ( XLALVector##name##REAL8_GEN( xOutRefD, in, Ntrials ) == XLAL_SUCCESS, XLAL_EFUNC ); \
303 tic = XLALGetCPUTime(); \
304 for (UINT4 l=0; l < Nruns; l ++ ) { \
305 XLAL_CHECK ( XLALVector##name##REAL8( xOutD, in, Ntrials ) == XLAL_SUCCESS, XLAL_EFUNC ); \
306 } \
307 toc = XLALGetCPUTime(); \
308 maxErr = maxRelerr = 0; \
309 for ( UINT4 i = 0; i < Ntrials; i ++ ) \
310 { \
311 REAL8 err = fabs ( xOut[i] - xOutRef[i] ); \
312 REAL8 relerr = Relerrd ( err, xOutRef[i] ); \
313 maxErr = fmax ( err, maxErr ); \
314 maxRelerr = fmax ( relerr, maxRelerr ); \
315 } \
316 XLALPrintInfo ( "%-32s: %4.0f Mops/sec [maxErr = %7.2g (tol=%7.2g), maxRelerr = %7.2g (tol=%7.2g)]\n", \
317 XLALVector##name##REAL8_name, (REAL8)Ntrials * Nruns / (toc - tic)/1e6, maxErr, (abstol), maxRelerr, (reltol) ); \
318 XLAL_CHECK ( (maxErr <= (abstol)), XLAL_ETOL, "%s: absolute error (%g) exceeds tolerance (%g)\n", #name "REAL8", maxErr, abstol ); \
319 XLAL_CHECK ( (maxRelerr <= (reltol)), XLAL_ETOL, "%s: relative error (%g) exceeds tolerance (%g)\n", #name "REAL8", maxRelerr, reltol ); \
320 }
321
322// local types
323typedef struct
324{
325 INT4 randSeed; /**< allow user to specify random-number seed for reproducible noise-realizations */
326 INT4 Nruns; // number of repated timing 'runs' to average over in order to improve variance of result
327 INT4 inAlign; // alignment of input vectors; default is sizeof(void*), i.e. no particular alignment
328 INT4 outAlign; // alignment of output vectors; default is sizeof(void*), i.e. no particular alignment
330
331
332// ---------- main ----------
333int
334main ( int argc, char *argv[] )
335{
337 UserInput_t *uvar = &uvar_s;
338
339 uvar->randSeed = 1;
340 uvar->Nruns = 1;
341 uvar->inAlign = uvar->outAlign = sizeof(void*);
342 // ---------- register user-variable ----------
343 XLALRegisterUvarMember( randSeed, INT4, 's', OPTIONAL, "Random-number seed");
344 XLALRegisterUvarMember( Nruns, INT4, 'r', OPTIONAL, "Number of repeated timing 'runs' to average over (=improves variance)" );
345 XLALRegisterUvarMember( inAlign, INT4, 'a', OPTIONAL, "Alignment of input vectors; default is sizeof(void*), i.e. no particular alignment" );
346 XLALRegisterUvarMember( outAlign, INT4, 'b', OPTIONAL, "Alignment of output vectors; default is sizeof(void*), i.e. no particular alignment" );
347
348 BOOLEAN should_exit = 0;
349 XLAL_CHECK( XLALUserVarReadAllInput( &should_exit, argc, argv, lalVCSInfoList ) == XLAL_SUCCESS, XLAL_EFUNC );
350 if ( should_exit ) {
351 exit (1);
352 }
353
354 srand ( uvar->randSeed );
355 XLAL_CHECK ( uvar->Nruns >= 1, XLAL_EDOM );
356 UINT4 Nruns = (UINT4)uvar->Nruns;
357
358 UINT4 Ntrials = 1000000 + 7;
359
360 INT4Vector *xOutI4;
361 INT4Vector *xOutRefI4;
362 XLAL_CHECK ( ( xOutI4 = XLALCreateINT4Vector ( Ntrials )) != NULL, XLAL_EFUNC );
363 XLAL_CHECK ( ( xOutRefI4 = XLALCreateINT4Vector ( Ntrials )) != NULL, XLAL_EFUNC );
364
365 UINT4Vector *xOutU4;
366 UINT4Vector *xOutRefU4;
367 XLAL_CHECK ( ( xOutU4 = XLALCreateUINT4Vector ( Ntrials )) != NULL, XLAL_EFUNC );
368 XLAL_CHECK ( ( xOutRefU4 = XLALCreateUINT4Vector ( Ntrials )) != NULL, XLAL_EFUNC );
369
370 REAL4VectorAligned *xIn_a, *xIn2_a, *xOut_a, *xOut2_a;
371 XLAL_CHECK ( ( xIn_a = XLALCreateREAL4VectorAligned ( Ntrials, uvar->inAlign )) != NULL, XLAL_EFUNC );
372 XLAL_CHECK ( ( xIn2_a = XLALCreateREAL4VectorAligned ( Ntrials, uvar->inAlign )) != NULL, XLAL_EFUNC );
373 XLAL_CHECK ( ( xOut_a = XLALCreateREAL4VectorAligned ( Ntrials, uvar->outAlign )) != NULL, XLAL_EFUNC );
374 XLAL_CHECK ( ( xOut2_a = XLALCreateREAL4VectorAligned ( Ntrials, uvar->outAlign )) != NULL, XLAL_EFUNC );
375 REAL4VectorAligned *xOutRef_a, *xOutRef2_a;
376 XLAL_CHECK ( (xOutRef_a = XLALCreateREAL4VectorAligned ( Ntrials, uvar->outAlign )) != NULL, XLAL_EFUNC );
377 XLAL_CHECK ( (xOutRef2_a = XLALCreateREAL4VectorAligned ( Ntrials, uvar->outAlign )) != NULL, XLAL_EFUNC );
378
379 // extract aligned REAL4 vectors from these
380 REAL4 *xIn = xIn_a->data;
381 REAL4 *xIn2 = xIn2_a->data;
382 REAL4 *xOut = xOut_a->data;
383 REAL4 *xOut2 = xOut2_a->data;
384 REAL4 *xOutRef = xOutRef_a->data;
385 REAL4 *xOutRef2 = xOutRef2_a->data;
386
387 REAL8VectorAligned *xInD_a, *xIn2D_a, *xOutD_a, *xOutRefD_a;
388 XLAL_CHECK ( ( xInD_a = XLALCreateREAL8VectorAligned ( Ntrials, uvar->inAlign )) != NULL, XLAL_EFUNC );
389 XLAL_CHECK ( ( xIn2D_a = XLALCreateREAL8VectorAligned ( Ntrials, uvar->inAlign )) != NULL, XLAL_EFUNC );
390 XLAL_CHECK ( ( xOutD_a = XLALCreateREAL8VectorAligned ( Ntrials, uvar->outAlign )) != NULL, XLAL_EFUNC );
391 XLAL_CHECK ( (xOutRefD_a= XLALCreateREAL8VectorAligned ( Ntrials, uvar->outAlign )) != NULL, XLAL_EFUNC );
392
393 // extract aligned REAL8 vectors from these
394 REAL8 *xInD = xInD_a->data;
395 REAL8 *xIn2D = xIn2D_a->data;
396 REAL8 *xOutD = xOutD_a->data;
397 REAL8 *xOutRefD = xOutRefD_a->data;
398
399 COMPLEX8VectorAligned *xInC_a, *xIn2C_a, *xOutC_a, *xOutRefC_a;
400 XLAL_CHECK ( ( xInC_a = XLALCreateCOMPLEX8VectorAligned ( Ntrials, uvar->inAlign )) != NULL, XLAL_EFUNC );
401 XLAL_CHECK ( ( xIn2C_a = XLALCreateCOMPLEX8VectorAligned ( Ntrials, uvar->inAlign )) != NULL, XLAL_EFUNC );
402 XLAL_CHECK ( ( xOutC_a = XLALCreateCOMPLEX8VectorAligned ( Ntrials, uvar->outAlign )) != NULL, XLAL_EFUNC );
403 XLAL_CHECK ( (xOutRefC_a = XLALCreateCOMPLEX8VectorAligned ( Ntrials, uvar->outAlign )) != NULL, XLAL_EFUNC );
404
405 // extract aligned COMPLEX8 vectors from these
406 COMPLEX8 *xInC = xInC_a->data;
407 COMPLEX8 *xIn2C = xIn2C_a->data;
408 COMPLEX8 *xOutC = xOutC_a->data;
409 COMPLEX8 *xOutRefC = xOutRefC_a->data;
410
411 REAL8 tic, toc;
412 REAL4 maxErr = 0, maxRelerr = 0;
413 REAL4 abstol, reltol;
414
415 for ( UINT4 i = 0; i < Ntrials; i ++ ) {
416 xIn[i] = 2000 * ( frand() - 0.5 );
417 xInD[i] = xIn[i];
418 }
419 abstol = 2e-7, reltol = 1e-5;
420
421 XLALPrintInfo ("Testing (INT4) for x in [-1000, 1000]\n");
422 // ==================== (INT4) ====================
423 TESTBENCH_VECTORMATH_S2I(INT4From,xIn);
424
425 // ==================== SCALAR MAX ====================
426 XLALPrintInfo ("Testing scalar max for x in [-1000, 1000]\n");
427 TESTBENCH_VECTORMATH_S2s(ScalarMax,xIn);
428 TESTBENCH_VECTORMATH_D2d(ScalarMax,xInD);
429
430 XLALPrintInfo ("Testing sin(x), cos(x) for x in [-1000, 1000]\n");
431 // ==================== SIN() ====================
433
434 // ==================== COS() ====================
436
437 // ==================== SINCOS() ====================
438 TESTBENCH_VECTORMATH_S2SS(SinCos,xIn);
439
440 // ==================== SINCOS(2PI*x) ====================
441 TESTBENCH_VECTORMATH_S2SS(SinCos2Pi,xIn);
442
443 // ==================== EXP() ====================
444 XLALPrintInfo ("\nTesting exp(x) for x in [-10, 10]\n");
445 for ( UINT4 i = 0; i < Ntrials; i ++ ) {
446 xIn[i] = 20 * ( frand() - 0.5 );
447 }
448
449 abstol = 4e-3, reltol = 3e-7;
451
452 // ==================== LOG() ====================
453 XLALPrintInfo ("\nTesting log(x) for x in (0, 10000]\n");
454 for ( UINT4 i = 0; i < Ntrials; i ++ ) {
455 xIn[i] = 10000.0f * frand() + 1e-6;
456 } // for i < Ntrials
457 abstol = 2e-6, reltol = 4e-7;
458
460
461 // ==================== ADD,MUL,ROUND ====================
462 for ( UINT4 i = 0; i < Ntrials; i ++ ) {
463 xIn[i] = -10000.0f + 20000.0f * frand() + 1e-6;
464 xIn2[i] = -10000.0f + 20000.0f * frand() + 1e-6;
465 xInD[i] = -100000.0 + 200000.0 * frand() + 1e-6;
466 xIn2D[i]= -100000.0 + 200000.0 * frand() + 1e-6;
467 xInC[i] = -10000.0f + 20000.0f * frand() + 1e-6 + ( -10000.0f + 20000.0f * frand() + 1e-6 ) * _Complex_I;
468 xIn2C[i]= -10000.0f + 20000.0f * frand() + 1e-6 + ( -10000.0f + 20000.0f * frand() + 1e-6 ) * _Complex_I;
469 } // for i < Ntrials
470 abstol = 2e-7, reltol = 2e-7;
471
472 XLALPrintInfo ("\nTesting round(x) for x in (-10000, 10000]\n");
473 TESTBENCH_VECTORMATH_S2S(Round,xIn);
474 TESTBENCH_VECTORMATH_D2D(Round,xInD);
475
476 XLALPrintInfo ("\nTesting add,multiply,shift,scale(x,y) for x,y in (-10000, 10000]\n");
477 TESTBENCH_VECTORMATH_SS2S(Add,xIn,xIn2);
478 TESTBENCH_VECTORMATH_SS2S(Sub,xIn,xIn2);
479 TESTBENCH_VECTORMATH_SS2S(Multiply,xIn,xIn2);
480 TESTBENCH_VECTORMATH_SS2S(Max,xIn,xIn2);
481
482 TESTBENCH_VECTORMATH_SS2S(Shift,xIn[0],xIn2);
483 TESTBENCH_VECTORMATH_SS2S(Scale,xIn[0],xIn2);
484 TESTBENCH_VECTORMATH_SSS2S(ScaleAdd,xIn[0],xIn,xIn2);
485
486 TESTBENCH_VECTORMATH_DD2D(Add,xInD,xIn2D);
487 TESTBENCH_VECTORMATH_DD2D(Sub,xInD,xIn2D);
488 TESTBENCH_VECTORMATH_DD2D(Multiply,xInD,xIn2D);
489 TESTBENCH_VECTORMATH_DD2D(Max,xInD,xIn2D);
490
491 TESTBENCH_VECTORMATH_DD2D(Shift,xInD[0],xIn2D);
492 TESTBENCH_VECTORMATH_DD2D(Scale,xInD[0],xIn2D);
493 TESTBENCH_VECTORMATH_DDD2D(ScaleAdd,xInD[0],xInD,xIn2D);
494
495 TESTBENCH_VECTORMATH_CC2C(Multiply,xInC,xIn2C);
496 TESTBENCH_VECTORMATH_CC2C(Add,xInC,xIn2C);
497
498 TESTBENCH_VECTORMATH_CC2C(Scale,xInC[0],xIn2C);
499 TESTBENCH_VECTORMATH_CC2C(Shift,xInC[0],xIn2C);
500 TESTBENCH_VECTORMATH_CCC2C(ScaleAdd,xIn[0],xInC,xIn2C);
501
502 // ==================== FIND ====================
503 for ( UINT4 i = 0; i < Ntrials; i ++ ) {
504 xIn[i] = -10000.0f + 20000.0f * frand() + 1e-6;
505 xIn2[i] = -10000.0f + 20000.0f * frand() + 1e-6;
506 } // for i < Ntrials
507
508 XLALPrintInfo ("\nTesting find for x,y in (-10000, 10000]\n");
509 TESTBENCH_VECTORMATH_SS2uU(FindVectorLessEqual,xIn,xIn2);
510
511 TESTBENCH_VECTORMATH_SS2uU(FindScalarLessEqual,xIn[0],xIn2);
512
513 XLALPrintInfo ("\n");
514
515 // ---------- clean up memory ----------
516 XLALDestroyINT4Vector ( xOutI4 );
517 XLALDestroyINT4Vector ( xOutRefI4 );
518
519 XLALDestroyUINT4Vector ( xOutU4 );
520 XLALDestroyUINT4Vector ( xOutRefU4 );
521
526
527 XLALDestroyREAL4VectorAligned ( xOutRef_a );
528 XLALDestroyREAL4VectorAligned ( xOutRef2_a );
529
533 XLALDestroyREAL8VectorAligned ( xOutRefD_a );
534
539
541
543
544 return XLAL_SUCCESS;
545
546} // main()
void LALCheckMemoryLeaks(void)
Definition: LALMalloc.c:784
const LALVCSInfoList lalVCSInfoList
NULL-terminated list of VCS and build information for LAL and its dependencies
int main(int argc, char *argv[])
#define TESTBENCH_VECTORMATH_CCC2C(name, in1, in2, in3)
#define TESTBENCH_VECTORMATH_D2D(name, in)
#define TESTBENCH_VECTORMATH_S2s(name, in)
#define TESTBENCH_VECTORMATH_SS2uU(name, in1, in2)
#define TESTBENCH_VECTORMATH_S2S(name, in)
#define TESTBENCH_VECTORMATH_S2I(name, in)
#define TESTBENCH_VECTORMATH_DD2D(name, in1, in2)
#define TESTBENCH_VECTORMATH_SSS2S(name, in1, in2, in3)
#define TESTBENCH_VECTORMATH_S2SS(name, in)
#define TESTBENCH_VECTORMATH_D2d(name, in)
#define TESTBENCH_VECTORMATH_SS2S(name, in1, in2)
#define TESTBENCH_VECTORMATH_DDD2D(name, in1, in2, in3)
#define TESTBENCH_VECTORMATH_CC2C(name, in1, in2)
#define frand()
int XLALPrintInfo(const char *fmt,...)
Definition: XLALError.c:90
unsigned char BOOLEAN
Boolean logical type, see Headers LAL(Atomic)Datatypes.h for more details.
double REAL8
Double precision real floating-point number (8 bytes).
#define XLAL_INIT_DECL(var,...)
C99 MACRO to declare and zero-initialize a variable, use as "type XLAL_INIT_DECL(var);".
uint32_t UINT4
Four-byte unsigned integer.
float complex COMPLEX8
Single-precision floating-point complex number (8 bytes total)
int32_t INT4
Four-byte signed integer.
float REAL4
Single precision real floating-point number (4 bytes).
int XLALUserVarReadAllInput(BOOLEAN *should_exit, int argc, char *argv[], const LALVCSInfoList vcs_list)
Put all the pieces together, and basically does everything: print help (if requested),...
Definition: UserInput.c:1064
void XLALDestroyUserVars(void)
Free all memory associated with user-variable linked list.
Definition: UserInput.c:349
#define XLALRegisterUvarMember(name, type, option, category,...)
Shortcut macro for registering new user variables, which are accessed via the struct-pointer '*uvar'.
Definition: UserInput.h:157
void XLALDestroyUINT4Vector(UINT4Vector *vector)
INT4Vector * XLALCreateINT4Vector(UINT4 length)
void XLALDestroyINT4Vector(INT4Vector *vector)
UINT4Vector * XLALCreateUINT4Vector(UINT4 length)
void XLALDestroyREAL4VectorAligned(REAL4VectorAligned *in)
Free a REAL4VectorAligned struct.
REAL8VectorAligned * XLALCreateREAL8VectorAligned(const UINT4 length, const UINT4 align)
Create a new REAL8VectorAligned struct with length length and alignment align.
void XLALDestroyREAL8VectorAligned(REAL8VectorAligned *in)
Free a REAL8VectorAligned struct.
REAL4VectorAligned * XLALCreateREAL4VectorAligned(const UINT4 length, const UINT4 align)
Create a new REAL4VectorAligned struct with length length and alignment align.
COMPLEX8VectorAligned * XLALCreateCOMPLEX8VectorAligned(const UINT4 length, const UINT4 align)
Create a new COMPLEX8VectorAligned struct with length length and alignment align.
void XLALDestroyCOMPLEX8VectorAligned(COMPLEX8VectorAligned *in)
Free a COMPLEX8VectorAligned struct.
#define XLAL_CHECK(assertion,...)
Macro to test an assertion and invoke a failure if it is not true in a function that returns an integ...
Definition: XLALError.h:810
@ XLAL_SUCCESS
Success return value (not an error number)
Definition: XLALError.h:401
@ XLAL_EFUNC
Internal function call failed bit: "or" this with existing error number.
Definition: XLALError.h:462
@ XLAL_EDOM
Input domain error.
Definition: XLALError.h:410
A special COMPLEX8Vector with n-byte aligned memory data array.
Definition: VectorMath.h:102
COMPLEX8 * data
start of aligned memory block
Definition: VectorMath.h:104
Vector of type INT4, see DATATYPE-Vector types for more details.
Definition: LALDatatypes.h:109
A special REAL4Vector with n-byte aligned memory data array.
Definition: VectorMath.h:70
REAL4 * data
start of aligned memory block
Definition: VectorMath.h:72
A special REAL8Vector with n-byte aligned memory data array.
Definition: VectorMath.h:86
REAL8 * data
start of aligned memory block
Definition: VectorMath.h:88
Vector of type UINT4, see DATATYPE-Vector types for more details.
Definition: LALDatatypes.h:118
INT4 randSeed
allow user to specify random-number seed for reproducible noise-realizations