How To Run JBLAS Java Linear Algebra Without Native Libraries
Asked Answered
S

0

2

I'd like to run JBLAS in a Kotlin application. I'm running OpenJDK 17 on a Mac OSX Monterey with M1.

I've added the JBLAS dependency to my Maven pom.xml.

I've written a JUnit test where one test succeeds and the other fails:

package fea

import org.jblas.DoubleMatrix
import org.jblas.Solve
import org.junit.jupiter.api.Assertions
import org.junit.jupiter.api.Test

class JBlasTest {

    @Test
    fun `create and add two double matricies`() {
        // setup
        val n = 3
        val a = DoubleMatrix(n, n, 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0)
        val b = DoubleMatrix.ones(n, n).mul(2.0)
        val expected = DoubleMatrix(n, n, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0, 11.0)
        // exercise
        val actual = a.add(b)
        // assert
        Assertions.assertEquals(expected, actual)
    }

    @Test
    fun `first solver`() {
        // setup
        val n = 3
        val a = DoubleMatrix(n, n, 1.0, 1.0, 2.0, 2.0, 4.0, -3.0, 3.0, 6.0, -5.0)
        val b = DoubleMatrix(n, 1, 9.0, 1.0, 0.0)
        val expected = DoubleMatrix(n, 1, 1.0, 2.0, 3.0)
        // exercise
        val actual = Solve.solve(a, b)
        // assert
        Assertions.assertEquals(expected, actual)
    }
}

The test that creates and adds two double matrices passes.

The test to solve A*x = b fails with an UnsatisfiedLinkError.

I added the lapack and openblas libraries to my Mac using brew:

brew install lapack openblas

I added the paths to the my LD_LIBRARY_PATH:

LD_LIBRARY_PATH=/opt/homebrew/opt/lapack:/opt/homebrew/opt/openblas

No joy. The test that creates and adds two double matricies passes; the first solver test fails. Here's the error message I get:

java.lang.UnsatisfiedLinkError: 'int org.jblas.NativeBlas.dgesv(int, int, double[], int, int, int[], int, double[], int, int)'

I don't know what library contains dgesv. I assumed that all the necessary dependencies would be available in the Open BLAS and LAPACK libraries I installed with brew.

I searched the jblas GitHub repo for a function named dgesv. IntelliJ could not find any method by that name.

enter image description here

It might be that my LD_LIBRARY_PATH is incorrect.

I tried cloning the repo and running mvn install. I had test failures that were also due to the missing dependencies. When I grep the surefire-reports text output for ERROR, I see lots of link errors.

I installed XCode from AppStore - didn't help.

I'm going to try building from GitHub source next. I'm not sure if I need to make changes to the Makefile to use M1.

Are these caused by libraries missing from Mac M1?

Any advice on next steps?

Sublittoral answered 12/6, 2022 at 16:14 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.