Configuring and Managing
Wolfram Language Kernels

Roman E. Maeder, Wolfram Research

(RowDefault[, (Spacer1), , (Spacer1), ])  #WolframTechConf

ABSTRACT

From within a Wolfram Language session it is possible to connect to other Wolfram Language engines (kernels) both locally, and on remote computers, using a variety of connection methods.

Such kernels can be used for ad-hoc evaluations, as session kernels of a notebook, or bundled for parallel computation.

Support for discovering, configuring, and managing kernel resources has been modernized over the last three language versions, and is now available in a single coherent way across a wide variety of environments from ad-hoc collections of workstations to managed clusters, supercomputers, and cloud compute services.

We give an overview over the kernel connection methods and their intended use cases.

Connection methods discussed include local kernels, remote-access (ssh), WSTPServer, and LightweightGrid.

20221019

Outline of Presentation

Overview

Obstacles for Remote Connections

Modern Remote Access Solutions

Kernel Configuration

Wolfram Language Engines for Remote Computation

Here are some quick examples for the various access methods.

Local Kernels

Of course, you can still launch local kernels as always:

LaunchKernels[8]

CloseKernels[];

Directly specify a binary to launch:

LocalEvaluate["file:///usr/local/bin/wolfram132",$Version]

SSH Access

Run a single evaluation on a kernel on a remote machine

RemoteEvaluate["ssh://vega",{$MachineName,$Version}]

Launch several parallel subkernels on a remote machine

LaunchKernels["ssh://andromeda?64"];
$KernelCount

ParallelEvaluate[$ProcessID]

CloseKernels[];

WSTPServer

Launch 4 kernels on a running WSTPServer

LaunchKernels["wstp://raspi8?4"]

Note the “?4”, technically an URL query argument.

ParallelEvaluate[$Version]

CloseKernels[];

Lightweight Grid

Launch kernels on known instances of Lightweight Grid:

LaunchKernels["lwg://test3macmini.wolfram.com?4"]

CloseKernels[];

Service Discovery

Discover running LightweightGrid Managers and services:

Needs["LightweightGridClient`"]

agents=RemoteServicesAgents["test3macmini.wolfram.com"]

allservices=Flatten[RemoteServiceInformation/@agents]

Tabulate their properties:

