Skip to content

Commit

Permalink
Update atlas-bash-util to set time for SLURM job if specified (#35)
Browse files Browse the repository at this point in the history
* Update atlas-slurm adds time from command

* Update slurm.sh

* Update atlas-slurm

* Update README.md

* Update VERSION

---------

Co-authored-by: Pedro Madrigal <[email protected]>
  • Loading branch information
anilthanki and pmb59 authored Jul 26, 2024
1 parent 6833072 commit 6d65292
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 15 deletions.
7 changes: 4 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -163,10 +163,11 @@ Usage:

```
./slurm/atlas-slurm -h
Usage: ./slurm/atlas-slurm [ -c <command string, mandatory field> ] \
Usage: ./atlas-slurm [ -c <command string, mandatory field> ] \
[ -w <working directory, mandatory field> ] \
[ -m <memory in MB or in the format <size>[units], defaults to cluster default. Different units can be specified using the suffix [K|M|G|T]> ] \
[ -p <number of cores, defaults to cluster default> ] \
[ -t <allocated maxtime, defaults to max allowed time for queue/partition. SLURM accepted format> ]
[ -j <job name, defaults to cluster default> ] \
[ -g <job group name, defaults to cluster default> ] \
[ -l <log prefix, no logs written by default> ] \
Expand All @@ -175,12 +176,12 @@ Usage: ./slurm/atlas-slurm [ -c <command string, mandatory field> ] \
[ -o <with -l, print standard output content? Defaults to no> ] \
[ -s <monitor style: 'status' for job status updates on polling, 'std_out_err' to report ongoing content of logs (where used). Defaults to std_out_err> ] \
[ -f <poll frequency in seconds if job is monitored. Defaults to 10.> ] \
[ -q <slurm queue, defaults to cluster default> ] \
[ -q <slurm queue/partition, defaults to cluster default> ] \
[ -u <suppress logging output? Default: no> ] \
[ -v <name of the conda environment in which to run the job> ]
```
Here, command (`-c`) and working directory (`-w`) are mandatory field for `atlas-slurm`. Specifying memory (`-m`) is advised, if memory is not specified with `-m` flag (e.g. `-m 1G`), it will use 4000Mb by default. If queue/partition is not specified it will use production by default.
Here, command (`-c`) and working directory (`-w`) are mandatory field for `atlas-slurm`. Specifying memory (`-m`) is advised, if memory is not specified with `-m` flag (e.g. `-m 1G`), it will use 4000Mb by default. Specifying time (`-t`) is advised, if time is not specified with `-t` flag (e.g. `-t 1:00:00`), it will use max allowed time for the queue/partition by default. If queue/partition is not specified it will use production by default.

Here, CPU-time is a mandatory field for SLURM submission. It will allocate maximum allowed time for the partition/queue by default.

Expand Down
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0.2.7
0.2.8
17 changes: 15 additions & 2 deletions atlas-slurm
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ usageOpts="[ -c <command string, mandatory field> ] \
[ -w <working directory, mandatory field> ] \
[ -m <memory in MB or in the format <size>[units], defaults to cluster default. Different units can be specified using the suffix [K|M|G|T]> ] \
[ -p <number of cores, defaults to cluster default> ] \
[ -t <allocated maxtime, defaults to max allowed time for partition. SLURM accepted format > ] \
[ -j <job name, defaults to cluster default> ] \
[ -l <log prefix, no logs written by default> ] \
[ -e <clean up log files after monitored run? Defaults to no> ] \
Expand All @@ -28,6 +29,7 @@ commandString=
workingDir=
memory=
cores=
maxTime=
jobName=
queue=
logPrefix=
Expand All @@ -39,7 +41,7 @@ monitorStyle=std_out_err
prioritise=no
quiet=no

while getopts ":c:w:m:p:j:g:l:o:e:n:f:q:s:r:v:u:" o; do
while getopts ":c:w:m:p:t:j:g:l:o:e:n:f:q:s:r:v:u:" o; do
case "${o}" in
c)
commandString=${OPTARG}
Expand All @@ -53,6 +55,9 @@ while getopts ":c:w:m:p:j:g:l:o:e:n:f:q:s:r:v:u:" o; do
p)
cores=${OPTARG}
;;
t)
maxTime=${OPTARG}
;;
j)
jobName=${OPTARG}
;;
Expand Down Expand Up @@ -103,13 +108,21 @@ if [[ ! -d "${workingDir}" ]]; then
mkdir -p "$workingDir" || die "Failed to create directory: $workingDir"
fi

if [ -z "$queue" ]; then
queue="production"
fi

if [ -z "$maxTime" ]; then
maxTime=$(slurm_maxtime_for_partition "$queue")
fi

# Submit the jobs
# if [ -n "${workingDir}/${logPrefix}.out" ]; then
# jobStdout="${workingDir}/${logPrefix}.out"
# jobStderr="${workingDir}/${logPrefix}.err"
# rm -rf $jobStdout $jobStderr
# fi
slurmJobId=$(slurm_submit "$commandString" "$queue" "$jobName" "$memory" "$cores" "$workingDir" "$logPrefix" "$prioritise" "$condaEnv" "$quiet")
slurmJobId=$(slurm_submit "$commandString" "$queue" "$jobName" "$memory" "$cores" "$maxTime" "$workingDir" "$logPrefix" "$prioritise" "$condaEnv" "$quiet")
submitStatus=$?

if [ "$submitStatus" -ne "0" ] && [ -n "$slurmJobId" ]; then
Expand Down
16 changes: 7 additions & 9 deletions slurm.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,16 @@

slurm_submit(){
local commandString="$1"
local jobQueue="${2:-production}"
local jobQueue="${2}"
local jobName="$3"
local slurmMem="${4:-4000}"
local nThreads="$5"
local workingDir="$6"
local logPrefix="$7"
local prioritise="$8"
local condaEnv="${9}"
local quiet="${10:-'no'}"


maxTime=$(slurm_maxtime_for_partition "$jobQueue")
local maxTime="$6"
local workingDir="$7"
local logPrefix="$8"
local prioritise="$9"
local condaEnv="${10}"
local quiet="${11:-'no'}"

if [ -n "$jobQueue" ]; then jobQueue=" -p ${jobQueue}"; fi
if [ -n "$jobName" ]; then jobName=" -J ${jobName}"; fi
Expand Down

0 comments on commit 6d65292

Please sign in to comment.