I try to use the LAPACK routine dpbtrf
(Documentaton) in c++ but always get a segmentation fault. I am not sure how to pass the matrix LAPACKE_dpbtrf
and tried to replicate it from the few examples I found without success. How to make the code below work?
I want to compute the cholesky decomposition of the matrix
1 -0.9 0 0 0
-0.9 1.81 -0.9 0 0
0 -0.9 1.81 -0.9 0
0 0 -0.9 1.81 -0.9
0 0 0 -0.9 1.81
Here is what I tried:
#include<iostream>
#include<lapacke.h>
int main() {
lapack_int info;
lapack_int N = 5;
lapack_int KD = 1;
lapack_int LDAB = KD + 1;
double AB[N * KD] = {
1, 1.81, 1.81, 1.81, 1.81,
-0.9, -0.9, -0.9, -0.9, -0.9
};
info = LAPACKE_dpbtrf( LAPACK_COL_MAJOR, 'L', N, KD, AB, LDAB);
for(int i=0;i<N * KD; i++)
{
std::cout << AB[i] << std::endl;
}
return(info);
}
Seems like you don't have the proper dimensions for AB
. According to the documentation, the size is (LDAB,N), not (KD,N).