Skip to content

Instantly share code, notes, and snippets.

@zkamvar
Last active March 18, 2020 15:15
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save zkamvar/3d1fa899db5eecb1295de4cd84052a7b to your computer and use it in GitHub Desktop.
Example SLURM script that records memory, time, and job id
FILES := file1.out \
file2.out \
file3.out \
file4.out \
file5.out \
file6.out \
file7.out \
file8.out \
file9.out
DIRS := $(basename $(FILES))
ROOT_DIR := $(strip $(shell echo $$WORK/$$(basename $$(pwd))))
.PHONY : all
all: $(FILES)
.PHONY : clean
clean :
$(RM) $(FILES)
$(RM) -r RUN
RUN :
-mkdir $@
%.out : %.txt RUN
sbatch \
-J $* \
-o $(ROOT_DIR)/RUN/$*.out \
-e $(ROOT_DIR)/RUN/$*.err \
run.sh $< $@
#!/usr/bin/env bash
#
# Set job time
#SBATCH --time=04:00:00
#
# Set array job range (0 to number of commands in cmd file (minus 1)) and concurrency (%N)
#SBATCH --array=0-0%1000
#
# Set memory requested and max memory
#SBATCH --mem=4gb
#
# Request some processors
#SBATCH --cpus-per-task=1
#SBATCH --ntasks=1
#
# -----------------------------------------------------------------------------
# This file makes a copy of one file to another on a SLURM Array.
#
# -----------------------------------------------------------------------------
#
#
if [ $# -lt 2 ]; then
echo
echo "Run a file"
echo
echo
echo "This script takes a file in and copies it to out"
echo
echo "Usage:"
echo
echo " sbatch -J JOBNAME \\"
echo " -o PATH/TO/outfile.out \\"
echo " -e PATH/TO/errorfile.err \\"
echo " run.sh <in> <out>"
echo
exit
fi
IN=$1
OUT=$2
CMD="cp $IN $OUT"
# Run the command through time with memory and such reporting.
# warning: there is an old bug in GNU time that overreports memory usage
# by 4x; this is compensated for in the SGE_Plotdir script.
TIME='/usr/bin/env time -f " \\tFull Command: %C \\n\\tMemory (kb): %M \\n\\t# SWAP (freq): %W \\n\\t# Waits (freq): %w \\n\\tCPU (percent): %P \\n\\tTime (seconds): %e \\n\\tTime (hh:mm:ss.ms): %E \\n\\tSystem CPU Time (seconds): %S \\n\\tUser CPU Time (seconds): %U " '
# Write details to stdout
echo " Job: $SLURM_ARRAY_JOB_ID"
echo
echo " Started on: " `/bin/hostname -s`
echo " Started at: " `/bin/date`
echo $CMD
eval $TIME$CMD # Running the command.
echo " Finished at: " `date`
echo
# End of file
@zkamvar
Copy link
Author

zkamvar commented Sep 1, 2017

To run:

# generate files
for i in {1..9}; do printf "Hello from file $i\!\n" > file$i.txt; done
# run make
make

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment