Single threaded Nd4j operations


My use case requires any application to run on a single thread as our hardware accepts multiple submissions from multiple users, and unintended multithreading can cause conflicts.

I am using Nd4j primarily for matrix multiplication calling Nd4j.setNumThreads(1) prior to any operations. Jobs I submit end up with ~170% CPU usage throughout their run however, indicating that multiple threads are still being used.

I am using version 1.0.0-beta4. I am wondering if I am just configuring it incorrectly to meet my requirements or if there is anything fundamental I am missing which would make this infeasible.

That setting only sets how many threads ND4J itself uses. But ND4J also uses BLAS libraries, which, unless configured differently, will use a varying number of threads, depending on the input size.

In order to tell the BLAS library (usually either OpenBLAS or MKL) to use just one thread you also need to set the “OMP_NUM_THREADS” environment variable to 1.

That looks like its working. Thanks for the quick response.