]> https://gitweb.dealii.org/ - dealii.git/commitdiff
Add test for new functionality
authorMartin Kronbichler <kronbichler@lnm.mw.tum.de>
Thu, 30 Jul 2015 11:36:21 +0000 (13:36 +0200)
committerMartin Kronbichler <kronbichler@lnm.mw.tum.de>
Thu, 30 Jul 2015 11:54:45 +0000 (13:54 +0200)
tests/trilinos/trilinos_sparsity_pattern_03.cc [new file with mode: 0644]
tests/trilinos/trilinos_sparsity_pattern_03.mpirun=4.output [new file with mode: 0644]

diff --git a/tests/trilinos/trilinos_sparsity_pattern_03.cc b/tests/trilinos/trilinos_sparsity_pattern_03.cc
new file mode 100644 (file)
index 0000000..fde4cf5
--- /dev/null
@@ -0,0 +1,98 @@
+// ---------------------------------------------------------------------
+//
+// Copyright (C) 2014 - 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.
+//
+// ---------------------------------------------------------------------
+
+
+
+// Tests IndexSet retrieval of Trilinos sparsity patterns
+
+#include "../tests.h"
+#include <deal.II/lac/trilinos_sparsity_pattern.h>
+#include <fstream>
+#include <iomanip>
+
+
+void test ()
+{
+  const unsigned int n_procs = Utilities::MPI::n_mpi_processes(MPI_COMM_WORLD);
+  const unsigned int myid = Utilities::MPI::this_mpi_process(MPI_COMM_WORLD);
+
+  TrilinosWrappers::SparsityPattern sp;
+
+  deallog << "Creating entries..." << std::endl;
+
+  IndexSet rows(2*n_procs);
+  rows.add_range(2*myid, 2*myid+2);
+  rows.compress();
+  IndexSet columns(3*n_procs);
+  columns.add_range(3*myid, 3*myid+3);
+  columns.compress();
+
+  sp.reinit(rows, columns, MPI_COMM_WORLD, 0);
+  deallog << "SP::is_compressed(): " << sp.is_compressed() << std::endl;
+
+  for (unsigned int i=2*myid; i<2*myid+2; ++i)
+    for (unsigned int j=0; j<3*n_procs; ++j)
+      if ((i+2*j+1) % 3 == 0)
+        sp.add (i,j);
+
+  deallog << "SP::is_compressed(): " << sp.is_compressed() << std::endl;
+
+  sp.compress ();
+
+  deallog << "SP::is_compressed(): " << sp.is_compressed() << std::endl;
+  deallog << "Number of entries: " << sp.n_nonzero_elements() << std::endl;
+  deallog << "Number of rows: " << sp.n_rows() << std::endl;
+  deallog << "Number of colums: " << sp.n_cols() << std::endl;
+
+  deallog << "Checks: ";
+  IndexSet stored_rows = sp.locally_owned_range_indices();
+  IndexSet stored_cols = sp.locally_owned_domain_indices();
+  AssertThrow(stored_rows == rows, ExcInternalError());
+  AssertThrow(stored_cols == columns, ExcInternalError());
+
+  const unsigned int stored_n_procs = Utilities::MPI::n_mpi_processes(sp.get_mpi_communicator());
+  const unsigned int stored_myid = Utilities::MPI::this_mpi_process(sp.get_mpi_communicator());
+
+  AssertThrow(stored_n_procs == n_procs, ExcInternalError());
+  AssertThrow(stored_myid == myid, ExcInternalError());
+
+  deallog << "OK" << std::endl;
+}
+
+
+
+int main (int argc, char **argv)
+{
+  std::ofstream logfile("output");
+  deallog.attach(logfile);
+  deallog.depth_console(0);
+  deallog.threshold_double(1.e-10);
+
+  Utilities::MPI::MPI_InitFinalize mpi_initialization (argc, argv, testing_max_num_threads());
+
+  if (Utilities::MPI::this_mpi_process(MPI_COMM_WORLD) == 0)
+    {
+      std::ofstream logfile ("output");
+      deallog.attach (logfile);
+      deallog.depth_console (0);
+      deallog.threshold_double (1.e-10);
+
+      test();
+    }
+  else
+    {
+      test();
+    }
+}
diff --git a/tests/trilinos/trilinos_sparsity_pattern_03.mpirun=4.output b/tests/trilinos/trilinos_sparsity_pattern_03.mpirun=4.output
new file mode 100644 (file)
index 0000000..3f7a181
--- /dev/null
@@ -0,0 +1,9 @@
+
+DEAL::Creating entries...
+DEAL::SP::is_compressed(): 0
+DEAL::SP::is_compressed(): 0
+DEAL::SP::is_compressed(): 1
+DEAL::Number of entries: 32
+DEAL::Number of rows: 8
+DEAL::Number of colums: 12
+DEAL::Checks: 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.