I'm running Mathematica on a machine wtih 48 cores and 96 threads. I want to limit the number of threads the computation can have access to. If I give LaunchKernels[1] it correctly launches a single kernel, but then the computation is distributed over many more threads (48, which I guess is some default value or the max license number). Is there a way to limit the number of threads?

Thanks, Paolo


It seems I misunderstood the kind of threading you were addressing when writing my original reply (below). For internally multithreaded functions launched from a single kernel I you can limit the cores used with this setting:

(* e.g. two cores *)

 "ParallelOptions" -> {"MKLThreadNumber" -> 2, "ParallelThreadNumber" -> 2}]

Have you already explored the Parallel menu under Edit > Preferences? Specifically the Manual setting under Local Kernels would appear to be what you seek.


enter image description here

  • $\begingroup$ Thanks. The machine is a server without graphic interface (do you know the corresponding config file?) However: 1) if I understand correctly this solution is not ideal: if I set (say) Manual = 4 wouldn't this apply to all computations? I would like the freedom to set the number of Kernels differently each time. 2) the problem does not seem to be the number of Kernels. I can launch a single one using LaunchKernels[1] inside the notebook, but then the computation uses many more threads anyway. It's like the single core distributes the computation over many threads, using all resources. $\endgroup$
    – Paolo Pani
    Jun 13 '20 at 6:22
  • $\begingroup$ Addendum: apparently the license number of kernels is 16 (as per $ConfiguredKernels). However, even when using a single kernels it launches many more threads than 16 $\endgroup$
    – Paolo Pani
    Jun 13 '20 at 6:39
  • $\begingroup$ @Paolo I see now. I think you need to set the "ParallelThreadNumber" and "MKLThreadNumber" in SystemOptions["ParallelOptions"] to limit that kind of multi-threading, but I don't think you can specify that per computation other than to change the setting and then change it back. I shall admit I haven't tried to do this myself as I only have four cores to work with. $\endgroup$
    – Mr.Wizard
    Jun 13 '20 at 6:39
  • $\begingroup$ thank you so much. You are right: indeed, current settings are MKLThreadNumber -> 48, ParallelThreadNumber -> 48 $\endgroup$
    – Paolo Pani
    Jun 13 '20 at 6:50

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.