Remote Mathematica Kernel on Unix from Windows
These instructions are specific for the CERN environment.
It is possible to run the Mathematica Front End
on
a Windows machine but run the kernel on Unix
via a MathLink connection. This allows you to run Unix commands (e.g.
the MAD program) inside a Mathematica function with the more comfortable
implementation of the Front End on Windows. Together with the AFS client for Windows, this is an
extremely useful
facility.
Beyond what you find in the Help/Getting Started/System-Specific
Information/Running a Kernel, there is useful information at a Wolfram FAQ
page and there is some
related information.
Current method (as of 1 March 2006)
Now that Mathematica 5.2 has SSH support for secure remote kernels, the
procedure has become relatively easy again in CERN. Open the Kernel/Kernel
Configuration Options ... Menu in the Front End and add a new kernel with
options similar to the following:
Since you must be using
Mathematica Version 5.2 on Windows, it is better to change the command used to
launch the kernel as shown (the default "math" on lxplus gives you Version 5.1,
although that will probably still work).
Open a notebook and set the
notebook's kernel to this new kernel (all as described in the Help ...).
For the first evaluation in the session, you will have to type your password for
your lxplus account. In fact the very first time you do it you will have
to accept some other things too. Here is an example:
As compared with the "Old Method"
below (which I now have trouble with), this does not allow you to launch other
Unix processes in local windows. So you will need to take care about
renewing your AFS token, etc.
Old method
However the last step, launching the kernel,
does not work on lxplus in CERN because of security policies. To get
around this, you must login to lxplus in a terminal window and launch it
there. Here is my recipe. Once you've done it once or
twice, it is pretty quick.
To save
typing, first create a tiny Unix script, called pcmath and keep in a directory on
your Unix path (~public/scripts/ in my case).
# Start mathematica kernel to be linked to
by Front End running on my PC
# Argument should be the MathLink port number.
# See http://cern.ch/jowett/ComputingNotes/MathematicaUnixKernelFromWindows.html
# Changed to Version 4, 28/10/1999
math -mathlink -linkmode connect -linkname
$1@pcslap02.cern.ch
If you copy this, you have to change the name of the PC "pcslap02"
to the name of your PC. Make the script executable with
chmod +x pcmath
In the Windows Front End, go to Kernel/Kernel Configuration Options
and define a new kernel like this (changing the Remote Login name of
course:
Actually the Advanced Options may not matter.
Then, whenever you want to start a session, the procedure is:
- Launch an X-server (Exceed in CERN) on your PC (this seems useless but is
necessary because of the way CERN has set up Mathematica on lxplus: it will
not start unless an X-display is available even though it will most likely
not be use.
- Launch a terminal window on lxplus and be ready to type a command.
- Open a notebook and select FEConnect as the notebook's kernal in Kernel/Notebook's
Kernel (you can do this cell-by-cell or even globally for all your
notebooks but this is probably the most practical thing). This will be
remembered as a property of the notebook until you change it.
- Evaluate an expression, e.g., by typing
2+2
in an input cell and then Shift-Enter. A MathLink prompt window will
appear, looking something like this:
Don't click OK yet but take note of the 4-digit port number (1796 in
this case).
- Go to the lxplus terminal window and type
pcmath 1796 &
(changing the value to the number you noted). Wait till you see
something like (occasionally this is a bit slow because of the lxplus file
system):
wait a few more seconds for good measure, and then go back to the MathLink
window (if it is hidden under other things, you can reveal it by clicking
the desktop button
(if you have it on your Task Bar) or WindowsKey-M) and now click the OK
button.
- You should then see the output from the evaluation of your expression and
you can carry on evaluating anything else you like.
Things worth knowing
To verify the machine you are running on, evaluate expressions like
{$MachineName,$MachineDomain,$OperatingSystem}
Unix system commands can then be evaluated in many ways and you can use
Mathematica to manipulate their output. E.g.,
Import["!ls -l","Lines"]
Run["xterm &"]
Be careful about launching processes in background and trying to get their
output, e.g. with
ReadList["!xterm &",String]
as this may leave the notebook in "Running ..." mode until the terminal
window is closed. I
Remember that the Front End is running on Windows so it will see the Windows
file system (which may include AFS if you use the AFS client). In
principle it need not: the notebook could be stored on your local hard disk for
example. The kernel sees the lxplus file system so any files it creates
will appear there. The kernel's current directory is seen with
Directory[]
and
can be changed with
SetDirectory[....]
When you write notebooks that use either local or remote kernels, it is good
practice to make them system-independent. Use lists and ToFileName for
filenames and Mathematica's virtual operating system (functions like CopyFile,
FileNames, etc.) as far as possible.
You can define further remote kernels to launch tasks in parallel. If you
have several notebooks open, they can each have different local or remote
kernels. You can copy paste output or input expressions between
them. Or the kernels can even communicate via MathLink (see the
Mathematica book).
Old information (no longer works in CERN) kept for
reference
Some older versions of the information, kept for reference.
This is basically equivalent to what is given at How
do I connect a Windows front end to a remote Unix kernel? except that
in the CERN environment there are a few obstacles to be overcome.
Here is the recipe I have found:
-
Make sure that the startup script for your default Unix shell sets some
valid value for DISPLAY. In my case, it was enough to set it to the
address of my X terminal in my .tcshrc file. However this
probably means that a session needs to be running on that X terminal and
that terminal will accept stuff from rsplus (xhost + etc.). And I'm
not sure how this affects other things. Maybe there is some NULL
value that can also be used or a better way to do this?
Start Mathematica on Windows, go to the Kernel/Kernel Configuration
Options menu.
-
Add a kernel.
-
Select basic options, give it the name "rsplus" or whatever
-
Select Launch on Remote Machine
-
Set Machine Name to rsplus.cern.ch
-
Remote login to your userid on rsplus.cern.ch
-
I select Append name to In/Out prompts and it works
-
I don't select Automatically launch ...
-
Select Advanced Options
-
I left the arguments to MLOpen as
-LinkMode Listen -LinkProtocol TCP -LinkOptions
MLDontInteract
-
For Shell command to launch kernel, I put
Z:\P32\Mathematica\3.0.1.1x\SystemFiles\FrontEnd\Binaries\Windows\winrsh.exe
-e -m -q -h rsplus.cern.ch -l jowett 'math -mathlink -LinkMode Connect
-LinkName "`linkname`"'
I.e. it seems you need to replace "winrsh" with the explicit
path to winrsh.exe. You may have to put your own user name in.
There seems to be a bug here, in that if you subsequently go back to
Basic Options, this setting disappears - watch out!
-
Select OK twice to close the dalogue.
-
Choose a notebook window, perhaps a new one.
-
From Kernel/Notebook's Kernel menu, select the rsplus kernel you
just created.
-
Try evaluating something in the notebook. You will be asked
for your password on rsplus. The first evaluation can take some time but
once the kernel is loaded, it goes much faster.
Further Notes on Recipe A
-
The remote kernel definition should be remembered for future sessions so
you only need to go through the above steps once and select the kernel
you want later.
-
You can also run a local kernel from the same Mathematica Front End.
Generally, you will want to do this in another notebook window although
you can change a given notebook's kernel forth and back very easily.
If you use the output prompt feature, then you can always see which kernel
produced a given output. Presumably you could run further remote
kernels too ...
-
Graphic output from rsplus appears in the Windows notebook - not the X
terminal as one might fear.
-
Running the Unix Front End with a Unix kernel, my experience is that you
can't abort or interrupt a running evaluation that has obviously gone wrong
or is taking too long. However you can interrupt a Unix kernel
from Windows.
-
Running programs like MAD from the Unix Front End does not always work
properly. Some of the terminal output from MAD tends to appear in
the terminal window from which you launched the Front End. This works
better on Windows: all the terminal output from MAD is captured by
the Windows Front End and displayed in the notebook interface (or returned
as a value).
-
So far, I have not succeeded in getting this to work with the SLAP WGS
machines. The connection is refused. The system administrator
has been contacted ...
-
The Mathematica variable $MachineName can be vrey useful in this context!
-
To run a Unix command and get hold of its output, evaluate expressions
like
ReadList["!pwd",String]
See also the Mathematica book, my Mathematica
notebook for interacting with CERN Unix systems (which runs very happily
like this) and my notes
on using AFS from Windows NT.
-
The winrsh program (path above) can be used by itself to execute Unix commands
from Windows.
-
Although there is no real need for it, it seems that the CERN startup scripts
for the kernel ("math") require DISPLAY to be set.
-
If your PC is slow then this may also give faster evaluation. However
this is not the case for my machine.
Recipe B
Here are some points worth noting:
-
If you start the kernel on the Unix machine by typing
math
in a terminal window, and then evaluating
$ParentLink = LinkConnect["xxxx@machine.cern.ch"]
(where xxxx is as explained in the
link Wolfram FAQ page mentioned above) any graphics will appear in an X-window
as well as in the Windows Front End. This can be avoided by starting
the kernel with
math -mathlink -linkmode connect -linkname
xxxx@machine.cern.ch
-
Be careful about launching processes in background, e.g. with
ReadList["!xterm &",String]
as this may leave the notebook in "Running ..." mode until the terminal
window is closed. It does not seem to happen for everything though
(nedit is OK ...).
Batch jobs
Another approach is to prepare a batch job and then submit it to a Unix
machine. This is very easy with the Auto-generated package mechanism.
See
DN
- Re: running calculations in a batch mode
and my
notes on batch jobs in CERN.
Last updated by JMJ, 29/7/1999.