MATLAB¶
MATLAB is a high-level technical computing language and interactive environment for algorithm development, data visualization, data analysis, and numeric computation.
License¶
MATLAB is proprietary software that requires a valid license to use It is freely available for academic use. CSC provides the following licenses, shared between all users, for academic use:
A network license 1766@license4.csc.fi provides the following academic licenses for Roihu: 5 MATLAB, 2 Parallel Computing Toolbox, 500 MATLAB Parallel Server.
The academic license allows use only for affiliates, that is, staff and students, of Finnish higher education institutions.
A network license 1766@license10.csc.fi provides the following academic licenses for LUMI: 25 MATLAB, 25 Simulink, 25 Control System Toolbox, 25 Curve Fitting Toolbox, 25 Deep Learning Toolbox, 25 Global Optimization Toolbox, 25 Image Processing Toolbox, 25 Optimization Toolbox, 25 Parallel Computing Toolbox, 25 Signal Processing Toolbox, 25 Statistics and Machine Learning Toolbox, 25 Wavelet Toolbox.
The academic license allows use only for teaching and academic research at degree-granting institutes.
Info
If you are a user from a commercial company or research institute, you must bring and use your own commercial license. Please contact CSC Service Desk for further instructions.
Available¶
We offer three ways to use MATLAB on CSC supercomputers. The best choice depends on your needs.
-
MATLAB web application is best for interactive use. It works like the desktop version and it's available on Roihu-CPU and LUMI.
-
MATLAB command-line interface is good for basic interactive and batch work. Available on Roihu-CPU and LUMI.
-
MATLAB Parallel Server is best for batch computing. You send jobs from your local MATLAB to the Roihu supercomputer. Your local toolboxes work on the supercomputer too.
All options support MATLAB versions R2023b to R2026b.
MATLAB web application¶

