jblas-project / jblas

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

strange native call failure under JAX-RS container (jersey-grizzly2), win7-x64 #44

Closed m0nzderr closed 4 years ago

m0nzderr commented 10 years ago

It all was quite perfect, until I finally tried to assemble my web-app that uses jblas at the backend. Unable to find a solution, and even debug, I'm asking for your help guys.

That's a dummy example that goes very ugly:

@Path("/myservice")
public class DummyService {
 @GET

    @GET
    @Path("test1")
    public String test1() 
    {
        final DoubleMatrix X=new DoubleMatrix(5,2,new double[]{1,2,3,4,5,6,7,8,9,10});
        final DoubleMatrix Q= X.dup();
       return Q.toString();
    }

    @Path("test2")
    public String test2()
    {
        final DoubleMatrix X=new DoubleMatrix(5,2,new double[]{1,2,3,4,5,6,7,8,9,10});

        try{

            final DoubleMatrix Q= Decompose.qr(X).q;

            // this line is never reacher

            return Q.toString();

            }catch(Throwable e){
                 // exception is never thrown
                 return "oops";
          }
    }
}

So, first, I do GET http://myhost/myservice/test1, and it works just as expected (I could see "[1,5;2,6;...]" in my browser. Than I do GET http://myhost/myservice/test2 and just nothing happens. No response (browser is eternally waiting), no error in Java console, no exception - nada.

Than I tried to debug, and found out that everything just literally goes away at the native call to dgeqrf here:

public static void geqrf(DoubleMatrix A, DoubleMatrix tau) {
    int info = NativeBlas.dgeqrf(A.rows, A.columns, A.data, 0, A.rows, tau.data, 0);
    checkInfo("GEQRF", info);
  }

I mean, literally dies - control point never reaches the statement "checkInfo("GEQRF", info)", no exceptions thrown. JVM stays up, since other services work fine, including calls to test1 work fine.

Of course, I tried to run the same test "off-line" (not within the server context) and it all works just fine.

In this example I used a very light-weighted standalone jersey-grizzly2 server, that is launched directly via "void main()", just as any other command-line java app.

Since test1() is able to perform a native call to JavaBlas.rcopy with success, I suspect that the problem with calling dgeqrf in test2() has something to do with a threading context. Since I'm unable even get an error code, I could only guess what it is (something like "MTA vs STA"?).

Any clues are appreciated!

Later I'll try to create a maven project with a running example.

mikiobraun commented 10 years ago

Hi m0nzderr,

Very strange indeed. What OS / CPU combination are you using?

-M

On Mon, Apr 14, 2014 at 6:51 AM, m0nzderr notifications@github.com wrote:

It all was quite perfect, until I finally tried to assemble my web-app that uses jblas at the backend. Unable to find a solution, and even debug, I'm asking for your help guys.

That's a dummy example that goes very ugly:

@Path("/myservice") public class DummyService { @GET

@GET
@Path("test1")
public String test1()
{
    final DoubleMatrix X=new DoubleMatrix(5,2,new double[]{1,2,3,4,5,6,7,8,9,10});
    final DoubleMatrix Q= X.dup();
   return Q.toString();
}

@Path("test2")
public String test2()
{
    final DoubleMatrix X=new DoubleMatrix(5,2,new double[]{1,2,3,4,5,6,7,8,9,10});

    try{

        final DoubleMatrix Q= Decompose.qr(X).q;

        // this line is never reacher

        return Q.toString();

        }catch(Throwable e){
             // exception is never thrown
             return "oops";
      }
}

}

So, first, I do GET http://myhost/myservice/test1, and it works just as expected (I could see "[1,5;2,6;...]" in my browser. Than I do GET http://myhost/myservice/test2 and just nothing happens. No response (browser is eternally waiting), no error in Java console, no exception - nada.

Than I tried to debug, and found out that everything just literally goes away at the native call to dgeqrf here:

public static void geqrf(DoubleMatrix A, DoubleMatrix tau) { int info = NativeBlas.dgeqrf(A.rows, A.columns, A.data, 0, A.rows, tau.data, 0); checkInfo("GEQRF", info); }

I mean, literally dies - control point never reaches the statement "checkInfo("GEQRF", info)", no exceptions thrown. JVM stays up, since other services work fine, including calls to test1 work fine.

Of course, I tried to run the same test "off-line" (not within the server context) and it all works just fine.

In this example I used a very light-weighted standalone jersey-grizzly2 server, that is launched directly via "void main()", just as any other command-line java app.

Since test1() is able to perform a native call to JavaBlas.rcopy with success, I suspect that the problem with calling dgeqrf in test2() has something to do with a threading context. Since I'm unable even get an error code, I could only guess what it is (something like "MTA vs STA"?).

Any clues are appreciated!

Later I'll try to create a maven project with a running example.

— Reply to this email directly or view it on GitHubhttps://github.com/mikiobraun/jblas/issues/44 .

Mikio Braun - http://blog.mikiobraun.de, http://twitter.com/mikiobraun

m0nzderr commented 10 years ago

Mikio, It happens on win 7x64, i7 930. Note, that it all runs perfectly find from any another thread. Only with jersey-grizzly2 threads it behaves that way. Unfortunately, due to the lack of time, I had to switch to another pure-java lib. Later I'm going to reconsider using jblas for another project (there I'll have deal with realy large scale problems) and will try to investigate the failure with unmanaged debugger (attached to .dlls).

mikiobraun commented 10 years ago

Hi m0nzderr,

yeah, no problem. Sorry, I didn't manage to have a look at it.

-M

On Tue, Apr 22, 2014 at 2:49 AM, m0nzderr notifications@github.com wrote:

Mikio, It happens on win 7x64, i7 930. Note, that it all runs perfectly find from any another thread. Only with jersey-grizzly2 threads it behaves that way. Unfortunately, due to the lack of time, I had to switch to another pure-java lib. Later I'm going to reconsider using jblas for another project (there I'll have deal with realy large scale problems) and will try to investigate the failure with unmanaged debugger (attached to .dlls).

— Reply to this email directly or view it on GitHubhttps://github.com/mikiobraun/jblas/issues/44#issuecomment-40993115 .

Mikio Braun - http://blog.mikiobraun.de, http://twitter.com/mikiobraun