source: palm/trunk/SCRIPTS/mrun @ 1758

Last change on this file since 1758 was 1758, checked in by maronga, 8 years ago

last commit documented

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