开发者

My code crashes when calling the F77_NAME() function from the lapack library

I'm trying to call the F77_NAME(dgeqrf) function from lapack lib but the program crashes. What do you think it is wrong ?

#include <stdio.h>
#include <R.h>
#include <R_ext/BLAS.h>
#include <R_ext/Lapack.h>

double* getcopy(int开发者_如何转开发* nrow, int* ncol,double* a)
{
    double* copy = malloc(*nrow**ncol*sizeof(double));
    int i;
    for(i=0;i<*nrow**ncol;i++)
    {
        copy[i] = a[i];
    }
    return copy;
}

int main() {
int m=3,n=3;
double a[] = {12,-51,4,6,167,-68,-4,24,-41};
double* acopy = getcopy(&m,&n,a);

double tau[3];
int info=0;
int i;

int one=1;
double* work = malloc(max(&one,&m)*sizeof(double));
int lwork = 0;
int lda = max(&m,&n);

F77_NAME(dgeqrf)(&m,&n,acopy,&m,tau,work,&lwork,&info);

for(i=0;i<m*n;i++)
printf("%f",acopy[i]);

return 0;
}


From dgeqrf.f source code:


*  LWORK   (input) INTEGER
*          The dimension of the array WORK.  LWORK >= max(1,N).
*          For optimum performance LWORK >= N*NB, where NB is
*          the optimal blocksize.
*
*          If LWORK = -1, then a workspace query is assumed; the routine
*          only calculates the optimal size of the WORK array, returns
*          this value as the first entry of the WORK array, and no error
*          message related to LWORK is issued by XERBLA.

So if you want an optimal run you first need to call the function with 'lwork' set to -1 to get the optimal size of 'work'.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