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);











share|improve this question























  • 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_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











  • @PaulMcKenzie I know. Just wanted you to point it out ;)
    – Ripi2
    Nov 9 at 20:01














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);











share|improve this question























  • 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_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











  • @PaulMcKenzie I know. Just wanted you to point it out ;)
    – Ripi2
    Nov 9 at 20:01












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);











share|improve this question















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






share|improve this question















share|improve this question













share|improve this question




share|improve this question








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










  • @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











  • @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]; -- 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










  • @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















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












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).






share|improve this answer




















  • 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










Your Answer






StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");

StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);

else
createEditor();

);

function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);



);













 

draft saved


draft discarded


















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

























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).






share|improve this answer




















  • 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














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).






share|improve this answer




















  • 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












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).






share|improve this answer












Seems like you don't have the proper dimensions for AB. According to the documentation, the size is (LDAB,N), not (KD,N).







share|improve this answer












share|improve this answer



share|improve this answer










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
















  • 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

















 

draft saved


draft discarded















































 


draft saved


draft discarded














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





















































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







Popular posts from this blog

Kleinkühnau

Makov (Slowakei)

Deutsches Schauspielhaus