From b33aacbf25c636f31d0485034b91cb61561e8bf6 Mon Sep 17 00:00:00 2001 From: Gonzalo Brito Gadeschi Date: Fri, 8 Mar 2024 13:15:32 -0800 Subject: [PATCH] Add option to silence errors --- src/main.cpp | 27 +++++++++++++++++++++++---- 1 file changed, 23 insertions(+), 4 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index f81fa94b..aa830895 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -5,6 +5,7 @@ // source code #include +#include #include #include #include @@ -29,6 +30,7 @@ unsigned int deviceIndex = 0; bool use_float = false; bool output_as_csv = false; Unit unit = MegaByte; +bool silence_errors = false; string csv_separator = ","; // Benchmarks: @@ -308,25 +310,37 @@ void check_solution(const unsigned int ntimes, vector& a, vector& b, vecto long double epsi = numeric_limits::epsilon() * 100.0; - if (errA > epsi) + bool failed = false; + if (errA > epsi) { + failed = true; cerr << "Validation failed on a[]. Average error " << errA << endl; - if (errB > epsi) + } + if (errB > epsi) { + failed = true; cerr << "Validation failed on b[]. Average error " << errB << endl; - if (errC > epsi) + } + if (errC > epsi) { + failed = true; cerr << "Validation failed on c[]. Average error " << errC << endl; + } // Check sum to 8 decimal places - if (selection == Benchmark::All && errSum > 1.0E-8) + if (selection == Benchmark::All && errSum > 1.0E-8) { + failed = true; cerr << "Validation failed on sum. Error " << errSum << endl << setprecision(15) << "Sum was " << sum << " but should be " << goldSum << endl; + } + + if (failed && !silence_errors) + exit(1); } @@ -446,6 +460,10 @@ void parseArguments(int argc, char *argv[]) { unit = Unit(GigaByte); } + else if (!string("--silence-errors").compare(argv[i])) + { + silence_errors = true; + } else if (!string("--help").compare(argv[i]) || !string("-h").compare(argv[i])) { @@ -465,6 +483,7 @@ void parseArguments(int argc, char *argv[]) cout << " --mibibytes Use MiB=2^20 for bandwidth calculation (default MB=10^6)" << endl; cout << " --gigibytes Use GiB=2^30 for bandwidth calculation (default MB=10^6)" << endl; cout << " --gigabytes Use GB=10^9 for bandwidth calculation (default MB=10^6)" << endl; + cout << " --silence-errors Ignores validation errors." << endl; cout << endl; exit(EXIT_SUCCESS); }