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.

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  (6)

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:

Possible Issues  (4)

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:

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

BibTeX

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

BibLaTeX

@online{reference.wolfram_2021_distributedefinitions, organization={Wolfram Research}, title={DistributeDefinitions}, year={2010}, url={https://reference.wolfram.com/language/ref/DistributeDefinitions.html}, note=[Accessed: 23-September-2021 ]}

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