CLAPACK在Windows上的安装与使用

CLAPACK在Windows上的安装与使用

弄了好久在windows中安装LAPACK真苦逼,首先电脑里没有FORTRAN的编译器,因此安照LAPACK的官网弄了好久也没有弄好,之后再ubantu下面轻松安装。但是windows中还是没有成功,于是在windows上安装CLAPACK吧!

一、简介

LAPACK(Linear Algebra PACKage)是一个高性能的线性代数计算库,以BLAS(Basic Linear Algebra Subprograms)为基础,用Fortran语言编写,可用于计算诸如求解线性代数方程、线性系统方程组的最小平方解、计算特征值和特征向量等问题。而CLAPACK则是LAPACK的C语言接口。

二、编译

环境:VS2013、cmake、clapack-3.2.1-cmake压缩包
官网安装连接:http://icl.cs.utk.edu/lapack-for-windows/clapack/index.html

具体步骤如下:
1. Download clapack-3.2.1-CMAKE.tgz and unzip.
下载压缩包并解压
2. Download cmake and install it on your machine.
下载cmake编译器并安装
3. Open CMAKE 打开cmake
- Point to your CLAPACK-3.2.1-CMAKE folder in the source code folder
在where is the source code 中浏览到第一步中解压的源码中
- Point to a new folder where you want the build to be (not the same is better)
新建一个文件夹,用来放置cmake编译后的clpack文件(最好不要放在源文件家中)
- Click configure, check the install path if you want to have the libraries and includes in a particular location.
点击 configure
- Choose Visual Studio Solution. You can also choose nmake or any other platform.
选择Visual Studio Solution,之后好像啥也不用做了
- You may have to click again configure until everything becomes white
你可能需要再点击一次configure 也是红色背景消失
- Click generate, that will create the Visual Studio for CLAPACK and you are done.
点击generate,他将创建vs的clapack工程
- Close CMAKE
关闭cmake
4、Look in your “build” folder, you have your CLAPACK Visual Studio Solution, just open it.
打开编译放置clapack的文件夹,你将看到创建的vs的解决方案,打开它
5、Build the “ALL_BUILD” project, it will build the solution and create the librarires
将ALL_BUILD设置为启动项并编译
6、Build the “INSTALL”. This will put the libraries and include in your install folder.
将INSTALL设置为启动项并编译
7、Build the “RUN_TESTS”. The BLAS and CLAPACK testings will be run.
将RUN_TESTS设置为启动项并编译。(部分编译不能通过,但没关系)
如果没修改CMAKE中的设置,那么搞定第6个步骤后,你会在C:\Program Files\CLAPACK发现你所需要的.h和.lib

三、使用

1、新建vs控制台项目
2、打开项目属性页
    a)添加clapack库目录

    b)添加库目录

    c)添加依赖项

3、新建文件

#include < stdio.h>
#include < stdlib.h>
#include "f2c.h"
#include "clapack.h"
int main(void)
{
    /* 3x3 matrix A
    * 76 25 11
    * 27 89 51
    * 18 60 32
    */
    doublereal A[16] = {
        0.35, 0.09, -0.44, 0.25,
        0.45, 0.07, -0.33, -0.32,
        -0.14, -0.54, -0.03, -0.13,
        -0.17, 0.35, 0.17, 0.11
    };
    integer info;
    int i, j;
    char jobvl = 'V';
    char jobvr = 'V';
    integer n = 4;
    doublereal *a = A;
    integer lda = 4;

    doublereal* wr = (doublereal*)malloc(sizeof(doublereal) * n);
    doublereal* wi = (doublereal*)malloc(sizeof(doublereal) * n);
    integer ldvr = 4;
    doublereal* vr = (doublereal*)malloc(sizeof(doublereal) * n * ldvr);
    integer ldvl = 4;
    doublereal* vl = (doublereal*)malloc(sizeof(doublereal) * n * ldvl);
    integer lwork = n * 4;
    doublereal *work = (doublereal*)malloc(sizeof(doublereal) * lwork);
    dgeev_(&jobvl, &jobvr, &n, a, &lda, wr, wi, vl, &ldvl, vr, &ldvr, work, &lwork, &info);
    printf("info:%d\n", info);
    printf("D = \n");
    for (i = 0; i < n; i++){
        for (j = 0; j < n; j++){
            if (i == j) printf("%10.5f", wr[i]);
            else printf("%10.5f", 0.0);
        }
        printf("\n");
    }
    printf("Vl = \n");
    for (i = 0; i < n; i++){
        for (j = 0; j < n; j++){
            printf("%10.5f", vl[n * j + i]);
        }
        printf("\n");
    }
    printf("Vr = \n");
    for (i = 0; i < n; i++){
        for (j = 0; j < n; j++){
            printf("%10.5f", vr[n * j + i]);
        }
        printf("\n");
    }
    return info;
}

4、编译

你可能感兴趣的:(杂记)