source: palm/trunk/SCRIPTS/mrun @ 1842

Last change on this file since 1842 was 1842, checked in by raasch, 8 years ago

last commit documented

  • Property svn:keywords set to Id Rev
File size: 168.5 KB
Line 
1#!/bin/bash
2
3# mrun - script for running PALM jobs
4
5#--------------------------------------------------------------------------------#
6# This file is part of PALM.
7#
8# PALM is free software: you can redistribute it and/or modify it under the terms
9# of the GNU General Public License as published by the Free Software Foundation,
10# either version 3 of the License, or (at your option) any later version.
11#
12# PALM is distributed in the hope that it will be useful, but WITHOUT ANY
13# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
14# A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
15#
16# You should have received a copy of the GNU General Public License along with
17# PALM. If not, see <http://www.gnu.org/licenses/>.
18#
19# Copyright 1997-2015  Leibniz Universitaet Hannover
20#--------------------------------------------------------------------------------#
21#
22# Current revisions:
23# ------------------
24#
25#
26# Former revisions:
27# -----------------
28# $Id: mrun 1842 2016-04-07 19:24:16Z raasch $
29#
30# 1841 2016-04-07 19:14:06Z raasch
31# script now running under bash
32#
33# 1804 2016-04-05 16:30:18Z maronga
34# test: implementing an execute mechanism where the execute command is given in the
35# configuration file
36# ROPTS removed from execution commands
37# Warnings about missing optional files or user code changed to informative messages
38# Removed parameter file check
39#
40# 1755 2016-02-22 13:53:39Z maronga
41# Minor bugfix to last commit
42#
43# 1753 2016-02-22 13:49:49Z maronga
44# Bugfix: use random job number when PBS job nummer retrieval fails on lccray*
45#
46# 1622 2015-07-20 06:21:36Z heinze
47# bugfix for Mistral (lcbullhh)
48#
49# 1621 2015-07-17 11:39:33Z heinze
50# adjustments for Mistral at DKRZ Hamburg (lcbullhh)
51#
52# 1609 2015-07-03 15:37:58Z maronga
53# Modified the random number of the temporary working directory to match the
54# queuing system number on HLRN-III (lccray*).
55#
56# 1604 2015-06-23 15:48:03Z suehring
57# Enable coupled runs for lcmuk
58#
59# 1598 2015-05-29 06:45:40Z raasch
60# bugfix for creating hostfile and total number of MPI tasks if run in openmp-mode on one node
61#
62# 1549 2015-01-30 14:26:16Z suehring
63# Enable interactive debug sessions with allinea debugger
64#
65# 1547 2015-01-29 15:09:12Z witha
66# adjustments for ForWind computing cluster (lcflow)
67#
68# 1491 2014-11-12 08:12:57Z heinze
69# correct setting of batch_job allowed for ibm-machines
70#
71# 1468 2014-09-24 14:06:57Z maronga
72# Typo removed (addres->address)
73# Bugfix: returning files to IMUK via ssh did not work for lccrayh and lcycrayb
74# Added support for restart runs (remote) for lcxe6
75#
76# 1442 2014-07-28 07:09:10Z raasch
77# default queues for HLRN-III (lccrayb/lccrayh) defined
78#
79# 1422 2014-07-02 10:01:25Z kanani
80# automatic restarts enabled for lccrayb,
81# adjustment of path to compilervars.sh at IMUK (see automatic restarts)
82#
83# 1420 2014-06-10 06:24:14Z raasch
84# -j1 option added to aprung command for lccrayf (CSC)
85#
86# 1402 2014-05-09 14:25:13Z raasch
87# batch_job added to envpar-NAMELIST
88#
89# 1357 2014-04-11 15:02:03Z witha
90# adjustments for lccrayh (automatic restarts on lccrayh outside of IMUK are now
91# possible)
92#
93# 1320 2014-03-20 08:40:49Z raasch
94# check namelist file set false by default
95#
96# 1304 2014-03-12 10:29:42Z raasch
97# ulimit option changed from -Ss to -s
98#
99# bugfix: missing "fi" in r1289
100#
101# 1289 2014-03-04 07:12:34Z raasch
102# comments translated to English
103# necriam-, fimm-, ibmy-, and sgi-specific code removed
104# export of variables for palm and interpret_config removed
105#
106# 1281 2014-02-01 07:55:49Z raasch
107# rsync-copy restricted to Cray machines, since command is unavailable on some
108# other systems
109#
110# 1279 2014-01-28 12:10:14Z raasch
111# tasks_per_node must not be an integral divisor of numprocs any more. This was done
112# in order to remove annoying restrictions concerning the number of processors which
113# appear on machines with larger nodes (e.g. containing 24 cores). Now without this
114# restriction, one of the nodes will be filled with less than the given number of
115# tasks per node. A respective warning is given.
116#
117# 1274 2014-01-09 13:14:54Z heinze
118# adjustments for lccrayh
119#
120# 1272 2014-01-08 10:19:32Z witha
121# small adjustment for lcflow
122#
123# 1270 2013-12-16 11:05:01Z fricke
124# call of combine_plot_fields adjusted for lccrayb/lccrayh
125#
126# 1255 2013-11-07 14:43:35Z raasch
127# further adjustments for lccrayb remote access
128#
129# 1241 2013-10-30 11:36:58Z heinze
130# Enable use of nudging input and input of large scale forcing from
131# external files
132#
133# 1229 2013-09-20 06:55:19Z raasch
134# further adjustments for lccrayb
135#
136# 1224 2013-09-16 07:27:23Z raasch
137# first adjustments for lccrayb
138#
139# 1210 2013-08-14 10:58:20Z raasch
140# fftw support added
141#
142# 1201 2013-07-10 16:17:59Z witha
143# adjustments for Forwind cluster (lcflow)
144#
145# 1199 2013-07-05 14:52:22Z raasch
146# adjustments for CSC Helsinki (lccrayf),
147# executables for batch jobs can be created in advance, in order to avoid calling
148# the compiler within the batch job (only works if batch jobs are submitted on
149# local host)
150#
151# 1190 2013-06-25 09:39:21Z heinze
152# enable use of automatic restarts for ibmh
153# use of cluster/express queue enabled (ibmh)
154#
155# 1124 2013-04-09 15:46:52Z raasch
156# variable "memory" is exported via typeset option -x, because otherwise an unknown
157# side effect may lead to data loss while getopts is reading the script-option arguments
158#
159# 1122 2013-04-09 08:37:16Z heinze
160# Bugfix: change type of variable last_char
161#
162# 1119 2013-04-05 15:11:19Z raasch
163# Bugfix for setting -T option for subjob
164#
165# 1108 2013-03-05 07:03:32Z raasch
166# bugfix for coupled runs on lckyut/lckyuh
167#
168# 1106 2013-03-04 05:31:38Z raasch
169# --stdin argument for mpiexec on lckyuh
170# -y and -Y settings output to header
171#
172# 1103 2013-02-20 02:15:53Z raasch
173# default script runs again under ksh, because of unsolved problems with read
174# from stdin: when bash script is called from a ksh, message "read error: 0:
175# Resource temporarily unavailable" appears and script does not stop,
176# further bash compatibility adjustments,
177# shebang line replaced by /bin/bash when running jobs on lckyuh; no restarts
178# on lckyuh, but mrun does not terminate and issues a warning instead
179#
180# 1101 2013-02-17 10:20:21Z raasch
181# script now running under bash instead of ksh, which required small adjustments
182# (output formatting with printf instead "typeset -L/-R", print replaced by echo,
183# read from stdin),
184# cross compilername on lckyuh compute nodes replaced by real compiler name
185#
186# 1099 2013-02-10 01:47:43Z raasch
187# adjustments for Kyushu-University computing center (lckyuh - hayaka)
188# and for Forwind cluster (lcflow)
189# small further adjustments for lckyut
190#
191# 1094 2013-02-03 01:52:12Z raasch
192# explicit ssh/scp port can be set in config file with environment variable
193# scp_port.  This port is handled to all ssh/scp/batch_scp calls.
194# decalpha parts (yonsei) removed
195#
196# 2013-02-02 07:06:13Z raasch
197# adjustments for Kyushu-University computing center (lckyut - tatara)
198#
199# 1083 2013-01-04 10:22:09Z maronga
200# bugfix in parameter file check (read %cpp_options was missing)
201#
202# 1069 2012-11-28 16:18:43Z maronga
203# bugfix: coupling mode was always set to mpi2, typos removed
204#
205# 1058 2012-11-21 07:00:35Z raasch
206# Intel inspector (inspxe) is given the number of PEs instead of the number of
207# nodes
208#
209# 1046 2012-11-09 14:38:45Z maronga
210# code put under GPL (PALM 3.9)
211#
212# 21/03/94 - Siggi - first version finished
213# 03/03/94 - Siggi - script development started
214#
215#--------------------------------------------------------------------------------#
216# mrun - script for running PALM jobs
217#--------------------------------------------------------------------------------#
218
219
220 
221    # DECLARATION OF VARIABLES AND THEIR DEFUALT VALUES
222
223 set +o allexport    # SUPPRESS EXPORT OF ALL VARIABLES, SINCE IN THE PAST THIS
224                     # LES TO PROBLEMS IN ROUTINES CALLED BY MRUN
225                     # (TOO MANY ARGUMENTS - PROBLEM)
226 set +o noclobber    # EXISTING FILES ARE ALLOWED TO BE OVERWRITTEN
227
228 AddFilenames=""
229 additional_conditions=""
230 add_source_path=""
231 afname=""
232 archive_save=true
233 archive_system=none
234 check_namelist_files=false
235 combine_plot_fields=true
236 compiler_name=""
237 cond1=""
238 cond2="" 
239 config_file=.mrun.config
240 coupled_dist=""
241 coupled_mode="mpi1"
242 cpp_opts=""
243 cpp_options=""
244 cpumax=0
245 cpurest=0
246 create_executable_for_batch=false
247 delete_temporary_catalog=true
248 do_batch=false
249 do_compile=true
250 do_remote=false
251 do_stagein=true
252 do_stageout=true
253 do_trace=false
254 email_notification="none"
255 exclude=""
256 executable=""
257 execute_command="none"
258 execution_error=false
259 fftw_inc=""
260 fftw_lib=""
261 fftw_support=false
262  fname=test
263 fromhost=""
264 global_revision=""
265 group_number=none
266 host=""
267 host_file=""
268 hp=""
269 ignore_archive_error=false
270 input_list=""
271 interpreted_config_file=""
272 job_catalog="~/job_queue"
273 job_on_file=""
274 keep_data_from_previous_run=false
275 link_local_input=false
276 link_local_output=false
277 localhost_realname=$(hostname)
278 local_dvrserver_running=.FALSE.
279 locat=normal
280 mainprog=""
281 makefile=""
282 max_par_io_str=""
283 mc=$0
284 while [[ $(echo $mc | grep -c "/") != 0 ]]
285 do
286    mc=`echo $mc | cut -f2- -d"/"`
287 done
288 module_calls=""
289 mrun_script_name=$mc
290 netcdf_inc=""
291 netcdf_lib=""
292 netcdf_support=false
293 node_usage=default
294 numprocs=""
295 numprocs_atmos=0
296 numprocs_ocean=0
297 OOPT=""
298 openmp=false
299 output_list=""
300 package_list=""
301 queue=none
302 read_from_config=""
303 restart_run=false
304 if [[ `hostname` = rte10 ]]
305 then
306    return_address=133.5.185.60
307    echo "+++ WARNING: fixed return_address = $return_address is used !!!!!"
308 elif [[ `hostname` = climate0 ]]
309 then
310    return_address=165.132.26.68
311    echo "+++ WARNING: fixed return_address = $return_address is used !!!!!"
312 elif [[ `hostname` = urban00 ]]
313 then
314    return_address=147.46.30.151
315    echo "+++ WARNING: fixed return_address = $return_address is used !!!!!"
316 else
317    return_address=$(nslookup `hostname` 2>&1 | grep "Address:" | tail -1 | awk '{print $2}')
318 fi
319 return_password=""
320 return_username=$LOGNAME
321 remotecall=false
322 remote_username=""
323 run_coupled_model=false
324 run_mode=""
325 store_on_archive_system=false
326 dashes="  ----------------------------------------------------------------------------"
327 silent=false
328 source_list=""
329 source_path=SOURCE
330 tasks_per_node=""
331 threads_per_task=1
332 tmpcreate=false
333 tmp_data_catalog=""
334 transfer_problems=false
335 usern=$LOGNAME
336 use_openmp=false
337 version="MRUN  2.1 Rev$Rev: 1842 $"
338 working_directory=`pwd`
339 TOPT=""
340 XOPT=""
341 zeit=$( date | cut -c 12-19 )
342
343 typeset -i  iec=0 iic=0 iin=0 ioc=0 iout=0 stagein_anz=0 stageout_anz=0
344 typeset -x -i  memory=0   # HAS TO BE EXPORTED HERE, OTHERWISE AN UNKNOWN SIDE
345                           # SIDE EFFECT MAY CAUSE DATA LOSS WHEN GETOPTS IS READING THE
346                           # SCRIPT-OPTION ARGUMENTS
347 typeset -i  cputime i ii iia iii iio icycle inode ival jobges jobsek last_char_int maxcycle minuten nodes pes remaining_pes sekunden tp1
348
349    # ERROR HANDLING IN CASE OF EXIT
350 trap 'rm -rf  $working_directory/tmp_mrun
351       if [[ $locat != normal  &&  $locat != control_c ]]
352       then
353
354              # CARRY OUT ERROR-COMMANDS GIVEN IN THE CONFIGURATION FILE (EC:)
355          (( i = 0 ))
356          while (( i < iec ))
357          do
358             (( i = i + 1 ))
359             printf "\n  *** Execution of ERROR-command:\n"
360             printf "  >>> ${err_command[$i]}\n"
361             eval  ${err_command[$i]}
362          done
363          if [[ -n $interpreted_config_file ]]
364          then
365             rm -rf  $interpreted_config_file
366          fi
367          if [[ -n .mrun_environment ]]
368          then
369             rm -rf  .mrun_environment
370          fi
371          if [[ $tmpcreate = true ]]
372          then
373             printf "\n  *** Contents of \"$TEMPDIR\":\n"
374             ls -al; cd
375             [[ $delete_temporary_catalog = true ]]  &&  rm -rf $TEMPDIR
376          fi
377          if [[ "$dvrserver_id" != "" ]]
378          then
379             echo "+++ killing dvrserver_id=$dvrserver_id"
380             kill $dvrserver_id
381          fi
382          if [[ -f ~/job_queue/JOBINFO.$QSUB_REQID ]]
383          then
384             rm -rf  ~/job_queue/JOBINFO.$QSUB_REQID
385          fi
386          printf "\n\n+++ MRUN killed \n\n"
387       elif [[ $locat != control_c ]]
388       then
389          printf "\n\n --> all actions finished\n\n"
390          printf "     Bye, bye $usern !!\n\n"
391       fi' exit
392
393
394    # ACTIONS IN CASE OF TERMINAL-BREAK (CONTROL-C):
395 trap 'rm -rf  $working_directory/tmp_mrun
396       rm -rf  $working_directory/tmp_check_namelist_files
397       [[ $tmpcreate = true ]]  &&  (cd; rm -rf $TEMPDIR)
398       if [[ -f ~/job_queue/JOBINFO.$QSUB_REQID ]]
399       then
400          rm -rf  ~/job_queue/JOBINFO.$QSUB_REQID
401       fi
402       if [[ "$dvrserver_id" != "" ]]
403       then
404          echo "+++ killing dvrserver_id=$dvrserver_id"
405          kill $dvrserver_id
406       fi
407       printf "\n+++ MRUN killed by \"^C\" \n\n"
408       locat=control_c
409       exit
410      ' 2
411
412
413    # CHECK IF THE PATH FOR THE PALM BINARIES (SCRIPTS+UTILITY-PROGRAMS) HAS
414    # BEEN SET
415 if [[ "$PALM_BIN" = "" ]]
416 then
417    printf "\n  +++ environment variable PALM_BIN has not been set"
418    printf "\n      please set it to the directory where the PALM scripts are located"
419    locat=palm_bin; exit
420 fi
421 export PATH=$PALM_BIN:$PATH
422
423
424
425    # READ SHELLSCRIPT-OPTIONS AND REBUILD THE MRUN-COMMAND STRING (MC),
426    # WHICH WILL BE USED TO START RESTART-JOBS
427 while  getopts  :a:AbBc:Cd:D:Fg:G:h:H:i:IkK:m:M:n:o:O:p:P:q:r:R:s:St:T:u:U:vw:xX:yY:zZ option
428 do
429   case  $option  in
430       (a)   afname=$OPTARG;;
431       (A)   store_on_archive_system=true; mc="$mc -A";;
432       (b)   do_batch=true; mc="$mc -b";;
433       (B)   delete_temporary_catalog=false; mc="$mc -B";;
434       (c)   config_file=$OPTARG; mc="$mc -c$OPTARG";;
435       (C)   restart_run=true; mc="$mc -C";;
436       (d)   fname=$OPTARG; mc="$mc -d$OPTARG";;
437       (D)   cpp_opts="$cpp_opts $OPTARG"; mc="$mc -D'$OPTARG'";;
438       (F)   job_on_file="-D"; mc="$mc -F";;
439       (g)   group_number=$OPTARG; mc="$mc -g$OPTARG";;
440       (G)   global_revision=$OPTARG; mc="$mc -G'$OPTARG'";;
441       (h)   host=$OPTARG; mc="$mc -h$OPTARG";;
442       (H)   fromhost=$OPTARG; mc="$mc -H$OPTARG";;
443       (i)   input_list=$OPTARG; mc="$mc -i'$OPTARG'";;
444       (I)   ignore_archive_error=true; mc="$mc -I";;
445       (k)   keep_data_from_previous_run=true; mc="$mc -k";;
446       (K)   additional_conditions="$OPTARG"; mc="$mc -K'$OPTARG'";;
447       (m)   memory=$OPTARG; mc="$mc -m$OPTARG";;
448       (M)   makefile=$OPTARG; mc="$mc -M$OPTARG";;
449       (n)   node_usage=$OPTARG; mc="$mc -n$OPTARG";;
450       (o)   output_list=$OPTARG; mc="$mc -o'$OPTARG'";;
451       (O)   use_openmp=true; threads_per_task=$OPTARG; mc="$mc -O$OPTARG";;
452       (p)   package_list=$OPTARG; mc="$mc -p'$OPTARG'";;
453       (P)   return_password=$OPTARG; mc="$mc -P$OPTARG";;
454       (q)   queue=$OPTARG; mc="$mc -q$OPTARG";;
455       (r)   run_mode=$OPTARG; mc="$mc -r'$OPTARG'";;
456       (R)   remotecall=true;return_address=$OPTARG; mc="$mc -R$OPTARG";;
457       (s)   source_list=$OPTARG; mc="$mc -s'$OPTARG'";;
458       (S)   read_from_config=false; mc="$mc -S";;
459       (t)   cpumax=$OPTARG; mc="$mc -t$OPTARG";;
460       (T)   mrun_tasks_per_node=$OPTARG; mc="$mc -T$OPTARG";;
461       (u)   remote_username=$OPTARG; mc="$mc -u$OPTARG";;
462       (U)   return_username=$OPTARG; mc="$mc -U$OPTARG";;
463       (v)   silent=true; mc="$mc -v";;
464       (w)   max_par_io_str=$OPTARG; mc="$mc -w$OPTARG";;
465       (x)   do_trace=true;set -x; mc="$mc -x";;
466       (X)   numprocs=$OPTARG; mc="$mc -X$OPTARG";;
467       (y)   ocean_file_appendix=true; mc="$mc -y";;
468       (Y)   run_coupled_model=true; coupled_dist=$OPTARG; mc="$mc -Y'$OPTARG'";;
469       (z)   check_namelist_files=false; mc="$mc -z";;
470       (Z)   combine_plot_fields=false; mc="$mc -Z";;
471       (\?)  printf "\n  +++ unknown option $OPTARG \n"
472             printf "\n  --> type \"$0 ?\" for available options \n"
473             locat=parameter;exit;;
474   esac
475 done
476
477
478    # SKIP GIVEN OPTIONS TO READ POSITIONAL PARAMETER, IF GIVEN
479    # CURRENTLY ONLY PARAMETER ? (TO OUTPUT A SHORT COMMAND INFO) IS ALLOWED
480 (( to_shift = $OPTIND - 1 ))
481 shift $to_shift
482
483    # PRINT SHORT DESCRIPTION OF MRUN OPTIONS
484 if [[ "$1" = "?" ]]
485 then
486   (printf "\n  *** mrun can be called as follows:\n"
487    printf "\n      $mrun_script_name  -b -c.. -d.. -D.. -f.. -F -h.. -i.. -I -K.. -m.. -o.. -p.. -r.. -R -s.. -t.. -T.. -v -x -X.. -y -Y.. -Z <modus> \n"
488    printf "\n      Description of available options:\n"
489    printf "\n      Option  Description                              Default-Value"
490    printf "\n        -a    base name of input files                 equiv. -d"
491    printf "\n        -A    archiving when using file-attribute fl"
492    printf "\n        -b    batch-job on local machine               ---"
493    printf "\n        -B    do not delete temporary directory at end ---"
494    printf "\n        -c    configuration file                       .mrun.config"
495    printf "\n        -d    base name of files attached to program   test"
496    printf "\n        -D    preprocessor(cpp)-directives             \"\" "
497    printf "\n        -F    create remote job file only              ---"
498    printf "\n        -h    execution host                           $localhost_realname"
499    printf "\n        -i    INPUT control list                       \"\" "
500    printf "\n        -I    archiving errors of previous batch-jobs"
501    printf "\n              will be ignored"
502    printf "\n        -k    keep data from previous run"
503    printf "\n        -K    additional conditions for controling"
504    printf "\n              usage of conditional code and"
505    printf "\n              env-variables in configuration file      \"\" "
506    printf "\n        -m    memory demand in MB (batch-jobs)         0 MB"
507    printf "\n        -M    Makefile name                            Makefile"
508    printf "\n        -n    node usage (shared/not_shared)           depending on -h"
509    printf "\n        -o    OUTPUT control list                      \"\" "
510    printf "\n        -O    threads per openMP task                  ---"
511    printf "\n        -p    software package list                    \"\" "
512    printf "\n        -q    queue                                    \"$queue\" "
513    printf "\n        -r    run control list (combines -i -o)        \"\" "
514    printf "\n        -s    filenames of routines to be compiled     \"\" "
515    printf "\n              must end with .f, .f90, .F, or .c !"
516    printf "\n              use \"..\" for more than one file and wildcards"
517    printf "\n              -s LM compiles all locally modified files"
518    printf "\n        -S    config file interpreted by shellscript   ---"
519    printf "\n        -t    allowed cpu-time in seconds (batch)      0"
520    printf "\n        -T    tasks per node                           depending on -h"
521    printf "\n        -u    username on remote machine               \"\" "
522    printf "\n        -v    no prompt for confirmation               ---"
523    printf "\n        -w    maximum parallel io streams              as given by -X"
524    printf "\n        -x    tracing of mrun for debug purposes       ---"
525    printf "\n        -X    # of processors (on parallel machines)   1"
526    printf "\n        -y    add appendix \"_O\" to all local output"
527    printf "\n              files (ocean precursor runs followed by"
528    printf "\n              coupled atmosphere-ocean runs)           ---"
529    printf "\n        -Y    run coupled model, \"#1 #2\" with" 
530    printf "\n              #1 atmosphere and #2 ocean processors    \"#/2 #/2\" depending on -X"
531    printf "\n        -Z    skip combine_plot_fields at the end of      "
532    printf "\n              the simulation                           ---"
533    printf "\n "
534    printf "\n      Possible values of positional parameter <modus>:"
535    printf "\n        \"?\"       -  this outline \n\n") | more
536    exit
537 elif [[ "$1" != "" ]]
538 then
539    printf "\n  +++ positional parameter $1 unknown \n"
540    locat=parameter; exit
541 fi
542
543
544
545    # SHORT STARTING MESSAGE
546 printf "\n*** $version "
547 printf "\n    will be executed.     Please wait ..."
548
549
550
551    # CHECK, IF CONFIGURATION FILE EXISTS
552 if [[ ! -f $config_file ]]
553 then
554    printf "\n\n  +++ configuration file: "
555    printf "\n           $config_file"
556    printf "\n      does not exist"
557    locat=connect; exit 
558 fi
559
560
561    # DETERMINE THE HOST-IDENTIFIER (localhost) FROM THE CONFIGURATION FILE
562 line=""
563 grep  "%host_identifier"  $config_file  >  tmp_mrun
564 while read line
565 do
566    if [[ "$line" != ""  &&  $(echo $line | cut -c1) != "#" ]]
567    then
568       HOSTNAME=`echo $line | cut -d" " -s -f2`
569       host_identifier=`echo $line | cut -d" " -s -f3`
570       if [[ $localhost_realname = $HOSTNAME ]]
571       then
572          localhost=$host_identifier
573          break
574       fi
575    fi
576 done < tmp_mrun
577
578 if [[ "$localhost" = "" ]]
579 then
580    printf "\n\n  +++ no host identifier found in configuration file \"$config_file\""
581    printf "\n      for local host \"$localhost_realname\"."
582    printf "\n      Please add line"
583    printf "\n      \"\%host_identifier $localhost_realname <identifier>\""
584    printf "\n      to the configuration file."
585    locat=localhost; exit
586 fi
587
588
589    # SET HOST-SPECIFIC VARIABLES
590 case  $localhost_realname  in
591     (r1*|r2*|h01*|b01*)     archive_system=tivoli;;
592     (cs*)                   archive_system=ut;;
593 esac
594
595
596    # ??? THIS SHOULD BE DECRIBED IN THE MRUN DOCUMENTATION ???
597    # SET BASENAME OF THE INPUT-FILES TO THE GENERAL BASENAME (GIVEN BY OPTION -d),
598    # IF IT HAS NOT BEEN SET BY THE USER DIFFERENTLY (USING OPTION -a)
599 [[ "$afname" = "" ]]  &&  afname=$fname
600
601
602    # ADD RUN-FILE ACTIVATION STRINGS (GIVEN BY OPTION -r) TO THE
603    # RESPECTIVE LISTS FOR ACTIVATING THE INPUT/OUTPUT FILE CONNECTION
604    # STATEMENTS IN THE CONFIGURATION FILE
605 if [[ "$run_mode" != "" ]]
606 then
607    input_list="$input_list $run_mode"
608    output_list="$output_list $run_mode"
609 fi
610
611
612    # ??? is this (and the respective option -H) really required ???
613    # STORE HOSTNAME, FROM WHICH THE JOB IS STARTED,
614    # BUT ONLY IF IT HASN'T BEEN ALREADY SET BY OPTION -H
615    # (MRUN IS AUTOMATICALLY SETTING THIS OPTION IN THE MRUN-CALLS WITHIN
616    # THOSE BATCH-JOBS, WHICH ARE CREATED BY MRUN ITSELF)
617 if [[ "$fromhost" = "" ]]
618 then
619    fromhost=$localhost
620 fi
621
622
623    # CHECK, IF EXECUTION SHALL TO BE DONE ON THE REMOTE-MACHINE.
624    # VALUE OF do_remote IS IMPORTANT FOR THE FILE CONNECTIONS.
625    # IN CASE OF EXECUTION ON A REMOTE-MACHINE, A BATCH-JOB HAS
626    # TO BE SUBMITTED (I.E. do_batch=true)
627 if [[ -n $host  &&  "$host" != $localhost ]]
628 then
629    do_batch=true
630    do_remote=true
631    case  $host  in
632        (ibm|ibmh|ibmkisti|ibmku|ibms|nech|lcbullhh|lccrayb|lccrayh|lccrayf|lcflow|lckyoto|unics|lcxe6|lcxt5m|lck|lckiaps|lckordi|lckyuh|lckyut|lcsb)  true;;
633        (*)  printf "\n"
634             printf "\n  +++ sorry: execution of batch jobs on remote host \"$host\""
635             printf "\n      is not available"
636             locat=nqs; (( iec = 0 )); exit;;
637    esac
638 else
639    host=$localhost
640 fi
641
642
643     # EVALUATE ADDITIONAL CONDITIONS GIVEN BY OPTION -K
644 if [[ -n $additional_conditions ]]
645 then
646    cond1=`echo $additional_conditions | cut -d" " -f1`
647    cond2=`echo $additional_conditions | cut -d" " -s -f2`
648    dummy=`echo $additional_conditions | cut -d" " -s -f3`
649    if [[ -n $dummy ]]
650    then
651       printf "\n  +++ more than 2 additional conditions given for Option \"-K\""
652       locat=options; exit
653    fi
654    block=_$cond1
655    [[ -n $cond2 ]]  &&  block=${block}_$cond2
656 fi
657
658
659      # EVALUATE MODEL COUPLING FEATURES (OPTION -Y) AND DETERMINE coupled_mode
660 if [[ $run_coupled_model = true ]] 
661 then
662
663    numprocs_atmos=`echo $coupled_dist | cut -d" " -s -f1`
664    numprocs_ocean=`echo $coupled_dist | cut -d" " -s -f2`
665
666    if (( $numprocs_ocean + $numprocs_atmos != $numprocs ))
667    then
668
669       printf "\n  +++ number of processors does not fit to specification by \"-Y\"."
670       printf "\n      PEs (total)     : $numprocs"
671       printf "\n      PEs (atmosphere): $numprocs_atmos"
672       printf "\n      PEs (ocean)     : $numprocs_ocean"
673       locat=coupling; exit
674
675    fi
676
677
678       # GET coupled_mode FROM THE CONFIG FILE
679    line=""
680    grep  "%cpp_options.*-D__mpi2.*$host" $config_file  >  tmp_mrun
681    while read line
682    do
683       echo line=\"$line\"
684       if [[ "$line" != ""  &&  $(echo $line | cut -c1) != "#" &&  $(echo $line | cut -d" " -s -f4) = $cond1 && $(echo $line | cut -d" " -s -f5)  = $cond2 ]]
685       then
686          coupled_mode="mpi2"
687       fi
688    done < tmp_mrun
689
690 fi
691
692    # CHECK, IF FILE-ARCHIVING HAS FAILED IN PREVIOUS JOB (OF A JOB-CHAIN)
693 if [[ -f ~/job_queue/ARCHIVE_ERROR_$fname ]]
694 then
695    if [[ $ignore_archive_error = false ]]
696    then
697       printf "\n  +++ data archiving of previous run failed"
698       printf "\n      see directory \~/job_queue on remote machine"
699       locat=archive; exit
700    else
701       printf "\n  +++ warning: data archiving in a previous run failed"
702       printf "\n      MRUN continues, trying to get backup copy"
703    fi
704 fi
705
706
707    # SAVE VALUES OF MRUN-OPTIONS SICHERN IN ORDER TO OVERWRITE
708    # THOSE VALUES GIVEN IN THE CONFIGURATION-FILE
709 mrun_memory=$memory
710 mrun_group_number=$group_number
711 mrun_cpumax=$cpumax
712 mrun_numprocs=$numprocs
713
714
715    # READ AND EVALUATE THE CONFIGURATION-FILE FROM WITHIN THIS SHELLSCRIPT
716    # (OPTION -S). THE DEFAULT IS USING THE ROUTINE <<<<
717 if [[ "$read_from_config" = false ]]
718 then
719    [[ $silent = false ]]  &&  printf "\n    Reading the configuration file... "
720
721       # READ THE CONFIGURATION FILE LINE BY LINE
722    while  read zeile
723    do
724        [[ $silent = false ]]  &&  printf "."
725
726
727          # FIRST REPLACE ENVIRONMENT-VARIABLES BY THEIR RESPECTIVE VALUES
728       eval  zeile=\"$zeile\"
729
730
731          # INTERPRET THE LINE
732       if [[ "$(echo $zeile)" = "" ]]
733       then
734             # EMPTY LINE, NO ACTION
735          continue
736
737       elif [[ "$(echo $zeile | cut -c1)"  =  "#" ]]
738       then
739
740             # LINE IS A COMMENT LINE
741          true
742
743       elif [[ "$(echo $zeile | cut -c1)"  =  "%" ]]
744       then
745
746             # LINE DEFINES AN ENVIRONMENT-VARIABLE
747          zeile=$(echo $zeile | cut -c2-)
748          var=`echo $zeile | cut -d" " -f1`
749          value=`echo $zeile | cut -d" " -s -f2`
750          for_host=`echo $zeile | cut -d" " -s -f3`
751          for_cond1=`echo $zeile | cut -d" " -s -f4`
752          for_cond2=`echo $zeile | cut -d" " -s -f5`
753
754          if [[ "$for_host" = ""  ||  ( "$for_host" = $host  &&  "$for_cond1" = "$cond1"  &&  "$for_cond2" = "$cond2" )  ||  $(echo "$input_list$output_list"|grep -c "$for_host") != 0 ]]
755          then
756
757                # REPLACE ":" BY " " IN COMPILER- CPP- OR LINKER-OPTIONS,
758                # "::" IS REPLACED BY ":".
759             value=`echo $value | sed 's/::/%DUM%/g' | sed 's/:/ /g' | sed 's/%DUM%/:/g'`
760
761
762                # VALUE FROM THE CONFIGURATION-FILE IS ASSIGNED TO THE
763                # ENVIRONMENT-VARIABLE, BUT ONLY IF NO VALUE HAS BEEN ALREADY
764                # ASSIGNED WITHIN THIS SCRIPT (E.G. BY SCRIPT-OPTIONS).
765                # NON-ASSIGNED VARIABLES HAVE VALUE "" OR 0 (IN CASE OF INTEGER).
766                # HENCE THE GENERAL RULE IS: SCRIPT-OPTION OVERWRITES THE
767                # CONFIGURATION-FILE.
768             if [[ "$(eval echo \$$var)" = ""  ||  "$(eval echo \$$var)" = "0" ]]
769             then
770                eval  $var=\$value
771
772                   # TERMINAL OUTPUT OF ENVIRONMENT-VARIABLES, IF TRACEBACK IS SWITCHED on
773                if [[ $do_trace = true ]]
774                then
775                   printf "\n*** ENVIRONMENT-VARIABLE $var = $value"
776                fi
777             fi
778
779                # IF AN ENVIRONMENT-VARIABLE DETERMINES THE HOST, THEN EVALUATE IT IMMEDIATELY:
780                # VALUE OF do-remote IS REQUIRED FOR THE FILE CONNECTIONS (COPY OF I/O FILES).
781                # IF EXECUTION IS SCHEDULED FOR A REMOTE-MASCHINE, A BATCH-JOB
782                # MUST HAVE TO BE STARTED
783             if [[ $var = host ]]
784             then
785                if [[ -n $host  &&  "$host" != $localhost ]]
786                then
787                   do_batch=true
788                   do_remote=true
789                   case  $host  in
790                       (ibm|ibmh|ibmkisti|ibmku|ibms|lcbullhh|lccrayb|lccrayh|lccrayf|lcflow|lckyoto|nech|unics|lcxe6|lcxt5m|lck|lckiaps|lckordi|lckyuh|lckyut|lcsb)  true;;
791                       (*)  printf "\n  +++ sorry: execution of batch jobs on remote host \"$host\""
792                            printf "\n      is not available"
793                            locat=nqs; exit;;
794                   esac
795                else
796                   host=$localhost
797                fi
798             fi
799
800                # USER-DEFINED ENVIRONMENT VARIABLES MUST BE EXPORTED,
801                # BECAUSE THEY MAY BE REQUIRED IN OTHER SCRIPTS CALLED
802                # BY MRUN (E.G. subjob)
803             export  $var
804          fi
805
806
807
808
809       elif [[ "$(echo $zeile | cut -c1-3)" = "EC:" ]]
810       then
811
812             # LINE DEFINES ERROR-COMMAND
813          (( iec = iec + 1 ))
814          zeile=$(echo $zeile | cut -c4-)
815          err_command[$iec]="$zeile"
816
817       elif [[ "$(echo $zeile | cut -c1-3)" = "IC:" ]]
818       then
819
820             # LINE DEFINES INPUT-COMMAND
821          (( iic = iic + 1 ))
822          zeile=$(echo $zeile | cut -c4-)
823          in_command[$iic]="$zeile"
824
825       elif [[ "$(echo $zeile | cut -c1-3)" = "OC:" ]]
826       then
827
828             # LINE DEFINES OUTPUT-COMMAND
829          (( ioc = ioc + 1 ))
830          zeile=$(echo $zeile | cut -c4-)
831          out_command[$ioc]="$zeile"
832
833       else
834
835             # LINE DEFINES FILE CONNECTION. READ THE FILE ATTRIBUTES.
836             # s2a: in/out - field
837             # s2b: loc    - field (optional)
838             # s2c: tr/ar  - field (optional)
839          s1=`echo $zeile | cut -d" " -f1`
840          s2=`echo $zeile | cut -d" " -s -f2`
841          s2a=$(echo $s2 | cut -d":" -f1)
842          if [[ $(echo $s2 | grep -c ":") = 0 ]]
843          then
844             s2b=""
845             s2c=""
846          else
847             s2b=`echo $s2 | cut -d":" -f2 | sed 's/:/ /g'`
848             s2c=`echo $s2 | cut -d":" -s -f3 | sed 's/:/ /g'`
849          fi
850          s3=`echo $zeile | cut -d" " -f3`
851          s4=`echo $zeile | cut -d" " -s -f4`
852          s5=`echo $zeile | cut -d" " -s -f5`
853          s6=`echo $zeile | cut -d" " -s -f6`
854
855       
856             # STORE FILE CONNECTION, IF ACTIVATED BY ACTIVATION-STRING FROM
857             # INPUT- OR OUTPUT-LIST.
858             # VARIABLE S3 MAY CONTAIN A LIST OF ACTIVATION STRINGS (FIELD-SEPERATOR ":").
859             # IF EXECUTION IS SCHEDULED FOR A REMOTE-MACHINE AND THE FILE IS ONLY
860             # LOCALLY REQUIRED ON THAT MACHINE (I.E. s2b = loc), THE FILE CONNECTION
861             # IS NOT CHECKED AND STORED.
862          IFSALT="$IFS"; IFS="$IFS:"
863          if [[ "$s2a" = in  &&  ! ( $do_remote = true  &&  ( "$s2b" = loc  ||  "$s2b" = locopt ) ) ]]
864          then
865             found=false
866             for  actual  in  $input_list
867             do
868                for  formal  in  $s3
869                do
870                   [[ $actual = $formal  ||  "$formal" = "-" ]]  &&  found=true
871                done
872             done
873             if [[ $found = true ]]
874             then
875                (( iin = iin + 1 ))
876                localin[$iin]=$s1; transin[$iin]=$s2b; actionin[$iin]=$s2c;
877                typein[$iin]=$s3; pathin[$iin]=$s4; endin[$iin]=$s5;
878                extin[$iin]=$s6
879             fi
880          elif [[ "$s2a" = out  &&  ! ( $do_remote = true  &&  "$s2b" = loc ) ]]
881          then
882             found=false
883             for  actual  in  $output_list
884             do
885                for  formal  in  $s3 
886                do
887                   [[ $actual = $formal  ||  "$formal" = "-"  ]]  &&  found=true
888                done
889             done
890             if [[ $found = true ]]
891             then
892                (( iout = iout + 1 ))
893                localout[$iout]=$s1; actionout[$iout]=$s2c; typeout[$iout]=$s3;
894                pathout[$iout]=$s4; endout[$iout]=$s5; extout[$iout]=$s6
895             fi
896          elif [[ "$s2a" != in  &&  "$s2a" != out ]]
897          then
898             printf "\n  +++ I/O-attribute in configuration file $config_file has the invalid"
899             printf "\n      value \"$s2\". Only \"in\" and \"out\" are allowed!"
900             locat=connect; exit
901          fi
902          IFS="$IFSALT"
903       fi
904    done < $config_file
905
906 else
907
908       # EVALUATE THE CONFIGURATION-FILE BY FORTRAN-PROGRAM
909    [[ $silent = false ]]  &&  printf "..."
910    interpreted_config_file=.icf.$RANDOM
911
912
913
914       # PROVIDE VALUES OF ENVIRONMENT-VARIABLE FOR interpret_config VIA NAMELIST-FILE
915    cat  >  .mrun_environment  <<  %%END%%
916 &mrun_environment  cond1 = '$cond1', cond2 = '$cond2',
917                    config_file = '$config_file', do_remote = '$do_remote',
918                    do_trace = '$do_trace', host = '$host',
919                    input_list = '$input_list', icf = '$interpreted_config_file',
920                    localhost = '$localhost', output_list = '$output_list' /
921
922%%END%%
923
924    if [[ "$host" != $localhost ]]
925    then
926
927          # REMOTE JOB FROM LOCAL HOST: JUST TAKE THE FIRST EXECUTABLE FOUND
928       interpret_config_executable=`ls -1 ${PALM_BIN}/interpret_config*.x 2>/dev/null`
929       if [[ $? != 0 ]]
930       then
931          printf "\n\n  +++ no interpret_config found"
932          printf "\n      run \"mbuild -u -h ...\" to generate utilities for this host"
933          locat=interpret_config; exit
934       fi
935       interpret_config_executable=`echo $interpret_config_executable | cut -d" " -f1`
936       $interpret_config_executable
937
938    else
939
940          # CHECK, IF THERE IS AN EXECUTABLE FOR THE BLOCK
941       if [[ ! -f ${PALM_BIN}/interpret_config${block}.x ]]
942       then
943          printf "\n\n  +++ no interpret_config found for given block \"$cond1 $cond2\""
944          printf "\n      run \"mbuild -u -h ...\" to generate utilities for this block"
945          locat=interpret_config; exit
946       else
947          interpret_config${block}.x
948       fi
949
950    fi
951    rm .mrun_environment
952
953
954       # EXECUTE SHELL-COMMANDS GENERATED BY interpret_config WITHIN THIS SHELL
955    chmod  u+x  $interpreted_config_file
956    export PATH=$PATH:.
957    . $interpreted_config_file
958    rm  $interpreted_config_file
959
960 fi
961
962
963    # VALUES OF MRUN-OPTIONS OVERWRITE THOSE FROM THE CONFIGURATION-FILE
964 [[ $mrun_memory     != 0   ]]  &&  memory=$mrun_memory
965 [[ "$mrun_group_number" != "none" ]]  &&  group_number=$mrun_group_number
966 [[ $mrun_cpumax     != 0   ]]  &&  cpumax=$mrun_cpumax
967 [[ "$mrun_numprocs" != ""  ]]  &&  numprocs=$mrun_numprocs
968 [[ "$max_par_io_str" != "" ]]  &&  maximum_parallel_io_streams=$max_par_io_str
969 [[ "$mrun_tasks_per_node" != "" ]]  &&  tasks_per_node=$mrun_tasks_per_node
970
971
972    # ON THE LOCAL MACHINE, DETERMINE (FROM THE CONFIGURATION-FILE) THE PATH
973    # FOR SOURCE-FILES TO BE COMPILED.
974    # IN A BATCH-JOB, SOURCES (ROUTINES TO BE COMPILED) ARE COMPLETE ALREADY.
975    # BEFORE MRUN IS CALLED IN THE JOB, SOURCES_COMPLETE = true IS ASSIGNED (SEE FURTHER BELOW).
976 if [[ "$SOURCES_COMPLETE" = "" ]]
977 then
978
979       # FIRST CHECK, IF A GLOBAL SOURCE PATH (TO BE USED FOR ALL HOSTS)
980       # HAS BEEN DEFINED
981    source_path=""
982    line=""
983    grep "%source_path" $config_file  >  tmp_mrun
984    while read line
985    do
986       if [[ "$line" != ""  &&  $(echo $line | cut -c1) != "#" ]]
987       then
988          if [[ "$(echo $line | cut -d" " -f3)" = "" ]]
989          then
990             global_source_path=`echo $line | cut -d" " -f2`
991          fi
992       fi
993    done  <  tmp_mrun
994
995    line=""
996    found=false
997    grep  " $localhost" $config_file | grep "%source_path"  >  tmp_mrun
998    while read line
999    do
1000       if [[ "$line" != ""  &&  $(echo $line | cut -c1) != "#" ]]
1001       then
1002          if [[ $found = true ]]
1003          then
1004             printf "\n\n  +++ more than one source path found in configuration file"
1005             printf "\n      for local host \"$localhost\" "
1006             locat=source_path; exit
1007          fi
1008          source_path=`echo $line | cut -d" " -f2`
1009          found=true
1010       fi
1011    done  <  tmp_mrun
1012    rm  tmp_mrun
1013
1014    if [[ "$source_path" = "" ]]
1015    then
1016       if [[ "$global_source_path" != "" ]]
1017       then
1018          source_path=$global_source_path
1019       else
1020          printf "\n\n  +++ no source path found in configuration file"
1021          printf "\n      for local host \"$localhost\" "
1022          locat=source_path; exit
1023       fi
1024    fi
1025    eval source_path=$source_path
1026
1027    if [[ ! -d $source_path ]]
1028    then
1029       printf "\n\n  +++ source path \"$source_path\" on local host"
1030       printf "\n      \"$localhost\" does not exist"
1031       locat=source_path; exit
1032    fi
1033
1034 fi
1035
1036
1037    # GET THE GLOBAL REVISION-NUMBER OF THE SVN-REPOSITORY
1038    # (HANDED OVER TO RESTART-RUNS USING OPTION -G)
1039 if [[ "$global_revision" = ""  &&  $host != "ibmkisti" ]]
1040 then
1041    global_revision=`svnversion $source_path  2>/dev/null`
1042    global_revision="Rev: $global_revision"
1043 fi
1044
1045
1046    # ??? das darf doch eigentlich garnicht passieren, weil optionen config-datei uebersteuern ???
1047    # CHECK AGAIN, IF EXECUTION SHALL BE DONE ON A REMOTE-HOST (BATCH-JOB).
1048    # (HOST MAY HAVE CHANGED DUE TO SETTINGS IN THE CONFIGURATION-FILE)
1049 if [[ -n $host  &&  "$host" != $localhost ]]
1050 then
1051    do_batch=true
1052    do_remote=true
1053    case  $host  in
1054        (ibm|ibmh|ibmkisti|ibmku|ibms|lcbullhh|lccrayb|lccrayh|lccrayf|lcflow|lckyoto|nech|unics|lcxe6|lcxt5m|lck|lckiaps|lckordi|lckyuh|lckyut|lcsb)  true;;
1055        (*)  printf "\n"
1056             printf "\n  +++ sorry: execution of batch jobs on remote host \"$host\""
1057             printf "\n      is not available"
1058             locat=nqs; (( iec = 0 )); exit;;
1059    esac
1060 else
1061    host=$localhost
1062 fi
1063
1064
1065
1066    # IN CASE OF PARALLEL EXECUTION, CHECK SOME SPECIFICATIONS CONCERNING PROCESSOR NUMBERS
1067 if [[ "$cond1" = parallel  ||  "$cond2" = parallel ]]
1068 then
1069
1070       # CHECK, IF NUMBER OF CORES TO BE USED HAS BEEN GIVEN
1071    if [[ ! -n $numprocs ]]
1072    then
1073       printf "\n"
1074       printf "\n  +++ option \"-K parallel\" requires additional specification"
1075       printf "\n      of the number of processors to be used by"
1076       printf "\n      mrun-option \"-X\" or by environment-variable"
1077       printf "\n      \"numprocs\" in the configuration file"
1078       locat=numprocs; (( iec = 0 )); exit
1079    fi
1080
1081       # CHECK, IF THE NUMBER OF CORES PER NODE HAS BEEN GIVEN UND IF IT IS AN
1082       # INTEGRAL DIVISOR OF THE TOTAL NUMBER OF CORES GIVEN BY OPTION -X
1083    if [[ "$tasks_per_node" = ""  &&  $host != lcflow  &&  $host != lcxt5m ]]
1084    then
1085       printf "\n"
1086       printf "\n  +++ option \"-T\" (tasks per node) is missing"
1087       printf "\n      set -T option or define tasks_per_node in the config file"
1088       locat=tasks_per_node; (( iec = 0 )); exit
1089    fi
1090
1091    if (( numprocs < tasks_per_node ))
1092    then
1093       printf "\n"
1094       printf "\n  +++ tasks per node (-T) cannot exceed total number of processors (-X)"
1095       printf "\n      given values: -T $tasks_per_node  -X $numprocs"
1096       locat=tasks_per_node; (( iec = 0 )); exit
1097    fi
1098
1099    if [[ $host != lcflow  &&  $host != lcxt5m ]]
1100    then
1101       (( nodes = numprocs / ( tasks_per_node * threads_per_task ) ))
1102       (( ival = $tasks_per_node ))
1103       (( pes = numprocs ))
1104       (( ii = pes / ival ))
1105       (( remaining_pes =  pes - ii * ival ))
1106       if (( remaining_pes > 0 ))
1107       then
1108          printf "\n"
1109          printf "\n  +++ WARNING: tasks per node (option \"-T\") is not an integral"
1110          printf "\n      divisor of the total number of processors (option \"-X\")"
1111          printf "\n      values of this mrun-call: \"-T $tasks_per_node\" \"-X $numprocs\""
1112          printf "\n      One of the nodes is filled with $remaining_pes instead of $tasks_per_node tasks"
1113          (( nodes = nodes + 1 ))
1114       fi
1115    fi
1116
1117
1118       # SETTINGS FOR SUBJOB-COMMAND
1119    OOPT="-O $threads_per_task"
1120
1121       # SET THE TOTAL NUMBER OF NODES, REQUIRED FOR THE SUBJOB-COMMAND (SEE FURTHER BELOW)
1122    if [[ "$tasks_per_node" != "" ]]
1123    then
1124       TOPT="-T $tasks_per_node"
1125    fi
1126
1127       # CHECK node_usage FOR ALLOWED VALUES AND SET DEFAULT VALUE, IF NECESSARY
1128    if [[ $node_usage = default ]]
1129    then
1130       if [[ $host = ibms ]]
1131       then
1132          node_usage=shared
1133       else
1134          node_usage=not_shared
1135       fi
1136    fi
1137
1138    if [[ $node_usage != shared  &&  $node_usage != not_shared  &&  $node_usage != singlejob  &&  "$(echo $node_usage | cut -c1-3)" != "sla" ]]
1139    then
1140       printf "\n"
1141       printf "\n  +++ node usage (option \"-n\") is only allowed to be set"
1142       printf "\n      \"shared\" or \"not_shared\""
1143       locat=tasks_per_node; (( iec = 0 )); exit
1144    fi
1145
1146 fi
1147
1148    # CHECK IF HOSTFILE EXISTS
1149 if [[ -n $hostfile ]]
1150 then
1151    if [[ ! -f $hostfile ]]
1152    then
1153       printf "\n"
1154       printf "\n  +++ hostfile \"$hostfile\" does not exist"
1155       locat=hostfile; exit
1156    fi
1157 fi
1158
1159
1160    # SET DEFAULT VALUE FOR THE MAXIMUM NUMBER OF PARALLEL IO STREAMS
1161 if [[ "$maximum_parallel_io_streams" = "" ]]
1162 then
1163    maximum_parallel_io_streams=$numprocs
1164 fi
1165
1166
1167    # SET PORT NUMBER OPTION FOR CALLS OF SSH/SCP, subjob AND batch_scp SCRIPTS
1168 if [[ "$scp_port" != "" ]]
1169 then
1170    PORTOPT="-P $scp_port"
1171    SSH_PORTOPT="-p $scp_port"
1172 fi
1173
1174
1175    # SET DEFAULT-QUEUE, IF NOT GIVEN
1176 if [[ $queue = none ]]
1177 then
1178    case  $host  in
1179        (ibmh)       queue=cluster;;
1180        (ibmkisti)   queue=class.32plus;;
1181        (lcbullhh)   queue=compute;;
1182        (lccrayb)    queue=mpp1q;;
1183        (lccrayh)    queue=mpp1q;;
1184        (lckiaps)    queue=normal;;
1185        (lckyoto)    queue=ph;;
1186        (lckyuh)     queue=fx-single;;
1187        (lckyut)     queue=cx-single;;
1188        (lctit)      queue=S;;
1189        (nech)       queue=none;;
1190        (unics)      queue=unics;;
1191    esac
1192 fi
1193
1194
1195    # GENERATE FULL FILENAMES OF INPUT-FILES, INCLUDING THEIR PATH
1196    # CHECK, IF INPUT-FILES EXIST, AND DETERMINE HIGHEST CYCLE NUMBER (IF CYCLES EXIST)
1197 (( i = 0 ))
1198 while (( i < iin ))
1199 do
1200    (( i = i + 1 ))
1201    (( maxcycle = 0 ))
1202
1203       # GENERATE PATH AND FULL FILE NAME (then-BRANCH: FIXED FULL NAME IS GIVEN, I.E. THE
1204       # FILE IDENTIFIER IS NOT PART OF THE FILENAME))
1205    if [[ "${actionin[$i]}" = di ]]
1206    then
1207       remotepathin[$i]=${pathin[$i]}/${endin[$i]}  # EVALUATE REMOTE-PATH ON THE REMOTE
1208                                                    # HOST ONLY
1209       eval filename=${pathin[$i]}/${endin[$i]}
1210    else
1211       remotepathin[$i]=${pathin[$i]}/${afname}${endin[$i]}  # EVALUATE REMOTE-PATH ON THE REMOTE
1212                                                             # HOST ONLY
1213       eval filename=${pathin[$i]}/${afname}${endin[$i]}
1214    fi
1215    eval pathname=${pathin[$i]}
1216
1217       # CHECK IF FILE EXISTS
1218    if [[ $(ls $filename* 2>&1 | grep -c "not found") = 1  || \
1219          $(ls $filename* 2>&1 | grep -c "nicht gefunden") = 1  || \
1220          $(ls $filename* 2>&1 | grep -c "No such file") = 1  || \
1221          $(ls $filename* 2>&1 | grep -c "does not exist") = 1 ]]
1222    then
1223
1224          # FILES WITH ATTRIBUTE locopt ARE OPTIONAL. NO ABORT, IF THEY DO NOT EXIST.
1225       if [[ "${transin[$i]}" != "locopt" ]]
1226       then
1227          printf "\n\n  +++ INPUT-file: "
1228          if [[ "${extin[$i]}" = "" ]]
1229          then
1230             printf "\n           $filename"
1231          else
1232             printf "\n           $filename.${extin[$i]}"
1233          fi
1234          printf "\n      does not exist\n"
1235          locat=input; exit
1236       else
1237          transin[$i]="unavailable"
1238       fi
1239    else
1240
1241          # DETERMINE THE FILE'S CYCLE NUMBER
1242       ls -1 -d $filename    >   filelist  2>/dev/null
1243       ls -1 -d $filename.*  >>  filelist  2>/dev/null
1244       while  read zeile
1245       do
1246          cycle=$(echo $zeile | cut -f2 -d".")
1247          if [[ "$cycle" = "$zeile" ]]
1248          then
1249             (( icycle = 0 ))
1250          elif [[ "$cycle" = "${extin[$i]}" ]]
1251          then
1252             (( icycle = 0 ))
1253          else
1254             (( icycle = $cycle ))
1255          fi
1256          if (( icycle > maxcycle ))
1257          then
1258             (( maxcycle = icycle ))
1259             file_to_be_used=$zeile
1260          fi
1261       done <filelist
1262       rm filelist
1263
1264          # APPEND CYCLE NUMBER TO FILENAME
1265       if (( maxcycle > 0 ))
1266       then
1267          if [[ "${extin[$i]}" != " "  &&   "${extin[$i]}" != "" ]]
1268          then
1269             filename=${filename}.$maxcycle.${extin[$i]}
1270          else
1271             filename=${filename}.$maxcycle
1272          fi
1273       else
1274          if [[ "${extin[$i]}" != " "  &&   "${extin[$i]}" != "" ]]
1275          then
1276             filename=${filename}.${extin[$i]}
1277          fi
1278       fi
1279       
1280          # STORE FILENAME WITHOUT PATH BUT WITH CYCLE NUMBER,
1281          # BECAUSE IT MIGHT BE REQUIRED LATER TO RESTORE THE FILE FROM AN ARCHIVE-SYSTEM
1282       absnamein[$i]=$filename
1283       if (( maxcycle > 0 ))
1284       then
1285          if [[ "${actionin[$i]}" = di ]]
1286          then
1287             frelin[$i]=${endin[$i]}.$maxcycle
1288          else
1289             frelin[$i]=${afname}${endin[$i]}.$maxcycle
1290          fi
1291       else
1292          if [[ "${actionin[$i]}" = di ]]
1293          then
1294             frelin[$i]=${endin[$i]}
1295          else
1296             frelin[$i]=${afname}${endin[$i]}
1297          fi
1298       fi
1299
1300    fi
1301 done
1302   
1303    # GENERATE FULL FILENAMES OF OUTPUT-FILES (WITHOUT $ OR ~),
1304    # CHECK, IF OUTPUT-FILES EXIST, AND DETERMINE HIGHEST CYCLE NUMBER (IF CYCLES EXIST),
1305    # OR, IN CASE THAT FILE DOES NOT EXIST, CHECK, IF IT CAN BE CREATED 
1306    # THESE ACTIONS ARE NOT CARRIED OUT, IF FILES SHALL BE TRASFERRED FROM THE REMOTE TO
1307    # THE LOCAL HOST (BECAUSE THEIR IS NO DIRECT ACCESS TO THE LOCAL DIRECTORIES FROM THE
1308    # REMOTE HOST)
1309 (( i = 0 ))
1310 while (( i < iout ))
1311 do
1312    (( i = i + 1 ))
1313    if [[ ! ( $fromhost != $localhost  &&  ( "${actionout[$i]}" = tr || "${actionout[$i]}" = tra || "${actionout[$i]}" = trpe ) ) ]]
1314    then
1315       if [[ "${actionout[$i]}" = tr ]]
1316       then
1317          actionout[$i]=""
1318       elif [[ "${actionout[$i]}" = trpe ]]
1319       then
1320          actionout[$i]=pe
1321       elif [[ "${actionout[$i]}" = tra ]]
1322       then
1323          actionout[$i]=a
1324       fi
1325       (( maxcycle = 0 ))
1326       eval filename=${pathout[$i]}/${fname}${endout[$i]}
1327       eval catalogname=${pathout[$i]}
1328       if [[ $(ls $filename* 2>&1 | grep -c "not found") = 1  || \
1329             $(ls $filename* 2>&1 | grep -c "nicht gefunden") = 1  || \
1330             $(ls $filename* 2>&1 | grep -c "No such file") = 1  || \
1331             $(ls $filename* 2>&1 | grep -c "does not exist") = 1 ]]
1332       then
1333     
1334             # IF OUTPUT-FILE DOES NOT EXIST CHECK, IF IT CAN BE CREATED
1335          if  cat /dev/null > $filename 
1336          then
1337             rm  $filename
1338          else
1339
1340                # CHECK, IF THE DIRECTORY WHERE FILE SHALL BE COPIED TO EXISTS
1341                # IF IT DOES NOT EXIST, TRY TO CREATE IT
1342             if [[ ! -d $catalogname ]]
1343             then
1344                if  mkdir -p  $catalogname
1345                then
1346                   printf "\n\n  *** directory:"
1347                   printf "\n           $catalogname"
1348                   printf "\n      was created\n"
1349                else
1350                   printf "\n\n  +++ OUTPUT-file:"
1351                   printf "\n           $filename"
1352                   printf "\n      cannot be created, because directory does not exist"
1353                   printf "\n      and cannot be created either"
1354                   printf "\n"
1355                   locat=output  ; exit
1356                fi 2>/dev/null
1357             else
1358                printf "\n\n  +++ OUTPUT-file:"
1359                printf "\n           $filename"
1360                printf "\n      cannot be created, although directory exists"
1361                printf "\n"
1362                locat=output  ; exit
1363             fi
1364          fi 2>/dev/null
1365       else
1366
1367             # DETERMINE THE CYCLE NUMBER
1368          ls -1 -d $filename    >   filelist  2>/dev/null
1369          ls -1 -d $filename.*  >>  filelist  2>/dev/null
1370          while  read zeile
1371          do
1372             cycle=$(echo $zeile | cut -f2 -d".")
1373             if [[ "$cycle" = "$zeile"  ||  "$cycle" = ${extout[$i]} ]]
1374             then
1375                (( icycle = 1 ))
1376             else
1377                (( icycle = $cycle + 1 ))
1378             fi
1379             if (( icycle > maxcycle ))
1380             then
1381                (( maxcycle = icycle ))
1382             fi
1383          done <filelist
1384          rm filelist
1385       fi
1386
1387          # APPEND CYCLE NUMBER TO FILENAME AND CHECK, IF FILE CAN BE CREATED
1388          # IN CASE OF FILE-APPEND, FILE MUST BE APPENDED TO THE ONE WITH HIGHEST CYCLE NUMBER
1389       if [[ "${actionout[$i]}" != a ]]
1390       then
1391          if (( maxcycle > 0 ))
1392          then
1393             filename=${filename}.$maxcycle
1394             if  cat /dev/null > $filename 
1395             then
1396                rm  $filename
1397             else
1398                printf "\n  +++ OUTPUT-file:"
1399                printf "\n           $filename"
1400                printf "\n      cannot be created"
1401                locat=output  ; exit
1402             fi
1403          fi
1404       else
1405          (( maxcycle = maxcycle - 1 ))
1406          if (( maxcycle > 0 ))
1407          then
1408             filename=${filename}.$maxcycle
1409          fi
1410       fi
1411       
1412          # STORE FILENAME WITHOUT PATH BUT WITH CYCLE NUMBER,
1413          # BECAUSE IT MIGHT BE REQUIRED LATER TO STORE THE FILE ON AN ARCHIVE-SYSTEM
1414          # OR TO PUT THIS FILENAME ON FILE OUTPUT_FILE_CONNECTIONS
1415       pathout[$i]=$filename
1416       if (( maxcycle > 0 ))
1417       then
1418          frelout[$i]=${fname}${endout[$i]}.$maxcycle
1419       else
1420          frelout[$i]=${fname}${endout[$i]}
1421       fi
1422
1423    fi
1424 done
1425
1426
1427     # THE DVR-PACKAGE REQUIRES ITS OWN LIBRARY
1428 if [[ $(echo $package_list | grep -c dvrp_graphics) != 0 ]]
1429 then
1430    if [[ "$dvr_inc" = "" ]]
1431    then
1432       printf "\n\n  +++ no value for \"dvr_inc\" given in configuration file"
1433       printf "\n      This is required for the dvrp_graphics package.\n"
1434       locat=dvr; exit
1435    fi
1436    if [[ "$dvr_lib" = "" ]]
1437    then
1438       printf "\n\n  +++ no value for \"dvr_lib\" given in configuration file"
1439       printf "\n      This is required for the dvrp_graphics package.\n"
1440       locat=dvr; exit
1441    fi
1442 fi
1443
1444
1445     # CHECK, WETHER A MAIN PROGRAM OR AN EXECUTABLE HAVE BEEN DECLARED.
1446     # EXECUTABLES DO NOT NEED TO BE COMPILED.
1447 if [[ "$mainprog" = ""  &&  "$executable" = "" ]]
1448 then
1449    printf "\n  +++ neither main program nor executable defined"
1450    locat=source; exit
1451 elif [[ "$mainprog" != ""  &&  "$executable" != "" ]]
1452 then
1453    printf "\n  +++ main program as well as executable defined"
1454    locat=source; exit
1455 elif [[ "$mainprog" = ""  &&  "$executable" != "" ]]
1456 then
1457    do_compile=false
1458 fi
1459
1460
1461    # CREATE SOURCE-DIRECTORY TO COLLECT ROUTINES TO BE COMPILED.
1462    # LATER THE MRUN-SCRIPT AND CONFIGURATION-FILE WILL ALSO BE COPIED TO THIS DIRECTORY.
1463 if [[ $restart_run != true  &&  "$SOURCES_COMPLETE" = "" ]]
1464 then
1465    rm -rf  SOURCES_FOR_RUN_$fname
1466    mkdir   SOURCES_FOR_RUN_$fname
1467 fi
1468
1469
1470    # COLLECT ALL ROUTINES TO BE COMPILED
1471    # THIS IS NOT REQUIRED WITHIN BATCH-JOBS, BECAUSE ROUTINES HAVE ALREADY BEEN COLLECTED
1472    # BY THE MRUN-CALL WHICH CREATED THE BATCH-JOB.
1473 if [[ $do_compile = true  &&  "$SOURCES_COMPLETE" = "" ]]
1474 then
1475
1476    [[ "$source_list" = LM ]]  &&  source_list=LOCALLY_MODIFIED
1477
1478    if [[ "$source_list" = LOCALLY_MODIFIED ]]
1479    then
1480
1481          # DETERMINE MODIFIED FILES OF THE SVN WORKING COPY
1482       source_list=""
1483       cd  $source_path
1484
1485
1486          # CHECK, IF DIRECTORY IS UNDER SVN CONTROL
1487       if [[ ! -d .svn ]]
1488       then
1489          printf "\n\n  +++ source directory"
1490          printf "\n         \"$source_path\" "
1491          printf "\n         is not under control of \"subversion\"."
1492          printf "\n         Please do not use mrun-option \"-s LOCALLY_MODIFIED\"\n"
1493       fi
1494
1495
1496          # LIST ALL MODIFIED SOURCE CODE FILES
1497       Filenames=""
1498       svn status  >  tmp_mrun
1499       while  read line
1500       do
1501          firstc=`echo $line | cut -c1`
1502          if [[ $firstc = M  ||  $firstc = "?" ]]
1503          then
1504             Name=`echo "$line" | cut -c8-`
1505             extension=`echo $Name | cut -d. -f2`
1506             if [[ "$extension" = f90 || "$extension" = F90 || "$extension" = f || "$extension" = F || "$extension" = c ]]
1507             then
1508                Filenames="$Filenames "$Name
1509             fi
1510          fi
1511       done < tmp_mrun
1512
1513
1514          # COPY FILES TO SOURCES_FOR_RUN_...
1515       for  dateiname  in  $Filenames
1516       do
1517          cp  $dateiname  $working_directory/SOURCES_FOR_RUN_$fname
1518          source_list=$source_list"$dateiname "
1519       done
1520
1521       cd -  > /dev/null
1522
1523
1524       # COPY FILES GIVEN BY OPTION -s TO DIRECTORY SOURCES_FOR_RUN_...
1525       # AUTOMATIC RESTART RUNS JUST ACCESS THE DIRECTORY CREATED BY THE INITIAL RUN
1526    elif [[ "$source_list" != ""  &&  $restart_run != true ]]
1527    then
1528
1529       cd  $source_path
1530
1531       for  filename  in  $source_list
1532       do
1533
1534             # SOURCE CODE FILE IS NOT ALLOWED TO INCLUDE PATH
1535          if [[ $(echo $filename | grep -c "/") != 0 ]]
1536          then
1537             printf "\n  +++ source code file:  $filename"
1538             printf "\n      must not contain (\"/\") "
1539             locat=source; exit
1540          fi
1541
1542          if [[ ! -f $filename ]]
1543          then
1544             printf "\n  +++ source code file:  $filename"
1545             printf "\n      does not exist"
1546             locat=source; exit
1547          else
1548             cp  $filename  $working_directory/SOURCES_FOR_RUN_$fname
1549          fi
1550
1551       done
1552
1553       cd -  > /dev/null
1554
1555    fi
1556
1557
1558       # CHECK, IF A MAIN PROGRAM EXISTS AND IF IT IS PART OF THE LIST OF FILES
1559       # TO BE COMPILED. IF NOT, ADD IT TO THE LIST.
1560    if [[ $restart_run != true ]]
1561    then
1562
1563       if [[ ! -f "$source_path/$mainprog" ]]
1564       then
1565          printf "\n\n  +++ main program:  $mainprog"
1566          printf "\n      does not exist in source directory"
1567          printf "\n      \"$source_path\"\n"
1568          locat=source; exit
1569       else
1570          if [[ $(echo $source_list | grep -c $mainprog) = 0 ]]
1571          then
1572             cp  $source_path/$mainprog  SOURCES_FOR_RUN_$fname
1573             source_list=${mainprog}" $source_list"
1574          fi
1575       fi
1576    fi
1577
1578
1579       # CHECK, IF MAKEFILE EXISTS AND COPY IT TO THE SOURCES_FOR_RUN... DIRECTORY
1580       # NOT REQUIRED FOR RESTART RUNS, SOURCES_FOR_RUN... HAS BEEN CREATED BY THE INITIAL RUN
1581    if [[ "$restart_run" != true ]]
1582    then
1583       [[ "$makefile" = "" ]]  &&  makefile=$source_path/Makefile
1584       if [[ ! -f $makefile ]]
1585       then
1586          printf "\n  +++ file \"$makefile\" does not exist"
1587          locat=make; exit
1588       else
1589          cp  $makefile  SOURCES_FOR_RUN_$fname/Makefile
1590       fi
1591    fi
1592
1593
1594       # COPY FILES FROM OPTIONAL SOURCE PATH GIVEN IN THE CONFIGURATION FILE
1595    if [[ $restart_run != true  &&  "$add_source_path" != "" ]]
1596    then
1597
1598          # DOES THE DIRECTORY EXIST?
1599       if [[ ! -d $add_source_path ]]
1600       then
1601          printf "\n\n  *** INFORMATIVE: additional source code directory"
1602          printf "\n      \"$add_source_path\" "
1603          printf "\n      does not exist or is not a directory."
1604          printf "\n      No source code will be used from this directory!\n"
1605          add_source_path=""
1606          if [[ $silent == false ]]
1607          then
1608             sleep 3
1609          fi
1610       else
1611
1612          cd $add_source_path
1613          found=false
1614
1615          Names=$(ls -1 *.f90 2>&1)
1616          [[ $(echo $Names | grep -c '*.f90') = 0 ]]  &&  AddFilenames="$Names"
1617          Names=$(ls -1 *.F90 2>&1)
1618          [[ $(echo $Names | grep -c '*.F90') = 0 ]]  &&  AddFilenames="$AddFilenames $Names"
1619          Names=$(ls -1 *.F 2>&1)
1620          [[ $(echo $Names | grep -c '*.F') = 0   ]]  &&  AddFilenames="$AddFilenames $Names"
1621          Names=$(ls -1 *.f 2>&1)
1622          [[ $(echo $Names | grep -c '*.f') = 0   ]]  &&  AddFilenames="$AddFilenames $Names"
1623          Names=$(ls -1 *.c 2>&1)
1624          [[ $(echo $Names | grep -c '*.c') = 0   ]]  &&  AddFilenames="$AddFilenames $Names"
1625
1626          cd -  > /dev/null
1627          cd  SOURCES_FOR_RUN_$fname
1628
1629             # COPY MAKEFILE IF EXISTING
1630          if [[ -f $add_source_path/Makefile ]]
1631          then
1632             printf "\n\n  *** user Makefile from directory"
1633             printf "\n      \"$add_source_path\" is used \n"
1634             if [[ $silent == false ]]
1635             then
1636                sleep 1
1637             fi
1638             cp  $add_source_path/Makefile  .
1639          fi
1640
1641          for  dateiname  in  $AddFilenames
1642          do
1643             if [[ -f $dateiname ]]
1644             then
1645                printf "\n  +++ source code file \"$dateiname\" found in additional"
1646                printf "\n      source code directory \"$add_source_path\" "
1647                printf "\n      but was also given with option \"-s\" which means that it should be taken"
1648                printf "\n      from directory \"$source_path\"."
1649                locat=source; exit
1650             fi
1651
1652             cp  $add_source_path/$dateiname  .
1653             source_list="$source_list $dateiname"
1654
1655                # CHECK IF FILE IS CONTAINED IN MAKEFILE
1656             if [[ $(grep -c $dateiname Makefile) = 0 ]]
1657             then
1658                printf "\n\n  +++ user file \"$dateiname\" "
1659                printf "\n      is not listed in Makefile \n"
1660                locat=source; exit
1661             else
1662
1663                if [[ $found = false ]]
1664                then
1665                   found=true
1666                   printf "\n\n  *** following user file(s) added to the"
1667                   printf " files to be translated:\n      "
1668                fi
1669                printf "$dateiname  "
1670                if [[ $silent == false ]]
1671                then
1672                   sleep 0.5
1673                fi
1674
1675             fi
1676          done
1677          [[ $found = true ]]  &&  printf "\n"
1678          cd -  > /dev/null
1679       fi
1680    fi
1681
1682
1683       # ADD ALL ROUTINES BELONGING TO SOFTWARE PACKAGES (GIVEN BY OPTION -p)
1684       # TO THE LIST OF FILES TO BE COMPILED
1685    if [[ $restart_run != true  &&  -n $package_list ]]
1686    then
1687
1688       cd  $source_path
1689
1690       for  package  in  $package_list
1691       do
1692
1693          [[ $package = "dvrp_graphics+1PE" ]]  &&  package=dvrp_graphics
1694
1695             # DETERMINE FILES BELONGING TO THE PACKAGE
1696             # ERROR MESSAGE ARE REDIRECTED TO /dev/null, BECAUSE WILDCARD (*) ALSO GIVES
1697             # THE NAME OF THE DIRECTORY
1698          package_source_list=`grep "defined( __$package " * 2>/dev/null | cut -f1 -d:`
1699
1700
1701             # ADD THESE FILES TO THE LIST OF FILES TO BE COMPILED,
1702             # IF THEY ARE NOT ALREADY PART OF THE LIST
1703          for  source_list_name  in  $package_source_list
1704          do
1705             if [[ $(echo $source_list | grep -c $source_list_name) = 0 ]]
1706             then
1707
1708                    # ONLY TAKE FILES WITH VALID SUFFIX
1709                ending=`echo $source_list_name | cut -f2 -d.`
1710                if [[ "$ending" = f90  ||  "$ending" = F90  ||  "$ending" = f  ||  "$ending" = F  ||  "$ending" = c ]]
1711                then
1712                   cp  $source_list_name  $working_directory/SOURCES_FOR_RUN_$fname
1713                   source_list="$source_list $source_list_name"
1714                fi
1715             fi
1716          done
1717       done
1718
1719       cd -  > /dev/null
1720    fi
1721
1722 fi  # do_compile=true
1723
1724
1725    # IF SOURCE CODE IS TO BE COMPILED, DO SOME MORE CHECKS
1726    # AND SET PRE-PROCESSOR DIRECTIVES
1727 if [[ $do_compile = true  ||  $create_executable_for_batch = true ]]
1728 then
1729
1730       # SET PREPROCESSOR-DIRECTIVES TO SELECT OPERATING SYSTEM SPECIFIC CODE
1731    if [[ $(echo $localhost | cut -c1-3) = ibm ]]
1732    then
1733       cpp_options="${cpp_options},-D__ibm=__ibm"
1734    elif [[ $(echo $localhost | cut -c1-3) = nec ]]
1735    then
1736       cpp_options="$cpp_options -D__nec"
1737    elif [[ $(echo $localhost | cut -c1-2) = lc ]]
1738    then
1739       cpp_options="$cpp_options -D__lc"
1740    else
1741       cpp_options="$cpp_options -D__$localhost"
1742    fi
1743
1744       # SET DIRECTIVES GIVEN BY OPTION -K (E.G. parallel)
1745    if [[ $(echo $localhost | cut -c1-3) = ibm ]]
1746    then
1747       [[ -n $cond1 ]]  &&  cpp_options="${cpp_options},-D__$cond1=__$cond1"
1748       [[ -n $cond2 ]]  &&  cpp_options="${cpp_options},-D__$cond2=__$cond2"
1749    else
1750       [[ -n $cond1 ]]  &&  cpp_options="$cpp_options -D__$cond1"
1751       [[ -n $cond2 ]]  &&  cpp_options="$cpp_options -D__$cond2"
1752    fi
1753
1754       # SET DIRECTIVES FOR ACTIVATING SOFTWARE-PACKAGES (OPTION -p)
1755    if [[ -n $package_list ]]
1756    then
1757       for  package  in  $package_list
1758       do
1759          if [[ $(echo $localhost | cut -c1-3) = ibm ]]
1760          then
1761             if [[ $package != "dvrp_graphics+1PE" ]]
1762             then
1763                cpp_options="${cpp_options},-D__$package=__$package"
1764             else
1765                cpp_options="${cpp_options},-D__dvrp_graphics=__dvrp_graphics"
1766                export use_seperate_pe_for_dvrp_output=true
1767             fi
1768          else
1769             if [[ $package != "dvrp_graphics+1PE" ]]
1770             then
1771                cpp_options="$cpp_options -D__$package"
1772             else
1773                cpp_options="$cpp_options -D__dvrp_graphics"
1774                export use_seperate_pe_for_dvrp_output=true
1775             fi
1776          fi
1777       done
1778    fi
1779
1780       # SET DIRECTIVES GIVEN BY OPTION -D
1781    if [[ -n $cpp_opts ]]
1782    then
1783       for  popts  in  $cpp_opts
1784       do
1785          if [[ $(echo $localhost | cut -c1-3) = ibm ]]
1786          then
1787             cpp_options="${cpp_options},-D__$popts=__$popts"
1788          else
1789             cpp_options="$cpp_options -D__$popts"
1790          fi
1791       done
1792    fi
1793
1794 else
1795
1796
1797       # FOR LOCAL RUNS CHECK AGAIN, IF EXECUTABLE EXISTS
1798    if [[ $do_remote = false ]]
1799    then
1800       if [[ ! -f $executable ]]
1801       then
1802          printf "\n  +++ executable file:  $executable"
1803          printf "\n      does not exist"
1804          locat=executable; exit
1805       fi
1806    fi
1807 fi
1808
1809
1810    # DETERMINE THE JOB MODE
1811 if [[ $(echo $localhost | cut -c1-3) = ibm ]]
1812 then
1813    if [[ "$LOADLBATCH" = yes ]]
1814    then
1815       batch_job=.TRUE.
1816       jobmo=BATCH
1817    else
1818       batch_job=.FALSE.
1819       jobmo=INTERACTIVE
1820    fi
1821 else
1822    if [[ "$ENVIRONMENT" = BATCH ]]
1823    then
1824       batch_job=.TRUE.
1825       jobmo=BATCH
1826    else
1827       batch_job=.FALSE.
1828       jobmo=INTERACTIVE
1829    fi
1830 fi
1831
1832    # NO INTERACTIVE RUNS ALLOWED ON LCTIT
1833 if [[ $host = lctit  &&  $jobmo = INTERACTIVE  &&  $do_batch = false ]]
1834 then
1835    printf "\n  +++ no interactive runs allowed on host \"$host\" "
1836    printf "\n      please submit batch job using mrun option \"-b\" \n"
1837    locat=normal; exit
1838 fi
1839
1840
1841    # CHECK, IF USER DEFINED A COMPILER
1842 if [[ "$compiler_name" = "" ]]
1843 then
1844
1845    printf "\n  +++ no compiler specified for \"$host $cond1 $cond2\""
1846    locat=compiler_name; exit
1847
1848 fi
1849
1850
1851    # DETERMINE THE NAME OF MRUN'S TEMPORARY WORKING DIRECTORY
1852
1853    # ON HLRN-III, USE THE QUEUING NAME. OTHERWISE USE USERNAME AND RANDOM NUMBER
1854 if [[ $do_batch = false && $(echo $host | cut -c1-6) = lccray ]]
1855 then
1856    kennung=$(checkjob $PBS_JOBID | grep Reservation | cut -d" " -s -f2 | cut -d"." -s -f2 | sed "s/['\"]//g")
1857    if [[ "$kennung" = "" ]]
1858    then
1859       kennung=$RANDOM
1860    fi
1861 else
1862    kennung=$RANDOM
1863 fi
1864
1865 if [[ "$tmp_user_catalog" = "" ]]
1866 then
1867    if [[ $localhost = ibmh ]]
1868    then
1869       tmp_user_catalog=$SCRATCH
1870    elif [[ $localhost = nech ]]
1871    then
1872       tmp_user_catalog=$WRKSHR
1873    else
1874       tmp_user_catalog=/tmp
1875    fi
1876 fi
1877 TEMPDIR=$tmp_user_catalog/${usern}.$kennung
1878
1879
1880    # DETERMINE THE NAME OF THE DIRECTORY WHICH IS USED TO TEMPORARILY STORE DATA FOR RESTART RUNS
1881 if [[ "$tmp_data_catalog" = "" ]]
1882 then
1883    if [[ $localhost = nech ]]
1884    then
1885       tmp_data_catalog=$WRKSHR/mrun_restart_data
1886    else
1887       tmp_data_catalog=/tmp/mrun_restart_data
1888    fi
1889 fi
1890
1891
1892    # IN CASE OF LOCAL RUNS REPLACE ENVIRONMENT VARIABLES BY THEIR VALUES
1893 if [[ $do_remote = false  &&  $do_compile = true  ||  $create_executable_for_batch = true ]]
1894 then
1895    eval  fopts=\"$fopts\"
1896    eval  lopts=\"$lopts\"
1897 fi
1898
1899
1900    # DETERMINE COMPILE- AND LINK-OPTIONS
1901 fopts="$fopts $netcdf_inc $fftw_inc $dvr_inc"
1902 lopts="$lopts $netcdf_lib $fftw_lib $dvr_lib"
1903 XOPT="-X $numprocs"
1904
1905
1906    # CHECK THE CPU-LIMIT. IT MUST BE GIVEN FOR BATCH-JOBS AND IS COMMUNICATED TO THE
1907    # EXECUTABLE VIA NAMELIST-PARAMETER cputime
1908 done=false
1909 while [[ $done = false ]]
1910 do
1911    cputime=$cpumax
1912    if (( $cputime == 0 ))
1913    then
1914       if [[ $do_batch = true ]]
1915       then
1916          printf "\n  +++ cpu-time is undefined"
1917          printf "\n  >>> Please type CPU-time in seconds as INTEGER:"
1918          printf "\n  >>> "
1919          read  cputime  1>/dev/null  2>&1
1920       else
1921          cputime=10000000   # NO CPU LIMIT FOR INTERACTIVE RUNS
1922       fi
1923    else
1924       done=true
1925    fi
1926    cpumax=$cputime
1927 done
1928
1929 (( minuten = cputime / 60 ))
1930 (( sekunden = cputime - minuten * 60 ))
1931
1932
1933    # CHECK THE MEMORY DEMAND
1934 if [[ $do_batch = true ]]
1935 then
1936    done=false
1937    while [[ $done = false ]]
1938    do
1939       if (( memory == 0 ))
1940       then
1941          printf "\n  +++ memory demand is undefined"
1942          printf "\n  >>> Please type memory in  MByte per process  as INTEGER:"
1943          printf "\n  >>> "
1944          read  memory  1>/dev/null  2>&1
1945       else
1946          done=true
1947       fi
1948    done
1949 fi
1950
1951
1952    # IN CASE OF REMOTE-JOBS CHECK, IF A USERNAME FOR THE REMOTE HOST IS GIVEN
1953 if [[ $do_remote = true  &&  -z $remote_username ]]
1954 then
1955    while [[ -z $remote_username ]]
1956    do
1957       printf "\n  +++ username on remote host \"$host\" is undefined"
1958       printf "\n  >>> Please type username:"
1959       printf "\n  >>> "
1960       read  remote_username
1961    done
1962    mc="$mc -u$remote_username"
1963 fi
1964
1965    # CHECK FOR INITIAL COMMANDS AFTER LOGIN
1966 if [[ "$login_init_cmd" != "" ]]
1967 then
1968    export init_cmds="${login_init_cmd};"
1969 fi
1970
1971
1972    # SET THE MODULE-LOAD COMMAD AND EXPORT IT FOR subjob
1973 if [[ "$modules" != "" ]]
1974 then
1975    if [[ $host = lctit ]]
1976    then
1977       export module_calls=". $modules"
1978    else
1979       export module_calls="module load ${modules};"
1980    fi
1981 fi
1982
1983    # OUTPUT OF THE MRUN-HEADER
1984 calltime=$(date)
1985 printf "\n"
1986 printf "#------------------------------------------------------------------------# \n"
1987 printf "| %-35s%35s | \n" "$version" "$calltime"
1988 printf "|                                                                        | \n"
1989 spalte1="called on:"; spalte2=$localhost_realname
1990 printf "| %-25s%-45s | \n" "$spalte1" "$spalte2"
1991 if [[ $do_remote = true ]]
1992 then
1993    spalte1="execution on:"; spalte2="$host (username: $remote_username)"
1994 else
1995    spalte1="execution on:"; spalte2="$host ($localhost_realname)"
1996 fi
1997 printf "| %-25s%-45s | \n" "$spalte1" "$spalte2"
1998 if [[ -n $numprocs ]]
1999 then
2000    if [[ $run_coupled_model = false ]]
2001    then
2002       spalte1="number of PEs:"; spalte2=$numprocs
2003    else
2004       spalte1="number of PEs:"; spalte2="$numprocs  (atmosphere: $numprocs_atmos, ocean: $numprocs_ocean)"
2005    fi
2006    printf "| %-25s%-45s | \n" "$spalte1" "$spalte2"
2007 fi
2008 if [[ -n $tasks_per_node ]]
2009 then
2010    spalte1="tasks per node:"; spalte2="$tasks_per_node (number of nodes: $nodes)"
2011    printf "| %-25s%-45s | \n" "$spalte1" "$spalte2"
2012    if (( remaining_pes > 0 ))
2013    then
2014       spalte1=" "; spalte2="one of the nodes only filled with $remaining_pes tasks"
2015       printf "| %-25s%-45s | \n" "$spalte1" "$spalte2"
2016    fi
2017 fi
2018 if [[ $maximum_parallel_io_streams != $numprocs ]]
2019 then
2020    spalte1="max par io streams:"; spalte2="$maximum_parallel_io_streams"
2021    printf "| %-25s%-45s | \n" "$spalte1" "$spalte2"
2022 fi
2023 if [[ $use_openmp = true ]]
2024 then
2025    spalte1="threads per task:"; spalte2="$threads_per_task"
2026    printf "| %-25s%-45s | \n" "$spalte1" "$spalte2"
2027 fi
2028 printf "|                                                                        | \n"
2029 if [[ $do_compile = true ]]
2030 then
2031    if [[ "$mopts" != "" ]]
2032    then
2033       spalte1="make options:"; spalte2=$(echo "$mopts" | cut -c-45)
2034       printf "| %-25s%-45s | \n" "$spalte1" "$spalte2"
2035       zeile=$(echo "$mopts" | cut -c46-)
2036       while [[ "$zeile" != "" ]]
2037       do
2038          spalte1=""
2039          spalte2=$(echo "$zeile" | cut -c-45)
2040          printf "| %-25s%-45s | \n" "$spalte1" "$spalte2"
2041          zeile=$(echo "$zeile" | cut -c46-)
2042       done
2043    fi
2044
2045    spalte1="cpp directives:"; spalte2=$(echo "$cpp_options" | cut -c-45)
2046    printf "| %-25s%-45s | \n" "$spalte1" "$spalte2"
2047    zeile=$(echo "$cpp_options" | cut -c46-)
2048    while [[ "$zeile" != "" ]]
2049    do
2050       spalte1=""
2051       spalte2=$(echo "$zeile" | cut -c-45)
2052       printf "| %-25s%-45s | \n" "$spalte1" "$spalte2"
2053       zeile=$(echo "$zeile" | cut -c46-)
2054    done
2055
2056    spalte1="compiler options:"; spalte2=$(echo "$fopts" | cut -c-45)
2057    printf "| %-25s%-45s | \n" "$spalte1" "$spalte2"
2058    zeile=$(echo "$fopts" | cut -c46-)
2059    while [[ "$zeile" != "" ]]
2060    do
2061       spalte1=""
2062       spalte2=$(echo "$zeile" | cut -c-45)
2063       printf "| %-25s%-45s | \n" "$spalte1" "$spalte2"
2064       zeile=$(echo "$zeile" | cut -c46-)
2065    done
2066
2067    spalte1="linker options:"; spalte2=$(echo "$lopts" | cut -c-45)
2068    printf "| %-25s%-45s | \n" "$spalte1" "$spalte2"
2069    zeile=$(echo "$lopts" | cut -c46-)
2070    while [[ "$zeile" != "" ]]
2071    do
2072       spalte1=""
2073       spalte2=$(echo "$zeile" | cut -c-45)
2074       printf "| %-25s%-45s | \n" "$spalte1" "$spalte2"
2075       zeile=$(echo "$zeile" | cut -c46-)
2076    done
2077
2078    spalte1="modules to be load:"; spalte2=$(echo "$modules" | cut -c-45)
2079    printf "| %-25s%-45s | \n" "$spalte1" "$spalte2"
2080    zeile=$(echo "$modules" | cut -c46-)
2081    while [[ "$zeile" != "" ]]
2082    do
2083       spalte1=""
2084       spalte2=$(echo "$zeile" | cut -c-45)
2085       printf "| %-25s%-45s | \n" "$spalte1" "$spalte2"
2086       zeile=$(echo "$zeile" | cut -c46-)
2087    done
2088
2089    spalte1="main program:"; spalte2=$mainprog
2090    printf "| %-25s%-45s | \n" "$spalte1" "$spalte2"
2091 else
2092    spalte1=executable:; spalte2=$executable
2093    printf "| %-25s%-45s | \n" "$spalte1" "$spalte2"
2094 fi
2095 printf "|                                                                        | \n"
2096 spalte1="base name of files:"; spalte2=$fname
2097 printf "| %-25s%-45s | \n" "$spalte1" "$spalte2"
2098 if [[ $fname != $afname ]]
2099 then
2100    spalte1="base name of input files:"; spalte2=$afname
2101    printf "| %-25s%-45s | \n" "$spalte1" "$spalte2"
2102 fi
2103 spalte1="INPUT control list:"; spalte2=$(echo $input_list)
2104 printf "| %-25s%-45s | \n" "$spalte1" "$spalte2"
2105 spalte1="OUTPUT control list:"; spalte2=$(echo $output_list)
2106 printf "| %-25s%-45s | \n" "$spalte1" "$spalte2"
2107
2108 if [[ "$ocean_file_appendix" = true ]]
2109 then
2110    printf "| %-35s%-35s | \n" "suffix \"_O\" is added to local files" " "
2111 fi
2112
2113 if [[ $do_batch = true  ||  "$LOADLBATCH" = yes ]]
2114 then
2115    spalte1="memory demand / PE":; spalte2="$memory MB"
2116    printf "| %-25s%-45s | \n" "$spalte1" "$spalte2"
2117    spalte1=CPU-time:; spalte2="$minuten:$sekunden"
2118    printf "| %-25s%-45s | \n" "$spalte1" "$spalte2"
2119 fi
2120
2121 if [[ $do_compile = true ]]
2122 then
2123    printf "|                                                                        | \n"
2124    printf "| Files to be compiled:                                                  | \n"
2125    zeile=$source_list
2126    while [[ "$zeile" != "" ]]
2127    do
2128       linestart=$(echo $zeile | cut -c-70)
2129       printf "| %-70s | \n" "$linestart"
2130       zeile=$(echo "$zeile" | cut -c71-)
2131    done
2132 fi
2133 printf "#------------------------------------------------------------------------#"
2134
2135
2136
2137    # OUTPUT OF FILE CONNECTIONS IN CASE OF TRACEBACK
2138 if [[ $do_trace = true ]]
2139 then
2140    (( i = 0 ))
2141    while (( i < iin ))
2142    do
2143       (( i = i + 1 ))
2144       if (( i == 1 ))
2145       then
2146          printf "\n\n >>> INPUT-file assignments:\n"
2147       fi
2148       printf "\n     ${localin[$i]} :  ${absnamein[$i]}"
2149    done
2150    (( i = 0 ))
2151    while (( i < iout ))
2152    do
2153       (( i = i + 1 ))
2154       if (( i == 1 ))
2155       then
2156          printf "\n\n >>> OUTPUT-file assignments:\n"
2157       fi
2158       printf "\n     ${localout[$i]} :  ${pathout[$i]}"
2159    done
2160    (( i = 0 ))
2161    while (( i < iic ))
2162    do
2163       (( i = i + 1 ))
2164       if (( i == 1 ))
2165       then
2166          printf "\n\n >>> INPUT-commands:\n"
2167       fi
2168       printf "\n     ${in_command[$i]}" 
2169    done
2170    (( i = 0 ))
2171    while (( i < ioc ))
2172    do
2173       (( i = i + 1 ))
2174       if (( i == 1 ))
2175       then
2176          printf "\n\n >>> OUTPUT-commands:\n"
2177       fi
2178       printf "\n     ${out_command[$i]}" 
2179    done
2180 fi
2181
2182    # QUERY FOR CONTINUE (ON LOCAL MACHINES ONLY)
2183 if [[ $remotecall = false  &&  $silent = false  &&  $jobmo != BATCH ]]
2184 then
2185    antwort=dummy
2186    printf "\n\n"
2187    printf " >>> everything o.k. (y/n) ?  "
2188    while  read antwort
2189    do
2190       if [[ "$antwort" != y  &&  "$antwort" != Y  &&  "$antwort" != n  &&  "$antwort" != N ]]
2191       then
2192          printf " >>> everything o.k. (y/n) ?  "
2193       else
2194          break
2195       fi
2196    done
2197    if [[ $antwort = n  ||  $antwort = N ]]
2198    then
2199       locat=user_abort; (( iec = 0 )); exit
2200    fi
2201    if [[ $do_batch = true ]]
2202    then
2203       printf " >>> batch-job will be created and submitted"
2204    else
2205       printf " >>> MRUN will now continue to execute on this machine"
2206    fi
2207 fi
2208
2209 
2210    # DETERMINE PATH FOR MAKE DEPOSITORY
2211 if [[ $do_batch = false  ||  $create_executable_for_batch = true ]]
2212 then
2213
2214    line=""
2215    grep "%depository_path" $config_file  >  tmp_mrun
2216    while read line
2217    do
2218       if [[ "$line" != ""  &&  $(echo $line | cut -c1) != "#" ]]
2219       then
2220          if [[ "$(echo $line | cut -d" " -s -f3)" = "" ]]
2221          then
2222             global_depository_path=`echo $line | cut -d" " -s -f2`
2223          fi
2224       fi
2225    done < tmp_mrun
2226
2227    line=""
2228    grep  " $localhost" $config_file | grep "%depository_path"  >  tmp_mrun
2229    while read line
2230    do
2231       if [[ "$line" != ""  &&  $(echo $line | cut -c1) != "#" ]]
2232       then
2233          if [[ "$(echo $line | cut -d" " -s -f4)" = "$cond1"  &&  "$(echo $line | cut -d" " -s -f5)" = "$cond2" ]]
2234          then
2235             local_depository_path=`echo $line | cut -d" " -s -f2`
2236          fi
2237       fi
2238    done < tmp_mrun
2239
2240    if [[ "$local_depository_path" = "" ]]
2241    then
2242       if [[ "$global_depository_path" != "" ]]
2243       then
2244          local_depository_path=$global_depository_path
2245       else
2246          printf "\n\n  +++ no depository path found in configuration file"
2247          printf "\n      for local host \"$localhost\" "
2248          printf "\n      please set \"\%depository_path\" in configuration file\n"
2249          locat=config_file; exit
2250       fi
2251    fi
2252    eval local_depository_path=$local_depository_path
2253    [[ "$cond1" != "" ]]  &&  local_depository_path=${local_depository_path}_$cond1
2254    [[ "$cond2" != "" ]]  &&  local_depository_path=${local_depository_path}_$cond2
2255
2256
2257    basename=`echo $mainprog | cut -f1 -d"."`
2258    eval make_depository=${local_depository_path}/${basename}_current_version.tar
2259    if [[ ! -f $make_depository ]]
2260    then
2261       printf "\n"
2262       printf "\n  *** WARNING: make depository \"$make_depository\" not found"
2263       printf "\n               \"make\" will fail, if the Makefile or other source files are missing\n"
2264    fi
2265
2266 fi
2267
2268
2269    # NOW PERFORM THOSE ACTIONS REQUIRED TO EXECUTE THE PROGRAM (PALM) ON THIS MACHINE
2270    # (COMPILING/LINKING, EXECUTING, COPYING I/O FILES)
2271 if [[ $do_batch = false ]]
2272 then
2273
2274
2275       # CREATE THE TEMPORARY WORKING DIRECTORY
2276    mkdir -p  $TEMPDIR
2277    chmod  go+rx  $TEMPDIR
2278    tmpcreate=true
2279
2280
2281       # COPY EITHER THE COMPLETE SOURCE CODE FILES TO BE COMPILED OR THE EXECUTABLE
2282       # INTO THE TEMPORARY WORKING DIRECTORY
2283    if [[ $do_compile = true ]]
2284    then
2285
2286          # ON NEC, COMPILATION IS DONE ON HOST CROSS VIA CROSS COMPILING
2287          # CREATE A TEMPORARY DIRECTORY ON THAT MACHINE (HOME MOUNTED VIA NFS)
2288       if [[ $localhost = nech ]]
2289       then
2290          TEMPDIR_COMPILE=$HOME/work/${usern}.$kennung
2291          if  mkdir -p  $TEMPDIR_COMPILE
2292          then
2293             printf "\n  *** \"$TEMPDIR_COMPILE\" "
2294             printf "\n      is generated as temporary directory for cross compiling\n"
2295          else
2296             printf "\n  +++ creating directory \"$TEMPDIR_COMPILE\" "
2297             printf "\n      needed for cross compilation failed"
2298             locat=compile
2299             exit
2300          fi
2301       else
2302          TEMPDIR_COMPILE=$TEMPDIR
2303       fi
2304
2305       cp  $make_depository  $TEMPDIR_COMPILE
2306       cd  $TEMPDIR_COMPILE
2307       tar -xf  $make_depository  >  /dev/null  2>&1
2308       cd -  > /dev/null
2309
2310          # DUE TO UNKNOWN REASONS, COPY WITH cp COMMAND CREATES CORRUPT
2311          # FILES ON CRAY XC30 SYSTEMS (HLRN III), rsync IS USED INSTEAD
2312       if [[ $(echo $host | cut -c1-6) = lccray ]]
2313       then
2314          rsync -av -t  SOURCES_FOR_RUN_$fname/*  $TEMPDIR_COMPILE  >  /dev/null
2315       else
2316          cp  SOURCES_FOR_RUN_$fname/*  $TEMPDIR_COMPILE  >  /dev/null
2317       fi
2318
2319    else
2320
2321       cp  $executable   ${TEMPDIR}/a.out
2322
2323    fi
2324
2325
2326       # CHANGE TO THE TEMPORARY WORKING DIRECTORY
2327    cd  $TEMPDIR
2328    printf "\n  *** changed to temporary directory: $TEMPDIR"
2329
2330
2331       # THE FOLLOWING IS REQUIRED FPR AVS-OUTPUT WITH PALM  ??? REMOVE ???
2332       # WRITE INFORMATIONS ABOUT THE OUTPUT-FILE CONNECTIONS TO A TEMPORARY FILE
2333       # THIS FILE CAN LATER BE READ FROM USER-DEFINED CODE TO DETERMINE THE
2334       # RELATION BETWEEN THE LOCAL TEMPORARY AND PERMANENT FILE NAMES
2335    (( i = 0 ))
2336    while (( i < iout ))
2337    do
2338       (( i = i + 1 ))
2339       if [[ "${actionout[$i]}" = tr  ||  "${actionout[$i]}" = tra  ||  "${actionout[$i]}" = trpe ]]
2340       then
2341          printf "${localout[$i]} ${actionout[$i]}\n${pathout[$i]}\n${localhost}_${fname}${endout[$i]}\n" >> OUTPUT_FILE_CONNECTIONS
2342       else
2343          printf "${localout[$i]} ${actionout[$i]}\n${pathout[$i]}\n${frelout[$i]}\n" >> OUTPUT_FILE_CONNECTIONS
2344       fi
2345    done
2346
2347
2348       # IF REQUIRED, START WITH COMPILING
2349    if [[ $do_compile = true ]]
2350    then
2351
2352
2353       if [[ -f a.out ]]
2354       then
2355
2356             # EXECUTABLE WAS CREATED DURING INTERACTIVE CALL OF MRUN
2357          printf "\n\n\n  *** executable a.out found"
2358          printf "\n      no compilation required \n"
2359
2360       else
2361
2362             # COMPILING WITH MAKE (ON NEC COMPILER IS CALLED ON HOST CROSS)
2363          printf "\n\n\n  *** compilation starts \n$dashes\n"
2364          printf "  *** compilation with make using following options:\n"
2365          printf "      make depository:          $make_depository"
2366          if [[ "$mopts" != "" ]]
2367          then
2368             printf "      make options:             $mopts\n"
2369          fi
2370          printf "      compilername:             $compiler_name\n"
2371          printf "      compiler options:         $fopts\n"
2372          printf "      preprocessor directives:  $cpp_options \n"
2373          printf "      linker options:           $lopts \n"
2374          if [[ "$modules" != "" ]]
2375          then
2376             printf "      modules to be load:       $modules \n"
2377          fi
2378          printf "      source code files:        $source_list \n"
2379
2380          if [[ $localhost = nech ]]
2381          then
2382             ssh  $SSH_PORTOPT  136.172.44.192 -l $usern "$init_cmds $module_calls cd \$HOME/work/${usern}.$kennung; sxmake $mopts -f Makefile PROG=a.out  F90=$compiler_name  COPT=\"$cpp_options\"  F90FLAGS=\"$fopts\"  LDFLAGS=\"$lopts\" "
2383             cp  $TEMPDIR_COMPILE/a.out  .
2384             [[ $? != 0 ]]  &&  compile_error=true
2385             rm -rf  $TEMPDIR_COMPILE
2386          elif [[ $localhost = ibmh ]]
2387          then
2388             printf "      compiler is called via ssh on \"plogin1\" \n"
2389             ssh  $SSH_PORTOPT  plogin1  -l $usern  "$init_cmds export PATH=/sw/ibm/xlf/13.1.0.8/usr/bin:$PATH; $module_calls cd $TEMPDIR; make $mopts -f Makefile PROG=a.out  F90=$compiler_name  COPT=\"$cpp_options\"  F90FLAGS=\"$fopts\"  LDFLAGS=\"$lopts\" "
2390             [[ ! -f a.out ]]  &&  compile_error=true
2391             continue   # STATUS=1, IF a.out EXISTS
2392          elif [[ $localhost = lcflow ]]
2393          then
2394             printf "      compiler is called via ssh on \"flow\" \n"
2395             /usr/bin/ssh  $SSH_PORTOPT  flow02.hpc.uni-oldenburg.de -l $usern "$init_cmds $module_calls cd $TEMPDIR; make $mopts -f Makefile PROG=a.out F90=$compiler_name COPT=\"$cpp_options\" F90FLAGS=\"$fopts\" LDFLAGS=\"$lopts\" "
2396             check_for_file=`/usr/bin/ssh $SSH_PORTOPT flow02.hpc.uni-oldenburg.de -l $usern "ls $TEMPDIR/a.out 2> /dev/null"`
2397             [[ "$check_for_file" = "" ]]  &&  compile_error=true
2398             continue   # STATUS=1, IF a.out EXISTS
2399          elif [[ $localhost = lcbullhh  ||  $localhost = lccrayb  ||  $localhost = lccrayf ||  $localhost = lccrayh ]]
2400          then
2401             make $mopts -f Makefile PROG=a.out  F90=$compiler_name  COPT="$cpp_options"  F90FLAGS="$fopts"  LDFLAGS="$lopts"
2402          else
2403             [[ "$init_cmds" != "" ]]  &&  eval $init_cmds
2404             [[ "$module_calls" != "" ]]  &&  eval $module_calls
2405             make $mopts -f Makefile PROG=a.out  F90=$compiler_name  COPT="$cpp_options"  F90FLAGS="$fopts"  LDFLAGS="$lopts"
2406          fi
2407
2408          if [[ $? != 0  ||  "$compile_error" = true  ||  "$module_compile_error" = true ]]
2409          then
2410             printf "\n  +++ error occured while compiling or linking"
2411             locat=compile
2412
2413             exit
2414          else
2415             printf "$dashes\n  *** compilation finished \n"
2416          fi
2417
2418       fi
2419
2420    fi
2421
2422
2423       # PROVIDE THE INPUT FILES
2424       # LOOP OVER ALL ACTIVATED FILES (LISTED IN THE CONFIGURATION FILE)
2425    (( i = 0 ))
2426    while (( i < iin ))
2427    do
2428       (( i = i + 1 ))
2429       if (( i == 1 ))
2430       then
2431          printf "\n\n  *** providing INPUT-files:\n$dashes"
2432       fi
2433
2434
2435          # SKIP OPTIONAL FILES, IF THEY DO NOT EXIST
2436       if [[ "${transin[$i]}" = unavailable ]]
2437       then
2438          if [[ "${extin[$i]}" = ""  ||  "${extin[$i]}" = " " ]]
2439          then
2440             printf "\n  *** INFORMATIVE: input file \"${pathin[$i]}/${afname}${endin[$i]}\" "
2441             printf "\n                   is not available!"
2442          else
2443             printf "\n  *** INFORMATIVE: input file \"${pathin[$i]}/${afname}${endin[$i]}.${extin[$i]}\" "
2444             printf "\n                   is not available!"
2445          fi
2446          continue
2447       fi
2448
2449          # CHECK FOR SINGLE FILE (SERIAL RUN) OR DIRECTORY (ONE FILE PER CORE FOR PARELLEL EXECUTION)
2450       files_for_pes=false; datentyp=file
2451       if [[ "${actionin[$i]}" = pe  &&  -n $numprocs ]]
2452       then
2453          files_for_pes=true; datentyp=directory
2454          actionin[$i]=""
2455       elif [[ "${actionin[$i]}" = pe  &&  ! -n $numprocs ]]
2456       then
2457          actionin[$i]=""
2458       elif [[ "${actionin[$i]}" = arpe  &&  -n $numprocs ]]
2459       then
2460          files_for_pes=true; datentyp=directory
2461          actionin[$i]="ar"
2462       elif [[ "${actionin[$i]}" = arpe  &&  ! -n $numprocs ]]
2463       then
2464          actionin[$i]="ar"
2465       elif [[ "${actionin[$i]}" = flpe  &&  -n $numprocs ]]
2466       then
2467          files_for_pes=true; datentyp=directory
2468          actionin[$i]="fl"
2469       elif [[ "${actionin[$i]}" = flpe  &&  ! -n $numprocs ]]
2470       then
2471          actionin[$i]="fl"
2472       fi
2473
2474       if [[ $files_for_pes = true ]]
2475       then
2476          printf "\n  >>> INPUT: ${absnamein[$i]}/....  to  ${localin[$i]}"
2477       else
2478          printf "\n  >>> INPUT: ${absnamein[$i]}  to  ${localin[$i]}"
2479       fi
2480
2481          # INPUT-FILE FOR A RESTART RUN.
2482          # CHECK, IF THIS FILE STILL EXISTS ON THE TEMPORARY DATA DIRECTORY.
2483          # IF NOT, TRY TO GET IT FROM THE ARCHIVE SYSTEM
2484       if [[ "${actionin[$i]}" = fl ]]
2485       then
2486          printf "\n      $datentyp will be fetched from temporary directory \"${tmp_data_catalog}\" !"
2487          if [[ $files_for_pes = false ]]
2488          then
2489             if [[ -f "$tmp_data_catalog/${frelin[$i]}" ]]
2490             then
2491                ln  $tmp_data_catalog/${frelin[$i]}  ${localin[$i]}
2492                got_tmp[$i]=true
2493             elif [[ -f "$WORK/${frelin[$i]}"  &&  $ignore_archive_error = true ]]
2494             then
2495                printf "\n  +++ $datentyp not found in \"$tmp_data_catalog\" !"
2496                printf "\n  *** trying to use backup copy in \"$WORK\" "
2497                cp  $WORK/${frelin[$i]}  ${localin[$i]}
2498             else
2499                printf "\n  +++ $datentyp not found in \"$tmp_data_catalog\" "
2500                printf "\n      or \"$tmp_data_catalog\" does not exist!"
2501                printf "\n  *** trying to get copy from archive"
2502                actionin[$i]=ar
2503             fi
2504          else
2505             if [[ -d "$tmp_data_catalog/${frelin[$i]}" ]]
2506             then
2507                mkdir  ${localin[$i]}
2508                cd $tmp_data_catalog/${frelin[$i]}
2509                for file in $(ls *)
2510                do
2511                   ln $file $TEMPDIR/${localin[$i]}
2512                done
2513                cd $TEMPDIR
2514                got_tmp[$i]=true
2515             elif [[ -d "$WORK/${frelin[$i]}"  &&  $ignore_archive_error = true ]]
2516             then
2517                printf "\n  +++ $datentyp not found in \"$tmp_data_catalog\" !"
2518                printf "\n  *** trying to use backup copy in \"$WORK\" "
2519                cp -r  $WORK/${frelin[$i]}  ${localin[$i]}
2520             else
2521                printf "\n  +++ $datentyp not found in \"$tmp_data_catalog\" "
2522                printf "\n      or \"$tmp_data_catalog\" does not exist!"
2523                printf "\n  *** trying to get copy from archive"
2524                actionin[$i]=ar
2525             fi
2526          fi
2527       fi
2528
2529
2530          # FILE IS STORED ON THE ARCHIVE SYSTEM
2531       if [[ "${actionin[$i]}" = ar ]]
2532       then
2533
2534          if [[ $files_for_pes = false ]]
2535          then
2536             printf "\n      file will be restored from archive-system ($archive_system)!"
2537          else
2538             printf "\n      directory will be restored from archive-system ($archive_system)!"
2539          fi
2540
2541          file_restored=false
2542
2543          if [[ $archive_system = asterix ]]
2544          then
2545             do_stagein=true
2546             (( stagein_anz = 0 ))
2547             while [[ $do_stagein = true ]]
2548             do
2549                if [[ $files_for_pes = false ]]
2550                then
2551                   stagein  -O  ${frelin[$i]}  >  STAGEIN_OUTPUT
2552                else
2553                   stagein  -t  -O  ${frelin[$i]}  >  STAGEIN_OUTPUT
2554                fi
2555                cat  STAGEIN_OUTPUT
2556                if [[ $(grep -c "st.msg:i24"  STAGEIN_OUTPUT) != 0 ]]
2557                then
2558                   file_restored=true
2559                   do_stagein=false
2560                else
2561                   (( stagein_anz = stagein_anz + 1 ))
2562                   if (( stagein_anz == 10 ))
2563                   then
2564                      printf "\n  +++ stagein stoped after 10 tries"
2565                      locat=stage
2566                      exit
2567                   fi
2568                   printf "\n  +++ restoring from archive failed, trying again:"
2569                   sleep 900
2570                fi
2571             done
2572          elif [[ $archive_system = DMF ]]
2573          then
2574             if [[ $files_for_pes = false ]]
2575             then
2576                printf "\n  +++ restoring of single files impossible with $archive_system !\n"
2577                locat=DMF
2578                exit
2579             else
2580                find  $ARCHIVE/${frelin[$i]}  -type m  -print  |  dmget
2581                cp  -r $ARCHIVE/${frelin[$i]}  $PWD
2582                file_restored=true
2583             fi
2584          elif [[ $archive_system = tivoli ]]
2585          then
2586             if [[ $files_for_pes = false ]]
2587             then
2588                ssh  $SSH_PORTOPT  $usern@bicedata.hlrn.de  "cp  $PERM/${frelin[$i]}  $PWD"
2589             else
2590                (( inode = 0 ))
2591                while (( inode < nodes ))
2592                do
2593                   ssh  $SSH_PORTOPT  $usern@bicedata.hlrn.de  "cd $PWD; tar  xf  $PERM/${frelin[$i]}/${frelin[$i]}.node_$inode.tar"
2594                   (( inode = inode + 1 ))
2595                done
2596             fi
2597             file_restored=true
2598          elif [[ $archive_system = ut ]]
2599          then
2600             if [[ $files_for_pes = false ]]
2601             then
2602                cp  $UT/${frelin[$i]}  .
2603             else
2604                (( inode = 0 ))
2605                while (( inode < nodes ))
2606                do
2607                   tar  xf  $UT/${frelin[$i]}/${frelin[$i]}.node_$inode.tar
2608                   (( inode = inode + 1 ))
2609                done
2610             fi
2611             file_restored=true
2612          else
2613             printf "\n  +++ archive_system=\"$archive_system\"   restore impossible!"
2614             locat=rearchive
2615             exit
2616          fi
2617
2618          if [[ $file_restored = true ]]
2619          then
2620
2621                # PUT FILE ON THE TEMPORARY DATA DIRECTORY TOO.
2622                # THIS WILL MAKE FILE ACCESS EASIER FOR LATER RUNS
2623             [[ ! -d $tmp_data_catalog ]]  &&  mkdir -p  $tmp_data_catalog; chmod  g+rx  $tmp_data_catalog
2624             if [[ $files_for_pes = false ]]
2625             then
2626                ln  -f  ${frelin[$i]}  $tmp_data_catalog/${frelin[$i]}
2627             else
2628                mkdir  $tmp_data_catalog/${frelin[$i]}
2629                ln  -f  ${frelin[$i]}/*  $tmp_data_catalog/${frelin[$i]}
2630             fi
2631             got_tmp[$i]=true
2632
2633                # PROVIDE THE FILE UNDER ITS LOCAL NAME
2634             mv  ${frelin[$i]}  ${localin[$i]}
2635
2636          fi
2637       fi
2638
2639
2640          # FILE IS STORED IN THE RESPECTIVE DIRECTORY GIVEN IN THE CONFIGURATION FILE
2641       if [[ "${actionin[$i]}" = ""  ||  "${actionin[$i]}" = "di"  ||  "${actionin[$i]}" = "npe" ]]
2642       then
2643
2644          if [[ "${actionin[$i]}" = "npe"  &&  -n $numprocs ]]
2645          then
2646
2647                # FILE COPIES ARE PROVIDED FOR ALL CORES
2648                # EACH FILE GETS A UNIQUE FILENAME WITH A FOUR DIGIT NUMBER
2649             printf "\n      file will be provided for $numprocs processors"
2650             mkdir  ${localin[$i]}
2651             ival=$numprocs
2652             (( ii = 0 ))
2653             while (( ii <= ival-1 ))
2654             do
2655                if (( ii < 10 ))
2656                then
2657                   cp  ${absnamein[$i]}  ${localin[$i]}/_000$ii
2658                elif (( ii < 100 ))
2659                then
2660                   cp  ${absnamein[$i]}  ${localin[$i]}/_00$ii
2661                elif (( ii < 1000 ))
2662                then
2663                   cp  ${absnamein[$i]}  ${localin[$i]}/_0$ii
2664                else
2665                   cp  ${absnamein[$i]}  ${localin[$i]}/_$ii
2666                fi
2667                (( ii = ii + 1 ))
2668             done
2669
2670          else
2671
2672             if [[ $files_for_pes = true ]]
2673             then
2674
2675                   # PROVIDE FILES FOR EACH CORE
2676                   # FIRST CREATE THE LOCAL DIRECTORY, THEN COPY FILES
2677                   # FROM THE PERMANENT DIRECTORY BY LINKING THEM TO THE LOCAL ONE
2678                printf "\n      providing $numprocs files for the respective processors"
2679                mkdir  ${localin[$i]}
2680                if [[ $link_local_input = true ]]
2681                    then
2682                    printf "      using ln -f\n"
2683                    cd ${absnamein[$i]}
2684                    for file in $(ls *)
2685                      do
2686                      ln -f $file  ${localin[$i]}
2687                    done
2688                    cd $TEMPDIR
2689                fi
2690
2691                   # IF "ln -f" FAILED OR IF "$link_local_input = false" DO A NORMAL "cp -r"
2692                if [[ ! -f "${localin[$i]}/_0000" ]]
2693                    then
2694                    if [[ $link_local_input = true ]]
2695                        then
2696                        printf "      ln failed for .../_0000, using cp...\n"
2697                    fi
2698                    cp -r  ${absnamein[$i]}/*  ${localin[$i]}
2699                fi
2700
2701             else
2702
2703                   # PROVIDE FILE FOR RUNS ON A SINGLE CORE
2704                if [[ $link_local_input = true ]]
2705                then
2706                    printf "      using ln -f\n"
2707                    ln -f  ${absnamein[$i]}  ${localin[$i]}
2708                fi
2709                # If "ln -f" fails of if "$link_local_input = false" do a normal "cp"
2710                if [[ ! -f "${localin[$i]}" ]]
2711                then
2712                    if [[ $link_local_input = true ]]
2713                    then
2714                        printf "      ln failed, using cp...\n"
2715                    fi
2716                    cp  ${absnamein[$i]}  ${localin[$i]}
2717                fi
2718             fi
2719          fi
2720       fi
2721
2722    done
2723    if (( i != 0 ))
2724    then
2725       printf "\n$dashes\n  *** all INPUT-files provided \n"
2726    fi
2727
2728
2729       # EXECUTE INPUT-COMMANDS GIVEN IN THE CONFIGURATION FILE
2730    (( i = 0 ))
2731    while (( i < iic ))
2732    do
2733       (( i = i + 1 ))
2734       if (( i == 1 ))
2735       then
2736          printf "\n\n  *** execution of INPUT-commands:\n$dashes"
2737       fi
2738       printf "\n  >>> ${in_command[$i]}"
2739       eval  ${in_command[$i]}
2740       if (( i == iic ))
2741       then
2742          printf "\n$dashes\n"
2743       fi
2744    done
2745
2746
2747       # SET THE REMAINING CPU-TIME
2748    cpurest=${cpumax}.
2749
2750
2751       # START DVR STREAMING SERVER
2752    if [[ $(echo $package_list | grep -c dvrp_graphics) != 0 ]]
2753    then
2754       if [[ "$dvr_server" != "" ]]
2755       then
2756
2757          printf "\n\n  *** preparing the dvr streaming server configuration file"
2758
2759             # CHECK, IF A DVR SERVER IS ALREADY RUNNING
2760          running_dvrserver_id=`echo $(ps -edaf | grep .dvrserver.config | grep -v grep) | cut -d" " -f2`
2761          if [[ "$running_dvrserver_id" != "" ]]
2762          then
2763
2764             printf "\n\n  +++ WARNING: A dvr server with id=$running_dvrserver_id is already running!"
2765             printf "\n      This server is used instead starting a new one!"
2766             printf "\n      If required, script \"process_dvr_output\" has to be run manually."
2767
2768          else
2769
2770                # COPY CONFIGURATION FILE FOR STREAMING SERVER FROM REPOSITORY TO HERE
2771             if [[ -f ${PALM_BIN}/.dvrserver.config ]]
2772             then
2773                cp  ${PALM_BIN}/.dvrserver.config  .
2774
2775                   # ENTERING THE BASEDIR, UID AND GID INTO THIS FILE
2776                user_id=`id -u`
2777                group_id=`id -g`
2778
2779                   # "&" IS REQUIRED AS A SEPERATOR, BECAUSE TEMPDIR CONTAINS "/"
2780                sed "s&<replace by dvr data directory>&${TEMPDIR}&g" .dvrserver.config > .dvrserver.1
2781                sed "s/<replace by user id>/$user_id/g"    .dvrserver.1 > .dvrserver.2
2782                sed "s/<replace by group id>/$group_id/g"  .dvrserver.2 > .dvrserver.3
2783                mv  .dvrserver.3  .dvrserver.config
2784                rm  .dvrserver.1  .dvrserver.2
2785
2786                   # START DVR SERVER IN BACKGROUND, GET HIS ID AND PRINT ON TERMINAL
2787                $dvr_server  .dvrserver.config  >>  DVR_LOGFILE  2>&1  &
2788                dvrserver_id=`echo $(ps -edaf | grep .dvrserver.config) | cut -d" " -f2`
2789                printf "\n  *** streaming server with id=$dvrserver_id is started in background"
2790                local_dvrserver_running=.TRUE.
2791             else
2792                printf "\n  +++ missing file \".dvrserver.config\" in directory:"
2793                printf "\n      \"$PALM_BIN\" "
2794                locat=dvr
2795                exit
2796             fi
2797
2798          fi
2799
2800       else
2801          printf "\n\n  --- INFORMATIVE: no dvr streaming server will be started"
2802       fi
2803    fi
2804
2805
2806       # CREATE THE NAMELIST-FILE WITH VALUES OF ENVIRONMENT-VARIABLES REQUIRED BY PALM
2807       # (FILE ENVPAR WILL BE READ BY PALM)
2808    cat  >  ENVPAR  <<  %%END%%
2809 &envpar  run_identifier = '$fname', host = '$localhost',
2810          write_binary = '$write_binary', tasks_per_node = $tasks_per_node,
2811          maximum_parallel_io_streams = $maximum_parallel_io_streams,
2812          maximum_cpu_time_allowed = ${cpumax}.,
2813          revision = '$global_revision',
2814          local_dvrserver_running = $local_dvrserver_running,
2815          batch_job = $batch_job /
2816
2817%%END%%
2818
2819
2820       # STARTING THE EXECUTABLE
2821    printf "\n\n  *** execution starts in directory\n      \"`pwd`\"\n$dashes\n"
2822    PATH=$PATH:$TEMPDIR
2823
2824
2825    if [[ $execute_command != "none" ]]
2826    then
2827
2828        printf "\n  +++ branch still not realized"
2829        locat=execution
2830        exit
2831
2832    else
2833
2834          # MPI DEBUG OPTION (ARGUMENT CHECKING, SLOWS DOWN EXECUTION DUE TO INCREASED LATENCY)
2835       if [[ "$mpi_debug" = true ]]
2836       then
2837          export MPI_CHECK_ARGS=1
2838          printf "\n  +++ MPI_CHECK_ARGS=$MPI_CHECK_ARGS"
2839       fi
2840
2841       if [[ "$totalview" = true ]]
2842       then
2843          printf "\n *** totalview debugger will be used"
2844          tv_opt="-tv"
2845       else
2846          tv_opt=""
2847       fi
2848
2849       if [[ "$cond1" = debug  ||  "$cond2" = debug ]]
2850       then
2851
2852             #Interactive ALLINEA DEBUG seesion
2853          if [[ "$ENVIRONMENT" != BATCH ]]
2854          then
2855             if [[ $host = lccrayb || $host = lccrayh ]]
2856             then
2857                if [[ "$allinea" = true ]]
2858                then
2859                   echo "--- aprun  -n $ii  -N $tasks_per_node  a.out  < runfile_atmos"
2860
2861                   ddt  aprun  -n $ii  -N $tasks_per_node  a.out
2862                   wait
2863                fi         
2864             fi
2865          fi
2866
2867          if [[ $localhost = ibmh ]]
2868          then
2869
2870                # SETUP THE IBM MPI ENVIRONMENT
2871             export MP_SHARED_MEMORY=yes
2872             export AIXTHREADS_SCOPE=S
2873             export OMP_NUM_THREADS=$threads_per_task
2874             export AUTHSTATE=files
2875             export XLFRTEOPTS="nlwidth=132:err_recovery=no"    # RECORD-LENGTH OF NAMELIST-OUTPUT
2876
2877                # FOLLOWING OPTIONS ARE MANDATORY FOR TOTALVIEW
2878             export MP_ADAPTER_USE=shared
2879             export MP_CPU_USE=multiple
2880             export MP_TIMEOUT=1200
2881
2882             unset  MP_TASK_AFFINITY
2883
2884             if [[ "$LOADLBATCH" = yes ]]
2885             then
2886                totalview   poe  a.out
2887             else
2888                echo totalview   poe  -a a.out  -procs $numprocs  -rmpool 0  -nodes 1
2889                export TVDSVRLAUNCHCMD=ssh
2890                totalview   poe  -a a.out  -procs $numprocs  -rmpool 0  -nodes 1
2891             fi
2892
2893          fi  # END DEBUG MODE
2894
2895       else
2896
2897             # NORMAL EXECUTION
2898          if [[ -n $numprocs ]]
2899          then
2900
2901                # RUNNING THE PROGRAM ON PARALLEL MACHINES
2902             if [[ $(echo $host | cut -c1-3) = ibm ]]
2903             then
2904
2905                   # SETUP THE IBM MPI ENVIRONMENT
2906                if [[ $host != ibmh  &&  $host != ibmkisti ]]
2907                then
2908                   export MP_SHARED_MEMORY=yes
2909                   export AIXTHREAD_SCOPE=S
2910                   export OMP_NUM_THREADS=$threads_per_task
2911                   export XLSMPOPTS="spins=0:yields=0:stack=20000000"
2912                   export AUTHSTATE=files
2913                   export XLFRTEOPTS="nlwidth=132:err_recovery=no"    # RECORD-LENGTH OF NAMELIST-OUTPUT
2914                   #  export MP_PRINTENV=yes
2915
2916                      # TUNING-VARIABLES TO IMPROVE COMMUNICATION SPEED
2917                      # DO NOT SHOW SIGNIFICANT EFFECTS (SEP 04, FEDERATION-SWITCH)
2918                   export MP_WAIT_MODE=poll
2919                   [[ $node_usage = not_shared ]]  &&  export MP_SINGLE_THREAD=yes
2920                fi
2921
2922                if [[ $host = ibmkisti ]]
2923                then
2924                   export LANG=en_US
2925                   export MP_SHARED_MEMORY=yes
2926                   if [[ $threads_per_task = 1 ]]
2927                   then
2928                      export MP_SINGLE_THREAD=yes
2929                      export MEMORY_AFFINITY=MCM
2930                   else
2931                      export OMP_NUM_THREADS=$threads_per_task
2932                   fi
2933                fi
2934
2935                if [[ "$LOADLBATCH" = yes ]]
2936                then
2937                   printf "\n--- Control: OMP_NUM_THREADS = \"$OMP_NUM_THREADS\" \n"
2938                   if [[ "$cond1" = hpmcount  ||  "$cond2" = hpmcount ]]
2939                   then
2940                      /opt/optibm/HPM_2_4_1/bin/hpmcount  a.out
2941                   else
2942                      if [[ $run_coupled_model = false ]]
2943                      then
2944                         if [[ "$ocean_file_appendix" = true ]]
2945                         then
2946                            echo "precursor_ocean"  >  runfile_atmos
2947                         else
2948                            echo "precursor_atmos"  >  runfile_atmos
2949                         fi
2950                      else
2951                         (( iia = $numprocs_atmos / $threads_per_task ))
2952                         (( iio = $numprocs_ocean / $threads_per_task ))
2953                         printf "\n      coupled run ($iia atmosphere, $iio ocean)"
2954                         printf "\n      using $coupled_mode coupling"
2955                         printf "\n\n"
2956                         echo "coupled_run $iia $iio"  >  runfile_atmos
2957                      fi
2958                      poe ./a.out  <  runfile_atmos
2959                   fi
2960                else
2961                   if [[ $localhost = ibmh  ||  $localhost = ibms ]]
2962                   then
2963                      poe  a.out  -procs $numprocs  -nodes 1  -rmpool 0
2964                   elif [[ $localhost = ibmkisti  ||  $localhost = ibmku ]]
2965                   then
2966                      if [[ -f $hostfile ]]
2967                      then
2968                         cp  $hostfile  hostfile
2969                      else
2970                         (( ii = 1 ))
2971                         while (( ii <= $numprocs ))
2972                         do
2973                            echo  $localhost_realname  >>  hostfile
2974                            (( ii = ii + 1 ))
2975                         done
2976                      fi
2977                      export MP_HOSTFILE=hostfile
2978                      if [[ $run_coupled_model = false ]]
2979                      then
2980                         if [[ "$ocean_file_appendix" = true ]]
2981                         then
2982                            echo "precursor_ocean"  >  runfile_atmos
2983                         else
2984                            echo "precursor_atmos"  >  runfile_atmos
2985                         fi
2986                      else
2987                         (( iia = $numprocs_atmos / $threads_per_task ))
2988                         (( iio = $numprocs_ocean / $threads_per_task ))
2989                         printf "\n      coupled run ($iia atmosphere, $iio ocean)"
2990                         printf "\n      using $coupled_mode coupling"
2991                         printf "\n\n"
2992                         echo "coupled_run $iia $iio"  >  runfile_atmos
2993                      fi
2994
2995                      poe  ./a.out  -procs $numprocs  <  runfile_atmos
2996
2997                   else
2998                      if [[ "$host_file" = "" ]]
2999                      then
3000                         printf "\n  +++ no hostfile given in configuration file"
3001                         locat=config_file
3002                         exit
3003                      else
3004                         eval host_file=$host_file
3005                      fi
3006                      export MP_HOSTFILE=$host_file
3007                      poe  a.out  -procs $numprocs  -tasks_per_node $numprocs
3008                   fi
3009                fi
3010
3011             elif [[ $host = nech ]]  # running on NEC machines
3012             then
3013
3014                (( ii = nodes ))
3015                if [[ $ii = 1 ]]
3016                then
3017                   export F_ERRCNT=0        # acceptable number of errors before program is stopped
3018                   export MPIPROGINF=YES
3019                   #  export F_TRACE=YES|FMT1|FMT2  # output of ftrace informations to job protocol
3020                   echo "*** execution on single node with mpirun"
3021                   mpirun  -np $numprocs  ./a.out
3022                else
3023                   (( i = 0 ))
3024                   while (( i < ii ))
3025                   do
3026                      echo "-h $i  -p $tasks_per_node  -e ./mpi_exec_shell"  >>  multinode_config
3027                      (( i = i + 1 ))
3028                   done
3029
3030                   echo "#!/bin/sh"                         >   mpi_exec_shell
3031                   echo " "                                 >>  mpi_exec_shell
3032                   echo "set -u"                            >>  mpi_exec_shell
3033                   echo "F_ERRCNT=0"                        >>  mpi_exec_shell
3034                   echo "MPIPROGINV=YES"                    >>  mpi_exec_shell
3035                   echo "OMP_NUM_THREADS=$threads_per_task" >>  mpi_exec_shell
3036                   echo "cpurest=$cpurest"                  >>  mpi_exec_shell
3037                   echo "fname=$fname"                      >>  mpi_exec_shell
3038                   echo "localhost=$localhost"              >>  mpi_exec_shell
3039                   echo "return_address=$return_address"    >>  mpi_exec_shell
3040                   echo "return_username=$return_username"  >>  mpi_exec_shell
3041                   echo "tasks_per_node=$tasks_per_node"    >>  mpi_exec_shell
3042                   echo "write_binary=$write_binary"        >>  mpi_exec_shell
3043                   echo "use_seperate_pe_for_dvrp_output=$use_seperate_pe_for_dvrp_output"  >>  mpi_exec_shell
3044                   echo "  "                                >>  mpi_exec_shell
3045                   echo "export F_ERRCNT"                   >>  mpi_exec_shell
3046                   echo "export MPIPROGINV"                 >>  mpi_exec_shell
3047                   echo "export OMP_NUM_THREADS"            >>  mpi_exec_shell
3048                   echo "export cpurest"                    >>  mpi_exec_shell
3049                   echo "export fname"                      >>  mpi_exec_shell
3050                   echo "export localhost"                  >>  mpi_exec_shell
3051                   echo "export return_address"             >>  mpi_exec_shell
3052                   echo "export return_username"            >>  mpi_exec_shell
3053                   echo "export tasks_per_node"             >>  mpi_exec_shell
3054                   echo "export write_binary"               >>  mpi_exec_shell
3055                   echo "export use_seperate_pe_for_dvrp_output"  >>  mpi_exec_shell
3056                   echo " "                                 >>  mpi_exec_shell
3057                   echo "exec  ./a.out"                     >>  mpi_exec_shell
3058
3059                   chmod u+x  mpi_exec_shell
3060                   export MPIPROGINF=YES
3061                   mpirun  -f multinode_config  &
3062                   wait
3063
3064                fi
3065
3066             elif [[ $(echo $host | cut -c1-2) = lc  &&  $host != lckyoto &&  $host != lctit ]]
3067             then
3068
3069                   # COPY HOSTFILE FROM SOURCE DIRECTORY OR CREATE IT, IF IT
3070                   # DOES NOT EXIST
3071                if [[  $host != lcbullhh  && $host != lccrayb  &&  $host != lccrayf  && $host != lccrayh  &&  $host != lckyuh  &&  $host != lckyut ]]
3072                then
3073                   if [[ -f $hostfile ]]
3074                   then
3075                      cp  $hostfile  hostfile
3076                      (( ii = $numprocs / $threads_per_task ))
3077                      [[ $ii = 0 ]]  &&  (( ii = 1 ))
3078                   else
3079                      (( ii = 1 ))
3080                      while (( ii <= $numprocs / $threads_per_task ))
3081                      do
3082                         echo  $localhost_realname  >>  hostfile
3083                         (( ii = ii + 1 ))
3084                      done
3085                      if (( $numprocs / $threads_per_task == 0 ))
3086                      then
3087                         echo  $localhost_realname  >>  hostfile
3088                      fi
3089                   fi
3090                   eval zeile=\"`head -n $ii  hostfile`\"
3091                   printf "\n  *** running on: $zeile"
3092                fi
3093
3094                (( ii = $numprocs / $threads_per_task ))
3095                [[ $ii = 0 ]]  &&  (( ii = 1 ))
3096                export OMP_NUM_THREADS=$threads_per_task
3097
3098                if [[ $threads_per_task != 1 ]]
3099                then
3100                      # INCREASE STACK SIZE TO UNLIMITED, BECAUSE OTHERWISE LARGE RUNS
3101                      # MAY ABORT
3102                   ulimit -s unlimited
3103                   printf "\n      threads per task: $threads_per_task  stacksize: unlimited"
3104                fi
3105                if [[ $run_coupled_model = false ]]
3106                then
3107                   if [[ "$ocean_file_appendix" = true ]]
3108                   then
3109                      echo "precursor_ocean"  >  runfile_atmos
3110                   else
3111                      echo "precursor_atmos"  >  runfile_atmos
3112                   fi
3113                   printf "\n\n"
3114
3115                   if [[ $host = lccrayb || $host = lccrayh ]]
3116                   then
3117                       echo "--- aprun  -n $ii  -N $tasks_per_node  a.out  <  runfile_atmos"
3118                       aprun  -n $ii  -N $tasks_per_node  a.out  <  runfile_atmos
3119                   elif [[ $host = lcbullhh ]]
3120                   then
3121                      export OMPI_MCA_pml=cm
3122                      export OMPI_MCA_mtl=mxm
3123                      export OMPI_MCA_coll=^ghc
3124                      export OMPI_MCA_mtl_mxm_np=0
3125                      export MXM_RDMA_PORTS=mlx5_0:1
3126                      export MXM_LOG_LEVEL=ERROR
3127                      export OMP_NUM_THREADS=$threads_per_task
3128                      export KMP_AFFINITY=verbose,granularity=core,compact,1
3129                      export KMP_STACKSIZE=64m
3130
3131                      srun  --nodes=$nodes --ntasks-per-node=$tasks_per_node ./a.out  <  runfile_atmos
3132
3133                   elif [[ $host = lccrayf ]]
3134                   then
3135                       aprun  -j1  -n $ii  -N $tasks_per_node  -m ${memory}M  a.out  <  runfile_atmos
3136                   elif [[ $host = lcxe6  ||  $host = lcxt5m ]]
3137                   then
3138                       aprun  -n $ii  -N $tasks_per_node  a.out  <  runfile_atmos
3139                   elif [[ $host = lcflow ]]
3140                   then
3141                      mpirun -np $ii a.out  < runfile_atmos
3142                   elif [[ $host = lcsb ]]
3143                   then
3144                      mpirun_rsh -hostfile $PBS_NODEFILE -np `cat $PBS_NODEFILE | wc -l` a.out  < runfile_atmos
3145                   elif [[ $host = lckiaps ]]
3146                   then
3147                      mpirun -np $ii  -f $PBS_NODEFILE  a.out  <  runfile_atmos
3148                   elif [[ $host = lckyu* ]]
3149                   then
3150                      mpiexec -n $ii --stdin runfile_atmos  ./a.out
3151                   else
3152                      mpiexec  -machinefile hostfile  -n $ii  a.out  <  runfile_atmos
3153                   fi
3154
3155                else
3156
3157                       # CURRENTLY THERE IS NO FULL MPI-2 SUPPORT ON ICE AND XT4
3158                   (( iia = $numprocs_atmos / $threads_per_task ))
3159                   (( iio = $numprocs_ocean / $threads_per_task ))
3160                   printf "\n      coupled run ($iia atmosphere, $iio ocean)"
3161                   printf "\n      using $coupled_mode coupling"
3162                   printf "\n\n"
3163
3164                   if [[ $coupled_mode = "mpi2" ]]
3165                   then
3166                      echo "atmosphere_to_ocean $iia $iio"  >  runfile_atmos
3167                      echo "ocean_to_atmosphere $iia $iio"  >  runfile_ocean
3168
3169                      if [[ $host = lccrayf  ||  $host = lcxe6  ||  $host = lcxt5m ]]
3170                      then
3171
3172                         aprun  -n $iia  -N $tasks_per_node  a.out < runfile_atmos  &
3173                         aprun  -n $iio  -N $tasks_per_node  a.out < runfile_ocean  &
3174
3175                      else
3176                             # WORKAROUND BECAUSE mpiexec WITH -env option IS NOT AVAILABLE ON SOME SYSTEMS
3177                          mpiexec  -machinefile hostfile  -n $iia  a.out  <  runfile_atmos &
3178                          mpiexec  -machinefile hostfile  -n $iio  a.out  <  runfile_ocean &
3179#                          mpiexec  -machinefile hostfile  -n $iia  -env coupling_mode atmosphere_to_ocean  a.out  &
3180#                          mpiexec  -machinefile hostfile  -n $iio  -env coupling_mode ocean_to_atmosphere  a.out  &
3181                      fi
3182                      wait
3183
3184                   else
3185
3186                      echo "coupled_run $iia $iio"  >  runfile_atmos
3187
3188                      if [[ $host = lccrayf  ||  $host = lcxe6  ||  $host = lcxt5m ]]
3189                      then
3190
3191                         aprun  -n $ii  -N $tasks_per_node  a.out < runfile_atmos
3192
3193                      elif [[ $host = lck || $host = lckordi ]]
3194                      then
3195
3196                         mpiexec -n $ii  ./a.out  <  runfile_atmos  &
3197
3198                      elif [[ $host = lckyu* ]]
3199                      then
3200
3201                         mpiexec -n $ii --stdin runfile_atmos  ./a.out
3202
3203                      elif [[ $host = lcmuk ]] 
3204                      then
3205
3206                         mpiexec  -machinefile hostfile  -n $ii  a.out  <  runfile_atmos
3207
3208                      fi
3209                      wait
3210                   fi
3211
3212                fi
3213
3214             elif [[ $host = lckyoto ]]
3215             then
3216                set -xv
3217                export P4_RSHCOMMAND=plesh
3218                echo "     P4_RSHCOMMAND = $P4_RSHCOMMAND"
3219                if [[ "$ENVIRONMENT" = BATCH ]]
3220                then
3221                   if [[ "$cond2" = fujitsu ]]
3222                   then
3223                      mpiexec  -n $numprocs  ./a.out  # for fujitsu-compiler
3224                   elif [[ "cond2" = pgi ]]
3225                   then
3226                      mpirun  -np $numprocs  -machinefile ${QSUB_NODEINF}  ./a.out
3227                   else
3228                      mpirun_rsh -np $numprocs -hostfile ${QSUB_NODEINF} MV2_USE_SRQ=0 ./a.out  ||  /bin/true
3229                   fi
3230                else
3231                   if [[ "$cond2" = "" ]]
3232                   then
3233                      mpiruni_rsh -np $numprocs ./a.out  # for intel
3234                   else
3235                      mpirun  -np $numprocs  ./a.out
3236                   fi
3237                fi
3238                set +xv
3239
3240             elif [[ $host = lctit ]]
3241             then
3242                export OMP_NUM_THREADS=$threads_per_task
3243                echo "OMP_NUM_THREADS=$OMP_NUM_THREADS"
3244                if [[ "$threads_per_task" != 1 ]]
3245                then
3246                   export MV2_ENABLE_AFFINITY=0
3247                fi
3248                echo "----- PBS_NODEFILE content:"
3249                cat $PBS_NODEFILE
3250                echo "-----"
3251                (( ii = $numprocs / $threads_per_task ))
3252                echo "mpirun  -np $ii  -hostfile $PBS_NODEFILE ./a.out"
3253                mpirun  -np $ii  -hostfile $PBS_NODEFILE  ./a.out
3254
3255             else
3256                mpprun  -n $numprocs  a.out
3257             fi
3258          else
3259             a.out
3260          fi
3261
3262       fi  # end normal (non-debug) execution
3263
3264    fi  # end explicit execute_command or host-specific execute actions
3265
3266    if [[ $? != 0 ]]
3267    then
3268
3269          # ABORT IN CASE OF RUNTIME ERRORS
3270       printf "\n  +++ runtime error occured"
3271       locat=execution
3272       exit
3273
3274    else
3275
3276       printf "\n$dashes\n  *** execution finished \n"
3277
3278          # STOP THE DVR STREAMING SERVER AND PROCESS THE DVR OUTPUT IN ORDER
3279          # TO CREAT DVRS- AND HTML-FILES CONTAINING ALL STREAMS
3280       if [[ "$dvrserver_id" != "" ]]
3281       then
3282          kill $dvrserver_id
3283          printf "\n  *** dvr server with id=$dvrserver_id has been stopped"
3284
3285             # IF THERE IS A DIRECTORY, DATA HAVE BEEN OUTPUT BY THE
3286             # STREAMING SERVER. OTHERWISE, USER HAS CHOSEN dvrp_output=local
3287          if [[ -d DATA_DVR ]]
3288          then
3289
3290                # ADD THE CURRENT DVR CONFIGURATION FILE TO THE DVR OUTPUT
3291                # DIRECTORY
3292             cp  .dvrserver.config  DATA_DVR
3293
3294                # PROCESS THE DVR OUTPUT (OPTION -s FOR GENERATING
3295                # SEQUENCE MODE DATA TOO)
3296             process_dvr_output  -d DATA_DVR  -f $fname  -s
3297
3298          else
3299
3300                # PROCESS THE LOCAL OUTPUT
3301             process_dvr_output  -l  -d DATA_DVR  -f $fname
3302
3303          fi
3304
3305       elif [[ $(echo $package_list | grep -c dvrp_graphics) != 0 ]]
3306       then
3307
3308             # PROCESS DVR OUTPUT GENERATD IN LOCAL MODE (dvrp_output=local)
3309          process_dvr_output  -l  -d DATA_DVR  -f $fname
3310
3311       fi
3312    fi
3313
3314
3315
3316       # CALL OF combine_plot_fields IN ORDER TO MERGE SINGLE FILES WRITTEN
3317       # BY EACH CORE INTO ONE FILE
3318   if [[ ! -f ${PALM_BIN}/combine_plot_fields${block}.x ]]
3319   then
3320      printf "\n\n\n  +++ WARNING: no combine_plot_fields found for given block \"$cond1 $cond2\""
3321      printf "\n      2d- and/or 3d-data may be incomplete!"
3322      printf "\n      Run \"mbuild -u -h $localhost\" to generate utilities for this block.\n"
3323   elif [[ "$combine_plot_fields" == true ]]
3324   then
3325      if [[ $localhost = lccrayh  ||  $localhost = lccrayb ]]
3326      then
3327         printf "\n\n\n *** post-processing: now executing \"aprun  -n 1  -N 1 combine_plot_fields${block}.x\" ..."
3328         aprun  -n 1  -N 1 combine_plot_fields${block}.x
3329      else
3330         printf "\n\n\n *** post-processing: now executing \"combine_plot_fields${block}.x\" ..."
3331         combine_plot_fields${block}.x
3332      fi
3333   else
3334
3335         # TEMPORARY SOLUTION TO SKIP combine_plot_fields. THIS IS REQUIRED IN CASE OF HUGE AMOUNT OF
3336         # DATA OUTPUT. TO DO: EXTEND THIS BRANCH BY CREATING A BATCH JOB for combine_plot_fields.
3337         # ??? koennen wir das streichen ???
3338      printf "\n\n\n *** post-processing: skipping combine_plot_fields (-Z option set) ..."
3339   fi
3340
3341
3342
3343       # EXECUTE OUTPUT-COMMANDS GIVEN IN THE CONFIGURATION FILE
3344    (( i = 0 ))
3345    while (( i < ioc ))
3346    do
3347       (( i = i + 1 ))
3348       if (( i == 1 ))
3349       then
3350          printf "\n\n  *** execution of OUTPUT-commands:\n$dashes"
3351       fi
3352       printf "\n  >>> ${out_command[$i]}"
3353       eval  ${out_command[$i]}
3354       if (( i == ioc ))
3355       then
3356          printf "\n$dashes\n"
3357       fi
3358    done
3359
3360
3361       # IN TRACE-MODE PRINT CONTENTS OF THE CURRENT (TEMPORARY) WORKING DIRECTORY
3362    if [[ $do_trace = true ]]
3363    then
3364       printf "\n\n"
3365       ls -al
3366    fi
3367
3368
3369
3370       # COPY LOCAL OUTPUT-FILES TO THEIR PERMANENT DESTINATIONS
3371    (( i = 0 ))
3372    while (( i < iout ))
3373    do
3374       (( i = i + 1 ))
3375       if (( i == 1 ))
3376       then
3377          printf "\n\n  *** saving OUTPUT-files:\n$dashes"
3378       fi
3379
3380          # CHECK FOR SINGLE FILE (SERIAL RUN) OR DIRECTORY (ONE FILE PER CORE FOR PARELLEL EXECUTION)
3381       files_for_pes=false; filetyp=file
3382       if [[ "${actionout[$i]}" = pe  &&  -n $numprocs ]]
3383       then
3384          files_for_pes=true; filetyp=directory
3385          actionout[$i]=""
3386       elif [[ "${actionout[$i]}" = pe  &&  ! -n $numprocs ]]
3387       then
3388          actionout[$i]=""
3389       elif [[ "${actionout[$i]}" = arpe  &&  -n $numprocs ]]
3390       then
3391          files_for_pes=true; filetyp=directory
3392          actionout[$i]="ar"
3393       elif [[ "${actionout[$i]}" = arpe  &&  ! -n $numprocs ]]
3394       then
3395          actionout[$i]="ar"
3396       elif [[ "${actionout[$i]}" = flpe  &&  -n $numprocs ]]
3397       then
3398          files_for_pes=true; filetyp=directory
3399          actionout[$i]="fl"
3400       elif [[ "${actionout[$i]}" = flpe  &&  ! -n $numprocs ]]
3401       then
3402          actionout[$i]="fl"
3403       elif [[ "${actionout[$i]}" = trpe  &&  -n $numprocs ]]
3404       then
3405          files_for_pes=true; filetyp=directory
3406          actionout[$i]="tr"
3407       elif [[ "${actionout[$i]}" = trpe  &&  ! -n $numprocs ]]
3408       then
3409          actionout[$i]="tr"
3410       fi
3411
3412       if [[ ! -f ${localout[$i]}  &&  $files_for_pes = false ]]
3413       then
3414          printf "\n  +++ temporary OUTPUT-file  ${localout[$i]}  does not exist\n"
3415       elif [[ ! -d ${localout[$i]}  &&  $files_for_pes = true ]]
3416       then
3417          printf "\n  +++ temporary OUTPUT-file  ${localout[$i]}/....  does not exist\n"
3418       else
3419
3420
3421             # COPY VIA SCP TO LOCAL HOST (ALWAYS IN BINARY MODE USING batch_scp option -m)
3422             # IF TARGET DIRECTORY DOES NOT EXISTS, TRY TO CREATE IT
3423          if [[ "${actionout[$i]}" = tr ]]
3424          then
3425             if [[ $localhost != $fromhost ]]
3426             then
3427                if [[ $files_for_pes = false ]]
3428                then
3429                   cps=""
3430                   cst=""
3431                else
3432                   cps=-c
3433                   cst="/"
3434                fi
3435                if [[ $localhost = nech ]]
3436                then
3437
3438                      # TRANSFER IN SEPERATE JOB
3439                      # FIRST COPY FILE TO TEMPORY DATA DIRECTORY
3440                   [[ ! -d $tmp_data_catalog/TRANSFER ]]  &&  mkdir -p  $tmp_data_catalog/TRANSFER
3441                   file_to_transfer=${fname}_${localout[$i]}_to_transfer_$kennung
3442                   if [[ $files_for_pes = false ]]
3443                   then
3444                      ln -f  ${localout[$i]}  $tmp_data_catalog/TRANSFER/$file_to_transfer
3445                   else
3446                      mkdir  $tmp_data_catalog/TRANSFER/$file_to_transfer
3447                      ln  ${localout[$i]}/*  $tmp_data_catalog/TRANSFER/$file_to_transfer
3448                   fi
3449
3450                   echo "set -x"                                    >    transfer_${localout[$i]}
3451                   echo "cd  $tmp_data_catalog/TRANSFER"            >>   transfer_${localout[$i]}
3452
3453                   printf "\n  >>> OUTPUT: ${localout[$i]}$cst  by SCP in seperate job to"
3454                   printf "\n              ${pathout[$i]}/${localhost}_${fname}${endout[$i]}$cst"
3455                   printf "\n              or higher cycle\n"
3456                   echo "batch_scp $PORTOPT $cps -b -m -u $return_username $return_address  $file_to_transfer \"${pathout[$i]}\" ${localhost}_${fname}${endout[$i]}  ${extout[$i]}"  >>  transfer_${localout[$i]}
3457
3458                   echo "[[ \$? = 0 ]]  &&  rm  $file_to_transfer"  >>  transfer_${localout[$i]}
3459
3460                   if [[ $localhost = nech ]]
3461                   then
3462                      subjob  -d  -c /pf/b/$usern/job_queue  -v  -q pp  -X 0  -m 1000  -t 900  $PORTOPT  transfer_${localout[$i]}
3463                   else
3464                      if [[ "$LOGNAME" = b323013 ]]
3465                      then
3466                         subjob  -v  -q c1  -X 0  -m 1000  -t 900  -c $job_catalog  $PORTOPT  transfer_${localout[$i]}
3467                      else
3468                         subjob  -d  -v  -q c1  -X 0  -m 1000  -t 900  -c $job_catalog  $PORTOPT  transfer_${localout[$i]}
3469                      fi
3470                   fi
3471
3472                else
3473
3474                      # TRANSFER WITHIN THIS JOB
3475                   transfer_failed=false
3476                   printf "\n  >>> OUTPUT: ${localout[$i]}$cst  by SCP to"
3477                   printf "\n              ${pathout[$i]}/${localhost}_${fname}${endout[$i]}$cst\n"
3478                   if [[ $localhost = lccrayb ]]
3479                   then
3480                      ssh $usern@blogin1 ". \\$HOME/.profile; cd $TEMPDIR; batch_scp $PORTOPT $cps -b -m -u $return_username $return_address  ${localout[$i]} \"${pathout[$i]}\" ${localhost}_${fname}${endout[$i]}  ${extout[$i]}"
3481                   elif [[ $localhost = lccrayh ]]
3482                   then
3483                      ssh $usern@hlogin1 ". \\$HOME/.profile; cd $TEMPDIR; batch_scp $PORTOPT $cps -b -m -u $return_username $return_address  ${localout[$i]} \"${pathout[$i]}\" ${localhost}_${fname}${endout[$i]}  ${extout[$i]}"
3484                   elif [[ $localhost = lcbullhh ]]
3485                   then
3486                      ssh $usern@mlogin101 ". \\$HOME/.profile; cd $TEMPDIR; batch_scp $PORTOPT $cps -b -m -u $return_username $return_address  ${localout[$i]} \"${pathout[$i]}\" ${localhost}_${fname}${endout[$i]}  ${extout[$i]}"
3487                   elif [[ $localhost = lcxe6 ]]
3488                   then
3489                      ssh $usern@hexagon ". \\$HOME/.profile; cd $TEMPDIR; batch_scp $PORTOPT $cps -b -m -u $return_username $return_address  ${localout[$i]} \"${pathout[$i]}\" ${localhost}_${fname}${endout[$i]}  ${extout[$i]}"
3490                   else
3491                      batch_scp $PORTOPT $cps -b -m -u $return_username $return_address  ${localout[$i]} "${pathout[$i]}" ${localhost}_${fname}${endout[$i]}  ${extout[$i]}
3492                   fi
3493                   [[ $? != 0 ]]  &&  transfer_failed=true
3494
3495                      # IF TRANSFER FAILED, CREATE BACKUP COPY ON THIS MACHINE
3496                   if [[ $transfer_failed = true ]]
3497                   then
3498                      printf "  +++ transfer failed. Trying to save a copy on this host under:\n"
3499                      printf "      ${pathout[$i]}/${localhost}_${fname}${endout[$i]}_$kennung\n"
3500
3501                         # FIRST CHECK, IF DIRECTORY EXISTS, AND CREATE IT, IF NECESSARY
3502                      eval  local_catalog=${pathout[$i]}
3503                      if [[ ! -d $local_catalog ]]
3504                      then
3505                         printf "  *** local directory does not exist. Trying to create:\n"
3506                         printf "      $local_catalog \n"
3507                         mkdir -p  $local_catalog
3508                      fi
3509                      eval  cp  ${localout[$i]}  ${pathout[$i]}/${localhost}_${fname}${endout[$i]}_$kennung
3510                      transfer_problems=true
3511                   fi
3512                fi
3513             else
3514
3515                   # UNSET actionout. DUE TO THIS SETTING, FILE WILL LATER JUST BE COPIED ON THIS MACHINE
3516                actionout[$i]=""
3517             fi
3518          fi
3519
3520
3521             # APPEND VIA SCP TO LOCAL HOST (ALWAYS IN BINARY MODE USING batch_scp option -m)
3522             # IF TARGET DIRECTORY DOES NOT EXISTS, TRY TO CREATE IT
3523          if [[ "${actionout[$i]}" = tra ]]
3524          then
3525             if [[ $localhost != $fromhost ]]
3526             then
3527                if [[ $localhost = ibmh  ||  $localhost = nech ]]
3528                then
3529
3530                      # TRANSFER IN SEPERATE JOB
3531                      # FIRST COPY FILE TO TEMPORY DATA DIRECTORY
3532                   [[ ! -d $tmp_data_catalog/TRANSFER ]]  &&  mkdir -p  $tmp_data_catalog/TRANSFER
3533                   file_to_transfer=${fname}_${localout[$i]}_to_transfer_$kennung
3534                   ln -f  ${localout[$i]}  $tmp_data_catalog/TRANSFER/$file_to_transfer
3535
3536                   echo "set -x"                                    >    transfer_${localout[$i]}
3537                   echo "cd  $tmp_data_catalog/TRANSFER"            >>   transfer_${localout[$i]}
3538
3539                   printf "\n  >>> OUTPUT: ${localout[$i]}  append by SCP in seperate job to"
3540                   printf "\n              ${pathout[$i]}/${localhost}_${fname}${endout[$i]}"
3541                   printf "\n              or higher cycle\n"
3542                   echo "batch_scp $PORTOPT -A -b -m -u $return_username $return_address  $file_to_transfer \"${pathout[$i]}\" ${localhost}_${fname}${endout[$i]}  ${extout[$i]}"  >>  transfer_${localout[$i]}
3543
3544                   echo "[[ \$? = 0 ]]  &&  rm  $file_to_transfer"  >>  transfer_${localout[$i]}
3545
3546                   if [[ $localhost = nech ]]
3547                   then
3548                      subjob  -d  -c /pf/b/$usern/job_queue  -v  -q pp  -X 0  -m 1000  -t 900  $PORTOPT  transfer_${localout[$i]}
3549                   else
3550                      if [[ $LOGNAME = b323013 ]]
3551                      then
3552                         subjob  -v  -q c1  -X 0  -m 1000  -t 900  -c $job_catalog  $PORTOPT  transfer_${localout[$i]}
3553                      else
3554                         subjob  -d  -v  -q c1  -X 0  -m 1000  -t 900  -c $job_catalog  $PORTOPT  transfer_${localout[$i]}
3555                      fi
3556                   fi
3557
3558                else
3559
3560                      # TRANSFER WITHIN THIS JOB
3561                   transfer_failed=false
3562                   printf "\n  >>> OUTPUT: ${localout[$i]}  append by SCP to"
3563                   printf "\n              ${pathout[$i]}/${localhost}_${fname}${endout[$i]}\n"
3564                   if [[ $localhost = lccrayb ]]
3565                   then
3566                      ssh $usern@blogin1 ". \\$HOME/.profile; cd $TEMPDIR; batch_scp $PORTOPT -A -b -m -u $return_username $return_address  ${localout[$i]} \"${pathout[$i]}\" ${localhost}_${fname}${endout[$i]}  ${extout[$i]}"
3567                   elif [[ $localhost = lccrayh ]]
3568                   then
3569                      ssh $usern@hlogin1 ". \\$HOME/.profile; cd $TEMPDIR; batch_scp $PORTOPT -A -b -m -u $return_username $return_address  ${localout[$i]} \"${pathout[$i]}\" ${localhost}_${fname}${endout[$i]}  ${extout[$i]}"
3570                   elif [[ $localhost = lcxe6 ]]
3571                   then
3572                      ssh $usern@hexagon ". \\$HOME/.profile; cd $TEMPDIR; batch_scp $PORTOPT -A -b -m -u $return_username $return_address  ${localout[$i]} \"${pathout[$i]}\" ${localhost}_${fname}${endout[$i]}  ${extout[$i]}"
3573                   else
3574                      batch_scp $PORTOPT -A -b -m -u $return_username  $return_address ${localout[$i]} "${pathout[$i]}" ${localhost}_${fname}${endout[$i]}  ${extout[$i]}
3575                   fi
3576                   [[ $? != 0 ]]  &&  transfer_failed=true
3577
3578                      # IF TRANSFER FAILED, CREATE BACKUP COPY ON THIS MACHINE
3579                   if [[ $transfer_failed = true ]]
3580                   then
3581                      printf "  +++ transfer failed. Trying to save a copy on this host under:\n"
3582                      printf "      ${pathout[$i]}/${localhost}_${fname}${endout[$i]}_$kennung\n"
3583
3584                         # FIRST CHECK, IF DIRECTORY EXISTS, AND CREATE IT, IF NECESSARY
3585                      eval  local_catalog=${pathout[$i]}
3586                      if [[ ! -d $local_catalog ]]
3587                      then
3588                         printf "  *** local directory does not exist. Trying to create:\n"
3589                         printf "      $local_catalog \n"
3590                         mkdir -p  $local_catalog
3591                      fi
3592
3593                      eval  cp  ${localout[$i]}  ${pathout[$i]}/${localhost}_${fname}${endout[$i]}_$kennung
3594                      transfer_problems=true
3595                   fi
3596                fi
3597             else
3598
3599                   # RESET actionout. DUE TO THIS SETTING, FILE WILL LATER JUST BE APPENDED ON THIS MACHINE
3600                actionout[$i]=a
3601             fi
3602          fi
3603
3604
3605             # OUTPUT-FILE FOR A RESTART-RUN.
3606             # FILE IS MOVED TO THE TEMPORARY DATA DIRECTORY USING link COMMAND.
3607             # OPTION -f IS USED TO OVERWRITE EXISTING FILES.
3608             # AS LAST ACTION, ARCHIVING IS INITIATED.
3609          if [[ "${actionout[$i]}" = fl ]]
3610          then
3611             [[ ! -d $tmp_data_catalog ]]  &&  mkdir -p  $tmp_data_catalog
3612             chmod  g+rx  $tmp_data_catalog
3613             if [[ $files_for_pes = false ]]
3614             then
3615                printf "\n  >>> OUTPUT: ${localout[$i]}  to"
3616                printf "\n              $tmp_data_catalog/${frelout[$i]} (temporary data catalog)\n"
3617                ln -f  ${localout[$i]}  $tmp_data_catalog/${frelout[$i]}
3618             else
3619                printf "\n  >>> OUTPUT: ${localout[$i]}/....  to"
3620                printf "\n              $tmp_data_catalog/${frelout[$i]} (temporary data catalog)\n"
3621                mkdir  $tmp_data_catalog/${frelout[$i]}
3622                cd ${localout[$i]}
3623                for file in $(ls *)
3624                do
3625                   ln -f $file $tmp_data_catalog/${frelout[$i]}
3626                done
3627                cd $TEMPDIR
3628             fi
3629
3630
3631                # CREATE AND SUBMIT ARCHIVING-JOB
3632             if [[ $store_on_archive_system = true ]]
3633             then
3634
3635                if [[ $archive_system = asterix ]]
3636                then
3637                   echo "cd  $tmp_data_catalog"                      >> archive_${frelout[$i]}
3638                   if [[ $files_for_pes = false ]]
3639                   then
3640                      echo "stageout  ${frelout[$i]}  > STAGE_OUTPUT${i}_$kennung" >> archive_${frelout[$i]}
3641                   else
3642                      echo "stageout -t  ${frelout[$i]}  > STAGE_OUTPUT${i}_$kennung" >> archive_${frelout[$i]}
3643                   fi
3644                   echo "cat  STAGE_OUTPUT${i}_$kennung"               >> archive_${frelout[$i]}
3645                   echo "if [[ \$(grep -c \"st.msg:150\"  STAGE_OUTPUT${i}_$kennung) != 0 ]]" >> archive_${frelout[$i]}
3646                   echo "then"                                       >> archive_${frelout[$i]}
3647                   echo "   do_stageout=false"                       >> archive_${frelout[$i]}
3648                   echo "else"                                       >> archive_${frelout[$i]}
3649                   echo "   echo \"  +++ $filetyp ${frelout[$i]}  could not be stored on archive-system\" " >> archive_${frelout[$i]}
3650                   echo "   cat  /dev/null  >  ~/job_queue/ARCHIVE_ERROR_$fname" >> archive_${frelout[$i]}
3651                   echo "   cat  STAGE_OUTPUT${i}_$kennung  >  ~/job_queue/archive_${frelout[$i]}_error" >> archive_${frelout[$i]}
3652                   echo "   echo \"  *** $filetyp ${frelout[$i]} will be copied to \$WORK as backup\" " >> archive_${frelout[$i]}
3653                   if [[ $files_for_pes = false ]]
3654                   then
3655                      echo "   cp   ${frelout[$i]}  \$WORK"                    >> archive_${frelout[$i]}
3656                   else
3657                      echo "   cp -r  ${frelout[$i]}  \$WORK/${frelout[$i]}"   >> archive_${frelout[$i]}
3658                   fi
3659                   echo "   echo \"  *** $filetyp ${frelout[$i]} saved\" " >> archive_${frelout[$i]}
3660                   echo "fi"                                         >> archive_${frelout[$i]}
3661                   echo "rm  STAGE_OUTPUT${i}_$kennung"              >> archive_${frelout[$i]}
3662                elif [[ $archive_system = DMF ]]
3663                then
3664                   echo "cd  $tmp_data_catalog"                      >> archive_${frelout[$i]}
3665                   if [[ $files_for_pes = false ]]
3666                   then
3667                      printf "\n  +++ archiving of single files impossible with $archive_system !\n"
3668                      locat=DMF
3669                      exit
3670                   else
3671                         # ??? nicht benötigte Archiv-Systeme entfernen ???
3672                         # FUER RECHNER IN JUELICH. DORT KOENNTEN AUCH
3673                         # EINZELNE DATEIEN GESICHERT WERDEN (SPAETER KORR.)
3674                      echo "rm -rf  \$ARCHIVE/${frelout[$i]}"     >> archive_${frelout[$i]}
3675                      echo "cp -r  ${frelout[$i]}  \$ARCHIVE"     >> archive_${frelout[$i]}
3676                   fi
3677                elif [[ $archive_system = tivoli ]]
3678                then
3679                   echo "cd  $tmp_data_catalog"                       >> archive_${frelout[$i]}
3680                   if [[ $files_for_pes = false ]]
3681                   then
3682                         # REMOVE EXISTING OLD FILES FROM THE ARCHIVE
3683                      echo "set -x"                                   >> archive_${frelout[$i]}
3684                      echo "rm  -rf  \$PERM/${frelout[$i]}"           >> archive_${frelout[$i]}
3685                      echo "cp  ${frelout[$i]} \$PERM/${frelout[$i]}" >> archive_${frelout[$i]}
3686                   else
3687
3688                      echo "set -x"                                   >> archive_${frelout[$i]}
3689                      echo "rm  -rf  \$PERM/${frelout[$i]}/*"         >> archive_${frelout[$i]}
3690                      echo "[[ ! -d \$PERM/${frelout[$i]} ]] && mkdir $PERM/${frelout[$i]}" >> archive_${frelout[$i]}
3691                      cd  $tmp_data_catalog
3692                      all_files=`ls -1 ${frelout[$i]}/*`
3693                      cd -  > /dev/null
3694                      (( inode = 0 ))
3695                      (( tp1   = tasks_per_node + 1 ))
3696                      while (( inode < nodes ))
3697                      do
3698                         files=`echo $all_files | cut -d" " -f1-$tasks_per_node`
3699                         all_files=`echo $all_files | cut -d" " -f$tp1-`
3700                         echo "tar  cvf \$PERM/${frelout[$i]}/${frelout[$i]}.node_$inode.tar $files"   >> archive_${frelout[$i]}
3701                         (( inode = inode + 1 ))
3702                      done
3703                   fi
3704                elif [[ $archive_system = ut ]]
3705                then
3706                   echo "cd  $tmp_data_catalog"                       >> archive_${frelout[$i]}
3707                   if [[ $files_for_pes = false ]]
3708                   then
3709                         # REMOVE EXISTING OLD FILES FROM THE ARCHIVE
3710                      echo "set -x"                                 >> archive_${frelout[$i]}
3711                      echo "rm  -rf  \$UT/${frelout[$i]}"           >> archive_${frelout[$i]}
3712                      echo "cp  ${frelout[$i]} \$UT/${frelout[$i]}" >> archive_${frelout[$i]}
3713                   else
3714
3715                      echo "set -x"                                 >> archive_${frelout[$i]}
3716                      echo "rm  -rf  \$UT/${frelout[$i]}/*"         >> archive_${frelout[$i]}
3717                      echo "[[ ! -d \$UT/${frelout[$i]} ]] && mkdir $UT/${frelout[$i]}" >> archive_${frelout[$i]}
3718                      cd  $tmp_data_catalog
3719                      all_files=`ls -1 ${frelout[$i]}/*`
3720                      cd -  > /dev/null
3721                      (( inode = 0 ))
3722                      (( tp1   = tasks_per_node + 1 ))
3723                      while (( inode < nodes ))
3724                      do
3725                         files=`echo $all_files | cut -d" " -f1-$tasks_per_node`
3726                         all_files=`echo $all_files | cut -d" " -f$tp1-`
3727                         echo "tar  cvf \$UT/${frelout[$i]}/${frelout[$i]}.node_$inode.tar $files"   >> archive_${frelout[$i]}
3728                         (( inode = inode + 1 ))
3729                      done
3730                   fi
3731                elif [[ $archive_system = none ]]
3732                then
3733                   printf "              +++ archiving on $localhost not available!\n"
3734                fi
3735
3736                if [[ $archive_system != none ]]
3737                then
3738                   if [[ $localhost = nech ]]
3739                   then
3740                      subjob  -d  -c /pf/b/$usern/job_queue  -v  -q pp  -X 0  -m 1000  -t 7200  $PORTOPT  archive_${frelout[$i]}
3741                   fi
3742                   printf "              Archiving of $tmp_data_catalog/${frelout[$i]} initiated (batch job submitted)\n"
3743                fi
3744             else
3745                printf "              +++ caution: option -A is switched off. No archiving on $archive_system!\n"
3746             fi
3747
3748
3749                # CREATE AN EMPTY DIRECTORY IN THE USERS PERMANENT DIRECTORY,
3750                # IN ORDER TO NOTE THE RESPECTIVE CYCLE NUMBER ON THE ARCHIVE SYSTEM
3751                # RESTART-JOBS ARE USING THESE EMPTY-DIRECTORIES TO GET THE CURRENT HIGHEST
3752                # CYCLE NUMBER ON THE ARCHIVE SYSTEM (IN CASE THAT INFORMATIONS ARE DIFFICULT TO
3753                # TO ACCESS FROM THE ARCHIVE-SYSTEM DIRECTLY))
3754             if [[ $files_for_pes = false ]]
3755             then
3756                cat  /dev/null  >  ${pathout[$i]}
3757             else
3758                mkdir -p  ${pathout[$i]}
3759             fi
3760
3761          fi
3762
3763
3764             # COPY FROM THIS HOST TO THE ARCHIVE-SYSTEM
3765             # IF ANY ARCHIVING FAILS, AN ERROR-FLAG-FILE IS SET
3766             # THIS FILE REMAINS TO BE SET, EVEN IF ARCHIVING OF FURTHER FILES IS SUCCESSFULL
3767          if [[ "${actionout[$i]}" = ar ]]
3768          then
3769             if [[ $files_for_pes = false ]]
3770             then
3771                printf "\n  >>> OUTPUT: ${localout[$i]}  to"
3772                printf "\n              ${pathout[$i]}"
3773                printf "\n              File will be copied to archive-system ($archive_system) !\n"
3774             else
3775                printf "\n  >>> OUTPUT: ${localout[$i]}/_....  to"
3776                printf "\n              ${pathout[$i]}"
3777                printf "\n              Directory will be copied to archive-system ($archive_system) !\n"
3778             fi
3779             mv  ${localout[$i]}  ${frelout[$i]}
3780
3781             file_saved=false
3782
3783             if [[ $archive_system = asterix ]]
3784             then
3785                do_stageout=true
3786                (( stageout_anz = 0 ))
3787                while [[ $do_stageout = true ]]
3788                do
3789                   if [[ $files_for_pes = false ]]
3790                   then
3791                      stageout  ${frelout[$i]}  > STAGE_OUTPUT
3792                   else
3793                      stageout  -t  ${frelout[$i]}  > STAGE_OUTPUT
3794                   fi
3795                   cat  STAGE_OUTPUT
3796                   if [[ $(grep -c "st.msg:150"  STAGE_OUTPUT) != 0 ]]
3797                   then
3798                      file_saved=true
3799                      do_stageout=false
3800                   else
3801                      if [[ $files_for_pes = false ]]
3802                      then
3803                         printf "\n  +++ file ${frelout[$i]}  could not be saved on archive-system"
3804                      else
3805                         printf "\n  +++ directory ${frelout[$i]} could not be saved on archive-system"
3806                      fi
3807                      (( stageout_anz = stageout_anz + 1 ))
3808                      if (( stageout_anz == 10 ))
3809                      then
3810                         printf "\n  +++ stoped after 10 unsuccessful tries!"
3811                         archive_save=false
3812                         do_stageout=false
3813                      else
3814                         printf "\n  *** new try to store on archive after 15 min:"
3815                         sleep 900
3816                      fi
3817                   fi
3818                done
3819             elif [[ $archive_system = DMF ]]
3820             then
3821                if [[ $files_for_pes = false ]]
3822                then
3823                   printf "\n  +++ archiving of single files impossible on $archive_system!\n"
3824                   locat=DMF
3825                   exit
3826                else
3827                   rm -rf  $ARCHIVE/${frelout[$i]}
3828                   cp -r  ${frelout[$i]}  $ARCHIVE
3829                fi
3830                file_saved=true
3831             elif [[ $archive_system = tivoli ]]
3832             then
3833                   # ARCHIVING ONLY POSSIBLE VIA BATCH-JOB
3834                   # IN THE MEANTIME, FILE IS STORED IN THE TEMPORARY DATA DIRECTORY,
3835                   # BECAUSE MRUN'S CURRENT TEMPORARY WORKING DIRECTORY MAY ALREADY BE DELETED
3836                   # WHEN THE ARCHIVE-JOB IS EXECUTED
3837                [[ ! -d $tmp_data_catalog ]]  &&  mkdir -p  $tmp_data_catalog
3838                chmod  g+rx  $tmp_data_catalog
3839                if [[ $files_for_pes = false ]]
3840                then
3841                   ln -f  ${frelout[$i]}  $tmp_data_catalog/${frelout[$i]}
3842                else
3843                   mkdir  $tmp_data_catalog/${frelout[$i]}
3844                   ln -f  ${frelout[$i]}/*  $tmp_data_catalog/${frelout[$i]}
3845                fi
3846
3847                   # GENERATE AND SUBMIT BATCH-JOB
3848                   # FILE HAS TO BE DELETED FROM THE TEMPORARY DATA DIRECTORY
3849                   # DELETE OLD EXISTING FILES FROM THE ARCHIVE
3850                echo "cd  $tmp_data_catalog"                       >  archive_${frelout[$i]}
3851                if [[ $files_for_pes = false ]]
3852                then
3853                   echo "rm  -rf  \$PERM/${frelout[$i]}"           >> archive_${frelout[$i]}
3854                   echo "cp  ${frelout[$i]} \$PERM/${frelout[$i]}" >> archive_${frelout[$i]}
3855                   echo "rm  -rf  ${frelout[$i]}"                  >> archive_${frelout[$i]}
3856                else
3857                   echo "rm  -rf  \$PERM/${frelout[$i]}.tar"       >> archive_${frelout[$i]}
3858                   echo "tar  cvf \$PERM/${frelout[$i]}.tar ${frelout[$i]}" >> archive_${frelout[$i]}
3859                   echo "rm  -rf  ${frelout[$i]}"                  >> archive_${frelout[$i]}
3860                fi
3861
3862                subjob  -v  -d  -q cdata  -X 0  -m 1000  -t 43200  -c $job_catalog  $PORTOPT  archive_${frelout[$i]}
3863                printf "              Archiving of $tmp_data_catalog/${frelout[$i]} initiated (batch job submitted)\n"
3864                file_saved=true
3865
3866             elif [[ $archive_system = ut ]]
3867             then
3868                   # ARCHIVING ONLY POSSIBLE VIA BATCH-JOB
3869                   # IN THE MEANTIME, FILE IS STORED IN THE TEMPORARY DATA DIRECTORY,
3870                   # BECAUSE MRUN'S CURRENT TEMPORARY WORKING DIRECTORY MAY ALREADY BE DELETED
3871                   # WHEN THE ARCHIVE-JOB IS EXECUTED
3872                [[ ! -d $tmp_data_catalog ]]  &&  mkdir -p  $tmp_data_catalog
3873                chmod  g+rx  $tmp_data_catalog
3874                if [[ $files_for_pes = false ]]
3875                then
3876                   ln -f  ${frelout[$i]}  $tmp_data_catalog/${frelout[$i]}
3877                else
3878                   mkdir  $tmp_data_catalog/${frelout[$i]}
3879                   ln -f  ${frelout[$i]}/*  $tmp_data_catalog/${frelout[$i]}
3880                fi
3881
3882                   # GENERATE AND SUBMIT BATCH-JOB
3883                   # FILE HAS TO BE DELETED FROM THE TEMPORARY DATA DIRECTORY
3884                   # DELETE OLD EXISTING FILES FROM THE ARCHIVE
3885                echo "cd  $tmp_data_catalog"                       >  archive_${frelout[$i]}
3886                if [[ $files_for_pes = false ]]
3887                then
3888                   echo "rm  -rf  \$UT/${frelout[$i]}"           >> archive_${frelout[$i]}
3889                   echo "cp  ${frelout[$i]} \$UT/${frelout[$i]}" >> archive_${frelout[$i]}
3890                   echo "rm  -rf  ${frelout[$i]}"                >> archive_${frelout[$i]}
3891                else
3892                   echo "rm  -rf  \$UT/${frelout[$i]}.tar"       >> archive_${frelout[$i]}
3893                   echo "tar  cvf \$UT/${frelout[$i]}.tar ${frelout[$i]}" >> archive_${frelout[$i]}
3894                   echo "rm  -rf  ${frelout[$i]}"                >> archive_${frelout[$i]}
3895                fi
3896
3897                subjob  -v  -c /pf/b/$usern/job_queue  -d  -q pp  -X 0  -m 1000  -t 7200  $PORTOPT  archive_${frelout[$i]}
3898                printf "              Archiving of $tmp_data_catalog/${frelout[$i]} initiated (batch job submitted)\n"
3899                file_saved=true
3900
3901             else
3902                printf "\n  +++ archive_system=\"$archive_system\"  archiving impossible!"
3903                archive_save=false
3904             fi
3905
3906                # CREATE EMPTY FLAG-FILE OR -DIRECTORY
3907                # IN ORDER TO NOTE THE RESPECTIVE CYCLE NUMBER ON THE ARCHIVE SYSTEM
3908                # RESTART-JOBS ARE USING THESE EMPTY-DIRECTORIES TO GET THE CURRENT HIGHEST
3909                # CYCLE NUMBER ON THE ARCHIVE SYSTEM (IN CASE THAT INFORMATIONS ARE DIFFICULT TO
3910                # TO ACCESS FROM THE ARCHIVE-SYSTEM DIRECTLY))
3911             if [[ $file_saved = true ]]
3912             then
3913                if [[ $files_for_pes = false ]]
3914                then
3915                   cat  /dev/null  >  ${pathout[$i]}
3916                else
3917                   mkdir -p  ${pathout[$i]}
3918                fi
3919             fi
3920
3921          fi
3922
3923             # APPEND ON THIS MACHINE
3924          if [[ "${actionout[$i]}" = "a" ]]
3925          then
3926             if [[ "${extout[$i]}" != " "  &&  "${extout[$i]}" != "" ]]
3927             then
3928                printf "\n  >>> OUTPUT: ${localout[$i]}  append to  ${pathout[$i]}.${extout[$i]}\n"
3929                cat  ${localout[$i]}  >>  ${pathout[$i]}.${extout[$i]}
3930             else
3931                printf "\n  >>> OUTPUT: ${localout[$i]}  append to  ${pathout[$i]}\n"
3932                cat  ${localout[$i]}  >>  ${pathout[$i]}
3933             fi
3934          fi
3935
3936             # COPY ON THIS MACHINE
3937             # COPY HAS TO BE USED, BECAUSE MOVE DOES NOT WORK IF FILE-ORIGIN AND TARGET ARE
3938             # ON DIFFERENT FILE-SYSTEMS
3939          if [[ "${actionout[$i]}" = ""  &&  $files_for_pes = false ]]
3940          then
3941
3942                # COPY IN CASE OF RUNS ON SINGLE CORES
3943             if [[ "${extout[$i]}" != " "  &&  "${extout[$i]}" != "" ]]
3944             then
3945                printf "\n  >>> OUTPUT: ${localout[$i]}  to  ${pathout[$i]}.${extout[$i]}\n"
3946                if [[ $link_local_output = true ]]
3947                then
3948                    printf "      using ln -f\n"
3949                    ln -f  ${localout[$i]}  ${pathout[$i]}.${extout[$i]}
3950                fi
3951                # If "ln -f" fails of if "$link_local_output = false" do a normal "cp"
3952                if [[ ! -f "${pathout[$i]}.${extout[$i]}" ]]
3953                then
3954                    if [[ $link_local_output = true ]]
3955                    then
3956                        printf "      ln failed, using cp...\n"
3957                    fi
3958                    cp  ${localout[$i]}  ${pathout[$i]}.${extout[$i]}
3959                fi
3960             else
3961                printf "\n  >>> OUTPUT: ${localout[$i]}  to  ${pathout[$i]}\n"
3962                if [[ $link_local_output = true ]]
3963                then
3964                    printf "      using ln -f\n"
3965                    ln -f  ${localout[$i]}  ${pathout[$i]}
3966                fi
3967                # If "ln -f" fails of if "$link_local_output = false" do a normal "cp"
3968                if [[ ! -f "${pathout[$i]}" ]]
3969                then
3970                    if [[ $link_local_output = true ]]
3971                    then
3972                        printf "      ln failed, using cp...\n"
3973                    fi
3974                    cp  ${localout[$i]}  ${pathout[$i]}
3975                fi
3976             fi
3977
3978          elif [[ "${actionout[$i]}" = ""  &&  $files_for_pes = true ]]
3979          then
3980
3981                # FILES FROM THE DIFFERENT CORES ARE MOVED WITH ln-COMMAND TO THE PERMANENT DIRECTORY
3982                # AS A FIRST STEP, THE PERMANENT DIRECTORY IS CREATED
3983             printf "\n  >>> OUTPUT: ${localout[$i]}/_....  to  ${pathout[$i]}\n"
3984             if [[ $link_local_output = true ]]
3985             then
3986                 printf "      using ln -f\n"
3987                 mkdir  ${pathout[$i]}
3988                 cd ${localout[$i]}
3989                 for file in $(ls *)
3990                 do
3991                   ln -f $file  ${pathout[$i]}
3992                 done
3993                 cd $TEMPDIR
3994             fi
3995
3996                # IF "ln -f" HAS FAILED OR IF "$link_local_output = false" DO A NORMAL COPY "cp -r"
3997             if [[ ! -f "${pathout[$i]}/_0000" ]]
3998             then
3999                 if [[ $link_local_output = true ]]
4000                 then
4001                     printf "      ln failed for .../_0000, using cp...\n"
4002                 fi
4003                 cp -r  ${localout[$i]}  ${pathout[$i]}
4004             fi
4005
4006          fi
4007       fi
4008    done
4009    if (( i != 0 ))
4010    then
4011       if [[ $transfer_problems = true ]]
4012       then
4013          printf "\n$dashes\n  *** OUTPUT-files saved"
4014          printf "\n  +++ WARNING: some data transfers failed! \n"
4015       else
4016          printf "\n$dashes\n  *** all OUTPUT-files saved \n"
4017       fi
4018    fi
4019
4020
4021       # IF REQUIRED, START A RESTART-JOB
4022       # FILE CONTINUE_RUN MUST HAVE BEEN CREATED BY THE EXECUTABLE (PALM)
4023    if [[ -f CONTINUE_RUN ]]
4024    then
4025
4026       if [[ $archive_save = true ]]
4027       then
4028
4029             # ADD RESTART-OPTIONS TO THE MRUN-CALL (IF THEY ARE NOT USED ALREADY):
4030             # -C TELLS MRUN THAT IT IS A RESTART-RUN
4031             # -v SILENT MODE WITHOUT INTERACTIVE QUERIES
4032             # -n BATCH-MODE (IMPORTANT ONLY IN CASE OF BATCH JOBS ON THE LOCAL MACHINE)
4033          [[ $(echo $mc | grep -c "\-C") = 0 ]]  &&  mc="$mc -C"
4034          [[ $(echo $mc | grep -c "\-v") = 0 ]]  &&  mc="$mc -v"
4035          [[ $(echo $mc | grep -c "\-b") = 0 ]]  &&  mc="$mc -b"
4036          if [[ $(echo $mc | grep -c "#") != 0 ]]
4037          then
4038             mc=`echo $mc | sed 's/#/f/g'`
4039          fi
4040
4041
4042             # START THE RESTART-JOB
4043          printf "\n\n  *** initiating restart-run on \"$return_address\" using command:\n"
4044          echo "      $mc"
4045          printf "\n$dashes\n"
4046          if [[ $localhost != $fromhost ]]
4047          then
4048
4049             if [[ $localhost = lcbullhh  ||  $localhost = lccrayb  ||  $localhost = lccrayh  ||  $localhost = nech  ||  $localhost = ibmh  ||  $localhost = ibmkisti  ||  $localhost = ibmku  ||  $localhost = ibms  ||  $localhost = lcflow  ||  $localhost = lckyu*  ||  $localhost = lcxe6 ]]
4050             then
4051                echo "*** ssh will be used to initiate restart-runs!"
4052                echo "    return_address=\"$return_address\" "
4053                echo "    return_username=\"$return_username\" "
4054                if [[ $(echo $return_address | grep -c "130.75.105") = 1 ]]
4055                then
4056                   if [[ $localhost = ibmh ]]
4057                   then
4058                      ssh $SSH_PORTOPT $usern@136.172.40.15 "ssh $SSH_PORTOPT $return_address -l $return_username \". \\\$HOME/.profile; module load intel-compiler hdf5 netcdf; PATH=\\\$PATH:$LOCAL_MRUN_PATH;export PALM_BIN=$LOCAL_MRUN_PATH;cd $LOCAL_PWD; $mc\" "
4059                   elif [[ $localhost = lcbullhh ]]
4060                   then
4061                      ssh $SSH_PORTOPT $usern@mlogin101 "ssh $SSH_PORTOPT $return_address -l $return_username \". \\\$HOME/.profile; module load intel-compiler hdf5 netcdf; PATH=\\\$PATH:$LOCAL_MRUN_PATH;export PALM_BIN=$LOCAL_MRUN_PATH;cd $LOCAL_PWD; $mc\" "
4062                   elif [[ $localhost = lccrayb ]]
4063                   then
4064                      ssh $usern@blogin1 "ssh $SSH_PORTOPT $return_address -l $return_username \". \\\$HOME/.profile; module load intel-compiler hdf5 netcdf; PATH=\\\$PATH:$LOCAL_MRUN_PATH; export PALM_BIN=$LOCAL_MRUN_PATH;cd $LOCAL_PWD; $mc\" "
4065                   elif [[ $localhost = lccrayh ]]
4066                   then
4067                      ssh $usern@hlogin1 "ssh $SSH_PORTOPT $return_address -l $return_username \". \\\$HOME/.profile; module load intel-compiler hdf5 netcdf; PATH=\\\$PATH:$LOCAL_MRUN_PATH; export PALM_BIN=$LOCAL_MRUN_PATH;cd $LOCAL_PWD; $mc\" "
4068                   elif [[ $localhost = lcxe6 ]]
4069                   then
4070                      ssh $usern@hexagon "ssh $SSH_PORTOPT $return_address -l $return_username \". \\\$HOME/.profile; module load intel-compiler hdf5 netcdf; PATH=\\\$PATH:$LOCAL_MRUN_PATH; export PALM_BIN=$LOCAL_MRUN_PATH;cd $LOCAL_PWD; $mc\" "
4071                   else
4072                      ssh $SSH_PORTOPT $return_address -l $return_username ". \\\$HOME/.profile; module load intel-compiler hdf5 netcdf; PATH=\$PATH:$LOCAL_MRUN_PATH;export PALM_BIN=$LOCAL_MRUN_PATH;cd $LOCAL_PWD; $mc "
4073                   fi
4074                else
4075                   if [[ $localhost = ibmkisti ]]
4076                   then
4077                      ssh $SSH_PORTOPT $usern@gaiad "ssh $SSH_PORTOPT $return_address -l $return_username \"PATH=\\\$PATH:$LOCAL_MRUN_PATH;export PALM_BIN=$LOCAL_MRUN_PATH;cd $LOCAL_PWD; $mc\" "
4078                   elif [[ $localhost = lcflow ]]
4079                   then
4080                      /usr/bin/ssh $SSH_PORTOPT $return_address -l $return_username "PATH=\$PATH:$LOCAL_MRUN_PATH;export PALM_BIN=$LOCAL_MRUN_PATH;cd $LOCAL_PWD; $mc "
4081                   elif [[ $localhost = lccrayb ]]
4082                   then
4083                      ssh $usern@blogin1 "ssh $SSH_PORTOPT $return_address -l $return_username \"PATH=\\\$PATH:$LOCAL_MRUN_PATH;export PALM_BIN=$LOCAL_MRUN_PATH;cd $LOCAL_PWD; $mc\" "
4084                   elif [[ $localhost = lccrayh ]]
4085                   then
4086                      ssh $usern@hlogin1 "ssh $SSH_PORTOPT $return_address -l $return_username \"PATH=\\\$PATH:$LOCAL_MRUN_PATH;export PALM_BIN=$LOCAL_MRUN_PATH;cd $LOCAL_PWD; $mc\" "
4087                   else
4088                      ssh $SSH_PORTOPT $return_address -l $return_username "PATH=\$PATH:$LOCAL_MRUN_PATH;export PALM_BIN=$LOCAL_MRUN_PATH;cd $LOCAL_PWD; $mc "
4089                   fi
4090                fi
4091             else
4092                printf "\n  +++ no restart mechanism available for host \"$localhost\" "
4093                locat=restart; exit
4094             fi
4095
4096                # WAIT TO ALLOW THE RESTART-JOB TO BE QUEUED, BEFORE THE CURRENT JOB IS FINISHED
4097             if [[ $queue = special1q ]]
4098             then
4099                sleep 120
4100             else
4101                sleep 30
4102             fi
4103
4104          else
4105
4106                # JOBS RUNNING (AND STARTED) ON THE LOCAL MACHINE CAN DIRECTLY CALL MRUN (WITHOUT
4107                # USING SSH)
4108             cd $LOCAL_PWD
4109             if [[ $localhost = lckyuh ]]
4110             then
4111                printf "\n  +++ WARNING: no restart mechanism available for host \"$localhost\" "
4112                printf "\n               please restart job manually using command:\n"
4113                printf "\n               \"$mc\" "
4114             else
4115                eval  $mc                # THE ' MUST BE EVALUATED
4116             fi
4117             cd -  > /dev/null
4118          fi
4119          if [[ $localhost = lckyuh ]]
4120          then
4121             printf "\n$dashes\n  *** restart-run to be initiated manually\n"
4122          else
4123             printf "\n$dashes\n  *** restart-run initiated \n"
4124          fi
4125
4126
4127             # DELETE INPUT-(RESTART)FILES, WHICH HAVE BEEN FETCHED FROM THE TEMPORARY DATA
4128             # DIRECTORY, BACAUSE THEY ARE NOT REQUIRED BY THE RESTART-JOB.
4129             # THIS IS DONE IN ORDER TO AVOID EXCEEDING DISC QUOTAS OR DISC SPACE (RESTART-FILES
4130             # MAY BE VERY HUGE)
4131          (( i = 0 ))
4132          while (( i < iin ))
4133          do
4134             (( i = i + 1 ))
4135             if [[ "${got_tmp[$i]}" = true   &&  $keep_data_from_previous_run = false ]]
4136             then
4137                rm -r  $tmp_data_catalog/${frelin[$i]}
4138             fi
4139          done
4140
4141       else
4142
4143          printf "\n  +++ no restart-run possible, since errors occured"
4144          printf "\n      during the archive process"
4145       fi
4146
4147    fi
4148
4149
4150   
4151       # SEND EMAIL NOTIFICATION ABOUT THE FINISHED RUN
4152    if [[ "$email_notification" != "none" ]]
4153    then
4154
4155       if [[ $localhost != $fromhost ]]
4156       then
4157          if [[ -f CONTINUE_RUN ]]
4158          then
4159             echo "PALM restart run necessary"        >   email_text
4160             echo "description header of actual run:" >>  email_text
4161             cat  CONTINUE_RUN                        >>  email_text
4162             echo "mrun-command to restart:"          >>  email_text
4163             echo "$mc"                               >>  email_text
4164          else
4165             echo "PALM run with base filename \"$fname\" on host \"$localhost\" finished"  >  email_text
4166          fi
4167          mail  $email_notification  <  email_text
4168          printf "\n  *** email notification sent to \"$email_notification\" "
4169       fi
4170    fi
4171
4172
4173
4174       # ALL ACTIONS FINISHED, TEMPORARY WORKING-DIRECTORY CAN BE DELETED
4175    cd  $HOME
4176    [[ $delete_temporary_catalog = true ]]  &&  rm -rf $TEMPDIR
4177
4178 else
4179
4180       # PREPARING ACTIONS,
4181       # IF A BATCH-JOB IS TO BE GENERATED AND STARTED ON A REMOTE-MACHINE GERECHNET
4182
4183       # BUILD THE MRUN-COMMAND TO BE CALLED IN THE BATCH-JOB ON THE REMOTE-MACHINE
4184    mrun_com="$mrun_script_name -a $afname -c $config_file -d $fname -h $host -H $fromhost -m $memory -t $cpumax -q $queue -R $return_address -U $return_username -u $remote_username"
4185    [[ "$cpp_opts" != "" ]]       &&  mrun_com=${mrun_com}" -D \"$cpp_opts\""
4186    [[ "$global_revision" != "" ]]  &&  mrun_com=${mrun_com}" -G \"$global_revision\""
4187    [[ $group_number != none ]]   &&  mrun_com=${mrun_com}" -g $group_number"
4188    [[ $do_compile = true ]]      &&  mrun_com=${mrun_com}" -s \"$source_list\""
4189    [[ "$input_list" != "" ]]     &&  mrun_com=${mrun_com}" -i \"$input_list\""
4190    [[ $ignore_archive_error = true ]]  &&  mrun_com=${mrun_com}" -I"
4191    [[ $keep_data_from_previous_run = true ]]  &&  mrun_com=${mrun_com}" -k"
4192    [[ "$additional_conditions" != "" ]]  &&  mrun_com=${mrun_com}" -K \"$additional_conditions\""
4193    [[ "$output_list" != "" ]]    &&  mrun_com=${mrun_com}" -o \"$output_list\""
4194    [[ "$read_from_config" = false ]]  &&  mrun_com=${mrun_com}" -S"
4195    [[ $do_trace = true ]]        &&  mrun_com=${mrun_com}" -x"
4196    [[ "$numprocs" != "" ]]       &&  mrun_com=${mrun_com}" -X $numprocs"
4197    if [[ $use_openmp = true ]]
4198    then
4199       mrun_com=${mrun_com}" -O $threads_per_task"
4200    fi
4201    [[ "$tasks_per_node" != "" ]]  &&  mrun_com=${mrun_com}" -T $tasks_per_node"
4202    [[ $store_on_archive_system = true ]]  &&  mrun_com=${mrun_com}" -A"
4203    [[ $package_list != "" ]]     &&  mrun_com=${mrun_com}" -p \"$package_list\""
4204    [[ $return_password != "" ]]  &&  mrun_com=${mrun_com}" -P $return_password"
4205    [[ $delete_temporary_catalog = false ]]  &&  mrun_com=${mrun_com}" -B"
4206    [[ $node_usage != default  &&  "$(echo $node_usage | cut -c1-3)" != "sla"  &&  $node_usage != novice ]]  &&  mrun_com=${mrun_com}" -n $node_usage"
4207    [[ "$ocean_file_appendix" = true ]]  &&  mrun_com=${mrun_com}" -y"
4208    [[ $run_coupled_model = true ]]  &&  mrun_com=${mrun_com}" -Y \"$coupled_dist\""
4209    [[ "$check_namelist_files" = false ]]  &&  mrun_com=${mrun_com}" -z"
4210    [[ "$combine_plot_fields" = false ]]  &&  mrun_com=${mrun_com}" -Z"
4211    [[ "$max_par_io_str" != "" ]]  &&  mrun_com=${mrun_com}" -w $max_par_io_str"
4212    if [[ $do_remote = true ]]
4213    then
4214       printf "\n>>>> MRUN-command on execution host:\n>>>> $mrun_com \n"
4215    fi
4216
4217
4218       # CREATE EXECUTABLE FOR BATCH JOB
4219    if [[ $create_executable_for_batch = true  &&  $restart_run != true ]]
4220    then
4221
4222       printf "\n  *** creating the executable for batch job\n"
4223
4224          # METHOD ONLY WORKS FOR BATCH JOBS ON LOCAL HOSTS
4225       if [[ $host != $localhost ]]
4226       then
4227          printf "\n  +++ creation of executables is only allowed for batch jobs on local hosts."
4228          printf "\n      Please set create_executable_for_batch = false in the config-file.\n"
4229          locat=create_executable; exit
4230       fi
4231
4232       mkdir  $working_directory/SOURCES_FOR_RUN_${fname}/TMPDIR_FOR_CREATING_EXECUTABLE
4233       cd  $working_directory/SOURCES_FOR_RUN_${fname}/TMPDIR_FOR_CREATING_EXECUTABLE
4234
4235       cp  $make_depository  .
4236       tar -xf  $make_depository  >  /dev/null  2>&1
4237       cp  ../*  .   >  /dev/null  2>&1
4238
4239       make $mopts -f Makefile PROG=a.out  F90=$compiler_name  COPT="$cpp_options"  F90FLAGS="$fopts"  LDFLAGS="$lopts"
4240
4241       if [[ $? != 0  ||  "$compile_error" = true  ||  "$module_compile_error" = true ]]
4242       then
4243          printf "\n  +++ error occured while compiling or linking"
4244          locat=compile
4245          exit
4246       fi
4247
4248       mv  a.out  ..
4249       cd -  >  /dev/null  2>&1
4250       rm -rf  $working_directory/SOURCES_FOR_RUN_${fname}/TMPDIR_FOR_CREATING_EXECUTABLE
4251
4252       printf "  *** executable created in \"$working_directory/SOURCES_FOR_RUN_${fname}\"\n "
4253
4254    fi
4255
4256
4257       # BUILD THE JOB-SCRIPTS ON FILE jobfile
4258    jobfile=jobfile.$RANDOM
4259
4260
4261       # CREATE TEMPORARY DIRECTORY AND SWITCH TO IT
4262    echo  "mkdir  $TEMPDIR"      >>  $jobfile
4263    echo  "cd  $TEMPDIR"         >>  $jobfile
4264
4265
4266       # ACTIVATE ERROR-TRACEBACK
4267    if [[ $do_trace = true ]]
4268    then
4269       echo  "set -x"                                    >>  $jobfile
4270    else
4271       echo  "set +vx"                                   >>  $jobfile
4272    fi
4273
4274
4275       # INITIALIZE THE ENVIRONMENT AND LOAD MODULES
4276    if [[ "$init_cmds" != "" ]]
4277    then
4278       echo  "$init_cmds"        >>  $jobfile
4279    fi
4280    if [[ "$module_calls" != "" ]]
4281    then
4282       echo  "$module_calls"     >>  $jobfile
4283    fi
4284
4285
4286       # PROVIDE SOURCE-CODE FILES, MRUN-SCRIPT AND CONFIGURATION-FILE FOR THE JOB
4287       # then-CLAUSE: FILES ARE COLLECTED IN THE SOURCES_FOR_RUN_... DIRECTORY ON THE LOCAL HOST,
4288       #              WHICH IS THEN FETCHED FROM THE BATCH-JOB BY USING cp/scp
4289       #              THE SOURCE-CODE FILES ALREADY EXIST IN THIS DIRECTORY
4290       # else-CLAUSE: FILE-CONTENTS ARE PUT INTO THE JOB-FILE AS HERE-DOCUMENTS
4291       #              THIS MAY CREATE A QUITE LARGE JOB-FILE, WHICH CAN CAUSE PROBLEMS WITH SOME
4292       #              QUEUEING-SYSTEMS
4293    if [[ $host = ibmkisti  ||  $host = lcbullhh  ||  $host = lccrayb  ||  $host = lccrayf  ||  $host = lccrayh ]]
4294    then
4295
4296          # COPY CONFIGURATION-FILE AND MRUN-SCRIPT INTO THE SOURCES_FOR_RUN... DIRECTORY
4297       if [[ $restart_run != true ]]
4298       then
4299          cp  $config_file  $working_directory/SOURCES_FOR_RUN_$fname
4300          cp  ${PALM_BIN}/$mrun_script_name  $working_directory/SOURCES_FOR_RUN_$fname
4301       fi
4302
4303          # COPY THE SOURCES_FOR_RUN... DIRECTORY FROM THE LOCAL HOST TO THE JOB VIA scp
4304          # (then-CLAUSE: JOBS ON THE LOCAL HOST CAN JUST USE cp)
4305       echo  "set -x"  >>  $jobfile
4306       if [[ $host = $localhost ]]
4307       then
4308             # DUE TO UNKNOWN REASONS, COPY WITH cp COMMAND CREATES CORRUPT
4309             # FILES ON CRAY XC30 SYSTEMS (CSC HELSINKI), rsync IS USED INSTEAD
4310          if [[ $(echo $host | cut -c1-6) = lccray ]]
4311          then
4312             echo  "rsync -av -t  $working_directory/SOURCES_FOR_RUN_$fname  ."  >>  $jobfile
4313          else
4314             echo  "cp -r  $working_directory/SOURCES_FOR_RUN_$fname  ."  >>  $jobfile
4315          fi
4316
4317       else
4318          if [[ $host = ibmkisti ]]
4319          then
4320                # ON KISTI'S IBM FIREWALL IS ONLY OPENED ON INTERACTIVE NODE
4321             echo  "localdir=\`pwd\`"                            >>  $jobfile
4322             echo  "ssh $SSH_PORTOPT $remote_username@gaiad \"cd \$localdir; scp $PORTOPT -r  $return_username@$return_address:$working_directory/SOURCES_FOR_RUN_$fname .\" "  >>  $jobfile
4323         elif [[ $host = lcbullhh ]]
4324          then
4325             echo  "localdir=\`pwd\`"                            >>  $jobfile
4326             echo  "ssh $SSH_PORTOPT $remote_username@mlogin101 \"cd \$localdir; scp $PORTOPT -r  $return_username@$return_address:$working_directory/SOURCES_FOR_RUN_$fname .\" "  >>  $jobfile
4327
4328          elif [[ $host = lccrayb ]]
4329          then
4330             echo  "localdir=\`pwd\`"                            >>  $jobfile
4331             echo  "ssh $SSH_PORTOPT $remote_username@blogin1 \"cd \$localdir; scp $PORTOPT -r  $return_username@$return_address:$working_directory/SOURCES_FOR_RUN_$fname .\" "  >>  $jobfile
4332          elif [[ $host = lccrayh ]]
4333          then
4334             echo  "localdir=\`pwd\`"                            >>  $jobfile
4335             echo  "ssh $SSH_PORTOPT $remote_username@hlogin1 \"cd \$localdir; scp $PORTOPT -r  $return_username@$return_address:$working_directory/SOURCES_FOR_RUN_$fname .\" "  >>  $jobfile
4336
4337          else
4338             echo  "scp $PORTOPT -r $return_username@$return_address:$working_directory/SOURCES_FOR_RUN_$fname ."  >>  $jobfile
4339          fi
4340       fi
4341       echo  "export SOURCES_COMPLETE=true"                      >>  $jobfile
4342
4343          # MOVE MRUN-SCRIPT AND CONFIGURATION-FILE FROM THE SOURCES_FOR_RUN... DIRECTORY TO THE
4344          # WORKING DIRECTORY OF THE JOB
4345       echo  "mv  SOURCES_FOR_RUN_$fname/$config_file  . "       >>  $jobfile
4346       echo  "mv  SOURCES_FOR_RUN_$fname/$mrun_script_name  . "  >>  $jobfile
4347       echo  "chmod u+rwx  $mrun_script_name"                    >>  $jobfile
4348       echo  "execute_mrun=true"                                 >>  $jobfile
4349       echo  " "                                                 >>  $jobfile
4350
4351    else
4352
4353          # PROVIDE SOURCE-CODE FILES AND MAKEFILE AS HERE DOCUMENT
4354       if [[ $do_compile = true ]]
4355       then
4356
4357          source_catalog=SOURCES_FOR_RUN_$fname
4358
4359              # CREATE SOURCES_FOR_RUN... DIRECTORY TO STORE THE SOURCE CODE FILES AND THE MAKEFILE
4360          echo  "mkdir  SOURCES_FOR_RUN_$fname"                >>  $jobfile
4361          echo  "export SOURCES_COMPLETE=true"                 >>  $jobfile
4362          echo  "cd     SOURCES_FOR_RUN_$fname"                >>  $jobfile
4363
4364          for  filename  in  $source_list
4365          do
4366                # BACKSLASH IS USED FOR MASKING
4367             echo  "cat > $filename << \"%END%\""              >>  $jobfile
4368             cat   $source_catalog/$filename                   >>  $jobfile
4369             echo  " "                                         >>  $jobfile
4370             echo  "%END%"                                     >>  $jobfile
4371             echo  " "                                         >>  $jobfile
4372          done
4373
4374             # BACKSLASH IS USED FOR MASKING
4375          echo  "cat > Makefile << \"%END%\""               >>  $jobfile
4376          cat   $source_catalog/Makefile                    >>  $jobfile
4377          echo  " "                                         >>  $jobfile
4378          echo  "%END%"                                     >>  $jobfile
4379          echo  " "                                         >>  $jobfile
4380
4381          echo  "cd -  > /dev/null"                         >>  $jobfile
4382
4383       fi
4384
4385
4386          # PROVIDE THE CONFIGURATION-FILE AS HERE-DOCUMENT
4387          # BACKSLASH IS USED FOR MASKING
4388          # LINES WITH #$ IN THE CONFIGURATION-FILE, COMING FROM THE SVN KEYWORD SUBSTITUTION,
4389          # ARE REMOVED FROM THE FILE IN ORDER TO AVOID PROBLEMS WITH THE SGE BATCH SYSTEM
4390       echo  "cat > $config_file << \"%END%\""      >>  $jobfile
4391       if [[ $host = lckyuh ]]
4392       then
4393             # NO CROSS-COMPILER ON COMPUTE NODE
4394          sed  's/frtpx/frt/g'  $config_file        >>  $jobfile
4395       else
4396          sed 's/#$.*//g'   $config_file            >>  $jobfile
4397       fi
4398       echo  "%END%"                                >>  $jobfile
4399       echo  " "                                    >>  $jobfile
4400
4401
4402          # PROVIDE THE MRUN-SCRIPTS AS HERE-DOCUMENT
4403          # BACKSLASH IS USED FOR MASKING
4404       echo  "cat > $mrun_script_name <<\"%END%\""  >>  $jobfile
4405       if [[ $host = lckyuh ]]
4406       then
4407          sed 's/\/bin\/ksh/\/bin\/bash/g' ${PALM_BIN}/$mrun_script_name  >>  $jobfile
4408       else
4409          cat  ${PALM_BIN}/$mrun_script_name        >>  $jobfile
4410       fi
4411       echo  "%END%"                                >>  $jobfile
4412       echo  "chmod u+x $mrun_script_name"          >>  $jobfile
4413       echo  "execute_mrun=true"                    >>  $jobfile
4414       echo  " "                                    >>  $jobfile
4415
4416    fi
4417
4418
4419       # GET REQUIRED INPUT-FILES BY SCP OR BY SENDING THEM WITH THE JOB AS HERE-DOCUMENT
4420       # PUT THESE FILES INTO THE USER'S RESPECTIVE PERMANENT DIRECTORIES ON THE REMOTE-HOST
4421       # IF THE DIRECTORIES DO NOT EXIST, TRY TO CREATE THEM
4422    if [[ $do_remote = true ]]
4423    then
4424       (( i = 0 ))
4425       while (( i < iin ))
4426       do
4427          (( i = i + 1 ))
4428          echo  "[[ ! -d ${pathin[$i]} ]]  &&  mkdir -p  ${pathin[$i]}"  >>  $jobfile
4429          if [[ "${transin[$i]}" = job ]]
4430          then
4431             echo  "cat > ${remotepathin[$i]} <<\"%END%\""    >>  $jobfile
4432             eval cat   ${pathin[$i]}/${frelin[$i]}           >>  $jobfile
4433             echo  " "                                        >>  $jobfile
4434             echo  "%END%"                                    >>  $jobfile
4435          else
4436             echo  "batch_scp $PORTOPT -b -o -g -s -u $return_username $return_address ${remotepathin[$i]} \"${pathin[$i]}\" ${frelin[$i]}" >>  $jobfile
4437          fi
4438
4439             # CHECK, IF FILE COULD BE CREATED
4440          echo  "if [[ \$? = 1 ]]"                    >>  $jobfile
4441          echo  "then"                                >>  $jobfile
4442          echo  "   echo \" \" "                      >>  $jobfile
4443          echo  "   echo \"+++ file ${remotepathin[$i]} could not be created\" "   >>  $jobfile
4444          echo  "   echo \"    please check, if directory exists on $host!\" "  >>  $jobfile
4445          echo  "   echo \"+++ MRUN will not be continued\" "  >>  $jobfile
4446          echo  "   execute_mrun=false"               >>  $jobfile
4447          echo  "fi"                                  >>  $jobfile
4448       done
4449    fi
4450
4451       # PROVIDE NAME OF THE CURRENT WORKING-DIRECTORY ON THE LOCAL MACHINE (FROM WHERE THE JOB IS
4452       # STARTED) BY SETTING AN ENVIRONMENT-VARIABLE. THIS INFORMATION IS USED IN THE JOB BY MRUN
4453       # IN CASE THAT RESTART-RUNS HAVE TO BE GENERATED
4454    echo  "LOCAL_PWD=$working_directory"                >>  $jobfile
4455    echo  "export LOCAL_PWD"                            >>  $jobfile
4456
4457       # PROVIDE THE PATH OF THE LOCAL MRUN-SCRIPT FOR THE SAME REASON
4458    echo  "LOCAL_MRUN_PATH=$PALM_BIN"                   >>  $jobfile
4459    echo  "export LOCAL_MRUN_PATH"                      >>  $jobfile
4460
4461       # lcflow ALSO REQUIRES TO PROVIDE PATH FOR THE PALM-SCRIPTS
4462#    if [[ $host = lcflow  ||  $localhost = lcflow ]]
4463#    then
4464       echo  "export PALM_BIN=$PALM_BIN" | sed -e 's:'$HOME':$HOME:'   >>  $jobfile
4465       echo  "export PATH=\$PATH:\$PALM_BIN"              >>  $jobfile
4466#    fi
4467
4468       # CALL MRUN WITHIN THE JOB (SETTING QUEUE IS A WORKAROUND FOR ibmkisti)
4469       # AS FINAL ACTION, REMOVE THE TEMPORARY DIRECTORY CREATED AT THE BEGINNING OF THE JOB
4470    echo  "set -x"                                        >>  $jobfile
4471    echo  "queue=$queue"                                  >>  $jobfile
4472    echo  "[[ \$execute_mrun = true ]]  &&  ./$mrun_com"  >>  $jobfile
4473    echo  'ls -al; echo `pwd`'                            >>  $jobfile
4474    echo  "cd \$HOME"                                     >>  $jobfile
4475    echo  "rm -rf  $TEMPDIR"                              >>  $jobfile
4476
4477
4478
4479
4480       # START THE JOB USING SUBJOB-COMMAND
4481    if [[ $silent = false ]]
4482    then
4483       printf "\n     "
4484    else
4485       printf "\n\n"
4486    fi
4487
4488    subjob  $job_on_file  -h $host  -u $remote_username -g $group_number -q $queue  -m $memory  -N $node_usage -t $cpumax  $XOPT  $TOPT  $OOPT  -n $fname  -v  -c $job_catalog  -e $email_notification  $PORTOPT  $jobfile
4489    rm -rf  $jobfile
4490
4491
4492 fi  # END OF REMOTE-PART
Note: See TracBrowser for help on using the repository browser.