Configure Remote Mathematica Kernel


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@, PORT2@" -LinkHost "" -LinkOptions MLDontInteract
  • Set Shell command to launce kernel: as LD_LIBRARY_PATH=/usr/lib ssh -R PORT1: -R PORT2: username@remote-host "/Applications/ -mathlink -LinkMode Connect -LinkProtocol TCPIP -LinkName PORT1@,PORT2@ -LinkHost"
  • 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 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)}