#!/bin/bash
#SBATCH --job-name namd
#SBATCH --ntasks=32
#SBATCH --time 24:00:00
#SBATCH --error=error.log
#SBATCH --output=output

# choose version of NAMD to use
VERSION=2.12
NAMD_DIR=/share/apps/namd/${VERSION}

# generate NAMD nodelist
for n in `echo $SLURM_NODELIST | scontrol show hostnames`; do
  echo "host ${n} ++shell ssh" >> nodelist.${SLURM_JOBID}
done

# total tasks
#PPN=`expr $SLURM_NTASKS_PER_NODE`
#P=`expr $(($PPN * $SLURM_NNODES))`

P=`expr $SLURM_NTASKS`

# execute
##################################################################
#CONFIG: change this
jobcfg=Equil.namd
jobout=equil.log
#END CONFIG
##################################################################

${NAMD_DIR}/charmrun ${NAMD_DIR}/namd2 +p ${P} ++nodelist nodelist.${SLURM_JOBID} +isomalloc_sync ${jobcfg} >& ${jobout} 

rm nodelist.${SLURM_JOBID}
