source: palm/trunk/SCRIPTS/mrun @ 2262

Last change on this file since 2262 was 2262, checked in by raasch, 7 years ago

bugfix for r2261

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