24小时热门版块排行榜    

CyRhmU.jpeg
查看: 2818  |  回复: 37
当前主题已经存档。

zyz1981

至尊木虫 (文坛精英)

医学物理

CLAPACK的安装与简单使用

CLAPACK是LAPACK的C语言接口。LAPACK的全称是Linear Algebra PACKage,是非常著名的线性代数库。LAPACK是用Fortran写的,为了方便C/C++程序的使用,就有了LAPACK的C接口库CLAPACK。LAPACK的主页是http://www.netlib.org/lapack/,CLAPACK则在http://www.netlib.org/clapack/

安装CLAPACK首先自从其主页上下载CLAPACK包http://www.netlib.org/clapack/clapack.tgz,解压。在其目录下的INSTALL目录中有make.inc的范本文件,比如在linux下就是make.inc.LINUX,将这个文件拷到CLAPACK目录下并改名为make.inc,并修改此文件中的相应参数,如果需要的话。CLAPACK需要F2CLIBS的libI77.a和libF77.a,一个tmglib和blas,这几个库都包含在了CLAPACK的安装包中,但是blas可以选用其他优化过的版本以得到更好的性能。在此我们使用CLAPACK中的blas。

首先编译F2CLIBS,用于将fortran转换为c语言,在CLAPACK目录下,make f2clib,在
CLAPACK/F2CLIBS下就会生成libI77.a和libF77.a。
编译tmglib,在CLAPACK目录下,make tmglib,会生成CLAPACK/tmglib_LINUX.a。
编译blas,在CLAPACK目录下,make blaslib,会生成CLAPACK/blas_LINUX.a。
最后是编译CLAPACK,make,会生成CLAPACK/lapack_LINUX.a

CLAPACK下的clapack.h就是所需要的头文件,除此之外还需要的一个头文件是F2CLIBS/f2c.h。

现在就通过使用CLAPACK中的一个函数sgesv_解线性方程组来学习一下使用的方法。

包括此函数在内的所有函数可以在CLAPACK/SRC下找到源代码,并在代码中有函数参数的说明信息。sgesv_的代码文件就是sgesv.c。

int sgesv_(integer *n, integer *nrhs, real *a, integer *lda, integer *ipiv, real *b, integer *ldb, integer *info)

sgesv_的功能是使用LU分解法解线性方程组AX=B,其中A是一个n*n的方阵。

integer *n, 方程的个数,也就是A的行数和列数
integer *nrhs, B的列数
real *a, 存储矩阵A数据的一维数组,在fortran中,数组是列主序存储,在此a中的二维数据也必须是列主序
integer *lda, 等于n
integer *ipiv, 一个输出数据数组,数组大小是n,具体什么功能不太明白,但是似乎不影响最后结果,谁明白请告诉我
real *b,存储矩阵B数据的一维数组,在fortran中,数组是列主序存储,在此b中的二维数据也必须是列主序
integer *ldb, 等于n
integer *info,输出参数,如果返回此参数为0,表示函数正常退出,否则表示出错

在此,我用了高教同济大学版线性代数第二版106页,2题(1)的数据。

A:
4,2,-1
3,-1,2
11,0,3

B:
2
10
8

代码:
#include
usingnamespace std;
#include
//因为程序是C++,而CLAPACK是C语言写的,所以在此处用extern关键字
extern"C"
{

    #include
}
int main(void) {
   
    integer M=3 ;
    integer N=1;
   
    real a[9]={4,3,11,2,-1,0,-1,2,3};
    real b[3]={2,10,8};

    integer lda;
    integer ldb;

    integer INFO;

    lda=M;
    ldb=M;
   
    integer ipiv[M];
   
    sgesv_(&M, &N, a, &lda,ipiv, b, &ldb, &INFO);
   
    if(INFO==0)
    {
       for(int i=0;i        {      
           cout<<        }      
    }
    else
    {
       cout<<"Failed."<     }   
   
    return EXIT_SUCCESS;
}

程序编译链接的时候,lapack_LINUX.a,tmglib_LINUX.a,blas_LINUX.a,libF77.a,libI77.a 这几个库文件都需要链接进去。

运算结果:
-14
56
54


转自:http://blog.csdn.net/daiyuchao/archive/2008/01/04/2026162.aspx
31楼2010-01-29 14:55:24
已阅   回复此楼   关注TA 给TA发消息 送TA红花 TA的回帖

zyz1981

至尊木虫 (文坛精英)

医学物理

Ubuntu(Unix)下Lapack的安装介绍(ifort)

* Lapack ( http://www.netlib.org/lapack/lapack.tgz )
download and unzip the file

1. Modify the make.inc file

make.inc file which is used by the makefiles in all directories.
This make.inc must be adapt to your computer system necessity.
Following is an example,

FORTRAN = ifort
OPTS = -O2
DRVOPTS = $(OPTS)
NOOPT = -O0
LOADER = ifort
LOADOPTS =


change the lines:

BLASLIB = ../../blas$(PLAT).a
LAPACKLIB = lapack$(PLAT).a
TMGLIB = tmglib$(PLAT).a
EIGSRCLIB = eigsrc$(PLAT).a
LINSRCLIB = linsrc$(PLAT).a

to --->
BLASLIB = ../../libblas$(PLAT).a
LAPACKLIB = liblapack$(PLAT).a
TMGLIB = libtmglib$(PLAT).a
EIGSRCLIB = libeigsrc$(PLAT).a
LINSRCLIB = liblinsrc$(PLAT).a

2. For the Makefile file
# The library can be set up to include routines for any combination
# of the four precisions. To create or add to the library, enter make
# followed by one or more of the precisions desired. Some examples:
# make single
# make single complex
# make single double complex complex16
# Alternatively, the command
# make
# without any arguments creates a library of all four precisions.
# The library is called
# lapack.a
# and is created at the next higher directory level.
#
# To remove the object files after the library is created, enter
# make clean

3. run in the terminal:
make blaslib
make all
cp *.a ~/lib


4. extract the file lapack95.tgz, and enter to the folder LAPACK95
The installation procedure:

1) Verify the make.inc file ("OPTS0", "MODLIB", "LAPACK77",
"BLAS" and "SUF".
2) cd SRC
3) Read the README file.
4) Run the make file with one of the selected library name.
5) cd ../TESTING
6) Read the README file.
7) Run the tests as described in README file.
8) run for a few tests from the directories EXAMPLES1 and
EXAMPLES2.

Change the settings in make.inc as following:
FC = ifort
FC1 = ifort



LAPACK_PATH = $(HOME)/lib
LAPACK95 = ../liblapack95.a
LAPACK77 = $(LAPACK_PATH)/liblapack.a
TMG77 = $(LAPACK_PATH)/libtmglib.a
BLAS = $(LAPACK_PATH)/libblas.a

