From 696bdc910b25d7b3be789a3a1bd57fe76c769fb5 Mon Sep 17 00:00:00 2001 From: Matthew K Defenderfer <mdefende@uab.edu> Date: Fri, 30 Aug 2024 11:42:45 -0500 Subject: [PATCH] add help, usage, default values, and more robust option handling --- src/submit-pol-job | 125 +++++++++++++++++++++++++++++++++++++++------ 1 file changed, 110 insertions(+), 15 deletions(-) diff --git a/src/submit-pol-job b/src/submit-pol-job index 4af941f..a53b285 100755 --- a/src/submit-pol-job +++ b/src/submit-pol-job @@ -1,23 +1,118 @@ #!/bin/bash -# schedule a policy run on gpfs - -outdir=$1 -policy=$2 -nodes=$3 -cores=$4 -ram=$5 -partition=$6 -filesystem=${7:-scratch} -time=${8:-60} -outfile=${9} - -DIR=$outdir POLICYFILE=$policy FILESYSTEM=${filesystem} OUTFILE=${outfile} && \ +set -euxo pipefail + +############################################################ +# Default Values # +############################################################ + +nodes=1 +ntasks=16 +mem_per_cpu="8G" +time="24:00:00" +partition="amd-hdr100,medium" +outdir="/data/rc/gpfs-policy/data" +policy="./policy/list-path-external" + +############################################################ +# Help # +############################################################ +usage() +{ +>&2 cat << EOF +Usage: $0 [ -h ] [ -o | --outdir ] [ -f | --outfile ] [ --with-dirs ] + [ -N | --nodes ] [ -n | --ntasks ] [ -p | --partition] + [ -t | --time ] [ -m | --mem-per-cpu ] + device +EOF +exit 1 +} + +help() +{ +>&2 cat << EOF +Wraps the run-mmpol.sh script for applying a policy file. Must be run directly +as root or via the run-submit-pol-job.py script. The default policy file is +./policy/list-path-external + +Usage: $0 [ -h ] [ -o | --outdir ] [ -f | --outfile ] [ --with-dirs ] + [ -N | --nodes ] [ -n | --ntasks ] [ -p | --partition ] + [ -t | --time ] [ -m | --mem ] + device + +options: + -h|--help Print this Help. + +Required: + device GPFS fileset/directory apply the policy to. Can be + specified as either the name of the fileset or the + full path to the directory + (Examples: scratch, /data/user/[username]) + +Path: + -o|--outdir Parent directory to save policy output to + (default: /data/rc/gpfs-policy/data) + -f|--outfile Name of the policy output file + (default: "") + +Policy Options: + --with-dirs Change to ./policy/list-path-dirplus (default: False) + +sbatch options: + -N|--nodes Number of nodes to run the job on (default: 1) + -n|--ntasks Number of tasks (default: 16) + -p|--partition Partition to submit tasks to + (default: amd-hdr100,medium) + -t|--time Max walltime (default: 24:00:00) + -m|--mem-per-cpu RAM per task (default: 8G) +EOF +exit 0 +} + +args=$(getopt -a -o ho:f:N:n:p:t:m: --long help,outdir:,outfile:,with-dirs,nodes:,ntasks:,partition:,time:,mem: -- "$@") + +if [[ $? -gt 0 ]]; then + usage +fi + +eval set -- ${args} + +while : +do + case $1 in + -h | --help) help ;; + -o | --outdir) outdir=$2 ; shift 2 ;; + -f | --outfile) outfile=$2 ; shift 2 ;; + --with-dirs) policy="./policy/list-path-dirplus" ; shift 1 ;; + -N | --nodes) nodes=$2 ; shift 2 ;; + -n | --ntasks) ntasks=$2 ; shift 2 ;; + -p | --partition) partition=$2 ; shift 2 ;; + -t | --time) time=$2 ; shift 2 ;; + -m | --mem-per-cpu) mem_per_cpu=$2 ; shift 2 ;; + --) shift; break ;; + *) >&2 echo Unsupported option: $1 + usage ;; + esac +done + +if [[ $# -eq 0 ]]; then + usage +fi + +device="$1" + +# Ensure gpfs_logdir is set +if [[ -z "$device" ]]; then + echo "Error: Specify either the name of a fileset or a directory path" + usage +fi + +DIR=$outdir POLICYFILE=$policy FILESYSTEM=${device} OUTFILE=${outfile} && \ DIR=$DIR POLICYFILE=$POLICYFILE FILESYSTEM=${FILESYSTEM} OUTFILE=${OUTFILE} \ sbatch \ -N $nodes \ - -c $cores \ + -n $ntasks \ -t $time \ - --mem-per-cpu=$ram \ + --mem-per-cpu=$mem_per_cpu \ -p $partition \ ./run-mmpol.sh -- GitLab