source: CIVL/examples/openacc/nbody/check.c

main
Last change on this file was ea777aa, checked in by Alex Wilton <awilton@…>, 3 years ago

Moved examples, include, build_default.properties, common.xml, and README out from dev.civl.com into the root of the repo.

git-svn-id: svn://vsl.cis.udel.edu/civl/trunk@5704 fb995dde-84ed-4084-dfe6-e5aef3e2452c

  • Property mode set to 100644
File size: 7.1 KB
Line 
1/*
2 * Copyright (c) 2016, NVIDIA Corporation. All rights reserved.
3 *
4 * Please refer to the NVIDIA end user license agreement (EULA) associated
5 * with this source code for terms and conditions that govern your use of
6 * this software. Any use, reproduction, disclosure, or distribution of
7 * this software and related documentation outside the terms of the EULA
8 * is strictly prohibited.
9 *
10 */
11
12
13#include <stdio.h>
14#include <math.h>
15
16#ifdef __cplusplus
17extern "C" {
18#endif
19
20void
21check(int* res, int* exp, int n)
22{
23 int i;
24 int tests_passed = 0;
25 int tests_failed = 0;
26
27 for (i = 0; i < n; i++) {
28 if (exp[i] == res[i]) {
29 tests_passed ++;
30 } else {
31 tests_failed ++;
32 if( tests_failed < 50 )
33 printf(
34 "test number %d FAILED. res %d(%08x) exp %d(%08x)\n",
35 i+1,res[i], res[i], exp[i], exp[i] );
36 }
37 }
38 if (tests_failed == 0) {
39 printf("%3d tests completed. %d tests PASSED. %d tests failed.\n",
40 n, tests_passed, tests_failed);
41 } else {
42 printf("%3d tests completed. %d tests passed. %d tests FAILED.\n",
43 n, tests_passed, tests_failed);
44 }
45}
46
47void
48check_(int* res, int* exp, int* np)
49{
50 check(res, exp, *np);
51}
52
53void
54checkf(float* res, float* exp, int n)
55{
56 int i;
57 int tests_passed = 0;
58 int tests_failed = 0;
59
60 for (i = 0; i < n; i++) {
61 if (exp[i] == res[i]) {
62 tests_passed ++;
63 } else {
64 tests_failed ++;
65 if( tests_failed < 50 )
66 printf(
67 "test number %d FAILED. res %g exp %g\n",
68 i+1,res[i], exp[i]);
69 }
70 }
71 if (tests_failed == 0) {
72 printf("%3d tests completed. %d tests PASSED. %d tests failed.\n",
73 n, tests_passed, tests_failed);
74 } else {
75 printf("%3d tests completed. %d tests passed. %d tests FAILED.\n",
76 n, tests_passed, tests_failed);
77 }
78}
79
80void
81checkf_(float* res, float* exp, int* np)
82{
83 checkf(res, exp, *np);
84}
85
86void
87checkftol(float* res, float* exp, int n)
88{
89 int i;
90 int tests_passed = 0;
91 int tests_failed = 0;
92 float tol = 0.000001;
93
94 for (i = 0; i < n; i++) {
95 if (exp[i] == res[i]) {
96 tests_passed ++;
97 }else if( exp[i] != 0.0 && fabsf((exp[i]-res[i])/exp[i]) <= tol ){
98 tests_passed ++;
99 }else if( exp[i] == 0.0 && res[i] <= tol ){
100 tests_passed ++;
101 } else {
102 tests_failed ++;
103 if( tests_failed < 50 )
104 printf(
105 "test number %d FAILED. res %f exp %f\n",
106 i+1,res[i], exp[i]);
107 }
108 }
109 if (tests_failed == 0) {
110 printf("%3d tests completed. %d tests PASSED. %d tests failed.\n",
111 n, tests_passed, tests_failed);
112 } else {
113 printf("%3d tests completed. %d tests passed. %d tests FAILED.\n",
114 n, tests_passed, tests_failed);
115 }
116}
117
118void
119checkftol_(float* res, float* exp, int* np)
120{
121 checkftol(res, exp, *np);
122}
123
124void
125checkftol5(float* res, float* exp, int n)
126{
127 int i;
128 int tests_passed = 0;
129 int tests_failed = 0;
130 float tol = 0.00002;
131
132 for (i = 0; i < n; i++) {
133 if (exp[i] == res[i]) {
134 tests_passed ++;
135 }else if( exp[i] != 0.0 && fabsf((exp[i]-res[i])/exp[i]) <= tol ){
136 tests_passed ++;
137 }else if( exp[i] == 0.0 && res[i] <= tol ){
138 tests_passed ++;
139 } else {
140 tests_failed ++;
141 if( tests_failed < 50 )
142 printf(
143 "test number %d FAILED. res %f exp %f\n",
144 i+1,res[i], exp[i]);
145 }
146 }
147 if (tests_failed == 0) {
148 printf("%3d tests completed. %d tests PASSED. %d tests failed.\n",
149 n, tests_passed, tests_failed);
150 } else {
151 printf("%3d tests completed. %d tests passed. %d tests FAILED.\n",
152 n, tests_passed, tests_failed);
153 }
154}
155
156
157void
158checkll(long long *res, long long *exp, int n)
159{
160 int i;
161 int tests_passed = 0;
162 int tests_failed = 0;
163
164 for (i = 0; i < n; i++) {
165 if (exp[i] == res[i]) {
166 tests_passed ++;
167 } else {
168 tests_failed ++;
169 if( tests_failed < 50 )
170 printf( "test number %d FAILED. res %lld(%0llx) exp %lld(%0llx)\n",
171 i+1,res[i], res[i], exp[i], exp[i] );
172 }
173 }
174 if (tests_failed == 0) {
175 printf("%3d tests completed. %d tests PASSED. %d tests failed.\n",
176 n, tests_passed, tests_failed);
177 } else {
178 printf("%3d tests completed. %d tests passed. %d tests FAILED.\n",
179 n, tests_passed, tests_failed);
180 }
181}
182
183void
184checkll_(long long *res, long long *exp, int *np)
185{
186 checkll(res, exp, *np);
187}
188
189void
190checkd(double* res, double* exp, int n)
191{
192 int i;
193 int tests_passed = 0;
194 int tests_failed = 0;
195
196 for (i = 0; i < n; i++) {
197 if (exp[i] == res[i])
198 tests_passed ++;
199 else {
200 tests_failed ++;
201 if( tests_failed < 50 )
202 printf("test number %d FAILED. res %lg exp %lg\n",
203 i+1, res[i], exp[i] );
204 }
205 }
206 if (tests_failed == 0) {
207 printf("%3d tests completed. %d tests PASSED. %d tests failed.\n",
208 n, tests_passed, tests_failed);
209 } else {
210 printf("%3d tests completed. %d tests passed. %d tests FAILED.\n",
211 n, tests_passed, tests_failed);
212 }
213}
214
215void
216checkd_(double* res, double* exp, int* np)
217{
218 checkd(res, exp, *np);
219}
220
221void
222checkdtol(double* res, double* exp, int n)
223{
224 int i;
225 int tests_passed = 0;
226 int tests_failed = 0;
227 double tol = 0.00000000002;
228
229 for (i = 0; i < n; i++) {
230 if (exp[i] == res[i]){
231 tests_passed ++;
232 }else if( exp[i] != 0.0 && ((exp[i]-res[i])/exp[i]) <= tol ){
233 tests_passed ++;
234 }else if( exp[i] == 0.0 && res[i] <= tol ){
235 tests_passed ++;
236 }else{
237 tests_failed ++;
238 if( tests_failed < 50 )
239 printf(
240 "test number %d FAILED. res %lg exp %lg\n",
241 i+1,res[i], exp[i]);
242 }
243 }
244 if (tests_failed == 0) {
245 printf("%3d tests completed. %d tests PASSED. %d tests failed.\n",
246 n, tests_passed, tests_failed);
247 } else {
248 printf("%3d tests completed. %d tests passed. %d tests FAILED.\n",
249 n, tests_passed, tests_failed);
250 }
251}
252
253void
254checkdtol_(double* res, double* exp, int* np)
255{
256 checkdtol(res, exp, *np);
257}
258
259void
260fcpyf_(float *r, float f)
261{
262 *r = f;
263}
264
265void
266fcpyf(float *r, float f)
267{
268 fcpyf_(r, f);
269}
270
271void
272fcpyi_(int *r, int f)
273{
274 *r = f;
275}
276
277void
278fcpyi(int *r, int f)
279{
280 fcpyi_(r, f);
281}
282
283#if defined(WINNT) || defined(WIN32)
284void
285__stdcall CHECK(int* res, int* exp, int* np)
286{
287 check_(res, exp, np);
288}
289
290void
291__stdcall CHECKD( double* res, double* exp, int* np)
292{
293 checkd_(res, exp, np);
294}
295
296void
297__stdcall CHECKF( double* res, double* exp, int* np)
298{
299 checkf_(res, exp, np);
300}
301
302void
303__stdcall CHECKFTOL( double* res, double* exp, int* np)
304{
305 checkftol_(res, exp, np);
306}
307
308void
309__stdcall CHECKDTOL( double* res, double* exp, int* np)
310{
311 checkdtol_(res, exp, np);
312}
313
314void
315__stdcall CHECKLL(long long *res, long long *exp, int *np)
316{
317 checkll_(res, exp, np);
318}
319
320void
321__stdcall FCPYF(float *r, float f)
322{
323 fcpyf_(r, f);
324}
325
326void
327__stdcall FCPYI(int *r, int f)
328{
329 fcpyi_(r, f);
330}
331#endif
332#ifdef __cplusplus
333}
334#endif
335
Note: See TracBrowser for help on using the repository browser.