how to make the call of the sub-routines of blas from lapack

Posted:
Fri Jul 06, 2007 4:04 am
by kirou11
please how to make the call of sub-routines of blas(level1,level2,leve3) from lapack
not: il have lapack instaled.

Posted:
Mon Jul 09, 2007 2:40 pm
by Julie
Kirou11,
do you have a BLAS library installed on your machine like ATLAS, GOTO or a vendor BLAS? see
http://www.netlib.org/lapack/faq.html#2.5 if you need to install one.
LAPACK library needs a BLAS library.
For example if you are calling the DGETRF routine (computes an LU factorization of a general matrix), LAPACK will call the following BLAS routines: DGEMM, DLASWP, DTRSM.
To be able to call a BLAS routine:
- In your code, you need to declare them as EXTERNAL before calling them:
- Code: Select all
* .. External Subroutines ..
EXTERNAL DGEMM, DLASWP, DTRSM
- you need to link your code with the BLAS library.
- Code: Select all
f77 mycode.f -o myprog.exe %BLASLIBRARY%
where %BLASLIBRARY% is the complete path of the BLAS library or
-L%PATHTOATLASLIB% -lf77blas -latlas if you are using ATLAS library or
-L%PATHTOGOTOLIB% -lgoto
Do not forget to add LAPACK first if you are using some LAPACK routines in your code:
- Code: Select all
f77 mycode.f -o myprog.exe %LAPACKLIBRARY% %BLASLIBRARY%
Hope it helps
Julie

Posted:
Tue Jul 10, 2007 8:48 am
by kirou11
hi,
but me I installed and I thus use Clapack I will like to know if the same thing, thanksjulie

Posted:
Tue Jul 10, 2007 8:49 am
by kirou11
sorry,
but me I installed and I use Clapack I will like to know if the same thing.

Posted:
Wed Jul 11, 2007 11:42 am
by Julie
kirou11
It is the same for CLAPACK, you just have to link with your CBLAS or ATLAS or a vendor BLAS.
You will have something like this if you are using CBLAS:
- Code: Select all
gcc prog.c ~/lib/clapack/libclapack.a ~/lib/clapack/libcblas.a -lm -lg2c
and like this if you are using ATLAS
- Code: Select all
gcc prog.c ~/lib/clapack/libclapack.a -lcblas -latlas -lm -lg2c
Julie

Posted:
Thu Jul 12, 2007 3:54 am
by kirou11
I did what you had said to me but I always have a problem here:
------------------------------------------------
#include <stdio.h>
#include <math.h>
#include <stdlib.h>
#include "/home/student/Desktop/CLAPACK/include/f2c.h"
#include "/home/student/Desktop/CLAPACK/include/clapack.h"
#include "/home/student/Desktop/CLAPACK/include/cblas.h"
int main (void)
{
extern int cblas_sgemm();
int lda = 3;
float A[] = { 0.11, 0.12, 0.13,
0.21, 0.22, 0.23 };
int ldb = 2;
float B[] = { 1011, 1012,
1021, 1022,
1031, 1032 };
int ldc = 2;
float C[] = { 0.00, 0.00,
0.00, 0.00 };
/* Compute C = A B */
cblas_sgemm (CblasRowMajor,
CblasNoTrans, CblasNoTrans, 2, 2, 3,
1.0, A, lda, B, ldb, 0.0, C, ldc);
printf ("[ %g, %g\n", C[0], C[1]);
printf (" %g, %g ]\n", C[2], C[3]);
return 0;
}
---------------------------------------------------------------------
gcc matrice.c -o matrice -L/home/student/Desktop/CLAPACK/lib -ltmglib -llapack -lblas -lF77 -lI77 -lm
-------------------------------------------------
matrice.c: In function `main':
matrice.c:11: error: conflicting types for 'cblas_sgemm'
/home/student/Desktop/CLAPACK/include/cblas.h:415: error: previous declaration of 'cblas_sgemm' was here
student@MasterControl:~/Desktop/CLAPACK$
----------------------------------------------------------

Posted:
Thu Jul 12, 2007 10:50 am
by Julien Langou
You need to remove line 11 of your code.
cblas_sgemm is a priory already and correctly defined in cblas.h and you have
included cblas.h on line 7.

Posted:
Fri Jul 13, 2007 3:59 am
by kirou11
if I remove line 11 I leave include.h I will have this error:
------------------------------------------------
/tmp/ccihquI6.o: In function `main':
matrice.c:(.text+0xa2): undefined reference to `cblas_sgemm'
collect2: ld returned 1 exit status
student@MasterControl:~/Desktop/CLAPACK$
------------------------------------------------

Posted:
Fri Jul 13, 2007 10:15 am
by Julie
kirou11
- Code: Select all
cblas_sgemm (CblasRowMajor,CblasNoTrans, CblasNoTrans, 2, 2, 3,1.0, A, lda, B, ldb, 0.0, C, ldc);
you are using
cblas in your code, not blas,
so you need to link also with the CBLAS library.
gcc matrice.c -o matrice -L/home/student/Desktop/CLAPACK/lib -llapack -L/home/student/Desktop/CBLAS/lib -lcblas -lblas -g2c -lm
Julie