This version is outdated by a newer approved version.DiffThis version (2022/06/20 09:01) was approved by msiegel.

This is an old revision of the document!

Mathematica Batch Jobs


In order to be able to use Mathematica, you have to load the program with the module load xyz command

[username@l32]$ module avail  # select a Mathematica version
[username@l32]$ module load Mathematica/10.0.2 # load desired version
[username@l32]$ module list   # check loaded modules
Currently Loaded Modulefiles:
  1) Mathematica/10.0.2  

(See also the introduction to the module command.)

Now, Mathematica can be called by

[username@l32]$ math 

Mathematica script example math-vsc3.m:

math = Environment["MATH_BIN"]
kernelsperhost = 16

$RemoteCommand = "ssh -x -f -l `3` `1` " <> math <> " -mathlink -linkmode Connect `4` -linkname '`2`' -subkernel -noinit" 

(* first host with one kernel less *)
LaunchKernels[RemoteMachine[hosts[[1]], kernelsperhost-1]];


        LaunchKernels[RemoteMachine[hosts[[i]], kernelsperhost]];
        , {i, imin, imax, idelta}] 

primelist = ParallelTable[Prime[k], {k, 1, 20000000}];

sbatch job script

#SBATCH -J par
#SBATCH -L mathematica@vsc

module purge
module load Mathematica/10.0.2 # load desired version

export MATH_BIN=`which math`
#export MATH_PROC=16
scontrol show hostnames $SLURM_NODELIST > nodelist
#execute prolog for getting access to license everywhere
srun hostname

math -run < math-vsc3.m
[username@l32]$ sbatch      # submit your job
[username@l32]$ squeue -u username    # check state of your job

The setup follows Local mathematica with remote kernel with the

Shell command to launch kernel:

for VSC3+

/Users/<LOCAL-USERNAME>/Library/ <VSC-USERNAME>@localhost:9998 /opt/sw/x86_64/generic/Mathematica/11.3/bin/math `linkname`

for VSC4

/Users/<LOCAL-USERNAME>/Library/ <VSC-USERNAME>@localhost:9998 /opt/sw/vsc4/VSC/x86_64/generic/Mathematica/12.3.1/bin/math `linkname`

Note that on VSC4, the salloc command [as described on the web link] does not need the Mathematica license. Just leave the -L parameter away.

  • doku/mathematica.1646915065.txt.gz
  • Last modified: 2022/03/10 12:24
  • by goldenberg