# Can you explain how the remote kernel work

I have use remote kernel almost every day, but I guess I never understand how it works. I have basically two questions:

1. How do we manually setup and use one kernel as a remote kernel to the other?

Suppose we have a two machines and for each machine I have a terminal opened.

Machine 1:

[user@001 ~]$ Machine 2: [user@002 ~]$


Now I launch a math kernel on each machine

Machine 1:

[user@001 ~]$math In[1]:=  Machine 2: [user@002 ~]$math
In[1]:=


Is it possible to use the kernel on machine 2 as a remote kernel for machine 1, without close the kernel and restart again? Assuming the communication between the two machines are good, and the ip address for the two machines are 1.1.1.1 and 1.1.1.2. From the documentation I know that one kernel will create mathlink and be listening, and the other kernel will try to connect to the created link. But how does this work in detail, for instance, could you show me the steps to connect the two in the above example?

1. In the documentation here, it shows the steps to mannully connect to the remote kernel. Could you example how does that work? I can use the remote kernel by following the steps there, but I don't quiet understand how it works.

For example, what does the "Arguments for MLOpen" used for? For instance, my default value is

-LinkMode Launch -LinkProtocol SharedMemory -LinkName "'/Applications/Mathematica.app/Contents/MacOS/MathKernel' -mathlink" -LinkOptions 3


Could you explain what each option and the argument mean? And sometimes I see option like "LinkHost" which seems to not well documented. What does LinkHost mean, does it mean the host the local kernel is at or the host of the remote kernel?

There is a very useful paper by David Wagner (point to me by halirutan) that explains all the details of how this work.

A simple example illustrates the process:

start a link on local computer, this will make the kernel listen on some ports

localIn[1]:= linktoremote = LinkCreate[LinkProtocol->"TCPIP"]
localOut[1]= LinkObject[53280@204.90.46.117,36536@204.90.46.117, 59, 1]


on remote computer, connect to this port on the local computer

remoteIn[1]:= linktolocal = LinkConnect["53280@204.90.46.117,36536@204.90.46.117",LinkProtocol->"TCPIP"]
remoteOut[1]= LinkObject[53280@204.90.46.117,36536@204.90.46.117, 59, 1]


Then the link will establish, and we can read and write to the link on both sides

write to the link on the remote computer

remoteIn[2]:= LinkWrite[linktolocal,"Hello from remote"]


read the link on the local computer

localIn[2]:= LinkRead[linktoremote]
localOut[2]= Hello from remote


write to the link on the local computer

localIn[3]:= LinkWrite[linktoremote,"Hello from local"]


read the link on the remote computer

remoteIn[3]:= LinkRead[linktolocal]
remoteOut[3]= Hello from local

• This doesn't work for me. – M.R. Jul 26 '16 at 0:17
• @M.R. What version are you using? It works for me on version 10.1. I'm not sure whether they have changed something recently. – xslittlegrass Jul 26 '16 at 3:05
• I have 10.4.1, my remote is in EC2, never ever gotten a remote kernel to work there. – M.R. Jul 26 '16 at 3:53
• I've never had experience with EC2. But maybe you could try the tunnel package. – xslittlegrass Jul 26 '16 at 14:12