jblas-project / jblas

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

Running jblas from multiple processes #59

Closed boscogh closed 9 years ago

boscogh commented 9 years ago

I have a case where I need to run more than 1 instance of jblass at a time, for example, 1st is continuesly calculating big matrix, while in 2nd I occasionally experimenting with intermediate results of the 1st. the problem is with mechanism of extracting native libraries into temp dir and loading it from there, even if I put 2 required dll in source dir, so they are copied into bin during compilation, the second case started and worked, but in the log it shows the error: -- org.jblas ERROR Could not create the temp file: java.io.FileNotFoundException: C:\Users\xxx\AppData\Local\Temp\libgcc_s_dw2-1.dll (The process can not access the file because the file is in use by another process). // translated back from Russian

-- org.jblas ERROR Could not create the temp file: java.io.FileNotFoundException: C:\Users\xxx\AppData\Local\Temp\libgfortran-3.dll (The process can not access the file because the file is in use by another process).

I use with same manner JNA jar, and it also depends on native dll, but with it I am able to put this dll's into some source folder (then copied to bin) and just point JNA during startup this folder (actually, since I use a default location for WIN32x86, I even don't point anything specially)

so I think it would be useful to every one to redesign dll load pattern into something more usable, without need on specifying environment variables, which is in my opinion a bit hard operation, having in mind you have everything in several separate development environments (eclipse in my case) running in parallel. again, I think the load pattern from JNA could be used as an example here. btw, JNA, of course, uses JNI for that, so they develop some C wrapper around library loading, and I believe this could be done for jblas as well.

boscogh commented 9 years ago

looking through sources, it seems that you always load 3d party dlls from same single place from temp dir. this is probably for optimization of time of extracting in from jar, I guess, right? BUT, for some reason the code in LibraryLoader.loadLibraryFromStream didn't check the existence of tempFile.

tempFile.isExists() before OutputStream.write in LibraryLoader.loadLibraryFromStream should solve the problem of running jblas from multiple JVM processes.