Using HyperQueue and local disk to process many small files efficiently¶
In this tutorial you will learn
- How to run many short tasks within a single Slurm job using HyperQueue
- How to use the fast local disk when processing many small files
This tutorial is done on Roihu, which requires that:
- you have a user account at CSC.
- your account belongs to a project that has access to the Roihu service.
Overview¶
HyperQueue is a tool for efficient
sub-node task scheduling and is well suited for task farming and running
embarrassingly parallel jobs.
In this example, we have more than 4000 files which we want to convert to
another format.
- Each file contains a SMILES string (an ASCII notation encoding the two-dimensional structure of a molecule) which we want to convert into a three-dimensional coordinate format.
- The computational cost of each of the conversions is expected to be comparable.
- Since the workflow involves many small files, we will also demonstrate the usage of the fast local disk to avoid stressing the parallel file system.
The workflow of this exercise¶
- Download the files from Allas.
- Decompress the files to
$TMPDIR. - Convert each
.smifile to a three-dimensional.sdfmolecular file format. - Archive and compress the output files and move them back to
/scratch.
Download the input files¶
-
Create and enter a suitable scratch directory on Roihu (replace
<project>with your CSC project, e.g.project_2001234): -
Download the input files representing molecules initially obtained from the ChEMBL database:
Create a HyperQueue batch script¶
We will use Open Babel to convert the
SMILES strings into a three-dimensional
.sdf coordinate format.
Multiple files can be converted using the batch conversion mode of Open
Babel. For 4000+ files this would, however, take more than an hour.
Submitting each conversion as a separate Slurm job is also a bad idea, since
each conversion takes just a few seconds. Running many short jobs will degrade
the performance of the scheduler for all users.
HyperQueue is a program that allows
us to schedule sub-node tasks within a Slurm allocation. One can think of
HyperQueue as a "Slurm within a Slurm", or a so-called "meta-scheduler", which
allows us to leverage embarrassing parallelism without overloading Slurm by
looping
srun or sbatch commands.
-
Copy the following script into a file
hq.shusing, e.g.,nano:#!/bin/bash #SBATCH --partition=small #SBATCH --account=<project> # replace <project> with your CSC project, e.g. project_2001234 #SBATCH --nodes=1 #SBATCH --ntasks-per-node=1 #SBATCH --cpus-per-task=48 #SBATCH --time=00:10:00 # Required by openbabel module load gcc/15.2.0 module load openmpi/5.0.10 module load hyperqueue openbabel # Specify a location for the HyperQueue server export HQ_SERVER_DIR=${PWD}/hq-server-${SLURM_JOB_ID} mkdir -p "${HQ_SERVER_DIR}" # Start the server in the background (&) and wait until it has started hq server start & until hq job list &>/dev/null ; do sleep 1 ; done # Start the workers in the background and wait for them to start srun --exact --cpu-bind=none --mpi=none hq worker start --cpus=${SLURM_CPUS_PER_TASK} & hq worker wait "${SLURM_NTASKS}" # Extract the input files to the local disk and cd there tar -xf smiles.tar.gz -C $TMPDIR cd $TMPDIR/smiles # Submit each Open Babel conversion as a separate HyperQueue job for f in *.smi ; do hq submit --stdout=none --stderr=none obabel $f -O ${f%.*}.sdf --gen3d best & done # Wait for all jobs to finish, then shut down the workers and server hq job wait all hq worker stop all hq server stop # Archive and compress the output .sdf files and copy the package back to /scratch tar -czf sdf.tar.gz *.sdf cp sdf.tar.gz $SLURM_SUBMIT_DIR -
As explained by the comments in the script above, HyperQueue works on a worker-server-client basis, i.e. a worker is started on each compute node to execute commands that the client submitted to the server.
- This is in principle what Slurm also does, the only difference is that you need to start the server and workers yourself.
- In this example, 48 cores (⅛ of a Roihu node) are reserved for processing the files, meaning that 48 conversion commands will be running in parallel.
Ideally, the number of sub-tasks should be larger than the number that can run simultaneously on the reserved resources, so that the Slurm job is not too short.
-
Submit the script with:
-
After a short while, you should notice that a file
sdf.tar.gzcontaining the output files has appeared in your working directory.Question
How long did it take to convert all files?
If you want to monitor the progress of your HyperQueue jobs/tasks,
just set the location of the HyperQueue server and use the
hq commands
(see the official documentation for details).
Note that the HQ job/task IDs are not the same as the Slurm job ID!
module load hyperqueue
export HQ_SERVER_DIR=${PWD}/hq-server-<slurmjobid>
hq job list
hq job info <hqjobid>
hq job progress <hqjobid>
hq task list <hqjobid>
hq task info <hqjobid> <hqtaskid>
Remember to load the
hyperqueue module before running the commands
above from the terminal, otherwise you will get an error message
-bash: hq: command not found.
Also note that these commands are available only after your job has
started running.
To get a report of how your jobs/tasks completed and spot possible
failures, you could also run one of these commands in your batch script and
redirect the output to a file before shutting down the server.