Interactive work on the compute nodes

Learning objectives

  • Understand what an interactive session is

  • Understand why one may need an interactive session

  • How to work with an interactive session (single + multiple cores)

  • Run an interactive-friendly Python script

  • Run an interactive-unfriendly Python script

  • Gfx Launcher and On-demand desktop

Questions

  • Imagine you are developing a Python script in a line-by-line fashion. How to do so best?
    • Why not do so on the login node?

    • Why not do so by using sbatch?

  • What is the drawback of using an interactive node?

Compute allocations in this workshop

  • Pelle: uppmax2025-2-393

  • Kebnekaise: hpc2n2025-151

  • Cosmos: lu2025-7-106

  • Alvis: naiss2025-22-934

  • Tetralith: naiss2025-22-934

  • Dardel: naiss2025-22-934

Storage space for this workshop

  • Pelle: /proj/hpc-python-uppmax

  • Kebnekaise: /proj/nobackup/fall-courses

  • Cosmos: /lunarc/nobackup/projects/lu2025-17-52

  • Alvis: /mimer/NOBACKUP/groups/courses-fall-2025

  • Tetralith: /proj/courses-fall-2025

  • Dardel: /cfs/klemming/projects/supr/courses-fall-2005

Introduction

Some users develop Python code in a line-by-line fashion.

  • These users typically want to run a (calculation-heavy) script frequently, to test if the code works.

  • However, scheduling each new line is too slow, as it can take minutes (or sometimes hours) before the new code is run through the batch system.

  • Instead, there is a way to directly work with such code: use an interactive session.

Some other users want to run programs that (1) use a lot of CPU and memory, and (2) need to be persistent/available. One good example is Jupyter.

  • Running such a program on a login nodes would harm all other users on the login node.

  • Running such a program on a computer node using sbatch would not allow a user to connect to it.

  • In such a case: use an interactive session.

