Information Technology
Using Mathematica on Ada

04-Jun-2008


Introduction

Mathematica is a fully integrated technical computing system, combining interactive calculation (both numeric and symbolic), visualization tools, and a complete programming environment. There are currently two ways to run Mathematica on the Ada cluster as described below.  These examples are intended to present a very simple configuration to run a minimal Mathematica job on Ada.  Adjust your configuration according to the complexity of your jobs.


Running Mathematica with the Graphical User Interface

In order to run Mathematica with the Graphical User Interface (GUI), follow the steps below:

1.  Login to Ada using SSH

In order to login to Ada, you must use the SSH software configured to tunnel (or redirect) X displays:
  • From Unix/Linux:


    ssh adauser@ada.rice.edu -X

  • From Windows:

    • You must use SSH and X-Win32 for Windows.  Both are available on the IT Software Distribution Page.  SSH will provide the mechanism to login to Ada, while X-Win32 will allow graphical applications running on Ada to be displayed on your desktop. For instructions on logging in to Ada using SSH and X-Win32, please see our FAQ on this subject.

2.  Configure your Ada environment to run Mathematica

After you have logged into Ada, use the module command to configure your Ada environment to run Mathematica.


adauser@adahost:~> module load mathematica

The module command will establish all of the environment variables needed to run the Mathematica program.

3.  Launch Mathematica

Run the mathematica command to launch the GUI.   This will run Mathematica on one of Ada's login nodes.   From this point you will be able to write and test your Mathematica programs using the GUI.  It is important to note that if you run a Mathematica program from this point, you will be running on the login node, not on a compute node.  This is acceptable only for debugging of short programs (< 30 minutes in duration).  Programs using a lot of CPU time on the login nodes will impact all users on the system.  Therefore, any programs found running for more than 30 minutes on the login nodes are subject to being killed at the system administrators descretion!

NOTE: Getting Mathematica's GUI to work remotely on Ada with the display appearing on your desktop system can be tricky since Mathematica will look for its fonts on your desktop, not on Ada. If you are using a Linux desktop, you can copy the Mathematica fonts from Ada to your desktop. Simply copy the contents of /opt/apps/mathematica/6.0/SystemFiles/Fonts/Type1 to some location on your desktop system, such as /home/username/mathematica/6.0/SystemFiles/Fonts/Type1. After the files have been copied, run this command on your desktop before launching Mathematica:


xset fp+ /home/username/mathematica/6.0/SystemFiles/Fonts/Type1/

For instructions on setting up Mathematica fonts on Macintosh, Windows, and various versions of Unix, please see the Mathematica Technical Support website.




Running Mathematica on Compute Nodes

It is preferable to run Mathematica jobs on the compute nodes of Ada, not the login nodes.  This is accomplished by running your Mathematica program from inside a PBS batch script as follows:

1.  Login to Ada using SSH

Login to Ada using SSH.  X11 tunneling as described in the previous section is not required.

2.  Configure your Ada environment to run Mathematica

After you have logged into Ada, use the module command to configure your Ada environment to run Mathematica..


adauser@adahost:~> module load mathematica

The module command will establish all of the environment variables needed to run the Mathematica program.

3.  Write a Mathematica Program

Write your Mathematica program and save it in a file.  For our example we will use a sample Mathematica program called math.m as illustrated below. This example will demonstrate a Mathematica program that accepts input from the command line and from a file while writing output to a file.


outputfile=$CommandLine[[2]]
inputfile=$CommandLine[[3]]
x=ToExpression[$CommandLine[[4]]]
instream = OpenRead[inputfile]
y=ToExpression[Read[instream, Number]]
functionX=N[Sin[x]]
functionY=N[Sin[y]]
outstream=OpenWrite[outputfile]
WriteString[outstream, x," ", y, " ", functionX," ", functionY, "\n"]

Save your program in a directory, such as /home/adauser/mathematica where adauser is your username.    You may want to create your files using the nano, vi or emacs text editors or use the Mathematica GUI.

4.  Write a PBS Batch Script

Include your Mathematica program (math.m in our example) in a PBS batch script named math.pbs, for example, as follows:


#PBS -q compute
#PBS -l walltime=4:00:00
#PBS -N Math
#PBS -V ##This is necessary to inherit environment variables
#PBS -M emailaddress@rice.edu
#PBS -m abe
#PBS -o /home/adauser/mathematica
#PBS -e /home/adauser/mathematica
echo "I ran on: "
cat $PBS_NODEFILE
cd /home/adauser/mathematica
math < math.m output.dat input.dat 0.2

NOTE:  This example will submit the math.m program to a single compute node on the cluster.  Output from the program will be found in a file called output.dat.  Input will come from the command line arguments and a file called input.dat. The latter file should contain a single number. Output and errors from the PBS batch script will be found in a file named JobID.OU and JobID.ER, respectively, where JobID is the PBS Job ID number assigned to your job.   There will be a different number for each job you submit. In the example above, substitute your username in place of adauser.

5.  Submit the PBS Job

Once you have written the PBS batch script math.pbs above, you must submit the job to the scheduler as follows:


adauser@adahost:~> cd /home/adauser/mathematica

adauser@adahost:~> qsub ./math.pbs

 

NOTE:  This will submit a single Mathematica job to a single processor on Ada.  Use the showq command to determine if your job is running or queued. In the example above, substitute your username in place of adauser.


More Information (Mathematica User's Guide)

The examples above are intended to be a very minimal example of how to get a single Mathematica compute job to run on a compute node.  There are a variety of ways to run multiple jobs.  One way to run multiple jobs is to repeat the process above for each job that you need to run.  Thus, you would submit your jobs serially, one per PBS batch script.  You can also write Unix/Linux shell scripts to submit multiple jobs from within the shell script utilizing only one batch script. This topic is beyond the scope of this document.

For more information on PBS batch scripts, monitoring your jobs, and general information for using Ada, please see our FAQ.

To get more help with Mathematica, use the Mathematica User's Guide available on the Wolfram Mathematica web site.



Getting Help

If you need assistance running Mathematica on Ada, please contact the Help Desk at 713-348-4357.

 

IT
Division of Information Technology
MS-119, P.O. Box 1892, Rice University, Houston, Texas 77251-1892
713-348-HELP(4357)