Created
January 23, 2020 22:18
-
-
Save mikerenfro/4d21fee5cd6c82b16e30c46fb2bf3226 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
if [ "${USER}" == "root" ]; then | |
USERNAME=$1 | |
else | |
USERNAME=$USER | |
fi | |
REQUESTED=525600000 | |
JOBID="" | |
# Identify smallest blocked job, it should be the next one to start | |
for line in $(squeue --noheader -t PD -u ${USERNAME} -o %i,%u,%c,%D,%r,%l | grep AssocGrpCPURunMinutesLimit); do | |
# echo $line | |
t_JOBID=$(echo $line | cut -d, -f1) | |
t_MINCPUS=$(echo $line | cut -d, -f3) | |
t_NODES=$(echo $line | cut -d, -f4) | |
t_TIME=$(echo $line | cut -d, -f6) | |
t_DAYS=$(echo $t_TIME | cut -d'-' -f1) | |
t_HRS=$(echo $t_TIME | cut -d'-' -f2 | cut -d: -f1) | |
t_MINS=$(echo $t_TIME | cut -d'-' -f2 | cut -d: -f2) | |
t_SECS=$(echo $t_TIME | cut -d'-' -f2 | cut -d: -f3) | |
t_DAYS=$((10#$t_DAYS)) | |
t_HRS=$((10#$t_HRS)) | |
t_MINS=$((10#$t_MINS)) | |
t_SECS=$((10#$t_SECS)) | |
t_REQ_MINUTES=$(( ${t_DAYS}*1440+${t_HRS}*60+${t_MINS}+${t_SECS}/60 )) | |
t_REQUESTED=$(( ${t_NODES}*${t_MINCPUS}*${t_REQ_MINUTES} )) | |
if [ ${t_REQUESTED} -lt ${REQUESTED} ]; then | |
# echo "Next job might be ${JOBID} (${t_REQUESTED} -lt ${REQUESTED})" | |
JOBID=${t_JOBID} | |
REQUESTED=${t_REQUESTED} | |
MINCPUS=${t_MINCPUS} | |
NODES=${t_NODES} | |
REQ_MINUTES=${t_REQ_MINUTES} | |
else | |
# echo "Next job won't be ${JOBID} (${t_REQUESTED} -ge ${REQUESTED})" | |
: | |
fi | |
done | |
if [ ! -z "${JOBID}" ]; then | |
echo "Next blocked job to run should be ${JOBID}, with ${REQUESTED} CPU-minute(s) requested" | |
else | |
echo "User ${USERNAME} has no blocked jobs" | |
exit 1 | |
fi | |
LIMIT_CURRENT=$(showuserlimits -u ${USERNAME} -l GrpTRESRunMins -s cpu | grep cpu | grep -v None | sed 's/,//g' | awk '{print $4, $8}') | |
LIMIT=$(echo ${LIMIT_CURRENT} | cut -d' ' -f1) | |
CURRENT=$(echo ${LIMIT_CURRENT} | cut -d' ' -f2) | |
FREE=$((${LIMIT}-${CURRENT})) | |
CPUS_USED=$(squeue --noheader -t R -u ${USERNAME} | awk '{print $7, "*", $8}' | paste -sd+ | bc) | |
DAYS=$(echo $TIME | cut -d'-' -f1) | |
HRS=$(echo $TIME | cut -d'-' -f2 | cut -d: -f1) | |
MINS=$(echo $TIME | cut -d'-' -f2 | cut -d: -f2) | |
SECS=$(echo $TIME | cut -d'-' -f2 | cut -d: -f3) | |
DAYS=$((10#$DAYS)) | |
HRS=$((10#$HRS)) | |
MINS=$((10#$MINS)) | |
SECS=$((10#$SECS)) | |
REQUESTED=$(( ${NODES}*${MINCPUS}*${REQ_MINUTES} )) | |
REQUIRED=$((${REQUESTED}-${FREE})) | |
START=$(( ${REQUIRED}/${CPUS_USED} )) | |
ESTIMATE=$(date --date="+${START} minutes" +"%a %b %d %H:%M %Z %Y") | |
echo "- Limit for running and queued jobs is ${LIMIT} CPU-minutes" | |
echo "- Running and pending jobs have ${CURRENT} CPU-minutes remaining" | |
echo "- Leaving ${FREE} CPU-minutes available currently" | |
echo "- Smallest blocked job, ${JOBID}, requested ${REQUESTED} CPU-minutes" | |
echo " (${MINCPUS} CPU(s) on ${NODES} node(s) for ${REQ_MINUTES} minute(s))" | |
echo "- Currently-running jobs release $((${CPUS_USED}*60)) CPU-minutes per hour of elapsed time" | |
echo "Estimated time for job ${JOBID} to enter queue is ${ESTIMATE}," | |
echo "if resources are available" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment