Mathematica

Overview

Mathematica is an integrated technical computing environment which combines numeric and symbolic compute engines, a graphics system, a programming language, a documentation system and connectivity to other programs. Mathematica may be used for handling complex symbolic calculations involving millions of terms, analyzing and visualizing data, numerical modeling and simulation, rapid application development, producing publication-quality output and presentations.

Version 11.2.0 and 11.3.0 are currently installed on the CSF.

Set up procedure

To set up the Mathematica environment you need to issue one of the following commands

module load apps/binapps/mathematica/13.2.1
module load apps/binapps/mathematica/12.2.0
module load apps/binapps/mathematica/11.3.0
module load apps/binapps/mathematica/11.2.0

Running the application interactively

To run Mathematica interactively you should first log into the CSF using the -X switch as follows

ssh -X -l username csf3.itservices.manchester.ac.uk

Next, load the Mathematica modulefile

module load apps/binapps/mathematica/13.2.1

Finally, run Mathematica via qrsh

qrsh -l short -V mathematica

Serial batch job submission

It is not possible to run Mathematica .nb files in batch mode. Instead, you must create a text-only file containing your Mathematica program. For example, create a text file called input.m containing the following

Table[
 NIntegrate[Sin[x^n], {x, 1, 10}, MaxRecursion -> 1000]
 , {n, 1, 70}]

A suitable SGE submission script, mathematica_job.sge, for the above would be

#!/bin/bash --login
#$ -cwd
#$ -V
module load apps/binapps/mathematica/13.2.1

math -noprompt < input.m > out.txt

Note that the executable that runs your script is math (i.e. the Mathematica Kernel) and not mathematica (The notebook interface)

To run the above job you should then use qsub

qsub mathematica_job.sge

Parallel batch job submission

A parallel version of input.m is

LaunchKernels[4];
ParallelTable[
  NIntegrate[Sin[x^n], {x, 1, 10}, MaxRecursion -> 1000], {n, 1, 70}] // AbsoluteTiming
CloseKernels[];

A suitable submission script is

#!/bin/bash --login
#$ -cwd
#$ -pe smp.pe 4 

module load apps/binapps/mathematica/13.2.1

export OMP_NUM_THREADS=$NSLOTS

math < input.m > out.txt

Note that the only difference is the -pe switch. Job submission is similar to that of serial jobs: use qsub.

Using ‘Export’ in batch job to create an image file

A simple .m file example

Export["testred.png", Graphics@{Red, Disk[{0, 0}, 1]}];

Issue

The ‘Export’ option relies on the linux DISPLAY variable which is not available to a batch job and results in errors similar to:

Qt issued a fatal error: QXcbConnection: Could not connect to display localhost:21.0

Aborted “${MathematicaFE}” -topDirectory “${TopDirectory}” “$@”

and an empty image file.

Solution

Use a utility called xvfb-run. An example batch script:

#!/bin/bash --login
#$ -cwd

module load apps/binapps/mathematica/13.2.1

xvfb-run math -noprompt < input.m > out.txt

Further info

Last modified on July 7, 2023 at 4:28 pm by George Leaver