Index: /trunk/oarutils/Makefile
===================================================================
--- /trunk/oarutils/Makefile	(revision 98)
+++ /trunk/oarutils/Makefile	(revision 99)
@@ -7,9 +7,10 @@
 
 TARGET_C    := mpilauncher
-TARGET_MAN  := mpilauncher.1    oar-envsh.1    oar-dispatch.1    oar-parexec.1
-TARGET_HTML := mpilauncher.html oar-envsh.html oar-dispatch.html oar-parexec.html
+TARGET_MAN  := mpilauncher.1    oar-envsh.1    oar-dispatch.1    oar-parexec.1    oar-profile.1
+TARGET_HTML := mpilauncher.html oar-envsh.html oar-dispatch.html oar-parexec.html oar-profile.html
 
 PREFIX     :=/opt/oar/current
 PREFIX_MAN  =$(PREFIX)/man
+PREFIX_ETC  =$(PREFIX)/etc
 
 
@@ -36,4 +37,5 @@
 	@install -d -m 0755 -o root -g root $(PREFIX)/bin
 	@install -d -m 0755 -o root -g root $(PREFIX_MAN)/man1
+	@install -d -m 0755 -o root -g root $(PREFIX_ETC)/
 	install -m 0755 -o root -g root oar-parexec $(PREFIX)/bin
 	install -m 0755 -o root -g root oar-dispatch $(PREFIX)/bin
@@ -43,4 +45,6 @@
 	install -m 0644 -o root -g root mpilauncher.1 $(PREFIX_MAN)/man1
 	install -m 0644 -o root -g root oar-envsh.1 $(PREFIX_MAN)/man1
+	install -m 0644 -o root -g root oar-profile.1 $(PREFIX_MAN)/man1
+	install -m 0644 -o root -g root oar-profile.sh $(PREFIX_ETC)
 
 sync:
@@ -62,4 +66,10 @@
 	sed -re 's#^[/ ]\* ?##; s#^// ?##' $< | pod2html > $@
 
+%.1: %.sh
+	pod2man -n $* $(PODFLAG) $< > $@
+
+%.html: %.sh
+	pod2html $< > $@
+
 %.1: %
 	pod2man -n $* $(PODFLAG) $< > $@
