Let's say I want to use LAPACK to solve a system of linear equations in C (GCC). I set up the problem as follows:
/* Want to solve Ax=b */
int n = ...; // size
double *A = ...; // nxn matrix
double *b = ...; // length-n vector
int m = 1; // number of columns in b (needs to be in a variable)
double *pivot; // records pivoting
int info; // return value
Now it seems I can use one of three functions to solve this problem. The first one is this:
dgesv_( &n, &m, A, &n, pivot, b, &n, &info );
I was surprised to see that this did not require any #include
s, which seems... weird.
The second function has almost the same signature, except for the prefix LAPACK_
which I think causes less ambiguity and is possibly less error-prone:
#include <lapack/lapacke.h>
LAPACK_dgesv( &n, &m, A, &n, pivot, b, &n, &info );
Note that this requires me to include lapacke.h
.
The third function changes the signature somewhat by returning info
and not taking all arguments as pointers:
#include <lapack/lapacke.h>
info = LAPACKE_dgesv( LAPACK_COL_MAJOR, n, m, A, n, pivot, b, n);
Again, this function requires lapacke.h
. It also requires linking to an extra library with -llapacke
.
All three functions need -llapack
.
I'm trying to figure out the differences between these functions.
I did some snooping around and I found the following macros in lapacke.h
and related header files:
#define LAPACK_GLOBAL(name,NAME) name##_
#define LAPACK_dgesv LAPACK_GLOBAL(dgesv,DGESV)
So it seems that LAPACK_dgesv()
and dgesv_()
are different names for the exact same function.
However, it appears LAPACKE_dgesv()
is something else with possibly a different implementation, especially considering the fact it needs an extra library.
So my question is: what are the differences between these two functions?
The documentation says LAPACKE is a C interface for LAPACK, but then what about the function dgesv_()
?
Clearly I can use it normally without needing LAPACKE and without compiling anything in Fortran, so how is that different?
Thanks.
Update
Curiously, the function dgemm_()
(matrix multiplication) does not have any LAPACK_dgemm()
equivalent.
What's going on?