source: trunk/oarutils/oar-profile.sh @ 221

Last change on this file since 221 was 102, checked in by g7moreau, 10 years ago
  • Add doc on env variable
  • Property svn:eol-style set to native
  • Property svn:executable set to *
File size: 8.0 KB
Line 
1if [ -d /opt/oar/current/bin/ ]
2then
3   export PATH=${PATH}:/opt/oar/current/bin/
4   export MANPATH=${MANPATH}:/opt/oar/current/man/
5
6   # OpenMPI connector
7   export OMPI_MCA_plm_rsh_agent=oarsh
8
9   # MPI NodeFile on second interface eth1
10   OAR_MSG_NODEFILE=${OAR_NODEFILE}-msg
11   [ -e "${OAR_MSG_NODEFILE}" ] && export OAR_MSG_NODEFILE
12
13   function oar_fixldpath () {
14      if [ -n "${LD_LIBRARY_PATH:+x}" ]
15      then
16         for ldpath in $(for lib in $(/sbin/ldconfig -p | awk 'BEGIN { FS = "=> " } ; {print $2}'); do dirname ${lib}; done | sort -u)
17         do
18            LD_LIBRARY_PATH="${LD_LIBRARY_PATH}:${ldpath}"
19         done
20      fi
21      }
22   declare -fx oar_fixldpath
23
24   function oar_mpirun () {
25      local exists_np=''
26      local exists_mf=''
27      local exists_vb=''
28
29      for opt in $*
30      do
31         [ "${opt}" == "-np" ]           && exists_np='y'
32         [ "${opt}" == "-machinefile" ]  && exists_mf='y'
33         [ "${opt}" == "--machinefile" ] && exists_mf='y'
34         [ "${opt}" == "-hostfile" ]     && exists_mf='y'
35         [ "${opt}" == "--hostfile" ]    && exists_mf='y'
36         [ "${opt}" == "--host" ]        && exists_mf='y'
37         [ "${opt}" == "-host" ]         && exists_mf='y'
38         [ "${opt}" == "-H" ]            && exists_mf='y'
39         [ "${opt}" == "--verbose" ]     && exists_vb='y'
40         [ "${opt}" == "-v" ]            && exists_vb='y'
41         [ "${opt}" == "--" ]            && break
42      done
43
44      [ -n "${VERBOSE:+x}" ] && exists_vb='y'
45
46      local mpi_option=''
47
48      # NODEFILE to use. By default specialized one
49      local nodefile="${OAR_NODE_FILE}"
50      [ -n "${OAR_MSG_NODEFILE:+x}" -a -e "${OAR_MSG_NODEFILE}" ] && nodefile="${OAR_MSG_NODEFILE}"
51      if [ -z ${exists_mf} ]
52      then
53         [ -e "${nodefile}" ] && mpi_option="-machinefile ${nodefile} ${mpi_option}"
54      fi
55
56      # Number of MPI parallel run. By default MAX.
57      local nbcpus=''
58      [ -e "${nodefile}" ]  && nbcpus=$(cat ${nodefile} | wc -l)
59      [ -n "${OAR_NP:+x}" ] && nbcpus=${OAR_NP}
60      if [ -z ${exists_np} ]
61      then
62         [ -z ${nbcpus} ] || mpi_option="-np ${nbcpus} ${mpi_option}"
63      fi
64
65      # VARIABLE to define in other MPI parallel run
66      for varenv in $(env \
67         | grep "^[ABCDEFGHIJKLMNOPQRSTUVWXYZ]" \
68         | egrep -v "^USER=|^TERM=|^OAR|^SGE_|^LS_COLORS=\
69            |^ENV=|^BASH_ENV=|^HOSTNAME=|^LOGNAME=|^MAIL=\
70            |^MANPATH=|^OMPI_MCA_plm_rsh_agent=|^PWD=\
71            |^SHELL=|^SSH_|^SUDO_COMMAND=|^HOME=|^DISPLAY=\
72            |^SHLVL=" \
73         | cut -f 1 -d '=' \
74         | sort )
75      do
76         mpi_option="${mpi_option} -x ${varenv}"
77      done
78
79      # Special case of LD_LIBRARY_PATH and system path
80      local ld_path="${LD_LIBRARY_PATH}"
81      oar_fixldpath
82
83      [ ! -z ${exists_vb} ] && echo mpirun ${mpi_option} $*
84      mpirun ${mpi_option} $*
85      [ ! -z ${ld_path} ] && LD_LIBRARY_PATH="${ld_path}"
86      }
87   declare -fx oar_mpirun
88
89   function oar_envmpirun () {
90      local exists_np=''
91      local exists_mf=''
92      local exists_vb=''
93
94      for opt in $*
95      do
96         [ "${opt}" == "-np" ]           && exists_np='y'
97         [ "${opt}" == "-machinefile" ]  && exists_mf='y'
98         [ "${opt}" == "--machinefile" ] && exists_mf='y'
99         [ "${opt}" == "-hostfile" ]     && exists_mf='y'
100         [ "${opt}" == "--hostfile" ]    && exists_mf='y'
101         [ "${opt}" == "--host" ]        && exists_mf='y'
102         [ "${opt}" == "-host" ]         && exists_mf='y'
103         [ "${opt}" == "-H" ]            && exists_mf='y'
104         [ "${opt}" == "--verbose" ]     && exists_vb='y'
105         [ "${opt}" == "-v" ]            && exists_vb='y'
106         [ "${opt}" == "--" ]            && break
107      done
108
109      [ -n "${VERBOSE:+x}" ] && exists_vb='y'
110
111      local mpi_option=''
112
113      # NODEFILE to use. By default specialized one
114      local nodefile="${OAR_NODE_FILE}"
115      [ -n "${OAR_MSG_NODEFILE:+x}" -a -e "${OAR_MSG_NODEFILE}" ] && nodefile="${OAR_MSG_NODEFILE}"
116      if [ -z ${exists_mf} ]
117      then
118         [ -e "${nodefile}" ] && mpi_option="-machinefile ${nodefile} ${mpi_option}"
119      fi
120
121      # Number of MPI parallel run. By default MAX.
122      local nbcpus=''
123      [ -e "${nodefile}" ]  && nbcpus=$(cat ${nodefile} | wc -l)
124      [ -n "${OAR_NP:+x}" ] && nbcpus=${OAR_NP}
125      if [ -z ${exists_np} ]
126      then
127         [ -z ${nbcpus} ] || mpi_option="-np ${nbcpus} ${mpi_option}"
128      fi
129
130      # Change login remote shell
131      local rsh_agent="${OMPI_MCA_plm_rsh_agent}"
132      if [ "${OMPI_MCA_plm_rsh_agent}" == "oarsh" ]
133      then
134         OMPI_MCA_plm_rsh_agent="oar-envsh"
135      fi
136
137      [ ! -z ${exists_vb} ] && echo mpirun ${mpi_option} $*
138      mpirun ${mpi_option} $*
139      [ ! -z ${rsh_agent} ] && OMPI_MCA_plm_rsh_agent="${rsh_agent}"
140      }
141   declare -fx oar_envmpirun
142
143   if [ -n "$PS1" -a -n "${OAR_JOB_WALLTIME_SECONDS}" ]
144   then
145      ( sleep $(( ${OAR_JOB_WALLTIME_SECONDS} - (10*60) )); \
146         echo; echo; echo "Close interactive session in 10min"; echo; \
147         sleep 0.2; printf \\a; \
148         sleep 0.2; printf \\a; \
149         sleep 0.2; printf \\a; \
150         sleep 8m; \
151         echo; echo; echo "Close interactive session in 2min"; echo; \
152         sleep 0.2; printf \\a; \
153         sleep 0.2; printf \\a; \
154         sleep 0.2; printf \\a; \
155         sleep 0.2; printf \\a; \
156         sleep 0.2; printf \\a; \
157         ) &
158   fi
159
160fi
161
162return
163
164################################################################
165# Documentation in POD format (like Perl)
166################################################################
167
168=head1 NAME
169
170oar-profile.sh - OAR bash profile to source
171
172=head1 SYNOPSIS
173
174 source oar-profile.sh
175
176 oar_mpirun [mpi_run option] command
177 oar_envmpirun [mpi_run option] command
178
179
180=head1 DESCRIPTION
181
182The use of MPI over a cluster need some parameters.
183When you use a batch scheduler like OAR,
184the most important option like C<-np> and C<-machinefile> could be defined by default for most case.
185
186This bash sript define two function C<oar_mpirun> and C<oar_envmpirun>.
187These are just wrapper and for most of the case,
188defined C<-np> and C<-machinefile> for you.
189With on of these wrapper, it is possible possible to use C<mpi_run>
190without any option...
191
192Because C<mpi_run> need to launch a command on a remote node on a cluster,
193theses wrappers are actually only validate for B<OpenMPI>
194which use C<ssh> by default as its transport from one node to another.
195
196=head1 COMMAND
197
198=over 12
199
200=item B<oar_mpirun> [mpi_run option] F<program>
201
202Wrapper to C<mpirun>, use C<oarsh> as remote shell,
203set environment variable on the remote side by using option C<-x> of C<mpirun>.
204If no option C<-np> or C<-machinefile> are defined,
205set them by default from OAR environment variable C<OAR_NODE_FILE>.
206Option C<-v> (or C<--verbose>) make an echo of the real C<mpirun> command on F<stdout>.
207
208All env variable are export by C<mpirun> except the following
209
210 USER TERM OAR* SGE_* LS_COLORS
211 ENV BASH_ENV HOSTNAME LOGNAME MAIL
212 MANPATH OMPI_MCA_plm_rsh_agent PWD
213 SHELL SSH_* SUDO_COMMAND= HOME DISPLAY
214 SHLVL
215
216=item B<oar_envmpirun> [mpi_run option] F<program>
217
218Wrapper to C<mpirun>, use C<oar-envsh> as remote shell which transmit environment variable
219(use the variable C<OMPI_MCA_plm_rsh_agent> for that).
220If no option C<-np> or C<-machinefile> are defined,
221set them by default from OAR environment variable C<OAR_NODE_FILE>.
222Option C<-v> (or C<--verbose>) make an echo of the real C<mpirun> command on F<stdout>.
223
224C<oar-envsh> export all the environment variable except the same list as above.
225
226=back
227
228You can use C<--machinefile>, C<-hostfile>, C<--hostfile> as alias for C<-machinefile>.
229If C<--host> C<-host> or C<-H> are defined, no option C<-machinefile> is set.
230
231At the end of the C<mpirun> option, you can use C<-->.
232Wrapper will then stop to analyse the command line.
233It could be important to use that if your F<program> has the same names for command line option...
234
235=head1 SEE ALSO
236
237mpirun, oarsh, oar-envsh
238
239=head1 AUTHORS
240
241Written by Gabriel Moreau, Grenoble - France
242
243=head1 LICENSE AND COPYRIGHT
244
245GPL version 2 or later
246
247Copyright (C) 2011-2013 Gabriel Moreau / LEGI - CNRS UMR 5519 - France
Note: See TracBrowser for help on using the repository browser.