+/**
+ * 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 <typename Number>
+inline
+ArrayView<const Number>
+make_array_view (const ArrayView<Number> &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 <typename Number>
+inline
+ArrayView<Number>
+make_array_view (ArrayView<Number> &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
#include <deal.II/lac/lapack_support.h>
#include <deal.II/base/mpi.h>
#include <deal.II/base/thread_management.h>
-#include <deal.II/base/array_view.h>
#include <mpi.h>
#include <memory>
* 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<const NumberType> &factors);
+ template <class InputVector>
+ void scale_columns(const InputVector &factors);
/**
* Scale the rows of the distributed matrix by the scalars provided in the array @p factors.
* 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<const NumberType> &factors);
+ template <class InputVector>
+ void scale_rows(const InputVector &factors);
private:
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
-template <typename NumberType>
-void ScaLAPACKMatrix<NumberType>::scale_columns(const ArrayView<const NumberType> &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<n_local_columns; ++i)
- {
- const NumberType s = factors[global_column(i)];
+ template <typename NumberType>
+ void scale_columns(ScaLAPACKMatrix<NumberType> &matrix,
+ const ArrayView<const NumberType> &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<matrix.local_n(); ++i)
+ {
+ const NumberType s = factors[matrix.global_column(i)];
+
+ for (unsigned int j=0; j<matrix.local_m(); ++j)
+ matrix.local_el(j,i) *= s;
+ }
+ }
+
+ template <typename NumberType>
+ void scale_rows(ScaLAPACKMatrix<NumberType> &matrix,
+ const ArrayView<const NumberType> &factors,
+ const bool grid_mpi_process_is_active)
+ {
+ Assert(matrix.m()==factors.size(),ExcDimensionMismatch(matrix.m(),factors.size()));
- for (int j=0; j<n_local_rows; ++j)
- local_el(j,i) *= s;
- }
+ if (grid_mpi_process_is_active)
+ for (unsigned int i=0; i<matrix.local_m(); ++i)
+ {
+ const NumberType s = factors[matrix.global_row(i)];
+
+ for (unsigned int j=0; j<matrix.local_n(); ++j)
+ matrix.local_el(i,j) *= s;
+ }
+ }
+
+ }
}
template <typename NumberType>
-void ScaLAPACKMatrix<NumberType>::scale_rows(const ArrayView<const NumberType> &factors)
+template <class InputVector>
+void ScaLAPACKMatrix<NumberType>::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<n_local_rows; ++i)
- {
- const NumberType s = factors[global_row(i)];
- for (int j=0; j<n_local_columns; ++j)
- local_el(i,j) *= s;
- }
+template <typename NumberType>
+template <class InputVector>
+void ScaLAPACKMatrix<NumberType>::scale_rows(const InputVector &factors)
+{
+ internal::scale_rows(*this, make_array_view(factors),
+ this->grid->mpi_process_is_active);
}
// instantiations
-template class ScaLAPACKMatrix<double>;
-template class ScaLAPACKMatrix<float>;
+#include "scalapack.inst"
DEAL_II_NAMESPACE_CLOSE
--- /dev/null
+// ---------------------------------------------------------------------
+//
+// 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<Number>;
+
+ template
+ void ScaLAPACKMatrix<Number>::scale_columns<Vector<Number>> (const Vector<Number>&);
+
+ template
+ void ScaLAPACKMatrix<Number>::scale_rows<Vector<Number>> (const Vector<Number>&);
+}
+
+for (VEC : GENERAL_CONTAINER_TYPES;
+ Number : REAL_SCALARS)
+{
+ template
+ void ScaLAPACKMatrix<Number>::scale_columns<VEC<Number>> (const VEC<Number>&);
+
+ template
+ void ScaLAPACKMatrix<Number>::scale_rows<VEC<Number>> (const VEC<Number>&);
+}