Index: /trunk/oarutils/oar-profile.sh
===================================================================
--- /trunk/oarutils/oar-profile.sh	(revision 99)
+++ /trunk/oarutils/oar-profile.sh	(revision 99)
@@ -0,0 +1,197 @@
+if [ -d /opt/oar/current/bin/ ]
+then
+   export PATH=${PATH}:/opt/oar/current/bin/
+   export MANPATH=${MANPATH}:/opt/oar/current/man/
+
+   # OpenMPI connector
+   export OMPI_MCA_plm_rsh_agent=oarsh
+
+   # MPI NodeFile on second interface eth1
+   OAR_MSG_NODEFILE=${OAR_NODEFILE}-msg
+   [ -e "${OAR_MSG_NODEFILE}" ] && export OAR_MSG_NODEFILE
+
+   function oar_fixldpath () {
+      if [ -n "${LD_LIBRARY_PATH:+x}" ]
+      then
+         for ldpath in $(for lib in $(/sbin/ldconfig -p | awk 'BEGIN { FS = "=> " } ; {print $2}'); do dirname ${lib}; done | sort -u)
+         do
+            LD_LIBRARY_PATH="${LD_LIBRARY_PATH}:${ldpath}"
+         done
+      fi
+      }
+   declare -fx oar_fixldpath
+
+   function oar_mpirun () {
+      local exists_np=''
+      local exists_mf=''
+      local exists_vb=''
+
+      for opt in $*
+      do
+         [ "${opt}" == "-np" ]           && exists_np='y'
+         [ "${opt}" == "-machinefile" ]  && exists_mf='y'
+         [ "${opt}" == "--machinefile" ] && exists_mf='y'
+         [ "${opt}" == "-hostfile" ]     && exists_mf='y'
+         [ "${opt}" == "--hostfile" ]    && exists_mf='y'
+         [ "${opt}" == "--host" ]        && exists_mf='y'
+         [ "${opt}" == "-host" ]         && exists_mf='y'
+         [ "${opt}" == "-H" ]            && exists_mf='y'
+         [ "${opt}" == "--verbose" ]     && exists_vb='y'
+         [ "${opt}" == "-v" ]            && exists_vb='y'
+         [ "${opt}" == "--" ]            && break
+      done
+
+      [ -n "${VERBOSE:+x}" ] && exists_vb='y'
+
+      local mpi_option=''
+
+      # NODEFILE to use. By default specialized one
+      local nodefile="${OAR_NODE_FILE}"
+      [ -n "${OAR_MSG_NODEFILE:+x}" -a -e "${OAR_MSG_NODEFILE}" ] && nodefile="${OAR_MSG_NODEFILE}"
+      if [ -z ${exists_mf} ]
+      then
+         [ -e "${nodefile}" ] && mpi_option="-machinefile ${nodefile} ${mpi_option}"
+      fi
+
+      # Number of MPI parallel run. By default MAX.
+      local nbcpus=''
+      [ -e "${nodefile}" ]  && nbcpus=$(cat ${nodefile} | wc -l)
+      [ -n "${OAR_NP:+x}" ] && nbcpus=${OAR_NP}
+      if [ -z ${exists_np} ]
+      then
+         [ -z ${nbcpus} ] || mpi_option="-np ${nbcpus} ${mpi_option}"
+      fi
+
+      # VARIABLE to define in other MPI parallel run
+      for varenv in $(env \
+         | grep "^[ABCDEFGHIJKLMNOPQRSTUVWXYZ]" \
+         | egrep -v "^USER=|^TERM=|^OAR|^SGE_|^LS_COLORS=\
+            |^ENV=|^BASH_ENV=|^HOSTNAME=|^LOGNAME=|^MAIL=\
+            |^MANPATH=|^OMPI_MCA_plm_rsh_agent=|^PWD=\
+            |^SHELL=|^SSH_|^SUDO_COMMAND=|^HOME=|^DISPLAY=\
+            |^SHLVL=" \
+         | cut -f 1 -d '=' \
+         | sort )
+      do
+         mpi_option="${mpi_option} -x ${varenv}"
+      done
+
+      # Special case of LD_LIBRARY_PATH and system path
+      local ld_path="${LD_LIBRARY_PATH}"
+      oar_fixldpath
+
+      [ ! -z ${exists_vb} ] && echo mpirun ${mpi_option} $*
+      mpirun ${mpi_option} $*
+      [ ! -z ${ld_path} ] && LD_LIBRARY_PATH="${ld_path}"
+      }
+   declare -fx oar_mpirun
+
+   function oar_envmpirun () {
+      local exists_np=''
+      local exists_mf=''
+      local exists_vb=''
+
+      for opt in $*
+      do
+         [ "${opt}" == "-np" ]           && exists_np='y'
+         [ "${opt}" == "-machinefile" ]  && exists_mf='y'
+         [ "${opt}" == "--machinefile" ] && exists_mf='y'
+         [ "${opt}" == "-hostfile" ]     && exists_mf='y'
+         [ "${opt}" == "--hostfile" ]    && exists_mf='y'
+         [ "${opt}" == "--host" ]        && exists_mf='y'
+         [ "${opt}" == "-host" ]         && exists_mf='y'
+         [ "${opt}" == "-H" ]            && exists_mf='y'
+         [ "${opt}" == "--verbose" ]     && exists_vb='y'
+         [ "${opt}" == "-v" ]            && exists_vb='y'
+         [ "${opt}" == "--" ]            && break
+      done
+
+      [ -n "${VERBOSE:+x}" ] && exists_vb='y'
+
+      local mpi_option=''
+
+      # NODEFILE to use. By default specialized one
+      local nodefile="${OAR_NODE_FILE}"
+      [ -n "${OAR_MSG_NODEFILE:+x}" -a -e "${OAR_MSG_NODEFILE}" ] && nodefile="${OAR_MSG_NODEFILE}"
+      if [ -z ${exists_mf} ]
+      then
+         [ -e "${nodefile}" ] && mpi_option="-machinefile ${nodefile} ${mpi_option}"
+      fi
+
+      # Number of MPI parallel run. By default MAX.
+      local nbcpus=''
+      [ -e "${nodefile}" ]  && nbcpus=$(cat ${nodefile} | wc -l)
+      [ -n "${OAR_NP:+x}" ] && nbcpus=${OAR_NP}
+      if [ -z ${exists_np} ]
+      then
+         [ -z ${nbcpus} ] || mpi_option="-np ${nbcpus} ${mpi_option}"
+      fi
+
+      # Change login remote shell
+      local rsh_agent="${OMPI_MCA_plm_rsh_agent}"
+      if [ "${OMPI_MCA_plm_rsh_agent}" == "oarsh" ]
+      then
+         OMPI_MCA_plm_rsh_agent="oar-envsh"
+      fi
+
+      [ ! -z ${exists_vb} ] && echo mpirun ${mpi_option} $*
+      mpirun ${mpi_option} $*
+      [ ! -z ${rsh_agent} ] && OMPI_MCA_plm_rsh_agent="${rsh_agent}"
+      }
+   declare -fx oar_envmpirun
+
+   if [ -n "$PS1" -a -n "${OAR_JOB_WALLTIME_SECONDS}" ]
+   then
+      ( sleep $(( ${OAR_JOB_WALLTIME_SECONDS} - (10*60) )); \
+         echo; echo; echo "Close interactive session in 10min"; echo; \
+         sleep 0.2; printf \\a; \
+         sleep 0.2; printf \\a; \
+         sleep 0.2; printf \\a; \
+         sleep 8m; \
+         echo; echo; echo "Close interactive session in 2min"; echo; \
+         sleep 0.2; printf \\a; \
+         sleep 0.2; printf \\a; \
+         sleep 0.2; printf \\a; \
+         sleep 0.2; printf \\a; \
+         sleep 0.2; printf \\a; \
+         ) &
+   fi
+
+fi
+
+return
+
+################################################################
+# Documentation in POD format (like Perl)
+################################################################
+
+=head1 NAME
+
+oar_mpirun oar_envmpirun - OAR wrapper to launch mpi
+
+=head1 SYNOPSIS
+
+ oar_mpirun command
+ oar_envmpirun command
+
+
+=head1 DESCRIPTION
+
+When you need to do MPI over a cluster,
+you need to fix your environnement used by your code on every node.
+
+
+
+=head1 SEE ALSO
+
+oarsub
+
+=head1 AUTHORS
+
+Written by Gabriel Moreau, Grenoble - France
+
+=head1 LICENSE AND COPYRIGHT
+
+GPL version 2 or later
+
+Copyright (C) 2011-2013 Gabriel Moreau / LEGI - CNRS UMR 5519 - France
