From 8fa914c43080de987a1c04ef35267fc7909588f2 Mon Sep 17 00:00:00 2001 From: Bruno Turcksin Date: Thu, 15 Feb 2018 22:07:41 -0500 Subject: [PATCH] Fix a bug in CUDAWrappers::Vector::reinit The second time that reinit was called the wrong number of elements was set to zero. --- source/lac/cuda_vector.cu | 2 +- tests/cuda/cuda_vector_03.cu | 46 ++++++++++++++++++++++++++++++++ tests/cuda/cuda_vector_03.output | 2 ++ 3 files changed, 49 insertions(+), 1 deletion(-) create mode 100644 tests/cuda/cuda_vector_03.cu create mode 100644 tests/cuda/cuda_vector_03.output diff --git a/source/lac/cuda_vector.cu b/source/lac/cuda_vector.cu index 9b9477afe8..c6164537e5 100644 --- a/source/lac/cuda_vector.cu +++ b/source/lac/cuda_vector.cu @@ -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 index 0000000000..bd83012d52 --- /dev/null +++ b/tests/cuda/cuda_vector_03.cu @@ -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 +#include + +// Check that reinit correctly set all the entries of the vector to zero + +void test() +{ + const unsigned int size = 100; + LinearAlgebra::CUDAWrappers::Vector a(size); + LinearAlgebra::ReadWriteVector read_write(size); + for (unsigned int i=0; i