Mathematica 9 is now available
Previous section-----Next section

SharedVariables

SharedVariables[{s1, s2, ...}]declares the symbols si as shared variables
SharedVariables[s1, s2, ...]same as SharedVariables[{s1, s2, ...}]
SharedDownValues[{f1, f2, ...}]declares the symbols fi as shared functions or data types
SharedDownValues[f1, f2, ...]same asSharedDownValues[{f1, f2, ...}]

Declaring shared variables and downvalues.

The command SharedVariables has the attribute HoldAll to prevent evaluation of the given variables, which usually have values.
The effect of SharedVariables or SharedDownValues is that all currently connected and newly launched remote kernels will perform all accesses to the shared variables through the master kernel.
$SharedVariablesthe list of currently shared variables (wrapped in Hold[])
$SharedDownValuesthe list of currently shared downvalues (wrapped in Hold[])
ClearShared[s1, s2, ...]unshares the given variables or downvalues
ClearShared[]unshares all variables and downvalues

Manipulating the set of shared variables and downvalues.

Clearing kernels with ClearSlaves[] will also clear any shared variables and downvalues.

SharedVariables

A variable s that has been declared shared with SharedVariables[s] exists only in the master (local) kernel. The following operations on a remote kernel are redefined so that they have the described effect.
sevaluation of the variable will consult the master kernel for the variable's current value
s = e, s := eassigning a value to s will perform the assignment in the master kernel
s++, s--, ++s, --sthe increment/decrement operation is performed in the master kernel (this operation is atomic and can be used for synchronization)
TestAndSet[s, e]if s has no value or its value is Null, set the value to e; otherwise, do nothing and return the current value of s (this operation is atomic and can be used for synchronization)
Part[Unevaluated[s],i]extracts a part of s; the operation will transmit only the requested part over the MathLink connection, not the whole value of s
s[[i]]= ereplace the specified part of the variable with a new value; the old value of s must have the necessary structure to permit the part assignment

Operations on shared variables.

For technical reasons, every shared variable must have a value. If the variable in the master kernel does not have a value, it is set to Null.
Note that other forms of assignments, such as conditional assignments involving side conditions, are not supported.
The customary form of part extraction, s[[i]], will transmit the whole value of s to the slave kernels. Use Part[Unevaluated[s],i] to transmit only the ith component.
If a variable is Protected at the time you declare it as shared, remote kernels can only access the variable, but not change its value.


Any questions about topics on this page? Click here to get an individual response.Buy NowMore Information
THIS IS DOCUMENTATION FOR AN OBSOLETE PRODUCT.