4

In mathematica, Eigenvalues is implemented internally using intel MKL.

When running

Eigenvalues[RandomReal[1.,{2000,2000}]

you will notice mathematica uses all available threads predefined in

SystemOptions["ParallelOptions" -> "MKLThreadNumber"]

However, if we use Eigenvalues in ParallelDo or ParallelTable

ParallelDo[Eigenvalues[RandomReal[1.,{2000,2000}],{1}]

the Threading feature of MKL automatically disabled.

How to avoid this? It is important, since I am working with very large matrices, and my cluster node has 24 cores. I have 6 tasks to do, I want to parallelize them, and each use 4 threads, so all the resources can be utilized. And what is more, can mathematica like MPI. In MPI when calling MKL threaded functions, MPI automatically, dynamically and evenly distribute all threads to different MPI processes. Is it possible in Mathematica?

matheorem
  • 17,132
  • 8
  • 45
  • 115
  • As an alternative if nothing else works, can you package your calculation as .m script files that you can run from shell, or even invoke from inside a ParallelDo? – Emilio Pisanty Apr 24 '16 at 17:23
  • @EmilioPisanty Of course, on a cluster, I have to pack my calculation as .m file. But what do you mean invoke inside ParallelDo? – matheorem Apr 24 '16 at 17:24
  • I mean something dirty like ParallelDo[Run["! MathKernel -script "<>filename[index], {index, indexRange}]. – Emilio Pisanty Apr 24 '16 at 17:57
  • 2
    Set "MKLThreadNumber" on the subkernels. – ilian Apr 24 '16 at 19:17
  • @ilian, perhaps you could post this as an answer? – user21 Apr 24 '16 at 21:18
  • 1
    @ilian Thanks! I forgot this trick! ParallelEvaluate@SetSystemOptions["ParallelOptions"->"MKLThreadNumber"->4] works. However, is it possible to make the thread distribution dynamic? I mean when one of the parallel tasks is done, the available threads can distributed to the running tasks. I tried setting MKLThreadNumber"->24 at first, but it harms the whole performance. – matheorem Apr 25 '16 at 00:45
  • 1
    I don't think it's possible within Mathematica, though with the default setting of MKL_DYNAMIC, MKL will itself take care of using fewer threads when necessary. – ilian Apr 25 '16 at 20:34
  • @ilian Where is MKL_DYNAMIC? If it is the default setting, why ParallelDo disable it? – matheorem Apr 26 '16 at 02:57

0 Answers0