Install cblas, LAPACK, and lapacke in Linux

Source: Internet
Author: User
Tags lapack gfortran

1.Make sure that the gfortran compiler is installed on the machine. If not, you can useSudo apt-Get install gfortran

2.DownloadBlas,
Cblas
,LAPACKSource code, these source code can be found on the http://www.netlib.org, download and unzip. Here is the download link for my installation http://www.netlib.org/blas/blas.tgz http://www.netlib.org/blas/blast-forum/cblas.tgz http://www.netlib.org/lapack/lapack-3.4.2.tgz, there will be three folders after the decompression,Blas,
Cblas,Lapack-3.4.2

3.Here is the specific compilation steps

1) Compile Blas, enter the BLAs folder, and execute the following commands

Gfortran-C-O3 *. F # compile all. f file, generate. o file ar RV libblas. A *. O # link all. o file, generate. file a su CP libblas. a/usr/local/lib # copy the library file to the system library directory

2) Compile cblas and enter the cblas folder. First, based on your computer platform, run a makefile in the directory. copy XXX to makefile. in, xxx indicates the computer platform. If it is Linux, makefile is used. in Linux, copy to makefile. in, and then execute the following command

CP .. /Blas/libblas. A Testing # compile libblas successfully in the previous step. copy A to make # The testing subdirectory under the cblas directory to compile sudo CP lib/cblas_linux.a/usr/local/lib/libcblas. A # copy the library file to the system library directory

3) Compile LAPACK and lapacke, this step is more troublesome, first of course is to enter the lapack-3.4.2 folder, and then according to the characteristics of the platform, the install directory corresponding make. inc. xxx copies a copy to the lapack-3.4.2 directory and name it make. inc. Here I copied install/make. inc. gfortran, because I use the gfortran compiler here.

Modify the lapack-3.4.2/makefile because LAPACK has been in the BLAs library, so you need to make the following changes

# Lib: lapacklib tmglib

Lib: blaslib variants lapacklig tmglib

Make # compile all LAPACK files CD lapacke # enter the lapacke folder, which contains the C language interface file make # compile lapackecp include /*. h/usr/local/include # copy the lapacke header file to the system header file directory CD .. # Return to the lapack-3.4.2 directory Cp *. a/usr/local/lib # copy all generated library files to the system library directory

The header files include lapacke. H, lapacke_config.h, lapacke_mangling.h, and lapacke_mangling_with_flags.h lapacke_utils.h.

The generated library files include: liblapack. A, liblapacke. A, librefblas. A, libtmglib.

Now, cblas and LAPACK are successfully installed on your computer.

Test:

You can go to lapacke to find the test code. Here is the official document of lapacke, such as the following code:

#include <stdio.h>#include <lapacke.h> int main (int argc, const char * argv[]){   double a[5*3] = {1,2,3,4,5,1,3,5,2,4,1,4,2,5,3};   double b[5*2] = {-10,12,14,16,18,-3,14,12,16,16};   lapack_int info,m,n,lda,ldb,nrhs;   int i,j;    m = 5;   n = 3;   nrhs = 2;   lda = 5;   ldb = 5;    info = LAPACKE_dgels(LAPACK_COL_MAJOR,'N',m,n,nrhs,a,lda,b,ldb);    for(i=0;i<n;i++)   {      for(j=0;j<nrhs;j++)      {         printf("%lf ",b[i+ldb*j]);      }      printf("\n");   }   return(info);}

Save the appeal code as test. C. When compiling, do not forget to use gfortran. In addition, you also need to connect to the library used to compile the above Code. Use the following command:

gfortran test.c -llapacke -llapack -lrefblas

If compilation is successful, the installation is successful. To understand the specific meaning of this code, you can go
View lapacke

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.