From: Martin Kronbichler Date: Wed, 12 Apr 2017 11:23:49 +0000 (+0200) Subject: Fix uninitialized memory in ghost range of distributed vector X-Git-Tag: v9.0.0-rc1~1697^2~1 X-Git-Url: https://gitweb.dealii.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=1f4b994c652e99a101db4be471153fe4eee26016;p=dealii.git Fix uninitialized memory in ghost range of distributed vector --- diff --git a/include/deal.II/lac/la_parallel_vector.templates.h b/include/deal.II/lac/la_parallel_vector.templates.h index b886ca1658..fedc272467 100644 --- a/include/deal.II/lac/la_parallel_vector.templates.h +++ b/include/deal.II/lac/la_parallel_vector.templates.h @@ -104,8 +104,8 @@ namespace LinearAlgebra // set entries to zero if so requested if (omit_zeroing_entries == false) this->operator = (Number()); - - vector_is_ghosted = false; + else + zero_out_ghosts(); } @@ -133,6 +133,8 @@ namespace LinearAlgebra if (omit_zeroing_entries == false) this->operator= (Number()); + else + zero_out_ghosts(); if (import_data != nullptr) { @@ -145,8 +147,6 @@ namespace LinearAlgebra import_data = nullptr; } - vector_is_ghosted = false; - thread_loop_partitioner = v.thread_loop_partitioner; } @@ -240,8 +240,6 @@ namespace LinearAlgebra dealii::internal::VectorOperations::Vector_copy copier(v.val, val); internal::VectorOperations::parallel_for(copier, 0, partitioner->local_size(), thread_loop_partitioner); - - zero_out_ghosts(); } diff --git a/tests/mpi/parallel_vector_21.cc b/tests/mpi/parallel_vector_21.cc new file mode 100644 index 0000000000..ae8d63853c --- /dev/null +++ b/tests/mpi/parallel_vector_21.cc @@ -0,0 +1,72 @@ +// --------------------------------------------------------------------- +// +// Copyright (C) 2017 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. +// +// --------------------------------------------------------------------- + +// Check that the data range representing ghosts is really initialized to zero +// when doing reinit() from another vector and manually setting the local +// range + +#include "../tests.h" +#include +#include +#include +#include +#include +#include +#include + +void test() +{ + unsigned int my_id = Utilities::MPI::this_mpi_process (MPI_COMM_WORLD); + unsigned int n_procs = Utilities::MPI::n_mpi_processes (MPI_COMM_WORLD); + + IndexSet locally_owned(n_procs*2); + locally_owned.add_range(my_id*2, my_id*2+2); + IndexSet ghost_set(n_procs*2); + ghost_set.add_index(0); + ghost_set.add_index(2); + + LinearAlgebra::distributed::Vector v(locally_owned, ghost_set, MPI_COMM_WORLD); + + // create vector without actually setting the entries since they will be + // overwritten soon anyway + LinearAlgebra::distributed::Vector v2; + v2.reinit(v, true); + + // set locally owned range of v2 manually + for (unsigned int i=0; i