Hi guys I've the following problem with ParallelDo: if I run the code:
r1 = {};
r2 = {};
zmin = 6;
zmax = 9;
tpass = 1;
zpass = 0.001;
Do[
MLEdata = Table[MLE[z, t], {z, zmin, zmax, zpass}];
MaxPeak = Max[MLEdata];
PosPeak = Position[MLEdata, MaxPeak];
OverHalfPeak = Select[MLEdata, # > MaxPeak/2 &];
NumPoints = Length[OverHalfPeak];
AppendTo[r1, PosPeak];
AppendTo[r2, NumPoints], {t, tmin, tmax, tpass}]
zPeak = zmin - zpass + r1*zpass // Flatten; (*pos. in um*)
DeltaMLE = r2 - 1; (*FWHM in nm*)
dat = Flatten /@ Transpose[{zPeak, DeltaMLE}];
Export["axial track.txt", dat, "Table"];
I get the values in zPeak and DeltaMLE listed in the right order, but if I use ParallelDo like this to speed up the computation:
r1 = {};
r2 = {};
SetShareVariable[r1,r2]
zmin = 6;
zmax = 9;
tpass = 1;
zpass = 0.001;
ParallelDo[
MLEdata = Table[MLE[z, t], {z, zmin, zmax, zpass}];
MaxPeak = Max[MLEdata];
PosPeak = Position[MLEdata, MaxPeak];
OverHalfPeak = Select[MLEdata, # > MaxPeak/2 &];
NumPoints = Length[OverHalfPeak];
AppendTo[r1, PosPeak];
AppendTo[r2, NumPoints], {t, tmin, tmax, tpass}]
zPeak = zmin - zpass + r1*zpass // Flatten; (*pos. in um*)
DeltaMLE = r2 - 1; (*FWHM in nm*)
dat = Flatten /@ Transpose[{zPeak, DeltaMLE}];
Export["axial track.txt", dat, "Table"];
the order is completely wrong. I understand that there are some side effects, but I don't understand how to correct for them (I'm pretty new with the parallelization). Could you help me?
Tableand avoiding side-effects (i.e.AppendTo) entirely? – Szabolcs Feb 18 '16 at 12:50MLE,tminandtmaxare missing. – Berg Feb 18 '16 at 13:14