slurm-jobscript.sh 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. #!/bin/bash
  2. #SBATCH --nodes=4 # num of dpnodes
  3. #SBATCH --ntasks-per-node=3 # combination of num dpnodes and workers per node (should be one more than num workers per node)
  4. #SBATCH --gres=gpu:2 # number of GPUs per node (should be one less than the num tasks per node)
  5. #SBATCH --mem=60G # mem per node
  6. #SBATCH --time=0-00:20 # max time (DD-HH:MM)
  7. #
  8. # Usage: sbatch slurm-jobscript.sh N_file data_output_dir cudadl_path
  9. # Example: sbatch slurm-jobscript.sh $HOME/N/N_70 $HOME/data $HOME/code/cudadl
  10. #
  11. TEMP_NFS_DIR="$HOME/controller_loc"
  12. PROBLEM_FILE="$1"
  13. SAVE_OUTPUT_DIR="$2"
  14. CUDADL_PATH="$3"
  15. #
  16. ##################################################################
  17. #
  18. NUM_DPNODES="$SLURM_JOB_NUM_NODES"
  19. NUM_WORKERS="$(( SLURM_JOB_NUM_NODES*(SLURM_NTASKS_PER_NODE-1) ))"
  20. MEM_PER_DPNODE="$(( SLURM_MEM_PER_NODE/1024 ))" # SLURM_MEM_PER_NODE will be in MB and we want GB
  21. #
  22. if [[ ! -e "$TEMP_NFS_DIR" ]]; then
  23. mkdir "$TEMP_NFS_DIR"
  24. elif [[ ! -d "$TEMP_NFS_DIR" ]]; then
  25. echo "$TEMP_NFS_DIR already exists but is not a directory" 1>&2
  26. exit 1
  27. fi
  28. #
  29. if [[ ! -e "$SAVE_OUTPUT_DIR" ]]; then
  30. mkdir "$SAVE_OUTPUT_DIR"
  31. elif [[ ! -d "$SAVE_OUTPUT_DIR" ]]; then
  32. echo "$SAVE_OUTPUT_DIR already exists but is not a directory" 1>&2
  33. exit 1
  34. fi
  35. #
  36. SAVE_OUTPUT_DIR="$SAVE_OUTPUT_DIR/$SLURM_JOB_ID"
  37. mkdir "$SAVE_OUTPUT_DIR" || exit 1
  38. #
  39. TEMP_NFS_FILE=$(mktemp -u "${TEMP_NFS_DIR}/loc.XXXXXXXXXX")
  40. #
  41. echo "Starting with $NUM_DPNODES dpnodes ($MEM_PER_DPNODE GB memory) and $NUM_WORKERS workers."
  42. #
  43. srun ${CUDADL_PATH}/slurm-wrapper.sh $SAVE_OUTPUT_DIR $TEMP_NFS_FILE $CUDADL_PATH -w $NUM_WORKERS -n $NUM_DPNODES -m $MEM_PER_DPNODE $PROBLEM_FILE 1