We recommend using the web interface to use MATLAB interactively.
-
Start by logging into the web interface of the cluster you want to use: www.roihu.csc.fi or www.lumi.csc.fi.
-
Then press the MATLAB icon to choose the MATLAB web application.
-
In the submit form, select appropriate resources for your session. We recommend at least 8 GB of memory before launching the MATLAB application. The MATLAB web application by itself consumes around 4 GB of memory.
-
You will be presented with the MATLAB web application license GUI. Select Online License Manager to log in with your MathWorks credentials. If you don't have a MathWorks account, you need to create a MathWorks account with your university's or organization's email address. Alternatively, select Network License Manager to use a network license.
-
The MATLAB application takes a couple of minutes to load. Then press Connect to MATLAB and the web application will open.
Error
If you are trying to log in using MathWorks credentials, but the MATLAB license GUI automatically loads the CSC license server, you need to clear the cached credentials first. To do this:
- Open the Login node shell application in the web interface.
- Run the following command to remove the cached credentials:
MATLAB command-line interface¶
You can use the MATLAB command-line interface with your own license (recommended) using Login Named User or Online Licensing modes. Both will prompt for your MathWorks username and password. Use via Login Named User (LNU):
Use via Online Licensing (OLL):
Alternatively, you can use the license pointed to by the MLM_LICENSE_FILE environment variable's value, which defaults to the CSC-provided academic license.
You can also run MATLAB scripts using the batch mode as follows:
You can use a different license by setting the following environment variable before starting MATLAB:
MATLAB Parallel Server¶
To submit batch jobs to Roihu from MATLAB on your own computer, see MATLAB Parallel Server.
Computational threads and parallel computing toolbox¶
MATLAB's linear algebra operations, element-wise operations on large arrays, and built-in mathematical operations have built-in threading, which is controlled by maxNumCompThreads.
MATLAB typically sets it automatically to the correct value, even in Slurm jobs.
You can compare the effects of setting one versus two threads for matrix multiplication by running the following MATLAB script:
A = rand(1000, 1000);
% One thread
maxNumCompThreads(1);
t0 = tic;
B = A*A;
t1 = toc(t0);
% Two threads
maxNumCompThreads(2);
t2 = tic;
C = A*A;
t3 = toc(t2);
% Compare times
fprintf("One thread : %g\nTwo threads: %g\n", t1, t3);
We can also parallelize code in MATLAB using the high-level constructs from the Parallel Computing Toolbox.
Consider the following serial code that pauses for one second n times and measures the execution time:
The following serial execution should run for around two seconds:
We can parallelize the function using the parallel for-loop construct, parfor, as follows:
function t = funcParallel(n)
t0 = tic;
parfor idx = 1:n
pause(1);
end
t = toc(t0);
end
To run parallel code, we need to create a parallel pool using processes or threads and then run the parallel code. We can create a parallel pool using two processes and run the parallel code with the same argument as the serial version, but it should only take around one second:
function t = funcProcesses(n)
pool = parpool('Processes', n);
t = funcParallel(n);
delete(pool);
end
Here's the same using a parallel pool with threads:
function t = funcThreads(n)
pool = parpool('Threads', n);
t = funcParallel(n);
delete(pool);
end
It is also possible to use GPUs in MATLAB, but only Nvidia GPUs are supported.
We can query the available GPU devices and perform computation on the GPU as follows:
function C = funcGPU(n)
gpuDevice();
A_gpu = gpuArray(rand(n, n));
B_gpu = gpuArray(rand(n, n));
C_gpu = A_gpu * B_gpu;
C = gather(C_gpu);
end
Let's run the function:
Extending the MATLAB environment¶
CSC's MATLAB installation runs inside an Apptainer container.
If you need software that the installation does not provide, such as a Python interpreter, extra system libraries, or command-line tools that your MATLAB code calls, you can build your own container image on top of CSC's MATLAB image and use it with the matlab module.
Since MATLAB is available on Roihu-CPU, build the container on the Roihu-CPU login node or on a Roihu-CPU compute node. See Building container images for general instructions and best practices about building containers on CSC supercomputers.
Writing the definition file¶
We extend CSC's MATLAB image by using it as the base image of the container, that is, by bootstrapping from a local image. You can see the path of the image that a specific MATLAB version uses as follows:
The MATLAB image is built on Rocky Linux, thus we install software into it with the DNF package manager. Here is an example of installing the MATLAB engine for Python on top of the MATLAB image:
Bootstrap: localimage
From: /appl/soft/manual/general/x86_64/matlab/r2026a/matlab.sif
%post
# Install Python
dnf install -y python3.11 python3.11-pip
# Install MATLAB engine into a virtual environment
cd /opt
python3.11 -m venv venv
. venv/bin/activate
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/opt/matlab/bin/glnxa64
python3.11 -m pip install matlabengine
%environment
PATH=/opt/venv/bin:$PATH
LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/opt/matlab/bin/glnxa64
The matlabengine package must match the MATLAB version of the base image.
The %environment section makes the virtual environment and the MATLAB libraries available at runtime, so that python3 resolves to the Python of the virtual environment and import matlab.engine finds the MATLAB libraries.
Building the container¶
We build the container from the definition file (matlab.def) into a container image (matlab.sif) using fakeroot.
The MATLAB image is large, so build it on scratch (replace <project> with your project) and keep an eye on your quota:
The build takes a while because Apptainer has to copy and recompress the whole base image.
Using the custom container¶
Load the same MATLAB version that you used as the base image and point the MATLAB_SIF_IMAGE environment variable to your own image:
The MATLAB commands provided by the module now run inside your own image:
We can also run other software that we installed into the image using the matlab-apptainer-exec command:
For example, we can call MATLAB from Python using the MATLAB engine as follows:
Note that CSC updates the MATLAB images, for example, to apply patches to a MATLAB version. If the base image changes, you need to rebuild your own image to pick up the changes.


