I have the following code, schematically:
$runningLogFile = "data.txt";
If[FileExistsQ[$runningLogFile], Get[$runningLogFile], Export[$runningLogFile, "", "Text"];];
f[x_, y_] := Block[{},
(*do some calculation*)
(*put append result to $runningLogFile*)
]
LaunchKernels[$ProcessorCount];
DistributeDefinitions[...];
ParallelTable[f[x,y], {x, 1, 10}, {y, 0, 15}];
This code works well, except for the fact that very ocassionally (surprisingly few times in fact, but still annoying) two threads try to write the result out to $runningLogFile
at the same time, and the results output get spliced together. Is there a way to do this in a thread safe manner? (perhaps similar to critical
procedure in openmp)
ParallelEvaluate[writetolog[msg], 1]
$\endgroup$ – ssch Dec 8 '12 at 14:46