Legacy Documentation

Parallel Computing Toolkit (2000)

This is documentation for an obsolete product.
Current products and services
Previous section-----Next section

Remote Definitions

Remote kernels do not have access to the values of variables defined in the local master kernel, nor do they have access to locally defined functions.
Parallel Computing Toolkit contains a command ExportEnvironment that makes it easy to transport local variables and definitions to all remote kernels. The main advantage of this method is that the application package does not need to be installed on the remote kernels. All definitions are sent through the existing connection to the remote kernels.

Exporting Definitions

ExportEnvironment[{s1, s2, ... }]export all definitions for symbols si to all remote kernels
ExportEnvironment[s1, s2, ... ]the same as ExportEnvironment[{s1, s2, ...}]
ExportEnvironment["Context`"]export all definitions for all symbols in the given context

Exporting definitions.

ExportEnvironment has the attribute HoldAll to prevent the evaluation of the symbols.
ExportEnvironment exports the following kinds of definitions: OwnValues, DownValues, SubValues, UpValues, DefaultValues, NValues.
ExportEnvironment sets the attributes of the remote symbols equal to the locally defined attributes, except for attributes such as Protected and Locked.
Any old definitions existing on the remote side are cleared before the new definitions are made.

Examples

Before evaluating these examples, load the package and then start several remote kernels.
In[1]:=
Define a variable with a value and a function with attributes.
In[2]:=
In[3]:=
The remote kernels do not know the symbol var as demonstrated with the next evaluation.
In[5]:=
Out[5]=
Here is a subtle point. The following remote evaluation seems to work, even though the symbols are not defined on the remote side.
In[6]:=
Out[6]=
The reason is that the remote kernels return the unevaluated expression func[var], because the function and variable are not defined on the remote kernel. The master kernel evaluates the returned results further, but it does so sequentially.
You can easily produce an example where the difference between remote and local evaluation becomes apparent.
On the local kernel, the symbol var evaluates to 5, and the Head of 5 is Integer.
In[7]:=
Out[7]=
On the remote kernels, var stays a symbol, and its head is Symbol.
In[8]:=
Out[8]=
You can export the local definitions to the remote kernels.
In[9]:=
Now the remote evaluation gives the same result as the local one.
In[10]:=
Out[10]=

Exporting Contexts

ExportEnvironment["Context`"] exports all definitions for all symbols in the given context. Thus, you can use the following to make all your interactively entered definitions known to the remote kernels.
In[11]:=
Out[11]=
Exporting the context of a package you have loaded may not have the same effect on the remote kernels as loading the package on each remote kernel. The reason is that loading a package may perform certain initializations and it may also define auxiliary functions in other contexts (such as a private context). Also, a package may load additional auxiliary packages that establish their own contexts.
ExportEnvironment["Context`"] is useful for exporting contexts for definitions that you have explicitly set up to be used on remote kernels. There is a separate command RemoteNeeds[] for remote loading of packages.
ClearSlaves[] clears any definitions for symbols in the Global` context on remote kernels.

Loading Packages on Remote Kernels

RemoteNeeds["Context`"]calls Needs["Context`"] in all remote kernels

Loading packages.

RemoteNeeds["Context`"] is essentially equivalent to RemoteEvaluate[Needs["Context`"]], but it is remembered and any newly launched remote kernels will be initialized as well.
Exporting the context of a package you have loaded may not have the same effect on the remote kernels as loading the package on each remote kernel with RemoteNeeds[]. The reason is that loading a package may perform certain initializations and it may also define auxiliary functions in other contexts (such as a private context). Also, a package may load additional auxiliary packages that establish their own contexts.
The next two commands load the Mathematica package FiniteFields` on the master kernel and all remote kernels.
In[12]:=
In[13]:=
Note that Mathematica packages available to the Version 6 master kernel may not be available on Version 5.2 remote kernels.

Example: Eigenvalues of Matrices

Definitions

The parameter prec gives the desired precision for the computation of the eigenvalues of a random nn matrix.
In[1]:=
The function mat generates a random nn matrix with numeric entries.
In[2]:=
The function tf measures the time it takes to find the eigenvalues.
In[3]:=
Make all these definitions known to all slave processors with the following command.
In[4]:=
Clear the local value of prec, since it is no longer needed. Then check that the definitions have been carried over to the slave processors.
In[5]:=
In[6]:=
Out[6]=

A sample run

Here you measure the time it takes to find the eigenvalues of 55 to 2525 matrices. Because the computations happen on remote computers that differ in their processor speeds, the results do not necessarily form an increasing sequence.
In[7]:=
Out[7]=
Alternatively, you can perform the same computation on each slave processor to measure their relative speed. Here you find the speed of calculation of the eigenvalues of a 2020 matrix on each of three slave processors.
In[8]:=
Out[8]=