agentProperties={"Agent","Name","VersionNumber","KernelNumber","KernelsAvailable"};
TableForm[MapThread[#,{agentProperties}]&/@allservices,TableHeadings->{Range[Length[allservices]], agentProperties}]

Choose one and set desired number of kernels:

kc=KernelConfiguration[allservices[[4]],"KernelCount"->2]

Launch them:

LaunchKernels[kc]

ParallelEvaluate[$Version]

CloseKernels[];

Modernizations in Versions 13.1 and 13.2

After more than 20 years, it was time for an overhaul of the kernel launching code in Parallel Tools.

Changed network architectures require new ways to make and receive connections (Firewalls, NAT)

Some legacy kernel launchers have reached their EOL (Lightweight Grid)

So we are introducing

A new unified and extensible way to configure kernels

Support for modern security features of remote access (SSH)

A new server for Wolfram engines (WSTPServer)

A new system for remembering persistent preferences

Still To Do

GUI for kernel configuration

Support for legacy cluster management systems

Deployment support for gridMathematica

Obstacles for Remote Connections

Or: navigating around the obstacles that security specialists invented to make life difficult for users.

NAT and Firewalls

I can see you, but you cannot see me

Outgoing connections are usually possible, but incoming ones are not, especially to random ports.

⟹ All connections must be in the same direction (out)

VPN and Multihome

For machines with multiple network interfaces (which will always be the case if you use VPN) you need to know on which interface incoming connections will terminate.

Password Prompts

Connections made programmatically cannot handle password prompts

When you make a lot of connections you don’t want to handle passwords prompts

⟹ Of course, you shouldn’t really use passwords anymore

OS Diversity

Thankfully, the world has converged towards linux for managed remote compute resources, but you still want to be able to use your ad-hoc collection of PCs and workstations for parallel computation.

Windows was the last to join the party, but now every OS offers a standard way for remote access (ssh client or server).

KernelConfiguration["remote.example.com","OperatingSystem"->"MacOSX"]

Modern Remote Access Solutions

The only tool you ever need for remote access, ssh, has learned quite a few tricks over the decades.

And there are new players in the VPN world.

SSH

Use Ssh keys or certificates instead of login passwords

The private part of an ssh key is usually protected at rest by a pass phrase, so you would still be prompted when using one, but

there are ssh agents that can cache the pass phrases

the agent can be tied to your login wallet/keyring and unlocked automatically

you can use connection sharing to avoid repeated prompts after the first one

Ssh can forward TCP connections from the remote end to your local machine, so everything travels through the secure tunnel established

When launching many parallel subkernels on a remote machine, only a single ssh connection is made, and all kernel links tunnel through the established ssh connection

Tailscale

Besides standard VPN for remote access to company resources or protection against insecure hotel networks, Tailscale also supports point-to-point connections (and it is free for a single user [with multiple machines]).

Here is a use case, working on a laptop anywhere in the world, and accessing a single machine inside my private network for parallel computation.

install tailscale on my windows machine which sits in my internal private network, inaccessible from the outside

install tailscale on my linux laptop, which I connected to the internet via my mobile phone, so it is an outside machine

start up WSTPServer on the windows machine

launch Mathematica on the laptop, and do

LaunchKernels["wstp://100.x.y.z?4"]

where 100.x.y.z is the tailscale IP of my windows machine

and there were my parallel kernels!

what I did not do

no messing with my firewall

no setup, no configuration, just log in to tailscale with my Google account

Engine Servers

Besides the legacy Lightweight Grid Server there is now a modern replacement, WSTPServer.

It can provide all kinds of kernels:

Single-use RemoteEvaluate kernels

Multiple parallel subkernels

Evaluators for the Frontend (notebook kernels)

Kernel Configuration

A new data type KernelConfiguration[] allows for full flexibility.
Short URL forms of configurations provide an easy way to specify to most often needed settings.

KernelConfiguration[]

The full form of kernel configuration.

The first argument can be an URL string, but short firms are recognized where they are unique, for example a domain name.

kc=KernelConfiguration["host.example.com"]

Kernel configurations have many properties.

kc[All]

Information[kc]

You can further configure kernels via option settings for any of the properties:

kc["Properties"]

KernelConfiguration["host.example.com","KernelCount"->4,"KernelCommand"->"/usr/local/bin/wolfram130"]

Or modify an existing configuration:

KernelConfiguration[kc,"KernelCount"->4,"KernelCommand"->"/usr/local/bin/wolfram130"]

but...

URLs for kernel configuration

Whenever possible, use the URL forms available:

KernelConfiguration["ssh://host.example.com//usr/local/bin/wolfram130?4"]

You can then leave out the KernelConfiguration wrapper:

LaunchKernels["ssh://host.example.com//usr/local/bin/wolfram130?4"]

$DefaultKernels

The kernels to use for parallel computation by default

$DefaultKernels={
8,
"ssh://vega?4",
"lwg://test3macmini.wolfram.com?2",
"wstp://raspi8?4"
}

LaunchKernels[]

ParallelEvaluate[$MachineName,"OneKernelPerMachine"]

CloseKernels[];

Persistent Settings

Remember the current vale of $DefaultKernels for all new sessions:

InitializationValue[$DefaultKernels]=$DefaultKernels

Now, if you quit and restart your session, the value will be restored.

To remove any persistent value:

Remove[InitializationValue[$DefaultKernels]]

InitializationValue[$DefaultKernels]

Next time, the value will revert to the default.

Using the URL forms, without the KernelConfiguration wrapper, will improve the startup time for new sessions.

Neat Example

Specify a remote machine:

server="ssh://andromeda";

Query it for its number of processors:

cores=RemoteEvaluate[server,$ProcessorCount]

Update the description with the discovered kernel count:

server=KernelConfiguration[server,"KernelCount"->cores]

Launch all of those parallel subkernels:

LaunchKernels[server];
$KernelCount

CloseKernels[];

Conclusions

The new framework for managing Wolfram Language Engines will replace legacy systems, such as Lightweight Grid, and the Kernel Configuration Options... setting for managing Notebook kernels.
It makes use of modern tools for remote access and computation.