As applied mathematicians, we often must run long numerical simulations.
However, we don't always want to stay at our desk babysitting the code in case it fails.
The solution is GNU screen.
Suppose we have two machines: laptop and caampc.
Our goal is to start a simulation in Matlab on caampc and then access it from laptop at home, eating dinner.
First, in the office, open a new terminal, and run screen.
caampc $ screen
After running this command, the terminal appears to have restarted -- the screen has been cleared,
and the command screen
no longer appears;
is now running.
It has spawned a new terminal inside your old terminal that is persistent.
If you close the terminal window, screen
will still be running.
More significantly, this terminal can be accessed again.
Now that we're in screen
lets fire up Matlab and run some code.
GUI displays are not preserved by screen
, so we need to run Matlab from the command line.
caampc $ matlab -nodesktop -nosplash
Once in Matlab, run the desired code.
Optionally, before you leave, detach the session, dropping back to your original terminal by pressing
control-a and then control-d.
The command control-a prefixes every screen
command; control-d stands for detach.
Now, it's time to go home and enjoy a tasty dinner.
On the computer you have with you, laptop, SSH into caampc.
laptop $ ssh caampc.caam.rice.edu
Once logged into caampc
, start up screen again.
This time, we need to tell screen
to join the already running version.
We do so by running
caampc $ screen -r
If you get an error like
There is a screen on:
There is no screen to be resumed.
you did not detach your already running session.
To solve this, simply tell screen to force the detachment and move the terminal session to your current terminal
caampc $ screen -rd
If everything is successful, you should be returned to the running session of Matlab.
Any progress should be visible in the screen session.
To quit screen
, exit Matlab, and then kill the terminal session
caampc $ exit
For more information on screen,
see the manual
or a tutorial.