]> https://gitweb.dealii.org/ - dealii.git/commitdiff
Fix a bug in CUDAWrappers::Vector::reinit 5908/head
authorBruno Turcksin <bruno.turcksin@gmail.com>
Fri, 16 Feb 2018 03:07:41 +0000 (22:07 -0500)
committerBruno Turcksin <bruno.turcksin@gmail.com>
Fri, 16 Feb 2018 14:05:45 +0000 (09:05 -0500)
The second time that reinit was called the wrong number of elements was set to
zero.

source/lac/cuda_vector.cu
tests/cuda/cuda_vector_03.cu [new file with mode: 0644]
tests/cuda/cuda_vector_03.output [new file with mode: 0644]

index 9b9477afe829a8d197b6e92973952f0882a00fe5..c6164537e5a488220d5d5507fc9bcc4f83502efd 100644 (file)
@@ -554,7 +554,7 @@ namespace LinearAlgebra
           if (omit_zeroing_entries == false)
             {
               cudaError_t error_code = cudaMemset(val, 0,
-                                                  n_elements*sizeof(Number));
+                                                  n*sizeof(Number));
               AssertCuda(error_code);
             }
         }
diff --git a/tests/cuda/cuda_vector_03.cu b/tests/cuda/cuda_vector_03.cu
new file mode 100644 (file)
index 0000000..bd83012
--- /dev/null
@@ -0,0 +1,46 @@
+// ---------------------------------------------------------------------
+//
+// Copyright (C) 2018 by the deal.II authors
+//
+// This file is part of the deal.II library.
+//
+// The deal.II library is free software; you can use it, redistribute
+// it, and/or modify it under the terms of the GNU Lesser General
+// Public License as published by the Free Software Foundation; either
+// version 2.1 of the License, or (at your option) any later version.
+// The full text of the license can be found in the file LICENSE at
+// the top level of the deal.II distribution.
+//
+// ---------------------------------------------------------------------
+
+#include "../tests.h"
+#include <deal.II/lac/cuda_vector.h>
+#include <deal.II/lac/read_write_vector.h>
+
+// Check that reinit correctly set all the entries of the vector to zero
+
+void test()
+{
+  const unsigned int size = 100;
+  LinearAlgebra::CUDAWrappers::Vector<double> a(size);
+  LinearAlgebra::ReadWriteVector<double> read_write(size);
+  for (unsigned int i=0; i<size; ++i)
+    read_write[i] = i;
+  a.import(read_write, VectorOperation::insert);
+
+  a.reinit(size/2);
+  AssertThrow(a.l1_norm()==0., ExcMessage("reinit did not zero the entry"));
+}
+
+
+int main(int argc, char **argv)
+{
+  initlog();
+  deallog.depth_console(0);
+
+  test();
+
+  deallog << "OK" <<std::endl;
+
+  return 0;
+}
diff --git a/tests/cuda/cuda_vector_03.output b/tests/cuda/cuda_vector_03.output
new file mode 100644 (file)
index 0000000..0fd8fc1
--- /dev/null
@@ -0,0 +1,2 @@
+
+DEAL::OK

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.