({{, (RefLink[$DistributedContexts, paclet:ref/$DistributedContexts])
is the default value of the (RefLink[DistributedContexts, paclet:ref/DistributedContexts]) option of functions such as (RefLink[ParallelTable, paclet:ref/ParallelTable]) and (RefLink[ParallelMap, paclet:ref/ParallelMap]).}})

OpenersNotesSection(Spacer1)Details

Before a parallel computation, definitions of symbols to be evaluated in a parallel kernel will automatically be distributed to all kernels, provided these symbols belong to a context given in the (RefLink[DistributedContexts, paclet:ref/DistributedContexts]) option.

The initial value is $DistributedContexts:=(RefLink[$Context, paclet:ref/$Context]), which distributes definitions of all symbols in the current context, but does not distribute definitions of symbols from packages.

OpenersPrimaryExamplesSection(Spacer1)Examples  (8)

OpenersExampleSection0(Spacer1)Basic Examples  (1)

Turn off automatic distribution of functions:

$DistributedContexts=None;

f[i_]:={i,$KernelID}

ParallelMap[f,{1,2,3,4}]

Restore the default value:

$DistributedContexts:=$Context

OpenersExampleSection1(Spacer1)Scope  (5)

By default, definitions in the current context are distributed automatically:

remote[x_]:={$KernelID,x^3}

ParallelTable[remote[i],{i,4}]

Do not distribute any definitions:

$DistributedContexts=None;

local[x_]:={$KernelID,x^2}

ParallelTable[local[i],{i,4}]

Distribute definitions for all symbols in all contexts appearing in a parallel computation:

$DistributedContexts=Automatic;

a`k:=$KernelID
b`k:=-$KernelID

ParallelTable[{a`k,b`k},{4}]

Distribute only definitions in the given contexts:

$DistributedContexts="a`";

a`m:=$KernelID
b`m:=-$KernelID

ParallelTable[{a`m,b`m},{4}]

Restore the default value:

$DistributedContexts:=$Context

OpenersExampleSection3(Spacer1)Properties & Relations  (1)

Find all parallel functions that currently use (RefLink[$DistributedContexts, paclet:ref/$DistributedContexts]):

Select[Names["System`Parallel*"],MemberQ[Options[Symbol[#]],DistributedContexts:>$DistributedContexts]&]

OpenersExampleSection4(Spacer1)Possible Issues  (1)

The value of (RefLink[$DistributedContexts, paclet:ref/$DistributedContexts]) is not used in (RefLink[Parallelize, paclet:ref/Parallelize]):

$DistributedContexts=None;

local1[x_]:={$KernelID,x^2}

Parallelize[Table[local1[i],{i,4}]]

Set the value of the (RefLink[DistributedContexts, paclet:ref/DistributedContexts]) option of (RefLink[Parallelize, paclet:ref/Parallelize]):

SetOptions[Parallelize,DistributedContexts->None]

local2[x_]:={$KernelID,x^3}

Parallelize[Table[local2[i],{i,4}]]

Restore all settings to their default values:

$DistributedContexts:=$Context

SetOptions[Parallelize,DistributedContexts:>$Context]

({{DocumentationFooterIconsRelatedFunction.png, ({{See Also}, {(RefLink[DistributedContexts, paclet:ref/DistributedContexts])  ▪  (RefLink[DistributeDefinitions, paclet:ref/DistributeDefinitions])  ▪  (RefLink[ParallelMap, paclet:ref/ParallelMap])  ▪  (RefLink[ParallelTable, paclet:ref/ParallelTable])}})}})