sisi4s
Loading...
Searching...
No Matches
ScaLapackSingularValueDecomposition.hpp
Go to the documentation of this file.
1#ifndef SCA_LAPACK_SINGULAR_VALUE_DECOMPOSITION_DEFINED
2#define SCA_LAPACK_SINGULAR_VALUE_DECOMPOSITION_DEFINED
3
4#include <math/Complex.hpp>
7
8namespace sisi4s {
9// base template
10template <typename F = double>
12
13// specialization for double
14template <>
16public:
20 : A(A_)
21 , U(U_)
22 , VT(VT_)
23 , workCount(-1)
24 , work(nullptr) {
25 double optimalWork;
26 int offset(1);
27 int info;
28 pdgesvd_("V",
29 "V",
30 &A->lens[0],
31 &A->lens[1],
32 A->getLocalValues(),
33 &offset,
34 &offset,
35 A->getDescriptor(),
36 nullptr,
37 U->getLocalValues(),
38 &offset,
39 &offset,
40 U->getDescriptor(),
41 VT->getLocalValues(),
42 &offset,
43 &offset,
44 VT->getDescriptor(),
45 &optimalWork,
46 &workCount,
47 &info);
48 // TODO: check info
49 workCount = static_cast<int>(optimalWork + 0.5);
50 // allocate work:
51 work = new double[workCount];
52 }
53
55 if (work) delete[] work;
56 work = nullptr;
57 }
58
59 void decompose(double *sigma) {
60 int offset(1);
61 int info;
62 pdgesvd_("V",
63 "V",
64 &A->lens[0],
65 &A->lens[1],
66 A->getLocalValues(),
67 &offset,
68 &offset,
69 A->getDescriptor(),
70 sigma,
71 U->getLocalValues(),
72 &offset,
73 &offset,
74 U->getDescriptor(),
75 VT->getLocalValues(),
76 &offset,
77 &offset,
78 VT->getDescriptor(),
79 work,
80 &workCount,
81 &info);
82 // TODO: check info
83 }
84
85protected:
89 double *work;
90};
91
92// specialization for complex
93template <>
95public:
99 : A(A_)
100 , U(U_)
101 , VT(VT_)
102 , workCount(-1)
103 , work(nullptr)
104 , realWork(nullptr) {
105 complex optimalWork;
106 double optimalRealWork;
107 int offset(1);
108 int info;
109 pzgesvd_("V",
110 "V",
111 &A->lens[0],
112 &A->lens[1],
113 A->getLocalValues(),
114 &offset,
115 &offset,
116 A->getDescriptor(),
117 nullptr,
118 U->getLocalValues(),
119 &offset,
120 &offset,
121 U->getDescriptor(),
122 VT->getLocalValues(),
123 &offset,
124 &offset,
125 VT->getDescriptor(),
126 &optimalWork,
127 &workCount,
128 &optimalRealWork,
129 &info);
130 // TODO: check info
131 workCount = static_cast<int>(std::real(optimalWork) + 0.5);
132 // allocate work:
133 work = new complex[workCount];
134 realWork = new double[static_cast<int64_t>(optimalRealWork + 0.5)];
135 }
136
138 if (work) delete[] work;
139 if (realWork) delete[] realWork;
140 work = nullptr;
141 realWork = nullptr;
142 }
143 void decompose(double *sigma) {
144 int offset(1);
145 int info;
146 pzgesvd_("V",
147 "V",
148 &A->lens[0],
149 &A->lens[1],
150 A->getLocalValues(),
151 &offset,
152 &offset,
153 A->getDescriptor(),
154 sigma,
155 U->getLocalValues(),
156 &offset,
157 &offset,
158 U->getDescriptor(),
159 VT->getLocalValues(),
160 &offset,
161 &offset,
162 VT->getDescriptor(),
163 work,
164 &workCount,
165 realWork,
166 &info);
167 // TODO: check info
168 }
169
170protected:
175 double *realWork;
176};
177} // namespace sisi4s
178
179#endif
void pdgesvd_(const char *jobu, const char *jobvt, const int *m, const int *n, const double *a, const int *ia, const int *ja, const int *desca, double *s, double *u, const int *iu, const int *ju, const int *descu, double *vt, const int *ivt, const int *jvt, const int *descvt, double *work, const int *lwork, int *info)
void pzgesvd_(const char *jobu, const char *jobvt, const int *m, const int *n, const sisi4s::complex *a, const int *ia, const int *ja, const int *desca, double *s, sisi4s::complex *u, const int *iu, const int *ju, const int *descu, sisi4s::complex *vt, const int *ivt, const int *jvt, const int *descvt, sisi4s::complex *work, const int *lwork, double *rwork, int *info)
Definition ScaLapackMatrix.hpp:22
complex * work
Definition ScaLapackSingularValueDecomposition.hpp:174
void decompose(double *sigma)
Definition ScaLapackSingularValueDecomposition.hpp:143
ScaLapackMatrix< complex > const * A
Definition ScaLapackSingularValueDecomposition.hpp:171
~ScaLapackSingularValueDecomposition()
Definition ScaLapackSingularValueDecomposition.hpp:137
ScaLapackMatrix< complex > * U
Definition ScaLapackSingularValueDecomposition.hpp:172
ScaLapackSingularValueDecomposition(ScaLapackMatrix< complex > const *A_, ScaLapackMatrix< complex > *U_, ScaLapackMatrix< complex > *VT_)
Definition ScaLapackSingularValueDecomposition.hpp:96
double * realWork
Definition ScaLapackSingularValueDecomposition.hpp:175
int workCount
Definition ScaLapackSingularValueDecomposition.hpp:173
int workCount
Definition ScaLapackSingularValueDecomposition.hpp:88
ScaLapackMatrix< double > const * A
Definition ScaLapackSingularValueDecomposition.hpp:86
void decompose(double *sigma)
Definition ScaLapackSingularValueDecomposition.hpp:59
ScaLapackMatrix< double > * U
Definition ScaLapackSingularValueDecomposition.hpp:87
~ScaLapackSingularValueDecomposition()
Definition ScaLapackSingularValueDecomposition.hpp:54
ScaLapackSingularValueDecomposition(ScaLapackMatrix< double > const *A_, ScaLapackMatrix< double > *U_, ScaLapackMatrix< double > *VT_)
Definition ScaLapackSingularValueDecomposition.hpp:17
double * work
Definition ScaLapackSingularValueDecomposition.hpp:89
Definition ScaLapackSingularValueDecomposition.hpp:11
Definition Algorithm.hpp:10
Complex< real > complex
Definition Complex.hpp:17