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

SharedDownValues

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.

SharedDownValues

A symbol f that has been declared shared with
exists only in the master (local) kernel. The following operations on a remote kernel are redefined so that they have the described effect.
f[i], f[i, j], ...evaluation of the function or array element f[i], and so forth, will consult the master kernel for the symbol's current downvalue
f[i]=e, f[i, j]=e, f[i]:=e, ...defining a value for f[i], and so forth, will perform the definition in the master kernel
f[[i]]++, f[[i]]--, ++f[[i]], --f[[i]]the increment/decrement operation is performed in the master kernel (this operation is atomic and can be used for synchronization)
TestAndSet[f[i], e]If f[i] has no value or its value is Null, set the value to e; otherwise, do nothing and return the current value of f[i] (this operation is atomic and can be used for synchronization)

Operations on shared functions.

For technical reasons, every expression of the form f[...] must have a value. If the expression f[...] in the master kernel does not evaluate, the result is set to Null.
Note that other forms of assignments, such as conditional assignments involving side conditions, are not supported.
You can define shared functions, as in the following. Be sure that the symbol x does not have a value in either the remote kernels or in the master kernel. The symbol x should not be a shared variable.
If you make a delayed assignment on a remote kernel, the right side of the definition will be evaluated on the remote kernel when you use the function. In an immediate assignment, it is evaluated on the master kernel.
If you make a delayed assignment on the master kernel, the right side of the definition will be evaluated on the master kernel when you use the function. To cause the right side to be evaluated on the remote kernel nevertheless, use SendBack[]:
You can implement indexed variables or arrays using shared downvalues of the form x[1], x[2], and so forth.
If a function is Protected when you declare it as shared, remote kernels can only use it, but not change its definition.


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