jblas-project / jblas

Linear Algebra for Java
http://jblas.org
BSD 3-Clause "New" or "Revised" License
590 stars 149 forks source link

JDK crash multithreading #133

Open XePeleato opened 2 years ago

XePeleato commented 2 years ago

Hello, I've been using this library for my research, it's great! I've recently come across an issue when working on multiple threads, I can't get it to reproduce consistently, it just happens, more consistently if I use ~24 threads.

I have enabled the -Xcheck:jni flag and this is the output when it crashes:

FATAL ERROR in native method: Using JNIEnv in the wrong thread
        at org.jblas.NativeBlas.dgeev(Native Method)
        at org.jblas.NativeBlas.dgeev(NativeBlas.java:302)
        at org.jblas.SimpleBlas.geev(SimpleBlas.java:375)
        at org.jblas.Eigen.eigenvalues(Eigen.java:89)

It indeed looks like a threading issue, however, it's not as obvious as it seems to me, since dgeev uses no cached reference to JNIEnv.

This happens only with the dgeev function, my application calculates eigenvalues and also does quite some matrix to matrix operations.

Also, it happens on a CentOs 7 amd64 system.

I'll be happy to provide any other detail necessary to address this issue.

Thanks!

mikiobraun commented 2 years ago

Hey!

Thanks for your patience. Does this problem persist? Can you tell me a bit more about this? Are the matrices shared or are they completely separate? How many cores does your machine have?

Best,

Mikio