From Documentation
(Redirected from Using MATLAB)
Jump to: navigation, search
MATLAB
Description: MATLAB
SHARCNET Package information: see MATLAB software page in web portal
Full list of SHARCNET supported software


Introduction

For users at University of Waterloo(UW), Western University(UWO) and McMaster University, special provisions have been made for access to campus license resources for SHARCNET machines located at those respective sites (See details below). If you have access to the site license at your home institution, you may run MATLAB jobs by compiling your MATLAB code into executable binaries using MATLAB the compiler, mcc, and run the compiled code as regular jobs without further license check (see site specific section below for details).

MATLAB on Graham

MATLAB 2017a is available on Graham with modules. However, neither does SHARCNET nor Compute Canada hold a licence for users. Users need to have access to a valid licence in order run Matlab on Graham. Users may run Matlab on Graham using their campus site license subject to the agreement by the site license management at their home institutions. Please check the info at [CC MATLAB] and submit a ticket at help@sharcnet.ca for details.

To use matlab 2017a on Graham:

module load matlab/2017a

If you have your own licence, say, you have a licence file called mymatlab.lic and placed in the folder $HOME/licenses, you may use the following command to launch Matlab

matlab -c $HOME/licenses/mymatlab.lic

Several Matlab compiler runtime (MCR) versions are installed on Graham as well. User can run compiled (using mcc) Matlab code on Graham without license restriction. Please check the available version using 'module avail' command on the system.

Job Submission

Graham uses Slurm scheduler, which is different from the sq command used on other Sharcnet clusters.

The following is a job script, Matlab_job.sh, to run single MATLAB job using the Slurm job scheduler:

#!/bin/bash 
#SBATCH --ntasks=1                # number of cpu (1 for sequential matlab job)
#SBATCH --mem-per-cpu=2096M       # memory; default unit is megabytes 
#SBATCH --time=0-00:20            # time (DD-HH:MM) 
#SBATCH --input=matlab_test.m     # input file
#SBATCH --output=matlab_test.log  # output file
module load matlab/2017a 
srun matlab -nodisplay -nosplash -nojvm -singleCompThread

Change the script to be an executable file, then submit the job from the input file directory with

sbatch matlab_job.sh

For slurm scheduler on Graham, see Running Jobs

Western University Site License

Users from Western are covered under the Total Academic Headcount (TAH) licence. Western currently offers access to MATLAB, Simulink, and companion toolboxes. Western users who want to use MATLAB on SHARCNET systems under TAH must first have their Western ID registered with ITS by contacting us prior to every Thursday noon, so that their usernames can be registered by ITS on Friday.

Using MATLAB is restricted to goblin and kraken's bull nodes.

Version Selection

To use MATLAB, first load the module

module load matlab

Job Submission

Interactive job is discouraged. To run a MATLAB job, you must use sqsub command, with option -i matlab_script, e.g.

sqsub -q serial -r 1h -o my_matlab.out -i my_matlab_code.m matlab

To run MATLAB jobs on kraken, use the following command, note the option "-f bul" must be used so that the MATLAB jobs will run on bull nodes where MATLAB is licensed to UWO users

sqsub -q serial -f bul -r 1h -o my_matlab.out -i my_matlab_code.m matlab

Using Multicores

In order to use the parallel programming feature of MATLAB provides, one needs to submit jobs to the threaded queue. The following are sample commands

On goblin:

sqsub -q threaded -n 8 -r 1h -o my_matlab.out -i my_matlab_code.m /opt/sharcnet/local/matlab/R2015a/bin/matlab -nodisplay -nosplash -nojvm

On kraken:

sqsub -q threaded -n 8 -f bul -r 1h -o my_matlab.out -i my_matlab_code.m /opt/sharcnet/local/matlab/R2015a/bin/matlab -nodisplay -nosplash -nojvm

Note, for running multicores, one needs to use the absolute path with the three options shown above.

General Notes

MATLAB Compiler 'mcc'

If you need to run the same code for a number of jobs, i.e., serial farm jobs, you can compile your MATLAB code using 'mcc'. The command to compile code myprog.m will be

mcc -m -R ' -nosplash -nodisplay -nodesktop -nojvm -singleCompThread' myprog

This will create an executable file myprog and a script file run_myprog.sh. To see what other options mcc has, you may use command mcc -help.

To run the executable, you must load the GCC module 4.3 or newer. To resolve a possible conflict, you will need to unload the intel module as suggested when you attempted to load a GCC module:

module unload intel

and then load the GCC module

module load gcc/4.3.4

You can then run myprog as a serial job using sqsub.

