LAPACK (1) -- installation and testing

Source: Internet
Author: User
Tags lapack gfortran

LAPACKLAPACK, short for Linear Algebra PACKage, a high-performance Linear Algebra library, home http://www.netlib.org/lapack.

1. Installation

LAPACK is written in fortran. LAPACKE is its C language interface. If LAPACK is installed first and then LAPACKE is installed, you can directly call the C function in the program to implement the required functions.

The following describes how to install these two packages.

1) LAPACK Installation

Download the lapack package from the official website. The latest version is 3.3.1. Decompress the package and check the README file. To install it on Linux (Ubuntu 10.04lts when I use it), configure the make. inc file first.

Some compilation parameters,

PLAT indicates the platform used. It will be connected to the name of the generated lib library. It was originally _ LINUX. I changed it to null.
FORTRAN indicates the fortran compiler you are using. It is set based on the compiler you have installed. I use gfortran.
OPTS indicates the degree of optimization during compilation. Set it to-O2.
The LOADER is basically the same as the FORTRAN one.

Determine the generation target as follows,

BLASLIB = http://www.cnblogs.com/libblas$(PLAT).a
LAPACKLIB = liblapack$(PLAT).a
TMGLIB = libtmglib$(PLAT).a
EIGSRCLIB = libeigsrc$(PLAT).a
LINSRCLIB = liblinsrc$(PLAT).a

The names of the original library files are not preceded by lib, which is added here. Because the library files on linux generally have the prefix lib, the name of the library is followed by-l during the link, and lib is not added at that time. If you have compiled and generated these libraries, You can rename them without recompiling them.

In Makefile, we can see that there are many options for the all line. When we make, we can enter lib, then only the lib will be generated. If we make it directly, all the items will be compiled, including testing. There is also a line of lib that lists the lib to be generated. The comment-out line does not contain blaslib. If blaslib has been installed, you do not need to change it. If it is not installed, comment out the previous line and remove the comment from this line. Or manually add them.

2) LAPACKE Installation

Download the lapacke package from the website, which is the corresponding package of Standard C language APIs for LAPACK, decompress the package, and view the README file.

Similarly, you need to modify the make. inc file,

CC indicates the C program compiler used, changed to gcc,
LINKER indicates the connector to be used during compilation. As mentioned in the previous comments, the fortran compiler used to compile lapack. a And blas. a is used here. Change to gfortran.

LAPACKE indicates the name of the library file to be generated. For example, change it to liblapacke..
The LAPACKE compilation requires the previously generated lapack library file. Therefore, set the LIBS line.
LIBS = $ (LAPACK_PATH)/liblapack. a $ (LAPACK_PATH)/libblas.

Here, LAPACK_PATH is the directory where liblapack. a is located.

Check the Makefile below. You can directly make or make lapacke to prevent it from compiling the test content. Then generate liblapacke..

2. Example

Because the library files are generated, you can place these library files under/usr/lib of the system. In this way, you do not need to provide paths when linking these libraries.

Test LAPACK first. Link has a test example, http://blog.sciencenet.cn/home.php? Mod = space & uid = 271986 & do = blog & id = 280793.

Compile with the following statement,

Gfortran test. f90-llapack-lblas

Then a. out is generated and can be executed.

Then test LAPACKE. There is a testing directory under the lapacke folder. Let's test a small program. Create a directory named test_lapacke, copy the test_utils.h file under testing/include, copy the utlis folder, and copy a. c file of the interface, such as cbdsqr_1.c. There are also header files in the include folder under the lapacke folder.

Compile the Code as follows,

Gcc *. h cbdsqr_1.c utils/*. c-llapack-lblas-llapacke

Compiled successfully, run, output PASSED ,.... The program runs correctly.

These are just tests. To use these libraries more conveniently, you can use either of the following methods: Put the library files under/usr/lib and use-l to specify the links to these libraries, at the same time, put the files under lapacke/include under/usr/include. When using this file, you can directly include these header files. Another way is to put these library files and the header files in your project directory. These two methods are similar.

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.