-
Notifications
You must be signed in to change notification settings - Fork 30
Native Linear Algebra Libraries
Like many java math packages, Scalala relies on netlib-java for underlying BLAS and LAPACK routines. Netlib-java includes both pure-java implementations, as well as the option to make JNI calls to the optimized libraries (e.g. using ACML, IMKL, or ATLAS). However, usually you have to build the jni libraries yourself. This is fairly straightforward, but there's little documentation.
Assuming you have lapack/blas libraries on your system (liblapack.so,libblas.so). If not, in Ubuntu you can install Atlas like so:
sudo apt-get install atlas-base-dev
First, checkout the netlib-java source:
svn checkout http://netlib-java.googlecode.com/svn/trunk/ netlib-java
Now we need to build the netlib jar and the jni libraries. First build the jar:
ant clean generate compile package cp lib/f2j/arpack-combo-*.jar lib/f2j/arpack-combined.jar cp netlib*.jar netlib-java-dev.jar
Now, to build the JNI libraries, we need to first find the JNI header directory on your system (try "locate jni.h"). For example this might be something like:
JNI_DIR=/usr/lib/jvm/java-6-openjdk/include/ #FIND CORRECT LOCATION
Next add this JNI directory to include directories in the makefile either manually, or with these short sed scripts:
cd jni sh configure jni_replacement=$(printf "%s\n" "$JNI_DIR" | sed 's/[\&/]/\\&/g') sed -e "s/CPPFLAGS=/CPPLAGS= -I${jni_replacement} -I. /g" Makefile.incl -i sed -e "s/CFLAGS=/CFLAGS= -I${jni_replacement} -I. /g" Makefile.incl -i
That's it! Finally, compile it:
make
This should produce libjniarpack-linux-.so, libjniblas-linux-.so, and libjnilapack-linux-*.so. Put these somewhere that will be found by $JAVA_LIBRARY_PATH and put the netlib jar somewhere in your $CLASSPATH. In eclipse, after including the netlib.jar in your path, you can include the .so files by going to Build Path -> Libraries -> Expand netlib.jar -> select Native library location -> click Edit.
In Java, you can check that it is using native code by printing the name property in the blas instance:
import org.netlib.blas.*;
...
System.out.println(BLAS.getInstance().getClass().getName());
Hopefully this is printed
org.netlib.blas.NativeBLAS
(References/More Info: netlib-java google code page, blog post on compiling jni)