Why I can use the lapack in C without clapack

Open discussion regarding features, bugs, issues, vendors, etc.

Why I can use the lapack in C without clapack

Postby ruoshan » Tue Mar 08, 2011 9:17 am

On Debian squeeze.I compile the following code by:gcc -llapack tt.c
And It can run.why? Isn't it a must to have clapack for C?
==================== tt.c ======================
#include <stdio.h>
//#include "clapack.h"
void dgtsv_(const long *Np, const long *NRHSp, double *DL,
double *D, double *DU, double *B, const long *LDBp,
long *INFOp);
double l[] = {
-1, -2, -1, -1
};
double d[] = {
2, 2, 3, 3, 1
};
double u[] = {
-1, -1, -1, -2
};
double x[] = {
1, 2, 3, 2, 1
};
static long
dgtsv(long N, long NRHS, double *DL, double *D, double *DU, double *B,
long LDB){
//extern void dgtsv_(const long *Np, const long *NRHSp, double *DL,
//double *D, double *DU, double *B, const long *LDBp,
//long *INFOp);
long info;
dgtsv_(&N, &NRHS, DL, D, DU, B, &LDB, &info);
return info;
}

int
main()
{
int i, info;
info = dgtsv(5, 1, l, d, u, x, 5);
if (info != 0) fprintf(stderr, "failure with error %d\n", info);
for (i=0; i<5; ++i) printf("%5.1f\n", x[i]);
return 0;
}
ruoshan
 
Posts: 2
Joined: Mon Mar 07, 2011 8:35 am

Re: Why I can use the lapack in C without clapack

Postby admin » Tue Mar 08, 2011 11:53 am

You have a problem with your link.
Try:
Code: Select all
gcc -c tt.c
gfortran tt.o -o tt.exe -llapack -lblas


and actually, we released a Standard C language APIs for LAPACK that would do exactly was you were trying to do.
You can download it here:http://netlib.org/lapack/#_standard_c_language_apis_for_lapack

Here is your code using LAPACKE:

Code: Select all
#include <stdio.h>
#include "lapacke.h"

int main (int argc, char **argv)
{
lapack_int info;
int i;
double l[] = {
-1, -2, -1, -1
};
double d[] = {
2, 2, 3, 3, 1
};
double u[] = {
-1, -1, -1, -2
};
double x[] = {
1, 2, 3, 2, 1
};
info = LAPACKE_dgtsv(LAPACK_COL_MAJOR,5, 1, l, d, u, x, 5);
if (info != 0) fprintf(stderr, "failure with error %d\n", info);
for (i=0; i<5; ++i) printf("%5.1f\n", x[i]);
return 0;
}


To compile and link:

Code: Select all
gcc -c tt_lapacke.c
gfortran tt_lapacke.o -o tt_lapacke.exe -llapacke -llapack -lblas
admin
Site Admin
 
Posts: 474
Joined: Wed Dec 08, 2004 7:07 pm


Return to User Discussion

Who is online

Users browsing this forum: No registered users and 2 guests