# ParallelTable and DistributeDefinitions

I have a function in the following form:

function[...] := With[
{...},
Table[
anotherfunction[i, j, ...],
{i, ...},
{j, ...},
...
]
]


If I'd like to replace Table with ParallelTable, do I need to put DistributeDefinitions["Global"] somewhere? If yes, where? (Before With, before ParallelTable, or before calling function?)

anotherfunction is defined globally, and uses other global variables.

-
I added the backtick. Click the edit link and see the source on how to do it (you need to surround the code with $n+1$ backticks if you want to include $n$ backticks). – Szabolcs Dec 20 '13 at 18:07

ParallelTable will automatically distribute the definitions of symbols used in the body of the table, as well as any dependencies, in version 8 and later. It is not necessary to use DistributeDefinitions with ParallelTable in these versions.
Note that ParallelEvaluate does not automatically distribute definitions like Parallelize, ParallelTable, ParallelMap, ParallelDo, etc. do. You do need to use DistributeDefinitions if you rely on ParallelEvaluate, however, you do not need to distribute the definitions of all symbols. Just distribute the symbol that you are actually using, anotherfunction in this case. DistributeDefinitions is smart enough to auto-distribute all the dependencies as well (unless you do something unusual such as converting strings to symbol names).
I'm not sure the opening sentence is correct, or DistributeDefinitions would be of very-corner-case usefulness only. As a simple counterexample, try BeginPackage["Test"]; Testf = Function[x, \$KernelID]; EndPackage[]; ParallelTable[f[x], {x, 8}], where the table is obviously returning the f[x] unevaluated for the master kernel to rework. Adding DistributeDefinitions["Test"] makes the table return a correct list of nonzero IDs. – Emilio Pisanty Apr 24 at 18:58
@Szabolcs Apologies, I didn't mean to come across anywhere near aggressive. My point was that it would be helpful to add '(excluding functions in packages)', or something similar, just as a note to new users that there are special considerations in place if packages or other contexts are in use. To be frank, though, I still don't fully understand what does and does not get distributed by default by ParallelTable, so I didn't want to jump into the wiki and write something that's wrong. If you feel that it's too much load on an introductory answer, though, that's still fine =). – Emilio Pisanty Apr 24 at 19:23