Segmentation fault when using dpbtrf
up vote
-1
down vote
favorite
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);
c++ lapack scientific-computing lapacke
|
show 3 more comments
up vote
-1
down vote
favorite
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);
c++ lapack scientific-computing lapacke
double AB[N * KD]warning: ISO C++ forbids variable length array. Don't rely on a compiler extension and use a pointer (with 'new') instead.
– Ripi2
Nov 9 at 19:53
double AB[N * KD];-- Don't do this. Do this:std::vector<double> AB(N * KD);. This probably doesn't fix your issue, but at least your code is now C++ compliant.
– PaulMcKenzie
Nov 9 at 19:56
@PaulMcKenzieLAPACKE_dpbtrfwants adouble *See src
– Ripi2
Nov 9 at 19:59
@Ripi2 -- A vector has a data member function that provides thedouble *you're speaking of.
– PaulMcKenzie
Nov 9 at 20:00
@PaulMcKenzie I know. Just wanted you to point it out ;)
– Ripi2
Nov 9 at 20:01
|
show 3 more comments
up vote
-1
down vote
favorite
up vote
-1
down vote
favorite
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);
c++ lapack scientific-computing lapacke
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);
c++ lapack scientific-computing lapacke
c++ lapack scientific-computing lapacke
edited Nov 9 at 19:51
asked Nov 9 at 19:36
Alex
3,22021530
3,22021530
double AB[N * KD]warning: ISO C++ forbids variable length array. Don't rely on a compiler extension and use a pointer (with 'new') instead.
– Ripi2
Nov 9 at 19:53
double AB[N * KD];-- Don't do this. Do this:std::vector<double> AB(N * KD);. This probably doesn't fix your issue, but at least your code is now C++ compliant.
– PaulMcKenzie
Nov 9 at 19:56
@PaulMcKenzieLAPACKE_dpbtrfwants adouble *See src
– Ripi2
Nov 9 at 19:59
@Ripi2 -- A vector has a data member function that provides thedouble *you're speaking of.
– PaulMcKenzie
Nov 9 at 20:00
@PaulMcKenzie I know. Just wanted you to point it out ;)
– Ripi2
Nov 9 at 20:01
|
show 3 more comments
double AB[N * KD]warning: ISO C++ forbids variable length array. Don't rely on a compiler extension and use a pointer (with 'new') instead.
– Ripi2
Nov 9 at 19:53
double AB[N * KD];-- Don't do this. Do this:std::vector<double> AB(N * KD);. This probably doesn't fix your issue, but at least your code is now C++ compliant.
– PaulMcKenzie
Nov 9 at 19:56
@PaulMcKenzieLAPACKE_dpbtrfwants adouble *See src
– Ripi2
Nov 9 at 19:59
@Ripi2 -- A vector has a data member function that provides thedouble *you're speaking of.
– PaulMcKenzie
Nov 9 at 20:00
@PaulMcKenzie I know. Just wanted you to point it out ;)
– Ripi2
Nov 9 at 20:01
double AB[N * KD] warning: ISO C++ forbids variable length array. Don't rely on a compiler extension and use a pointer (with 'new') instead.– Ripi2
Nov 9 at 19:53
double AB[N * KD] warning: ISO C++ forbids variable length array. Don't rely on a compiler extension and use a pointer (with 'new') instead.– Ripi2
Nov 9 at 19:53
double AB[N * KD]; -- Don't do this. Do this: std::vector<double> AB(N * KD);. This probably doesn't fix your issue, but at least your code is now C++ compliant.– PaulMcKenzie
Nov 9 at 19:56
double AB[N * KD]; -- Don't do this. Do this: std::vector<double> AB(N * KD);. This probably doesn't fix your issue, but at least your code is now C++ compliant.– PaulMcKenzie
Nov 9 at 19:56
@PaulMcKenzie
LAPACKE_dpbtrf wants a double * See src– Ripi2
Nov 9 at 19:59
@PaulMcKenzie
LAPACKE_dpbtrf wants a double * See src– Ripi2
Nov 9 at 19:59
@Ripi2 -- A vector has a data member function that provides the
double * you're speaking of.– PaulMcKenzie
Nov 9 at 20:00
@Ripi2 -- A vector has a data member function that provides the
double * you're speaking of.– PaulMcKenzie
Nov 9 at 20:00
@PaulMcKenzie I know. Just wanted you to point it out ;)
– Ripi2
Nov 9 at 20:01
@PaulMcKenzie I know. Just wanted you to point it out ;)
– Ripi2
Nov 9 at 20:01
|
show 3 more comments
1 Answer
1
active
oldest
votes
up vote
1
down vote
accepted
Seems like you don't have the proper dimensions for AB. According to the documentation, the size is (LDAB,N), not (KD,N).
Thanks for pointing out this mistake. However, I still do not get the desired result.
– Alex
Nov 9 at 20:21
You mean, it still crashes?
– Matthieu Brucher
Nov 9 at 20:22
No, but there is still something wrong.
– Alex
Nov 9 at 20:22
You may want to post a new question then, if it's not obvious like a row/column issue.
– Matthieu Brucher
Nov 9 at 20:23
1
Perhaps you are right. But since the compile error is gone I can try to find the solution myself.
– Alex
Nov 9 at 20:39
add a comment |
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
1
down vote
accepted
Seems like you don't have the proper dimensions for AB. According to the documentation, the size is (LDAB,N), not (KD,N).
Thanks for pointing out this mistake. However, I still do not get the desired result.
– Alex
Nov 9 at 20:21
You mean, it still crashes?
– Matthieu Brucher
Nov 9 at 20:22
No, but there is still something wrong.
– Alex
Nov 9 at 20:22
You may want to post a new question then, if it's not obvious like a row/column issue.
– Matthieu Brucher
Nov 9 at 20:23
1
Perhaps you are right. But since the compile error is gone I can try to find the solution myself.
– Alex
Nov 9 at 20:39
add a comment |
up vote
1
down vote
accepted
Seems like you don't have the proper dimensions for AB. According to the documentation, the size is (LDAB,N), not (KD,N).
Thanks for pointing out this mistake. However, I still do not get the desired result.
– Alex
Nov 9 at 20:21
You mean, it still crashes?
– Matthieu Brucher
Nov 9 at 20:22
No, but there is still something wrong.
– Alex
Nov 9 at 20:22
You may want to post a new question then, if it's not obvious like a row/column issue.
– Matthieu Brucher
Nov 9 at 20:23
1
Perhaps you are right. But since the compile error is gone I can try to find the solution myself.
– Alex
Nov 9 at 20:39
add a comment |
up vote
1
down vote
accepted
up vote
1
down vote
accepted
Seems like you don't have the proper dimensions for AB. According to the documentation, the size is (LDAB,N), not (KD,N).
Seems like you don't have the proper dimensions for AB. According to the documentation, the size is (LDAB,N), not (KD,N).
answered Nov 9 at 19:48
Matthieu Brucher
6,5941331
6,5941331
Thanks for pointing out this mistake. However, I still do not get the desired result.
– Alex
Nov 9 at 20:21
You mean, it still crashes?
– Matthieu Brucher
Nov 9 at 20:22
No, but there is still something wrong.
– Alex
Nov 9 at 20:22
You may want to post a new question then, if it's not obvious like a row/column issue.
– Matthieu Brucher
Nov 9 at 20:23
1
Perhaps you are right. But since the compile error is gone I can try to find the solution myself.
– Alex
Nov 9 at 20:39
add a comment |
Thanks for pointing out this mistake. However, I still do not get the desired result.
– Alex
Nov 9 at 20:21
You mean, it still crashes?
– Matthieu Brucher
Nov 9 at 20:22
No, but there is still something wrong.
– Alex
Nov 9 at 20:22
You may want to post a new question then, if it's not obvious like a row/column issue.
– Matthieu Brucher
Nov 9 at 20:23
1
Perhaps you are right. But since the compile error is gone I can try to find the solution myself.
– Alex
Nov 9 at 20:39
Thanks for pointing out this mistake. However, I still do not get the desired result.
– Alex
Nov 9 at 20:21
Thanks for pointing out this mistake. However, I still do not get the desired result.
– Alex
Nov 9 at 20:21
You mean, it still crashes?
– Matthieu Brucher
Nov 9 at 20:22
You mean, it still crashes?
– Matthieu Brucher
Nov 9 at 20:22
No, but there is still something wrong.
– Alex
Nov 9 at 20:22
No, but there is still something wrong.
– Alex
Nov 9 at 20:22
You may want to post a new question then, if it's not obvious like a row/column issue.
– Matthieu Brucher
Nov 9 at 20:23
You may want to post a new question then, if it's not obvious like a row/column issue.
– Matthieu Brucher
Nov 9 at 20:23
1
1
Perhaps you are right. But since the compile error is gone I can try to find the solution myself.
– Alex
Nov 9 at 20:39
Perhaps you are right. But since the compile error is gone I can try to find the solution myself.
– Alex
Nov 9 at 20:39
add a comment |
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53232240%2fsegmentation-fault-when-using-dpbtrf%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
double AB[N * KD]warning: ISO C++ forbids variable length array. Don't rely on a compiler extension and use a pointer (with 'new') instead.– Ripi2
Nov 9 at 19:53
double AB[N * KD];-- Don't do this. Do this:std::vector<double> AB(N * KD);. This probably doesn't fix your issue, but at least your code is now C++ compliant.– PaulMcKenzie
Nov 9 at 19:56
@PaulMcKenzie
LAPACKE_dpbtrfwants adouble *See src– Ripi2
Nov 9 at 19:59
@Ripi2 -- A vector has a data member function that provides the
double *you're speaking of.– PaulMcKenzie
Nov 9 at 20:00
@PaulMcKenzie I know. Just wanted you to point it out ;)
– Ripi2
Nov 9 at 20:01