# Cuba Integrator can't perform parallelization

I was using Cuba library to do some integration, but I found that it's generally much slower with parallelization than without.

MWE:

Install["/path/to/Cuba/Vegas"];
SetOptions[Vegas,Verbose->0];
Vegas[Sin[x],{x,0,1},PrecisionGoal->6,MaxPoints->10^6]//AbsoluteTiming
(*{8.48996, {{0.4597, 0.0000217312, 4.32426*10^-14 }}}*)
MapSample = ParallelMap;
Vegas[Sin[x],{x,0,1},PrecisionGoal->6,MaxPoints->10^6]//AbsoluteTiming
(*{55.2991, {{0.4597, 0.0000217312, 4.32426*10^-14 }}}*)


We can see that parallelization (with 16 kernels) is 7 times slower than without parallelization. If I increase the number of kernels to 32, the speed is even slower (102s).

EDIT:

The tests performed above is on a workstation with E5-2680 v3 (48 threads) and I tried both MMA 11.3 and 12.1. I also tested it on a PC with a i7-4790 (only opened 6 kernels) and the MMA version is 12.1. Cuba in question is Cuba-4.2.

• It would be helpful to know the specs of the rest of the system...often the bottleneck is something else. Aug 31, 2020 at 11:35
• @morbo I added some infos. Hope it helps. Sep 1, 2020 at 7:20
• My guess that the MKL is multi-threaded, but ParallelMap sets the maximum number of threads to 1 (one), and you lose the efficiency of the MKL, if the Cuba package is written to take advantage of it. The advice here and in the comments here may be helpful. Sep 1, 2020 at 16:25
• @MichaelE2 Manually setting MKLThreadNumber to 4 in parallel kernels didn't help. Sep 2, 2020 at 19:50