source: palm/trunk/SCRIPTS/mrun @ 2141

Last change on this file since 2141 was 2141, checked in by gronemeier, 7 years ago

changed check for existing files at beginning

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