1 #!/bin/sh
2 #
3 # control script for chemsh. This script serves to
4 #
5 # 1) define TCLLIBPATH for chemsh Tcl scripts
6 # 2) select tk or no tk depending on $DISPLAY setting
7 # and arguments and run the correct executable
8 # 3) treat a single argument as a script to execute
9 # (in a manner consistent between tk and no tk version)
10 #
11 # extra arguments
12 #
13 # -tk run with tk
14 # -notk run without tk
15 # -p <nodes> Parallel execution
16 #
17 ##
18 ## TCL_LIBRARY setting is not usually needed but may help if you
19 ## move the installation after compilation.
20 ##
21 ##TCL_LIBRARY=_TCLROOT_/lib/tcl8.4
22 ##export TCL_LIBRARY
24 #if cygwin#
25 TCL_LIBRARY=/usr/share/tcl8.4
26 export TCL_LIBRARY
27 #endif#
29 #
30 # This attempts to load the correct version of the Tcl .so files
31 # It is needed as they may be in the system path as well
32 #
33 LD_LIBRARY_PATH="_TCLROOT_/lib:${LD_LIBRARY_PATH}"
34 export LD_LIBRARY_PATH
36 #
37 # Add the bin directory to the path to
38 # a) pick up other executables which are part of ChemShell
39 # b) access rungamess if installed as part of ChemShell distrib
40 # c) append any other executable paths as specified in the
41 # individual modules (see module_config.sh)
42 #
43 PATH="_PATH_/../../bin:_PATH_/../../scripts:_PATH_/../../../GAMESS-UK/rungamess:${PATH}_PATHAPPEND_"
44 export PATH
46 #
47 # Should not need to change below here, except perhaps to support
48 # additional debug or parallel execution modes
49 #
50 TCLLIBPATH=_PATH_/../../tcl
51 export TCLLIBPATH
53 # uff definitions
54 CHEMSH_DATA_DIR=_PATH_/../../data
55 export CHEMSH_DATA_DIR
57 # for GULP 3.3
58 GULP_LIB=_PATH_/../../../GULP/Libraries
59 export GULP_LIB
61 # for g95
63 #if g95#
64 G95_UNBUFFERED_6=1
65 export G95_UNBUFFERED_6
66 #endif#
68 run_lam()
69 {
70 app=$1
71 mode=$2
72 appfile=$3
73 echo Running LAM MPI: app=$app mode=$mode appfile=$appfile
74 #
75 echo '# MPI application file' > $appfile
76 oldhost=XXX
77 j=0
78 jj=0
80 # newhost=`printenv NODE$j`
81 # while test ABC$newhost != ABC
82 # do
83 # if test $oldhost = $newhost
84 # then
85 # # re-use previous key if we are sharing the node
86 # jj=`expr $jj - 1`
87 # fi
88 # oldhost=$newhost
89 # j=`expr $j + 1`
90 # jj=`expr $jj + 1`
91 # newhost=`printenv NODE$j`
92 # done
94 echo $app >> $appfile
96 # if test $mode = master-slave
97 # then
98 # jj=`expr $jj - 1`
99 # echo $app -c 1 n$jj >> $appfile
100 # fi
102 echo ============== Application file for this job ===========
103 cat $appfile
104 echo ========================================================
106 #
107 # Execute the application (inherit stdin/stdout)
108 #
110 echo Start at `date`
111 # mpirun -v -w $appfile
112 /usr/local/lam/bin/mpirun -v -w -O -c2c -x TCLLIBPATH $appfile
113 echo End at `date`
114 date
115 stat=$?
116 return $stat
117 }
121 #
122 # This is set on some systems, but not all
123 #
124 PWD=`pwd`
125 export PWD
126 #
127 tk=0
128 #
129 args=" "
130 prog=$0
131 tcgmsg=0
132 procs=0
133 debug=0
134 user=$LOGNAME
135 script=undefined
136 while test $# != 0
137 do
138 skip=0
139 save=1
140 case $1 in
142 -display) tk=1; skip=1;;
144 -tk) tk=1; save=0;;
146 -notk) tk=0; save=0;;
148 -d) debug=1; save=0;;
150 -p) shift; procs=$1; save=0;;
152 -t) tcgmsg=1; save=0;;
154 -f) case $script in
155 undefined) shift; script=$1;;
156 *) echo $prog: unexpected argument $1; exit;;
157 esac
158 save=0;;
160 -*) skip=1 ;;
162 *) case $script in
163 undefined)script=$1;;
164 *) echo $prog: unexpected argument $1; exit;;
165 esac
166 save=0;;
167 esac
168 #
169 # pass onto interpreter argument line
170 #
171 case $save in
172 0) ;;
173 1) args="$args $1";;
174 esac
176 shift
177 #
178 # if skip is set, pass next arg without checking it
179 #
180 case $skip in
181 0) ;;
182 1) args="$args $1" ; shift ;;
183 esac
185 done
187 case $tk in
188 0) ;;
189 1) case ${DISPLAY:-X} in
190 X) echo "warning X-windows not available, check DISPLAY and xhost permissions";;
191 esac
192 #if notk#
193 echo "-tk option ignored (notk specified in build)"
194 tk=0
195 #endif#
196 ;;
197 esac
199 #echo script=$script
200 #echo prog=$prog
201 #echo args=$args
202 #
203 # attempt to hide the differences in
204 # argument handling of tclsh and wish
205 # derivatives
206 #
208 case $tk in
209 0)
210 app=_PATH_/../../bin/chemsh.x
211 #if cygwin#
212 app=_PATH_/../../bin/chemshprog.exe
213 #elseif poe#
214 app=_PATH_/../../bin/chemsh.x.poe
215 #endif#
216 ;;
217 1)
218 app=_PATH_/../../bin/chemsh.x.tk;;
219 esac
222 case $debug in
223 1)
224 #if linux cygwin#
225 #if rms#
226 prun -n 1 gdb $app
227 #else#
228 gdb $app
229 #endif#
230 #else#
231 dbx $app
232 #endif#
233 exit;;
234 esac
236 # RMS .. QSW software for linux/compaq
237 #if rms#
238 rms=1
239 #else#
240 rms=0
241 #endif#
243 #if sp2 sp3 sp4#
244 poe=1
245 case $procs in 0) procs=1;; esac
246 #elseif CRAY#
247 poe=3
248 case $procs in 0) procs=1;; esac
249 #elseif ga-mpi mpi dmpi#
250 #if lam#
251 poe=5
252 #else#
253 poe=4
254 #if dmpi#
255 dmpi=1
256 #else#
257 dmpi=0
258 #endif#
259 #endif#
260 case $procs in 0) procs=1;; esac
261 #elseif ga tcgmsg#
262 poe=2
263 #else#
264 poe=0
265 #endif#
267 #
268 case $poe in
269 0)
270 #
271 # Standard serial case
272 #
273 case $script in
274 undefined) $app $args;;
275 *) case $tk in
276 1) $app $args -f $script ;;
277 0) $app $args $script ;;
278 esac;;
279 esac;;
280 1)
281 #
282 # IBM SP2 (no graphics)
283 #
284 MP_CSS_INTERRUPT=yes
285 export MP_CSS_INTERRUPT
286 case $script in
287 undefined) poe $app $args -rmpool 2 -procs $procs -euilib ip;;
288 *) poe $app $args $script -rmpool 2 -procs $procs -euilib ip;;
289 esac;;
290 2)
291 #
292 # Run under control of parallel
293 #
294 case $tcgmsg in
295 0)
296 # No .p file
297 case $procs in
298 0)
299 # TCGMSG app should run without parallel on 1 proc
300 case $script in
301 undefined) $app $args;;
302 *) case $tk in
303 1) $app $args -f $script ;;
304 0) $app $args $script ;;
305 esac ;;
306 esac ;;
307 *)
308 echo Running TCGMSG app=$app nodes=$procs
309 oldhost=XXX
310 j=0
311 jj=0
312 newhost=`hostname`
313 appfile=chemsh.p
314 rm -f $appfile
316 case ${PBS_NODEFILE:=null} in
317 null)
318 while test $j -lt $procs
319 do
320 #echo $jj $newhost
321 if test ABC$newhost = ABC
322 then
323 echo "Not enough hosts defined, set more NODE\$n variables"
324 exit -1
325 fi
326 if test $oldhost = $newhost
327 then
328 # re-use previous key if we are sharing the node
329 jj=`expr $jj - 1`
330 fi
331 oldhost=$newhost
332 ntask=1
333 echo $user $newhost $ntask $app . >> $appfile
334 j=`expr $j + 1`
335 jj=`expr $jj + 1`
336 newhost=`printenv NODE$j`
337 done;;
339 *) echo PBS JOB
340 GAMESS_HOSTS=`cat $PBS_NODEFILE`
341 i=0
342 lasthost=none
343 for host in ${GAMESS_HOSTS}
344 do
345 if test $i -lt $procs
346 then
347 # if test $host != $lasthost
348 # then
349 echo $user $host 1 $app .>> $appfile
350 lasthost=$host
351 # fi
352 fi
353 i=`expr $i + 1`
354 done;;
355 esac
357 echo Start at `date`
358 case $script in
359 undefined) parallel chemsh $args;;
360 *) parallel chemsh $script $args;;
361 esac
362 echo End at `date`
363 ;;
364 esac;;
365 1)
366 if test -f chemsh.p
367 then
368 echo Start at `date`
369 case $script in
370 undefined) parallel chemsh $args;;
371 *) parallel chemsh $script $args;;
372 esac
373 echo End at `date`
374 else
375 echo "You must profile a chemsh.p file to use the -t options"
376 exit -1
377 fi
378 ;;
379 esac;;
380 3)
381 #
382 # T3E
383 #
384 case $script in
385 undefined) mpprun -n $procs $app;;
386 *) mpprun -n $procs $app $script;;
387 esac;;
389 4)
390 #
391 # MPI and DMPI (compaq), QSW
392 #
394 if test $dmpi = 1
395 then
396 case $script in
397 undefined) dmpirun -np $procs $app;;
398 *) dmpirun -np $procs $app < $script;;
399 esac
400 else
401 case $rms in
402 1)
403 case $script in
404 undefined) prun -n $procs $app;;
405 *) prun -n $procs $app $script;;
406 esac;;
407 0)
408 case $script in
409 undefined) mpirun -np $procs $app $args;;
410 *) mpirun -np $procs $app $script $args;;
411 esac;;
412 esac
414 fi
415 ;;
417 5)
418 #
419 # LAM MPI (lobosq/pbs)
420 #
422 case ${NODE0:=null} in
423 null) lobos=0;;
424 *) lobos=1;;
425 esac
427 case ${PBS_NODEFILE:=null} in
428 null) ;;
429 *) GAMESS_HOSTS=`cat $PBS_NODEFILE`
430 esac
432 mode=spmd
434 case $lobos in
436 1) # host list is provided by queueing software, daemons are already started
437 echo rungamess: Job is running under LoBoSQ
438 cat $script | run_lam $app $mode gamess.application
439 stat=$?;;
441 0) # Take hosts from GAMESS_HOSTS
442 echo rg_exe.lam: dir=`pwd` procs=$procs hostlist=$GAMESS_HOSTS
443 rm -f gamess.lamhosts
444 i=0
445 lasthost=none
446 for host in ${GAMESS_HOSTS}
447 do
449 if test $i -lt $procs
450 then
451 eval NODE$i=$host
452 export NODE$i
453 if test $host != $lasthost
454 then
455 echo $host >> gamess.lamhosts
456 lasthost=$host
457 fi
458 fi
459 i=`expr $i + 1`
460 done
461 cat gamess.lamhosts
462 /usr/local/lam/bin/lamboot gamess.lamhosts
463 case $script in
464 undefined) run_lam $app $mode gamess.application;;
465 *) run_lam $app $mode gamess.application < $script;;
466 esac
467 stat=$?
468 /usr/local/lam/bin/wipe gamess.lamhosts
469 # /usr/local/lam/bin/lamclean -v
470 rm -f gamess.lamhosts;;
471 esac;;
472 esac

