source: palm/trunk/SCRIPTS/mrun @ 1866

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

scripts adjusted for lcocean

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