Fortran 90/95 library for sparse matrices?

2019-03-15 03:34发布

问题:

I am looking for a library for dealing with sparse matrices in fortran 90/95. I only need very basic operations like matrix-vector multiplication. What do you suggest I use?

I have searched around and an extension(?) to BLAS called "sparse blas", documented in chapter 3 of the blast technical forum specification:

http://www.netlib.org/blas/blast-forum/,

seems ideal. According to that document, there should be a fortran 95 interface to the library. However, I haven't been able to find an actual implementation of this specification anywhere that I was able to download. I am kind of getting the impression that the fortran 95 sparse blas specification isn't really implemented anywhere? Not as open source anyway.

I also found a library called sparsekit:

http://people.sc.fsu.edu/~jburkardt/f_src/sparsekit/sparsekit.html

Anyone got any experience with either one of these two, or any other sparse matrix library for fortran 90/95? I would like advice on which one to use, and also where to get it (in the case of sparsekit the source code is available through the above link). Is there anything like a "standard" for sparse matrices, like BLAS is for dense ones?

Cheers,

Arne

回答1:

OK, I'll partially answer my own questions:

Where to find a full f95 implementation of Sparse BLAS was provided by @alexurba above:

http://www.netlib.org/toms/818

That was it! This script creates all the source code in the folder that you run it (I have never seen software provided in this manner before).

To make the INSTALL script work I needed to do some changes: The install instructions tell you to edit the INSTALL script and choose the appropriate "arch". Your choices are: AIX, ALPHA, CRAY, HP, NAG, SGI and SUN. Neither of these seemed appropriate to me, as I am using linux and the only fortran compiler I have on this computer is gfortran. I didn't quite understand the purpose of this option, but what I did that worked was the following:

1) In INSTALL, make up a new "arch" I called GNU by setting the variable SB_ARCH='GNU'. 2) In SOFTWARE/Makefile change FC = f90 to FC = gfortran, 3) In TESTER/ copy the file Makefile.NAG to Makefile.GNU, change FC = f90 to FC = gfortran, and change all instances of the the word 'NAG' to 'GNU'. (You'll probably also want to change the FFLAGS option in the Makefiles.)

After this I ran INSTALL, and then TESTER/test_all, and the tests spit out "0.000..." as errors, which I assume to mean everything is working.

I must say I found finding this source code unusually difficult. Luckily this thread comes up quite high on google when searching "fortran 90 sparse matrix library" now.

My final solution: Ironically, after finally finding a full implementation of Sparse BLAS I have decided that for my problem it is better to use a more direct approach, since all I'll probably need is matrix-vector multiplication: Figure out what sparse matrix representation to use (Compressed Sparse Row (CSR) seems to be appropriate for my problem), dig out the corresponding matrix-vector multiplication routine from the Sparse BLAS source code, see how it wants it input, and just use that directly in my code.