then run in the terminal:
cd SRC
make double_dcomplex
cd ..
cp lapack95.a ~/lib/liblapack95.a
cp ./lapack95_modules/* ~/include

转自:http://www.39g.com/html/kaifa/281/2009/12/359229517805.htm
32楼2010-01-29 14:58:00
已阅   回复此楼   关注TA 给TA发消息 送TA红花 TA的回帖

zyz1981

至尊木虫 (文坛精英)

医学物理

关于LAPACK

官方网站:
http://netlib.amss.ac.cn/lapack/index.html

用户手册:
http://netlib.amss.ac.cn/lapack/lug/index.html
http://www.netlib.org/lapack/lawn41/index.html


LAPACK (Linear Algebra PACKage) 是Oak Ridge 国家实验室、加州大学Davis 分校和Illinois 大学等联合开发的线性代数函数库,用于在不同高性能计算环境上高效求解数值线性代数问题[7] 。

LAPACK 采用标准Fortran 77 编写。LAPACK 支持实型和复型数据类型,完全支持单精度和双精度计算。LAPACK 可以在向量机, 高性能超标量工作站,和共享存储多处理机上高效运行,也可以在各种类型的单机(PC, 工作站, 大型机)上获得满意的结果。LAPACK 最新版本为lapack-3.0。

  

测试文件:Single Precision Example (sgeev):
program test_sgeev
c Purpose: Compute the eigenvalues and, optionally, the left and/or
c right eigenvectors for an n-by-n real nonsymmetric matrix.
c Usage: call sgeev(jobvl, jobvr, n, a, lda, wr, wi, vl, ldvl, vr, ldvr,
c work, lwork, info)

integer nout, n, lda, lwork, ldvr, ldvl
parameter (nout=6, n=3, lda=n, lwork=5*n, ldvl=n, ldvr=n)
integer i, j, info
real a(lda,n), vr(ldvr,n), vl(ldvl,n)
real work(lwork), wi(n), wr(n)
external sgeev
c
data a / 3, 7, -4, 2, 8, -4, -1, -1, 3 /
c
call sgeev('N', 'V', n, a, lda, wr, wi, vl, ldvl, vr, ldvr,
& work, lwork, info)
c
write (*,*)
print*,' *** the real part of the computed eigenvalues ***'
write(nout, 98) (wr(i), i=1,n)
c
write (*,*)
print*,' *** the imaginary part of the computed eigenvalues ***'
write(nout, 98) (wi(i), i=1,n)
c
write (*,*)
print*,' *** the right eigenvectors ***'
do 10 i = 1,ldvr
write(nout, 99) vr(i,1), vr(i,2), vr(i,3)
10 continue
98 format (1x,f10.4)
99 format (1x,3f10.4)
c
end


***** OUTPUT: *****

*** the real part of the computed eigenvalues ***
11.0000
1.0000
2.0000

*** the imaginary part of the computed eigenvalues ***
0.0000
0.0000
0.0000

*** the right eigenvectors ***
-0.2673 -0.7071 -0.3714
-0.8018 0.7071 0.5571
0.5345 0.0000 0.7428


*********************


DGGEV 广义特征值求解,测试程序
     implicit none
      integer     i,info
      real(8)       ::  aa(2,2),bb(2,2),x(2),vl(2,2),vr(2,2)
      real(8)       ::  WORK(16,2),A1(2), A2(2), B1(2)
      data bb/10., 0., 0., 10./
      data aa/20000, -10000, -10000, 10000/
      call DGGEV('N','V',2,AA,2,BB,2,A1,A2,B1,VL,2,VR,2,WORK,16,info)
      do i=1,2
            x(i)=A1(i)/B1(i)
      end do
      write(*,*)x
      end

解:2628   382


Windows环境编译方法
http://jsy.dyn.dhs.org/maths/for ... dows/#installLAPACK

转自:http://zhousicheng.googlepages.com/a_042
33楼2010-01-29 15:02:03
已阅   回复此楼   关注TA 给TA发消息 送TA红花 TA的回帖

zyz1981

至尊木虫 (文坛精英)

医学物理

LAPACK + ATLAS安装指南

1. make.inc
基本上,在linux上面,如果你gcc是装好的,make.inc参数我修改的就是把库文件的_LINUX后缀给取消了。

BLASLIB      = ../../blas.a  #这个下面有解释
LAPACKLIB    = lapack.a
TMGLIB       = tmglib.a
EIGSRCLIB    = eigsrc.a
LINSRCLIB    = linsrc.a

如果你想对lapack的编译进行优化,你可以指定CPU,比如我的cpu(Core 2 Duo E6750),在OPT后面加上 -march=nocona 。

2.使用自带blas库:

如果你要用LAPCK自带的refblas.a 库(就是不更改../../blas.a 这一行),你需要更改根目录下的 Makefile,把

lib: lapacklib tmglib
#lib: blaslib lapacklib tmglib

改为

#lib: lapacklib tmglib
lib: blaslib lapacklib tmglib

就可以了(就是说,先编译refblas库,生成blas.a文件,然后再编译其他程序)。

3. 使用优化的BLAS库,比如ATLAS

如果你有优化的BLAS库,比如机器优化的atlas,可以用比如 -lf77blas -latlas 来替换第一个 ../../blas.a ,同时,保持2)步里面的 lib: 行为原始状态(不包含 blaslib)

BLASLIB      = -L/usr/lib/atlas -lf77blas -latlas

当然,这个只是测试用途。你甚至可以不管它。

4.
下面就是 make ,我一般用普通用户在emacs下面编译,有什么错误一眼能看见,最后sudo make install 来安装。

转自:http://www.ccthere.com/article/1524741
34楼2010-01-29 15:06:46
已阅   回复此楼   关注TA 给TA发消息 送TA红花 TA的回帖

zyz1981

至尊木虫 (文坛精英)

医学物理

ATLAS安装&资源

http://atlas.asp.net/docs/overview/install.aspx
上面的地址,是官方的安装说明(英文),这里我大概就说一下里面有什么东西.
http://atlas.asp.net/上面下载最新版本,然后安装,一路NEXT.其中涉及到安装ATLAS的项目模板,注册.asbx 的文件扩展名到IIS.
安装之后你就可以在VS2005中建立ATLAS项目,不多说.
下面是说如何在现有的项目中使用Atlas:
1 打开项目工程
2  C:\Program Files\Microsoft ASP.NET\Atlas\v2.0.50727\Atlas
到上面的路径把Microsoft.Web.Atlas.dll拷贝到你的BIN目录,然后就可以引用了.在工具箱里面选择项,然后你的工具箱里面就会多一系列的控件.如updatePanel等.
3 修改WEB.CONFIG文件
把下面的节点放到的子节点的位置(注意:configSections必须是CONFIGURATION的第一个子节点)
   
     
      

     
   

   
     
      
      
      
     

   

下面的放到 的子节点的位置:

      
         
         
      

     


     
     
      
      
     

     
      
     

4 OK
5 下面你可以写些测试程序,看效果如何

资源:
http://dflying.cnblogs.com
http://pwqzc.cnblogs.com


转自:http://www.cnblogs.com/lbk/archive/2006/06/01/415081.html
35楼2010-01-29 15:11:13
已阅   回复此楼   关注TA 给TA发消息 送TA红花 TA的回帖

zyz1981

至尊木虫 (文坛精英)

医学物理

linux下intel的ifort,icc编译器以及数学库MKL的下载安装及配置详解

ifort,icc是一款非常不错的编译器,intel有非商业版,可以免费下载,虽不提供技术支持,但对于大多数普通用户来讲,已经够用了.下面我就ifort,icc编译器的下载安装及配置过程介绍如下,另外还介绍了相应的数学库MKL(Math Kernel Library )的安装,希望对您有用。

我们的操作系统是Red Hat Enterprise Linux5-AS-X86-64。

1)下载:

http://www.intel.com/cd/software/products/asmo-na/eng/279831.htm下载Free Non-Commercial(非商业版)的ifort,icc以及MKL。很简单,只需要提供邮箱,然后按照步骤一步步来就行了,intel会把序列号和一个licence文件发到你邮箱里。这里以64位版本l_fc_p_10.1.015_intel64.tar.gz,l_cc_p_10.1.015_intel64,以及数学库l_mkl_p_1.0..1.014.tgz为例。

2)安装:

a) 以root身份登陆linux,tar -zxvf l_fc_p_10.1.015.tar.gz,解压缩.

b) # cd  l_fc_p_10.1.015

# ./install.sh

c) 选择1,进入安装,然后有输入序列号的选择,如果直接输入序列号,就选1(推荐使用),然后输入序列号,如果不能上网,或网络认证太慢,可以提供licence文件的路径的话,选2,然后根据提示输入licence文件的全部路径及文件名(以.lic结尾)。

d)选择Typical install典型安装(推荐使用),如果是高级用户,可以选择advanced.

e)阅读协议,一路回车,到最后根据提示输入accept。

f)然后都是默认安装,一路回车就安装完毕。

l_cc_p_10.1.015_intel64,以及数学库l_mkl_p_1.0..1.014.tgz的安装步骤同上。

3)配置:

进入安装目录下才/bin,默认路径为/opt/intel/fce/10.0.008/bin,/opt/intel/cce/10.0.015/bin。

source ifortvars.sh(.csh)

source iccvars.sh

到此安装设置完毕。分别输入which ifort,which icc如果能看到/opt/intel/fce/10.0.008/bin/ifort ,/opt/intel/cce/10.0.015/bin/icc,那么就安装设置成功了,赶紧用个fortran程序去测试吧。

另外,还有一种定义环境变量的方法,切换到root用户下,vi /etc/profile/,在该文件中定义环境变量如下所示:

#intel compiler

source /opt/intel/cce/10.1.015/bin/iccvars.sh

source /opt/intel/fce/10.0.008/bin/ifortvars.sh然后,保存退出,source /etc/profile,到此为止,intel编译器安装完毕。

转自:http://www.linuxdiyf.com/bbs/thread-94066-1-1.html
36楼2010-01-29 15:16:02
已阅   回复此楼   关注TA 给TA发消息 送TA红花 TA的回帖

zyz1981

至尊木虫 (文坛精英)

医学物理

关于 intel MKL 的安装使用的几点

1: 安装
可以在 intel 网站获得免费的 Linux 个人版. 运行 install.sh 脚本即可.

2: 配置
由于 Fortran95 接口的 blas,lapack 使用更加简单, 在安装后首先应该编译这
些接口的源文件, 根据 userguide 手册: 进入 interface 目录下相应的位置如
blas95, 并根据平台类型选择编译参数:
                        
make PLAT=lnx32 lib- for IA-32 architecture                        
make PLAT=lnx32e lib- for Intel® 64 architecture                     
make PLAT=lnx64 lib- for IA-64 architecture.

编译完后, 将 obj 目录下的头文件 *.mod 转移到 include 目录, 库文件 *.a
转入 lib/32 目录

环境变量设置:
source /opt/intel/mkl/10.0.5.025/tools/environment/mklvars32.sh
export MKL_FLAG='-lmkl_lapack95 -lmkl_ia32 -lguide -lpthread'
上面的设置根据具体平台需求来定.

3: 使用时加上编译链接参数 $MKL_FLAG 即可, 可以通过 man 函数名获得函数
的详细使用手册.
  

转自:http://blog.sina.com.cn/s/blog_4b8c0f290100fiym.html
37楼2010-01-29 15:17:18
已阅   回复此楼   关注TA 给TA发消息 送TA红花 TA的回帖

wzh上善若水

木虫 (著名写手)

引用回帖:
Originally posted by zyz1981 at 2010-01-29 14:04:03:
关键字: icc linux 安装
ifort,icc是一款非常不错的编译器,intel有非商业版,可以免费下载,虽不提供技术支持,但对于大多数普通用户来讲,已经够用了.下面我就ifort,icc编译器的下载安装及配置过程介绍如下 ...

我整需要这些,可以把这些发给我吗,QQ邮箱,659891560,不胜感激
知 止 而 后 有 定 ; 定 而 后 能 靜 ; 靜 而 后 能 安 ; 安 而 后 能 慮 ; 慮 而 后 能 得
38楼2010-04-15 22:59:48
已阅   回复此楼   关注TA 给TA发消息 送TA红花 TA的回帖
相关版块跳转 我要订阅楼主 maomao1210 的主题更新
普通表情 高级回复(可上传附件)
信息提示
请填处理意见