Differences
This shows you the differences between two versions of the page.
Both sides previous revision Previous revision Next revision | Previous revision | ||
doku:mathematica [2015/05/13 08:19] – [VSC-3] ir | doku:mathematica [2022/09/20 13:41] (current) – [SLURM] groda | ||
---|---|---|---|
Line 1: | Line 1: | ||
======= Mathematica Batch Jobs ======= | ======= Mathematica Batch Jobs ======= | ||
- | ===== VSC-2 ===== | ||
- | ==== Sun Grid Engine ==== | ||
- | The simplest way is to create a file with your mathematica commands, e.g. ' | ||
- | < | ||
- | # the following option makes sure the job will run in the current directory | ||
- | #$ -cwd | ||
- | # this option makes sure the job has the same environment variables as the submission shell | ||
- | #$ -V | ||
- | MATHDIR=/ | + | === SLURM === |
- | $MATHDIR/ | + | |
- | </ | + | In order to be able to use Mathematica, |
- | If we name the above file as math-job.sh and place it in the same directory as math-input.m we can submit it from the same directory | + | |
< | < | ||
- | user@l01 $ qsub math-job.sh | + | [username@l32]$ module load Mathematica |
+ | [username@l32]$ module list # check loaded modules | ||
+ | Currently Loaded Modulefiles: | ||
+ | [...] | ||
+ | 18) Mathematica/ | ||
</ | </ | ||
- | The output will be left in file '' | + | (See also the introduction to the [[https:// |
- | + | Now, Mathematica can be called by | |
- | You could also incorporate mathematica commands in the job file itself, rather then have them in a separate file: | + | |
< | < | ||
- | #$ -cwd | + | [username@l32]$ math |
- | #$ -V | + | |
- | + | ||
- | MATHDIR=/ | + | |
- | + | ||
- | $MATHDIR/math << | + | |
- | 1+1 | + | |
- | 3*3 | + | |
- | END_MATH_COMMANDS | + | |
</ | </ | ||
- | The above notations means that everything between "<< | + | ==== Example: Parallel Mathematica Task ==== |
- | ==== Parallel Usage ==== | + | Mathematica script example '' |
- | Jobscript: | + | |
< | < | ||
- | #$ -N parallel | ||
- | #$ -q all.q | ||
- | #$ -pe mpich 32 | ||
+ | GetEnvironment[" | ||
+ | math = Environment[" | ||
+ | kernelsperhost = 16 | ||
+ | hosts=Import[" | ||
- | #learn how to read in this file into mathematica directly | ||
- | cp -v $TMPDIR/ | ||
- | / | ||
- | |||
- | </ | ||
- | |||
- | Mathematica script named '' | ||
- | |||
- | < | ||
- | (* configuration for starting remote kernels *) | ||
Needs[" | Needs[" | ||
- | $RemoteCommand= " | + | $RemoteCommand = "ssh -x -f -l `3` `1` " |
- | (* initialize the kernels on all machines defined in the host file *) | + | (* first host with one kernel less *) |
+ | LaunchKernels[RemoteMachine[hosts[[1]], | ||
- | hosts=Import[" | ||
- | |||
- | (* on the master node initialize only one kernel less, since one is already running *) | ||
imin=2; | imin=2; | ||
imax=Length[hosts]; | imax=Length[hosts]; | ||
idelta=1; | idelta=1; | ||
- | Do[ | + | Do[ |
- | Print[" | + | LaunchKernels[RemoteMachine[hosts[[i]], kernelsperhost]]; |
- | LaunchKernels[RemoteMachine[hosts[[i]]]];, | + | |
- | {i, | + | |
- | ] | + | |
- | |||
- | (* actual calculation *) | ||
primelist = ParallelTable[Prime[k], | primelist = ParallelTable[Prime[k], | ||
Print[primelist] | Print[primelist] | ||
- | |||
</ | </ | ||
+ | sbatch job script | ||
+ | '' | ||
+ | < | ||
+ | #!/bin/bash | ||
+ | # | ||
+ | #SBATCH -J par | ||
+ | #SBATCH -N 2 | ||
+ | #SBATCH -L mathematica@vsc | ||
- | ===== VSC-3 ===== | + | |
- | === SLURM === | + | module |
- | In order to be able to use Mathematica, | + | module load Mathematica/ |
- | < | + | |
- | [username@l32]$ module avail # select a Mathematica version | + | |
- | [username@l32]$ | + | export MATH_BIN=`which math` |
- | [username@l32]$ module list # check loaded modules | + | #export MATH_PROC=16 |
- | Currently Loaded Modulefiles: | + | scontrol show hostnames |
- | 1) Mathematica/ | + | #execute prolog for getting access to license everywhere |
+ | srun hostname | ||
+ | |||
+ | |||
+ | math -run < math-vsc3.m | ||
</ | </ | ||
- | (See also the introduction to the [[https:// | ||
- | Now, Mathematica can be called by | ||
< | < | ||
- | [username@l32]$ | + | [username@l32]$ |
+ | [username@l32]$ squeue -u username | ||
</ | </ | ||
- | ==== Example: Parallel Mathematica Task ==== | + | ==== remote kernel connection |
+ | |||
+ | The setup follows | ||
+ | [[https:// | ||
+ | with the | ||
- | Using the same Mathematica script example '' | + | **Shell command to launch kernel:** |
+ | |||
+ | for VSC3+ | ||
< | < | ||
- | #!/bin/bash | + | /Users/<LOCAL-USERNAME>/ |
- | # | + | |
- | # | + | |
- | # | + | |
- | #SBATCH --ntasks-per-node=16 | + | |
- | #SBATCH --ntasks-per-core=1 | + | |
- | #SBATCH --threads-per-core=1 | + | |
- | + | ||
- | math -run "<< | + | |
</ | </ | ||
+ | for VSC4 | ||
< | < | ||
- | [username@l32]$ sbatch jobPar.sh # submit your job | + | / |
- | [username@l32]$ squeue | + | |
</ | </ | ||
+ | |||
+ | Note that on VSC4, the salloc command [as described on the | ||
+ | cc-mathematik.univie.ac.at web link] does not need the Mathematica | ||
+ | license. Just leave the -L parameter away. |