37 const double *diag,
const double *sdiag) {
40 char jobz = eigVec ?
'V' :
'N';
48 memcpy(alp, diag, n*
sizeof(
double));
49 memcpy(bet, sdiag, (n-1)*
sizeof(
double));
54 Malloc(work, 2*n-2,
double);
56 DSTEV(&jobz, &nn, alp, bet, sv, &ldz, work, &info);
63 printf(
"DSTEV ERROR: INFO %d\n", info);
93 int SymmTridEigS(
double *eigVal,
double *eigVec,
int n,
double vl,
double vu,
94 int *nevO,
const double *diag,
const double *sdiag) {
108 Malloc(work, lwork,
double);
112 Calloc(iwork, liwork,
int);
120 memcpy(alp, diag, n*
sizeof(
double));
122 memcpy(bet, sdiag, (n-1)*
sizeof(
double));
131 DSTEMR(&jobz, &range, &n, alp, bet, &t0, &t1, NULL, NULL, nevO,
132 eigVal, eigVec, &n, &n, isuppz, &tryrac, work, &lwork,
133 iwork, &liwork, &info);
136 printf(
"dstemr_ error %d\n", info);
156 void SymEigenSolver(
int n,
double *A,
int lda,
double *Q,
int ldq,
double *lam) {
165 for (i=0; i<n; i++) {
166 for (j=0; j<n; j++) {
167 Q[j+i*ldq] = A[j+i*lda];
172 int lwork = -1, info;
173 DSYEV(&jobz, &uplo, &n, Q, &ldq, lam, &work_size, &lwork, &info);
175 fprintf(stdout,
"DSYEV error [query call]: %d\n", info);
179 lwork = (int) work_size;
181 Malloc(work, lwork,
double);
182 DSYEV(&jobz, &uplo, &n, Q, &ldq, lam, work, &lwork, &info);
184 fprintf(stdout,
"DSYEV error [comp call]: %d\n", info);
195 void CGS_DGKS(
int n,
int k,
int i_max,
double *Q,
double *v,
double *nrmv,
double *w) {
197 double eta = 1.0 / sqrt(2.0);
200 char cT =
'T', cN =
'N';
201 double done=1.0, dmone=-1.0, dzero=0.0;
203 double old_nrm =
DNRM2(&n, v, &one);
204 double new_nrm = 0.0;
206 for (i=0; i<i_max; i++) {
208 DGEMV(&cT, &n, &k, &done, Q, &n, v, &one, &dzero, w, &one);
209 DGEMV(&cN, &n, &k, &dmone, Q, &n, w, &one, &done, v, &one);
212 for (j=0; j<k; j++) {
213 double t = -
DDOT(&n, &Q[j*n], &one, v, &one);
214 DAXPY(&n, &t, &Q[j*n], &one, v, &one);
217 new_nrm =
DNRM2(&n, v, &one);
218 if (new_nrm > eta * old_nrm) {
235 void CGS_DGKS2(
int n,
int k,
int i_max,
double *Z,
double *Q,
236 double *v,
double *w) {
240 char cT =
'T', cN =
'N';
241 double done=1.0, dmone=-1.0, dzero=0.0;
243 for (i=0; i<i_max; i++) {
245 DGEMV(&cT, &n, &k, &done, Q, &n, v, &one, &dzero, w, &one);
246 DGEMV(&cN, &n, &k, &dmone, Z, &n, w, &one, &done, v, &one);
249 for (j=0; j<k; j++) {
250 double t = -
DDOT(&n, &Q[j*n], &one, v, &one);
251 DAXPY(&n, &t, &Z[j*n], &one, v, &one);
269 void orth(
double *V,
int n,
int k,
double *Vo,
double *work) {
273 DCOPY(&nk, V, &one, Vo, &one);
274 double tt =
DDOT(&n, Vo, &one, Vo, &one);
275 double nrmv = sqrt(tt);
276 double t = 1.0 / nrmv;
277 DSCAL(&n, &t, Vo, &one);
278 for (i = 1; i < k; i++) {
282 DSCAL(&n, &t, Vo+istart, &one);
void SymEigenSolver(int n, double *A, int lda, double *Q, int ldq, double *lam)
interface to LAPACK SYMMETRIC EIGEN-SOLVER
void DSTEV(char *jobz, int *n, double *diagonal, double *subdiagonal, double *V, int *ldz, double *work, int *info)
double DDOT(int *n, double *x, int *incx, double *y, int *incy)
void CGS_DGKS(int n, int k, int i_max, double *Q, double *v, double *nrmv, double *w)
Classical GS reortho with Daniel, Gragg, Kaufman, Stewart test.
void save_vec(int n, const double *x, const char fn[])
void DSYEV(char *jobz, char *uplo, int *n, double *fa, int *lda, double *w, double *work, int *lwork, int *info)
void DSTEMR(char *jobz, char *range, int *n, double *D, double *E, double *VL, double *VU, int *IL, int *IU, int *M, double *W, double *Z, int *LDZ, int *NZC, int *ISUPPZ, logical *TRYRAC, double *WORK, int *LWORK, int *IWORK, int *LIWORK, int *INFO)
void DSCAL(int *n, double *a, double *x, int *incx)
#define Calloc(base, nmem, type)
int SymmTridEig(double *eigVal, double *eigVec, int n, const double *diag, const double *sdiag)
compute all eigenvalues and eigenvectors of a symmetric tridiagonal matrix
This file contains function prototypes and constant definitions internally used in EVSL...
void orth(double *V, int n, int k, double *Vo, double *work)
Orthogonalize columns of n-by-k matrix V.
#define Malloc(base, nmem, type)
void DGEMV(char *trans, int *m, int *n, double *alpha, double *a, int *lda, double *x, int *incx, double *beta, double *y, int *incy)
evslStat evslstat
global statistics of EVSL
void CGS_DGKS2(int n, int k, int i_max, double *Z, double *Q, double *v, double *w)
Classical GS reortho. No test. just do i_max times used in generalized ev problems.
void DAXPY(int *n, double *alpha, double *x, int *incx, double *y, int *incy)
double DNRM2(int *n, double *x, int *incx)
Defs for blaslapack routines.
int SymmTridEigS(double *eigVal, double *eigVec, int n, double vl, double vu, int *nevO, const double *diag, const double *sdiag)
compute eigenvalues and eigenvectors of a symmetric tridiagonal matrix in a slice ...
double evsl_timer()
evsl timer for mac
void DCOPY(int *n, double *dx, int *incx, double *dy, int *incy)