# Draw from HistogramDistribution with ParallelTable

I wanted to check something, but ran into troubles using HistogramDistribution in combination with ParallelTable.

The code does the following: Compute a HistogramDistribution of some sample and use some function which draws from that HistogramDistribution. Here's a stripped down version of the code that reproduces my problem:

exampledist =
TruncatedDistribution[{0, 1.16},
HistogramDistribution[
RandomVariate[ExponentialDistribution[1], 1000], 3]];
SetSharedVariable[exampledist];

drawExample[n_] :=

Module[{draws = Table[0, {n}]},
(*check some stuff, do something*)
For[i = 1, i <= n, i++,
draws[[i]] = First[RandomVariate[exampledist, 1]];
];
Return[draws];
];

drawExample[3]
ParallelTable[Table[drawExample[3], {1}], {i, 1, 2}]


The output is:

{1.05817, 1.05732, 0.47069}

and

 {{{DataDistribution[<<"Histogram">>, {1000}], DataDistribution[<<"Histogram">>, {1000}], DataDistribution[<<"Histogram">>, {1000}]}}, \ {{DataDistribution[<<"Histogram">>, {1000}], DataDistribution[<<"Histogram">>, {1000}], DataDistribution[<<"Histogram">>, {1000}]}}} 

Why can't I use the distribution in ParallelTable? First I thought the definition isn't shared properly, so I added SetSharedVariable, but that didn't resolve it. Does anyone know what I am missing here? Thank you very much.

-
This just works for me. What version are you using (evaluate \$Version)? –  Andy Ross Dec 15 '12 at 23:30
8.0 for Linux x86 (64-bit) –  user13655 Dec 16 '12 at 8:51

This works. It has some redundancies, though, which I kept, because I don't know what this is part off.

exampledist =
TruncatedDistribution[{0, 1.16},
HistogramDistribution[
RandomVariate[ExponentialDistribution[1], 1000], 3]];

In[109]:= RandomVariate[exampledist, 10]

Out[109]= {0.912899, 0.628297, 0.349011, 0.650514, 0.232781, \
0.731322, 1.08089, 0.194195, 0.892419, 0.533181}

drawExample[n_] := RandomVariate[exampledist, n]

In[115]:= ParallelTable[Table[drawExample[15], {1}], {2}]

Out[115]= {{{1.04123, 0.904413, 0.370872, 0.999883, 0.160472,
0.924548, 0.522067, 0.899367, 0.224375, 0.33492, 0.765098,
0.463829, 0.820183, 0.524134, 0.480491}}, {{0.269976, 0.69883,
1.03064, 1.03798, 0.410801, 0.128295, 0.804953, 0.903301, 1.12766,
0.095034, 0.806157, 1.15963, 0.657254, 0.730021, 0.740129}}}

-
I just tried your idea with the module and it gives the same problem. The module seems to cause the problems. However, I have to keep it because drawExample does some computations before. –  user13655 Dec 15 '12 at 13:04
It works for me with Module. –  asim Dec 15 '12 at 16:11
ok, ill give it a try again. thank you for your suggestion. –  user13655 Dec 16 '12 at 8:49