SetSharedVariable

SetSharedVariable[s1,s2,]

declares the symbols si as shared variables whose values are synchronized among all parallel kernels.

Details

  • The unique value of a shared variable is maintained by the master kernel and every access on a parallel subkernel is synchronized through the master kernel.
  • Shared variables without a value evaluate to Null.

Examples

open allclose all

Basic Examples  (1)

Make xs be a (global) shared variable:

In[1]:=
Click for copyable input

Each subkernel increments the (global) shared variable value:

In[2]:=
Click for copyable input
Out[2]=
In[3]:=
Click for copyable input
Out[3]=

Without sharing, each subkernel has its own (local) copy of the variable:

In[4]:=
Click for copyable input
In[5]:=
Click for copyable input
Out[5]=
In[6]:=
Click for copyable input
Out[6]=

Scope  (4)

Generalizations & Extensions  (1)

Applications  (5)

Properties & Relations  (1)

Possible Issues  (1)

See Also

$SharedVariables  UnsetShared  SetSharedFunction  DistributeDefinitions  OwnValues

Introduced in 2008
(7.0)