WOLFRAM

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

Examples

open allclose all

Basic Examples  (2)Summary of the most common use cases

Make sure parallel subkernels are launched:

Out[1]=1

Values used in subkernels need to be distributed first:

Out[3]=3
Out[4]=4
Out[5]=5
Out[6]=6
Out[7]=7

Symbols in the default context are distributed automatically:

Out[2]=2
Out[3]=3

Scope  (5)Survey of the scope of standard use cases

Values of variables:

Out[1]=1
Out[2]=2

Functions:

Out[1]=1
Out[2]=2

Upvalues:

Out[1]=1
Out[2]=2

Attributes:

Out[1]=1
Out[1]=1
Out[2]=2

Distribute definitions for all symbols in the current context:

Out[3]=3

Generalizations & Extensions  (1)Generalized and extended use cases

Auxiliary definitions on which a distributed definition depends are also automatically distributed:

Out[2]=2
Out[3]=3

Properties & Relations  (7)Properties of the function, and connections to other functions

DistributeDefinitions overwrites any previous values and attributes present:

Out[2]=2
Out[3]=3
Out[4]=4

Remove a distributed definition by clearing the function and distributing it again:

Out[2]=2
Out[4]=4

DistributeDefinitions uses ParallelEvaluate to transport definitions to all kernels:

An explicit ParallelEvaluate does the same:

Out[4]=4

Distributed definitions are remembered for new kernels; the effect of ParallelEvaluate is not:

Out[6]=6

For higher-level parallel commands, functions defined interactively are automatically distributed:

Out[2]=2

Distribute definitions manually and disable automatic distribution:

Out[5]=5

Symbols that have values only on the subkernels are not distributed:

Out[1]=1
Out[2]=2

The values on the subkernels remain intact:

Out[3]=3

As soon as a symbol gets a local value, it will be distributed with the next parallel computation:

Out[5]=5

Use ParallelNeeds to set up a package on all parallel kernels:

Out[2]=2

Use DistributeDefinitions to set up your own definitions:

Out[5]=5

$DistributedDefinitions gives the list of all symbols whose definitions have been distributed:

Out[2]=2
Out[3]=3

The list also includes symbols that were distributed automatically:

Out[4]=4
Out[5]=5

Possible Issues  (5)Common pitfalls and unexpected behavior

A function used that is not known on the parallel kernels may lead to sequential evaluation:

Out[2]=2

Define the function on all parallel kernels:

The function is now evaluated on the parallel kernels:

Out[4]=4

The use of DistributeDefinitions does not suppress automatic distribution of definitions:

Modify the definition:

The modified definition is automatically distributed:

Out[3]=3

Suppress the automatic distribution of definitions:

Out[6]=6

Symbols defined only on the subkernels are not distributed automatically:

Out[8]=8

Certain objects with an internal state may not work efficiently when distributed:

Out[1]=1
Out[2]=2
Out[4]=4

Recompute such objects on all subkernels for better performance:

Out[5]=5
Out[7]=7

Alternatively, reevaluate the data on all subkernels:

Out[8]=8
Out[10]=10

Definitions of symbols with the ReadProtected attribute cannot be distributed:

Out[2]=2
Out[3]=3

Definitions are only distributed as needed; if a definition has not changed, it is not distributed again:

Out[2]=2
Out[4]=4

Both symbols are still distributed:

Out[5]=5

Neat Examples  (1)Surprising or curious use cases

Quickly visualize the Gaussian primes:

Out[2]=2
Wolfram Research (2008), DistributeDefinitions, Wolfram Language function, https://reference.wolfram.com/language/ref/DistributeDefinitions.html (updated 2010).
Wolfram Research (2008), DistributeDefinitions, Wolfram Language function, https://reference.wolfram.com/language/ref/DistributeDefinitions.html (updated 2010).

Text

Wolfram Research (2008), DistributeDefinitions, Wolfram Language function, https://reference.wolfram.com/language/ref/DistributeDefinitions.html (updated 2010).

Wolfram Research (2008), DistributeDefinitions, Wolfram Language function, https://reference.wolfram.com/language/ref/DistributeDefinitions.html (updated 2010).

CMS

Wolfram Language. 2008. "DistributeDefinitions." Wolfram Language & System Documentation Center. Wolfram Research. Last Modified 2010. https://reference.wolfram.com/language/ref/DistributeDefinitions.html.

Wolfram Language. 2008. "DistributeDefinitions." Wolfram Language & System Documentation Center. Wolfram Research. Last Modified 2010. 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

Wolfram Language. (2008). DistributeDefinitions. Wolfram Language & System Documentation Center. Retrieved from https://reference.wolfram.com/language/ref/DistributeDefinitions.html

BibTeX

@misc{reference.wolfram_2025_distributedefinitions, author="Wolfram Research", title="{DistributeDefinitions}", year="2010", howpublished="\url{https://reference.wolfram.com/language/ref/DistributeDefinitions.html}", note=[Accessed: 29-March-2025 ]}

@misc{reference.wolfram_2025_distributedefinitions, author="Wolfram Research", title="{DistributeDefinitions}", year="2010", howpublished="\url{https://reference.wolfram.com/language/ref/DistributeDefinitions.html}", note=[Accessed: 29-March-2025 ]}

BibLaTeX

@online{reference.wolfram_2025_distributedefinitions, organization={Wolfram Research}, title={DistributeDefinitions}, year={2010}, url={https://reference.wolfram.com/language/ref/DistributeDefinitions.html}, note=[Accessed: 29-March-2025 ]}

@online{reference.wolfram_2025_distributedefinitions, organization={Wolfram Research}, title={DistributeDefinitions}, year={2010}, url={https://reference.wolfram.com/language/ref/DistributeDefinitions.html}, note=[Accessed: 29-March-2025 ]}