From 74ce83d0998b1b2e3986258af50108cc6ad25f36 Mon Sep 17 00:00:00 2001
From: Lukas Cejka <lukas.ostatek@gmail.com>
Date: Sun, 23 Jun 2019 18:08:10 +0200
Subject: [PATCH] Added exception handling for allocation on CPU

---
 src/Benchmarks/SpMV/spmv.h | 26 ++++++++++++++++++--------
 1 file changed, 18 insertions(+), 8 deletions(-)

diff --git a/src/Benchmarks/SpMV/spmv.h b/src/Benchmarks/SpMV/spmv.h
index e608416d87..5313a2d837 100644
--- a/src/Benchmarks/SpMV/spmv.h
+++ b/src/Benchmarks/SpMV/spmv.h
@@ -101,17 +101,22 @@ benchmarkSpMV( Benchmark & benchmark,
             // FIXME: Adds the message to the log file, HOWEVER, it does so with
             //  incorrect formatting: The "!" marks are not at the same line 
             //  as the message and sometimes they're omitted altogether.
-//            benchmark.addErrorMessage( "Failed to read matrix!", 1 );            
-            return false;
+//            benchmark.addErrorMessage( "Failed to read matrix!", 1 ); 
+             
+             // CORRECT? MatrixReader can fail for other reasons than Host Allocation issues, is this throw ok?
+             throw Exceptions::HostBadAlloc();
+             return false;
          }
       }
-      catch( std::bad_alloc )
+      // HOW? How does this work if the "if" statement above fails.
+      catch( Exceptions::HostBadAlloc e )
       {
          // FIXME: Adds the message to the log file, HOWEVER, it does so with
          //  incorrect formatting: The "!" marks are not at the same line 
          //  as the message and sometimes they're omitted altogether.
 //         benchmark.addErrorMessage( "Failed to allocate memory for matrix!", 1 );
-         return false;
+          e.what();
+          return false;
       }
     
     // cuSPARSE handle setup
@@ -149,17 +154,22 @@ benchmarkSpMV( Benchmark & benchmark,
             // FIXME: Adds the message to the log file, HOWEVER, it does so with
             //  incorrect formatting: The "!" marks are not at the same line 
             //  as the message and sometimes they're omitted altogether.
-//            benchmark.addErrorMessage( "Failed to read matrix!", 1 );            
-            return false;
+//            benchmark.addErrorMessage( "Failed to read matrix!", 1 );
+             
+             // CORRECT? MatrixReader can fail for other reasons than Host Allocation issues, is this throw ok?
+             throw Exceptions::HostBadAlloc();
+             return false;
          }
       }
-      catch( std::bad_alloc )
+      // HOW? How does this work if the "if" statement above fails.
+      catch( Exceptions::HostBadAlloc e )
       {
          // FIXME: Adds the message to the log file, HOWEVER, it does so with
          //  incorrect formatting: The "!" marks are not at the same line 
          //  as the message and sometimes they're omitted altogether.
 //         benchmark.addErrorMessage( "Failed to allocate memory for matrix!", 1 );
-         return false;
+          e.what();
+          return false;
       }
     
 #ifdef HAVE_CUDA
-- 
GitLab