Where can I find BLAS example code (in Fortran)?

一笑奈何 提交于 2019-12-11 07:07:50

问题


I have been searching for decent documentation on blas, and I have found some 315 pages of dense material that ctrl-f does not work on. It provides all the information regarding what input arguments the routines take, but there are a LOT of input arguments and I could really use some example code. I am unable to locate any. I know there has to be some or no one would be able to use these libraries!

Specifically, I use ATLAS installed via macports on a mac osx 10.5.8 and I use gfortran from gcc 4.4 (also installed via macports). I am coding in Fortran 90. I am still quite new to Fortran, but I have a fair amount of experience with mathematica, matlab, perl, and shell scripting.

I would like to be able to initialize and multiply a dense complex vector by a dense symmetric (but not hermitian) complex matrix. The elements of the matrix are defined through a mathematical function of the indices--call it f(i,j).

Could anyone provide some code or a link to some code?


回答1:


Starting with http://www.netlib.org/blas/, you see that the routine you're looking for is zgemv, here http://www.netlib.org/blas/zgemv.f --- it's a complex ('z') matrix ('m') vector ('v') multiply.

If your vectors are just normal arrays, i.e. they are contiguous in memory, then INCX and INCY arguments are just 1. As far as LDA parameter is concerned, just keep it equal to the matrix size. Other parameters are straightforward. For example:

  implicit none

  integer, parameter :: N=2

  complex*16, parameter :: imag1 = cmplx(0.d0, 1.d0)
  complex*16 :: a(N,N), x(N), y(N)

  complex*16 :: alpha, beta

  a(:,:)=imag1;
  x(:)=1.d0
  y(:)=0.d0

  alpha=1.d0; beta=0.d0

  call zgemv('N',N,N,alpha,a,N,x,1,beta,y,1)


  print*, y


  end      

In general, every time I need a BLAS or LAPACK routine, I look up the parameters on netlib.

EDIT: the code above doesn't use the fact that your matrix is symmetric. If you want that, then look up the zsymv routine. (Thanks to @MRocklin.)



来源:https://stackoverflow.com/questions/4637888/where-can-i-find-blas-example-code-in-fortran

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!