Using Mathematica at CAMK

General information

 

Mathematica is a platform for all forms of computations. It's used mostly for symbolic math but can do much more. The full manual is available from the program level and on the web.

 

There are 7 Mathematica licenses available at CAMK. The software consists of two independent components - the graphical frontend and the kernel, so actually there are 7 frontend licenses and 7 kernel licenses. Each of them can be used separatelly, e.g. the frontend for editing notebooks and the kernel for calculations in the text mode (useful in the batch system).

Since users tend to "forget" to close their interactive sessions, while the number of licenses is small, there are some restrictions enforced. Currently:

 

  • 3 kernel and 1 frontend licenses are available only from the psk cluster


To display current usage of the Mathematica licenses type monitorlm on psk.
If all the licenses are busy please negotiate directly with their users. System administrators can kill abandoned (no immediate contact), idle (no kernel activity) sessions.
To start Mathematica on any workstation in the CAMK network type mathematica or (if it wasn't set up) /Vol/share/Mathematica/7.0/Executables/mathematica.

Running Mathematica in the queueing system (on cluster nodes)

When running Mathematica in the queueing system it is required to use qsub with option -l software=math:1 (1 is the number of requested licenses). It enables the batch system to hold execution of jobs if there are no available licenses (they will stay in the queue until the license is freed; otherwise such jobs would crash).

 

Various ways of using Mathematica under the queueing system are presented below. Please refer to man qsub and Cluster user's guide to learn about the queueing system and job submission.

 

Batch processing. Mathematica can read commands from a notebook file or a plain text file. The latter is recommended for batch processing since you can easily edit the commands in your favourite text editor without using the Mathematica frontend. Here is an example infile.m:
2+2
Integrate[x,{x,0,1}]
To process it and save the output to outfile.m file type
math < infile.m > outfile.m
or to get more "raw" output add option -noprompt
math -nopromt < infile.m > outfile.m
- experimnt! Here is an example job script:

#PBS -N batch_math1
#PBS -l software=math:1
#PBS -l mem=100m
#PBS -q short
cd my_directory math < infile.m > outfile.m


Tip

To convert Mathematica notebook file into plain text file use Mathematica's Front End features:
1. Select the cell or set of cells that contain the commands you wish to be written to the infile text file.
2. These cells will be defined as initialization cells by clicking on Cell-> Cell Properties-> Initialization_Cell in the menu bar.
3. Generate a text file by choosing from menu File-> Save_As_Special...-> Package_Format

Tip

By default only output lines go to standard output. If you want also input lines to appear there add in the first line of your infile:
AppendTo[$Echo, "stdout"]

Note about plots: there is no graphic output to the screen in this mode. You should export plots to a file or better - save the data to a file and create plots with apropriate software like gnuplot or xmgrace (mathematica graphics looks really awful). If you have to export plot to a file the Mathematica still needs to run the frontend (really! :-O) so you have to give access to your display - read below about "interactive graphical mode". In short - suppose you have an input file in.m
a=Plot[Cos[2*x],{x,0,Pi}]
Export["a.eps",a]
Log in to pskt: ssh -X psk and submitt a job script like this:

#PBS -N batch_math1
#PBS -l software=math:1
#PBS -l mem=100m
#PBS -q short
#PBS -X
cd my_directory math < in.m > outfile.m

Eps file will be crated in my_directory.

Interactive text mode. Ssh to psk. Submit an interactive job (option -I):
> qsub -I -q short -l software=math:1
and you will be given a shell session on one of the nodes. Run Mathematica in the text mode
> math
and type Mathematica commands. To exit Mathematica type Quit and to finish the job type logout.
Interactive graphical mode. Like above but use -X twice:
> ssh -X psk
> qsub -I -X -l software=math:1 .....
and run mathematica

Tip

You can also create the job script to start an interactive session. (Each line starting with #PBS is expected to contain command line options to qsub). Example: qsub jobfile where jobfile contains

#PBS -N math_job1
#PBS -l software=math:1
#PBS -l mem=100m
#PBS -q short
#PBS -I
#PBS -X mathematica

Working in the interactive mode on psk

Log in to psk
ssh -X psk
(the -X is important) and type
mathematica
That's it! Remember that all the limits for interactive processes on psk apply (the cpu time and memory limits are listed in the message after you log in).

Additional notes

On some systems an error message may pop up during frontend start - do not click OK, close this window with the small cross in the upper right corner instead. If you can't see mathematical symbols properly please send request to adm@camk.edu.pl to install the mathematica fonts on your computer.