source: trunk/oarutils/oar-mpirun @ 425

Last change on this file since 425 was 112, checked in by g7moreau, 10 years ago
  • Update mpirun script
File size: 2.1 KB
Line 
1#!/bin/bash -e
2#
3# 2014/01/06 gabriel
4
5function oar_fixldpath () {
6   if [ -n "${LD_LIBRARY_PATH:+x}" ]
7   then
8      for ldpath in $(for lib in $(/sbin/ldconfig -p | awk 'BEGIN { FS = "=> " } ; {print $2}'); do dirname ${lib}; done | sort -u)
9      do
10         LD_LIBRARY_PATH="${LD_LIBRARY_PATH}:${ldpath}"
11      done
12   fi
13   }
14declare -fx oar_fixldpath
15
16exists_np=''
17exists_mf=''
18exists_vb=''
19
20for opt in $*
21do
22   [ "${opt}" == "-np" ]           && exists_np='y'
23   [ "${opt}" == "-machinefile" ]  && exists_mf='y'
24   [ "${opt}" == "--machinefile" ] && exists_mf='y'
25   [ "${opt}" == "-hostfile" ]     && exists_mf='y'
26   [ "${opt}" == "--hostfile" ]    && exists_mf='y'
27   [ "${opt}" == "--host" ]        && exists_mf='y'
28   [ "${opt}" == "-host" ]         && exists_mf='y'
29   [ "${opt}" == "-H" ]            && exists_mf='y'
30   [ "${opt}" == "--verbose" ]     && exists_vb='y'
31   [ "${opt}" == "-v" ]            && exists_vb='y'
32   [ "${opt}" == "--" ]            && break
33done
34
35[ -n "${VERBOSE:+x}" ] && exists_vb='y'
36
37mpi_option=''
38
39# NODEFILE to use. By default specialized one
40nodefile="${OAR_NODE_FILE}"
41[ -n "${OAR_MSG_NODEFILE:+x}" -a -e "${OAR_MSG_NODEFILE}" ] && nodefile="${OAR_MSG_NODEFILE}"
42if [ -z ${exists_mf} ]
43then
44   [ -e "${nodefile}" ] && mpi_option="-machinefile ${nodefile} ${mpi_option}"
45fi
46
47# Number of MPI parallel run. By default MAX.
48nbcpus=''
49[ -e "${nodefile}" ]  && nbcpus=$(cat ${nodefile} | wc -l)
50[ -n "${OAR_NP:+x}" ] && nbcpus=${OAR_NP}
51if [ -z ${exists_np} ]
52then
53   [ -z ${nbcpus} ] || mpi_option="-np ${nbcpus} ${mpi_option}"
54fi
55
56# VARIABLE to define in other MPI parallel run
57for varenv in $(env \
58   | grep "^[ABCDEFGHIJKLMNOPQRSTUVWXYZ]" \
59   | egrep -v "^USER=|^TERM=|^OAR|^SGE_|^LS_COLORS=\
60      |^ENV=|^BASH_ENV=|^BASH_FUNC_|^HOSTNAME=|^LOGNAME=|^MAIL=\
61      |^MANPATH=|^PWD=\
62      |^OMPI_MCA_orte_rsh_agent=|^OMPI_MCA_plm_rsh_agent=\
63      |^SHELL=|^SSH_|^SUDO_COMMAND=|^HOME=|^DISPLAY=\
64      |^SHLVL=" \
65   | cut -f 1 -d '=' \
66   | sort )
67do
68   mpi_option="${mpi_option} -x ${varenv}"
69done
70
71# Special case of LD_LIBRARY_PATH and system path
72oar_fixldpath
73
74[ ! -z ${exists_vb} ] && echo mpirun ${mpi_option} $*
75exec mpirun ${mpi_option} $*
Note: See TracBrowser for help on using the repository browser.