I followed the instructions in this howto from wolfram, but I keep getting the error:

The kernel New Kernel failed to connect to the front end. (Error = MLECONNECT). You should try running the kernel connection outside front end.

I have both Pi's on my LAN, and am sure the ip addresses are correct and visible (I am remote controlling them from my PC with a VNC remote desktop program and can login to the remote Pi via ssh from my local Pi.). I tried fiddling with the advanced options (e.g. replacing the default 'wolframssh' with 'mathssh' and the -wstp option with -mathlink), but this didn't help.

The local Pi is a Raspberry Pi 2, the remote one is an older Raspberry Pi.

I also found this old post suggesting I write out the ip address in the -LinkHost ipaddres. That didn't solve the issue either. (I am also confused about the posts and documentation writing the ipaddress sometimes with one, sometimes with two 's'. Also, is the -LinkHost the frontend machine, or the kernel machine? If a frontend hosts a kernel or a kernel hosts a frontend seems up for semantic discussion.) Neither writing out the local Pi ip address or the remote Pi ip address in -LinkHost ipaddres solved the problem.

Any suggestions would be greatly appreciated!

  • That you're worried about the spelling of "ipaddress" suggests to me that you are actually using that word literally instead of replacing it with its numerical value. Is that true? – Sjoerd C. de Vries Mar 4 '15 at 23:30
  • @SjoerdC.deVries Perhaps, but the RPi version of Mathematica does not come with WolframSSH.jar in the SystemFiles/Java/ path as does the Windows version. I'm not sure where this file would be located in a Linux flavor or if there is something missing from the RPi edition. – bobthechemist Mar 4 '15 at 23:50
  • @Sjoerd C. de Vries No, I replaced it with the actual numerical value. However, the default configuration has -Linkhost ipaddress (literally, with two 's'). – yippy_yay Mar 5 '15 at 7:54

Because there seems to be no quality resource or documentation on this subject, I will attempt to provide as close of a hand-holding solution as possible. I think this is feasible in the present case since we are restricting ourselves to one version of Mathematica on one platform (the RPi).

My setup

I have two RPis on my internal network. The local RPi is a version 2 board (4 cores) with the name of coruscant and the remote RPi is a model B with the name lcdlab. Both computers are running the latest version of Mathematica for the RPi (as if this writing $Version is February 3, 2015 and uname -a is 3.18.7-v7+ for coruscant and 3.18.7+ for lcdlab.). No firewall exists between the two RPis and each can ping one another. I do not have a VPN interfering with communication between the RPis. Additionally, I have followed these directions for setting up the avahi daemon on each RPi, so that I can refer to them by hostname rather than IP address. I have enabled ssh on each RPi through raspi-config. I am using the pi user account on both computers.

I have tried to use to indicate the remote computer (in my case, lcdlab) and (in my case, coruscant) to indicate the two RPis wherever possible. Replace with the appropriate hostname/ipaddress for your configuration.

Step 1 - Create passwordless ssh access

The remote (lcdlab in my case) RPi will need to be accessed via ssh without requiring the end user to enter a password. To do that, I used these directions. In summary, on the local machine (coruscant):

ssh-keygen
ssh-copy-id pi@<remote>

Try to log on to the remote RPi with ssh pi@<remote>. You need to be able to complete this step before moving on to the next one.

Step 2 - Establish a remote kernel connection

I am using the suggestions from this answer. I have reproduced the relevant steps below:

mathl[link_] := "wolfram -mathlink -linkmode Connect -linkprotocol TCPIP -linkname "
    <> link <> " -subkernel -noinit &< /dev/null &";
machine = "<remote>";
link = LinkCreate[LinkProtocol -> "TCPIP"];
linkname = First@link;
cmd = "ssh " <> $UserName <> "@" <> machine <> " \"" <> mathl[linkname] <> "\"";

Important Note: When working on this solution, I would run in to problems with executing the commands below in the FrontEnd (aka using mathematica instead of wolfram). The X gui would become unresponsive and the only way I could resolve the problem was to reboot the RPi either through a separate ssh connection or by pulling the plug. I was able to work around these problems by placing the above commands in a file called linkinit.wl and then calling from a terminal wolfram -initfile linkinit.wl. Then, if I had a typo or some other problem, I would not end up with a dead X session. Once I was sure that there were no typos in the symbols above, I was able to get the operations to perform properly in a Mathematica notebook.

