MATLAB: Difference between revisions
(separate cmd line usage from BYOL) |
(show license test, mention -nojvm and java.log files) |
||
Line 5: | Line 5: | ||
There are two main ways of using MATLAB on Compute Canada clusters. | There are two main ways of using MATLAB on Compute Canada clusters. | ||
<ol> | <ol> | ||
<li> Running MATLAB | <li> Running MATLAB directly. This approach requires you to have access to a MATLAB license. You may either: | ||
<ol style="list-style-type:lower-alpha"> | <ol style="list-style-type:lower-alpha"> | ||
<li>Bring your own license, which involves using a license you already have access to, typically owned by your institution, faculty, department or lab.</li> | <li>Bring your own license, which involves using a license you already have access to, typically owned by your institution, faculty, department or lab.</li> | ||
Line 23: | Line 23: | ||
Accessing your campus license for MATLAB from a Compute Canada cluster requires some technical configuration. Specifically, the license server on your campus must be reachable by our compute nodes. This will require our technical team to get in touch with the technical people managing your license software. For some campuses, this has already been done. If so, when you load the MATLAB module and try a test such as the one below, it should find a license automatically. If this is not the case, please write to [[Technical support | technical support]], so that we can arrange this for you. | Accessing your campus license for MATLAB from a Compute Canada cluster requires some technical configuration. Specifically, the license server on your campus must be reachable by our compute nodes. This will require our technical team to get in touch with the technical people managing your license software. For some campuses, this has already been done. If so, when you load the MATLAB module and try a test such as the one below, it should find a license automatically. If this is not the case, please write to [[Technical support | technical support]], so that we can arrange this for you. | ||
== Running MATLAB | === Test your license arrangement === | ||
[name@cluster ~]$ module load matlab/2018a | |||
[name@cluster ~]$ matlab -nodisplay -nojvm -r "fprintf('%s\n', license()); exit" | |||
< M A T L A B (R) > | |||
Copyright 1984-2018 The MathWorks, Inc. | |||
R2018a (9.4.0.813654) 64-bit (glnxa64) | |||
February 23, 2018 | |||
For online documentation, see http://www.mathworks.com/support | |||
For product information, visit www.mathworks.com. | |||
987654 | |||
[name@cluster ~]$ | |||
== Running MATLAB directly == | |||
<!--T:4--> | <!--T:4--> | ||
'''Important:''' | '''Important:''' Any MATLAB calculation larger than a short test job of, say, 5 minutes, must be submitted to the scheduler. For instructions on using the scheduler, please see the [[Running jobs]] page. | ||
<!--T:14--> | <!--T:14--> | ||
Line 59: | Line 74: | ||
Remove the <code>-singleCompThread</code> option if you have requested | Remove the <code>-singleCompThread</code> option if you have requested | ||
more than one core with <code--cpus-per-task</code>. | more than one core with <code>--cpus-per-task</code>. | ||
For further information on the command line options <code>-nodisplay</code>, <code>-singleCompThread</code>, and <code>-r</code>, | You should also ensure that the size of your MATLAB [https://www.mathworks.com/help/distcomp/parpool.html parpool] | ||
matches the number of cores you requested. | |||
Each time you run MATLAB it will create a file like <code>java.log.12345</code> unless you supply the <code>-nojvm</code> option. | |||
However, using <code>-nojvm</code> may interfere with certain plotting functions. | |||
For further information on the command line options <code>-nodisplay</code>, <code>-singleCompThread</code>, | |||
<code>-nojvm</code>, and <code>-r</code>, | |||
see [https://www.mathworks.com/help/matlab/ref/matlablinux.html matlab (Linux)] on the Mathworks web site. | see [https://www.mathworks.com/help/matlab/ref/matlablinux.html matlab (Linux)] on the Mathworks web site. | ||
== Using the MATLAB Compiler Runtime libraries == <!--T:5--> | |||
== Using the MATLAB Compiler Runtime libraries == | |||
<!--T:5--> | |||
You can also compile your code using the MATLAB compiler, included among the Compute Canada-hosted modules. See documentation for the Compiler at the [https://www.mathworks.com/help/compiler/index.html MathWorks] website. Here is an example MATLAB file function. | You can also compile your code using the MATLAB compiler, included among the Compute Canada-hosted modules. See documentation for the Compiler at the [https://www.mathworks.com/help/compiler/index.html MathWorks] website. Here is an example MATLAB file function. | ||
Revision as of 17:59, 27 September 2018
Using MATLAB on Compute Canada clusters
There are two main ways of using MATLAB on Compute Canada clusters.
- Running MATLAB directly. This approach requires you to have access to a MATLAB license. You may either:
- Bring your own license, which involves using a license you already have access to, typically owned by your institution, faculty, department or lab.
- Run MATLAB on Cedar, which has a license available for any student, professor or academic researcher.
- Running a compiled MATLAB application. This method requires compiling your code into a binary using the MATLAB compiler (mcc). You can then run that binary executable using the appropriate MATLAB Runtime.
More details about these approaches are provided below.
Bringing your own license
Compute Canada is a hosting provider for MATLAB. This means that we have MATLAB installed on our clusters and can provision access to MATLAB by allowing you to bring your own license from your institution and run computations on our infrastructure. In general, any license can be used on our clusters. For any questions regarding additional usage of your license outside of your campus, we encourage you to contact the system administrator at your institution or MathWorks account manager.
Accessing your campus license for MATLAB from a Compute Canada cluster requires some technical configuration. Specifically, the license server on your campus must be reachable by our compute nodes. This will require our technical team to get in touch with the technical people managing your license software. For some campuses, this has already been done. If so, when you load the MATLAB module and try a test such as the one below, it should find a license automatically. If this is not the case, please write to technical support, so that we can arrange this for you.
Test your license arrangement
[name@cluster ~]$ module load matlab/2018a [name@cluster ~]$ matlab -nodisplay -nojvm -r "fprintf('%s\n', license()); exit" < M A T L A B (R) > Copyright 1984-2018 The MathWorks, Inc. R2018a (9.4.0.813654) 64-bit (glnxa64) February 23, 2018 For online documentation, see http://www.mathworks.com/support For product information, visit www.mathworks.com. 987654 [name@cluster ~]$
Running MATLAB directly
Important: Any MATLAB calculation larger than a short test job of, say, 5 minutes, must be submitted to the scheduler. For instructions on using the scheduler, please see the Running jobs page.
A simple SLURM script that you can use to submit a matlab script example, named cosplot.m - see the section below, is as follows:
#!/bin/bash -l
#SBATCH --job-name=matlab_test
#SBATCH --account=def-someprof # adjust this to match the accounting group you are using to submit jobs
#SBATCH --time=0-03:00 # adjust this to match the walltime of your job
#SBATCH --nodes=1
#SBATCH --ntasks=1
#SBATCH --cpus-per-task=1 # adjust this if you are using parallel commands
#SBATCH --mem=4000 # adjust this according to your the memory requirement per node you need
#SBATCH --mail-user=you@youruniversity.ca # adjust this to match your email address
#SBATCH --mail-type=ALL
# Load the appropriate matlab module
module load matlab/2018a
# Remove -singleCompThread if you are using parallel commands
srun matlab -nodisplay -singleCompThread -r "cosplot"
You can then submit the job using the usual sbatch command as follows:
[name@server ~]$ sbatch matlab_slurm.sl
Remove the -singleCompThread
option if you have requested
more than one core with --cpus-per-task
.
You should also ensure that the size of your MATLAB parpool
matches the number of cores you requested.
Each time you run MATLAB it will create a file like java.log.12345
unless you supply the -nojvm
option.
However, using -nojvm
may interfere with certain plotting functions.
For further information on the command line options -nodisplay
, -singleCompThread
,
-nojvm
, and -r
,
see matlab (Linux) on the Mathworks web site.
Using the MATLAB Compiler Runtime libraries
You can also compile your code using the MATLAB compiler, included among the Compute Canada-hosted modules. See documentation for the Compiler at the MathWorks website. Here is an example MATLAB file function.
function cosplot()
% MATLAB file example to approximate a sawtooth
% with a truncated Fourier expansion.
nterms=5;
fourbypi=4.0/pi;
np=100;
y(1:np)=pi/2.0;
x(1:np)=linspace(-2.0*pi,2*pi,np);
for k=1:nterms
twokm=2*k-1;
y=y-fourbypi*cos(twokm*x)/twokm^2;
end
%(The following commands for generating graphics output work
% with MATLAB 7 on glacier but produce empty plots with MATLAB 6
% on some other clusters.)
plot(x,y)
print -dpsc matlab_test_plot.ps
quit
end
To compile it, you would use the command
[name@yourserver ~]$ mcc -m -R -nodisplay cosplot.m
This will produce a binary named cosplot, as well as a wrapper script. To run the binary on Compute Canada servers, you will only require the binary. The wrapper script, named run_cosplot.sh, will not work as is on our servers, because MATLAB assumes that some libraries can be found in specific locations. Instead, we provide a different wrapper script, called run_mcr_binary.sh which sets the correct paths.
On one of our servers, load an MCR module corresponding to the MATLAB version you used to build the executable:
[name@server ~]$ module load mcr/R2018a
Run the following command:
[name@server ~]$ setrpaths.sh --path cosplot
then use your binary as so:
[name@server ~]$ run_mcr_binary.sh cosplot
You will only need to run the setrpaths.sh command once for each compiled binary. The run_mcr_binary.sh will instruct you to run it if it detects that it has not been done.
Important: Like any other intensive job, you must always run MCR code within a job that you will have submitted to the scheduler. For instructions on using the scheduler, please see the Running jobs page.