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]}}