From: Martin Kronbichler Date: Thu, 30 Jul 2015 11:36:21 +0000 (+0200) Subject: Add test for new functionality X-Git-Tag: v8.4.0-rc2~699^2~2 X-Git-Url: https://gitweb.dealii.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=85ffc38344ce071679b2776169ed4fb5cbb20583;p=dealii.git Add test for new functionality --- diff --git a/tests/trilinos/trilinos_sparsity_pattern_03.cc b/tests/trilinos/trilinos_sparsity_pattern_03.cc new file mode 100644 index 0000000000..fde4cf587c --- /dev/null +++ b/tests/trilinos/trilinos_sparsity_pattern_03.cc @@ -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 +#include +#include + + +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 index 0000000000..3f7a181d7f --- /dev/null +++ b/tests/trilinos/trilinos_sparsity_pattern_03.mpirun=4.output @@ -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