#!/bin/bash
#PBS -N PDOS75-100
#PBS -q C
#PBS -j oe
#PBS -l nodes=8:ppn=16

ulimit -s unlimited
export OMP_NUM_THREADS=16
program=~/Work/alm/anphon/anphon

PPN=1
NP=8

#***********************************************************************************
NODELIST=`cat ${PBS_NODEFILE} | sort | uniq`
for node in ${NODELIST}
do
    FLAG_MPDPY=`ssh ${node} /bin/ps ux | /bin/grep python | /bin/grep mpd.py`

    if [ -n "${FLAG_MPDPY}" ]; then
	echo "mpd.py is already running on host" ${node}

	ssh ${node} mpdallexit
	FLAG_MPDPY=`ssh ${node} /bin/ps ux | /bin/grep python | /bin/grep mpd.py`
	if [ -z "${FLAG_MPDPY}" ]; then
	    echo "mpd.py on node" ${node} "was successfully killed."
	else 
	    echo "could not terminate mpd.py on node" ${node} 
	fi
    fi
done
#***********************************************************************************


cd ${PBS_O_WORKDIR}
mpdboot -n 8 -f ${PBS_NODEFILE}
mpiexec -ppn ${PPN} -np ${NP} ${program} input_phdos.txt > BGG_W202020_submit2.log3
mpdallexit
