Launching and Connecting
Mathematica can run parallel kernels in a number of different ways; locally on the same machine or remote on other machines connected in a network. Furthermore, the network might be a homogeneous grid controlled by some dedicated management application, or it might be a heterogenous grid. To use all these different configurations
Mathematica needs to launch the parallel kernels and then communicate with them. When working with remote machines it is complicated to launch the parallel kernels. However the parallel kernels were launched, communication always uses
MathLink.
Typically,
Mathematica launches parallel kernels automatically as they are needed. This uses settings from the
Parallel Preferences, but you can also launch kernels manually with the command
LaunchKernels. This might be useful if you were running in a batch mode.
This section will discuss issues related to launching and connecting to parallel kernels. It will cover the different connection methods that are provided, each specialized to the different types of environment in which
Mathematica may be running.
Launching Kernels
Mathematica parallel computation will, typically, automatically launch kernels when a parallel command is executed. The kernels that are launched are those that are set in the
Parallel Preferences. The default setting is to launch kernels that run on the same computer, using the
Local Kernels connection method; for a two-core machine there will be two parallel kernels. You can see the kernels that will be automatically launched with
$ConfiguredKernels; in the following there will be two local kernels.
| Out[1]= |  |
If you use
LaunchKernels, with no arguments this will launch the kernels that have been configured. Here, the two kernels are launched.
| Out[2]= |  |
Note that you do not need to use
LaunchKernels, instead if you had used a parallel command such as
ParallelTable, the kernels would also have been launched automatically.
At any time you can see the kernels that are running with
Kernels. This shows the two kernels that have been launched.
| Out[3]= |  |
You can also use
LaunchKernels to launch kernels manually, without configuring them in the preferences. The details are different for each connection method and are described in the following sections.
The rest of this section now describes configuration and launching for each of the different connection methods.
Local Kernels
The Local Kernels connection method is used to run parallel kernels on the same computer as the master
Mathematica. It is suitable for a multi-core environment, and is the easiest way to set up for parallel computation.
Configuration of the Local Kernels connection method is done through the
Parallel Preferences. The configuration panel looks similar to the following.
Since the parallel kernels are all launched on the same computer as the master kernel this is the easiest to configure. The main question is the number of kernels to be launched, the automatic setting is to use the number of processor cores and the number of parallel kernel licenses.
The number of processor cores is given by
$ProcessorCount; if you with to change its value you can unprotect it and assign a new value. Here, its value is 2.
| Out[1]= |  |
The number of parallel kernel licenses is given by

