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.
ParallelMap
sets the maximum number of threads to1
(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. $\endgroup$