source: palm/trunk/SCRIPTS/mrun @ 1304

Last change on this file since 1304 was 1304, checked in by raasch, 10 years ago

openmp bugfix + bugfix for single core MPI runs
ulimit option in mrun changed from -Ss to -s

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