sqsub -r 1.0h -o run_myprog.log ./run_myprog.sh [matlabroot] [arguments]

matlabroot is the path to local matlab such as /opt/sharcnet/local/matlab/R2010b

Help

Western users who want to run MATLAB on SHARCNET systems must have access to a valid licence. To use the Western site licence, one must make a request through SHARCNET ticket system (or email to help@sharcnet.ca) before Thursday noon.

If you see a license error, please open a ticket on the SHARCNET webportal submit ticket or contact the local staff for immediate attention.

University of Waterloo Site License

Users in UW who have access to UW MATLAB site license UW_IST can run standard MATLAB on orca, saw, mosaic.

Please note that UW IST has set up a MATLAB license cap on Sharcnet clusters, therefore each user is advised only to run a few jobs (<10?) at a time in order to let other users have a chance to run MATLAB jobs the same time .

Version Selection

UW MATLAB R2016b, R2015b, R2014a and R2012b are available on orca, mosaic and saw, user side PATH setting is not needed.

Job Submission

submit a job to the scheduler using sqsub

  • Prepare a job directory for matlab, i.e., /work/yourid/matlab.
  • Copy the sample executable and test files
cd /work/yourid/matlab 
cp ~jemmyhu/Matlab/uwmatlab .
cp ~jemmyhu/Matlab/matlab_test.m .
  • Using 'sqsub' to submit the job into the default serial queue, use 3GB memory for example
sqsub --mpp=3g -r 1.0d -o matlab_test.log -i matlab_test.m ./uwmatlab

the runscript 'uwmatlab' is simply one line command to run batch job on the cluster, i.e., for R2014a:

/opt/sharcnet/local/matlab/R2014a/bin/matlab -nodisplay -nosplash -nojvm -singleCompThread

A few simple examples can be found in

/home/jemmyhu/matlab/

Run interactive MATLAB jobs on mosaic

First, you can choose which MATLAB version to use and add it to your PATH, e.g., for R2016b, add the following line to the end of your .bash_profile file (this is a one time setting)

export PATH=/opt/sharcnet/local/matlab/R2016b/bin:$PATH

exit and login in again to check for the setting by typing 'which matlab', it should give

[jemmyhu@mos1:~] which matlab
/opt/sharcnet/local/matlab/R2016b/bin/matlab

Second, MATLAB window is a graphical application, each time when you login, you have to enable X11 forwarding (enable client X-Window) before login to Mosaic. If you login from a mac or linux client, you should add -Y to ssh. i.e.,

ssh -Y username@mosaic.sharcnet.ca 

There are two ways to run interactive MATLAB jobs on mosaic. One is to ssh to the dev-node mos1

ssh -Y mos1 

Run interactive matlab on mos1

[jemmyhu@mos1:~] matlab

The second way is to reserve a node for interactive jobs, you can submit a "sleep <seconds>" program to the gpu queue with no output file like this:

[jemmyhu@mos-login:~] sqsub -q gpu -f threaded -n 20 --gpp=1 --mpp=150g -r 10h -o /dev/null sleep 36000

This will reserve a full single node for 10 hours, and it runs the sleep command as a placeholder in the scheduler. The sleep command should be set to run for as long as your reservation is set - in this case, 60 seconds * 60 minutes * 10 hours = 36000.

Once the job starts running, you can use sqjobs to check which node the job is running:

[jemmyhu@mos-login:~] sqjobs
jobid queue state ncpus nodes time command
------ ----- ----- ----- ----- ---- -------
304617   gpu     R    20   mos5    208s sleep 36000


And then use ssh -Y to login to that node. Please be sure you add -Y before you login to that node.

[jemmyhu@mos-login:~] ssh -Y mos5
 
[jemmyhu@mos5:~] matlab

General Notes

MATLAB Compiler 'mcc'

The steps to use 'mcc' and run serial farming MATLAB jobs for UW site license on orca are

  • Set up the environments by adding the following two lines to your .bash_profile file, e.g., for R2014a
module load R2014a.mcr
export PATH=/opt/sharcnet/local/matlab/R2014a/bin:$PATH
export LD_LIBRARY_PATH=/opt/sharcnet/local/matlab/R2014a/runtime/glnxa64/:${LD_LIBRARY_PATH}

logout, then login to orca again

  • Compile your MATLAB code myprog.m on orca's Development Node (ssh to one of orc-dev1, orc-dev2, orc-dev3 or orc-dev4, then go to the directory where your *.m file exists), then run 'mcc' command
ssh orc-dev1
cd /work/yourid/matlab
mcc -m -R ' -nosplash -nodisplay -nodesktop -nojvm -singleCompThread' myprog
#for multiple .m files, use all in mcc
mcc -m -R ' -nosplash -nodisplay -nodesktop -nojvm -singleCompThread' cod21.m code2.m ...
  • Run myprog as a standard serial job using sqsub from login node, using 3GB memory.
sqsub --mpp=3g -r 1.0h -o run_myprog.log ./run_myprog.sh $mcrroot [arguments]

Helps

  • If you have any questions/concerns or see a license error, please open a ticket on the SHARCNET webportal submit ticket.

McMaster University Site Licence

For McMaster users who have contributed to the campus license pool, MATLAB is available on Wobbie, Iqaluk and Requin.

Version Selection

To use MATLAB, first load the module

module load matlab

Job Submission

To submit a MATLAB job, you must use sqsub command, with option -i matlab_script, e.g.

sqsub -q serial -r 1h -o my_matlab.out -i my_matlab_code.m matlab

General Notes

MATLAB Compiler 'mcc'

After 'module load matlab', you can compile your MATLAB code myprog.m with command

mcc -m -R '-nosplash,-nodisplay,-nodesktop,-nojvm,-singleCompThread' myprog

This will create an executable file myprog and a script file run_myprog.sh. To see what other options mcc has, you may use command mcc -help. You may wish to omit the "singleCompThread" if your code can effectively use multiple threads.

To run the executable, you must load the GCC module 4.3 or newer. To resolve a possible conflict, you will need to unload the default compiler module as suggested before you attempted to load a GCC module:

module unload pathscale

and then load the GCC module

module load gcc/4.3.4

You can then run myprog as a serial job using sqsub.

sqsub -r 1.0h -o run_myprog.log ./run_myprog.sh [matlabroot] [arguments]

matlabroot is the path to local matlab such as /opt/sharcnet/local/matlab/R2012b

Helps

  • MATLAB license access on Requin happens via a tunnel (since these machines are on SHARCNET's network, not the campus.) This tunnel can die sometimes - if you see a license error, open a ticket on the SHARCNET website submit ticket or email hahn@sharcnet.ca to get it fixed.

MATLAB for non-site license users

For users out of Western, Waterloo, and McMaster, you cannot run the regular MATLAB code at SHARCNET due to license restriction. If you really need to run MATLAB at SHARCNET, the alternatives are

MATLAB Compiler Runtime (MCR)

If your license includes MATLAB compiler, mcc (check the availability under matlabroot/bin/ on your local machine), you can compiler MATLAB codes to be standalone binary code on a Linux system. The standalone executable can be run using the MCR at SHARCNET without license requirement.

SHARCNET has R2012b, R2013b, R2014a, R2016a MCR installed on several systems. Because the version between your mcc and the MCR should match exactly, you have to load the correct version of MCR on SHARCNET clusters. The procedures are

1) compile your code, the mcc command is the same as explained above for the site license users, i.e.,

mcc -m -R ' -nosplash -nodisplay -nodesktop -nojvm -singleCompThread' myprog

2) copy the files generated by mcc to SHARCNET, e.g., your /work directory on SHARCNET cluster

3) module load the match version of MCR, you can add the module load line into your .bash_profile, e.g., for R2014a MCR, it is

module load matlab/R2014a.mcr

exit and login again to effect the change.

4) submit as a regular job to the queue on the cluster, or run directly from command line on a viz-workstation

sqsub -r 1.0h -o run_myprog.log ./run_myprog.sh  $mcrroot [arguments]

Use SHARCNET MATLAB PCT License

If you have a client side Parallel Computing Toolbox (PCT) license, and you can modify your code to make use of the Parallel Computing Toolbox (PCT), you can follow the instructions above for SHARCNET MATLAB PCT License to run MATLAB PCT code at SHARCNET without further license requirement.

Use Octave

Explained below

Running MATLAB Code with Octave

If you do not have a MATLAB license and you are not using any MATLAB specific functions or toolboxes, an alternative to run batch MATLAB jobs on SHARCNET is to use Octave[1]. To run a MATLAB code myprog.m, simply type command

octave myprog.m

To submit a job that takes no more than 30 minutes to run, use command

sqsub -q serial -o myprog.out -r 30m octave myprog.m

Octave's syntax is almost 99% compatible with MATLAB. Some minor modifications, however, might be necessary in some cases.

References

o The Mathworks Homepage
http://www.mathworks.com/

o Parallel Computing Toolbox Main
http://www.mathworks.com/products/parallel-computing/

o Submit Matlab Jobs to Sharcnet using Desktop Client
https://www.sharcnet.ca/help/index.php/Using_MATLAB