sisi4s
Loading...
Searching...
No Matches
ScaLapackHermitianEigenSystemDc.hpp
Go to the documentation of this file.
1#ifndef SCA_LAPACK_HERMITIAN_EIGEN_SYSTEM_DC_DEFINED
2# define SCA_LAPACK_HERMITIAN_EIGEN_STSTEM_DC_DEFINED
3
4# include <math/Complex.hpp>
6# include <extern/ScaLapack.hpp>
7# include <util/Exception.hpp>
8
9# include <memory>
10
11namespace sisi4s {
12// base template
13template <typename F = double>
15
16// specialization for double
17template <>
19public:
21 const std::shared_ptr<ScaLapackMatrix<double>> &A_,
22 const std::shared_ptr<ScaLapackMatrix<double>> &U_)
23 : A(A_)
24 , U(U_)
25 , workCount(-1)
26 , integerWorkCount(-1)
27 , work(nullptr)
28 , integerWork(nullptr) {
29 // TODO: check if matrix is quadratic
30 double optimalWork;
31 int optimalIntegerWork;
32 int offset(1);
33 int info;
34 pdsyevd_("V",
35 "L",
36 &A->lens[0],
37 A->getLocalValues(),
38 &offset,
39 &offset,
40 A->getDescriptor(),
41 nullptr,
42 U->getLocalValues(),
43 &offset,
44 &offset,
45 U->getDescriptor(),
46 &optimalWork,
47 &workCount,
48 &optimalIntegerWork,
49 &integerWorkCount,
50 &info);
51 if (info != 0) {
52 throw new EXCEPTION("ERROR: PDSYEVD initialization failed");
53 }
54 workCount = static_cast<int>(optimalWork + 0.5);
55 integerWorkCount = optimalIntegerWork;
56 // allocate work:
57 work = new double[workCount];
58 integerWork = new int[integerWorkCount];
59 }
60
62 if (work) delete[] work;
63 if (integerWork) delete[] integerWork;
64 work = nullptr;
65 integerWork = nullptr;
66 }
67
68 void solve(double *lambda) {
69 int offset(1);
70 int info;
71 pdsyevd_("V",
72 "L",
73 &A->lens[0],
74 A->getLocalValues(),
75 &offset,
76 &offset,
77 A->getDescriptor(),
78 lambda,
79 U->getLocalValues(),
80 &offset,
81 &offset,
82 U->getDescriptor(),
83 work,
84 &workCount,
85 integerWork,
86 &integerWorkCount,
87 &info);
88 if (info != 0) {
89 throw new EXCEPTION("ERROR: PDSYEVD diagonlization failed");
90 }
91 }
92
93protected:
94 std::shared_ptr<ScaLapackMatrix<double>> A, U;
95 int workCount, integerWorkCount;
96 double *work;
98};
99
100// specialization for complex
101template <>
103public:
105 const std::shared_ptr<ScaLapackMatrix<complex>> &A_,
106 const std::shared_ptr<ScaLapackMatrix<complex>> &U_)
107 : A(A_)
108 , U(U_)
109 , workCount(-1)
110 , realWorkCount(-1)
111 , integerWorkCount(-1)
112 , work(nullptr)
113 , realWork(nullptr)
114 , integerWork(nullptr) {
115 // TODO: check if matrix is quadratic
116 complex optimalWork;
117 double optimalRealWork;
118 int optimalIntegerWork;
119 int offset(1);
120 int info;
121 pzheevd_("V",
122 "L",
123 &A->lens[0],
124 A->getLocalValues(),
125 &offset,
126 &offset,
127 A->getDescriptor(),
128 nullptr,
129 U->getLocalValues(),
130 &offset,
131 &offset,
132 U->getDescriptor(),
133 &optimalWork,
134 &workCount,
135 &optimalRealWork,
136 &realWorkCount,
137 &optimalIntegerWork,
138 &integerWorkCount,
139 &info);
140 if (info != 0) {
141 throw new EXCEPTION("ERROR: PZHEEVD initialization failed");
142 }
143 workCount = static_cast<int>(std::real(optimalWork) + 0.5);
144 realWorkCount = static_cast<int64_t>(optimalRealWork + 0.5);
145 integerWorkCount = optimalIntegerWork;
146 // allocate work:
147 work = new complex[workCount];
148 // NOTE that realWorkCount actually refers to a number of complexes
149 realWork = new double[2 * realWorkCount];
150 integerWork = new int[integerWorkCount];
151 }
152
154 if (work) delete[] work;
155 if (realWork) delete[] realWork;
156 if (integerWork) delete[] integerWork;
157 work = nullptr;
158 realWork = nullptr;
159 integerWork = nullptr;
160 }
161
162 void solve(double *lambda) {
163 int offset(1);
164 int info;
165 pzheevd_("V",
166 "L",
167 &A->lens[0],
168 A->getLocalValues(),
169 &offset,
170 &offset,
171 A->getDescriptor(),
172 lambda,
173 U->getLocalValues(),
174 &offset,
175 &offset,
176 U->getDescriptor(),
177 work,
178 &workCount,
179 realWork,
180 &realWorkCount,
181 integerWork,
182 &integerWorkCount,
183 &info);
184 if (info != 0) {
185 throw new EXCEPTION("ERROR: PZHEEVD diagonlization failed");
186 }
187 }
188
189protected:
190 std::shared_ptr<ScaLapackMatrix<complex>> A, U;
191 int workCount, realWorkCount, integerWorkCount;
193 double *realWork;
195};
196} // namespace sisi4s
197
198#endif
#define EXCEPTION(message)
Definition Exception.hpp:8
void pdsyevd_(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 *iwork, const int *liwork, int *info)
void pzheevd_(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 *iwork, const int *liwork, int *info)
int integerWorkCount
Definition ScaLapackHermitianEigenSystemDc.hpp:191
std::shared_ptr< ScaLapackMatrix< complex > > A
Definition ScaLapackHermitianEigenSystemDc.hpp:190
int * integerWork
Definition ScaLapackHermitianEigenSystemDc.hpp:194
ScaLapackHermitianEigenSystemDc(const std::shared_ptr< ScaLapackMatrix< complex > > &A_, const std::shared_ptr< ScaLapackMatrix< complex > > &U_)
Definition ScaLapackHermitianEigenSystemDc.hpp:104
double * realWork
Definition ScaLapackHermitianEigenSystemDc.hpp:193
void solve(double *lambda)
Definition ScaLapackHermitianEigenSystemDc.hpp:162
complex * work
Definition ScaLapackHermitianEigenSystemDc.hpp:192
~ScaLapackHermitianEigenSystemDc()
Definition ScaLapackHermitianEigenSystemDc.hpp:153
std::shared_ptr< ScaLapackMatrix< double > > A
Definition ScaLapackHermitianEigenSystemDc.hpp:94
void solve(double *lambda)
Definition ScaLapackHermitianEigenSystemDc.hpp:68
int * integerWork
Definition ScaLapackHermitianEigenSystemDc.hpp:97
int integerWorkCount
Definition ScaLapackHermitianEigenSystemDc.hpp:95
~ScaLapackHermitianEigenSystemDc()
Definition ScaLapackHermitianEigenSystemDc.hpp:61
double * work
Definition ScaLapackHermitianEigenSystemDc.hpp:96
ScaLapackHermitianEigenSystemDc(const std::shared_ptr< ScaLapackMatrix< double > > &A_, const std::shared_ptr< ScaLapackMatrix< double > > &U_)
Definition ScaLapackHermitianEigenSystemDc.hpp:20
Definition ScaLapackHermitianEigenSystemDc.hpp:14
Definition ScaLapackMatrix.hpp:22
Definition Algorithm.hpp:10
Complex< real > complex
Definition Complex.hpp:17