Short answer.
Here is my answer to a different question that illustrates how you can build a list in parallel.
Long answer.
First of all, you should not use Append to incrementally build lists, as pointed out by @Roman. Lists are implemented as arrays inside Mathematica, and so Append, effectively, copies the whole array at every iteration. The following takes 3 seconds on my machine:
aaa = {}; Do[aaa = Append[aaa, i], {i, 50000}] // AbsoluteTiming
There are two useful idioms to avoid this copying: (a) create a linked list, or (b) use Sow and Reap.
bbb = {}; Do[bbb = {bbb, i}, {i, 50000}]; bbb = Flatten[bbb]; // AbsoluteTiming
(* {0.024124, Null} *)
ccc = Reap[Do[Sow[i], {i, 50000}]][[2, 1]]; // AbsoluteTiming
(* {0.019154, Null} *)
aaa == bbb == ccc
(* True *)
However, you cannot directly use Sow and Reap with Parallel do as described here. And the double-linked trick wouldn't work either, because the parallel kernel that executes your code needs to modify the same variable. The ParallelEvaluate in the above-linked solution solves this problem.
Appendis a terribly inefficient way of constructing a list. Please look intoTableorSow. – Roman Feb 01 '23 at 16:12AppendToit works. Tryaaa = {}; Do[Do[AppendTo[aaa, {i, j}], {j, 1, 5}], {i, 4}]and checkaaa. One gets the list you want byTableeasier and faster. But perhaps, your problem is more complex than described in the question. – Alexei Boulbitch Feb 01 '23 at 16:19Do, notParallelDo. – Victor K. Feb 01 '23 at 16:35Do) stops working withParallelDo. YourAppendTocode is also unlikely to work with parallelization - you cannot assign to the same variable across multiple threads, without some additional tricks. – Victor K. Feb 01 '23 at 16:48