I tried to optimize the code for generating power tower fractals from here. As the author suggested, I tried to memorize the points already tested in a list.
Here is my code :
convlist = {};
convQ[z_, max_] := Module[{list},
If[MemberQ[convlist, z], 1,
list =
Quiet[NestWhileList[N[(z^#)] &, z, Abs[#1 - #2] > 0.01 &, 2, max]];
If[Length[list] < max,
convlist = Union[convlist, list];
1, 0]]]
LaunchKernels[8];
ParallelEvaluate[SetSystemOptions["CatchMachineUnderflow" -> False]];
DistributeDefinitions[convQ];
SetSharedVariable[convlist];
towerFract[xmin_, xmax_, ymin_, ymax_, step_] :=
ArrayPlot[
ParallelTable[
convQ[x + I y, 50], {x, xmin, xmax, step}, {y, ymin, ymax, step}]]
towerFract[-1, 0, -1, 0, 0.01]
However, my code does not seem to work properly :
- the CPU is not used at 100% (whereas in the original version it is)
- I don't have a proper result.
I think that it may be related to the CatchMachineUnderflow option, or to the SetSharedVariable declaration.
My questions are :
- How to make my code work properly, and, if possible, efficiently?
- Is there a better way of doing what I am trying to do?
