Results 1 to 6 of 6

Thread: [SOLVED] FORTRAN, BLAS and matrix multiplication

  1. #1
    Join Date
    Aug 2005
    Beans
    55
    Distro
    Xubuntu 6.10 Edgy

    [SOLVED] FORTRAN, BLAS and matrix multiplication

    Hi,

    I am starting to feel really stupid, but I can't figure out how to use BLAS to multiply a matrix by a vector... I wrote the following Fortran code:

    Code:
          REAL*8 X(2, 3) /1.D0, 2.D0, 3.D0, 4.D0, 5.D0, 6.D0/
          REAL*8 Y(3) /2.D0, 2.D0, 2.D0/
          REAL*8 Z(2)
          CALL DGEMV('N', 2, 3, 1.D0, X, 2, Y, 1, 0.D0, Z, 1)
          PRINT *, Z
          STOP
          END
    DGEMV is a routine from BLAS, which should calculate Z=(0)*Z + (1)*X*Y...

    Compiling the above and linking to BLAS,

    Code:
    g77 test.f -o3 -lblas
    and then running it, produces:

    Code:
    7.63918485E-313  1.01855798E-312
    Which is wrong since the answer should be, 18 and 24???

    Any help would be much appreciated!

  2. #2
    WW is offline Iced Blended Vanilla Crème Ubuntu
    Join Date
    Oct 2004
    Beans
    1,532

    Re: FORTRAN, BLAS and matrix multiplication

    I don't see anything obviously wrong. Your example worked fine for me, on computer running gutsy with g77 and the refblas3-* packages, and on a Mac with blas compiled from source using gfortran.

    How did you install blas? From a package, or from source? If from source, did you use g77 to build the library?

  3. #3
    Join Date
    Aug 2005
    Beans
    55
    Distro
    Xubuntu 6.10 Edgy

    Re: FORTRAN, BLAS and matrix multiplication

    Hmmm, my memory is somewhat hazy. I know that I didn't compile it... I did install, from the repos, LAPACK and ATLAS, both of which should (I think) install BLAS... My compiler also doesn't complain about the library being missing, so it must be there.

  4. #4
    WW is offline Iced Blended Vanilla Crème Ubuntu
    Join Date
    Oct 2004
    Beans
    1,532

    Re: FORTRAN, BLAS and matrix multiplication

    Try compiling with gfortran instead of g77.

  5. #5
    Join Date
    Aug 2005
    Beans
    55
    Distro
    Xubuntu 6.10 Edgy

    Re: FORTRAN, BLAS and matrix multiplication

    OK, no change when I do that, but when I compile with -llapack instead of -lblas it suddenly spits out the right answer...

    Odd, maybe BLAS isn't correctly installed on my system. Anyway, LAPACK works (even with g77), so I am happy (for now).

    Thank you for your help... Any further ideas, please post them. (I am not a programmer, just a statistician needing to code something...)

  6. #6
    Join Date
    Dec 2008
    Beans
    1

    Re: [SOLVED] FORTRAN, BLAS and matrix multiplication

    This sort of thing happens when you specify the wrong kind (the 8 in 'real(8)' or 'real*8') of your (input or output) variables. Try another kind. Probably the default kind in BLAS is not 8.
    Last edited by jgte; December 3rd, 2008 at 03:35 PM.

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •