#!/bin/bash

# check if on login node
HOST="$(hostname)"
if [[ $HOST = login* ]]; then
  echo "ERROR: No heavy computations on the login node!"
  exit 1
fi

# get the process rank
RANK=$PMI_RANK

# output node, rank, local id
echo "[ $(printf "%02u" $SLURM_NODEID) ] [ $(printf "%02u" $SLURM_PROCID) ] [ $(printf "%02u" $SLURM_LOCALID) ] "

# output more info
if [ $RANK -eq 0 ]; then
  sleep 25
  echo -e "
           user: $SLURM_JOB_USER
        account: $SLURM_JOB_ACCOUNT
   submitted at: $SLURM_SUBMIT_HOST
 submitted from: $SLURM_SUBMIT_DIR
         run at: $PWD
         job ID: $SLURM_JOB_ID
       job name: $SLURM_JOB_NAME
        cluster: $SLURM_CLUSTER_NAME
      partition: $SLURM_JOB_PARTITION
       run from: $SLURMD_NODENAME
      num nodes: $SLURM_JOB_NUM_NODES
 tasks per node: $SLURM_NTASKS_PER_NODE
      num tasks: $SLURM_NTASKS
     nodes used: $SLURM_JOB_NODELIST
  cpus per task: $SLURM_CPUS_PER_TASK
  job cpus used: $SLURM_JOB_CPUS_PER_NODE
  num processes: $SLURM_NPROCS
"
  scontrol show job --detail $SLURM_JOB_ID
fi

# exit the script with zero exit code
exit 0
