1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

jblas on Arch Linux

Last updated at Posted at 2018-01-13

Arch Linux でも行列計算したい!Clojure(Java)で!

手順

  1. arch linuxの環境を作りましょう(最新のjava環境(openjdk)、Rubyもインストールしておきましょう)(https://qiita.com/elect/items/328c28c310b385de7d23)

2. 次にjblasのjarファイルをダウンロードします。(Getting Started->Download the jar from the downloads pageより)

3. 普通に java -server -jar jblas-1.4.2.jar をしてみます。

4. こんな感じのエラーが返ってきます

    java -jar jblas-1.2.4.jar 
    -- org.jblas INFO jblas version is 1.2.4
    Simple benchmark for jblas
    Running sanity benchmarks.

    checking vector addition... ok
    -- org.jblas CONFIG BLAS native library not found in path. Copying native library from the archive. Consider installing the library somewhere in the path (for Windows: PATH, for Linux: LD_LIBRARY_PATH).
    -- org.jblas CONFIG ArchFlavor native library not found in path. Copying native library libjblas_arch_flavor from the archive. Consider installing the library somewhere in the path (for Windows: PATH, for Linux: LD_LIBRARY_PATH).
    -- org.jblas CONFIG Loading libjblas_arch_flavor.so from /lib/static/Linux/amd64/, copying to libjblas_arch_flavor.so.
    -- org.jblas ERROR Couldn't load copied link file: java.lang.UnsatisfiedLinkError: /tmp/jblas5239787082843388211/libjblas_arch_flavor.so: libgfortran.so.3: cannot open shared object file: No such file or directory.

    On Linux 64bit, you need additional support libraries.
    You need to install libgfortran3.

    For example for debian or Ubuntu, type "sudo apt-get install libgfortran3"

    For more information, see 
    https://github.com/mikiobraun/jblas/wiki/Missing-Libraries
    Exception in thread "main" java.lang.UnsatisfiedLinkError: org.jblas.NativeBlas.dgemm(CCIIID[DII[DIID[DII)V
	at org.jblas.NativeBlas.dgemm(Native Method)
	at org.jblas.SimpleBlas.gemm(SimpleBlas.java:247)
	at org.jblas.DoubleMatrix.mmuli(DoubleMatrix.java:1781)
	at org.jblas.DoubleMatrix.mmul(DoubleMatrix.java:3138)
	at org.jblas.util.SanityChecks.checkMatrixMultiplication(SanityChecks.java:91)
	at org.jblas.util.SanityChecks.main(SanityChecks.java:182)
	at org.jblas.benchmark.Main.main(Main.java:114)
    -- org.jblas INFO Deleting /tmp/jblas5239787082843388211/libjblas_arch_flavor.so
    -- org.jblas INFO Deleting /tmp/jblas5239787082843388211

要するに、libgfortran.so.3 が見つかりませんよって意味です

  1. gcc-6をインストールしましょう。 (yaourt -S gcc6)
    この中に入っているlibgfortran.so.3が必要になります

  2. sudo ln -s /usr/lib/gcc/x86_64-pc-linux-gnu/6.X.X/libgfortran.so.3 /usr/lib/ (6.X.Xはバージョン名) でリンクを /usr/lib 下に貼ります(絶対パスで記述して下さい)

  3. もう一度 java -server -jar jblas-1.2.4.jar してみると上手く動きます

    java -server -jar jblas-1.2.4.jar
    -- org.jblas INFO jblas version is 1.2.4
    Simple benchmark for jblas
    Running sanity benchmarks.
    checking vector addition... ok
    -- org.jblas CONFIG BLAS native library not found in path. Copying native library from the archive. Consider installing the library somewhere in the path (for Windows: PATH, for Linux: LD_LIBRARY_PATH).
    -- org.jblas CONFIG ArchFlavor native library not found in path. Copying native library libjblas_arch_flavor from the archive. Consider installing the library somewhere in the path (for Windows: PATH, for Linux: LD_LIBRARY_PATH).
    -- org.jblas CONFIG Loading libjblas_arch_flavor.so from /lib/static/Linux/amd64/, copying to libjblas_arch_flavor.so.
    -- org.jblas CONFIG Loading libjblas.so from /lib/static/Linux/amd64/sse3/, copying to libjblas.so.
    checking matrix multiplication... ok
    checking existence of dsyev...... ok
    [-0.210656, -0.640445, -0.451188; -0.509085, -0.116445, 0.796815; -0.807515, 0.407556, -0.398408; 0.210656, 0.640445, -0.052780]
    [17.233688; 1.414214; 0.000000]
    [-0.470605, 0.782218, 0.408248; -0.571449, 0.082339, -0.816497; -0.672293, -0.617540, 0.408248]
    [17.233688; 1.414214; 0.000000]
    checking existence of dgesvd...... ok
    Checking complex return values... (z = -21.0 + 88.0i)
    Check whether we're catching XERBLA errors. If you see something like "** On entry to DGEMM  parameter number  4 had an illegal value", it didn't work!
    checking XERBLA... ok
    Sanity checks passed.

    Each benchmark will take about 5 seconds...

    Running benchmark "native matrix multiplication, single precision".
    n = 10   :  1.281 GFLOPS (3203374 iterations in 5.0 seconds)
    n = 100  : 11.192 GFLOPS (27980 iterations in 5.0 seconds)
    n = 1000 : 18.981 GFLOPS (48 iterations in 5.1 seconds)
    -- org.jblas INFO Deleting /tmp/jblas6793705967272229922/libjblas.so
    -- org.jblas INFO Deleting /tmp/jblas6793705967272229922/libjblas_arch_flavor.so
    -- org.jblas INFO Deleting /tmp/jblas6793705967272229922

これで、jblasを使う事ができるようになります。

jblasを使った例 (Clojure)

  • clatrix ライブラリ
  • incanter ライブラリ などなど
    行列演算が高速になり、統計処理、機械学習などを高速に行うことが出来るようになります!もっとも、neandertharl の方がより早く計算が出来ますが、Rと同じような関数を取り揃えているIncanterが使えることはかなり大きいアドバンテージになっています。

広告?: Clojure for Data Science はいいぞ!

機械学習始めてみたいけど、いきなりわけの分からないところから入りたくない!っていう人向けの本です。平均の導出から始まり、分類や回帰まで幅広く学ぶことが出来ます。
また、ソースコードは ここ に載っているので、とりあえず何が出来るのか見てみたい人はこちらから触ってみるのも良いかもしれません。

1
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?