From: Timo Heister Date: Mon, 12 Jan 2015 14:20:58 +0000 (-0500) Subject: test copying Trilinos SparseMatrix X-Git-Tag: v8.3.0-rc1~553^2~7 X-Git-Url: https://gitweb.dealii.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=0aed1e8014fc6363ba12e9163df4c4b0a0278ced;p=dealii.git test copying Trilinos SparseMatrix It looks like Trilinos is overwriting a matrix even though I am making a copy. Test currently fails. --- diff --git a/tests/mpi/trilinos_sparse_matrix_02.cc b/tests/mpi/trilinos_sparse_matrix_02.cc new file mode 100644 index 0000000000..c219430baf --- /dev/null +++ b/tests/mpi/trilinos_sparse_matrix_02.cc @@ -0,0 +1,120 @@ +// --------------------------------------------------------------------- +// +// 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. +// +// --------------------------------------------------------------------- + + + +// This demonstrates a bug where copying a Trilinos matrix and then modifying +// the source will edit both matrices. + +#include "../tests.h" +#include +#include +#include +#include +#include +#include +#include +#include +#include + + +void test () +{ + const unsigned int n_procs = Utilities::MPI::n_mpi_processes(MPI_COMM_WORLD); + const unsigned int my_id = Utilities::MPI::this_mpi_process(MPI_COMM_WORLD); + + const unsigned int n_rows = 4; + + IndexSet locally_owned (n_rows); + + if (n_procs == 1) + { + locally_owned.add_range(0, n_rows); + } + else if (n_procs == 2) + { + // should be { [0, 2), [2, n_rows) } + if (my_id == 0) + locally_owned.add_range(0, 2); + else if (my_id == 1) + locally_owned.add_range(2, n_rows); + } + else + Assert (false, ExcNotImplemented()); + + TrilinosWrappers::SparsityPattern sp (locally_owned, locally_owned, MPI_COMM_WORLD); + if (my_id == 0) + { + sp.add (0, 0); + sp.add (0, 2); + } + if ((n_procs == 1) || (my_id == 1)) + sp.add(2,3); + sp.compress(); + + TrilinosWrappers::SparseMatrix A; + A.reinit (sp); + TrilinosWrappers::SparseMatrix B; + B.reinit(A); + + A.add(0, 0, 0.1); + A.add(0, 2, 0.2); + if ((n_procs == 1) || (my_id == 1)) + A.add(2,3, 0.3); + + double l1a = (n_procs==1) ? 0.3 : 0.4; + double l1b = n_procs*1.2; + + A.compress(VectorOperation::add); + deallog << "1: " << A.l1_norm() << " " << B.l1_norm() + << " (should be " << l1a << " 0.0)" << std::endl; + + deallog << "set B=A..." << std::endl; + + B = A; + deallog << "2: " << A.l1_norm() << " " << B.l1_norm() + << " (should be " << l1a << " " << l1a << ")" << std::endl; + + if (my_id==0) + { + deallog << "A(0,0)=" << A(0,0) << std::endl; + deallog << "B(0,0)=" << B(0,0) << std::endl; + } + + deallog << "reassemble A..." << std::endl; + + A = 0; + A.add(0, 0, -1.2); + A.compress(VectorOperation::add); + deallog << "3: " << A.l1_norm() << " " << B.l1_norm() + << " (should be " << l1b << " " << l1a << ")" << std::endl; + + if (my_id==0) + { + deallog << "A(0,0)=" << A(0,0) << std::endl; + deallog << "B(0,0)=" << B(0,0) << std::endl; + } + + if (my_id == 0) deallog << "OK" << std::endl; +} + + + +int main (int argc, char **argv) +{ + Utilities::MPI::MPI_InitFinalize mpi_initialization(argc, argv, 1); + MPILogInitAll log; + test(); +} diff --git a/tests/mpi/trilinos_sparse_matrix_02.with_trilinos=true.mpirun=1.output b/tests/mpi/trilinos_sparse_matrix_02.with_trilinos=true.mpirun=1.output new file mode 100644 index 0000000000..ce91aeb968 --- /dev/null +++ b/tests/mpi/trilinos_sparse_matrix_02.with_trilinos=true.mpirun=1.output @@ -0,0 +1,11 @@ + +DEAL:0::1: 0.300000 0.00000 (should be 0.300000 0.0) +DEAL:0::set B=A... +DEAL:0::2: 0.300000 0.300000 (should be 0.300000 0.300000) +DEAL:0::A(0,0)=0.100000 +DEAL:0::B(0,0)=0.100000 +DEAL:0::reassemble A... +DEAL:0::3: 1.20000 0.300000 (should be 1.20000 0.300000) +DEAL:0::A(0,0)=-1.20000 +DEAL:0::B(0,0)=0.100000 +DEAL:0::OK diff --git a/tests/mpi/trilinos_sparse_matrix_02.with_trilinos=true.mpirun=2.output b/tests/mpi/trilinos_sparse_matrix_02.with_trilinos=true.mpirun=2.output new file mode 100644 index 0000000000..2b393600dd --- /dev/null +++ b/tests/mpi/trilinos_sparse_matrix_02.with_trilinos=true.mpirun=2.output @@ -0,0 +1,18 @@ + +DEAL:0::1: 0.400000 0.00000 (should be 0.400000 0.0) +DEAL:0::set B=A... +DEAL:0::2: 0.400000 0.400000 (should be 0.400000 0.400000) +DEAL:0::A(0,0)=0.200000 +DEAL:0::B(0,0)=0.200000 +DEAL:0::reassemble A... +DEAL:0::3: 2.40000 0.400000 (should be 2.40000 0.400000) +DEAL:0::A(0,0)=-2.40000 +DEAL:0::B(0,0)=0.200000 +DEAL:0::OK + +DEAL:1::1: 0.400000 0.00000 (should be 0.400000 0.0) +DEAL:1::set B=A... +DEAL:1::2: 0.400000 0.400000 (should be 0.400000 0.400000) +DEAL:1::reassemble A... +DEAL:1::3: 2.40000 0.400000 (should be 2.40000 0.400000) +