#!/bin/bash -f

# example for 1 node 8 processors
#PBS -l nodes=8:ppn=8
#PBS -l walltime=124:0:0     
#PBS -W group_list=athena
#PBS -q athena_q
#PBS -A athena

#setenv SCRATCH /scratch/

# load modules
source /etc/profile.d/modules.sh
module load gcc intel/compiler intel/mkl openmpi/intel math/fftw/2.1.5

# change into your working directory
#cd working_dir
cd $PBS_O_WORKDIR

nprocs=`cat $PBS_NODEFILE | wc -l | sed "s/ //g"`

#start creating .machines
cat $PBS_NODEFILE > .machines_current
#cat $PBS_NODEFILE |cut -c1-6 >.machines_current
aa=`wc -l .machines_current | awk {'print $1'}`
echo '#' > .machines

# example for an MPI parallel lapw0 
echo -n 'lapw0:' >> .machines

i=1
while [ $i -lt $aa ]
do
echo -n `cat $PBS_NODEFILE |head -$i | tail -1` ' ' >>.machines
i=$(( $i + 1 ))
done
echo  `cat $PBS_NODEFILE |head -$i|tail -1` ' ' >>.machines

#example for k-point parallel lapw1/2
i=1
while [ $i -le $aa ]
do
echo -n '1:' >>.machines
head -$i .machines_current |tail -1 >> .machines
i=$(( $i + 1 ))
done
echo 'granularity:1' >>.machines
echo 'extrafine:1' >>.machines

#define here your WIEN2k command
#run_lapw -p -i 40 -fc 1. -I