Now, to create the remote kernel connection, in a wolfram (or mathematica, once you've debugged) session:

process = StartProcess[$SystemShell];
WriteLine[process,cmd];
LinkWrite[link,Unevaluated@{$MachineName,Now[]}];
LinkRead@link

You will need to evaluate LinkRead@link several more times in order to see the ResultPacket containing the desired output. Once you have observed this information do not attempt to read from the link again or you risk hanging the wolfram/mathematica session. We can now clean up with:

LinkClose@link;
KillProcess@process;

...and move on to the next step. Again, if you have not been able to complete this step, you should not move on to the next one.

Step 3 - Creating a usable remote kernel connection

At this point, we know that a remote connection can be established, and now we need to create one that can easily perform computations. Open the preferences dialog using FrontEndTokenExecute["PreferencesDialog"]. Under the Parallel tab, select the remote tab and enter the following custom launch command

ssh -x -f -l `3` `1` wolfram -mathlink -linkmode Connect `4` -linkname '`2`' 
  -subkernel -noinit 

The screen should look something like this

enter image description here

We can now test the kernel with the following from a Mathematica notebook.

CloseKernels[] (* Make sure multiple kernels not available *)
ParallelTable[Prime[i], {i, 1, 5}] (* Should generate an error *)
Launch["<remote>"]
ParallelTable[Prime[i], {i, 1, 5}] (* Should make you happy *)

Step 4 - Remote kernel for Notebook evaluations

There's a subtle difference between establishing a kernel for remote parallel computations and creating the connection so that a notebook is using the remote kernel for computations. This step describes the latter configuration, which may or may not be needed.

Select "Kernel Configuration Options..." under the Evaluation pulldown menu item in a Mathematica notebook and add a new kernel. First, use the basic options and set the kernel name, the Remote machine radio button machine name and kernel program. Note that a full path is used for the kernel, and this is important.

enter image description here

Next, switch from the basic options to Advanced options and modify the shell command as I have done in the image below

enter image description here

The important changes here are the switch from WolframSSH.jar (which doesn't exist on the RPi) to ssh, the full path name to the wolfram command (which should have already been set if you followed the instructions above), the change from -wstp to -mathlink (which may not have a real effect; I haven't tested it) and the explicit calling of in the -LinkHost argument.

If all has gone well, then running the following command in a local Mathematica notebook:

CreateDocument[Null,Evaluator->"<remote>"]

will result in a new Notebook that will use the remote kernel to perform computations.

Epilog

The biggest problem I had with developing this solution was typographical errors. In particular, I kept missing "'" and spaces. I can't stress enough that setting up remote kernels is very unforgiving of typos, and I hope that I have not introduced any into this answer.

  • Very detailed and explicit! I can't get beyond step 2, though. I copied the linkinit.wl script and it does not crash the Mathematica front-end, however the system remains in limbo, accepting but not computing further input after LinkWrite[link,Unevaluated@{$MachineName,Now[]}]; – yippy_yay Mar 10 '15 at 11:41
  • @SebastianHenckel I have very little experience with low-level link communication commands such as LinkWrite and LinkRead; my experience suggests they are very unforgiving. In the example above, I evaluate the process = ... cell once and the LinkRead@link cell 4 times, with the last returning the output of Unevaulated@{$Machine.... Are you saying that you are not able to get any output from LinkRead@link? – bobthechemist Mar 10 '15 at 13:36
  • If I just want a notebook on one pi to use a remote kernal on another pi, can I use steps 1 and 4? – Young Aug 7 '16 at 22:35
  • @bobthechemist no matter what I try I can't get this to work. I'm stuck on LinkWrite[link,Unevaluated@{$MachineName,Now[]}]; it just evaluates forever and never returns an error or proceeds ... I've tried skipping to step 4 and using every combination and I get the same error as the OP – Young Aug 8 '16 at 4:31
  • @young Not sure what the problem might be. Perhaps ask a question on the site so you can provide a complete list of the steps you are taking and the configuration you are using? – bobthechemist Aug 8 '16 at 11:27

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

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