]> https://gitweb.dealii.org/ - dealii.git/commitdiff
Add tests for: Patch by Fahad Alrasched: Add extract_subvector_to() function to all...
authorWolfgang Bangerth <bangerth@math.tamu.edu>
Mon, 2 Sep 2013 22:03:39 +0000 (22:03 +0000)
committerWolfgang Bangerth <bangerth@math.tamu.edu>
Mon, 2 Sep 2013 22:03:39 +0000 (22:03 +0000)
git-svn-id: https://svn.dealii.org/trunk@30556 0785d39b-7218-0410-832d-ea1e28bc413d

tests/gla/extract_subvector_to.cc [new file with mode: 0644]
tests/gla/extract_subvector_to/ncpu_1/cmp/generic [new file with mode: 0644]
tests/gla/extract_subvector_to_parallel.cc [new file with mode: 0644]
tests/gla/extract_subvector_to_parallel/ncpu_2/cmp/generic [new file with mode: 0644]

diff --git a/tests/gla/extract_subvector_to.cc b/tests/gla/extract_subvector_to.cc
new file mode 100644 (file)
index 0000000..e967217
--- /dev/null
@@ -0,0 +1,128 @@
+// ---------------------------------------------------------------------
+// $Id$
+//
+// Copyright (C) 2004 - 2013 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.
+//
+// ---------------------------------------------------------------------
+
+
+
+// test the various VECTOR::extract_subvector_to functions
+
+#include "../tests.h"
+#include <deal.II/lac/generic_linear_algebra.h>
+#include <deal.II/base/index_set.h>
+#include <deal.II/lac/constraint_matrix.h>
+#include <fstream>
+#include <iostream>
+#include <iomanip>
+#include <vector>
+
+
+template <class Vector>
+void test (Vector &vector)
+{
+  const unsigned int myid = Utilities::MPI::this_mpi_process (MPI_COMM_WORLD);
+
+  for (unsigned int i=0; i<vector.size(); ++i)
+    vector(i) = i;
+
+  // select every other element
+  std::vector<typename Vector::size_type> indices;
+  for (unsigned int j=0; j<vector.size()/2; ++j)
+    indices.push_back (2*j);
+
+  // do the extraction with the function that takes indices, then
+  // assert correctness
+  std::vector<typename Vector::value_type> values1 (indices.size());
+  vector.extract_subvector_to (indices, values1);
+  for (unsigned int j=0; j<vector.size()/2; ++j)
+    Assert (values1[j] == 2*j, ExcInternalError());
+
+  // do the same with the version of the function that takes iterators
+  std::vector<typename Vector::value_type> values2 (indices.size());
+  vector.extract_subvector_to (indices.begin(),
+                              indices.end(),
+                              values2.begin());
+  for (unsigned int j=0; j<vector.size()/2; ++j)
+    Assert (values2[j] == 2*j, ExcInternalError());
+
+  // done
+  if (myid==0)
+    deallog << "OK" << std::endl;
+}
+
+
+
+int main (int argc, char **argv)
+{
+  Utilities::MPI::MPI_InitFinalize mpi_initialization(argc, argv, 1);
+  MPILogInitAll log(__FILE__);
+  {
+    {
+      deallog.push("deal.II");
+      Vector<double> v(17);
+      test (v);
+      deallog.pop();
+    }
+
+    {
+      deallog.push("PETSc");
+      PETScWrappers::Vector v(17);
+      test (v);
+      deallog.pop();
+    }
+
+    {
+      deallog.push("Trilinos");
+      TrilinosWrappers::Vector v(17);
+      test (v);
+      deallog.pop();
+    }
+
+
+    {
+      deallog.push("deal.II");
+      BlockVector<double> v(3);
+      v.block(0).reinit(7);
+      v.block(1).reinit(5);
+      v.block(2).reinit(3);
+      v.collect_sizes();
+      test (v);
+      deallog.pop();
+    }
+
+    {
+      deallog.push("PETSc");
+      PETScWrappers::BlockVector v(3);
+      v.block(0).reinit(7);
+      v.block(1).reinit(5);
+      v.block(2).reinit(3);
+      v.collect_sizes();
+      test (v);
+      deallog.pop();
+    }
+
+    {
+      deallog.push("Trilinos");
+      TrilinosWrappers::BlockVector v(3);
+      v.block(0).reinit(7);
+      v.block(1).reinit(5);
+      v.block(2).reinit(3);
+      v.collect_sizes();
+      test (v);
+      deallog.pop();
+    }
+
+  }
+
+}
diff --git a/tests/gla/extract_subvector_to/ncpu_1/cmp/generic b/tests/gla/extract_subvector_to/ncpu_1/cmp/generic
new file mode 100644 (file)
index 0000000..784d66b
--- /dev/null
@@ -0,0 +1,7 @@
+
+DEAL:0:deal.II::OK
+DEAL:0:PETSc::OK
+DEAL:0:Trilinos::OK
+DEAL:0:deal.II::OK
+DEAL:0:PETSc::OK
+DEAL:0:Trilinos::OK
diff --git a/tests/gla/extract_subvector_to_parallel.cc b/tests/gla/extract_subvector_to_parallel.cc
new file mode 100644 (file)
index 0000000..c859a1a
--- /dev/null
@@ -0,0 +1,183 @@
+// ---------------------------------------------------------------------
+// $Id$
+//
+// Copyright (C) 2004 - 2013 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.
+//
+// ---------------------------------------------------------------------
+
+
+
+// test the various VECTOR::extract_subvector_to functions for
+// parallel vectors and block vectors
+
+#include "../tests.h"
+#include <deal.II/lac/generic_linear_algebra.h>
+#include <deal.II/base/index_set.h>
+#include <deal.II/lac/parallel_block_vector.h>
+#include <fstream>
+#include <iostream>
+#include <iomanip>
+#include <vector>
+
+
+template <class Vector>
+void set (Vector &vector)
+{
+  for (unsigned int i=0; i<vector.size(); ++i)
+    if (vector.locally_owned_elements().is_element(i))
+      vector(i) = i;
+  vector.compress (VectorOperation::insert);
+}
+
+
+template <class Vector>
+void test (Vector &vector)
+{
+  const unsigned int myid = Utilities::MPI::this_mpi_process (MPI_COMM_WORLD);
+
+  // select every other element
+  std::vector<typename Vector::size_type> indices;
+  for (unsigned int j=0; j<vector.size()/2; ++j)
+    indices.push_back (2*j);
+
+  // do the extraction with the function that takes indices, then
+  // assert correctness
+  std::vector<typename Vector::value_type> values1 (indices.size());
+  vector.extract_subvector_to (indices, values1);
+  for (unsigned int j=0; j<vector.size()/2; ++j)
+    Assert (values1[j] == 2*j, ExcInternalError());
+
+  // do the same with the version of the function that takes iterators
+  std::vector<typename Vector::value_type> values2 (indices.size());
+  vector.extract_subvector_to (indices.begin(),
+                              indices.end(),
+                              values2.begin());
+  for (unsigned int j=0; j<vector.size()/2; ++j)
+    Assert (values2[j] == 2*j, ExcInternalError());
+
+  // done
+  if (myid==0)
+    deallog << "OK" << std::endl;
+}
+
+
+
+int main (int argc, char **argv)
+{
+  Utilities::MPI::MPI_InitFinalize mpi_initialization(argc, argv, 1);
+  MPILogInitAll log(__FILE__);
+  const unsigned int myid = Utilities::MPI::this_mpi_process (MPI_COMM_WORLD);
+  {
+    IndexSet local (10);
+    if (myid==0)
+      local.add_range(0,5);
+    if (myid==1)
+      local.add_range(5,10);
+
+    IndexSet dense_local (10);
+    dense_local.add_range(0,10);
+
+    // {
+    //   deallog.push("deal.II");
+    //   parallel::distributed::Vector<double> w(local, dense_local, MPI_COMM_WORLD);
+    //   set (w);
+    //   parallel::distributed::Vector<double> v(local, dense_local, MPI_COMM_WORLD);
+    //   v = w; // get copy of vector including ghost elements
+    //   test (v);
+    //   deallog.pop();
+    // }
+
+    {
+      deallog.push("PETSc");
+      PETScWrappers::MPI::Vector w(local, MPI_COMM_WORLD);
+      set (w);
+      PETScWrappers::MPI::Vector v(local, dense_local, MPI_COMM_WORLD);
+      v = w; // get copy of vector including ghost elements
+      test (v);
+      deallog.pop();
+    }
+
+    {
+      deallog.push("Trilinos");
+      TrilinosWrappers::MPI::Vector w(local, MPI_COMM_WORLD);
+      set (w);
+      TrilinosWrappers::MPI::Vector v(local, dense_local, MPI_COMM_WORLD);
+      v = w; // get copy of vector including ghost elements
+      test (v);
+      deallog.pop();
+    }
+
+
+    std::vector<IndexSet> partitioning;
+    {
+      IndexSet block1(10);
+      if (myid==0)
+       block1.add_range(0,7);
+      if (myid==1)
+       block1.add_range(7,10);
+
+      IndexSet block2(6);
+      if (myid==0)
+       block2.add_range(0,2);
+      if (myid==1)
+       block2.add_range(2,6);
+
+      partitioning.push_back(block1);
+      partitioning.push_back(block2);
+    }
+
+    std::vector<IndexSet> dense_partitioning;
+    {
+      IndexSet block1(10);
+      block1.add_range(0,10);
+
+      IndexSet block2(6);
+      block2.add_range(0,6);
+
+      dense_partitioning.push_back(block1);
+      dense_partitioning.push_back(block2);
+    }
+
+
+    // {
+    //   deallog.push("deal.II");
+    //   parallel::distributed::BlockVector<double> w(partitioning, MPI_COMM_WORLD);
+    //   set (w);
+    //   parallel::distributed::BlockVector<double> v(partitioning, dense_partitioning, MPI_COMM_WORLD);
+    //   v = w; // get copy of vector including ghost elements
+    //   test (v);
+    //   deallog.pop();
+    // }
+
+    {
+      deallog.push("PETSc");
+      PETScWrappers::MPI::BlockVector w(partitioning, MPI_COMM_WORLD);
+      set (w);
+      PETScWrappers::MPI::BlockVector v(partitioning, dense_partitioning, MPI_COMM_WORLD);
+      v = w; // get copy of vector including ghost elements
+      test (v);
+      deallog.pop();
+    }
+
+    {
+      deallog.push("Trilinos");
+      TrilinosWrappers::MPI::BlockVector w(partitioning, MPI_COMM_WORLD);
+      set (w);
+      TrilinosWrappers::MPI::BlockVector v(partitioning, dense_partitioning, MPI_COMM_WORLD);
+      v = w; // get copy of vector including ghost elements
+      test (v);
+      deallog.pop();
+    }
+
+  }
+
+}
diff --git a/tests/gla/extract_subvector_to_parallel/ncpu_2/cmp/generic b/tests/gla/extract_subvector_to_parallel/ncpu_2/cmp/generic
new file mode 100644 (file)
index 0000000..ae4bdbf
--- /dev/null
@@ -0,0 +1,7 @@
+
+DEAL:0:PETSc::OK
+DEAL:0:Trilinos::OK
+DEAL:0:PETSc::OK
+DEAL:0:Trilinos::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.