From: Martin Kronbichler Date: Thu, 21 Apr 2016 10:59:10 +0000 (+0200) Subject: Fix Trilinos mat-mat multiplication X-Git-Tag: v8.5.0-rc1~1087^2 X-Git-Url: https://gitweb.dealii.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=30f5eec927bf29b932f7122f316cd15d961cde83;p=dealii.git Fix Trilinos mat-mat multiplication --- diff --git a/doc/news/changes.h b/doc/news/changes.h index 6015244161..4878966edc 100644 --- a/doc/news/changes.h +++ b/doc/news/changes.h @@ -42,7 +42,7 @@ inconvenience this causes.
(Daniel Arndt, 2016/04/18) - +
  • Changed: FlatManifold takes as argument a periodicity option. This used to be a Point, but it should have been a Tensor<1,dim>. This is now changed. @@ -201,6 +201,13 @@ inconvenience this causes.

    Specific improvements

      +
    1. Fixed: The methods TrilinosWrappers::SparseMatrix::(T)mmult previously + produced invalid matrix sizes if the final matrix was non-square. This has + been fixed. +
      + (Martin Kronbichler, Daniel Jodlbauer, 2016/04/21) +
    2. +
    3. New: Added an optional string parameter to the ParameterHandler::read_input () and ParameterHandler::read_input_from_string() functions. When a line which equals this string is encountered, the parsing of parameters @@ -209,7 +216,6 @@ inconvenience this causes. (Denis Davydov, 2016/04/20)
    4. -
    5. New: Added move operations to IndexSet.
      (Daniel Shapero, 2016/04/19) diff --git a/source/lac/trilinos_sparse_matrix.cc b/source/lac/trilinos_sparse_matrix.cc index ba82179ff5..56ad9213e0 100644 --- a/source/lac/trilinos_sparse_matrix.cc +++ b/source/lac/trilinos_sparse_matrix.cc @@ -2295,7 +2295,10 @@ namespace TrilinosWrappers // matrix that we got as a result. Epetra_CrsMatrix *C_mat; ML_Operator2EpetraCrsMatrix(C_, C_mat); - C_mat->FillComplete(); + C_mat->FillComplete(mod_B->DomainMap(), + transpose_left ? + inputleft.trilinos_matrix().DomainMap() : + inputleft.trilinos_matrix().RangeMap()); C_mat->OptimizeStorage(); result.reinit (*C_mat); diff --git a/tests/trilinos/sparse_matrix_mmult_01.cc b/tests/trilinos/sparse_matrix_mmult_01.cc new file mode 100644 index 0000000000..857f569d2b --- /dev/null +++ b/tests/trilinos/sparse_matrix_mmult_01.cc @@ -0,0 +1,81 @@ +// --------------------------------------------------------------------- +// +// Copyright (C) 2016 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. +// +// --------------------------------------------------------------------- + + + +// check TrilinosWrappers::SparseMatrix::mmult for non-square matrices + +#include +#include +#include + +#include "../tests.h" + +using namespace dealii; + + +template +void out_matrix_size(const MATRIX &M, + const std::string &name) +{ + deallog << name << " = " << M.m() << " x " << M.n() << std::endl; +} + + +int main(int argc, char *argv[]) +{ + Utilities::MPI::MPI_InitFinalize mpi(argc, argv); + + mpi_initlog(); + + TrilinosWrappers::SparsityPattern P_A; + TrilinosWrappers::SparseMatrix A; + P_A.reinit(4, 3); + P_A.compress(); + A.reinit(P_A); + + TrilinosWrappers::SparsityPattern P_B; + TrilinosWrappers::SparseMatrix B; + P_B.reinit(3, 5); + P_B.compress(); + B.reinit(P_B); + + out_matrix_size(A, "A"); + out_matrix_size(B, "B"); + + TrilinosWrappers::SparseMatrix AB; + A.mmult(AB, B); + + out_matrix_size(AB, "A.B"); + + Assert (AB.m() == A.m(), ExcInternalError()); + Assert (AB.n() == B.n(), ExcInternalError()); + + TrilinosWrappers::SparsityPattern P_C; + TrilinosWrappers::SparseMatrix C; + P_C.reinit(4, 5); + P_C.compress(); + C.reinit(P_C); + + out_matrix_size(C, "C"); + + TrilinosWrappers::SparseMatrix AtC; + A.Tmmult(AtC, C); + + out_matrix_size(AtC, "At.C"); + + Assert (AtC.m() == A.n(), ExcInternalError()); + Assert (AtC.n() == C.n(), ExcInternalError()); +} diff --git a/tests/trilinos/sparse_matrix_mmult_01.output b/tests/trilinos/sparse_matrix_mmult_01.output new file mode 100644 index 0000000000..686d240096 --- /dev/null +++ b/tests/trilinos/sparse_matrix_mmult_01.output @@ -0,0 +1,6 @@ + +DEAL::A = 4 x 3 +DEAL::B = 3 x 5 +DEAL::A.B = 4 x 5 +DEAL::C = 4 x 5 +DEAL::At.C = 3 x 5