From f5660de6fe76b55574cf8a521da035d2ecc38058 Mon Sep 17 00:00:00 2001 From: Jean-Paul Pelteret Date: Thu, 15 Feb 2018 09:50:16 +0100 Subject: [PATCH] Generalise Scalapack scale_columns and scale_rows functions --- include/deal.II/base/array_view.h | 40 +++++++++++++++++ include/deal.II/lac/scalapack.h | 13 ++++-- source/lac/CMakeLists.txt | 1 + source/lac/scalapack.cc | 71 ++++++++++++++++++++++--------- source/lac/scalapack.inst.in | 36 ++++++++++++++++ 5 files changed, 137 insertions(+), 24 deletions(-) create mode 100644 source/lac/scalapack.inst.in diff --git a/include/deal.II/base/array_view.h b/include/deal.II/base/array_view.h index 4321e61fd5..84cfeb6627 100644 --- a/include/deal.II/base/array_view.h +++ b/include/deal.II/base/array_view.h @@ -524,6 +524,46 @@ make_array_view (ElementType *const begin, ElementType *const end) +/** + * Create a view from an ArrayView itself. + * + * This function is used for @p const references to objects of ArrayView type. + * It only exists for compatibility purposes. + * + * @param[in] array_view The ArrayView that we wish to make a copy of. + * + * @relates ArrayView + */ +template +inline +ArrayView +make_array_view (const ArrayView &array_view) +{ + return make_array_view (array_view.cbegin(), array_view.cend()); +} + + + +/** + * Create a view from an ArrayView itself. + * + * This function is used for non-@p const references to objects of ArrayView type. + * It only exists for compatibility purposes. + * + * @param[in] array_view The ArrayView that we wish to make a copy of. + * + * @relates ArrayView + */ +template +inline +ArrayView +make_array_view (ArrayView &array_view) +{ + return make_array_view (array_view.begin(), array_view.end()); +} + + + /** * Create a view to an entire Tensor object. This is equivalent to initializing * an ArrayView object with a pointer to the first element and the size of the diff --git a/include/deal.II/lac/scalapack.h b/include/deal.II/lac/scalapack.h index 0cc03e9b87..68e673bb56 100644 --- a/include/deal.II/lac/scalapack.h +++ b/include/deal.II/lac/scalapack.h @@ -26,7 +26,6 @@ #include #include #include -#include #include #include @@ -543,8 +542,12 @@ public: * The array @p factors must have as many entries as the matrix columns. * * Copies of @p factors have to be available on all processes of the underlying MPI communicator. + * + * @note The fundamental prerequisite for the @p InputVector is that it must be possible to + * create an ArrayView from it; this is satisfied by the @p std::vector and Vector classes. */ - void scale_columns(const ArrayView &factors); + template + void scale_columns(const InputVector &factors); /** * Scale the rows of the distributed matrix by the scalars provided in the array @p factors. @@ -552,8 +555,12 @@ public: * The array @p factors must have as many entries as the matrix rows. * * Copies of @p factors have to be available on all processes of the underlying MPI communicator. + * + * @note The fundamental prerequisite for the @p InputVector is that it must be possible to + * create an ArrayView from it; this is satisfied by the @p std::vector and Vector classes. */ - void scale_rows(const ArrayView &factors); + template + void scale_rows(const InputVector &factors); private: diff --git a/source/lac/CMakeLists.txt b/source/lac/CMakeLists.txt index defcbb0fb2..f98f40e702 100644 --- a/source/lac/CMakeLists.txt +++ b/source/lac/CMakeLists.txt @@ -73,6 +73,7 @@ SET(_inst precondition_block.inst.in relaxation_block.inst.in read_write_vector.inst.in + scalapack.inst.in solver.inst.in sparse_matrix_ez.inst.in sparse_matrix.inst.in diff --git a/source/lac/scalapack.cc b/source/lac/scalapack.cc index 864962d2df..67e068e0cc 100644 --- a/source/lac/scalapack.cc +++ b/source/lac/scalapack.cc @@ -1506,43 +1506,72 @@ void ScaLAPACKMatrix::load_parallel(const char *filename) -template -void ScaLAPACKMatrix::scale_columns(const ArrayView &factors) +namespace internal { - Assert(n_columns==(int)factors.size(),ExcDimensionMismatch(n_columns,factors.size())); + namespace + { - if (this->grid->mpi_process_is_active) - for (int i=0; i + void scale_columns(ScaLAPACKMatrix &matrix, + const ArrayView &factors, + const bool grid_mpi_process_is_active) + { + Assert(matrix.n()==factors.size(),ExcDimensionMismatch(matrix.n(),factors.size())); + + if (grid_mpi_process_is_active) + for (unsigned int i=0; i + void scale_rows(ScaLAPACKMatrix &matrix, + const ArrayView &factors, + const bool grid_mpi_process_is_active) + { + Assert(matrix.m()==factors.size(),ExcDimensionMismatch(matrix.m(),factors.size())); - for (int j=0; j -void ScaLAPACKMatrix::scale_rows(const ArrayView &factors) +template +void ScaLAPACKMatrix::scale_columns(const InputVector &factors) { - Assert(n_rows==(int)factors.size(),ExcDimensionMismatch(n_rows,factors.size())); + internal::scale_columns(*this, make_array_view(factors), + this->grid->mpi_process_is_active); +} + - if (this->grid->mpi_process_is_active) - for (int i=0; i +template +void ScaLAPACKMatrix::scale_rows(const InputVector &factors) +{ + internal::scale_rows(*this, make_array_view(factors), + this->grid->mpi_process_is_active); } // instantiations -template class ScaLAPACKMatrix; -template class ScaLAPACKMatrix; +#include "scalapack.inst" DEAL_II_NAMESPACE_CLOSE diff --git a/source/lac/scalapack.inst.in b/source/lac/scalapack.inst.in new file mode 100644 index 0000000000..0e3ca68740 --- /dev/null +++ b/source/lac/scalapack.inst.in @@ -0,0 +1,36 @@ +// --------------------------------------------------------------------- +// +// Copyright (C) 2017 - 2018 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. +// +// --------------------------------------------------------------------- + + +for (Number : REAL_SCALARS) +{ + template class ScaLAPACKMatrix; + + template + void ScaLAPACKMatrix::scale_columns> (const Vector&); + + template + void ScaLAPACKMatrix::scale_rows> (const Vector&); +} + +for (VEC : GENERAL_CONTAINER_TYPES; + Number : REAL_SCALARS) +{ + template + void ScaLAPACKMatrix::scale_columns> (const VEC&); + + template + void ScaLAPACKMatrix::scale_rows> (const VEC&); +} -- 2.39.5