Chapter 9 Interactive Session
While using the cluster, you might need to build and test scripts interactively before running them. Luckily, you can work directly on the cluster by creating an interactive session. When you launch an interactive session, the cluster assigns you a portion of the networked computers called a “node”. This node (or part of one) is dedicated to you for a period of time rather than using the Slurm job submission system.
Because an interactive session takes up resources directly on the cluster whether you’re actively using it or not, it’s best to use interactive sessions only when a task cannot be done by submitting a script.
9.1 Starting the session
When starting an interactive session, you’re going to need to think about what you are testing and what resources you might need on the node you are requesting to use. You can always start an interactive session using the default values if you aren’t sure what you need yet.
Start an interactive session on a node by running the command:
grabnode
You will be prompted with several questions about the type of resources on the node you want. We don’t need anything fancy, so we will set up the session to use minimal resources. You can enter the following:
- How many CPUs/cores would you like to grab on the node? 1
- How much memory (GB) would you like to grab? 20
- Please enter the max number of days you would like to grab this node: 1
- Do you need a GPU? N
- When prompted, enter your password
You requested 1 CPU, 20GB of RAM, and don’t need a GPU. The GPU, or Graphics Processing Unit, is similar to the CPU. The GPU was originally designed to quickly render graphics (such as for video games), but today can be used to run complex artificial intelligence applications or computationally intensive jobs.
You will see that you are now logged on to the compute node “gizmo” instead of the login node “rhino”. Remember that the part of the cluster where you log in is called rhino
. The part of the cluster where jobs are run is called gizmo
.
9.2 Running Interactive Commands
You can start working on the node by running a similar command as we used in the job we submitted via script. Echo a message by running:
echo "Hello, again!"
9.3 Using Pre-installed Software Modules
Let’s get a bit more advanced. We can load a preconfigured software bundle called a module. This is very convenient because it means we don’t need to install anything manually! In this example, we will load a module containing R version 4.2.0. You can learn more about what modules are available and how to request new ones for the Fred Hutch cluster here.
ml fhR/4.2.0-foss-2021b
Next, launch R:
R
You can play around with R here. For example, you might run:
head(mtcars)
Close the R session by typing:
q()
R will ask if you want to save your workspace. Type n
for no and hit return.
Close the interactive node by typing:
exit
9.3.1 Loading Modules in non-interactive mode
You have just seen how to load in software modules in the interactive mode. When you launch a job via sbatch
to start computing on the compute nodes, you may also need to load in software modules. You can add the ml
command within your shell script, such as the following:
#!/bin/bash
ml fhR/4.2.0-foss-2021b
Rscript my_r_script.R
grabnode
This command starts an interactive session on the cluster.