- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi all, I'm new to MKL. I should admit that I'm not very familiar with the concepts of linkages between MKL and C++. It would be great if someone could give me some hints!
For example, I want to find the eigenvalues of a 2x2 non-symmetric real matrix. I would like to use the routine "dgeev" with C++ in Linux. Here is what I wrote:
#include // with MKL library included
using namespace std;
int main()
{
int n=2, lwork=-1, info;
double *a, *wr, *wi, *vl, *vr, *work;
a=new double[n*n];
a[0]=1.2; a[1]=2.3; a[2]=3.4; a[3]=4.5; // the 4 matrix elements
wr=new double;
wi=new double;
work=new double[1];
dgeev("N", "N", &n, a, &n, wr, wi, vl, &n, vr, &n, work, &lwork, &info);
cout << "eigenvalues(real part) = " << wr[0] << " " << wr[1] << " ";
cout << "eigenvalues(imag part) = " << wi[0] << " " << wi[1] << " ";
return 0;
}
Then I compiled and ran it. The actual eigenvalues should be non-zero real numbers, however the above program gave me all zeros. I have tried many modifications but it just gave zeros. Is there anything wrong with my codes?
Regards,
Wenling Chan
For example, I want to find the eigenvalues of a 2x2 non-symmetric real matrix. I would like to use the routine "dgeev" with C++ in Linux. Here is what I wrote:
#include
using namespace std;
int main()
{
int n=2, lwork=-1, info;
double *a, *wr, *wi, *vl, *vr, *work;
a=new double[n*n];
a[0]=1.2; a[1]=2.3; a[2]=3.4; a[3]=4.5; // the 4 matrix elements
wr=new double
wi=new double
work=new double[1];
dgeev("N", "N", &n, a, &n, wr, wi, vl, &n, vr, &n, work, &lwork, &info);
cout << "eigenvalues(real part) = " << wr[0] << " " << wr[1] << " ";
cout << "eigenvalues(imag part) = " << wi[0] << " " << wi[1] << " ";
return 0;
}
Then I compiled and ran it. The actual eigenvalues should be non-zero real numbers, however the above program gave me all zeros. I have tried many modifications but it just gave zeros. Is there anything wrong with my codes?
Regards,
Wenling Chan
Link Copied
1 Reply
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Quoting - chuenhung@hotmail.com
Hi all, I'm new to MKL. I should admit that I'm not very familiar with the concepts of linkages between MKL and C++. It would be great if someone could give me some hints!
For example, I want to find the eigenvalues of a 2x2 non-symmetric real matrix. I would like to use the routine "dgeev" with C++ in Linux. Here is what I wrote:
#include // with MKL library included
using namespace std;
int main()
{
int n=2, lwork=-1, info;
double *a, *wr, *wi, *vl, *vr, *work;
a=new double[n*n];
a[0]=1.2; a[1]=2.3; a[2]=3.4; a[3]=4.5; // the 4 matrix elements
wr=new double;
wi=new double;
work=new double[1];
dgeev("N", "N", &n, a, &n, wr, wi, vl, &n, vr, &n, work, &lwork, &info);
cout << "eigenvalues(real part) = " << wr[0] << " " << wr[1] << " ";
cout << "eigenvalues(imag part) = " << wi[0] << " " << wi[1] << " ";
return 0;
}
Then I compiled and ran it. The actual eigenvalues should be non-zero real numbers, however the above program gave me all zeros. I have tried many modifications but it just gave zeros. Is there anything wrong with my codes?
Regards,
Wenling Chan
For example, I want to find the eigenvalues of a 2x2 non-symmetric real matrix. I would like to use the routine "dgeev" with C++ in Linux. Here is what I wrote:
#include
using namespace std;
int main()
{
int n=2, lwork=-1, info;
double *a, *wr, *wi, *vl, *vr, *work;
a=new double[n*n];
a[0]=1.2; a[1]=2.3; a[2]=3.4; a[3]=4.5; // the 4 matrix elements
wr=new double
wi=new double
work=new double[1];
dgeev("N", "N", &n, a, &n, wr, wi, vl, &n, vr, &n, work, &lwork, &info);
cout << "eigenvalues(real part) = " << wr[0] << " " << wr[1] << " ";
cout << "eigenvalues(imag part) = " << wi[0] << " " << wi[1] << " ";
return 0;
}
Then I compiled and ran it. The actual eigenvalues should be non-zero real numbers, however the above program gave me all zeros. I have tried many modifications but it just gave zeros. Is there anything wrong with my codes?
Regards,
Wenling Chan
Setting lwork = -1 will only determine optimum size of work variable. You need to obtain the value of work returned by the function dgeev, then revise the values of work and lwork and re-run with appropriate values.
See MKL Reference guide for setting appropriate values of lwork.

Reply
Topic Options
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page