Reference documentation for deal.II version 9.1.0-pre
scalapack.h
1 // ---------------------------------------------------------------------
2 //
3 // Copyright (C) 2017 - 2018 by the deal.II authors
4 //
5 // This file is part of the deal.II library.
6 //
7 // The deal.II library is free software; you can use it, redistribute
8 // it, and/or modify it under the terms of the GNU Lesser General
9 // Public License as published by the Free Software Foundation; either
10 // version 2.1 of the License, or (at your option) any later version.
11 // The full text of the license can be found in the file LICENSE.md at
12 // the top level directory of deal.II.
13 //
14 // ---------------------------------------------------------------------
15 
16 #ifndef dealii_scalapack_h
17 #define dealii_scalapack_h
18 
19 #include <deal.II/base/config.h>
20 
21 #ifdef DEAL_II_WITH_SCALAPACK
22 
23 # include <deal.II/base/exceptions.h>
24 # include <deal.II/base/mpi.h>
25 # include <deal.II/base/process_grid.h>
26 # include <deal.II/base/thread_management.h>
27 
28 # include <deal.II/lac/full_matrix.h>
29 # include <deal.II/lac/lapack_support.h>
30 
31 # include <mpi.h>
32 
33 # include <memory>
34 
35 DEAL_II_NAMESPACE_OPEN
36 
106 template <typename NumberType>
107 class ScaLAPACKMatrix : protected TransposeTable<NumberType>
108 {
109 public:
113  using size_type = unsigned int;
114 
120  const size_type n_rows,
121  const size_type n_columns,
122  const std::shared_ptr<const Utilities::MPI::ProcessGrid> &process_grid,
123  const size_type row_block_size = 32,
124  const size_type column_block_size = 32,
126 
132  const size_type size,
133  const std::shared_ptr<const Utilities::MPI::ProcessGrid> process_grid,
134  const size_type block_size = 32,
136  LAPACKSupport::Property::symmetric);
137 
141  ~ScaLAPACKMatrix() override = default;
142 
147  void
148  reinit(
149  const size_type n_rows,
150  const size_type n_columns,
151  const std::shared_ptr<const Utilities::MPI::ProcessGrid> &process_grid,
152  const size_type row_block_size = 32,
153  const size_type column_block_size = 32,
155 
159  void
160  reinit(const size_type size,
161  const std::shared_ptr<const Utilities::MPI::ProcessGrid> process_grid,
162  const size_type block_size = 32,
164  LAPACKSupport::Property::symmetric);
165 
169  void
171 
176  get_property() const;
177 
182  get_state() const;
183 
192 
199  void
200  copy_to(FullMatrix<NumberType> &matrix) const;
201 
207  void
209 
234  void
236  const std::pair<unsigned int, unsigned int> &offset_A,
237  const std::pair<unsigned int, unsigned int> &offset_B,
238  const std::pair<unsigned int, unsigned int> &submatrix_size) const;
239 
248  void
250 
262  void
264  const NumberType a = 0.,
265  const NumberType b = 1.,
266  const bool transpose_B = false);
267 
277  void
278  add(const NumberType b, const ScaLAPACKMatrix<NumberType> &B);
279 
289  void
290  Tadd(const NumberType b, const ScaLAPACKMatrix<NumberType> &B);
291 
312  void
313  mult(const NumberType b,
315  const NumberType c,
317  const bool transpose_A = false,
318  const bool transpose_B = false) const;
319 
337  void
340  const bool adding = false) const;
341 
359  void
362  const bool adding = false) const;
363 
381  void
384  const bool adding = false) const;
385 
404  void
407  const bool adding = false) const;
408 
429  void
430  save(const char * filename,
431  const std::pair<unsigned int, unsigned int> &chunk_size =
432  std::make_pair(numbers::invalid_unsigned_int,
434 
446  void
447  load(const char *filename);
448 
454  void
456 
462  void
464 
477  void
478  invert();
479 
495  std::vector<NumberType>
497  const std::pair<unsigned int, unsigned int> &index_limits,
498  const bool compute_eigenvectors);
499 
508  std::vector<NumberType>
510  const std::pair<NumberType, NumberType> &value_limits,
511  const bool compute_eigenvectors);
512 
529  std::vector<NumberType>
531  const std::pair<unsigned int, unsigned int> &index_limits,
532  const bool compute_eigenvectors);
533 
544  std::vector<NumberType>
546  const std::pair<NumberType, NumberType> &value_limits,
547  const bool compute_eigenvectors);
548 
577  std::vector<NumberType>
579  ScaLAPACKMatrix<NumberType> *VT = nullptr);
580 
621  void
622  least_squares(ScaLAPACKMatrix<NumberType> &B, const bool transpose = false);
623 
647  unsigned int
648  pseudoinverse(const NumberType ratio);
649 
664  NumberType
665  reciprocal_condition_number(const NumberType a_norm) const;
666 
670  NumberType
671  l1_norm() const;
672 
676  NumberType
677  linfty_norm() const;
678 
682  NumberType
683  frobenius_norm() const;
684 
688  size_type
689  m() const;
690 
694  size_type
695  n() const;
696 
700  unsigned int
701  local_m() const;
702 
706  unsigned int
707  local_n() const;
708 
712  unsigned int
713  global_row(const unsigned int loc_row) const;
714 
718  unsigned int
719  global_column(const unsigned int loc_column) const;
720 
724  NumberType
725  local_el(const unsigned int loc_row, const unsigned int loc_column) const;
726 
730  NumberType &
731  local_el(const unsigned int loc_row, const unsigned int loc_column);
732 
743  template <class InputVector>
744  void
745  scale_columns(const InputVector &factors);
746 
757  template <class InputVector>
758  void
759  scale_rows(const InputVector &factors);
760 
761 private:
766  NumberType
767  norm_symmetric(const char type) const;
768 
773  NumberType
774  norm_general(const char type) const;
775 
786  std::vector<NumberType>
788  const bool compute_eigenvectors,
789  const std::pair<unsigned int, unsigned int> &index_limits =
790  std::make_pair(numbers::invalid_unsigned_int,
792  const std::pair<NumberType, NumberType> &value_limits =
793  std::make_pair(std::numeric_limits<NumberType>::quiet_NaN(),
794  std::numeric_limits<NumberType>::quiet_NaN()));
795 
815  std::vector<NumberType>
817  const bool compute_eigenvectors,
818  const std::pair<unsigned int, unsigned int> &index_limits =
819  std::make_pair(numbers::invalid_unsigned_int,
821  const std::pair<NumberType, NumberType> &value_limits =
822  std::make_pair(std::numeric_limits<NumberType>::quiet_NaN(),
823  std::numeric_limits<NumberType>::quiet_NaN()));
824 
825  /*
826  * Stores the distributed matrix in @p filename
827  * using serial routines
828  */
829  void
830  save_serial(const char * filename,
831  const std::pair<unsigned int, unsigned int> &chunk_size) const;
832 
833  /*
834  * Loads the distributed matrix from file @p filename
835  * using serial routines
836  */
837  void
838  load_serial(const char *filename);
839 
840  /*
841  * Stores the distributed matrix in @p filename
842  * using parallel routines
843  */
844  void
845  save_parallel(const char * filename,
846  const std::pair<unsigned int, unsigned int> &chunk_size) const;
847 
848  /*
849  * Loads the distributed matrix from file @p filename
850  * using parallel routines
851  */
852  void
853  load_parallel(const char *filename);
854 
860 
866 
872  std::shared_ptr<const Utilities::MPI::ProcessGrid> grid;
873 
877  int n_rows;
878 
883 
888 
893 
898 
903 
907  int descriptor[9];
908 
912  mutable std::vector<NumberType> work;
913 
917  mutable std::vector<int> iwork;
918 
923  std::vector<int> ipiv;
924 
929  const char uplo;
930 
935  const int first_process_row;
936 
942 
947  const int submatrix_row;
948 
953  const int submatrix_column;
954 
959 };
960 
961 // ----------------------- inline functions ----------------------------
962 
963 # ifndef DOXYGEN
964 
965 template <typename NumberType>
966 inline NumberType
967 ScaLAPACKMatrix<NumberType>::local_el(const unsigned int loc_row,
968  const unsigned int loc_column) const
969 {
970  return (*this)(loc_row, loc_column);
971 }
972 
973 
974 
975 template <typename NumberType>
976 inline NumberType &
977 ScaLAPACKMatrix<NumberType>::local_el(const unsigned int loc_row,
978  const unsigned int loc_column)
979 {
980  return (*this)(loc_row, loc_column);
981 }
982 
983 
984 template <typename NumberType>
985 inline unsigned int
987 {
988  return n_rows;
989 }
990 
991 
992 
993 template <typename NumberType>
994 inline unsigned int
996 {
997  return n_columns;
998 }
999 
1000 
1001 
1002 template <typename NumberType>
1003 unsigned int
1005 {
1006  return n_local_rows;
1007 }
1008 
1009 
1010 
1011 template <typename NumberType>
1012 unsigned int
1014 {
1015  return n_local_columns;
1016 }
1017 
1018 
1019 # endif // DOXYGEN
1020 
1021 DEAL_II_NAMESPACE_CLOSE
1022 
1023 #endif // DEAL_II_WITH_SCALAPACK
1024 
1025 #endif
std::vector< NumberType > eigenpairs_symmetric_by_index_MRRR(const std::pair< unsigned int, unsigned int > &index_limits, const bool compute_eigenvectors)
Definition: scalapack.cc:1408
void copy_transposed(const ScaLAPACKMatrix< NumberType > &B)
Definition: scalapack.cc:625
ScaLAPACKMatrix(const size_type n_rows, const size_type n_columns, const std::shared_ptr< const Utilities::MPI::ProcessGrid > &process_grid, const size_type row_block_size=32, const size_type column_block_size=32, const LAPACKSupport::Property property=LAPACKSupport::Property::general)
Definition: scalapack.cc:79
std::vector< NumberType > eigenpairs_symmetric_by_value_MRRR(const std::pair< NumberType, NumberType > &value_limits, const bool compute_eigenvectors)
Definition: scalapack.cc:1431
NumberType reciprocal_condition_number(const NumberType a_norm) const
Definition: scalapack.cc:1958
size_type n_rows() const
unsigned int size_type
Definition: scalapack.h:113
size_type m() const
static const unsigned int invalid_unsigned_int
Definition: types.h:173
LAPACKSupport::State state
Definition: scalapack.h:859
unsigned int global_column(const unsigned int loc_column) const
Definition: scalapack.cc:285
void copy_to(FullMatrix< NumberType > &matrix) const
Definition: scalapack.cc:303
void save(const char *filename, const std::pair< unsigned int, unsigned int > &chunk_size=std::make_pair(numbers::invalid_unsigned_int, numbers::invalid_unsigned_int)) const
Definition: scalapack.cc:2256
NumberType norm_general(const char type) const
Definition: scalapack.cc:2062
ScaLAPACKMatrix< NumberType > & operator=(const FullMatrix< NumberType > &)
Definition: scalapack.cc:237
const char uplo
Definition: scalapack.h:929
unsigned int pseudoinverse(const NumberType ratio)
Definition: scalapack.cc:1871
void load(const char *filename)
Definition: scalapack.cc:2673
unsigned int local_m() const
void mTmult(ScaLAPACKMatrix< NumberType > &C, const ScaLAPACKMatrix< NumberType > &B, const bool adding=false) const
Definition: scalapack.cc:855
size_type n() const
std::vector< NumberType > eigenpairs_symmetric(const bool compute_eigenvectors, const std::pair< unsigned int, unsigned int > &index_limits=std::make_pair(numbers::invalid_unsigned_int, numbers::invalid_unsigned_int), const std::pair< NumberType, NumberType > &value_limits=std::make_pair(std::numeric_limits< NumberType >::quiet_NaN(), std::numeric_limits< NumberType >::quiet_NaN()))
Definition: scalapack.cc:1118
std::vector< NumberType > eigenpairs_symmetric_by_index(const std::pair< unsigned int, unsigned int > &index_limits, const bool compute_eigenvectors)
Definition: scalapack.cc:1073
void mult(const NumberType b, const ScaLAPACKMatrix< NumberType > &B, const NumberType c, ScaLAPACKMatrix< NumberType > &C, const bool transpose_A=false, const bool transpose_B=false) const
Definition: scalapack.cc:710
void scale_columns(const InputVector &factors)
Definition: scalapack.cc:3121
std::shared_ptr< const Utilities::MPI::ProcessGrid > grid
Definition: scalapack.h:872
std::vector< int > iwork
Definition: scalapack.h:917
const int submatrix_column
Definition: scalapack.h:953
void reinit(const size_type n_rows, const size_type n_columns, const std::shared_ptr< const Utilities::MPI::ProcessGrid > &process_grid, const size_type row_block_size=32, const size_type column_block_size=32, const LAPACKSupport::Property property=LAPACKSupport::Property::general)
Definition: scalapack.cc:121
const TableIndices< N > & size() const
LAPACKSupport::Property get_property() const
Definition: scalapack.cc:219
void least_squares(ScaLAPACKMatrix< NumberType > &B, const bool transpose=false)
Definition: scalapack.cc:1779
NumberType norm_symmetric(const char type) const
Definition: scalapack.cc:2121
void scale_rows(const InputVector &factors)
Definition: scalapack.cc:3132
void set_property(const LAPACKSupport::Property property)
Definition: scalapack.cc:209
std::vector< int > ipiv
Definition: scalapack.h:923
const int first_process_row
Definition: scalapack.h:935
void add(const ScaLAPACKMatrix< NumberType > &B, const NumberType a=0., const NumberType b=1., const bool transpose_B=false)
Definition: scalapack.cc:635
std::vector< NumberType > eigenpairs_symmetric_by_value(const std::pair< NumberType, NumberType > &value_limits, const bool compute_eigenvectors)
Definition: scalapack.cc:1098
int column_block_size
Definition: scalapack.h:892
Threads::Mutex mutex
Definition: scalapack.h:958
SymmetricTensor< rank_, dim, Number > transpose(const SymmetricTensor< rank_, dim, Number > &t)
const int submatrix_row
Definition: scalapack.h:947
NumberType l1_norm() const
Definition: scalapack.cc:2020
void TmTmult(ScaLAPACKMatrix< NumberType > &C, const ScaLAPACKMatrix< NumberType > &B, const bool adding=false) const
Definition: scalapack.cc:869
void mmult(ScaLAPACKMatrix< NumberType > &C, const ScaLAPACKMatrix< NumberType > &B, const bool adding=false) const
Definition: scalapack.cc:827
NumberType local_el(const unsigned int loc_row, const unsigned int loc_column) const
NumberType frobenius_norm() const
Definition: scalapack.cc:2048
std::vector< NumberType > eigenpairs_symmetric_MRRR(const bool compute_eigenvectors, const std::pair< unsigned int, unsigned int > &index_limits=std::make_pair(numbers::invalid_unsigned_int, numbers::invalid_unsigned_int), const std::pair< NumberType, NumberType > &value_limits=std::make_pair(std::numeric_limits< NumberType >::quiet_NaN(), std::numeric_limits< NumberType >::quiet_NaN()))
Definition: scalapack.cc:1449
std::vector< NumberType > compute_SVD(ScaLAPACKMatrix< NumberType > *U=nullptr, ScaLAPACKMatrix< NumberType > *VT=nullptr)
Definition: scalapack.cc:1659
unsigned int local_n() const
std::vector< NumberType > work
Definition: scalapack.h:912
const int first_process_column
Definition: scalapack.h:941
LAPACKSupport::Property property
Definition: scalapack.h:865
void Tadd(const NumberType b, const ScaLAPACKMatrix< NumberType > &B)
Definition: scalapack.cc:700
~ScaLAPACKMatrix() override=default
int descriptor[9]
Definition: scalapack.h:907
unsigned int global_row(const unsigned int loc_row) const
Definition: scalapack.cc:268
void Tmmult(ScaLAPACKMatrix< NumberType > &C, const ScaLAPACKMatrix< NumberType > &B, const bool adding=false) const
Definition: scalapack.cc:841
void compute_cholesky_factorization()
Definition: scalapack.cc:883
NumberType linfty_norm() const
Definition: scalapack.cc:2034
LAPACKSupport::State get_state() const
Definition: scalapack.cc:228
void compute_lu_factorization()
Definition: scalapack.cc:916