-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmyLapack.cpp
32 lines (30 loc) · 985 Bytes
/
myLapack.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
#ifdef OSX
// #include <Accelerate/Accelerate.h>//On OSX
#include "lapack_wrapper.h"
#elif defined MKL
#include "mkl.h"
#endif
#include "myLapack.h"
void Diag(double* Kij, int N, double* Eig, double* EigVec)
{
memcpy(EigVec, Kij, N * N * sizeof(double));
int ldA = N;
int lwork = -1;
double worktest;
int info;
dsyev((char*)"V", (char*)"U", &N, EigVec, &ldA, Eig, &worktest, &lwork, &info);
if(info != 0){
std::ostringstream err;
err << "\nError in Lapack function 'dsyev': Lapack INFO = " << info << "\n";
throw std::runtime_error(err.str());
}
lwork = (int)worktest;
double* work= (double*)malloc(sizeof(double)*lwork);
dsyev((char*)"V", (char*)"U", &N, EigVec, &ldA, Eig, work, &lwork, &info);
if(info != 0){
std::ostringstream err;
err << "\n Error in Lapack function 'dsyev': Lapack INFO = " << info << "\n";
throw std::runtime_error(err.str());
}
free(work);
}