To submit Mathematica jobs to compute nodes using SLURM, the Mathematica command to be executed must be contained in a single .m script. The .m script will then be passed to themathcommand in a batch script. Please note that, currently, we support only in a batch mode, not an interactive mode.
It is also important to note that we currently have 2 licenses of Mathematica for a cluster. We then limit the total job to run to 2. You must choose qos=cu_math and partition=math in your SLURM script.
An example of math-1core.m,
Pause[600];
A = Sum[i, {i,1,100}]
B = Mean[{25, 36, 22, 16, 8, 42}]
Answer = A + B
Quit[];
And here is an example of the SLURM script (example7a.slurm),
Job submission is done in the same way as other SLURM jobs, e.g. usingsbatch example7a.slurm.
Multiple CPUs
For multiple CPUs in a machine, Mathematica can be run in parallel using the built in Parallel commands or by utilizing the parallel API. Note that, the Parallel Mathematica jobs are limited to one node, but can utilize all CPU cores on the node. You can use 16 CPUs maximum.
(*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]&]]];