I use some dirty code to set environment variable in Scala from second answer of this question
I test this in IDE(IDEA Intellij) and set OMP_NUM_THREADS
at the beginning of my class.
import org.scalatest.{FlatSpec, Matchers}
class MyTest extends FlatSpec with Matchers {
val m = Map("OMP_NUM_THREADS" -> "1")
EnvHacker.setEnv(m)
After set, I could read from System.env
, it works. But when my program runs, it does not use this. I tried set it in static block, but still not work.
But if I set it in IDE run configuration(before JVM run), it works and runs as I expect. So seems it is read before I modify the variable.
Or in other word, I have a piece of code, what is the earliest way to call it in Java/Scala. e.g. static block is called before the first line of main method.
Some details updated:
I am using tensorflow-mkl Java API, it would read System environment variable OMP_NUM_THREADS
at some time, according to my test result, this operation is before the system static block. However, I want to control in code because I do not know the configuration expected without code logic.