SetSharedVariable

SetSharedVariable[s1, s2, ...]
declares the symbols as shared variables whose values are synchronized among all parallel kernels.

DetailsDetails

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

ExamplesExamplesopen allclose all

Basic Examples (1)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]=
New in 7
New to Mathematica? Find your learning path »
Have a question? Ask support »