Accessing results in ParallelDo
- To: mathgroup at smc.vnet.net
- Subject: [mg126093] Accessing results in ParallelDo
- From: Themis Matsoukas <tmatsoukas at me.com>
- Date: Mon, 16 Apr 2012 06:10:06 -0400 (EDT)
- Delivered-to: l-mathgroup@mail-archive0.wolfram.com
I have been experimenting with parallel computing on Mathematica 8 on a two core MacBook Pro but I can't figure how to access to the results calculated in ParallelDo. Here is a a simple loop that builds a list b by appending random numbers. This runs fine and prints list b as it is generated in each of the two kernels. However, when I ask for b at the end of the loop I get b={}. ClearAll["Global`*"]; CloseKernels[]; LaunchKernels[]; NoP = 4; b = {}; ParallelDo[ b = Append[b, RandomInteger[{1, NoP}]]; Print["b = ", b], {i, 1, 4} ]; Print["Final result: b=", b] b = {4} <---kernel 2 (my annotation) b = {3} <---kernel 1 b = {4,2} <---kernel 2 b = {3,3} <---kernel 1 Final result: b={} My question is, how do I pass the results of ParallelDo into a variable outside the loop? Thanks