]> https://gitweb.dealii.org/ - dealii.git/commitdiff
Fix a bug in a CUDA vector constructor 5825/head
authorBruno Turcksin <bruno.turcksin@gmail.com>
Mon, 29 Jan 2018 00:33:31 +0000 (19:33 -0500)
committerBruno Turcksin <bruno.turcksin@gmail.com>
Mon, 29 Jan 2018 00:59:21 +0000 (19:59 -0500)
The constructor did not set the values in the vector to zero

include/deal.II/lac/cuda_vector.h
source/lac/cuda_vector.cu

index aa407fff13f420aabaadc5ea85c3181b560aed9f..488138ccfbdc5d4fba7127e4270817b368212b56 100644 (file)
@@ -27,7 +27,6 @@
 DEAL_II_NAMESPACE_OPEN
 
 class CommunicationPatternBase;
-class IndexSet;
 template <typename Number> class ReadWriteVector;
 
 namespace LinearAlgebra
index 41501d896889d5f4486d284f7b43b13c0cde469b..36b2be442b29024a8d1409e1ae6da7270dd9e4a6 100644 (file)
@@ -503,11 +503,10 @@ namespace LinearAlgebra
     template <typename Number>
     Vector<Number>::Vector(const size_type n)
       :
-      n_elements(n)
+      val(nullptr),
+      n_elements(0)
     {
-      // Allocate the memory
-      cudaError_t error_code = cudaMalloc(&val, n_elements*sizeof(Number));
-      AssertCuda(error_code);
+      reinit(n, false);
     }
 
 
@@ -542,7 +541,7 @@ namespace LinearAlgebra
         }
       else
         {
-          if (n_elements != n)
+          if ((n_elements != n) && (val != nullptr))
             {
               cudaError_t error_code = cudaFree(val);
               AssertCuda(error_code);

In the beginning the Universe was created. This has made a lot of people very angry and has been widely regarded as a bad move.

Douglas Adams


Typeset in Trocchi and Trocchi Bold Sans Serif.