DFT-EFE
 
Loading...
Searching...
No Matches
ScalapackWrapper.h
Go to the documentation of this file.
1/******************************************************************************
2 * Copyright (c) 2021. *
3 * The Regents of the University of Michigan and DFT-EFE developers. *
4 * *
5 * This file is part of the DFT-EFE code. *
6 * *
7 * DFT-EFE is free software: you can redistribute it and/or modify *
8 * it under the terms of the Lesser GNU General Public License as *
9 * published by the Free Software Foundation, either version 3 of *
10 * the License, or (at your option) any later version. *
11 * *
12 * DFT-EFE is distributed in the hope that it will be useful, but *
13 * WITHOUT ANY WARRANTY; without even the implied warranty *
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. *
15 * See the Lesser GNU General Public License for more details. *
16 * *
17 * You should have received a copy of the GNU Lesser General Public *
18 * License at the top level of DFT-EFE distribution. If not, see *
19 * <https://www.gnu.org/licenses/>. *
20 ******************************************************************************/
21
22
23
24#ifndef ScaLAPACKMatrix_h
25#define ScaLAPACKMatrix_h
26
27#include "ProcessGrid.h"
28#include "LapackSupport.h"
29#include <memory>
30#include "LinearAlgebraTypes.h"
31
32namespace dftefe
33{
34 namespace linearAlgebra
35 {
41 template <typename NumberType>
43 {
44 public:
55 const size_type n_columns,
56 const std::shared_ptr<const ProcessGrid> &process_grid,
57 const size_type row_block_size = 32,
61
71 ScaLAPACKMatrix(const size_type size,
72 const std::shared_ptr<const ProcessGrid> &process_grid,
73 const size_type block_size = 32,
76
80 ~ScaLAPACKMatrix() = default;
81
91 void
93 const size_type n_columns,
94 const std::shared_ptr<const ProcessGrid> &process_grid,
95 const size_type row_block_size = 32,
99
108 void
109 reinit(const size_type size,
110 const std::shared_ptr<const ProcessGrid> &process_grid,
111 const size_type block_size = 32,
114
115
119 void
121
126 get_property() const;
127
132 get_state() const;
133
134
140 void
142
143
147 void
148 conjugate();
149
150
163 void
165 const NumberType a = 0.,
166 const NumberType b = 1.,
167 const bool transpose_B = false);
168
169
182 void
184 const NumberType a = 0.,
185 const NumberType b = 1.,
186 const bool conjugate_transpose_B = false);
187
197 void
199
200
210 void
212
233 void
234 mult(const NumberType b,
236 const NumberType c,
238 const bool transpose_A = false,
239 const bool transpose_B = false) const;
240
241
262 void
263 zmult(const NumberType b,
265 const NumberType c,
267 const bool conjugate_transpose_A = false,
268 const bool conjugate_transpose_B = false) const;
269
270
288 void
291 const bool adding = false) const;
292
311 void
314 const bool adding = false) const;
315
334 void
337 const bool adding = false) const;
338
358 void
361 const bool adding = false) const;
362
363
381 void
384 const bool adding = false) const;
385
404 void
407 const bool adding = false) const;
408
428 void
431 const bool adding = false) const;
432
453 void
456 const bool adding = false) const;
457
458
463 m() const;
464
469 n() const;
470
474 unsigned int
475 local_m() const;
476
480 unsigned int
481 local_n() const;
482
486 unsigned int
487 global_row(const unsigned int loc_row) const;
488
492 unsigned int
493 global_column(const unsigned int loc_column) const;
494
498 NumberType
499 local_el(const unsigned int loc_row, const unsigned int loc_column) const;
500
504 NumberType &
505 local_el(const unsigned int loc_row, const unsigned int loc_column);
506
514
522
536 invert();
537
545 void
546 scale_columns(const std::vector<NumberType> &factors);
547
555 void
556 scale_rows(const std::vector<NumberType> &factors);
557
558
566 void
567 scale_columns_realfactors(const std::vector<double> &factors);
568
576 void
577 scale_rows_realfactors(const std::vector<double> &factors);
578
594 std::vector<double>
596 const std::pair<unsigned int, unsigned int> &index_limits,
597 const bool compute_eigenvectors,
598 ScalapackError & scalapackError);
599
616 std::vector<double>
618 const std::pair<unsigned int, unsigned int> &index_limits,
619 const bool compute_eigenvectors,
620 ScalapackError & scalapackError);
621
622 private:
633 std::vector<double>
635 const bool compute_eigenvectors,
636 ScalapackError & scalapackError,
637 const std::pair<unsigned int, unsigned int> &index_limits =
638 std::make_pair(std::numeric_limits<unsigned int>::max(),
639 std::numeric_limits<unsigned int>::max()),
640 const std::pair<double, double> &value_limits =
641 std::make_pair(std::numeric_limits<double>::quiet_NaN(),
642 std::numeric_limits<double>::quiet_NaN()));
643
664 std::vector<double>
666 const bool compute_eigenvectors,
667 ScalapackError & scalapackError,
668 const std::pair<unsigned int, unsigned int> &index_limits =
669 std::make_pair(std::numeric_limits<unsigned int>::max(),
670 std::numeric_limits<unsigned int>::max()),
671 const std::pair<double, double> &value_limits =
672 std::make_pair(std::numeric_limits<double>::quiet_NaN(),
673 std::numeric_limits<double>::quiet_NaN()));
674
675
679 std::vector<NumberType> values;
680
686
692
698 std::shared_ptr<const ProcessGrid> grid;
699
704
709
714
719
724
729
734
738 mutable std::vector<NumberType> work;
739
743 mutable std::vector<int> iwork;
744
749 std::vector<int> ipiv;
750
755 const char uplo;
756
762
768
773 const int submatrix_row;
774
780 };
781
782 // ----------------------- inline functions ----------------------------
783
784 template <typename NumberType>
785 inline NumberType
786 ScaLAPACKMatrix<NumberType>::local_el(const unsigned int loc_row,
787 const unsigned int loc_column) const
788 {
789 return values[loc_column * n_local_rows + loc_row];
790 // return (*this)(loc_row, loc_column);
791 }
792
793
794
795 template <typename NumberType>
796 inline NumberType &
797 ScaLAPACKMatrix<NumberType>::local_el(const unsigned int loc_row,
798 const unsigned int loc_column)
799 {
800 return values[loc_column * n_local_rows + loc_row];
801 // return (*this)(loc_row, loc_column);
802 }
803
804
805 template <typename NumberType>
806 inline unsigned int
808 {
809 return n_rows;
810 }
811
812
813
814 template <typename NumberType>
815 inline unsigned int
817 {
818 return n_columns;
819 }
820
821
822
823 template <typename NumberType>
824 unsigned int
826 {
827 return n_local_rows;
828 }
829
830
831
832 template <typename NumberType>
833 unsigned int
835 {
836 return n_local_columns;
837 }
838
839 } // namespace linearAlgebra
840} // namespace dftefe
842#endif // ScaLAPACKMatrix_h
Scalapack wrapper adapted from dealii library and extended implementation to complex datatype.
Definition: ScalapackWrapper.h:43
void zmult(const NumberType b, const ScaLAPACKMatrix< NumberType > &B, const NumberType c, ScaLAPACKMatrix< NumberType > &C, const bool conjugate_transpose_A=false, const bool conjugate_transpose_B=false) const
Definition: ScalapackWrapper.t.cpp:710
ScalapackError compute_cholesky_factorization()
Definition: ScalapackWrapper.t.cpp:979
unsigned int global_column(const unsigned int loc_column) const
Definition: ScalapackWrapper.t.cpp:205
LAPACKSupport::State get_state() const
Definition: ScalapackWrapper.t.cpp:178
const char uplo
Definition: ScalapackWrapper.h:755
void zCmCmult(ScaLAPACKMatrix< NumberType > &C, const ScaLAPACKMatrix< NumberType > &B, const bool adding=false) const
Definition: ScalapackWrapper.t.cpp:967
std::vector< double > eigenpairs_hermitian_MRRR(const bool compute_eigenvectors, ScalapackError &scalapackError, const std::pair< unsigned int, unsigned int > &index_limits=std::make_pair(std::numeric_limits< unsigned int >::max(), std::numeric_limits< unsigned int >::max()), const std::pair< double, double > &value_limits=std::make_pair(std::numeric_limits< double >::quiet_NaN(), std::numeric_limits< double >::quiet_NaN()))
Definition: ScalapackWrapper.t.cpp:1594
void mTmult(ScaLAPACKMatrix< NumberType > &C, const ScaLAPACKMatrix< NumberType > &B, const bool adding=false) const
Definition: ScalapackWrapper.t.cpp:898
void zadd(const ScaLAPACKMatrix< NumberType > &B, const NumberType a=0., const NumberType b=1., const bool conjugate_transpose_B=false)
Definition: ScalapackWrapper.t.cpp:470
void TmTmult(ScaLAPACKMatrix< NumberType > &C, const ScaLAPACKMatrix< NumberType > &B, const bool adding=false) const
Definition: ScalapackWrapper.t.cpp:912
LAPACKSupport::Property get_property() const
Definition: ScalapackWrapper.t.cpp:170
int n_local_rows
Definition: ScalapackWrapper.h:723
size_type m() const
Definition: ScalapackWrapper.h:807
void copy_conjugate_transposed(const ScaLAPACKMatrix< NumberType > &B)
Definition: ScalapackWrapper.t.cpp:550
int n_columns
Definition: ScalapackWrapper.h:708
const int submatrix_row
Definition: ScalapackWrapper.h:773
void reinit(const size_type n_rows, const size_type n_columns, const std::shared_ptr< const 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: ScalapackWrapper.t.cpp:71
std::vector< double > eigenpairs_hermitian(const bool compute_eigenvectors, ScalapackError &scalapackError, const std::pair< unsigned int, unsigned int > &index_limits=std::make_pair(std::numeric_limits< unsigned int >::max(), std::numeric_limits< unsigned int >::max()), const std::pair< double, double > &value_limits=std::make_pair(std::numeric_limits< double >::quiet_NaN(), std::numeric_limits< double >::quiet_NaN()))
Definition: ScalapackWrapper.t.cpp:1238
void scale_rows_realfactors(const std::vector< double > &factors)
Definition: ScalapackWrapper.t.cpp:1884
LAPACKSupport::State state
Definition: ScalapackWrapper.h:685
const int first_process_column
Definition: ScalapackWrapper.h:767
std::shared_ptr< const ProcessGrid > grid
Definition: ScalapackWrapper.h:698
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: ScalapackWrapper.t.cpp:558
void conjugate()
Definition: ScalapackWrapper.t.cpp:224
void scale_rows(const std::vector< NumberType > &factors)
Definition: ScalapackWrapper.t.cpp:1845
void scale_columns(const std::vector< NumberType > &factors)
Definition: ScalapackWrapper.t.cpp:1825
int column_block_size
Definition: ScalapackWrapper.h:718
int n_local_columns
Definition: ScalapackWrapper.h:728
unsigned int local_n() const
Definition: ScalapackWrapper.h:834
NumberType local_el(const unsigned int loc_row, const unsigned int loc_column) const
Definition: ScalapackWrapper.h:786
std::vector< double > eigenpairs_hermitian_by_index_MRRR(const std::pair< unsigned int, unsigned int > &index_limits, const bool compute_eigenvectors, ScalapackError &scalapackError)
Definition: ScalapackWrapper.t.cpp:1569
std::vector< NumberType > values
Definition: ScalapackWrapper.h:679
int row_block_size
Definition: ScalapackWrapper.h:713
void copy_transposed(const ScaLAPACKMatrix< NumberType > &B)
Definition: ScalapackWrapper.t.cpp:542
void scale_columns_realfactors(const std::vector< double > &factors)
Definition: ScalapackWrapper.t.cpp:1864
void copy_to(ScaLAPACKMatrix< NumberType > &dest) const
Definition: ScalapackWrapper.t.cpp:247
const int first_process_row
Definition: ScalapackWrapper.h:761
int descriptor[9]
Definition: ScalapackWrapper.h:733
ScalapackError invert()
Definition: ScalapackWrapper.t.cpp:1069
void add(const ScaLAPACKMatrix< NumberType > &B, const NumberType a=0., const NumberType b=1., const bool transpose_B=false)
Definition: ScalapackWrapper.t.cpp:402
void set_property(const LAPACKSupport::Property property)
Definition: ScalapackWrapper.t.cpp:160
int n_rows
Definition: ScalapackWrapper.h:703
LAPACKSupport::Property property
Definition: ScalapackWrapper.h:691
void Tmmult(ScaLAPACKMatrix< NumberType > &C, const ScaLAPACKMatrix< NumberType > &B, const bool adding=false) const
Definition: ScalapackWrapper.t.cpp:884
unsigned int local_m() const
Definition: ScalapackWrapper.h:825
const int submatrix_column
Definition: ScalapackWrapper.h:779
size_type n() const
Definition: ScalapackWrapper.h:816
std::vector< int > ipiv
Definition: ScalapackWrapper.h:749
void zmmult(ScaLAPACKMatrix< NumberType > &C, const ScaLAPACKMatrix< NumberType > &B, const bool adding=false) const
Definition: ScalapackWrapper.t.cpp:925
void zmCmult(ScaLAPACKMatrix< NumberType > &C, const ScaLAPACKMatrix< NumberType > &B, const bool adding=false) const
Definition: ScalapackWrapper.t.cpp:953
unsigned int global_row(const unsigned int loc_row) const
Definition: ScalapackWrapper.t.cpp:186
void zCmmult(ScaLAPACKMatrix< NumberType > &C, const ScaLAPACKMatrix< NumberType > &B, const bool adding=false) const
Definition: ScalapackWrapper.t.cpp:939
void mmult(ScaLAPACKMatrix< NumberType > &C, const ScaLAPACKMatrix< NumberType > &B, const bool adding=false) const
Definition: ScalapackWrapper.t.cpp:870
std::vector< double > eigenpairs_hermitian_by_index(const std::pair< unsigned int, unsigned int > &index_limits, const bool compute_eigenvectors, ScalapackError &scalapackError)
Definition: ScalapackWrapper.t.cpp:1215
ScalapackError compute_lu_factorization()
Definition: ScalapackWrapper.t.cpp:1020
std::vector< NumberType > work
Definition: ScalapackWrapper.h:738
std::vector< int > iwork
Definition: ScalapackWrapper.h:743
Property
Definition: LapackSupport.h:92
@ general
No special properties.
Definition: LapackSupport.h:94
@ hermitian
Matrix is symmetric.
Definition: LapackSupport.h:96
State
Definition: LapackSupport.h:39
dealii includes
Definition: AtomFieldDataSpherical.cpp:31
unsigned int size_type
Definition: TypeConfig.h:8
Definition: LinearAlgebraTypes.h:133