#!?SHELL_EXECUTION?

# $Id: mpirun_template 3529 2008-09-26 08:42:08Z courtois $

#
# script template to run Code_Aster using MPI
#
#
# This template contains following Python strings formatting keys :
#
#     cmd_to_run         : Code_Aster command line
#     mpi_get_procid_cmd : command to retreive processor ID
#
# automatically generated for job number #%(num_job)s
#

PROCID=`%(mpi_get_procid_cmd)s`

if [ -z "$PROCID" ]; then
   echo "Processor ID is not defined !"
   exit 4
fi

TMPDIR=%(local_wrkdir)sproc.$PROCID

if [ -e $TMPDIR ]; then
   rm -rf $TMPDIR
fi
%(cp_cmd)s %(wrkdir)s $TMPDIR
chmod 0700 $TMPDIR

cd $TMPDIR

%(cmd_to_run)s
iret=$?

if [ -f info_cpu ]; then
   infos=`cat info_cpu`
   echo "PROC=$PROCID INFO_CPU=$infos"
fi

if [ $PROCID -eq 0 ]; then
   cp -rf $TMPDIR/* %(wrkdir)s/
   kret=$?
   if [ $kret -gt $iret ]; then
      iret=$kret
   fi
fi
rm -rf $TMPDIR

exit $iret