which is controlled by the
Mathematica license. Here the value is 4.
| Out[2]= |  |
A setting of 4 means that you can launch up to 4 parallel kernels.
Manual Launching
If you want to launch kernels manually and avoid the configuration mechanism you can pass arguments directly to
LaunchKernels. This might be useful if you were running
Mathematica in a batch mode directly from a command line.
| LaunchKernels[num] | Launch num local kernels. |
| LaunchKernels["localhost"] | Launch a local kernel. |
| LaunchKernels[LocalMachine[num]] | Launch num local kernels. |
| LaunchKernels[LocalMachine[cmd]] | Launch a local kernel using operating-system command cmd. |
Manual launching of local kernels.
The Local Kernels connection method supports launching local kernels directly from
LaunchKernels by passing it an integer (setting the number of kernels) or by specifiying the string
localhost. In addition, you can give more detailed settings inside of
LocalMachine. To do so you must first load the
LocalKernels` package, this is shown below.
Now you can pass arguments to
LocalMachine. The following sets the number of local kernels to launch.
| Out[2]= |  |
It might be more useful to change the command used to launch remote kernels. The default command is set by
$mathkernel, which has a typical setting as follows.
You can pass the command directly into
LocalMachine. The following would be suitable for a non-standard installation of
Mathematica.
| Out[3]= |  |
An alternative would be to modify the value of
$mathkernel before launching any kernels.
Once you have launched the parallel kernels then all the parallel functions of
Mathematica can be used.
The Lightweight Grid
The Lightweight Grid connection method is used to run parallel workers on different computers from the master
Mathematica. It uses Wolfram Lightweight Grid technology to launch
Mathematica on the remote machines. It is suitable for a heterogeneous network and where there is no management technology.
Configuration of the Lightweight Grid connection method is done through the
Parallel Preferences. The configuration panel should look similar to the following.
In this setup the master kernel has found three other computers running a Lightweight Grid Manager and each is configured to run 2 kernels.
More information can be found in the
Lightweight Grid documentation.
Manual Launching
If you want to launch kernels manually and avoid the configuration mechanism you can pass arguments directly to
LaunchKernels. This might be useful if you were running
Mathematica in a batch mode directly from a command line.
| LaunchKernels[url] | Launch a kernel using the Lightweight Grid on server url. |
| LaunchKernels[LightweightGrid[url]] | Launch a kernel using the Lightweight Grid on server url. |
Manual launching of Lightweight Grid kernels.
The Lightweight Grid connection method supports launching kernels directly from
LaunchKernels by passing it the name of a Lightweight Grid manager. In addition, you can give more detailed settings inside of
LightweightGrid. To do so you must first load the
LightweightGridClient` package, this is shown below.
Now you use arguments in
LightweightGrid when you launch a kernel. An example is shown below.
| Out[2]= |  |
Once you have launched the parallel kernels then all the parallel functions of
Mathematica can be used.
More information can be found in the
Lightweight Grid documentation.
Cluster Integration
The Cluster Integration connection method is used to run parallel workers on different computers from the master
Mathematica. It integrates with a large number of third party cluster management technologies.
Configuration of the Cluster Integration connection method is done through the
Parallel Preferences. The configuration panel should look similar to the following.
In this setup one cluster has been configured to use Windows Computer Cluster Server, with a head node of clusterboss. Each machine is setup to run 2 kernels.
Mathematica supports the following cluster management technologies.
- Windows Computer Cluster Server
- Platform
LSF®
- Altair
PBS Professional®
Manual Launching
If you want to launch kernels manually and avoid the configuration mechanism you can pass arguments directly to
LaunchKernels. This might be useful if you were running
Mathematica in a batch mode directly from a command line.
| LaunchKernels[cluster[args]] | Launch a kernel using Cluster Integration on cluster. |
Manual launching of ClusterIntegration kernels.
The Cluster Integration connection method supports launching kernels directly from
LaunchKernels. To do so you must first load the
ClusterIntegration` package, this is shown below.
To launch on a particular cluster you have to pass the name for that cluster into
LaunchKernels. For example, to use Windows Compute Cluster Server, you would use
CCS. An example is shown below which launches two kernels.
| Out[2]= |  |
Note that for this to work you need to have Windows Compute Cluster Server configured to work.
Once you have launched the parallel kernels then all the parallel functions of
Mathematica can be used.
More information can be found in the
Cluster Integration documentation.
Remote Kernels
The Remote Kernels connection method is used to run parallel workers on different computers from the master
Mathematica. It relies on using remote shell invocation technology for launching, and is typically harder to configure and maintain.
Configuration of the Remote Kernels connection method is done through the
Parallel Preferences. The configuration panel should look similar to the following.
In this configuration two remote machines are configured each to provide four parallel kernels.
On Windows the default setting is to use rsh to launch kernels on the remote machines, other platforms use ssh. This is because ssh is typically not available for Windows. Of course, any machines will have to be configured to allow remote shell invocation from the master machine.
You can modify the launch command that is used to launch the kernel. In the command you can use a number of parameters that are inserted before the command is actually used. For example, the parameter `1` is used to refer to the name of the remote machine that is being used.
| `1` | The name of the remote machine. |
| `2` | The name of the link created on the local machine (when the remote machine is connecting). |
| `3` | The user name to execute the remote shell. |
| `4` | The link protocol to use to for the MathLink connection. |
Launch command parameters.
The default value for the user name is to use
$UserName, the user running the local copy of
Mathematica.
Manual Launching
If you want to launch kernels manually and avoid the configuration mechanism you can pass arguments directly to
LaunchKernels. This might be useful if you were running
Mathematica in a batch mode directly from a command line.
| LaunchKernels[RemoteMachine[host]] | Launch a remote kernel on machine host. |
| LaunchKernels[RemoteMachine[host, num]] | Launch num remote kernels on machine host. |
| LaunchKernels[RemoteMachine[host, command, num]] | Launch num remote kernels on machine host using command as a remote command. |
Manual launching of remote kernels.
The Remote Kernels connection method supports launching remote kernels directly from
LaunchKernels. To do so you must first load the Remote
Kernels` package, this is shown below.
To launch you pass arguments in
RemoteMachine. The following launches one remote kernel on machine
remote1.wolfram.com.
| Out[2]= |  |
It might be more useful to change the command used to launch remote kernels. The default command is set by
$RemoteCommand, which has a typical setting as follows. Note that rsh is only used on Windows, on other platforms ssh is used.
Note that the parameters for the remote command are described in the
previous section. The user name argument is set by
$RemoteUserName, which is set by defult to
$UserName.
You can pass the command directly into
LocalMachine. The following would be suitable for a non-standard installation of
Mathematica.
An alternative would be to modify the value of
$RemoteKernel before launching any kernels.
Once you have launched the parallel kernels then all the parallel functions of
Mathematica can be used.
Raw MathLink Connections
It is also possible to launch parallel kernels with raw
MathLink connections. This is an extremely inconvenient way to setup parallel computation and is only useful for testing purposes.
In the following example, the application for raw link connections is loaded. Then another copy of
Mathematica is launched giving both -subkernel and -mathlink as command line options. Finally, this link is passed to
LaunchKernels, making the remote kernel a worker kernel.
| Out[3]= |  |
| Out[4]= |  |