ATLAS: error when computing inverse of a matrix

30 Views Asked by At

I am getting an error while computing the inverse of a matrix using ATLAS library.

I get the error output:

On entry to DTRSM parameter number 9 had an illegal value
Aborted (core dumped)

I have a found this code from : https://cpp.hotexamples.com/examples/-/-/dgetrf_/cpp-dgetrf_-function-examples.html

I want to compute inverse of a 5x5 matrix using ATLAS library but I am unable to compute it because of the issue:

testinv.c:30:17: warning: implicit declaration of function 'dgetri_' is invalid in C99 [-Wimplicit-function-declaration] dgetri_ (&N,A,&N,IPIV,WORK,&LWORK,&INFO); ^

testinv.c:38:9: warning: implicit declaration of function 'dgetrf_' is invalid in C99 [-Wimplicit-function-declaration] dgetrf_ (&N,&N,A,&N,IPIV,&INFO); ^

testinv.c:40:17: warning: implicit declaration of function 'dgetri_' is invalid in C99 [-Wimplicit-function-declaration] dgetri_ (&N,A,&N,IPIV,WORK,&LWORK,&INFO); ^

3 warnings generated. cc -o testinv testinv.o -lm

On entry to DTRSM parameter number 9 had an illegal value
Aborted (core dumped)

This is my code:

#include<math.h>
#include<cblas.h>
#include<stdlib.h>

int main ( ){
        int INFO;
        int N;
        static int * IPIV=NULL;
        static int LWORK=0;
        static double * WORK=NULL;
        static int last_n=0;

        N = 25;
        double A[25] = {
                0.67, 0.00, 0.00, 0.00, 0.00,
               -0.20, 3.82, 0.00, 0.00, 0.00,
                0.19,-0.13, 3.27, 0.00, 0.00,
               -1.06, 1.06, 0.11, 5.86, 0.00,
                0.46,-0.48, 1.10,-0.98, 3.54
        };

        if ( N>last_n){
                if (NULL==IPIV){
                        WORK = malloc(sizeof(double));
                } else {
                        free(IPIV);
                }
                LWORK = -1;
                dgetri_ (&N,A,&N,IPIV,WORK,&LWORK,&INFO);
                LWORK=(int)WORK[0];
                free(WORK);
                WORK = malloc(LWORK*sizeof(double));
                IPIV = malloc(N*sizeof(int));
                last_n = N;
        }

        dgetrf_ (&N,&N,A,&N,IPIV,&INFO);
        if ( INFO==0){
                dgetri_ (&N,A,&N,IPIV,WORK,&LWORK,&INFO);
        }

        printf("INFO \n");
        return 0;
1

There are 1 best solutions below

0
AudioBubble On

From what I see, you're trying to use the ATLAS library but you're not including it when compiling. Take a look at this and let me know if it's still an issue: https://michaellindon.github.io/lindonslog/programming/atlas-blas-lapack-linear-algebra-libraries/index.html