About Jupyter

  • For HPC2N, using Jupyter on HPC2N is possible, and can be done either from the OpenOnDemand portal (easy) or through a batch job and ThinLinc (harder).

  • For UPPMAX, using Jupyter is easy.

  • For LUNARC, using Jupyter (https://lunarc-documentation.readthedocs.io/en/latest/guides/applications/Python/#jupyter-lab) works best using the LUNARC HPC Desktop. Go to the Applications menu, hover over Applications - Python, and select Jupyter Lab from the menu that pops up to the right.

  • For NSC, using Jupyter is easiest done through ThinLinc, but can also be used via an SSH tunnel.

  • For PDC, you can use Jupyter easiest through the GfxLauncher in ThinLinc: https://support.pdc.kth.se/doc/login/interactive_hpc/

  • For C3SE, you can easiest use Jupyter through the OpenOnDemand portal.

In this session we will talk about

  • interactive/salloc/srun

  • Running a Python script interactively

  • Open-on-demand desktop

An interactive session is a session with direct access to a compute node. Or alternatively: an interactive session is a session, in which there is no queue before a command is run on a compute node.

You can find information about the cluster hardware in the Common section: https://uppmax.github.io/HPC-python/common/understanding_clusters.html

Any longer, resource-intensive, or parallel jobs must be run through a batch script or an interactive session.

  • Demanding work (CPU or Memory intensive) should be done on the compute nodes.

  • If you need live interaction you should start an “interactive session”

  • On Cosmos (LUNARC), Dardel (PDC), Alvis (C3SE), and Kebnekaise (HPC2N) it can be done graphically with the Desktop-On-Demand tool GfxLauncher or portal.

  • Otherwise the terminal approach will work in all centers.

The different way HPC2N, UPPMAX, LUNARC, NSC, PDC, and C3SE provide for an interactive session

Here we define an interactive session as a session with direct access to a compute node. Or alternatively: an interactive session is a session, in which there is no queue before a command is run on a compute node.

Some centers only offer command line interactive sessions, and some also have ways of providing graphicsal interactive sessions.

The way this differs between the centers (command line):

  • HPC2N: the user remains on a login node. All commands can be sent directly to the compute node using srun

  • UPPMAX: the user is actually on a computer node. Whatever command is done, it is run on the compute node

  • LUNARC: the user is actually on a computer node if the correct menu option is chosen. Whatever command is done, it is run on the compute node

  • NSC: the user is actually on a computer node if the correct menu option is chosen. Whatever command is done, it is run on the compute node

  • PDC: the user remains on a login node and can submit jobs to the compute node with srun or (recommended) the user login to the compute node with ssh after the job is allocated. Any commands are then run directly on the compute node.

  • C3SE: the user runs a shell on a compute node.

Start an interactive session

To start an interactive session, one needs to allocate resources on the cluster first.

The command to request an interactive node differs per HPC cluster:

Cluster

interactive

salloc

srun

GfxLauncher/OpenOnDemand portal

Tetralith (NSC)

Recommended

N/A

N/A

N/A

Dardel (PDC)

N/A

Recommended

N/A

Possible (GfxLauncher)

Alvis (C3SE)

N/A

N/A

Works

Recommended (OOD)

Kebnekaise (HPC2N)

N/A

Recommended

N/A

Recommended (OOD)

Pelle (UPPMAX)

Recommended

Works

N/A

N/A

Cosmos (LUNARC)

Works

N/A

N/A

Recommended (GfxLauncher)

Start an interactive session in the simplest way (command line)

To start an interactive session in the simplest way, as shown here:

The command interactive is recommended at NSC.

Use:

interactive -A [project_name] -t HHH:MM:SS

Where [project_name] is the NAISS project name, for example interactive -A naiss2025-22-934.

If you need more CPUs/GPUs, etc. you need to ask for that as well. The default which gives 1 CPU.

The output will look similar to this:

[x_birbr@tetralith3 ~]$ interactive -A naiss2025-22-403
salloc: Pending job allocation 44252533
salloc: job 44252533 queued and waiting for resources
salloc: job 44252533 has been allocated resources
salloc: Granted job allocation 44252533
salloc: Waiting for resource configuration
salloc: Nodes n340 are ready for job
[x_birbr@n340 ~]$

Note that the prompt has changed to show that one is on an interactive node.

Indeed, all you need at most of the centers, for command line interactivity, is the project name, as well as time - and also partition for PDC.

However, this simplest way may have some default settings that do not fit you.

  • session duration is too short

  • the session has too few cores available (default is usually 1)

  • or if you need GPUs

You can add more resources the same way as for batch jobs.

There is some information here: <https://uppmax.github.io/R-python-julia-matlab-HPC/python/interactivePython.html#start-an-interactive-session-in-a-more-elaborate-way>.

End an interactive session

You leave interactive mode with exit.

Check to be in an interactive session

For UPPMAX, LUNARC, C3SE, and NSC (and in some cases PDC)

You check if you are in an interactive session with:

hostname

If the output contains the words pelle, cosmos, tetralith, alvis or login you are on the login node.

If the output contains:

  • p[number].uppmax.uu.se, where [number] is a number, you are on a compute node at UPPMAX (pelle).

  • cn[number], where [number] is a number, you are on a compute node at LUNARC (cosmos).

  • n[number], where [number] is a number, you are on a compute node at NSC (tetralith).

  • nid[number], where [number] is a number, you are on a compute node at PDC (dardel).

  • alvis[number]-[other-number], where [number] is the login node you logged into (usually 2 or 3) and othernumber is a number, you are on a compute node at C3SE (alvis).

For HPC2N (and sometimes PDC)

You check if you are in an interactive session with:

srun hostname
  • If the output is b-cn[number].hpc2n.umu.se, where [number] is a number, you are more-or-less on a compute node at Kebnekaise.

  • If the output is b-an[number], where [number] is a number, you are still on a login node on Kebnekaise.

Do NOT do

hostname

for HPC2N as it will always show that you are on a login node

Check that the number of cores booked is correct

You can do this with

$ srun hostname

And then you will get one line of output per core booked.

Running a Python script in an interactive session

To run a Python script in an interactive session, first load the Python modules:

module load [python/version + any prerequisites]

Suggested versions (and prerequisites):

  • UPPMAX/pelle: Python/3.12.3-GCCcore-13.3.0

  • LUNARC/cosmos: GCC/13.2.0 Python/3.11.5 SciPy-bundle/2023.11

  • C3SE/Alvis: Python/3.11.3-GCCcore-12.3.0 OpenMPI/4.1.5-GCC-12.3.0 SciPy-bundle/2023.07-gfbf-2023a

  • NSC/tetralith: buildtool-easybuild/4.9.4-hpc71cbb0050 GCC/13.2.0 Python/3.11.5

  • PDC/dardel: cray-python/3.11.7

To run a Python script on 1 core, do:

python [my_script.py]

where [my_script.py] is the Python script (including the path if it is ot in the current directory), for example srun python ~/my_script.py.

To run a Python script on each of the requested cores, do:

srun python [my_script.py]

where [my_script.py] is the Python script (including the path if it is noth in the current directory), for example srun python ~/my_script.py.

Not all Python scripts are suitable for an interactive session. This will be demonstrated by two Python example scripts.

Our first example Python script is called sum-2args.py: it is a simple script that adds two numbers from command-line arguments:

import sys

x = int(sys.argv[1])
y = int(sys.argv[2])

sum = x + y

print("The sum of the two numbers is: {0}".format(sum))

Our second example Python script is called add2.py: it is a simple script that adds two numbers from user input:

# This program will add two numbers that are provided by the user

# Get the numbers
a = int(input("Enter the first number: "))
b = int(input("Enter the second number: "))

# Add the two numbers together
sum = a + b

# Output the sum
print("The sum of {0} and {1} is {2}".format(a, b, sum))

Exercise

  • Why is/is it not a good script for interactive?

  • Try start an interactive session and run the scripts.

Conclusion

Keypoints

You have:

  • learned a little about login nodes and compute nodes

  • seen how to use a compute node interactively, which differs between HPC2N, UPPMAX, LUNARC, C3SE, NSC, and PDC (particularly between HPC2N (and PDC) and the others)

  • checked if we are in an interactive session

  • checked if we have booked the right number of cores

  • run Python scripts in an interactive session, which differs between HPC2N and the others

  • seen that not all Python scripts can be run interactively on multiples cores

  • exited an interactive session