#!/bin/tcsh
#$ -S /bin/tcsh
#
#$ -N W2web_Job
##$ -m ae
##$ -M xxx@mail.xx.yy
#
# MPIR_HOME from submitting environment
#$ -v MPIR_HOME
#
# needs in
#   $NSLOTS
#       the number of tasks to be used
#   $TMPDIR/machines
#       a valid machine file to be passed to mpirun
#
#$ -cwd
#$ -o job.out
#$ -e job.err
# mpich / jobs_per_node = number of nodes  
#$ -q  intelsupermicro.q
#$ -pe mpich 12
source ~/.cshrc

set mpijob=1
set jobs_per_node=12
setenv OMP_NUM_THREADS 1

echo "Got $NSLOTS slots." > job.out
echo "Got $NSLOTS slots." > job.err

cd /home/yljia/wien2k/TiC/testqsub/TiC
pwd

echo '  '
set proclist=`cat $TMPDIR/machines`
set nproc=$NSLOTS
echo $nproc nodes for this job: $proclist

if( -e .proclist_tmp)  rm .proclist_tmp
if ($jobs_per_node != 12 ) then
set j=1
while ($j <= $nproc )
@ j1 = $j + $jobs_per_node
@ j1 = $j1 - 1
echo $proclist[$j-$j1] >>.proclist_tmp
@ j = $j + 12
end
set proclist=`cat .proclist_tmp`
rm .proclist_tmp
set nproc=$#proclist
endif
echo $nproc nodes for this job: $proclist

echo '#' > .machines

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

#example for k-point and mpi parallel lapw1/2
#set j=1
#while ($j <= $jobs_per_node )
set i=1
while ($i <= $nproc )
echo -n '1:' >>.machines
@ i1 = $i + $mpijob
@ i2 = $i1 - 1
echo $proclist[$i-$i2] >>.machines
set i=$i1
end
echo 'granularity:1' >>.machines
echo 'extrafine:1' >>.machines

date
cd /home/yljia/wien2k/TiC/testqsub/TiC
run_lapw -p  -ec 0.0001 -NI >& /home/yljia/wien2k/TiC/testqsub/TiC/STDOUT