Skip to content

Instantly share code, notes, and snippets.

@adrienbernede
Created July 12, 2022 11:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save adrienbernede/7e0f57042fdb65d220061a8ef57b0c24 to your computer and use it in GitHub Desktop.
Save adrienbernede/7e0f57042fdb65d220061a8ef57b0c24 to your computer and use it in GitHub Desktop.
A minimal example of shared allocation between CI jobs on Gitlab (using Slurm)
##############################################################################
# Copyright (c) 2022, Lawrence Livermore National Security, LLC and RADIUSS
# project contributors. See the COPYRIGHT file for details.
#
# SPDX-License-Identifier: (MIT)
##############################################################################
# The allocation name must be unique
variables:
ALLOC_NAME: ${CI_PROJECT_NAME}_ci_${CI_PIPELINE_ID}
stages:
- allocate
- run
- release
.on_ruby:
tags:
- shell
- ruby
allocate_resources (on ruby):
extends: .on_ruby
variables:
GIT_STRATEGY: none
stage: allocate
script:
- salloc --partition=pdebug --time=10 --nodes=1 --cpus-per-task=36 --no-shell --job-name=${ALLOC_NAME}
run:1:
extends: .on_ruby
# With slum versions >= 20.11 it is mandatory to specify whether we want concurrent/overlapping jobs
variables:
SLURM_OVERLAP: 1
stage: run
script:
# Retrieving the allocation name in a separate shell is the uglier part
- export JOBID=$(squeue -h --name=${ALLOC_NAME} --format=%A)
# Allocation options here serve for scheduling inside the main allocation
- srun $( [[ -n "${JOBID}" ]] && echo "--jobid=${JOBID}" ) --time=1 --nodes=1 ./script
run:2:
extends: .on_ruby
variables:
SLURM_OVERLAP: 1
stage: run
script:
- export JOBID=$(squeue -h --name=${ALLOC_NAME} --format=%A)
- srun $( [[ -n "${JOBID}" ]] && echo "--jobid=${JOBID}" ) --time=1 --nodes=1 ./script
run:3:
extends: .on_ruby
variables:
SLURM_OVERLAP: 1
stage: run
script:
- export JOBID=$(squeue -h --name=${ALLOC_NAME} --format=%A)
- srun $( [[ -n "${JOBID}" ]] && echo "--jobid=${JOBID}" ) --time=1 --nodes=1 ./script
release_resources (on ruby):
variables:
GIT_STRATEGY: none
extends: .on_ruby
stage: release
script:
- export JOBID=$(squeue -h --name=${ALLOC_NAME} --format=%A)
- ([[ -n "${JOBID}" ]] && scancel ${JOBID})
# Releasing the allocation must be done even of pipeline failure.
when: always
#### script example for demo: ####
#
# #!/bin/bash
#
# echo "## START: $(date)"
# echo "This script is running on $(hostname)"
# echo "Let’s sleep for 3 seconds..."
# sleep 3
# echo "## END: $(date)"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment