1
$\begingroup$

I am having trouble with a C program that uses the function dsysv from LAPACK. Everything compiles and works without any errors, my only problem is, that the routine doesn't chance any of the arrays it is supposed to. The code (only hardcode for test purposes):

#include <iostream>
using namespace std;

extern "C" {
extern int dsysv_( char*, int* , int* , double* ,int*,int*, double*,int*,             double* ,int* ,int *); 
}  

int main() {

int n=3;
int nrhs=1;
int lda= 3;
int ldb=3;
int ipiv[3]={0,0,0}; 
    double a[3*3] = {
    1,2,3,
    0,4,5,
    0,0,6
    };
double b[3]={1,2,3};
int info=42;
int lwork=-1;
double work[1]={0};
char uplo='U';

dsysv_(&uplo,  &n, &nrhs, a, &lda,  ipiv, b,  &ldb, work, &lwork, &info);

cout<<"info: "<<info<<endl;
for(int i=0; i<3; i++){
    cout<<b[i]<<" ";
}
cout <<endl<<"and A: "<<endl;
for(int i=0; i<9; i++){
    cout<<a[i]<<" ";
}

return 1;
}

which returns:

info: 0

1 2 3 

and A: 

1 2 3 0 4 5 0 0 6 

Although the function is supposed to overwrite a and b. I think I miss something really obvious here, which I am not aware of since I just started working with LAPACK and would appreciate any help with it.

$\endgroup$
2
$\begingroup$
  • Set lwork to 1. (By using -1, LAPACK does not do any computation. It returns the optimal size for work).
  • Set uplo to 'L' (Your definition of a actually fills the lower part. You have in C double a[3*3] = {a_{11}, a_{21}, a_{31}, a_{12}, a_{22}, a_{32}, a_{13}, a_{23}, a_{33}};)
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.