Reputation: 717
I'm trying to solve some linear equation (which is symmetrical, tridiagonal and positive). I have to use LAPACKE. My code is as follows:
#include <lapacke.h>
#include <stdio.h>
void print_mtrx(double * mtrx, int n, int m)
{
int i, j;
for(i = 0; i < n; i++)
{
for(j = 0; j < m; j++)
{
printf("%f ", mtrx[i*m+j]);
}
printf("\n");
}
printf("\n");
}
int main()
{
double matrix[5*5] = {
2, 0, 0, 0, 0,
0, 2, 0, 0, 0,
0, 0, 2, 0, 0,
0, 0, 0, 2, 0,
0, 0, 0, 0, 2
};
double rozw[5] = {1,2,3,4,5};
double matrix2[5*5] = {
7, 0, 0, 0, 0,
0, 7, 0, 0, 0,
0, 0, 7, 0, 0,
0, 0, 0, 7, 0,
0, 0, 0, 0, 7
};
LAPACKE_dptsv(LAPACK_COL_MAJOR, 5, 5, matrix, matrix2, rozw, 5);
print_mtrx(matrix, 5, 5);
print_mtrx(matrix2, 5, 5);
print_mtrx(rozw, 5, 1);
}
LAPACKE's function seems to do nothing, without any errors. The main problem is, I have no idea what do the function parameters stand for. I've searched long, but there is no real documentation. Here is what I managed to found or guess:
How can I find real meaning of these arguments? How can I make my code work?
Upvotes: 2
Views: 1572
Reputation: 8966
When it comes to documentation for BLAS and/or LAPACK, Intel is probably the most comprehensive out there. You can look up the docs for ?ptsv, which explains what each parameter is for.
(Hint: when searching for a BLAS or LAPACK in Google, be sure to drop the s
/d
/c
/z
prefix.)
Here's the relevant snippet:
The routine solves for
X
the real or complex system of linear equationsA*X = B
, whereA
is ann
-by-n
symmetric/Hermitian positive-definite tridiagonal matrix, the columns of matrixB
are individual right-hand sides, and the columns ofX
are the corresponding solutions.
A
is factored asA = L*D*LT
(real flavors) orA = L*D*LH
(complex flavors), and the factored form ofA
is then used to solve the system of equationsA*X = B
.Input Parameters
n
: The order of matrixA
;n ≥ 0
.
nrhs
: The number of right-hand sides, the number of columns inB
;nrhs ≥ 0
.
d
: Array, dimension at leastmax(1, n)
. Contains the diagonal elements of the tridiagonal matrixA
.
e
,b
: Arrays:e(n - 1)
,b(ldb,*)
. The arraye
contains the(n - 1)
subdiagonal elements ofA
. The array b contains the matrixB
whose columns are the right-hand sides for the systems of equations. The second dimension ofb
must be at leastmax(1,nrhs)
.
ldb
: The leading dimension ofb
;ldb ≥ max(1, n)
.Output Parameters
d
: Overwritten by then
diagonal elements of the diagonal matrixD
from theL*D*LT
(real) /L*D*LH
(complex) factorization ofA
.
e
: Overwritten by the(n - 1)
subdiagonal elements of the unit bidiagonal factorL
from the factorization ofA
.
b
: Overwritten by the solution matrixX
.
info
: Ifinfo = 0
, the execution is successful. Ifinfo = -i
, thei
-th parameter had an illegal value. Ifinfo = i
, the leading minor of orderi
(and therefore the matrixA
itself) is not positive-definite, and the solution has not been computed. The factorization has not been completed unlessi = n
.
Upvotes: 1
Reputation: 717
So one must to look into documentation of pure LAPACK (http://www.netlib.org/lapack/explore-html/d0/dea/dptsv_8f.html#af1bd4c731915bd8755a4da8086fd79a8), and also ignore incorrect (in case of LAPACKE) remark that LDB be greater or equal max(1,N).
The correct program is as follows:
#include <lapacke.h>
#include <stdio.h>
void print_mtrx(double * mtrx, int n, int m)
{
int i, j;
for(i = 0; i < n; i++)
{
for(j = 0; j < m; j++)
{
printf("%f ", mtrx[i*m+j]);
}
printf("\n");
}
printf("\n");
}
int main()
{
double diagonal[5] = {5,1,5,1,5};
double subdiagonal[4] = {0,0,0,0};
double solution[5] = {1,2,3,4,5};
LAPACKE_dptsv(LAPACK_ROW_MAJOR, 5 /*size of matrix*/, 1 /*number of columns in solution*/,
diagonal, subdiagonal, solution, 1 /*leading dimension of solution vector*/);
print_mtrx(solution, 5, 1);
}
Upvotes: 2