sisi4s
Loading...
Searching...
No Matches
ScaLapackHermitianEigenSystem.hpp
Go to the documentation of this file.
1#ifndef SCA_LAPACK_HERMITIAN_EIGEN_SYSTEM_DEFINED
2# define SCA_LAPACK_HERMITIAN_EIGEN_STSTEM_DEFINED
3
4# include <math/Complex.hpp>
6# include <extern/ScaLapack.hpp>
7
8namespace sisi4s {
9// base template
10template <typename F = double>
12
13// specialization for double
14template <>
16public:
19 : A(A_)
20 , U(U_)
21 , workCount(-1)
22 , work(nullptr) {
23 // TODO: check if matrix is quadratic
24 double optimalWork;
25 int offset(1);
26 int info;
27 pdsyev_("V",
28 "L",
29 &A->lens[0],
30 A->getLocalValues(),
31 &offset,
32 &offset,
33 A->getDescriptor(),
34 nullptr,
35 U->getLocalValues(),
36 &offset,
37 &offset,
38 U->getDescriptor(),
39 &optimalWork,
40 &workCount,
41 &info);
42 // TODO: check info
43 workCount = static_cast<int>(optimalWork + 0.5);
44 // allocate work:
45 work = new double[workCount];
46 }
47
49 if (work) delete[] work;
50 work = nullptr;
51 }
52
53 void solve(double *lambda) {
54 int offset(1);
55 int info;
56 pdsyev_("V",
57 "L",
58 &A->lens[0],
59 A->getLocalValues(),
60 &offset,
61 &offset,
62 A->getDescriptor(),
63 lambda,
64 U->getLocalValues(),
65 &offset,
66 &offset,
67 U->getDescriptor(),
68 work,
69 &workCount,
70 &info);
71 // TODO: check info
72 }
73
74protected:
78 double *work;
79};
80
81// specialization for complex
82template <>
84public:
87 : A(A_)
88 , U(U_)
89 , workCount(-1)
90 , realWorkCount(-1)
91 , work(nullptr)
92 , realWork(nullptr) {
93 // TODO: check if matrix is quadratic
94 complex optimalWork;
95 double optimalRealWork;
96 int offset(1);
97 int info;
98 pzheev_("V",
99 "L",
100 &A->lens[0],
101 A->getLocalValues(),
102 &offset,
103 &offset,
104 A->getDescriptor(),
105 nullptr,
106 U->getLocalValues(),
107 &offset,
108 &offset,
109 U->getDescriptor(),
110 &optimalWork,
111 &workCount,
112 &optimalRealWork,
113 &realWorkCount,
114 &info);
115 // TODO: check info
116 workCount = static_cast<int>(std::real(optimalWork) + 0.5);
117 realWorkCount = static_cast<int64_t>(optimalRealWork + 0.5);
118 // allocate work:
119 work = new complex[workCount];
120 // NOTE that realWorkCount actually refers to a number of complexes
121 realWork = new double[2 * realWorkCount];
122 }
123
125 if (work) delete[] work;
126 if (realWork) delete[] realWork;
127 work = nullptr;
128 realWork = nullptr;
129 }
130
131 void solve(double *lambda) {
132 int offset(1);
133 int info;
134 pzheev_("V",
135 "L",
136 &A->lens[0],
137 A->getLocalValues(),
138 &offset,
139 &offset,
140 A->getDescriptor(),
141 lambda,
142 U->getLocalValues(),
143 &offset,
144 &offset,
145 U->getDescriptor(),
146 work,
147 &workCount,
148 realWork,
149 &realWorkCount,
150 &info);
151 // TODO: check info
152 }
153
154protected:
157 int workCount, realWorkCount;
159 double *realWork;
160};
161} // namespace sisi4s
162
163#endif
void pdsyev_(const char *jobz, const char *upperLower, const int *m, const double *a, const int *ia, const int *ja, const int *desca, double *lambda, double *z, const int *iz, const int *jz, const int *descz, double *work, const int *lwork, int *info)
void pzheev_(const char *jobz, const char *upperLower, const int *m, const sisi4s::complex *a, const int *ia, const int *ja, const int *desca, double *lambda, sisi4s::complex *z, const int *iz, const int *jz, const int *descz, sisi4s::complex *work, const int *lwork, double *realWork, const int *lRealCount, int *info)
int realWorkCount
Definition ScaLapackHermitianEigenSystem.hpp:157
ScaLapackMatrix< complex > * U
Definition ScaLapackHermitianEigenSystem.hpp:156
void solve(double *lambda)
Definition ScaLapackHermitianEigenSystem.hpp:131
~ScaLapackHermitianEigenSystem()
Definition ScaLapackHermitianEigenSystem.hpp:124
complex * work
Definition ScaLapackHermitianEigenSystem.hpp:158
double * realWork
Definition ScaLapackHermitianEigenSystem.hpp:159
ScaLapackHermitianEigenSystem(ScaLapackMatrix< complex > const *A_, ScaLapackMatrix< complex > *U_)
Definition ScaLapackHermitianEigenSystem.hpp:85
ScaLapackMatrix< complex > const * A
Definition ScaLapackHermitianEigenSystem.hpp:155
ScaLapackHermitianEigenSystem(ScaLapackMatrix< double > const *A_, ScaLapackMatrix< double > *U_)
Definition ScaLapackHermitianEigenSystem.hpp:17
ScaLapackMatrix< double > const * A
Definition ScaLapackHermitianEigenSystem.hpp:75
~ScaLapackHermitianEigenSystem()
Definition ScaLapackHermitianEigenSystem.hpp:48
void solve(double *lambda)
Definition ScaLapackHermitianEigenSystem.hpp:53
int workCount
Definition ScaLapackHermitianEigenSystem.hpp:77
ScaLapackMatrix< double > * U
Definition ScaLapackHermitianEigenSystem.hpp:76
double * work
Definition ScaLapackHermitianEigenSystem.hpp:78
Definition ScaLapackHermitianEigenSystem.hpp:11
Definition ScaLapackMatrix.hpp:22
Definition Algorithm.hpp:10
Complex< real > complex
Definition Complex.hpp:17