source: palm/trunk/SCRIPTS/mrun @ 2147

Last change on this file since 2147 was 2147, checked in by scharf, 7 years ago

improved palmplot, added two imuk hosts, changed allocation of resources for lcbullhh and corrected land surface parameters

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