#PBS -S /bin/sh
#PBS -N PathSer0.02
#PBS -l nodes=1:Other
#PBS -q OneL
#PBS -o PathSer0.02.batch-log
#PBS -j oe
#PBS -M Paul.Fleurat-Lessard@ens-lyon.fr
#PBS -m aeb


#!/bin/bash

home_dir=$PBS_O_WORKDIR
work_dir=$PBS_O_WORKDIR
Job=Test_Vasp_Serial
numb=run1

######################################
#
# you might have to change the following variables
#
######################################
#
# Where is Path.exe ??
#
PathExe=~/Programs/Carte/src/Path.exe
#
# Where is VASP ?
#
export VASP=/home/dloffred/VASP_SOURCES/Intel_P4/VASP46_CINEB
#
# Whre is mpirun ?
#
export MPIRUN=/usr/local/mpich-intel-090404/bin/mpirun
#
# Some libraries... 
#
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/opt/intel/fc/9.1.037/lib/:/opt/intel/cc/9.1.045/lib:/usr/lib:/opt/intel/mkl/8.1/lib/32
export PATH=/opt/intel/fc/9.1.037/bin/:/opt/intel/cc/9.1.045/bin/:$PATH:$HOME/bin:/usr/local/mpich-intel9/bin
export LD_RUN_PATH=$LD_RUN_PATH:/opt/intel/fc/9.1.037/lib/:/opt/intel/cc/9.1.045/lib
export MANPATH=$MANPATH:/opt/intel/fc/9.1.037/man/:/opt/intel/cc/9.1.045/man
export LANG=C
#
#Usually nothing has to be changed after this line
#
#################################################




#################################
#
# We create the machinefile
#
# even if it is not really needed for SERIAL calculations
#
#################################
nodes=`cat $PBS_NODEFILE`
nnodes=`wc $PBS_NODEFILE | awk '{print $1}'` 

confile=$home_dir/ip.$PBS_JOBID.conf
touch $confile
j="init"
for i in $nodes
do
if [ $j != $i ]
then echo "$i:1" >> $confile
else
	echo "vous calculez sur des noeuds smp"
fi
j=$i
done

#############################
#
#  We create the 'VaspExe' file that Path will use to run the
# actual VASP calculations of E and forces
#
#############################
cd $work_dir
echo "$MPIRUN -nolocal -machinefile $confile -np $nnodes $VASP > out_$numb" >  ./RunVasp
chmod u+x ./RunVasp

###############################
#
# We launch PATH
#
###############################
ln -s ${PathExe} .

./Path.exe ${Job}.path &> ${Job}.out
 
