I have a simple routine (I thought it was simple), that I cannot parallize. It goes like this

Clear[ParallelSow, Arep, Brep, xrep];
ParallelSow[expr_] := Sow[expr];

Data = Reap[ParallelDo[
     Arep = (-1 + 2 RandomInteger[]) Exp[-14 RandomReal[] ];
     Brep = (-1 + 2 RandomInteger[]) Exp[-14 RandomReal[] ];
     xrep = (-1 + 2 RandomInteger[]) Exp[-14 RandomReal[] ];
     cosmo = {A + B, B - A} /. {A -> Arep, B -> Brep, x -> xrep};
     If[Brep^2 + 4 Arep < 0, Continue[]];
     If[! (-1 <= (1/2)*(Brep + Sqrt[Brep^2 + 4*Arep]) <= 
          1 || -1 <= (1/2)*(Brep - Sqrt[Brep^2 + 4*Arep]) <= 1), 
      Continue[], , Print["Error 1"]];
     If[0.943 < cosmo[[1]] < 0.981 && cosmo[[2]] < 0.15,
      ParallelSow[{Arep, Brep, xrep, cosmo}]
      , Null, Print["Error 2"]]
     , 100000]][[2]][[1]]

And in the end I get a

ParallelDo::nopar1: <<1>> cannot be parallelized; proceeding with sequential evaluation. >>

Where <<1>> refers to the expression above.

I looked into the documentation and googled it. I have no idea what is in my code I cannot parallelize...

  • 2
    $\begingroup$ Please show a complete minimal example. Look at sscce.org for guidance. $\endgroup$
    – Szabolcs
    Commented Oct 13, 2016 at 11:36
  • $\begingroup$ Done, sorry about that. $\endgroup$
    – romanovzky
    Commented Oct 13, 2016 at 11:42

1 Answer 1


The syntax for ParallelDo is incorrect for your version of Mathematica. There should be an error message that makes this clear:

Do::itform: Argument 100000 at position 2 does not have the correct form for an iterator. >>

Use ParallelDo[..., {n}] instead of ParallelDo[..., n]

In v10.3 your syntax works. I'm not sure in which exact version this syntax was introduced, but I know that in 10.0 it doesn't work. I don't have v10.2.

  • 1
    $\begingroup$ I don't like this new syntax that omits the {...}, it causes ambiguities which lead to misunderstandings. If I had reliable WiFi, I'd link to the question, but right now my network barely works. $\endgroup$
    – Szabolcs
    Commented Oct 13, 2016 at 11:48
  • $\begingroup$ The error message was not informative enough. Thank you a lot! I should upgrade the Mathematica version, I have a university licence and can upgrade it at any time... I lost the entire morning going through many different ways of writing the same code! $\endgroup$
    – romanovzky
    Commented Oct 13, 2016 at 11:49
  • 1
    $\begingroup$ @romanovzky No need to upgrade just for this, just put in those braces. It's just a new syntax but it doesn't bring new functionality. Of course if you have access to v11, go ahead, it's nicer than 10.x :-) $\endgroup$
    – Szabolcs
    Commented Oct 13, 2016 at 11:50
  • $\begingroup$ True that. TBH I've been a bit annoyed on how many times Wolfram changes these little things in the last versions of Mathematica, it makes working the same notebook on different computers (lapton, uni desktop, etc) very frustrating... $\endgroup$
    – romanovzky
    Commented Oct 13, 2016 at 11:51

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.