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).

Please do not leave Mathematica sessions open when not needed!

To display current usage of the Mathematica licenses type monitorlm on chuck.
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/<select version>/Executables/mathematica.

On the cluster - remember to login to chcuk with X forwarding: ssh -X chuck .

Running Mathematica in the queueing system (on cluster nodes)

Various ways of using Mathematica under the queueing system are presented below. Please refer to man sbatch/srun 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:

#SLURM -N batch_math1
#SLURM -mem=100m
#SLURM -p 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 the cluster frontend: ssh -X chuck and submitt a job script like this:

#SLURM -N batch_math1
#SLURM -mem=100m
#SLURM -p short
cd my_directory math < in.m > outfile.m

Eps file will be crated in my_directory.
 
Interactive text/graphical mode. Ssh to chuck. Submit an interactive job:
> srun --pty bash -l
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.
To run mathematica in graphical mode type
> 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

#SLURM -N math_job1
#SLURM -mem=100m
#SLURM -p short
#SLURM --pty

Working in the interactive mode on chuck

Log in to chuck
ssh -X chuck
(the -X is important) and type
mathematica
That's it! Remember that all the limits for interactive processes on chuck 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.