Am I using the BLAS/LAPACK libraries when using MTJ?

1k Views Asked by At

I'm not sure this is the right place to ask my question, so if not, I apologize.

I'm writing a Java program that does a lot of sparse matrix multiplications. After some research, I've found that the Matrix Toolkits Java provides some of the best performance, but only when using the netlib-java wrapper for BLAS/LAPACK fortran libraries.

Now I've tried following the instructions on these github pages, and I have installed both BLAS and LAPACK from the Arch Linux repositories:

$ pacman -Ss lapack
extra/lapack 3.5.0-1 [installed]
    Linear Algebra PACKage
$ pacman -Ss blas
extra/blas 3.5.0-1 [installed]
    Basic Linear Algebra Subprograms

When checking /usr/lib/, it does contain

-rwxr-xr-x 1 root root 1866088 Jan 27 21:46 liblapacke.so
lrwxrwxrwx 1 root root      13 Jan 27 21:46 liblapacke.so.3 -> liblapacke.so 
lrwxrwxrwx 1 root root      13 Jan 27 21:46 liblapacke.so.3.5.0 -> liblapacke.so
-rwxr-xr-x 1 root root 5878120 Jan 27 21:46 liblapack.so 
lrwxrwxrwx 1 root root      12 Jan 27 21:46 liblapack.so.3 -> liblapack.so
lrwxrwxrwx 1 root root      12 Jan 27 21:46 liblapack.so.3.5.0 -> liblapack.so

and

-rwxr-xr-x 1 root root 358448 Jan 27 21:46 libblas.so
lrwxrwxrwx 1 root root     10 Jan 27 21:46 libblas.so.3 -> libblas.so
lrwxrwxrwx 1 root root     10 Jan 27 21:46 libblas.so.3.5.0 -> libblas.so

Now, my program multiplies a sparse matrix of about 450,000x450,000 elements with a vector. This takes about a second. I'm running on an Intel Core 2 Duo @ 2.53GHz.

My question after all this is, am I really using the Fortran backend, or still the Java implementation of these functions? I realize my calculations are large, but I still feel they could be faster... Is there any way to check which libraries are used while running?

Thanks in advance! Regards,

Linus

EDIT:

I've just tried something, which to me suggests that I am in fact NOT using the libraries. I've renamed both liblapack and libblas, assuming this would make it impossible for Java to find them. My program still ran after renaming the libraries, and more importantly, took just as long... I guess what I'm looking for now is how to make sure that the libraries are loaded and being used!

2

There are 2 best solutions below

0
On

There is an easy way to check which version of the BLAS library you are using in your code:

System.out.println(BLAS.getInstance().getClass().getName());

If you are running the Native library, you should see something like:

com.github.fommil.netlib.NativeSystemBLAS

If, on the contrary, you are still linked to JBLAS, then you should see instead a reference to F2jBLAS or JBLAS

With that said, you still need to make sure that your sysmtem BLAS library is linked to the correct implementation (custom-compiled OpenBLAS, Intel MLK, etc.) if you want the very best performance.

3
On

You are using the shared libraries, which should be written in Fortran.

Keep in mind that for a large matrix, it is not unreasonable that the multiplication takes time.