Getting results from parallel computations

Parallel instances read a global but do not set a global?

Well, I still don’t know why the above doesn’t work. But this does work.

parallel example 2.nb (5.44 KB)

Read up on DistributeDefinitions and SetSharedVariable. Your question is also the correct answer: Parallel instances read a global [via the default DistributeDefinitions] but do not set a global [unless SetSharedVariable[x] has been executed on each global variable x].

The parallel kernels run independently. “Shared” resources in RAM are not shared so much as copied between processes.

Generally, one avoids SetSharedVariable, since interprocess copying is not very efficient. Instead, return the data from each kernel, if possible. For instance:

 {ret1, ret2, ret3, ret4} = Parallelize[foo /@ Range[4]]

Thanks for this. I had tried DistributeDefinitions, but that didn’t do it. I found using Return from Parallelize did it, as you suggested, and it’s just as simple as what I originally tried.