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:
48 using size_type_scalapack = unsigned int;
60 const std::shared_ptr<const ProcessGrid> &process_grid,
65
76 const std::shared_ptr<const ProcessGrid> &process_grid,
77 const size_type_scalapack block_size = 32,
80
84 ~ScaLAPACKMatrix() = default;
85
95 void
98 const std::shared_ptr<const ProcessGrid> &process_grid,
103
112 void
113 reinit(const size_type_scalapack size,
114 const std::shared_ptr<const ProcessGrid> &process_grid,
115 const size_type_scalapack block_size = 32,
118
119
123 void
125
130 get_property() const;
131
136 get_state() const;
137
138
144 void
146
147
151 void
152 conjugate();
153
154
167 void
169 const NumberType a = 0.,
170 const NumberType b = 1.,
171 const bool transpose_B = false);
172
173
186 void
188 const NumberType a = 0.,
189 const NumberType b = 1.,
190 const bool conjugate_transpose_B = false);
191
201 void
203
204
214 void
216
237 void
238 mult(const NumberType b,
240 const NumberType c,
242 const bool transpose_A = false,
243 const bool transpose_B = false) const;
244
245
266 void
267 zmult(const NumberType b,
269 const NumberType c,
271 const bool conjugate_transpose_A = false,
272 const bool conjugate_transpose_B = false) const;
273
274
292 void
295 const bool adding = false) const;
296
315 void
318 const bool adding = false) const;
319
338 void
341 const bool adding = false) const;
342
362 void
365 const bool adding = false) const;
366
367
385 void
388 const bool adding = false) const;
389
408 void
411 const bool adding = false) const;
412
432 void
435 const bool adding = false) const;
436
457 void
460 const bool adding = false) const;
461
462
467 m() const;
468
473 n() const;
474
478 unsigned int
479 local_m() const;
480
484 unsigned int
485 local_n() const;
486
490 unsigned int
491 global_row(const unsigned int loc_row) const;
492
496 unsigned int
497 global_column(const unsigned int loc_column) const;
498
502 NumberType
503 local_el(const unsigned int loc_row, const unsigned int loc_column) const;
504
508 NumberType &
509 local_el(const unsigned int loc_row, const unsigned int loc_column);
510
518
526
540 invert();
541
549 void
550 scale_columns(const std::vector<NumberType> &factors);
551
559 void
560 scale_rows(const std::vector<NumberType> &factors);
561
562
570 void
571 scale_columns_realfactors(const std::vector<double> &factors);
572
580 void
581 scale_rows_realfactors(const std::vector<double> &factors);
582
598 std::vector<double>
600 const std::pair<unsigned int, unsigned int> &index_limits,
601 const bool compute_eigenvectors,
602 ScalapackError & scalapackError);
603
620 std::vector<double>
622 const std::pair<unsigned int, unsigned int> &index_limits,
623 const bool compute_eigenvectors,
624 ScalapackError & scalapackError);
625
626 private:
637 std::vector<double>
639 const bool compute_eigenvectors,
640 ScalapackError & scalapackError,
641 const std::pair<unsigned int, unsigned int> &index_limits =
642 std::make_pair(std::numeric_limits<unsigned int>::max(),
643 std::numeric_limits<unsigned int>::max()),
644 const std::pair<double, double> &value_limits =
645 std::make_pair(std::numeric_limits<double>::quiet_NaN(),
646 std::numeric_limits<double>::quiet_NaN()));
647
668 std::vector<double>
670 const bool compute_eigenvectors,
671 ScalapackError & scalapackError,
672 const std::pair<unsigned int, unsigned int> &index_limits =
673 std::make_pair(std::numeric_limits<unsigned int>::max(),
674 std::numeric_limits<unsigned int>::max()),
675 const std::pair<double, double> &value_limits =
676 std::make_pair(std::numeric_limits<double>::quiet_NaN(),
677 std::numeric_limits<double>::quiet_NaN()));
678
679
683 std::vector<NumberType> values;
684
690
696
702 std::shared_ptr<const ProcessGrid> grid;
703
708
713
718
723
728
733
738
742 mutable std::vector<NumberType> work;
743
747 mutable std::vector<int> iwork;
748
753 std::vector<int> ipiv;
754
759 const char uplo;
760
766
772
777 const int submatrix_row;
778
784 };
785
786 // ----------------------- inline functions ----------------------------
787
788 template <typename NumberType>
789 inline NumberType
790 ScaLAPACKMatrix<NumberType>::local_el(const unsigned int loc_row,
791 const unsigned int loc_column) const
792 {
793 return values[loc_column * n_local_rows + loc_row];
794 // return (*this)(loc_row, loc_column);
795 }
796
797
798
799 template <typename NumberType>
800 inline NumberType &
801 ScaLAPACKMatrix<NumberType>::local_el(const unsigned int loc_row,
802 const unsigned int loc_column)
803 {
804 return values[loc_column * n_local_rows + loc_row];
805 // return (*this)(loc_row, loc_column);
806 }
807
808
809 template <typename NumberType>
810 inline unsigned int
812 {
813 return n_rows;
814 }
815
816
817
818 template <typename NumberType>
819 inline unsigned int
821 {
822 return n_columns;
823 }
824
825
826
827 template <typename NumberType>
828 unsigned int
830 {
831 return n_local_rows;
832 }
833
834
835
836 template <typename NumberType>
837 unsigned int
839 {
840 return n_local_columns;
841 }
842
843 } // namespace linearAlgebra
844} // namespace dftefe
846#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:738
ScalapackError compute_cholesky_factorization()
Definition: ScalapackWrapper.t.cpp:1019
unsigned int global_column(const unsigned int loc_column) const
Definition: ScalapackWrapper.t.cpp:206
LAPACKSupport::State get_state() const
Definition: ScalapackWrapper.t.cpp:178
const char uplo
Definition: ScalapackWrapper.h:759
void zCmCmult(ScaLAPACKMatrix< NumberType > &C, const ScaLAPACKMatrix< NumberType > &B, const bool adding=false) const
Definition: ScalapackWrapper.t.cpp:1007
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:1634
void mTmult(ScaLAPACKMatrix< NumberType > &C, const ScaLAPACKMatrix< NumberType > &B, const bool adding=false) const
Definition: ScalapackWrapper.t.cpp:938
void zadd(const ScaLAPACKMatrix< NumberType > &B, const NumberType a=0., const NumberType b=1., const bool conjugate_transpose_B=false)
Definition: ScalapackWrapper.t.cpp:480
void TmTmult(ScaLAPACKMatrix< NumberType > &C, const ScaLAPACKMatrix< NumberType > &B, const bool adding=false) const
Definition: ScalapackWrapper.t.cpp:952
LAPACKSupport::Property get_property() const
Definition: ScalapackWrapper.t.cpp:170
int n_local_rows
Definition: ScalapackWrapper.h:727
size_type_scalapack m() const
Definition: ScalapackWrapper.h:811
void copy_conjugate_transposed(const ScaLAPACKMatrix< NumberType > &B)
Definition: ScalapackWrapper.t.cpp:566
int n_columns
Definition: ScalapackWrapper.h:712
const int submatrix_row
Definition: ScalapackWrapper.h:777
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:1278
void scale_rows_realfactors(const std::vector< double > &factors)
Definition: ScalapackWrapper.t.cpp:1927
LAPACKSupport::State state
Definition: ScalapackWrapper.h:689
const int first_process_column
Definition: ScalapackWrapper.h:771
std::shared_ptr< const ProcessGrid > grid
Definition: ScalapackWrapper.h:702
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:574
void conjugate()
Definition: ScalapackWrapper.t.cpp:226
void scale_rows(const std::vector< NumberType > &factors)
Definition: ScalapackWrapper.t.cpp:1886
void scale_columns(const std::vector< NumberType > &factors)
Definition: ScalapackWrapper.t.cpp:1865
int column_block_size
Definition: ScalapackWrapper.h:722
int n_local_columns
Definition: ScalapackWrapper.h:732
unsigned int local_n() const
Definition: ScalapackWrapper.h:838
NumberType local_el(const unsigned int loc_row, const unsigned int loc_column) const
Definition: ScalapackWrapper.h:790
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:1609
std::vector< NumberType > values
Definition: ScalapackWrapper.h:683
int row_block_size
Definition: ScalapackWrapper.h:717
void copy_transposed(const ScaLAPACKMatrix< NumberType > &B)
Definition: ScalapackWrapper.t.cpp:558
void reinit(const size_type_scalapack n_rows, const size_type_scalapack n_columns, const std::shared_ptr< const ProcessGrid > &process_grid, const size_type_scalapack row_block_size=32, const size_type_scalapack column_block_size=32, const LAPACKSupport::Property property=LAPACKSupport::Property::general)
Definition: ScalapackWrapper.t.cpp:71
void scale_columns_realfactors(const std::vector< double > &factors)
Definition: ScalapackWrapper.t.cpp:1906
void copy_to(ScaLAPACKMatrix< NumberType > &dest) const
Definition: ScalapackWrapper.t.cpp:249
const int first_process_row
Definition: ScalapackWrapper.h:765
int descriptor[9]
Definition: ScalapackWrapper.h:737
ScalapackError invert()
Definition: ScalapackWrapper.t.cpp:1109
unsigned int size_type_scalapack
Definition: ScalapackWrapper.h:48
void add(const ScaLAPACKMatrix< NumberType > &B, const NumberType a=0., const NumberType b=1., const bool transpose_B=false)
Definition: ScalapackWrapper.t.cpp:406
void set_property(const LAPACKSupport::Property property)
Definition: ScalapackWrapper.t.cpp:160
int n_rows
Definition: ScalapackWrapper.h:707
LAPACKSupport::Property property
Definition: ScalapackWrapper.h:695
void Tmmult(ScaLAPACKMatrix< NumberType > &C, const ScaLAPACKMatrix< NumberType > &B, const bool adding=false) const
Definition: ScalapackWrapper.t.cpp:924
unsigned int local_m() const
Definition: ScalapackWrapper.h:829
const int submatrix_column
Definition: ScalapackWrapper.h:783
size_type_scalapack n() const
Definition: ScalapackWrapper.h:820
std::vector< int > ipiv
Definition: ScalapackWrapper.h:753
void zmmult(ScaLAPACKMatrix< NumberType > &C, const ScaLAPACKMatrix< NumberType > &B, const bool adding=false) const
Definition: ScalapackWrapper.t.cpp:965
void zmCmult(ScaLAPACKMatrix< NumberType > &C, const ScaLAPACKMatrix< NumberType > &B, const bool adding=false) const
Definition: ScalapackWrapper.t.cpp:993
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:979
void mmult(ScaLAPACKMatrix< NumberType > &C, const ScaLAPACKMatrix< NumberType > &B, const bool adding=false) const
Definition: ScalapackWrapper.t.cpp:910
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:1255
ScalapackError compute_lu_factorization()
Definition: ScalapackWrapper.t.cpp:1060
std::vector< NumberType > work
Definition: ScalapackWrapper.h:742
std::vector< int > iwork
Definition: ScalapackWrapper.h:747
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
Definition: LinearAlgebraTypes.h:133