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

Examples

open allclose all

Basic Examples  (2)

Make sure parallel subkernels are launched:

Values used in subkernels need to be distributed first:

Symbols in the default context are distributed automatically:

Scope  (5)

Values of variables:

Functions:

Upvalues:

Attributes:

Distribute definitions for all symbols in the current context:

Generalizations & Extensions  (1)

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

Properties & Relations  (7)

DistributeDefinitions overwrites any previous values and attributes present:

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

DistributeDefinitions uses ParallelEvaluate to transport definitions to all kernels:

An explicit ParallelEvaluate does the same:

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

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

Distribute definitions manually and disable automatic distribution:

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

The values on the subkernels remain intact:

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

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

Use DistributeDefinitions to set up your own definitions:

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

The list also includes symbols that were distributed automatically:

Possible Issues  (5)

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

Define the function on all parallel kernels:

The function is now evaluated on the parallel kernels:

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

Modify the definition:

The modified definition is automatically distributed:

Suppress the automatic distribution of definitions:

Symbols defined only on the subkernels are not distributed automatically:

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

Recompute such objects on all subkernels for better performance:

Alternatively, reevaluate the data on all subkernels:

Definitions of symbols with the ReadProtected attribute cannot be distributed:

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

Both symbols are still distributed:

Neat Examples  (1)

Quickly visualize the Gaussian primes:

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).

CMS

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

BibTeX

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

BibLaTeX

@online{reference.wolfram_2024_distributedefinitions, organization={Wolfram Research}, title={DistributeDefinitions}, year={2010}, url={https://reference.wolfram.com/language/ref/DistributeDefinitions.html}, note=[Accessed: 21-November-2024 ]}