# Mysterious behaviour of ParallelTable

This question is related to Export bug in combination with ParallelTable?.

The following code shows an even stranger bug than in the upper question.

The y-axis should always be logarithmic, but in the resulting plot files it jumps randomly between logarithmic and linear. The linear axis numbers are wrong.

ChoiceDialog[{FileNameSetter[Dynamic[outputDir], "Directory"], Dynamic[outputDir]}];
SetDirectory[outputDir];

image = ColorConvert[ExampleData[{"TestImage", "Lena"}], "Grayscale"];
levels = ImageLevels[image, "Byte"];
hist = Histogram[WeightedData @@ Transpose[levels], 256,
ScalingFunctions -> "Log", ImageSize -> 600];

ParallelTable[

fileName = StringJoin[outputDir, "\\histogram_parallel_table_", ToString[i], ".png"];

Export[fileName, hist, "PNG"],

{i, 1, 10}

];


This error does not occur when Table is used or when logarithmic scaling is removed.

For one run I got e.g. the following two different plots (there are more):

i=1:

i=6:

I am programming with Mathematica 10.3.1.0 on Windows 10 Professional 64 Bit and have an i7-4940-MX 3,1 GHz processor (4 cores).

• Possibly this is something to do with frontend rendering being used when Table is employed but kernel rendering when ParallelTable is invoked. – Ymareth Jan 18 '16 at 15:10
• Can you reproduce that? In the ParallelTable description it says: ParallelTable will give the same results as Table, except for side effects during the computation. May be something has to be specified with DistributedContexts? – mrz Jan 18 '16 at 15:21
• I'll try when home if I can. Can you try this with ParallelTable replaced with ParallelEvaluate using $KernelID insted of your iterator i? – Ymareth Jan 18 '16 at 16:02 • Were you able to reproduce the bug? How does the code exactly should look like, when ParallelEvaluate and $KernelID  are used? – mrz Jan 20 '16 at 8:53
• @mrz, this is the same bug from the other questioin, mathematica.stackexchange.com/q/104310/9490. Parallel kernels for some inane reason have trouble dealing with log ticks – Jason B. Mar 4 '16 at 13:54

Confirmation rather than answer. I'm not sure the original example is entirely functional, at least it was not for me. Mine is...

SetDirectory["F:\\Temp"]; (* Adjust to suit your environment *)
hist = Histogram[RandomVariate[NormalDistribution[0, 1], 10000], ScalingFunctions -> "Log", ImageSize -> 600]


Note log scale on y-axis in resulting histogram.

DistributeDefinitions[hist]; (*missing in original - seems necessary or remote kernels don't know what hist is.*)

ParallelEvaluate[Export[StringJoin["histogram_parallel_table_",ToString[\$KernelID],".png"],hist,"PNG"]];


This gives me a log scale in all 8 versions produced BUT only the one from kernel 1 has the scaled labelled with log intervals (1,10,100,1000). 2-8 are labelled (1,2,3,4,5,6,7,8); Ln(count).

From Kernel 1...

From Kernels 2-8...

• Running on 10.3.1 on Win 10 – Ymareth Jan 28 '16 at 21:35
• Thank you for you help ... this is strange ... I hope somebody can again look into that ... – mrz Feb 5 '16 at 17:08

This is a workaround, which I found at

example/OutOfCoreImageHistogramComputation

counts = ConstantArray[0, 256];

f[x_] := Block[{b = Clip[Floor[255*x + .5], {0, 255}]}, counts[[b + 1]]++];

image = ColorConvert[ExampleData[{"TestImage", "Lena"}], "Grayscale"];

ImageScan[f, image];

BarChart[counts, BarSpacing -> 0, ImageSize -> 600, ScalingFunctions -> "Log"]

ChoiceDialog[{FileNameSetter[Dynamic[outputDir], "Directory"], Dynamic[outputDir]}];
SetDirectory[outputDir];

ParallelTable[

fileName = StringJoin[outputDir, "\\histogram_parallel_table_", ToString[i], ".png"];

Export[fileName, plot, "PNG"],

{i, 1, 10}

];


All plots look the same and the vertical scale is always logarithmic.

For all i: