Local Mathematica with Remote Kernel

Mathematica supports running the computation kernel on a different host than the Mathematica frontend itself. This functionality allows us to use the processing speed and memory (64 GB) of a VSC-3 cluster node for Mathematica computations while still having a local frontend.

The following instructions only work on Linux and macOS, we are trying to find a way to do the same on Windows. Also, you need to use the SSH key-based login to the VSC-3, see the Access to VSC Wiki entry for information on how to set this up.

The instructions are split into the steps that are only needed once and the steps that need to be done each time the remote kernel should be used.

Steps Needed to be Done Only Once

  1. Download the tunnel.sh script and make it executable (on the command line type "chmod +x tunnel.sh"). Remember the location where you saved the script.

    This script contains the logic needed to connect to a remote SSH server and correctly start the Mathematica kernel there.

  2. Start Mathematica and add a new remote kernel.

    • Go to "Evaluation -> Kernel Configuration Options" and click "Add".

    • Type in a descriptive name (e.g. "VSC-3 Remote Kernel") and select "Advanced Options".
    • In "Arguments to MLOpen" type in the following on one line:

      -LinkMode Listen -LinkProtocol TCPIP -LinkHost 127.0.0.1 -LinkOptions MLDontInteract
    • In "Shell command to launch kernel" type in the following on one line:

      "/path/to/tunnel.sh" VSCUSERNAME@localhost:9998 /opt/sw/x86_64/generic/Mathematica/10.0.2/bin/math "`linkname`"

      Make sure you specify the correct path where you saved the script and the correct VSC-3 username, not your local username. The path to the Mathematica kernel may change in the future when the VSC-3 adds a new Mathematica release.

    • Check the "Raw MathLink connection" box.

    • Click on "OK" to close the dialog and then "OK" another time to get back to the main Mathematica interface.

    After these steps you have a new kernel configuration defined that starts a kernel not locally on your host but on the VSC-3.

  3. Update your SSH configuration file ~/.ssh/config to make connecting to the VSC-3 cluster using SSH keys easier. Put the following lines into it, using your VSC-3 username

    Host vsc3.vsc.ac.at
    Port 27
    User VSCUSERNAME

    Now you can connect to the VSC-3 cluster by just entering ssh vsc3.vsc.ac.at.

Connect to the Remote Kernel

The following steps are needed to connect to the remote kernel:

  1. Open a terminal on your computer and copy-paster (or enter) the following commands:

    ssh vsc3.vsc.ac.at
    salloc -N 1 -L mathematica@vsc
    srun hostname

    The command creates a new SSH connection to the VSC-3 login node vsc3.vsc.ac.at. Inside this connection a cluster node is allocated which is reserved as long as the shell is not closed. Additionally, the name of the reserved cluster node is output for use in the next step.

    Note the name of the cluster node, it has the form "nXX-YYY".

  2. Open another terminal on your computer and execute the following command:

    ssh -L 9998:nXX-YYY:22 -N vsc3.vsc.ac.at

    Substitute "nXX-YYY" with the cluster node hostname from the last step. This command creates another connection to the VSC-3 login node and a tunnel that connects the local port 9998 with the SSH port on the reserved cluster node.

  3. Start Mathematica and under "Evaluation -> Notebook's Kernel" select the remote kernel that you added.

When you enter something in the frontend, the remote kernel on the VSC-3 cluster node is automatically started and the computation performed. If you enter "SystemInformation[]" the output will show you that the kernel is indeed running on the cluster node.

After you are finished, make sure that you release the job allocation for the cluster node by exiting the shell that was started in step 1.