[SOLVED] lapack code (in c++) crashes during runtime

Open discussion regarding features, bugs, issues, vendors, etc.

[SOLVED] lapack code (in c++) crashes during runtime

Postby eigenguy » Fri Jun 22, 2012 12:04 pm

Some functions work fine, but most functions don't. Here's a sample piece of code that fails during runtime:

#include <iostream>
#include <lapacke.h>

int main()
{
//test lapack

double a[2][2] = {3,4,2,3};



lapack_int n,m,lda,info1,info2;
lapack_int* ipiv;
double* work;

n = 2;
m = 2;
lda = 2;

std::cout << "test";

info1 = LAPACKE_dgetrf(LAPACK_ROW_MAJOR,m,n,*a,lda,ipiv);
std::cout << "test";
info2 = LAPACKE_dgetri(LAPACK_ROW_MAJOR,n,*a,lda,ipiv);

std::cout << "test";

int i,j;
for(int i=0; i<n; i++) {


for(j=0;j<n;j++) {

std::cout << a[i][j] << std::endl;
}

}

return(info1*info2);
}


------------------------------

There's no error message. I do see the first "test" message, but then it simply crashes. I'm using the MinGW compiler. Anyone ever had this issue before?
Last edited by eigenguy on Fri Jun 22, 2012 1:14 pm, edited 1 time in total.
eigenguy
 
Posts: 3
Joined: Thu Jun 21, 2012 6:27 pm

Re: lapack code (in c++) crashes during runtime

Postby admin » Fri Jun 22, 2012 12:20 pm

First, just to let your know that your code works on my machine (just needed a small modification) with GNU compilers.

Code: Select all
#include <iostream>
#include "lapacke.h"

int main()
{
//test lapack

double a[2][2] = {3,4,2,3};



lapack_int n,m,lda,info1,info2;
lapack_int ipiv[2];
double* work;

n = 2;
m = 2;
lda = 2;

std::cout << "test LAPACKE_dgetrf" << "\n";

info1 = LAPACKE_dgetrf(LAPACK_ROW_MAJOR,m,n,*a,lda,ipiv);
std::cout << "test LAPACKE_dgetri"<< "\n";
info2 = LAPACKE_dgetri(LAPACK_ROW_MAJOR,n,*a,lda,ipiv);

std::cout << "tests done"<< "\n";

int i,j;
for(int i=0; i<n; i++) {


for(j=0;j<n;j++) {

std::cout << a[i][j] << std::endl;
}

}

return(info1*info2);
}


Here is the result I got:
$ ./prog.exe
test LAPACKE_dgetrf
test LAPACKE_dgetri
tests done
3
-4
-2
3


I will try with the mingw compiler, but as they are GNU based, it should change anything.
admin
Site Admin
 
Posts: 501
Joined: Wed Dec 08, 2004 7:07 pm

Re: lapack code (in c++) crashes during runtime

Postby eigenguy » Fri Jun 22, 2012 12:44 pm

Thanks admin! It works when I instantiate ipiv as an array. =)
eigenguy
 
Posts: 3
Joined: Thu Jun 21, 2012 6:27 pm


Return to User Discussion

Who is online

Users browsing this forum: Bing [Bot], Google [Bot], Yahoo [Bot] and 3 guests