4
$\begingroup$

I'd like to set up a cluster of WL nodes without using the notebook user interface. Everything I've seen about how to set up a WL remote kernel talks about how to configure the remote kernel by going to the Evaluation ► Parallel Kernel Configuration menu item. But I'd like to do this using only the CLI.

For example, say I have a few Raspberry Pi's with Wolfram Engine installed and a server with the free Wolfram Engine. I'd like to use the server as the master node to run wolframscripts and the Raspberry Pi's as remote kernels. But all of them are headless and so I can't use the Mathematica UI to set anything up. I have SSH access to everything and can set up SSH key authentication if required.

How do I go about setting up the server master node to use the Raspberry Pi's as remote kernels using only the CLI.

$\endgroup$

1 Answer 1

5
$\begingroup$

I was able to get this working and it was simpler than I thought. The Parallel Computing Tools documentation was very helpful (specifically here for manual launching of the remote kernels).

Note: I did this using Ubuntu as the master and a few Raspberry Pi's for the remote nodes.

First you need to make sure you have passwordless SSH key authentication between the master node and the remote nodes.

Using the LaunchKernels[] function worked fine using the default SSH connection parameters. The following Wolframscript shows the remote kernels working.

#!/usr/bin/env wolframscript

remotes = {
  "192.168.1.150",
  "192.168.1.151",
  "192.168.1.152",
  "192.168.1.153"
};

Needs["SubKernels`RemoteKernels`"];

LaunchKernels[RemoteMachine[#]] & /@ remotes;

(* Print the remote machine names *)
remoteMachineNames = ParallelEvaluate[$MachineName];
Print@remoteMachineNames;

(* Print the non-parallelized timing for comparison *)
localTime = Map[(Pause[1]; f[#]) &, {a, b, c, d}] // AbsoluteTiming;
Print[localTime];

(* Print the parallelized timing*)
remoteTime = ParallelMap[(Pause[1]; f[#]) &, {a, b, c, d}] // AbsoluteTiming;
Print[remoteTime];

Update: After this was posted it was pointed out that the remote machines are multicore and so it would be nice to use these cores as remote kernels. After some searching it was found that RemoteMachine[] can take a second argument indicating the number or kernels to instantiate on the remote machine.

LaunchKernels[RemoteMachine[#, 4 (* the RPi is quad core*)]] & /@ remotes;

Here is a slight modification to the calculation above to use 16 subkernels.

Print["local"];
localTime = Map[(Pause[1]; f[#]) &, Range[16]] // AbsoluteTiming;
Print[localTime];

Print["remote"];
remoteTime = ParallelMap[(Pause[1]; f[#]) &, Range[16]] // AbsoluteTiming;
Print[remoteTime];

The output:

local
{16.011285, {f[1], f[2], f[3], f[4], f[5], f[6], f[7], f[8], f[9], f[10], f[11], f[12], f[13], f[14], f[15], f[16]}}
remote
{1.060237, {f[1], f[2], f[3], f[4], f[5], f[6], f[7], f[8], f[9], f[10], f[11], f[12], f[13], f[14], f[15], f[16]}}
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.