The Presentations Application (which I am the author of) has a few routines to aid in the parallel processing of graphics.
Here is a serial contour plot of a complex function. (Presentations has routines for drawing complex functions directly with complex variables.)
<<Presentations`
Module[{f = z \[Function] Sin[z/2], z, zmin = 0, zmax = 4 (1 + I)},
serial0 =
Draw2D[
{ComplexCartesianContour[f[z], {z, zmin, zmax}, Abs,
Contours -> Range[0, 4, 0.1],
ColorFunctionScaling -> False,
ColorFunction -> (ColorData["Rainbow"][Rescale[#, {0, 4}]] &),
PlotPoints -> 5,
MaxRecursion -> 4]},
Frame -> True,
ImageSize -> 300]
]; // AbsoluteTiming
serial0
{0.298017, Null}

The following statement parallel loads all the Presentations package routines to the processors.
ParallelLoadPresentations[]
The following routine will subdivide the complex plane into rectangular regions.
ComplexParallelPartitionDomain[{var, nRe, nIm, start, end, overlap}]
will generate a list of nRe x nIm complex subiterators in the form {{var, start1, end1},...}
for partitioning complex drawing object domains. The parameter overlap has a default value of 0 but otherwise may be used to overlap each subdomain except on the right and top boundaries.
Here, since I have six processors, we will use
ComplexParallelPartitionDomain[{z, 2, 3, 0, 4 (1 + I), 0}]
{{z, 0, 2 + (4 I)/3}, {z, (4 I)/3, 2 + (8 I)/3},
{z, (8 I)/3, 2 + 4 I}, {z, 2, 4 + (4 I)/3},
{z, 2 + (4 I)/3, 4 + (8 I)/3}, {z, 2 + (8 I)/3, 4 + 4 I}}
I find that a convenient way to do parallel processing is to use the ParallelSubmit
and WaitAll
mechanism. Here is the code for the parallel processing version.
Module[{f = z \[Function] Sin[z/2], z, zmin = 0, zmax = 4 (1 + I)},
par1 =
Draw2D[
{WaitAll[
ParallelSubmit[{f},
ComplexCartesianContour[f[z], #, Abs,
Contours -> Range[0, 4, 0.1],
ColorFunctionScaling -> False,
ColorFunction -> (ColorData["Rainbow"][
Rescale[#, {0, 3.7}]] &),
PlotPoints -> 6,
MaxRecursion -> 3]] & /@
ComplexParallelPartitionDomain[{z, 2, 3, 0, 4 (1 + I), 0}]
]},
Frame -> True,
ImageSize -> 300]
]; // AbsoluteTiming
par1
{0.101006, Null}

Next I will try Sjoerd's example above.
region = {x, y} \[Function] (Mod[Sqrt[x^2 + y^2] - 7/2 ArcTan[x, y] + Sin[x] +
Cos[y], \[Pi]] < \[Pi]/2)
(serial1 = RegionPlot[region[x, y], {x, -35, 35}, {y, -35, 35},
PlotPoints -> 20,
MaxRecursion -> 5]); // AbsoluteTiming
serial1
{44.546548, Null}

There is a similar partitioning function for x-y domains.
ParallelPartitionDomain[{x, 2, -35, 35, 0}, {y, 3, -35, 35, 0}]
{{{x, -35, 0}, {y, -35, -(35/3)}}, {{x, -35, 0}, {y, -(35/3), 35/3}},
{{x, -35, 0}, {y, 35/3, 35}}, {{x, 0, 35}, {y, -35, -(35/3)}},
{{x, 0, 35}, {y, -(35/3), 35/3}}, {{x, 0, 35}, {y, 35/3, 35}}}
There is one problem with partitioning RegionPlot
s in this way. If we want the automatic outlining of the region, then with partitioning we obtain some boundary lines on the edges of the partition. These are also on the edges of the serial plot but much less noticable. Drawing the boundary lines definitely improves the image. One way to handle this is to use a darker color for the region and the same color for the boundary lines.
par2 =
Draw2D[
{WaitAll[
ParallelSubmit[{region},
RegionDraw[region[x, y], Evaluate[Sequence @@ #],
MaxRecursion -> 3, PlotPoints -> 20,
PlotStyle -> Darker@Orange,
BoundaryStyle -> Darker@Orange]] & /@
ParallelPartitionDomain[{x, 2, -35, 35, 0}, {y, 3, -35, 35, 0}]
]},
Frame -> True,
ImageSize -> 350]; // AbsoluteTiming
par2
{2.196126, Null}

Notice that we obtained a speedup of a factor of 20, despite using only six processors, and the Parallel Kernel Status showing a speedup of 5.45. This is because we were able to use much less recursion to obtain the same quality of plot. These comparisions are a bit tricky because we have to compare the two plots by eye and we have two variables, PlotPoints
and MaxRecursion
to adjust. Nevertheless, a smaller piece of a plot will generally be topologically simpler and we can often achieve speedups that exceed the number of processors.
ListContourPlot
instead? The mesh does not have to be regular. $\endgroup$ParallelMap
and then plot them? $\endgroup$