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 modelling 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/14.2.1 module load apps/binapps/mathematica/13.2.1 # These may no longer work on the CSF. 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 username@csf3.itservices.manchester.ac.uk # # UPPERcase X
Next, load the Mathematica modulefile
module load apps/binapps/mathematica/14.2.1
Finally, run Mathematica via srun
# 14.2.1 only has the command-line interface (we are working on getting the GUI interface) srun -p interactive -t 0-1 --pty math # 13.2.1 has the GUI interface, started with the mathematica command srun -p interactive -t 0-1 --pty mathematica
- Further information about how to start X-Windows and GUI applications on the CSF.
- More details concerning srun
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 Slurm submission script, mathematica_job.sbatch
, for the above would be
#!/bin/bash --login #SBATCH -p serial # Use the nodes dedicated to 1-core jobs #SBATCH -t 2-0 # Max time the job can run for (2-0 is 2 days, max permitted is 7 days) module purge module load apps/binapps/mathematica/14.2.1 # Output will be written to the slurm-JOBID.out file math -noprompt < input.m
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
sbatch mathematica_job.sbatch
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 #SBATCH -p multicore # Use the AMD 168-core nodes for parallel jobs #SBATCH -n 4 # (or --ntasks=) Number of cores to use #SBATCH -t 2-0 # Wallclock timelimit for the job (2-0 is 2 days, max permitted is 7 days) #$ -pe smp.pe 4 module purge module load apps/binapps/mathematica/14.2.1 # Inform mathematica how many cores it can use. $SLURM_NTASKS is the -n number above. export OMP_NUM_THREADS=$SLURM_NTASKS # Output will be written to the slurm-JOBID.out file math -noprompt < input.m
Use sbatch jobscript
to submit the job as before.
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
If you receive the following error:
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, try the following jobscript.
Solution
Use a utility called xvfb-run
. An example batch script:
#!/bin/bash --login #SBATCH -p serial # Use the nodes dedicated to 1-core jobs #SBATCH -t 2-0 # Max time the job can run for (2-0 is 2 days, max permitted is 7 days) module purge module load apps/binapps/mathematica/14.2.1 xvfb-run math -noprompt < input.m