Banded system solution from C using LAPACK DGBSV
I tried to find a similar thread related to this topic, but no one seems to care about tape systems (...)
I am interested in a strip pass matrix solution using LAPACK / ScaLAPACK from C code. First, I want to achieve a consistent solution using LAPACK before trying to do anything with ScaLAPACK.
Problem. The difference between row and column for both languages affects the process of my solution. Here's the system I intend to solve:
The following code converts this matrix to the LAPACK data structure specified in here .
int rr = 6; // Rank.
int kl = 2; // Number of lower diagonals.
int ku = 1; // Number of upper diagonals.
int nrhs = 1; // Number of RHS.
double vals[36] = {0.0, 0.0, 0.0, 0.0, 0.0, 0.0, // Req. ex. space.
0.0, 0.0, 0.0, 0.0, 0.0, 0.0, // Req. ex. space.
666.0, 0.0, 0.0, 0.0, 0.0, 22.5, // First up diag.
1.0, -50.0, -50.0, -50.0, -50.0, -2.6, // Main diagonal.
27.5, 27.5, 27.5, 27.5, 4.0, 666.0, // First low diag.
0.0, 0.0, 0.0, -1.0, 666.0, 666.0}; // 2nd low diag.
int lda = rr; // Leading dimension of the matrix.
int ipiv[6]; // Information on pivoting array.
double rhs[] = {1.0, 1.0, 1.0, 1.0, 1.0, 0.0}; // RHS.
int ldb = lda; // Leading dimension of the RHS.
int info = 0; // Evaluation variable for solution process.
int ii; // Iterator.
int jj; // Iterator.
dgbsv_(&rr, &kl, &ku, &nrhs, vals, &lda, ipiv, rhs, &ldb, &info);
printf("info = %d\n", info);
for (ii = 0; ii < ldb; ii++) {
printf("%f\n", rhs[ii]);
}
putchar('\n');
As I said, I am concerned that the way I was translating my matrix is wrong given the col-major nature as well as the indexed nature of Fortran as my solution gives:
[ejspeiro@node01 lapack-ex02]$ make runs
`pwd`/blogs < blogs.in
info = 1
1.000000
1.000000
1.000000
1.000000
1.000000
0.000000
The return value from Fortran info = 1
implies that the factorization is complete, but U(1,1) = 0
in the LU factorization A = LU
.
Any help is more than welcome.
Thanks, advanced!
Ok, I'll answer this to call it "solvable".
These files are functional code. I'm making it available, if someone has the same problem: decision striped system of equations using LAPACK with the C .
- https://dl.dropbox.com/u/5432016/banded/cmtk.h
- https://dl.dropbox.com/u/5432016/banded/blogs.c
And if anyone has any additional implementation suggestions, I would gladly welcome them!
My next step is to distribute the underlying matrices to be solved with ScaLAPACK.
Thank!
As you noticed, your matrix was entered in string format. By writing it in column major, the lines that we will visually match the columns:
double vals[36] = {0.0, 0.0, 0.0, 1.0, 27.5, 0.0,
0.0, 0.0, 0.0, -50.0, 27.5, 0.0,
0.0, 0.0, 22.5, -50.0, 27.5, 0.0,
0.0, 0.0, 22.5, -50.0, 27.5, -1.0,
0.0, 0.0, 22.5, -50.0, 4.0, 0.0,
0.0, 0.0, 22.5, -2.6, 0.0, 0.0};