**Mathematica**

**Wolfram's Mathematica** is a complete tool to perform modeling, simulation, visualization, development, documentation, and deployment. The features include:**Compute and Visualize: **Numerics of any precision, symbolics, or visualization--*Mathematica* is the ultimate computational tool, with system-wide technology to ensure reliability, ease-of-use, and performance. Use *Mathematica* computation directly, as the engine in an infrastructure, or integrated into a standalone application.

Develop: Develop applets, applications, documents, or infrastructure components and systems using *Mathematica*'s unique mix of capabilities--achieving record times on large projects or making small developments practical at all.

Document and deployment: *Mathematica* offers a wide range of innovative deployment options based on the *Mathematica* notebook. Whether your deliverables are interactive documents, applications, infrastructure components, or presentations,*Mathematica* notebooks are the complete solution--deployable locally or across a network.

**Important Notes**

- When running the parallel version of Mathematica, request the number of processors (ppn) equal to the index value of LaunchKernels.
- Mathematica uses network license within campus

**Installed Versions**

All the available versions of MATHEMATICA for use can be viewed by issuing the following command. This applies for other applications as well.

output:

`---------------------- /usr/local/share/modulefiles -------------------------`

mathematica/10.0 mathematica/9.0(default)

The default version is identified by "(default)" behind the module name and can be loaded as:

The other versions of MATHEMATICA can be loaded as:

`module load mathematica/<version>`

## Running Mathematica Jobs

### Interactive Job Submission

**Graphical Interface:** Since you need to set the math font locally, probably you can use only linux box or cygwin to enable Mathematica on the cluster.

Load the mathematica module

`module load mathematica`

Download math fonts to your local machine. The location of the Mathematica fonts is

` $MATHROOT/SystemFiles/Fonts`

Once you have it in your home directory on your local terminal, you need to execute the following commands:

`xset fp+ ~/math-fonts/Fonts/Type1`

`xset fp rehash`

Request a compute Node:

`qsub -I `

After it logs you into one of the comp nodes or at login, type:

`module load mathematica`

Run Mathematica

**kernel or command line only:**You can run Mathematica in Command Mode (no need to have mathematica fonts installed). Request the compute node and run mathematica as in Graphical User Interface.

`In[1]:= 2 + 3`

`Out[1]= 5`

`In[2]:= Exit`

**Serial Batch Job**Prepare a job script "job.pbs" like the one below, where mathtest.m is a mathematica script file also included below.

**job.pbs:**

`#PBS -N test`

`#PBS -l walltime=00:01:00`

`#PBS -l nodes=1:ppn=1`

`#PBS -j oe`

`cd $PBS_O_WORKDIR`

`module load mathematica`

`cp mathtest.m $PFSDIR`

`cd $PFSDIR`

`math -noprompt -run "<<mathtest.m"`

`cp -r * $PBS_O_WORKDIR`

**mathtest.m:**`(* ::Package:: *)`

`t=Table[Prime[i],{i,100000}];`

`t>>"t.out";`

`Exit[]`

Submit the job:

`qsub job.pbs`

Check the result in "t.out"

**Parallel Batch Job**

Mathematica will work with local node kernels to spawn kernels on each processor with OpenMP procedure, so we can launch up to 12 kernels for each job. You have to request enough processors in your PBS script to cover your usage.

Prepare a job script (parjob.pbs) like the one below, where parallel.m is a mathematica script file included below as well.

**parjob.pbs:**`#PBS -N test`

`#PBS -l walltime=00:01:00`

`#PBS -l nodes=1:ppn=2`

`#PBS -j oe`

`cd $PBS_O_WORKDIR`

`module load mathematica`

`pbsdcp -s parallel.m $PFSDIR`

`cd $PFSDIR`

`math -noprompt -run "<<parallel.m"`

`cp -r * $PBS_O_WORKDIR`

**parallel.m:**

`(* ::Package:: *)`

`LaunchKernels[2];`

`Parallelize[Select[Range[10000],PrimeQ[2^# - 1]&]] >>"test.out";`

`Exit[]`

(Important Note: set the index value of LaunchKernels[n] equal to ppn value (nodes=1:ppn=n) in PBS script)

Submit the job:

`qsub parjob.pbs`

Check the result in "test.out"

**References:**

Demo of mathematica: http://www.youtube.com/watch?v=ilm14HYsl6M