Differences
This shows you the differences between two versions of the page.
Both sides previous revision Previous revision Next revision | Previous revision | ||
doku:matlab-save [2015/05/12 10:25] – [Example: Serial Matlab Task] ir | doku:matlab-save [2022/02/01 21:18] (current) – removed goldenberg | ||
---|---|---|---|
Line 1: | Line 1: | ||
- | ====== Matlab Jobs ====== | ||
- | |||
- | ==== Run Matlab Task from command line ==== | ||
- | |||
- | Generate a matlab package called //test.m//, | ||
- | < | ||
- | add(2,3.4) | ||
- | </ | ||
- | and a function //add.m//, | ||
- | < | ||
- | z=x+y</ | ||
- | There are two ways to run this from the command line | ||
- | option 1:< | ||
- | / | ||
- | option 2:< | ||
- | / | ||
- | |||
- | ===== Batch Matlab job on VSC-2 ===== | ||
- | ==== Example: Serial Matlab Task ==== | ||
- | |||
- | Create a new directory | ||
- | < | ||
- | [username@l01 ~]$ mkdir TestMatlab | ||
- | [username@l01 ~]$ cd TestMatlab | ||
- | </ | ||
- | Create an example file called '' | ||
- | < | ||
- | [username@l01 TestMatlab]$ cat myplot.m | ||
- | h = figure; | ||
- | t = 0: | ||
- | plot(' | ||
- | saveas(h,' | ||
- | </ | ||
- | Then create a new file called '' | ||
- | < | ||
- | #$ -N matlab | ||
- | #$ -l h_rt=00: | ||
- | / | ||
- | </ | ||
- | The contents of your directory should now be: | ||
- | < | ||
- | [username@l01 TestMatlab]$ ls | ||
- | matlab.sh | ||
- | </ | ||
- | Submit your job: | ||
- | < | ||
- | [username@l01 TestMatlab]$ qsub matlab.sh | ||
- | </ | ||
- | When the job has finished you will see a " | ||
- | |||
- | ==== Example: Local Matlabpool ==== | ||
- | |||
- | For using all cores on a machine effetively, a so-called matlabpool can be started: | ||
- | |||
- | < | ||
- | #$ -N matlab | ||
- | #$ -pe mpich 8 | ||
- | #$ -V | ||
- | #$ -cwd | ||
- | #$ -l h_rt=00: | ||
- | / | ||
- | </ | ||
- | |||
- | < | ||
- | matlabpool %open local 8 % local profile is default setting, at most 8 workers are allowed with the local scheduler | ||
- | |||
- | matlabpool size | ||
- | |||
- | n = 500; K = 50; L = 10; T = zeros(1,L); | ||
- | |||
- | % serial inner loop | ||
- | for l = 1:L | ||
- | tic | ||
- | for k = 1:K | ||
- | eig(rand(n)); | ||
- | end | ||
- | T(l) = toc; | ||
- | end | ||
- | |||
- | disp([' | ||
- | |||
- | % parallel inner loop | ||
- | for l = 1:L | ||
- | tic | ||
- | parfor k = 1:K | ||
- | eig(rand(n)); | ||
- | end | ||
- | T(l) = toc; | ||
- | end | ||
- | |||
- | disp([' | ||
- | |||
- | matlabpool close | ||
- | </ | ||
- | |||
- | |||
- | ==== Currently not available on VSC: Matlab Parallel Jobs using Matlab distributed computed environment (MDCE) ==== | ||
- | |||
- | In November 2012 a test installation of the MDCE enviroment was available for one month. For running Matlab in | ||
- | parallel it has to connect to so called matlab workers. The job script below starts the MDCE processes, sets up | ||
- | a MJS environment and connects a number of worker to it. Start up of the workers takes some minutes. | ||
- | |||
- | __Currenlty this software is not installed. From VSC Administration point of view most task can be handled with | ||
- | the already existing campus workstation licences. If you are in need of this feature please **[[doku: | ||
- | |||
- | |||
- | The job script and a sample parallel matlab job can be downloaded here: {{: | ||
- | |||
- | Job script: | ||
- | < | ||
- | |||
- | #$ -N matlab_test | ||
- | #$ -pe mpich 32 | ||
- | #$ -V | ||
- | #$ -cwd | ||
- | |||
- | MATLAB_SCRIPT=calc_mjs.m | ||
- | |||
- | MATLAB=/ | ||
- | MDCE=/ | ||
- | DIST_DIR=/ | ||
- | |||
- | NSLOTS_PER_NODE_AVAILABLE=8 | ||
- | NSLOTS_PER_NODE_USED=2 | ||
- | NSLOTS_REDUCED=`echo " | ||
- | echo " | ||
- | uniq $TMPDIR/ | ||
- | |||
- | JOBMANAGER_HOST=`head -n 1 $TMPDIR/ | ||
- | JOBMANAGER=matlab_`whoami` | ||
- | |||
- | #Kill all old matlab processes | ||
- | for node in `cat $TMPDIR/ | ||
- | do | ||
- | ssh $node 'for i in `ps axu |grep matlab| tr -s " "|grep -v grep | cut -d " " -f 2`;do echo $i; kill -9 $i; done; rm -rf /tmp/matlab ;' | ||
- | done | ||
- | |||
- | $MDCE start -clean | ||
- | ${DIST_DIR}/ | ||
- | ${DIST_DIR}/ | ||
- | #pdsh is too fast for the license server ... | ||
- | for worker in `cat $TMPDIR/ | ||
- | do | ||
- | echo starting workers on host $worker | ||
- | ssh $worker $MDCE start -clean | ||
- | for i in `seq 1 $NSLOTS_PER_NODE_USED` | ||
- | do | ||
- | ${DIST_DIR}/ | ||
- | done | ||
- | done | ||
- | |||
- | #What we actually want to do: | ||
- | $MATLAB -nodisplay < $MATLAB_SCRIPT | ||
- | |||
- | #Clean up: | ||
- | ${DIST_DIR}/ | ||
- | for worker in `cat $TMPDIR/ | ||
- | do | ||
- | echo stopping worker on $worker | ||
- | for i in `seq 1 $NSLOTS_PER_NODE_USED` | ||
- | do | ||
- | ${DIST_DIR}/ | ||
- | done | ||
- | ssh $worker $MDCE stop -clean | ||
- | done | ||
- | echo done | ||
- | </ | ||
- | |||
- | ===== Batch Matlab job on VSC-3 ===== | ||
- | In order to be able to use matlab, you have to load the program with the ' | ||
- | < | ||
- | [username@l32]$ module avail # select a matlab version | ||
- | [username@l32]$ module load Matlab/ | ||
- | [username@l32]$ module list # check loaded modules | ||
- | Currently Loaded Modulefiles: | ||
- | 1) Matlab/ | ||
- | </ | ||
- | (See also the introduction to the [[https:// | ||
- | |||
- | Now, Matlab can be called by | ||
- | < | ||
- | [username@l32]$ matlab | ||
- | </ | ||
- | |||
- | ==== Example: Serial Matlab Task ==== | ||
- | |||
- | Analogously to VSC-2, we use the matlab m-file {{doku: | ||
- | < | ||
- | #!/bin/bash | ||
- | # | ||
- | #SBATCH -J test # job name | ||
- | #SBATCH -N 1 # number of nodes | ||
- | #SBATCH --ntasks-per-node=1 | ||
- | #SBATCH --ntasks-per-core=1 | ||
- | #SBATCH --threads-per-core=1 | ||
- | #SBATCH --time=10 | ||
- | |||
- | export OMP_NUM_THREADS=1 | ||
- | |||
- | time matlab < myplot.m | ||
- | </ | ||
- | |||
- | < | ||
- | [username@l32]$ sbatch jobSerial.sh | ||
- | [username@l32]$ squeue -u username | ||
- | </ | ||