About these pages

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:

  1. 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.
  2. Launch a terminal window on lxplus and be ready to type a command. 
  3. 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.
  4. 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). 
  5. 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.
  6. 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

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:
  1. 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?

  2. Start Mathematica on Windows, go to the Kernel/Kernel Configuration Options menu.
  3. Add a kernel.
  4. Select basic options, give it the name "rsplus" or whatever
  5. Select Launch on Remote Machine
  6. Set Machine Name to rsplus.cern.ch
  7. Remote login to your userid on rsplus.cern.ch
  8. I select Append name to In/Out prompts and it works
  9. I don't select Automatically launch ...
  10. Select Advanced Options
  11. I left the arguments to MLOpen as

  12. -LinkMode Listen -LinkProtocol TCP -LinkOptions MLDontInteract
  13. For Shell command to launch kernel, I put

  14. 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!
  15. Select OK twice to close the dalogue.
  16. Choose a notebook window, perhaps a new one.
  17. From Kernel/Notebook's Kernel menu, select the rsplus kernel you just created.
  18. 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

Recipe B

Here are some points worth noting:

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.