How can I make definitions inside ParallelTable
to use them outside?
For example, if I execute:
ParallelTable[a[i] = i, {i, 1, 3}]
and after that, I try to access the value of a[1]
, I don't get 1
as I'd expect. Is there a way to make definitions inside ParallelTable
so that I can access to them outside?
Note that what I want to do is more sophisticated than the trivial example above. Though there would probably be a way to do it without making definitions inside ParallelTable
, it would really make my life easier if I could do it.
a
! There are as manya
's as you started subkernels and everya
has a different value. If the situation is as simple as in your toy example, alla
's are equal of course, but then there would be no reason to do this on the parallel kernels. Question: Which of thea
's would like to be defined on your main kernel? $\endgroup$a
indeed depends on the executed code of the sub-kernel:ParallelTable[a = i; i, {i, 1, 20}]; ParallelEvaluate[a]
$\endgroup$SetSharedVariable[a]
. The value ofa
will be held only in the master kernel and read by the slave kernels only via callbacks, so there could be some performance implications in this case. $\endgroup$