source: palm/trunk/SCRIPTS/mrun @ 1914

Last change on this file since 1914 was 1914, checked in by witha, 8 years ago

Merged branch/forwind into trunk

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