Matlab on the Grid
Compiling Matlab executables
As a quick example, create the file mcctest.m , which contains the following:
function mcctest |
Compile it using:
mcc85 -m mcctest.m |
You will end up with a number of files in that directory, including an “mcctest” binary, as well as a “run_mcctest.sh” script.
To run the binary, run:
./run_mcctest.sh /PATH/TO/MATLAB |
In this case, that would be:
./run_mcctest.sh /ad/eng/opt/matlab-8.5/ |
On other platforms, run “help mcc” from within Matlab for more information.
Note that you must test-run it once directly before qsub’bing it, so that the MCR cache can build without causing race conditions. (You don’t have to run it to completion — you can always ctrl-c out of it after it’s finished building the cache and has begun executing.)
Run in Batch
Now, to qsub the compiled executable, you would run:
qsub -cwd -b y “./run_mcctest.sh /ad/eng/opt/matlab-8.5/” |
Note that your mileage may vary with newer versions of MATLAB. In particular, the newest versions want to put the MCR cache in your home directory, where batch qsub jobs can’t find it. To get around this set the MCR_CACHE_ROOT variable to the directory you wish to have the MCR cache in (such as /mnt/nokrb/yourusername), as described here and here. You should also change the MATLAB_PREFDIR variable so that MATLAB doesn’t try to use a Kerberized directory within qsub.
Taken together you could use a wrapper script like the below and qsub that (or just embed the export commands inside run_mcctest.sh itself.)
#$ -cwd |
Run scripts in Matlab without compiling them
This should work equally well in all versions of Matlab, but be warned, it *does* grab a license for each instance that is executing! So if you run a hundred jobs, you could easily eat all available licenses and cause denial of service for people who are just trying to use Matlab on their desktop!
matlab -r mcctest -nodesktop -nojvm -nosplash |
This runs your .m file and exits Matlab at the end. Note that if you qsub this, the .o file contains EVERYTHING that Matlab outputs to text, including its little version splash at the beginning.
An example qsub script would be:
#$ -V export MATLAB_PREFDIR=/mnt/nokrb/$USER/MATLAB |
Using the script makes it so that you don’t have to put so many flags into the command line. You’ll see we put some commonly used flags (“-j y” for joining .o and .e files, -N for the name of the output files, -V for passing through all variables from the current running shell) directly into the script.
Using GPUs
If you are using MATLAB’s GPU features, make sure to specify “-l gpu=1” (or a higher number for multi-GPU codes) and use a queue that’s gpu-enabled. Remember you need to ask enghelp for permission to be added to these queues.
Links