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

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.

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.