Skip to content

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.

  1. MATLAB web application is best for interactive use. It works like the desktop version and it's available on Roihu-CPU and LUMI.

  2. MATLAB command-line interface is good for basic interactive and batch work. Available on Roihu-CPU and LUMI.

  3. 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

MATLAB web application

We recommend using the web interface to use MATLAB interactively.

  1. Start by logging into the web interface of the cluster you want to use: www.roihu.csc.fi or www.lumi.csc.fi.

  2. Then press the MATLAB icon to choose the MATLAB web application.

    • MATLAB OOD pinned apps
  3. 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.

    • MATLAB OOD form
  4. 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.

    • MATLAB license GUI
  5. 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:

  1. Open the Login node shell application in the web interface.
  2. Run the following command to remove the cached credentials:
    rm -rf "$HOME/.matlab/MWI"
    

MATLAB command-line interface

On Roihu-CPU, you can load the MATLAB module as follows:

module load matlab

On LUMI, you must add the module files under CSC's local directory to the module path before loading the module as follows:

module use /appl/local/csc/modulefiles
module load matlab

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):

matlab -nodisplay -licmode online

Use via Online Licensing (OLL):

matlab -nodisplay -licmode onlinelicensing

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:

matlab -batch <script>

You can use a different license by setting the following environment variable before starting MATLAB:

export MLM_LICENSE_FILE="port@mylicenseserver.com"

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:

compthreads.m
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:

funcSerial.m
function t = funcSerial(n)
t0 = tic;
for idx = 1:n
    pause(1);
end
t = toc(t0);
end

The following serial execution should run for around two seconds:

t_serial = funcSerial(2)

We can parallelize the function using the parallel for-loop construct, parfor, as follows:

funcParallel.m
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:

funcProcesses.m
function t = funcProcesses(n)
pool = parpool('Processes', n);
t = funcParallel(n);
delete(pool);
end
t_processes = funcProcesses(2)

Here's the same using a parallel pool with threads:

funcThreads.m
function t = funcThreads(n)
pool = parpool('Threads', n);
t = funcParallel(n);
delete(pool);
end
t_threads = funcThreads(2)

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:

funcGPU.m
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:

C = funcGPU(1000);

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:

module show matlab/r2026a

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:

matlab.def
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:

cd /scratch/<project>
apptainer build --fakeroot --bind="$TMPDIR:/tmp" matlab.sif matlab.def

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:

module load matlab/r2026a
export MATLAB_SIF_IMAGE=/scratch/<project>/matlab.sif

The MATLAB commands provided by the module now run inside your own image:

matlab -nodisplay

We can also run other software that we installed into the image using the matlab-apptainer-exec command:

matlab-apptainer-exec python3 --version

For example, we can call MATLAB from Python using the MATLAB engine as follows:

engine.py
import matlab.engine

eng = matlab.engine.start_matlab()
print(eng.sqrt(16.0))
eng.quit()
matlab-apptainer-exec python3 engine.py

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.

Do you find this page useful?
Thank you for your feedback!
Thank you! Your feedback is appreciated.

Please let us know how we could improve this page by contacting us or by creating an issue in GitHub. You can also edit this page yourself and contribute your improvements by creating a pull request.

November 5, 2026