DistributeDefinitions[s1,s2,…]
distributes all definitions for the symbols si to all parallel kernels.
DistributeDefinitions["context`"]
distributes definitions for all symbols in the specified context.
DistributeDefinitions
DistributeDefinitions[s1,s2,…]
distributes all definitions for the symbols si to all parallel kernels.
DistributeDefinitions["context`"]
distributes definitions for all symbols in the specified context.
Details and Options
- DistributeDefinitions in effect applies ParallelEvaluate to all assignments for values and attributes with the symbols si, including not only ownvalues but also downvalues, upvalues, and other types of values.
- DistributeDefinitions applies itself recursively to any symbols appearing in the definitions of the symbols si.
- DistributeDefinitions has attribute HoldAll.
- DistributeDefinitions in effect "registers" the definitions for the symbols si so that they are automatically distributed to every new parallel kernel that may be launched.
- DistributeDefinitions[expr] for an arbitrary expression expr distributes definitions for all symbols appearing in expr.
- The following options can be given:
-
DistributedContexts $DistributedContexts contexts of symbols considered for distribution ProgressReporting $ProgressReporting whether to report the progress of the computation - Only symbols whose context is listed in the contexts given by the DistributedContexts option are considered for distribution of definitions.
- The ProgressReporting option specifies whether to report the progress of the distribution of definitions.
- DistributeDefinitions returns the list of symbols actually distributed, wrapped in HoldForm. Symbols whose definition has not changed are not included.
Examples
open all close allBasic Examples (2)
Make sure parallel subkernels are launched:
LaunchKernels[];$KernelCountValues used in subkernels need to be distributed first:
ctx`y = 42;ParallelEvaluate[ToString[ctx`y]]$DistributedDefinitionsDistributeDefinitions[ctx`y]ParallelEvaluate[ToString[ctx`y]]$DistributedDefinitionsSymbols in the default context are distributed automatically:
y = 43;ParallelEvaluate[ToString[y]]$DistributedDefinitionsScope (5)
ni = 5;nd := $KernelID
DistributeDefinitions[ni, nd]ParallelEvaluate[{ni, nd}]nfactors[n_] := Total[FactorInteger[(10 ^ n - 1/9)][[All, 2]]]
DistributeDefinitions[nfactors]ParallelMap[nfactors, Range[50, 70]]g/:f[g[x_]] := fg[x, $KernelID]
DistributeDefinitions[g]ParallelMap[f, {g[1], h[2], g[3]}]np = 5;Protect[np]
DistributeDefinitions[np]ParallelEvaluate[np = $KernelID, First[Kernels[]]]Distribute definitions for all symbols in the current context:
f[x_] := N[Pi ^ x, $prec];$prec = 50;DistributeDefinitions[Evaluate[Context[]]];ParallelEvaluate[f[$KernelID]]Generalizations & Extensions (1)
Auxiliary definitions on which a distributed definition depends are also automatically distributed:
prec = 18;
mtest[n_] := Timing[Inverse[RandomReal[{-1, 1}, {n, n}, WorkingPrecision -> prec]]][[1]]DistributeDefinitions[mtest]ParallelTable[mtest[i], {i, 10, 100, 10}]Properties & Relations (7)
DistributeDefinitions overwrites any previous values and attributes present:
ParallelEvaluate[f[0] = "Zero";f[x_] := x ^ 2, DistributedContexts -> None];ParallelMap[f, {0, 1, 2, 3, 4}, DistributedContexts -> None]f[x_] := x ^ 2
DistributeDefinitions[f]ParallelMap[f, {0, 1, 2, 3, 4}, DistributedContexts -> None]Remove a distributed definition by clearing the function and distributing it again:
f[x_] := Labeled[Framed[x ^ 2], $KernelID]
DistributeDefinitions[f];ParallelMap[f, {1, 2, 3, 4}]ClearAll[f];DistributeDefinitions[f];ParallelMap[f, {1, 2, 3, 4}]DistributeDefinitions uses ParallelEvaluate to transport definitions to all kernels:
f[n_] := PrimeQ[2 ^ n - 1]DistributeDefinitions[f];An explicit ParallelEvaluate does the same:
ParallelEvaluate[g[n_] := PrimeQ[2 ^ n + 1]];ParallelEvaluate[Through[{Identity, f, g}[$KernelID]]]Distributed definitions are remembered for new kernels; the effect of ParallelEvaluate is not:
CloseKernels[];LaunchKernels[];ParallelEvaluate[Through[{Identity, f, g}[$KernelID]]]For higher-level parallel commands, functions defined interactively are automatically distributed:
ftest[n_] := Labeled[Framed[PrimeQ[2 ^ n - 1]], $KernelID]ParallelMap[ftest, Range[1275, 1285]]Distribute definitions manually and disable automatic distribution:
gtest[n_] := Labeled[Framed[PrimeQ[2 ^ n - 1]], $KernelID]DistributeDefinitions[gtest];ParallelMap[gtest, Range[1275, 1285], DistributedContexts -> None]Symbols that have values only on the subkernels are not distributed:
ParallelEvaluate[xr = 5]DistributeDefinitions[xr]The values on the subkernels remain intact:
ParallelTable[Sqrt[i] / xr, {i, 5}]As soon as a symbol gets a local value, it will be distributed with the next parallel computation:
xr = 6;ParallelTable[Sqrt[i] / xr, {i, 5}]Use ParallelNeeds to set up a package on all parallel kernels:
Needs["GraphUtilities`"]
ParallelNeeds["GraphUtilities`"]ParallelEvaluate[HamiltonianCycles[CompleteGraph[3], All]]Use DistributeDefinitions to set up your own definitions:
hcg[n_] := HamiltonianCycles[CompleteGraph[n], All]DistributeDefinitions[hcg];ParallelMap[hcg, Range[4]]$DistributedDefinitions gives the list of all symbols whose definitions have been distributed:
a = 2;b = 3;DistributeDefinitions[a]$DistributedDefinitionsThe list also includes symbols that were distributed automatically:
ParallelEvaluate[b]$DistributedDefinitionsPossible Issues (5)
A function used that is not known on the parallel kernels may lead to sequential evaluation:
ftest[n_] := Labeled[Framed[PrimeQ[2 ^ n - 1]], $KernelID]ParallelEvaluate[ftest[$KernelID], DistributedContexts -> None]Define the function on all parallel kernels:
DistributeDefinitions[ftest];The function is now evaluated on the parallel kernels:
ParallelEvaluate[ftest[$KernelID], DistributedContexts -> None]The use of DistributeDefinitions does not suppress automatic distribution of definitions:
f[i_] := {i, $KernelID}
DistributeDefinitions[f];Clear[f]The modified definition is automatically distributed:
Parallelize[Map[f, Range[8]]]Suppress the automatic distribution of definitions:
g[i_] := {i, $KernelID}
DistributeDefinitions[g];Clear[g]Parallelize[Map[g, Range[8]], DistributedContexts -> None]Symbols defined only on the subkernels are not distributed automatically:
ParallelEvaluate[h[i_] := {i, $KernelID}];Parallelize[Map[h, Range[8]]]Certain objects with an internal state may not work efficiently when distributed:
data = RandomReal[{-1, 1}, 1000];
fdata = ListInterpolation[data]Timing[Table[fdata[r], {r, 1.0, 1000, 0.1}];]DistributeDefinitions[fdata];ParallelEvaluate[Timing[Table[fdata[r], {r, 1.0, 1000, 0.1}];], First[Kernels[]]]Recompute such objects on all subkernels for better performance:
DistributeDefinitions[data, fdata]ParallelEvaluate[fdata = ListInterpolation[data];];ParallelEvaluate[Timing[Table[fdata[r], {r, 1.0, 1000, 0.1}];], First[Kernels[]]]Alternatively, reevaluate the data on all subkernels:
fdata1 = fdata;
DistributeDefinitions[fdata1]ParallelEvaluate[fdata1 = fdata1];ParallelEvaluate[Timing[Table[fdata1[r], {r, 1.0, 1000, 0.1}];], Last[Kernels[]]]Definitions of symbols with the ReadProtected attribute cannot be distributed:
ftest[n_] := Labeled[Framed[PrimeQ[2 ^ n - 1]], $KernelID];
SetAttributes[ftest, ReadProtected]DistributeDefinitions[ftest]ParallelMap[ftest, Range[$KernelCount]]Definitions are only distributed as needed; if a definition has not changed, it is not distributed again:
a = 2;b = 3;DistributeDefinitions[a, b]b = 4;DistributeDefinitions[a, b]Both symbols are still distributed:
$DistributedDefinitionsText
Wolfram Research (2008), DistributeDefinitions, Wolfram Language function, https://reference.wolfram.com/language/ref/DistributeDefinitions.html (updated 2025).
CMS
Wolfram Language. 2008. "DistributeDefinitions." Wolfram Language & System Documentation Center. Wolfram Research. Last Modified 2025. https://reference.wolfram.com/language/ref/DistributeDefinitions.html.
APA
Wolfram Language. (2008). DistributeDefinitions. Wolfram Language & System Documentation Center. Retrieved from https://reference.wolfram.com/language/ref/DistributeDefinitions.html
BibTeX
@misc{reference.wolfram_2026_distributedefinitions, author="Wolfram Research", title="{DistributeDefinitions}", year="2025", howpublished="\url{https://reference.wolfram.com/language/ref/DistributeDefinitions.html}", note=[Accessed: 13-June-2026]}
BibLaTeX
@online{reference.wolfram_2026_distributedefinitions, organization={Wolfram Research}, title={DistributeDefinitions}, year={2025}, url={https://reference.wolfram.com/language/ref/DistributeDefinitions.html}, note=[Accessed: 13-June-2026]}