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 13:32] – [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/ | + | |
- | </ | + | |
- | 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 with | + | |
- | < | + | |
- | user@l01 $ qsub math-job.sh | + | |
- | </ | + | |
- | + | ||
- | The output will be left in file '' | + | |
- | + | ||
- | You could also incorporate mathematica commands in the job file itself, rather then have them in a separate file: | + | |
+ | In order to be able to use Mathematica, | ||
< | < | ||
- | #$ -cwd | + | [username@l32]$ module load Mathematica |
- | #$ -V | + | [username@l32]$ module list |
- | + | Currently Loaded Modulefiles: | |
- | MATHDIR=/ | + | [...] |
- | + | 18) Mathematica/ | |
- | $MATHDIR/ | + | |
- | 1+1 | + | |
- | 3*3 | + | |
- | END_MATH_COMMANDS | + | |
</ | </ | ||
- | The above notations means that everything between "<< | ||
- | |||
- | ==== Parallel Usage ==== | ||
- | Jobscript: | ||
- | < | ||
- | #$ -N parallel | ||
- | #$ -q all.q | ||
- | #$ -pe mpich 32 | ||
- | |||
- | |||
- | # $TMPDIR/ | ||
- | # copy this file to a temporary file which will be read in by Mathematica; | ||
- | # in the following the small Mathematics m-file will start a kernel on each machine; | ||
- | # since the kernel on the master is already running, it is sufficient | ||
- | # to start the kernels beginning with the second host in the machines file. | ||
- | |||
- | cp -v $TMPDIR/ | ||
- | |||
- | / | ||
- | |||
- | </ | ||
- | |||
- | Mathematica script named '' | ||
- | |||
- | < | ||
- | (* configuration for starting remote kernels *) | ||
- | |||
- | Needs[" | ||
- | $RemoteCommand= "ssh `1` -n -l `3` \"/ | ||
- | |||
- | |||
- | (* initialize the kernels on all machines defined in the host file *) | ||
- | |||
- | hosts=Import[" | ||
- | |||
- | (* since the kernel on the master is already running, initialization starts with host 2 *) | ||
- | imin=2; | ||
- | imax=Length[hosts]; | ||
- | idelta=1; | ||
- | |||
- | Do[ | ||
- | Print[" | ||
- | LaunchKernels[RemoteMachine[hosts[[i]]]];, | ||
- | {i, | ||
- | ] | ||
- | |||
- | |||
- | (* actual calculation *) | ||
- | primelist = ParallelTable[Prime[k], | ||
- | Print[primelist] | ||
- | |||
- | </ | ||
- | |||
- | |||
- | ===== VSC-3 ===== | ||
- | === SLURM === | ||
- | In order to be able to use Mathematica, | ||
- | < | ||
- | [username@l32]$ module avail # select a Mathematica version | ||
- | [username@l32]$ module load Mathematica/ | ||
- | [username@l32]$ module list # check loaded modules | ||
- | Currently Loaded Modulefiles: | ||
- | 1) Mathematica/ | ||
- | </ | ||
(See also the introduction to the [[https:// | (See also the introduction to the [[https:// | ||
- | |||
Now, Mathematica can be called by | Now, Mathematica can be called by | ||
< | < | ||
Line 109: | Line 23: | ||
Mathematica script example '' | Mathematica script example '' | ||
< | < | ||
- | (* configuration for starting remote kernels *) | + | |
+ | GetEnvironment[" | ||
+ | math = Environment[" | ||
+ | kernelsperhost = 16 | ||
+ | hosts=Import[" | ||
+ | |||
Needs[" | Needs[" | ||
+ | $RemoteCommand = "ssh -x -f -l `3` `1` " <> math <> " -mathlink -linkmode Connect `4` -linkname ' | ||
- | (* 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, | + | |
- | ] | + | |
- | + | primelist = ParallelTable[Prime[k], | |
- | (* actual calculation *) | + | |
- | primelist = ParallelTable[Prime[k], | + | |
Print[primelist] | Print[primelist] | ||
</ | </ | ||
+ | |||
sbatch job script | sbatch job script | ||
'' | '' | ||
Line 139: | Line 55: | ||
#!/bin/bash | #!/bin/bash | ||
# | # | ||
- | #SBATCH -J par # job name | + | #SBATCH -J par |
- | #SBATCH -N 2 # number of nodes=2 | + | #SBATCH -N 2 |
- | #SBATCH --ntasks-per-node=16 | + | #SBATCH -L mathematica@vsc |
- | #SBATCH --ntasks-per-core=1 | + | |
- | #SBATCH --threads-per-core=1 | + | |
- | module load Mathematica/ | ||
- | scontrol show hostnames $SLURM_NODELIST > ./nodelist | + | module purge |
+ | module load Mathematica/10.0.2 # load desired version | ||
- | rm machines_tmp | ||
- | tasks_per_node=16 | + | export MATH_BIN=`which math` |
- | nodes=2 | + | #export MATH_PROC=16 |
- | for ((line=1; line< | + | scontrol show hostnames |
- | do | + | #execute prolog for getting access to license everywhere |
- | for ((tN=1; tN< | + | srun hostname |
- | do | + | |
- | head -$line nodelist | + | |
- | done | + | |
- | done | + | |
- | echo "this is the content of the host machines file" | ||
- | cat machines_tmp | ||
math -run < math-vsc3.m | math -run < math-vsc3.m | ||
Line 171: | Line 78: | ||
[username@l32]$ squeue -u username | [username@l32]$ squeue -u username | ||
</ | </ | ||
+ | |||
+ | ==== remote kernel connection ==== | ||
+ | |||
+ | The setup follows | ||
+ | [[https:// | ||
+ | with the | ||
+ | |||
+ | **Shell command to launch kernel:** | ||
+ | |||
+ | for VSC3+ | ||
+ | < | ||
+ | / | ||
+ | </ | ||
+ | |||
+ | for VSC4 | ||
+ | < | ||
+ | / | ||
+ | </ | ||
+ | |||
+ | 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. |