Fixing the number of threads in optimization