简体   繁体   English

在Mac OS X上链接Fortran中的LAPACK

[英]Linking LAPACK in Fortran on Mac OS X

I imagine this to be a standard noob problem but after spending all morning searching the web, I decided to bug you anyway. 我认为这是一个标准的菜鸟问题,但在整个上午搜索网络后,我决定不管怎么说。 I'm on Mac OS 10.9 and I'd like to call a LAPACK eigenvalue routine from a Fortran program. 我在Mac OS 10.9上,我想从Fortran程序中调用LAPACK特征值例程。 I had the pleasure of being introduced to Fortran just yesterday, so please excuse any foolish mistakes. 我有幸在昨天被介绍给Fortran,所以请原谅任何愚蠢的错误。

This is the minimal example I want to get to run: 这是我想要运行的最小例子:

program eigtest
    complex A(3,3)
    real eigs(3)
    A(1,1) = cmplx(1,0)
    A(1,2) = cmplx(0,2)
    A(1,3) = cmplx(3,0)
    A(2,1) = cmplx(0,-2)
    A(2,2) = cmplx(5,0)
    A(2,3) = cmplx(1,-1)
    A(3,1) = cmplx(3,0)
    A(3,2) = cmplx(1,1)
    A(3,3) = cmplx(7,0)
    call heevd(A, eigs)
    write(*,*) eigs
end

I learned that on OS X, LAPACK is part of the Accelerate framework, so I tried things like: 我了解到在OS X上,LAPACK是Accelerate框架的一部分,所以我尝试了类似的东西:

gfortran -o eigtest -framework accelerate eigtest.f95

but the linker complains: 但链接器抱怨:

Undefined symbols for architecture x86_64:
  "_heevd_", referenced from:
      _MAIN__ in ccleuVFO.o
ld: symbol(s) not found for architecture x86_64
collect2: ld returned 1 exit status

I'm not sure that the Accelerate framework has that nice fortran95 call to heevd(A, eigs). 我不确定Accelerate框架是否有对heevd(A,eigs)的好的fortran95调用。 Below, I wrap up the zheevd lapack subroutine (with all of its workspace variables) to keep the call nice and tight. 下面,我将zheevd lapack子例程(包含其所有工作空间变量)包装起来,以保持调用的良好和紧密。 You can store such ugliness inside an external module somewhere that you can load in your programs. 您可以将这样的丑陋存储在可以在程序中加载的某个外部模块中。 I think intel MKL has most of the lapack95 interfaces, and there may be other better ways with the os x framework. 我认为intel MKL具有大多数lapack95接口,并且os x框架可能还有其他更好的方法。 The code below compiles with: 下面的代码汇编为:

gfortran -o eigtest -framework Accelerate eigtest.f95    

program eigtest
    complex(kind=8),allocatable :: A(:,:), eigs(:), vecs(:,:)
    integer                     :: ierr

    allocate(A(3,3),stat=ierr)
    if (ierr /= 0) STOP "*** not enough memory ***"

    A(1,1) = cmplx(1,0)
    A(1,2) = cmplx(0,2)
    A(1,3) = cmplx(3,0)
    A(2,1) = cmplx(0,-2)
    A(2,2) = cmplx(5,0)
    A(2,3) = cmplx(1,-1)
    A(3,1) = cmplx(3,0)
    A(3,2) = cmplx(1,1)
    A(3,3) = cmplx(7,0)
    !call heevd(A, eigs)
    call wrapped_zheevd(A, eigs,vecs)
    write(*,*) eigs

    contains

subroutine wrapped_zheevd (matin, &
                         zvals,zvecs )
    integer                                  :: ndim
    complex(kind=8),intent(in),  allocatable :: matin(:,:)
    complex(kind=8),intent(out), allocatable :: zvals(:),zvecs(:,:)
    character*1                              :: jobz='V',uplo='U'
    integer                                  :: info,lda,liwork,lrwork,lwork,n
    integer,                     allocatable :: iwork(:)
    real(kind=8),                allocatable :: rwork(:), w(:)
    complex(kind=8),             allocatable :: A(:,:),   work(:)
    integer                                  :: ierr

    ndim=size(matin(1,:))

    if (allocated(zvecs)) deallocate(zvecs)
    if (allocated(zvals)) deallocate(zvals)
    allocate(zvecs(ndim,ndim),zvals(ndim),stat=ierr)
    if (ierr /= 0) STOP "*** not enough memory ***"

    n=ndim
    lda=n

    lwork  = 2*n+n**2
    lrwork = 1+5*n+2*n**2
    liwork = 3+5*n

    allocate(a(ndim,ndim),w(ndim),work(lwork),&
             rwork(lrwork),iwork(liwork),stat=ierr)
    if (ierr /= 0) STOP "*** not enough memory ***"

    a=matin

    call zheevd(jobz,uplo,n,a,lda,w,work,lwork,rwork,lrwork,iwork,liwork,info)

    zvals=w
    zvecs=a

    deallocate(a,w,rwork,iwork,work)

end subroutine

end

This link suggests that the missing method is an Intel library call: 此链接表明缺少的方法是英特尔库调用:

http://software.intel.com/sites/products/documentation/hpc/mkl/mklman/index.htm#GUID-9AD3B5B7-DC35-4DF7-A126-9A8730FE98CA.htm http://software.intel.com/sites/products/documentation/hpc/mkl/mklman/index.htm#GUID-9AD3B5B7-DC35-4DF7-A126-9A8730FE98CA.htm

I wonder where its equivalent lives on Mac? 我想知道它在Mac上的等效产品在哪里? Do you have gfortran? 你有gfortran吗?

http://gcc.gnu.org/wiki/GFortranBinaries http://gcc.gnu.org/wiki/GFortranBinaries

Does the bottom message suggest that there's no 64 bit version available? 底部消息是否表明没有64位版本可用?

Sorry - more questions than answers. 对不起 - 问题多于答案。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM