- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I want to solve system of linear algebraic equations with function dgesv. I want to understand how to use MKL functions from C++, but all examples are written forFortran.
double a1[16]={1.80, 2.88, 2.05, -0.89,
5.25, -2.95, -0.95, -3.80,
1.58, -2.69, -2.90, -1.04,
-1.11, -0.66, -0.59, 0.80};
double b1[4]={9.52, 24.35, 0.77, -6.22};
int N1=1,info,Size=4;
int *ipiv = new int[Size];
dgesv(&Size,&N1,a1,&Size,ipiv,b1,&Size,&info);
Arrayb1 must contain solution of system (1,-1,3,-5), but it contains other values(-1.37, -9.78, 10.53, -42.06).
What's my mistake? May be, because ofindexing? (in C++ from 0, in Fortran from 1)
And I shoulddefine arrays a1 and b1as
double a1[16]={ 0, 0, 0, 0, 0,
0, 1.80, 2.88, 2.05, -0.89,
0, 5.25, -2.95, -0.95, -3.80,
0, 1.58, -2.69, -2.90, -1.04,
0, -1.11, -0.66, -0.59, 0.80};
double b1[4]={0, 9.52, 24.35, 0.77, -6.22};
Or not?
Link Copied
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I want to solve system of linear algebraic equations with function dgesv. I want to understand how to use MKL functions from C++, but all examples are written forFortran.
double a1[16]={1.80, 2.88, 2.05, -0.89,
5.25, -2.95, -0.95, -3.80,
1.58, -2.69, -2.90, -1.04,
-1.11, -0.66, -0.59, 0.80};
double b1[4]={9.52, 24.35, 0.77, -6.22};
int N1=1,info,Size=4;
int *ipiv = new int[Size];
dgesv(&Size,&N1,a1,&Size,ipiv,b1,&Size,&info);
Arrayb1 must contain solution of system (1,-1,3,-5), but it contains other values(-1.37, -9.78, 10.53, -42.06).
What's my mistake? May be, because ofindexing? (in C++ from 0, in Fortran from 1)
And I shoulddefine arrays a1 and b1as
double a1[16]={ 0, 0, 0, 0, 0,
0, 1.80, 2.88, 2.05, -0.89,
0, 5.25, -2.95, -0.95, -3.80,
0, 1.58, -2.69, -2.90, -1.04,
0, -1.11, -0.66, -0.59, 0.80};
double b1[4]={0, 9.52, 24.35, 0.77, -6.22};
Or not?
Hi,
I might be wrong but:
(1) dgesv is LAPACK function
(2) it takes a coefficient matrix, that is, A
(3) for LAPACK call consider matrix reordering (to Fortran style column-wise), passing first argument may go (may not?) into play.
(4) LAPACK also requires passing data by address and not value
All that is summarized, for example, here.
A.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content

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