I'm trying to evaluate an expression by a repeated application of a list of rules. Like
tmp1=exp//.rules;
Here exp is a list. No definitions are made for symbols appearing in rules and exp. In principle, the calculation can be parallelized by
tmp1=ParallelTable[xx//.rules, {xx, exp}, Method -> "FinestGrained"];
However, it is found that the evaluation of xx//.rules in the subkernels is much slower. This can be seen by comparing the following two codes:
tmp1=ParallelTable[(Print[#[[1]]];#[[2]])&@AbsoluteTiming[xx//.rules], {xx, exp}, Method -> "FinestGrained"];
tmp2=Table[(Print[#[[1]]];#[[2]])&@AbsoluteTiming[xx//.rules], {xx, exp}];
Sorry that I fail to get a simplified example, because the rules are very complicated, and the problem disappears for simplified rules. Similar problems were discussed in the question parallelization performance. As was suggested in sec. 3.4 of the answer by Szabolcs, one may try to reevaluate expressions in the subkernels. However, this method doesn't seem to work for rules. Does anyone have some good suggestions?
ps, the Mathematica version on my computer is 11.0.0 for Linux x86 (64-bit) (July 28, 2016).
Printprobably defeats parallelization completely. – Michael E2 Apr 19 '20 at 00:46Printwill cause interaction of the subkernels with the main kernel -- and even more important -- with the by far slowest component of Mathematica: the frontend. – Henrik Schumacher Apr 19 '20 at 07:37Printwill affect the total time for the calculation, but not the time spent on the code insidePrint. To see this, one can removePrint, and check the final output. – Wen Chern Apr 19 '20 at 07:47