MEX-files

In the Matlab-lab on sparse matrices, it was stated that we would fix the slow matrix-vector multiply with banded matrices. We will do that by linking Matlab with a compiled Fortran-routine from Netlib.

Fetch dgbmv.f from Netlib/BLAS.
Write a MEX-file in C (you may use a wrapper
m-file as
well, if you like). You do not have to
implement all the capabilities of dgbmv.f,
it is sufficient that the MEX-file can handle y = B * x, where x and y
are vectors and B is a square band matrix. It should be possible for
the upper
and lower bandwidths to be different. Call your routine from Matlab and test it on some simple examples so you can see that everything works correctly. Run your routine from Matlab and check the speedup compared to the sparse version. You must probably use faster BLAS (see below) to get any speedup. |

If you change the C-code and recompile, you (may) have to clear the mex-function to see the changes. In help clear it says that clear functions removes all compiled M- and MEX-functions. This is the way to mex your program.

chmod u+w mexopts.sh add write permissons for you

Edit

change

to

Use the default

Now try to compile your C-file and Fortran files.

provided

You will get an error message:

Warning: You are using gcc version "4.1.2". The version

etc.

but it seems to work OK anyhow.

For better speed:

You may try to use the Intel MKL (comes with Matlab), I had problems using GotoBLAS with Matlab 2011. To use MKL:

- you need to use
`long`integers (and not`int`) in your mex-file - ln -s /chalmers/sw/sup64/matlab-2011b/bin/glnxa64/mkl.so libmkl.so (once in the directory where you are mexing)
- add -lgfortran to CLIBS in your mexopts-file
- mex with mex -f ./mexopts.sh bandsolve.c -L. -lmkl
- set your LD_LIBRARY_PATH to . in the directory where you are mexing and starting Matlab
- start Matlab and test
- do not type clear functions in Matlab, it will hang when using MKL (don't know why)