]> https://gitweb.dealii.org/ - dealii.git/commitdiff
Add a few more TpetraWrappers and EpetraWrapper tests with a matrix-vector product
authorDaniel Arndt <daniel.arndt@iwr.uni-heidelberg.de>
Wed, 20 Feb 2019 15:49:54 +0000 (16:49 +0100)
committerDaniel Arndt <daniel.arndt@iwr.uni-heidelberg.de>
Wed, 20 Feb 2019 15:53:00 +0000 (16:53 +0100)
include/deal.II/lac/trilinos_sparse_matrix.h
tests/trilinos/sparse_matrix_vector_12.cc [new file with mode: 0644]
tests/trilinos/sparse_matrix_vector_12.output [new file with mode: 0644]
tests/trilinos/sparse_matrix_vector_13.cc [new file with mode: 0644]
tests/trilinos/sparse_matrix_vector_13.output [new file with mode: 0644]
tests/trilinos/sparse_matrix_vector_14.cc [new file with mode: 0644]
tests/trilinos/sparse_matrix_vector_14.output [new file with mode: 0644]
tests/trilinos/sparse_matrix_vector_15.cc [new file with mode: 0644]
tests/trilinos/sparse_matrix_vector_15.output [new file with mode: 0644]

index 183875e6bec35da18f751875ff4c907ddcab422b..b07e06c6f3c0269eedb4d912296b1eaf0c274546 100644 (file)
@@ -1566,6 +1566,7 @@ namespace TrilinosWrappers
      * <ul>
      * <li> TrilinosWrappers::MPI::Vector,
      * <li> LinearAlgebra::EpetraWrappers::Vector,
+     * <li> LinearAlgebra::TpetraWrappers::Vector,
      * <li> Vector<double>,
      * <li> LinearAlgebra::distributed::Vector<double>.
      * </ul>
diff --git a/tests/trilinos/sparse_matrix_vector_12.cc b/tests/trilinos/sparse_matrix_vector_12.cc
new file mode 100644 (file)
index 0000000..398cf91
--- /dev/null
@@ -0,0 +1,126 @@
+// ---------------------------------------------------------------------
+//
+// Copyright (C) 2013 - 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.md at
+// the top level directory of deal.II.
+//
+// ---------------------------------------------------------------------
+
+
+
+// check SparseMatrix::vmult, vmult_add with
+// LinearAlgebra::EpetraWrappers::Vector
+
+#include <deal.II/base/utilities.h>
+
+#include <deal.II/lac/la_parallel_vector.h>
+#include <deal.II/lac/read_write_vector.h>
+#include <deal.II/lac/trilinos_sparse_matrix.h>
+
+#include <iostream>
+#include <vector>
+
+#include "../tests.h"
+
+
+void
+test(LinearAlgebra::EpetraWrappers::Vector &v,
+     LinearAlgebra::EpetraWrappers::Vector &w)
+{
+  LinearAlgebra::ReadWriteVector<double> read_write_v(v.size());
+  LinearAlgebra::ReadWriteVector<double> read_write_w(w.size());
+
+  TrilinosWrappers::SparseMatrix m(w.size(), v.size(), v.size());
+  for (unsigned int i = 0; i < m.m(); ++i)
+    for (unsigned int j = 0; j < m.n(); ++j)
+      m.set(i, j, i + 2 * j);
+
+  for (unsigned int i = 0; i < v.size(); ++i)
+    read_write_v(i) = i;
+
+  m.compress(VectorOperation::insert);
+  v.import(read_write_v, VectorOperation::insert);
+
+  // w:=Mv
+  m.vmult(w, v);
+
+  // make sure we get the expected result
+  read_write_w.import(w, VectorOperation::insert);
+  for (unsigned int i = 0; i < m.m(); ++i)
+    {
+      double result = 0;
+      for (unsigned int j = 0; j < m.n(); ++j)
+        result += (i + 2 * j) * j;
+      AssertThrow(read_write_w(i) == result, ExcInternalError());
+    }
+
+  m.vmult_add(w, v);
+
+  // make sure we get the expected result
+  read_write_w.import(w, VectorOperation::insert);
+  for (unsigned int i = 0; i < m.m(); ++i)
+    {
+      double result = 0;
+      for (unsigned int j = 0; j < m.n(); ++j)
+        result += (i + 2 * j) * j;
+      AssertThrow(read_write_w(i) == result + result, ExcInternalError());
+    }
+
+  deallog << "OK" << std::endl;
+}
+
+
+
+int
+main(int argc, char **argv)
+{
+  initlog();
+
+  Utilities::MPI::MPI_InitFinalize mpi_initialization(
+    argc, argv, testing_max_num_threads());
+
+
+  try
+    {
+      {
+        LinearAlgebra::EpetraWrappers::Vector v(complete_index_set(100),
+                                                MPI_COMM_SELF);
+        LinearAlgebra::EpetraWrappers::Vector w(complete_index_set(95),
+                                                MPI_COMM_SELF);
+        test(v, w);
+      }
+    }
+  catch (std::exception &exc)
+    {
+      std::cerr << std::endl
+                << std::endl
+                << "----------------------------------------------------"
+                << std::endl;
+      std::cerr << "Exception on processing: " << std::endl
+                << exc.what() << std::endl
+                << "Aborting!" << std::endl
+                << "----------------------------------------------------"
+                << std::endl;
+
+      return 1;
+    }
+  catch (...)
+    {
+      std::cerr << std::endl
+                << std::endl
+                << "----------------------------------------------------"
+                << std::endl;
+      std::cerr << "Unknown exception!" << std::endl
+                << "Aborting!" << std::endl
+                << "----------------------------------------------------"
+                << std::endl;
+      return 1;
+    };
+}
diff --git a/tests/trilinos/sparse_matrix_vector_12.output b/tests/trilinos/sparse_matrix_vector_12.output
new file mode 100644 (file)
index 0000000..0fd8fc1
--- /dev/null
@@ -0,0 +1,2 @@
+
+DEAL::OK
diff --git a/tests/trilinos/sparse_matrix_vector_13.cc b/tests/trilinos/sparse_matrix_vector_13.cc
new file mode 100644 (file)
index 0000000..e13c996
--- /dev/null
@@ -0,0 +1,125 @@
+// ---------------------------------------------------------------------
+//
+// Copyright (C) 2013 - 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.md at
+// the top level directory of deal.II.
+//
+// ---------------------------------------------------------------------
+
+
+
+// check SparseMatrix::Tvmult, Tvmult_add with
+// LinearAlgebra::EpetraWrappers::Vector
+
+#include <deal.II/base/utilities.h>
+
+#include <deal.II/lac/la_parallel_vector.h>
+#include <deal.II/lac/read_write_vector.h>
+#include <deal.II/lac/trilinos_sparse_matrix.h>
+
+#include <iostream>
+#include <vector>
+
+#include "../tests.h"
+
+
+void
+test(LinearAlgebra::EpetraWrappers::Vector &v,
+     LinearAlgebra::EpetraWrappers::Vector &w)
+{
+  LinearAlgebra::ReadWriteVector<double> read_write_v(v.size());
+  LinearAlgebra::ReadWriteVector<double> read_write_w(w.size());
+
+  TrilinosWrappers::SparseMatrix m(v.size(), w.size(), w.size());
+  for (unsigned int i = 0; i < m.m(); ++i)
+    for (unsigned int j = 0; j < m.n(); ++j)
+      m.set(i, j, i + 2 * j);
+
+  for (unsigned int i = 0; i < v.size(); ++i)
+    read_write_v(i) = i;
+
+  m.compress(VectorOperation::insert);
+  v.import(read_write_v, VectorOperation::insert);
+
+  // w:=Mv
+  m.Tvmult(w, v);
+
+  // make sure we get the expected result
+  read_write_w.import(w, VectorOperation::insert);
+  for (unsigned int i = 0; i < m.n(); ++i)
+    {
+      double result = 0;
+      for (unsigned int j = 0; j < m.m(); ++j)
+        result += (j + 2 * i) * j;
+      AssertThrow(read_write_w(i) == result, ExcInternalError());
+    }
+
+  m.Tvmult_add(w, v);
+  // make sure we get the expected result
+  read_write_w.import(w, VectorOperation::insert);
+  for (unsigned int i = 0; i < m.n(); ++i)
+    {
+      double result = 0;
+      for (unsigned int j = 0; j < m.m(); ++j)
+        result += (j + 2 * i) * j;
+      AssertThrow(read_write_w(i) == result + result, ExcInternalError());
+    }
+
+  deallog << "OK" << std::endl;
+}
+
+
+
+int
+main(int argc, char **argv)
+{
+  initlog();
+
+  Utilities::MPI::MPI_InitFinalize mpi_initialization(
+    argc, argv, testing_max_num_threads());
+
+
+  try
+    {
+      {
+        LinearAlgebra::EpetraWrappers::Vector v(complete_index_set(95),
+                                                MPI_COMM_SELF);
+        LinearAlgebra::EpetraWrappers::Vector w(complete_index_set(100),
+                                                MPI_COMM_SELF);
+        test(v, w);
+      }
+    }
+  catch (std::exception &exc)
+    {
+      std::cerr << std::endl
+                << std::endl
+                << "----------------------------------------------------"
+                << std::endl;
+      std::cerr << "Exception on processing: " << std::endl
+                << exc.what() << std::endl
+                << "Aborting!" << std::endl
+                << "----------------------------------------------------"
+                << std::endl;
+
+      return 1;
+    }
+  catch (...)
+    {
+      std::cerr << std::endl
+                << std::endl
+                << "----------------------------------------------------"
+                << std::endl;
+      std::cerr << "Unknown exception!" << std::endl
+                << "Aborting!" << std::endl
+                << "----------------------------------------------------"
+                << std::endl;
+      return 1;
+    };
+}
diff --git a/tests/trilinos/sparse_matrix_vector_13.output b/tests/trilinos/sparse_matrix_vector_13.output
new file mode 100644 (file)
index 0000000..0fd8fc1
--- /dev/null
@@ -0,0 +1,2 @@
+
+DEAL::OK
diff --git a/tests/trilinos/sparse_matrix_vector_14.cc b/tests/trilinos/sparse_matrix_vector_14.cc
new file mode 100644 (file)
index 0000000..fed0ac1
--- /dev/null
@@ -0,0 +1,126 @@
+// ---------------------------------------------------------------------
+//
+// Copyright (C) 2013 - 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.md at
+// the top level directory of deal.II.
+//
+// ---------------------------------------------------------------------
+
+
+
+// check SparseMatrix::vmult, vmult_add with
+// LinearAlgebra::TpetraWrappers::Vector<double>
+
+#include <deal.II/base/utilities.h>
+
+#include <deal.II/lac/la_parallel_vector.h>
+#include <deal.II/lac/read_write_vector.h>
+#include <deal.II/lac/trilinos_sparse_matrix.h>
+
+#include <iostream>
+#include <vector>
+
+#include "../tests.h"
+
+
+void
+test(LinearAlgebra::TpetraWrappers::Vector<double> &v,
+     LinearAlgebra::TpetraWrappers::Vector<double> &w)
+{
+  LinearAlgebra::ReadWriteVector<double> read_write_v(v.size());
+  LinearAlgebra::ReadWriteVector<double> read_write_w(w.size());
+
+  TrilinosWrappers::SparseMatrix m(w.size(), v.size(), v.size());
+  for (unsigned int i = 0; i < m.m(); ++i)
+    for (unsigned int j = 0; j < m.n(); ++j)
+      m.set(i, j, i + 2 * j);
+
+  for (unsigned int i = 0; i < v.size(); ++i)
+    read_write_v(i) = i;
+
+  m.compress(VectorOperation::insert);
+  v.import(read_write_v, VectorOperation::insert);
+
+  // w:=Mv
+  m.vmult(w, v);
+
+  // make sure we get the expected result
+  read_write_w.import(w, VectorOperation::insert);
+  for (unsigned int i = 0; i < m.m(); ++i)
+    {
+      double result = 0;
+      for (unsigned int j = 0; j < m.n(); ++j)
+        result += (i + 2 * j) * j;
+      AssertThrow(read_write_w(i) == result, ExcInternalError());
+    }
+
+  m.vmult_add(w, v);
+
+  // make sure we get the expected result
+  read_write_w.import(w, VectorOperation::insert);
+  for (unsigned int i = 0; i < m.m(); ++i)
+    {
+      double result = 0;
+      for (unsigned int j = 0; j < m.n(); ++j)
+        result += (i + 2 * j) * j;
+      AssertThrow(read_write_w(i) == result + result, ExcInternalError());
+    }
+
+  deallog << "OK" << std::endl;
+}
+
+
+
+int
+main(int argc, char **argv)
+{
+  initlog();
+
+  Utilities::MPI::MPI_InitFinalize mpi_initialization(
+    argc, argv, testing_max_num_threads());
+
+
+  try
+    {
+      {
+        LinearAlgebra::TpetraWrappers::Vector<double> v(complete_index_set(100),
+                                                        MPI_COMM_SELF);
+        LinearAlgebra::TpetraWrappers::Vector<double> w(complete_index_set(95),
+                                                        MPI_COMM_SELF);
+        test(v, w);
+      }
+    }
+  catch (std::exception &exc)
+    {
+      std::cerr << std::endl
+                << std::endl
+                << "----------------------------------------------------"
+                << std::endl;
+      std::cerr << "Exception on processing: " << std::endl
+                << exc.what() << std::endl
+                << "Aborting!" << std::endl
+                << "----------------------------------------------------"
+                << std::endl;
+
+      return 1;
+    }
+  catch (...)
+    {
+      std::cerr << std::endl
+                << std::endl
+                << "----------------------------------------------------"
+                << std::endl;
+      std::cerr << "Unknown exception!" << std::endl
+                << "Aborting!" << std::endl
+                << "----------------------------------------------------"
+                << std::endl;
+      return 1;
+    };
+}
diff --git a/tests/trilinos/sparse_matrix_vector_14.output b/tests/trilinos/sparse_matrix_vector_14.output
new file mode 100644 (file)
index 0000000..0fd8fc1
--- /dev/null
@@ -0,0 +1,2 @@
+
+DEAL::OK
diff --git a/tests/trilinos/sparse_matrix_vector_15.cc b/tests/trilinos/sparse_matrix_vector_15.cc
new file mode 100644 (file)
index 0000000..870712b
--- /dev/null
@@ -0,0 +1,125 @@
+// ---------------------------------------------------------------------
+//
+// Copyright (C) 2013 - 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.md at
+// the top level directory of deal.II.
+//
+// ---------------------------------------------------------------------
+
+
+
+// check SparseMatrix::Tvmult, Tvmult_add with
+// LinearAlgebra::TpetraWrappers::Vector<double>
+
+#include <deal.II/base/utilities.h>
+
+#include <deal.II/lac/la_parallel_vector.h>
+#include <deal.II/lac/read_write_vector.h>
+#include <deal.II/lac/trilinos_sparse_matrix.h>
+
+#include <iostream>
+#include <vector>
+
+#include "../tests.h"
+
+
+void
+test(LinearAlgebra::TpetraWrappers::Vector<double> &v,
+     LinearAlgebra::TpetraWrappers::Vector<double> &w)
+{
+  LinearAlgebra::ReadWriteVector<double> read_write_v(v.size());
+  LinearAlgebra::ReadWriteVector<double> read_write_w(w.size());
+
+  TrilinosWrappers::SparseMatrix m(v.size(), w.size(), w.size());
+  for (unsigned int i = 0; i < m.m(); ++i)
+    for (unsigned int j = 0; j < m.n(); ++j)
+      m.set(i, j, i + 2 * j);
+
+  for (unsigned int i = 0; i < v.size(); ++i)
+    read_write_v(i) = i;
+
+  m.compress(VectorOperation::insert);
+  v.import(read_write_v, VectorOperation::insert);
+
+  // w:=Mv
+  m.Tvmult(w, v);
+
+  // make sure we get the expected result
+  read_write_w.import(w, VectorOperation::insert);
+  for (unsigned int i = 0; i < m.n(); ++i)
+    {
+      double result = 0;
+      for (unsigned int j = 0; j < m.m(); ++j)
+        result += (j + 2 * i) * j;
+      AssertThrow(read_write_w(i) == result, ExcInternalError());
+    }
+
+  m.Tvmult_add(w, v);
+  // make sure we get the expected result
+  read_write_w.import(w, VectorOperation::insert);
+  for (unsigned int i = 0; i < m.n(); ++i)
+    {
+      double result = 0;
+      for (unsigned int j = 0; j < m.m(); ++j)
+        result += (j + 2 * i) * j;
+      AssertThrow(read_write_w(i) == result + result, ExcInternalError());
+    }
+
+  deallog << "OK" << std::endl;
+}
+
+
+
+int
+main(int argc, char **argv)
+{
+  initlog();
+
+  Utilities::MPI::MPI_InitFinalize mpi_initialization(
+    argc, argv, testing_max_num_threads());
+
+
+  try
+    {
+      {
+        LinearAlgebra::TpetraWrappers::Vector<double> v(complete_index_set(95),
+                                                        MPI_COMM_SELF);
+        LinearAlgebra::TpetraWrappers::Vector<double> w(complete_index_set(100),
+                                                        MPI_COMM_SELF);
+        test(v, w);
+      }
+    }
+  catch (std::exception &exc)
+    {
+      std::cerr << std::endl
+                << std::endl
+                << "----------------------------------------------------"
+                << std::endl;
+      std::cerr << "Exception on processing: " << std::endl
+                << exc.what() << std::endl
+                << "Aborting!" << std::endl
+                << "----------------------------------------------------"
+                << std::endl;
+
+      return 1;
+    }
+  catch (...)
+    {
+      std::cerr << std::endl
+                << std::endl
+                << "----------------------------------------------------"
+                << std::endl;
+      std::cerr << "Unknown exception!" << std::endl
+                << "Aborting!" << std::endl
+                << "----------------------------------------------------"
+                << std::endl;
+      return 1;
+    };
+}
diff --git a/tests/trilinos/sparse_matrix_vector_15.output b/tests/trilinos/sparse_matrix_vector_15.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.