I am experiencing speed issues with ParallelTable. There are a few related problems on SX posted here and here, but no resolution. The various respondents to those problems seem to be focused around PackedArray issues, but in this case I really can't see that it would be an issue (but happy to be shown wrong if it fixes the problems, of course).
Viz., I'm doing a bunch of computational geometry and need to compute RegionDistance over a regular 3D grid to create a volume. Here's a greatly-simplified example ---
f = RegionDistance[Sphere[]]; vol = Table[f[{x, y, z}], {x, -2, 2, .1}, {y, -2, 2, .1}, {z, -2, 2, .1}]; // AbsoluteTiming (* {0.235526, Null} *) vol = ParallelTable[f[{x, y, z}], {x, -2, 2, .1}, {y, -2, 2, .1}, {z, -2, 2, .1}]; // AbsoluteTiming (* {19.9908, Null} *) So, 100x slower. I'm pretty agile with parallel computing, writ large, and have tried all varieties of Method, DistributeDefinitions and friends, evaluated things in ParallelEvaluate blocks, messed with contexts, &c.
Very frustrating. Has anyone found a solution here?
ParallelEvaluate[f = RegionDistance[Sphere[]]];beforeParallelTable? $\endgroup$f'lives' in the various kernels.DistributeDefinitionsdoesn't seem to work, so I'm assuming that, when the remote kernel needsfit is getting it from the controlling kernel, perhaps on each iteration? Very messy. Anyway- thank you for the reminder @ilian Next pint is on me. $\endgroup$InputFormof the distance function and gets recomputed repeatedly on the subkernels. I'd also like to mention thatRegionDistanceFunctionwill do automatic multithreading when given a list of points, e.g. I get a better timing if I don't use parallel kernels and doAbsoluteTiming[vol = f[Table[{x, y, z}, {x, -2, 2, .1}, {y, -2, 2, .1}, {z, -2, 2, .1}]];]instead. $\endgroup$