Reputation: 2301
We want to solve x for Ax=b,
A=
0 2 3
1 1 -1
0 -1 1
b=
13
0
1
x=
1
2
3
The program below first writes A=P*L*U
. It works with columns. It is something like:
float a[3*3]={
0,1,0,
2,1,-1,
3,-1,1
};
float b[8]={
13,
0,
1
lapack_int n=3,lda=3,ldb=3,nrhs=1,info,piv[3];
info= LAPACKE_sgetrf(LAPACK_COL_MAJOR,n,n,a,lda,piv);
info= LAPACKE_sgetrs(LAPACK_COL_MAJOR,'N',n,nrhs,a,lda,piv,b,ldb);
This works. Now I would like to program with rows:
float a[3*3]={
0,2,3,
1,1,-1,
0,-1,1
};
float b[8]={
13,
0,
1
lapack_int n=3,lda=3,ldb=1,nrhs=1,info,piv[3];
info= LAPACKE_sgetrf(LAPACK_ROW_MAJOR,n,n,a,lda,piv);
info= LAPACKE_sgetrs(LAPACK_ROW_MAJOR,'N',n,nrhs,a,lda,piv,b,ldb);
My question is: why must ldb=1
(instead of 3)?
Upvotes: 1
Views: 99
Reputation: 9817
This behavior is due to the wrapper LAPACKE.
If LAPACK_COL_MAJOR
is used, the wrapper almost directly calls sgetrs()
of LAPACK, as shown in the source of LAPACKE. Hence, the leading dimension ldb
of the array b
must be equal or higher than the number of rows of the matrix a
, that is n=3
. Therefore, the requirement is LDB >= max(1,N)
as in sgetrs()
.
One the other hand, if LAPACK_ROW_MAJOR
is used, b
is transposed. Consequently, the leading dimension of the array ldb
is now related to the number of right hand sides nrhs=1
. The requirement is now LDB >= max(1,NRHS)
as tested on line 59 : if( ldb < nrhs )
. Then the array b
and the matrix are transposed by calling LAPACKE_sge_trans
. Finally, sgetrs()
is called using lbd=n
and the result is transposed back.
Upvotes: 1