PARALLEL PACKAGE TUTORIAL

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 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 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.

In[1]:=
Click for copyable input
Out[1]=

If you use LaunchKernels with no arguments, this will launch the kernels that have been configured. Here, the two kernels are launched.

In[2]:=
Click for copyable input
Out[2]=

Note that you do not need to use LaunchKernels—if instead 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.

In[3]:=
Click for copyable input
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 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.

1.gif

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 wish to change its value, you can unprotect it and assign a new value. Here, its value is 2.

In[1]:=
Click for copyable input
Out[1]=

The number of parallel kernel licenses is given by , which is controlled by the Mathematica license. Here the value is 4.

In[2]:=
Click for copyable input
Out[2]=

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 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 specifying the string . In addition, you can give more detailed settings inside of . To do so, you must first load the package, which is shown below.

In[1]:=
Click for copyable input

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

In[2]:=
Click for copyable input
Out[2]=

It might be more useful to change the command used to launch remote kernels. The default command is set by , which has a typical setting as follows.

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

In[3]:=
Click for copyable input
Out[3]=

An alternative would be to modify the value of 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 Parallel Preferences. The configuration panel should look similar to the following.

12.gif

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 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 . To do so you must first load the package, which is shown below.

In[1]:=
Click for copyable input

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

In[2]:=
Click for copyable input
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 Parallel Preferences. The configuration panel should look similar to the following.

16.gif

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.

Mathematica supports the following cluster management technologies:

  • Windows Computer Cluster Server
  • Windows HPC Server 2008
  • 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 Cluster Integration kernels.

The Cluster Integration connection method supports launching kernels directly from LaunchKernels. To do so, you must first load the package, which is shown below.

In[1]:=
Click for copyable input

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 . An example is shown below that launches two kernels.

In[2]:=
Click for copyable input
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 Parallel Preferences. The configuration panel should look similar to the following.

19.gif

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 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 package, which is shown below.

In[1]:=
Click for copyable input

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

In[2]:=
Click for copyable input
Out[2]=

It might be more useful to change the command used to launch remote kernels. The default command is set by , 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 , which is set by default to $UserName.

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

In[5]:=
Click for copyable input
Out[5]=
Click for copyable input

An alternative would be to modify the value of 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 and as command line options. Finally, this link is passed to LaunchKernels, making the remote kernel a worker kernel.

In[1]:=
Click for copyable input
In[2]:=
Click for copyable input
Out[3]=
In[4]:=
Click for copyable input
Out[4]=
New to Mathematica? Find your learning path »
Have a question? Ask support »