Skip to content

Commit bbea0e9

Browse files
committed
Add option to silence errors
1 parent cba455d commit bbea0e9

File tree

1 file changed

+23
-4
lines changed

1 file changed

+23
-4
lines changed

src/main.cpp

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
// source code
66

77
#include <algorithm>
8+
#include <array>
89
#include <chrono>
910
#include <cmath>
1011
#include <cstring>
@@ -29,6 +30,7 @@ unsigned int deviceIndex = 0;
2930
bool use_float = false;
3031
bool output_as_csv = false;
3132
Unit unit = MegaByte;
33+
bool silence_errors = false;
3234
string csv_separator = ",";
3335

3436
// Benchmarks:
@@ -308,25 +310,37 @@ void check_solution(const unsigned int ntimes, vector<T>& a, vector<T>& b, vecto
308310

309311
long double epsi = numeric_limits<T>::epsilon() * 100.0;
310312

311-
if (errA > epsi)
313+
bool failed = false;
314+
if (errA > epsi) {
315+
failed = true;
312316
cerr
313317
<< "Validation failed on a[]. Average error " << errA
314318
<< endl;
315-
if (errB > epsi)
319+
}
320+
if (errB > epsi) {
321+
failed =true;
316322
cerr
317323
<< "Validation failed on b[]. Average error " << errB
318324
<< endl;
319-
if (errC > epsi)
325+
}
326+
if (errC > epsi) {
327+
failed =true;
320328
cerr
321329
<< "Validation failed on c[]. Average error " << errC
322330
<< endl;
331+
}
323332
// Check sum to 8 decimal places
324-
if (selection == Benchmark::All && errSum > 1.0E-8)
333+
if (selection == Benchmark::All && errSum > 1.0E-8) {
334+
failed = true;
325335
cerr
326336
<< "Validation failed on sum. Error " << errSum
327337
<< endl << setprecision(15)
328338
<< "Sum was " << sum << " but should be " << goldSum
329339
<< endl;
340+
}
341+
342+
if (failed && !silence_errors)
343+
exit(1);
330344

331345
}
332346

@@ -446,6 +460,10 @@ void parseArguments(int argc, char *argv[])
446460
{
447461
unit = Unit(GigaByte);
448462
}
463+
else if (!string("--silence-errors").compare(argv[i]))
464+
{
465+
silence_errors = true;
466+
}
449467
else if (!string("--help").compare(argv[i]) ||
450468
!string("-h").compare(argv[i]))
451469
{
@@ -465,6 +483,7 @@ void parseArguments(int argc, char *argv[])
465483
cout << " --mibibytes Use MiB=2^20 for bandwidth calculation (default MB=10^6)" << endl;
466484
cout << " --gigibytes Use GiB=2^30 for bandwidth calculation (default MB=10^6)" << endl;
467485
cout << " --gigabytes Use GB=10^9 for bandwidth calculation (default MB=10^6)" << endl;
486+
cout << " --silence-errors Ignores validation errors." << endl;
468487
cout << endl;
469488
exit(EXIT_SUCCESS);
470489
}

0 commit comments

Comments
 (0)