Launching and Connecting

The Wolfram Language 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, the Wolfram Language 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 WSTP.

Typically, the Wolfram Language launches parallel kernels automatically as they are needed. This uses settings from Parallel Preferences, but you can also launch kernels manually with the command (RefLink[LaunchKernels, paclet:ref/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 the Wolfram Language may be running.

Launching Kernels

Wolfram Language parallel computation will, typically, automatically launch kernels when a parallel command is executed. The kernels that are launched are those that are set in 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 (RefLink[$ConfiguredKernels, paclet:ref/$ConfiguredKernels]); in the following there will be two local kernels.

$ConfiguredKernels

If you use (RefLink[LaunchKernels, paclet:ref/LaunchKernels]) with no arguments, this will launch the kernels that have been configured. Here, the two kernels are launched.

LaunchKernels[]

Note that you do not need to use (RefLink[LaunchKernels, paclet:ref/LaunchKernels])—if instead you had used a parallel command such as (RefLink[ParallelTable, paclet:ref/ParallelTable])—the kernels would also have been launched automatically.

At any time you can see the kernels that are running with (RefLink[Kernels, paclet:ref/Kernels]). This shows the two kernels that have been launched.

Kernels[]

You can also use (RefLink[LaunchKernels, paclet:ref/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 Wolfram Language. It is suitable for a multicore environment, and is the easiest way to set up for parallel computation.

Configuration of the local kernels connection method is done through 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 (RefLink[$ProcessorCount, paclet:ref/$ProcessorCount]); if you wish to change its value, you can unprotect it and assign a new value. Here, its value is 2.

$ProcessorCount

The number of parallel kernel licenses is given by $MaxLicenseSubprocesses, which is controlled by the Wolfram System license. Here the value is 4.

$MaxLicenseSubprocesses

A setting of 4 means that you can launch up to four parallel kernels.

Manual Launching

If you want to launch kernels manually and avoid the configuration mechanism, you can pass arguments directly to (RefLink[LaunchKernels, paclet:ref/LaunchKernels]). This might be useful if you were running the Wolfram Language in a batch mode directly from a command line.

Manual launching of local kernels.

The local kernels connection method supports launching local kernels directly from (RefLink[LaunchKernels, paclet:ref/LaunchKernels]) by passing it an integer (setting the number of kernels) or by specifying the string localhost. In addition, you can give more detailed settings inside of LocalMachine. To do so, you must first load the LocalKernels` package, which is shown below.

Needs["SubKernels`LocalKernels`"]

Now you can pass arguments to LocalMachine. The following sets the number of local kernels to launch.

LaunchKernels[LocalMachine[1]]

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.

??$mathkernel

You can pass the command directly into LocalMachine. The following would be suitable for a non-standard installation of the Wolfram System.

LaunchKernels[LocalMachine["'/Applications/Mathematica.app/Contents/MacOS/MathKernel' -subkernel -noinit -mathlink"]]

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 the Wolfram Language can be used.

The Lightweight Grid

The Lightweight Grid connection method is used to run parallel workers on different computers from the master Wolfram Language. It uses Wolfram Lightweight Grid technology to launch the Wolfram Language 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 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 two 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 (RefLink[LaunchKernels, paclet:ref/LaunchKernels]). This might be useful if you were running the Wolfram Language in a batch mode directly from a command line.

Manual launching of Lightweight Grid kernels.

The Lightweight Grid connection method supports launching kernels directly from (RefLink[LaunchKernels, paclet:ref/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, which is shown below.

Needs["LightweightGridClient`"]

Now you use arguments in LightweightGrid when you launch a kernel. An example is shown below.

LaunchKernels[LightweightGrid["octet"]]

Once you have launched the parallel kernels, then all the parallel functions of the Wolfram Language 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 Wolfram Language. It integrates with a large number of third party cluster management technologies.

Configuration of the Cluster Integration connection method is done through 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 two kernels.

The Wolfram Language supports the following cluster management technologies:

More information can be found in the Cluster Integration documentation.

Manual Launching

If you want to launch kernels manually and avoid the configuration mechanism, you can pass arguments directly to (RefLink[LaunchKernels, paclet:ref/LaunchKernels]). This might be useful if you were running the Wolfram Language in a batch mode directly from a command line.

Manual launching of Cluster Integration kernels.

The Cluster Integration connection method supports launching kernels directly from (RefLink[LaunchKernels, paclet:ref/LaunchKernels]). To do so, you must first load the ClusterIntegration` package, which is shown below.

Needs["ClusterIntegration`"]

To launch on a particular cluster, you have to pass the name for that cluster into (RefLink[LaunchKernels, paclet:ref/LaunchKernels]). For example, to use Windows Compute Cluster Server, you would use CCS. An example is shown below that launches two kernels.

LaunchKernels[CCS["winccs"],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 the Wolfram Language 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 Wolfram Language. 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 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.

Launch command parameters.

The default value for the user name is to use (RefLink[$Username, paclet:ref/$Username]), the user running the local copy of the Wolfram Language.

Manual Launching

If you want to launch kernels manually and avoid the configuration mechanism, you can pass arguments directly to (RefLink[LaunchKernels, paclet:ref/LaunchKernels]). This might be useful if you were running the Wolfram Language in a batch mode directly from a command line.

Manual launching of remote kernels.

The remote kernels connection method supports launching remote kernels directly from (RefLink[LaunchKernels, paclet:ref/LaunchKernels]). To do so you must first load the RemoteKernels` package, which is shown below.

Needs["SubKernels`RemoteKernels`"]

To launch, you pass arguments in RemoteMachine. The following launches one remote kernel on machine remote1.wolfram.com.

LaunchKernels[RemoteMachine["remote1.wolfram.com"]]

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.

??$RemoteCommand

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 default to (RefLink[$Username, paclet:ref/$Username]).

??$RemoteUsername

You can pass the command directly into RemoteMachine. The following would be suitable for a non-standard installation of the Wolfram System.

LaunchKernels[RemoteMachine["remote1.wolfram.com","rsh `1` -n -l `3` \"D:\\Mathematica\math -mathlink -linkmode Connect `4` -linkname `2` -subkernel -noinit >& /dev/null &", 4]]

KernelObject[2, "remote1.wolfram.com"]

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 the Wolfram Language can be used.

Raw WSTP Connections

It is also possible to launch parallel kernels with raw WSTP 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 the Wolfram Language is launched giving both -subkernel and -mathlink as command line options. Finally, this link is passed to (RefLink[LaunchKernels, paclet:ref/LaunchKernels]), making the remote kernel a worker kernel.

Needs[ "SubKernels`LinkKernels`"]

kernel = "/Applications/Mathematica.app/Contents/MacOS/MathKernel";
link = LinkLaunch[kernel <> " -subkernel -mathlink"]

LaunchKernels[link]