Mpi PBS

#!/bin/sh
#
# job name (default is the name of pbs script file)
#---------------------------------------------------
#PBS -N job_name
#
# Submit the job to the queue "queue_name"
#---------------------------------------------------
#PBS -q queue_name
#
# Send the mail messages (see below) to a user address
# This line and the Technion address are mandatory! 
#-----------------------------------------------------------------
#PBS -M user@campus.technion.ac.il
#
# send me mail when the job begins
#---------------------------------------------------
#PBS -mb
# send me mail when the job ends 
#---------------------------------------------------
#PBS -me
# send me mail when the job aborts (with an error)
#---------------------------------------------------
#PBS -ma
#
# Comment: if you want more than one message to be sent, you
# must group the flags in one line, otherwise only the last #flag is executed
#-------------------------------------------------------------
#PBS -mbea
#
# resource limits: number and distribution of parallel processes 
#--------------------------------------------------------------- 
#PBS -l select=M:ncpus=N:mpiprocs=N -l place=scatter
#
# comment: this select statement means: use M chunks (nodes), 
# use N CPUs for N mpi tasks on each of M nodes. 
# "scatter" will use exactly N CPUs from each node, while 
# omitting "-l place" statement will fill all available CPUs # of M nodes 
# 
# resource limits: max amount of memory P Gb to be used by the 
# job OPTIONAL
#-------------------------------------------------------------
#PBS -l select=mem=PGb
#
# resource limits: max. wall clock time during which job can run
# OPTIONAL, limited by queue wall time limit
#--------------------------------------------------------------
#PBS -l walltime=3:20:00
#
# specifying working directory: only mydir in PBS Generator ! 
#------------------------------------------------------
PBS_O_WORKDIR=$HOME/mydir

cd $PBS_O_WORKDIR
#
# running MPI executable with M*N processes 
#------------------------------------------------------

mpirun -np M*N ./mpi_program.exe < input.file > output.file

#
# comment: the "np" must be equal the number of chunks multiplied by the number of "ncpus"