Configure Remote Mathematica Kernel

2016年06月04日

I got a Respberry pi which have free Wolfram Mathematica but the CPU is not fast enough. So I configured it to use a remote Mathematica kernel over SSH.

Open Evaluation->Kernel Configuration Options to add a new kernel:

  • Set Kernel Name as you want
  • Choose Remote Machine type
  • Choose Advanced Options
  • Set Arguments tp MLOpen: as -LinkMode Listen -LinkProtocol TCPIP -LinkName "PORT1@127.0.0.1, PORT2@127.0.0.1" -LinkHost "127.0.0.1" -LinkOptions MLDontInteract
  • Set Shell command to launce kernel: as LD_LIBRARY_PATH=/usr/lib ssh -R PORT1:127.0.0.1:PORT1 -R PORT2:127.0.0.1:PORT2 username@remote-host "/Applications/Mathematica.app/Contents/MacOS/MathKernel -mathlink -LinkMode Connect -LinkProtocol TCPIP -LinkName PORT1@127.0.0.1,PORT2@127.0.0.1 -LinkHost 127.0.0.1"
  • Choose the kernel just been set and run any command in notebook (e.g. $Version) to check whether the remote kernel is working or not.

To be noticed, we use LinkName here to fix the port used and then use SSH with port forwarding to connect.

We need set LD_LIBRARY_PATH to exclude Mathematica library path first to avoid SSH complain libcrypto.so.1.0.0: no version information available (required by ssh).

Tips for mathematica:

xp = Table[x^n, {n, 1, 5}]
xp /. x^2 -> y

xp /. {x^n_?EvenQ -> y^(n/2)}
xp /. {x^n_ /; OddQ[n] -> y^(n/2)}
xp /. {x^n_ /; (Mod[#, 5] == 0 &)[n] -> y^(n/2)}