Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
Last revisionBoth sides next revision
doku:matlab-save [2015/05/12 10:18] irdoku:matlab-save [2017/08/31 13:57] – removed ir
Line 1: Line 1:
-====== Matlab Jobs ====== 
- 
-==== Run Matlab Task from command line ==== 
- 
-Generate a matlab package called //test.m//, 
-<code> 
-add(2,3.4) 
-</code> 
-and a function //add.m//, 
-<code>function z=add(x,y) 
-z=x+y</code> 
-There are two ways to run this from the command line 
-option 1:<code> 
-/opt/sw/matlab-80/bin/matlab -nodisplay < test.m</code> 
-option 2:<code> 
-/opt/sw/matlab-80/bin/matlab -nodisplay -r  "add(2,3.4)"</code> 
- 
-===== Batch Matlab job on VSC-2 =====  
-==== Example: Serial Matlab Task ==== 
- 
-Create a new directory 
-<code> 
-[username@l01 ~]$ mkdir TestMatlab 
-[username@l01 ~]$ cd TestMatlab 
-</code> 
-Create an example file called ''myplot.m'' or download it from {{doku:myplot.m|here}} and put it in this directory: 
-<code> 
-[username@l01 TestMatlab]$ cat myplot.m 
-h = figure; 
-t = 0:pi/20:2*pi; 
-plot('v6',t,sin(t).*2) 
-saveas(h,'myFigFile','jpg') 
-</code> 
-Then create a new file called ''matlab.sh'' as your job script, with the following basic contents: 
-<code> 
-#$ -N matlab 
-#$ -l h_rt=00:10:00 
-/opt/sw/matlab-80/bin/matlab < myplot.m 
-</code> 
-The contents of your directory should now be: 
-<code> 
-[username@l01 TestMatlab]$ ls 
-matlab.sh  myplot.m 
-</code> 
-Submit your job: 
-<code> 
-[username@l01 TestMatlab]$ qsub matlab.sh 
-</code> 
-When the job has finished you will see a "myFigFile.jpg" image file created.  
- 
-==== Example: Local Matlabpool ==== 
- 
-For using all cores on a machine effetively, a so-called matlabpool can be started: 
- 
-<code> 
-#$ -N matlab 
-#$ -pe mpich 8 
-#$ -V 
-#$ -cwd 
-#$ -l h_rt=00:10:00 
-/opt/matlab-tu/bin/matlab < main.m 
-</code> 
- 
-<code> 
-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(['serial: ',num2str(mean(T))]) 
- 
-% parallel inner loop 
-for l = 1:L 
-tic 
-parfor k = 1:K 
-    eig(rand(n)); 
-end 
-T(l) = toc; 
-end 
- 
-disp(['parallel: ',num2str(mean(T))]) 
- 
-matlabpool close 
-</code> 
- 
- 
-==== 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:contact|contact system administration]]**.__ 
- 
- 
-The job script and a sample parallel matlab job can be downloaded here:  {{:doku:matlab:matlab_mjs.tar.gz}} 
- 
-Job script: 
-<code> 
- 
-#$ -N matlab_test 
-#$ -pe mpich 32 
-#$ -V 
-#$ -cwd 
- 
-MATLAB_SCRIPT=calc_mjs.m 
- 
-MATLAB=/opt/sw/matlab-80/bin/matlab 
-MDCE=/opt/sw/matlab-dcs_R2012b/toolbox/distcomp/bin/mdce 
-DIST_DIR=/opt/sw/matlab-80/toolbox/distcomp/bin 
- 
-NSLOTS_PER_NODE_AVAILABLE=8 
-NSLOTS_PER_NODE_USED=2 
-NSLOTS_REDUCED=`echo "$NSLOTS / $NSLOTS_PER_NODE_AVAILABLE * $NSLOTS_PER_NODE_USED" | bc  ` 
-echo "starting run with $NSLOTS_REDUCED processes; $NSLOTS_PER_NODE_USED per node" 
-uniq $TMPDIR/machines  > $TMPDIR/machines_uniq 
- 
-JOBMANAGER_HOST=`head -n 1 $TMPDIR/machines_uniq` 
-JOBMANAGER=matlab_`whoami` 
- 
-#Kill all old matlab processes 
-for node in `cat $TMPDIR/machines_uniq` 
-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}/startjobmanager -name $JOBMANAGER -remotehost $JOBMANAGER_HOST  -v 
-${DIST_DIR}/nodestatus -remotehost $JOBMANAGER_HOST 
-#pdsh is too fast for the license server ... 
-for worker in `cat $TMPDIR/machines_uniq` 
-do 
- echo starting workers on host $worker 
- ssh $worker $MDCE start -clean 
- for i in `seq 1 $NSLOTS_PER_NODE_USED` 
- do 
- ${DIST_DIR}/startworker -remotehost $worker -name ${worker}_worker$i -jobmanager $JOBMANAGER -jobmanagerhost $JOBMANAGER_HOST 
- done 
-done 
- 
-#What we actually want to do: 
-$MATLAB -nodisplay < $MATLAB_SCRIPT 
- 
-#Clean up: 
-${DIST_DIR}/stopjobmanager -name $JOBMANAGER -remotehost $JOBMANAGER_HOST  -v 
-for worker in `cat $TMPDIR/machines_uniq` 
-do 
- echo stopping worker on $worker 
- for i in `seq 1 $NSLOTS_PER_NODE_USED` 
- do 
- ${DIST_DIR}/stopworker -remotehost $worker -name ${worker}_worker$i 
- done 
- ssh $worker $MDCE stop -clean 
-done 
-echo done 
-</code> 
- 
-===== Batch Matlab job on VSC-3 =====  
-In order to be able to use matlab, you have to load the program with the 'module load xyz' command 
-<code> 
-[username@l32]$ module avail  # select a matlab version 
-[username@l32]$ module load Matlab/v8.5_R2015a # load selected version 
-[username@l32]$ module list   # check loaded modules 
-Currently Loaded Modulefiles: 
-  1) Matlab/v8.5_R2015a     
-</code> 
-(See also the introduction to the [[https://wiki.vsc.ac.at/doku.php?id=doku:slurm|module command.]]) 
- 
-Now, Matlab can be called by 
-<code> 
-[username@l32]$ matlab   
-</code> 
- 
-==== Example: Serial Matlab Task ==== 
- 
-Analogously to VSC-2, we use the matlab m-file {{doku:myplot.m|myplot.m}} and create a file called ''matlab.sh'' as your job script, with the following basic contents: 
-<code> 
-#!/bin/bash 
-# 
-#SBATCH -J test 
-#SBATCH -N 1 
-#SBATCH --ntasks-per-node=1  
-#SBATCH --ntasks-per-core=1 
-#SBATCH --threads-per-core=1 
-#SBATCH --time=10                   # run time unit=minutes 
- 
-export OMP_NUM_THREADS=1 
- 
-time matlab < myplot.m 
-</code>