Mathematica

GUI Mathematica quickstart

Once logged in, start the interactive job as above adding arguments --x11 --pty to the srun command (see Slurm for more info)

@@ srun --cpus-per-task=1 --time=0-2:00 --mem=12G --x11 --pty mathematica @@ where the time is in D-HH:MM </p>

GUI Mathematica with parallel calcs

Once logged into a terminal (with X windows enabled), request a set of resources to be allocated for 2 hours (eg. 16 cores spreads over 4 different nodes)

@@ salloc --nodes=4 --ntasks-per-node=1 --cpus-per-task=4 --time=0-2:00 --mem=16GB
mathematica &
@@

which runs mathematica front-end on the master node but don't do any calculations yet!

Next you need to setup mathematica to run on where the CPUs are located. This can be done automatically by adding to the top of your notebook
@@ (*−−−−−−−−−−−−−−*)
Needs["LightweightGridClient`"]

machines =
ReadList["!scontrol show hostname $SLURM_NODELIST", "String"]

NumericQ[countthreads =
ToExpression[ Environment["SLURM_CPUS_PER_TASK"]]]

LaunchKernels[
LightweightGrid[{"Agent" -> #, "KernelCount" -> countthreads,
"LocalLinkMode" -> "Connect", "Service" -> "",
"Timeout" -> 30}]] & /@ machines

(*−−−−−−−−−−−−−−*)
@@

For more info on this talk to Prof. Tom Stace.

Mathematica code

To run Mathematica calculations, you can also put your Mathematica commands into a file. You can then submit the job to sbatch with a script:</p> @@

  1. !/bin/bash
    #SBATCH --job-name math-example
    #SBATCH --time=02:00:00
    #SBATCH --nodes=1
    #SBATCH --ntasks=1
    #SBATCH --mem=16G

    module load mathematica
    srun math -run '<<filename.m'
    @@

Note

  • Mathematica can use a lot memory so if your job stalls or fails, try again with more memory.

Mathematica parallel code

UQ's Mathematica license permits running Mathematica in parallel on up to 16 cores on a single host. For example this code in file math-parallel.m: @@ (*Limits Mathematica to requested resources*)
Unprotect[$ProcessorCount];$ProcessorCount = 16;

(*Prints the machine name that each kernel is running on*)
Print[ParallelEvaluate[$MachineName]];

(*Prints all Mersenne PRime numbers less than 2000*)
Print[Parallelize[Select[Range[2000],PrimeQ[2^#-1]&]]];
Quit[]; @@

can be run with this submission script: @@

  1. !/bin/bash
    #SBATCH --job-name=math_parallel
    #SBATCH --nodes=1
    #SBATCH --ntasks-per-node=16
    #SBATCH --mem=16G

    module load mathematica
    math -run '<<./math-parallel.m'
    @@

GridMathematica

Jobs requiring more than 16 cores or more than one node can be run using GridMathematica. If you want to use GridMathematica send a request to the ITS help desk?.

Page last modified on February 05, 2021, at 03:00 PM
Powered by PmWiki