Saturday, April 27, 2013

Remote kernel for Mathematica via home router

Let's say you are sitting at home, surfing internet via your wireless router, and suddenly feel the unexplained urge to run some Mathematica computations. You can not do that using your laptop: the urge is too powerful, it requires 16 parallel kernels. But you can do that using your workstation which is sitting at your office 10 miles away (it's raining outside).  “Remote kernel is a solutions”, you think.


So you open “Kernel Configuration Options” in your local copy of Mathematica and add a remote kernel with just basic options:

Machine Name: my.office.work.edu
Remote Login: killbull
Kernel Program: math

You type “2+2” in the Front End, enter ssh password and get, instead of “4”, the frustrating error message: 

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

Being a smart person you immediately realize the following:
  1. Remote kernel can’t talk to your local Front End since you have firewall running. You add exception for the remote workstation’s IP address right away.
  2. Since you use the router your IP is 192.168.1.10 and is not visible from the ourside world. You have to make a VPN connection to your office network to allow the remote kernel to talk to your local Front End. It’s done in no time.  
In order to figure out the host name assigned to your laptop you run in terminal:


$ math -mathlink -linkcreate -linkprotocol TCPIP
Link created on: 33234@129-3-222-111.vpn.uh.edu,23253@129-3-222-111.vpn.work.edu

So remote Mathematica’s kernel will happily communicate with 129-3-222-111.vpn.work.edu. Obviously, you can google "what is my IP" and it instead.

Now you return to Mathematica’s “Kernel Configuration Options” and edit your remote kernel's properties. You click  “Advanced Options” and instead of Mathematica’s default

`java` -jar `mathssh` killbull@my.office.work.edu math -mathlink -LinkMode Connect -LinkProtocol TCPIP -LinkName "`linkname`" -LinkHost `ipaddress`

you enter

ssh  killbull@my.office.work.edu /home/killbull/install/bin/MathKernel -mathlink -LinkMode Connect -LinkProtocol TCPIP -LinkName "`linkname`" -LinkHost `129-3-222-111.vpn.work.edu`

Here

- “ssh” is instead of “`java` -jar `mathssh`“ so that Mathematica will use regular OpenSSH to communicate. This will allow you to make use of your huge .ssh/config file.
- “/home/killbull/install/bin/MathKernel” instead of just “math” since your Mathematica binaries on the remove machine are not in the PATH.
- “129-3-222-111.vpn.work.edu” instead of “ipaddress” so that remote Kernel will know where to find you local Front End.

Now everything work’s, and you can start to satisfy your urge immediately.

3 comments:

  1. Hi, I Could't fix the conection since the vpn server is different from the kernel server. Is there other option to achieve this? Thx

    ReplyDelete
    Replies
    1. Dear Francisco, you need VPN only to get an IP address visible from outside your router. So that your server, where Mathematica kernel is running, can talk back to your computer at home. There is no need for VPN and the kernel to be on the same server. You may choose not to use VPN at all and configure your router instead (make it forward packets to your home computer). I just think that VPN is simpler. As for you question, can you provide more details on error you are getting?

      Delete
  2. This working. Thanks very much...

    ReplyDelete