]> https://gitweb.dealii.org/ - dealii.git/commitdiff
bugfix: la::p::Vector::compress(insert) now correctly zeroes ghosts 6102/head
authorDenis Davydov <davydden@gmail.com>
Mon, 26 Mar 2018 13:32:20 +0000 (15:32 +0200)
committerDenis Davydov <davydden@gmail.com>
Mon, 26 Mar 2018 13:32:20 +0000 (15:32 +0200)
doc/news/changes/minor/20180326DenisDavydov [new file with mode: 0644]
include/deal.II/lac/la_parallel_vector.templates.h
tests/mpi/parallel_vector_03a.cc [new file with mode: 0644]
tests/mpi/parallel_vector_03a.mpirun=2.output [new file with mode: 0644]

diff --git a/doc/news/changes/minor/20180326DenisDavydov b/doc/news/changes/minor/20180326DenisDavydov
new file mode 100644 (file)
index 0000000..1846744
--- /dev/null
@@ -0,0 +1,4 @@
+Fixed: LinearAlgebra::distributed::Vector::compress(VectorOperation::insert) now flashes
+ghost part of the vector in Release mode.
+<br>
+(Denis Davydov, 2018/03/17)
index 04e95f50f6e71bfa19906ad546702abd40c95f0a..6a1a0c53f9eb0717e7e3fcd8b0c29624c86bc2d9 100644 (file)
@@ -560,8 +560,9 @@ namespace LinearAlgebra
 #ifdef DEAL_II_WITH_MPI
       vector_is_ghosted = false;
 
-      if (compress_requests.size() == 0)
-        return;
+      // in order to zero ghost part of the vector, we need to call
+      // import_from_ghosted_array_finish() regardless of
+      // compress_requests.size() == 0
 
       // make this function thread safe
       Threads::Mutex::ScopedLock lock (mutex);
diff --git a/tests/mpi/parallel_vector_03a.cc b/tests/mpi/parallel_vector_03a.cc
new file mode 100644 (file)
index 0000000..6d913b8
--- /dev/null
@@ -0,0 +1,123 @@
+// ---------------------------------------------------------------------
+//
+// Copyright (C) 2011 - 2015 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.
+//
+// ---------------------------------------------------------------------
+
+
+// similar to parallel_sparse_vector_03.cc, but make sure
+// compress(insert) zeroes out ghosts in Release mode
+
+#include "../tests.h"
+#include <deal.II/base/utilities.h>
+#include <deal.II/base/index_set.h>
+#include <deal.II/lac/la_parallel_vector.h>
+#include <fstream>
+#include <iostream>
+#include <vector>
+
+void check(const unsigned int myid,
+           const LinearAlgebra::distributed::Vector<double> &v)
+{
+  if (myid==0)
+    {
+      AssertThrow(v(10) == 10.0, ExcInternalError());
+      AssertThrow(v(11) == 0., ExcInternalError());
+      AssertThrow(v(12) == 0., ExcInternalError());
+      AssertThrow(v(14) == 14., ExcInternalError());
+
+      AssertThrow(v(5) == 55., ExcInternalError());
+    }
+  else
+    {
+      AssertThrow(v(4) == 0., ExcInternalError());
+      AssertThrow(v(5) == 55., ExcInternalError());
+      AssertThrow(v(6) == 66., ExcInternalError());
+    }
+}
+
+
+void test ()
+{
+  unsigned int myid = Utilities::MPI::this_mpi_process (MPI_COMM_WORLD);
+  unsigned int numproc = Utilities::MPI::n_mpi_processes (MPI_COMM_WORLD);
+
+  Assert (numproc==2, ExcNotImplemented());
+
+  const unsigned int size = 20;
+  IndexSet local_owned(size);
+  IndexSet local_nonzero(size);
+  IndexSet local_relevant(size);
+  if (myid==0)
+    {
+      local_owned.add_range(0,10);
+      local_nonzero.add_range(5,10);
+      local_relevant = local_owned;
+      local_relevant.add_range(10,13);
+      local_relevant.add_range(14,15);
+    }
+  else
+    {
+      local_owned.add_range(10,size);
+      local_nonzero.add_range(10,11);
+      local_nonzero.add_range(13,15);
+      local_relevant = local_owned;
+      local_relevant.add_range(4,7);
+    }
+
+  LinearAlgebra::distributed::Vector<double> v(local_owned, local_relevant, MPI_COMM_WORLD);
+  v = 0.;
+
+  // set local values
+  for (unsigned int i = 0; i < local_nonzero.n_elements(); i++)
+    v(local_nonzero.nth_index_in_set(i)) = local_nonzero.nth_index_in_set(i);
+
+  // set value from processor which does not own it:
+  v(5) = 55.;
+  v.compress(VectorOperation::insert);
+
+  // add to value from processor which has it as a ghost
+  if (myid == 1)
+    v(6) = 60;
+  v.compress(VectorOperation::add); // 60 + 6
+  // compress(insert) used to leave ghosts un-touched which resulted in
+  // the wrong 55+55 for this compress(add) operation.
+
+  v.update_ghost_values();
+
+  check(myid,v);
+
+  if (myid == 0)
+    deallog << "OK" << std::endl;
+}
+
+
+
+int main (int argc, char **argv)
+{
+  Utilities::MPI::MPI_InitFinalize mpi_initialization (argc, argv, testing_max_num_threads());
+
+  unsigned int myid = Utilities::MPI::this_mpi_process (MPI_COMM_WORLD);
+  deallog.push(Utilities::int_to_string(myid));
+
+  if (myid == 0)
+    {
+      std::ofstream logfile("output");
+      deallog.attach(logfile);
+      deallog << std::setprecision(4);
+
+      test();
+    }
+  else
+    test();
+
+}
diff --git a/tests/mpi/parallel_vector_03a.mpirun=2.output b/tests/mpi/parallel_vector_03a.mpirun=2.output
new file mode 100644 (file)
index 0000000..be8d055
--- /dev/null
@@ -0,0 +1,2 @@
+
+DEAL:0::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.