HPhi++  3.1.0
matrixlapack.cpp File Reference

wrapper for linear algebra operations using lapack More...

#include "matrixlapack.hpp"
#include <cstdlib>

Go to the source code of this file.

Functions

int zheev_ (char *jobz, char *uplo, int *n, std::complex< double > *a, int *lda, double *w, std::complex< double > *work, int *lwork, double *rwork, int *info)
 
int dsyevx_ (char *jobz, char *range, char *uplo, int *n, double *a, int *lda, double *vl, double *vu, int *il, int *iu, double *abstol, int *m, double *w, double *z__, int *ldz, double *work, int *lwork, int *iwork, int *ifail, int *info)
 
int ZHEEVall (int xNsize, std::complex< double > **A, double *r, std::complex< double > **vec)
 obtain eigenvalues and eigenvectors of Hermite matrix A More...
 

Detailed Description

wrapper for linear algebra operations using lapack

Version
0.1, 0.2
Author
Takahiro Misawa (The University of Tokyo)

Definition in file matrixlapack.cpp.

Function Documentation

◆ dsyevx_()

int dsyevx_ ( char *  jobz,
char *  range,
char *  uplo,
int *  n,
double *  a,
int *  lda,
double *  vl,
double *  vu,
int *  il,
int *  iu,
double *  abstol,
int *  m,
double *  w,
double *  z__,
int *  ldz,
double *  work,
int *  lwork,
int *  iwork,
int *  ifail,
int *  info 
)

◆ zheev_()

int zheev_ ( char *  jobz,
char *  uplo,
int *  n,
std::complex< double > *  a,
int *  lda,
double *  w,
std::complex< double > *  work,
int *  lwork,
double *  rwork,
int *  info 
)

Referenced by ZHEEVall().

◆ ZHEEVall()

int ZHEEVall ( int  xNsize,
std::complex< double > **  A,
double *  r,
std::complex< double > **  vec 
)

obtain eigenvalues and eigenvectors of Hermite matrix A

Parameters
xNsizesize of matrix
Amatrix
reigenvalues
veceigenvectors
Returns
Author
Takahiro Misawa (The University of Tokyo)
Kazuyoshi Yoshimi (The University of Tokyo)

Definition at line 63 of file matrixlapack.cpp.

References zheev_(), and zheevd_().

Referenced by lapack_diag().

63  {
64 
65  int i, j, k;
66  char jobz, uplo;
67  int n, lda, lwork, info, lrwork;
68  double *rwork;
69  double *w;
70  std::complex<double> *a, *work;
71 #ifdef SR
72  int *iwork, liwork;
73  liwork = 5 * xNsize + 3;
74  iwork = (int*)malloc(liwork * sizeof(double));
75 #endif
76 
77  n = lda = xNsize;
78 #ifdef SR
79  lwork = xNsize * xNsize + 2 * xNsize; /* 3*xNsize OK?*/
80  lrwork = 2 * xNsize*xNsize + 5 * xNsize + 1;
81 #else
82  lwork = 4 * xNsize; /* 3*xNsize OK?*/
83  lrwork = lwork;
84 #endif
85 
86  a = (std::complex<double>*)malloc(xNsize*xNsize * sizeof(std::complex<double>));
87  w = (double*)malloc(xNsize * sizeof(double));
88  work = (std::complex<double>*)malloc(lwork * sizeof(std::complex<double>));
89  rwork = (double*)malloc(lrwork * sizeof(double));
90 
91  k = 0;
92  for (j = 0; j < xNsize; j++) {
93  for (i = 0; i < xNsize; i++) {
94  a[k] = A[i][j];
95  k++;
96  }
97  }
98 
99  jobz = 'V';
100  uplo = 'U';
101 
102 #ifdef SR
103  int zheevd_(char *jobz, char *uplo, int *n, std::complex<double> *a, int *lda, double *w, std::complex<double> *work, int *lwork, double *rwork, int *iwork, int *liwork, int *info);
104  free(iwork);
105 #else
106  zheev_(&jobz, &uplo, &n, a, &lda, w, work, &lwork, rwork, &info);
107 #endif
108 
109  if (info != 0) {
110  free(a);
111  free(w);
112  free(work);
113  free(rwork);
114  return 0;
115  }
116 
117  k = 0;
118  for (i = 0; i < xNsize; i++) {
119  for (j = 0; j < xNsize; j++) {
120  vec[j][i] = a[k];
121  k++;
122  }
123  }
124 
125 
126  for (k = 0; k < xNsize; k++) {
127  r[k] = w[k];
128  }
129 
130  free(a);
131  free(w);
132  free(work);
133  free(rwork);
134 
135  return 1;
136 }
int zheev_(char *jobz, char *uplo, int *n, std::complex< double > *a, int *lda, double *w, std::complex< double > *work, int *lwork, double *rwork, int *info)
void zheevd_(char *jobz, char *uplo, int *n, std::complex< double > *a, int *lda, double *w, std::complex< double > *work, int *lwork, double *rwork, int *lrwork, int *iwork, int *liwork, int *info)