Quantcast
Channel: Intel® Software - Intel® oneAPI Math Kernel Library & Intel® Math Kernel Library
Viewing all articles
Browse latest Browse all 3005

problem with the C interface to Lapack LU factorization

$
0
0

Hi,

I've written the following C code that should perform the LU factorization

of a general n x n matrix

#include <mkl.h>

#include "mkl_lapack.h"

#define N 3

double* A;
lapack_int n=N;
lapack_int* ipiv;

int main(){
    int i=0,j=0,ierr=0;
    A=malloc(n*n*sizeof(double));
    ipiv=malloc(n*sizeof(lapack_int));
    A[0]=1e0;A[1]=0e0;A[2]=0e0;
    A[3]=2e0;A[4]=3e0;A[5]=0e0;
    A[6]=4e0;A[7]=5e0;A[8]=6e0;
    ierr=LAPACKE_dgetrf(LAPACK_ROW_MAJOR,n,n,A,n,ipiv);
    for(i=0;i<n;i++){
        for(j=0;j<n;j++)
          printf("%f ",A[i*n+j]);
        printf("\n");
    }
    printf("ierr=%d\n",ierr);
    free(A);
    free(ipiv);
    return 0;
}

the result (computed with mathematica) should give for U the 3x3 diagonal matrix {1,3,6}

and for L={{1., 0., 0.}, {2., 1., 0.}, {4., 1.66667, 1.}}. However, the code seems to fail.

Am I doing some mistake?

Thank you!

F

 


Viewing all articles
Browse latest Browse all 3005

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>