Mathematica Stack Exchange is a question and answer site for users of Mathematica. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

This question arose during my analysis of the following problem: filling gaps. (The code used here is Simon Woods's work.)

FoldList seems to not cooperate with ParallelMap and I do not understand it:

f[_, y_] := y
f[x_, "."] := x

fill[data_] := 
 Transpose[FoldList[f, First[#], Rest[#]] & /@ Transpose[data]]

fillP[data_] := Transpose[
   FoldList[f, First[#], Rest[#]] &,

data = Table[RandomChoice[{1, "."}], {10^6}, {4}]~Prepend~(Range@4);

Timings are as follows:

fill@data; // Timing // First (* -> 3.868825 *)
fillP@data; // Timing // First (* -> 4.056026 *)
share|improve this question
Try mapping Length instead of FoldList[..]&, and maybe do a ByteCount on data. See what happens. – Michael E2 Jun 10 '13 at 21:57
@MichaelE2 Map is faster then. I assume it is because of something like "preparing for parallelization". But for more complicated procedures than Lenght I expect faster ParallelMap option. It worked for some types of procedures (link). Or maybe I do not see what You are trying to tell me :) – Kuba Jun 10 '13 at 22:13
What did you find for ByteCount@data? Almost 200MB? That has to be sent to each kernel. What happens to the timings of Length if the data is cut in half? Or to a tenth of its size? Is the time proportional to the size of data? Perhaps you will be able to answer your own question. ;D – Michael E2 Jun 10 '13 at 22:29
See also: (2886) – Oleksandr R. Jun 11 '13 at 3:24
I linked Simon's name to his profile. This is not so much an issue of attribution, but since users are able to change their usernames, if they do so, the interpretation of references to their old identities becomes extremely confusing otherwise. – Oleksandr R. Jun 11 '13 at 3:36

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.