19
$\begingroup$

I perform long calculations on a fast remote machine running the Mathematica kernel, where I followed the very useful guide Remote Kernel Strategies to establish the connection. I wonder, however, if there is a way to detach the Frontend from the running kernel in the same way as one can use the Linux program screen to keep remote shell sessions alive. I couldn't find anything similar for Mathematica, even though such a feature would be very convenient. Is there a way of doing that?

Many thanks,

Andreas.

$\endgroup$
  • $\begingroup$ Unfortunately the front end isn’t supporting this in v12 - it may work but many dynamics and other things will most assuredly break, pinking and freezing galore! $\endgroup$ – M.R. Jun 11 at 4:37
  • $\begingroup$ If you have the option of running remote desktop sessions on the remote machine that would allow you to running the front-end on the remote machine as well, then that would usually preferable. In this case the remote session manager will deal with the process of reconnecting. $\endgroup$ – mmeent Jun 13 at 9:11
13
$\begingroup$

This comes a little late, but this is my solution:

Remote Machine running linux with tmux (similar to screen but newer, should work with screen but I dont know the commands) and Mathematica 10 installed.

Local Machine running MacOS Yosemite with Mathematica 10.

  1. Launch tmux in remote machine and execute Mathematica:

    tmux

    wolfram (executable to mathematica in terminal mode)

  2. Now create a link with TCPIP protocol. Record the linkname="linkPort1@remoteIP,linkPort2@remoteIP" generated.

    link=LinkCreate[LinkProtocol -> "TCPIP"]                                
    LinkObject[linkPort1@remoteIP,linkPort2@remoteIP, 72, 1]
    
  3. Now in local machine, start Mathematica and go to Evaluation->Kernel Configuration Options -> Add... and fill out the window just as showed below.Dont forget to replace (insert remote ip ) by the remote machine ip address and insertLinkName by the link name that was generated above enter image description here clic ok. Then open a new notebook and set the above created kernel as the notebooks kernel. Dont evaluate anything yet in this notebook.

  4. Go back to your remote machine and run

    $ParentLink=link
    
  5. Finally go back to the notebook in your local machine and evaluate something:

    $Version 
    

So now you are running the kernel in the remote machine with the front end in your local machine.

  1. To disconnect from the Kernel, evaluate the following in your notebook:

    LinkClose /@ Links[]
    

At this point your kernel is still running in the remote machine. To reattach follow steps 2 through 5.

This could be automatized with a script. Also if you know that a port is always available, you could set the link with a persisten name so that you dont have to reconfigure the remote kernel each time you attach.

$\endgroup$
  • 1
    $\begingroup$ Thanks! I just tried what you suggested, using screen on the remote host. It seems to work! Thanks again for stating the solution to this problem in such a clear way! Andreas. $\endgroup$ – andy269 Jun 5 '15 at 19:46
  • $\begingroup$ Sadly this wonderful trick appears to crash Mathematica 12... $\endgroup$ – Ranza Apr 29 at 17:52
  • $\begingroup$ @Ranza Which operating system does it crash on? $\endgroup$ – Szabolcs Jun 7 at 8:01
  • $\begingroup$ MacOS Mojave connecting to Linux Remote $\endgroup$ – Ranza Jun 7 at 9:23
  • $\begingroup$ @Ranza you should email support@wolfram.com with the crash information, so they can investigate and hopefully fix the issue (if you are so inclined) $\endgroup$ – user6014 Jun 7 at 15:42
2
$\begingroup$

I have not done this before, but here's how I would approach this:

run the kernel on the remote machine from the command line using the 'background process' approach (i.e. '&' or "start")...

then run a script that will dump out the Mathlink connection id (or equivalent)...pass this to the front-end you want to be the client and start/restart the Mathlink connection...

$\endgroup$
  • $\begingroup$ Hm, okay, thank you, I might try that. I will report on the outcome later. Andreas. $\endgroup$ – andy269 Mar 23 '15 at 19:44

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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