MATLAB
From FarmShare
Line 28: | Line 28: | ||
==first steps== | ==first steps== | ||
- | |||
- | |||
- | |||
- | |||
Per [[FarmShare software]] try something like: | Per [[FarmShare software]] try something like: | ||
Line 45: | Line 41: | ||
==interactive MATLAB== | ==interactive MATLAB== | ||
- | |||
- | |||
- | |||
- | |||
- | |||
- | |||
- | |||
- | + | [[Matlab-interactive]] | |
- | + | ||
- | + | ||
- | + | [[Matlab-parallel]] | |
- | |||
- | |||
== example single matlab file run via qsub == | == example single matlab file run via qsub == |
Revision as of 10:38, 28 November 2013
Contents |
getting list of available matlab versions
You can run module spider matlab to get a list of available matlab versions
$ module spider matlab -------------------------------------------------------------------------------------------------------------------- matlab: -------------------------------------------------------------------------------------------------------------------- Description: MATLAB and toolboxes Versions: matlab/r2012b matlab/r2013a -------------------------------------------------------------------------------------------------------------------- To find detailed information about matlab please enter the full name. For example: $ module spider matlab/r2013a --------------------------------------------------------------------------------------------------------------------
first steps
Per FarmShare software try something like:
module avail module load matlab
If you're running MATLAB for the first time, it'll try to write some stuff into $HOME/.matlab so make sure you have your AFS tokens or else MATLAB will crash with an undecipherable error message.
As of 9/22/2013 this works on the corn.stanford.edu cluster but NOT on the myth.stanford.edu cluster.
interactive MATLAB
example single matlab file run via qsub
Here's our helloworld.m:
disp('Hello World');
Here's a command to run that non-interactively:
matlab -nodesktop < helloworld.m
We want to run this same command via the job scheduling system. Let's write a job script (save this as matlab_example.script)
#!/bin/bash #$ -N matlab_example #$ -m bes #$ -M chekh@stanford.edu module load matlab matlab -nodesktop < /farmshare/software/examples/matlab/helloworld.m
Submit the script:
qsub matlab_example.script
Look at the job status:
qstat
You should get output file like matlab_example.oXXXXX
Warning: No display specified. You will not be able to display graphics on the screen. Warning: No window system found. Java option 'MWT' ignored < M A T L A B (R) > Copyright 1984-2011 The MathWorks, Inc. R2011b (7.13.0.564) 64-bit (glnxa64) August 13, 2011 To get started, type one of these: helpwin, helpdesk, or demo. For product information, visit www.mathworks.com. >> Hello World
example second matlab file run via qsub
Now we want to make sure we avoid AFS.
Here's our helloworld.m:
disp('Hello World');
Here's a command to run that non-interactively:
matlab -nodesktop < helloworld.m
We want to run this same command via the job scheduling system. Let's write a job script.
#!/bin/bash #$ -N matlab_example #$ -m bes #$ -M chekh@stanford.edu module load matlab matlab -nodesktop < /farmshare/software/examples/matlab/helloworld.m
Submit the script:
cd /farmshare/user_data/$USER qsub -cwd matlab_example.script
Look at the job status:
qstat
You should get output file like matlab_example.oXXXXX in your current directory
Warning: No display specified. You will not be able to display graphics on the screen. Warning: No window system found. Java option 'MWT' ignored < M A T L A B (R) > Copyright 1984-2011 The MathWorks, Inc. R2011b (7.13.0.564) 64-bit (glnxa64) August 13, 2011 To get started, type one of these: helpwin, helpdesk, or demo. For product information, visit www.mathworks.com. >> Hello World
PCT
We have the Parallel Computing Toolbox, you can use that to parallelize your job across multiple cores in a single machine.
Here's how to write a job using MDCS: http://docs.uabgrid.uab.edu/wiki/MatLab_CLI#Parallel_MATLAB
You can use the "maxNumCompThreads" command (deprecated) to see how many parallel threads you can run. I get "24" on barley, or "8" on corn.
simple PCT run on corn
matlab -nodesktop -r 'maxNumCompThreads' >> matlabpool ( 'open', 'local', 8) Starting matlabpool using the 'local' configuration ... connected to 8 labs. >> >> matlabpool size ans = 8 >> feature('numCores') ans = 8 Then use 'parfor' instead of 'for'.
matlabpool of size 0 and size 1 are effectively the same, except the latter uses a PCT toolbox license.
Here are some training slides and example code that I copied from http://www.osc.edu/~samsi/sc11edu/
matlab with matlabpools on the barley
A good way to speed up your matlab code on barley is to submit your matlab job with the shm parallel environment. The parallel environment is specified with -pe shm 4 below. The number you specify after shm will be the number of cores allocated to your job (all from the same host). In this case we are asking for 4 cores, which then become workers in a matlab pool.
There is a problem that frequently occurs with matlab if you run many jobs which all use matlab pools. Matlab is naive and does not handle having multiple instances running at the same time. To allow many matlabpools to be run simulataneously, use the following code to setup your pool. You may substitute any number between 1 and 12 for the number of cores (12 being the max matlab will let us use with current license).
#!/bin/bash #$ -N matlabfft #$ -S /bin/bash #$ -pe shm 4 #$ -l mem_free=500M #$ -cwd hostname echo "" echo "" echo "" module load matlab matlab -nodesktop <<EOF cluster = parcluster('local') tmpdirforpool = tempname mkdir(tmpdirforpool) cluster.JobStorageLocation = tmpdirforpool msg = sprintf('setting matlabpool to %s', getenv('NSLOTS')) cluster.NumWorkers = str2num(getenv('NSLOTS')) matlabpool(cluster) cluster a = ones(1000,1000) disp('begin running parfor') parfor i = 1:10000 b=ones./a end disp('done running parfor') matlabpool close EOF
tomlab
We have a TOMLAB license. To start it up:
- launch matlab r2013a
- cd to /farmshare/software/non-free/MATLAB-R2013a/tomlab
- startup
example session:
'/tmp/highlight.css' was not created by highlight --fragment --syntax='m' --style-outfile='/tmp/highlight.css' (dir=/tmp)
You need to specify a language like this: <source lang="html">...</source>
Supported languages for syntax highlighting:
abap4, abc, abnf, actionscript, ada, agda, algol, ampl, amtrix, applescript, arc, arm, as400cl, ascend, asp, aspect, assembler, ats, autohotkey, autoit, avenue, awk, bat, bbcode, bcpl, bibtex, biferno, bison, blitzbasic, bms, bnf, boo, c, ceylon, charmm, chill, clean, clearbasic, clipper, clojure, clp, cobol, coldfusion, crk, csharp, css, d, dart, diff, dylan, ebnf, eiffel, erlang, euphoria, express, fame, felix, fortran77, fortran90, frink, fsharp, fx, gambas, gdb, go, graphviz, haskell, haxe, hcl, html, httpd, icon, idl, idlang, inc_luatex, informix, ini, innosetup, interlis, io, jasmin, java, js, jsp, ldif, lhs, lilypond, limbo, lindenscript, lisp, logtalk, lotos, lotus, lua, luban, make, maple, matlab, maya, mercury, miranda, mod2, mod3, modelica, moon, ms, mssql, mxml, n3, nasal, nbc, nemerle, netrexx, nice, nsis, nxc, oberon, objc, ocaml, octave, oorexx, os, oz, paradox, pas, pdf, perl, php, pike, pl1, plperl, plpython, pltcl, pov, pro, progress, ps, ps1, psl, pure, pyrex, python, q, qmake, qu, r, rebol, rexx, rnc, rpg, rpl, ruby, s, sas, scala, scilab, sh, small, smalltalk, sml, snmp, snobol, spec, spn, sql, squirrel, sybase, tcl, tcsh, tex, ts, tsql, ttcn3, txt, upc, vala, vb, verilog, vhd, xml, xpp, yaiff, yang, znn
Search the farmshare-discuss archives for posts about Matlab.