source: palm/trunk/SCRIPTS/palmrun @ 2566

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

palmrun adjusted for grid engine batch systems, informative messages reduced and reformatted

  • Property svn:executable set to *
  • Property svn:keywords set to Id
File size: 86.8 KB
Line 
1#!/bin/bash
2
3# palmrun - 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 2017  Leibniz Universitaet Hannover
20#--------------------------------------------------------------------------------#
21#
22# Current revisions:
23# ------------------
24#
25#
26# Former revisions:
27# -----------------
28# $Id: palmrun 2566 2017-10-20 08:50:47Z raasch $
29# execute command for combine_plot_fields added
30# "TEMPDIR" renamed "tempdir"
31# temporary working directory for local batch jobs is created immediately within
32# the user's palmrun call, due to a requirement of the "grid engine" batch
33# system, where the working directory is given with batch directive -wd and must
34# already exist when the job is submitted,
35# informative messages in non-trace mode reduced and partly reformatted
36#
37# 2551 2017-10-18 07:25:11Z raasch
38# TEMPDIR added as replacement string to be used in batch directives
39#
40# 2512 2017-10-04 08:26:59Z raasch
41# bugfix for determining cycle numbers of NetCDF input files
42#
43# 2506 2017-09-29 08:30:37Z raasch
44# option -V added to check for an existing SOURCES_FOR_RUN_... folder
45# host configuration added to SOURCES_FOR_RUN_... folder name
46# host_identifier renamed host_configuration
47# option -W added to allow for job dependencies
48#
49# 2501 2017-09-26 11:41:55Z raasch
50# default value for number of cores (option -X) set to 1
51# bugfix for mechanism which overwrites configuration file settings with values
52# provided by palmrun options
53#
54# 2499 2017-09-22 16:47:58Z kanani
55# option -h named configuration identifier
56#
57# 2480 2017-09-19 06:24:14Z maronga
58# bugfix for last revision
59#
60# 2479 2017-09-19 06:12:16Z raasch
61# option -A (project account number) added
62#
63# 2422 2017-09-08 08:25:41Z raasch
64# initial revision
65#
66#--------------------------------------------------------------------------------#
67# palmrun - script for running PALM jobs on local and remote hosts
68#--------------------------------------------------------------------------------#
69
70
71 
72    # DECLARATION OF VARIABLES AND THEIR DEFAULT VALUES
73
74 set +o allexport    # SUPPRESS EXPORT OF ALL VARIABLES, SINCE IN THE PAST THIS
75                     # LEAD TO PROBLEMS IN ROUTINES CALLED BY PALMRUN
76                     # (TOO MANY ARGUMENTS - PROBLEM)
77 set +o noclobber    # EXISTING FILES ARE ALLOWED TO BE OVERWRITTEN
78
79 typeset -i  ibd=0 ibdt=0 iec=0 iic=0 iin=0 ioc=0 iout=0
80 typeset -x -i  memory=0   # HAS TO BE EXPORTED HERE, OTHERWISE AN UNKNOWN SIDE
81                           # SIDE EFFECT MAY CAUSE DATA LOSS WHEN GETOPTS IS READING THE
82                           # SCRIPT-OPTION ARGUMENTS
83 typeset -i  cores cputime cpu_hours cpu_minutes cpu_seconds i ii iia iii iio
84 typeset -i  icycle inode ival maxcycle mpi_tasks
85 typeset -i  nodes remaining_cores run_number tasks_per_node threads_per_task
86
87 activation_string_list=""
88 AddFilenames=""
89 combine_plot_fields=true
90 compiler_name=""
91 compiler_name_ser=""
92 compiler_options=""
93 cores=1
94 cores_atmos=0
95 cores_ocean=0
96 coupled_dist=""
97 cpp_options=""
98 cpumax=0
99 create_batch_job=false
100 create_jobfile_only=false
101 create_remote_batch_job=false
102 dashes="  ----------------------------------------------------------------------------"
103 defaultqueue=""
104 delete_temporary_catalog=true
105 do_compile=true
106 do_trace=false
107 executable=""
108 execute_command=""
109 execution_error=false
110 fileconnection_file=.palm.iofiles
111 fname=test
112 global_revision=""
113 host_configuration="default"
114 hostfile=""
115 hp=""
116 keep_data_from_previous_run=false
117 link_local_input=false
118 link_local_output=false
119 linker_options=""
120 local_jobcatalog=""
121 locat=normal
122 makefile=""
123 max_par_io_str=""
124 prc=$0
125 while [[ $(echo $prc | grep -c "/") != 0 ]]
126 do
127    prc=`echo $prc | cut -f2- -d"/"`
128 done
129 module_calls=""
130 palmrun_memory=""
131 palmrun_script_name=$prc
132 openmp=false
133 previous_job=""
134 project_account=""
135 queue=none
136 restart_run=false
137 return_address=""
138 remote_jobcatalog=""
139 remote_username=""
140 running_in_batch_mode=false
141 run_coupled_model=false
142 run_id=""
143 silent=false
144 source_list=""
145 source_path=""
146 tasks_per_node=0
147 threads_per_task=1
148 transfer_problems=false
149 user_source_path=""
150 use_existing_sources_folder=""
151 use_openmp=false
152 version="palmrun  1.0 Rev$Rev: 2303 $"
153 working_directory=`pwd`
154 write_binary=""
155 TOPT=""
156
157
158    # ERROR HANDLING IN CASE OF EXIT
159 trap 'if [[ $locat != normal  &&  $locat != control_c ]]
160       then
161
162              # CARRY OUT ERROR-COMMANDS GIVEN IN THE CONFIGURATION FILE (EC:)
163          (( i = 0 ))
164          while (( i < iec ))
165          do
166             (( i = i + 1 ))
167             printf "\n  *** Execution of ERROR-command:\n"
168             printf "  >>> ${err_command[$i]}\n"
169             eval  ${err_command[$i]}
170          done
171          [[ $delete_temporary_catalog = true ]]  &&  (cd; rm -rf $tempdir)
172          printf "\n\n+++ palmrun killed \n\n"
173       elif [[ $locat != control_c ]]
174       then
175          printf "\n --> palmrun finished\n\n"
176       fi' exit
177
178
179    # ACTIONS IN CASE OF TERMINAL-BREAK (CONTROL-C):
180 trap 'cd; rm -rf $tempdir
181       printf "\n+++ palmrun killed by \"^C\" \n\n"
182       locat=control_c
183       exit
184      ' 2
185
186
187    # READ SHELLSCRIPT-OPTIONS AND REBUILD THE PALMRUN-COMMAND STRING (prc),
188    # WHICH WILL BE USED TO START RESTART-JOBS
189 while  getopts  :a:A:bBCd:FG:h:jkm:M:O:q:r:R:s:t:T:u:U:vVw:W:xX:yY:Z option
190 do
191   case  $option  in
192       (a)   activation_string_list=$OPTARG; prc="$prc -a'$OPTARG'";;
193       (A)   project_account=$OPTARG; prc="$prc -A'$OPTARG'";;
194       (b)   create_batch_job=true; prc="$prc -b";;
195       (B)   delete_temporary_catalog=false; prc="$prc -B";;
196       (C)   restart_run=true; prc="$prc -C";;
197       (d)   fname=$OPTARG; prc="$prc -d$OPTARG";;
198       (F)   create_jobfile_only=true;;
199       (G)   global_revision=$OPTARG; prc="$prc -G'$OPTARG'";;
200       (h)   host_configuration=$OPTARG; prc="$prc -h$OPTARG";;
201       (j)   running_in_batch_mode=true;;
202       (k)   keep_data_from_previous_run=true; prc="$prc -k";;
203       (m)   palmrun_memory=$OPTARG; prc="$prc -m$OPTARG";;
204       (M)   makefile=$OPTARG; prc="$prc -M$OPTARG";;
205       (O)   use_openmp=true; threads_per_task=$OPTARG; prc="$prc -O$OPTARG";;
206       (q)   queue=$OPTARG; prc="$prc -q$OPTARG";;
207       (r)   run_id=$OPTARG;;
208       (R)   return_address=$OPTARG;;
209       (s)   source_list=$OPTARG;;
210       (t)   palmrun_cpumax=$OPTARG; prc="$prc -t$OPTARG";;
211       (T)   palmrun_tasks_per_node=$OPTARG; prc="$prc -T$OPTARG";;
212       (u)   remote_username=$OPTARG; prc="$prc -u$OPTARG";;
213       (U)   return_username=$OPTARG; prc="$prc -U$OPTARG";;
214       (v)   silent=true; prc="$prc -v";;
215       (V)   use_existing_sources_folder="-V";;
216       (w)   max_par_io_str=$OPTARG; prc="$prc -w$OPTARG";;
217       (W)   previous_job=$OPTARG;;
218       (x)   do_trace=true;set -x; prc="$prc -x";;
219       (X)   palmrun_cores=$OPTARG; prc="$prc -X$OPTARG";;
220       (y)   ocean_file_appendix=true; prc="$prc -y";;
221       (Y)   run_coupled_model=true; coupled_dist=$OPTARG; prc="$prc -Y'$OPTARG'";;
222       (Z)   combine_plot_fields=false; prc="$prc -Z";;
223       (\?)  printf "\n  +++ unknown option $OPTARG \n"
224             printf "\n  --> type \"$0 ?\" for available options \n"
225             locat=parameter;exit;;
226   esac
227 done
228
229
230    # SKIP GIVEN OPTIONS TO READ POSITIONAL PARAMETER, IF GIVEN
231    # CURRENTLY ONLY PARAMETER ? (TO OUTPUT A SHORT COMMAND INFO) IS ALLOWED
232 (( to_shift = $OPTIND - 1 ))
233 shift $to_shift
234
235    # PRINT SHORT DESCRIPTION OF PALMRUN OPTIONS
236 if [[ "$1" = "?" ]]
237 then
238   (printf "\n  *** Description of available palmrun options:\n"
239    printf "\n      Option  Description                              Default-Value"
240    printf "\n        -a    activation string list                   \"\" "
241    printf "\n        -A    project account number                   ---"
242    printf "\n        -b    batch-job on local machine               ---"
243    printf "\n        -B    do not delete temporary directory at end ---"
244    printf "\n        -d    base name of files attached to program   test"
245    printf "\n        -F    create batch job file only               ---"
246    printf "\n        -h    host configuration                       \"default\" "
247    printf "\n        -k    keep data from previous run"
248    printf "\n        -m    memory demand in MB (batch-jobs)         0 MB"
249    printf "\n        -M    Makefile name                            Makefile"
250    printf "\n        -O    threads per openMP task                  ---"
251    printf "\n        -q    queue                                    \"$queue\" "
252    printf "\n        -s    filenames of routines to be compiled     \"\" "
253    printf "\n              must end with .f, .f90, .F, or .c !"
254    printf "\n              use \"..\" for more than one file and wildcards"
255    printf "\n              -s LM compiles all locally modified files"
256    printf "\n        -t    allowed cpu-time in seconds (batch)      0"
257    printf "\n        -T    tasks per node                           ---"
258    printf "\n        -u    username on remote machine               \"\" "
259    printf "\n        -v    no prompt for confirmation               ---"
260    printf "\n        -V    check if SOURCES_FOR_RUN_... exists      ---"
261    printf "\n        -w    maximum parallel io streams              as given by -X"
262    printf "\n        -W    name of job to wait for                  ---"
263    printf "\n        -x    tracing of palmrun for debug purposes    ---"
264    printf "\n        -X    # of processors (on parallel machines)   1"
265    printf "\n        -y    add appendix \"_O\" to all local output"
266    printf "\n              files (ocean precursor runs followed by"
267    printf "\n              coupled atmosphere-ocean runs)           ---"
268    printf "\n        -Y    run coupled model, \"#1 #2\" with" 
269    printf "\n              #1 atmosphere and #2 ocean processors    \"#/2 #/2\" depending on -X"
270    printf "\n        -Z    skip combine_plot_fields at the end of      "
271    printf "\n              the simulation                           ---"
272    printf "\n "
273    printf "\n      Possible values of positional parameter <modus>:"
274    printf "\n        \"?\"       -  this outline \n\n") | more
275    exit
276 elif [[ "$1" != "" ]]
277 then
278    printf "\n  +++ positional parameter $1 unknown \n"
279    locat=parameter; exit
280 fi
281
282
283
284    # SHORT STARTING MESSAGE
285 printf "\n*** $version "
286 printf "\n    will be executed.     Please wait ..."
287
288
289    # BUILD THE CONFIGURATION-FILE NAME AND THE SOURCES_FOR_RUN-FOLDER NAME
290 config_file=.palm.config.$host_configuration
291 sources_for_run_catalog=SOURCES_FOR_RUN_${host_configuration}_$fname
292
293
294    # CHECK, IF CONFIGURATION FILE EXISTS
295 if [[ ! -f $config_file ]]
296 then
297    printf "\n\n  +++ configuration file: "
298    printf "\n           $config_file"
299    printf "\n      does not exist"
300    locat=connect; exit 
301 fi
302
303
304    # CHECK, IF FILE CONNECTION FILE EXISTS
305 if [[ ! -f $fileconnection_file ]]
306 then
307    printf "\n\n  +++ file connection file: "
308    printf "\n           $fileconnection_file"
309    printf "\n      does not exist"
310    locat=connect; exit 
311 fi
312
313
314    # CHECK, IF THE ACTIVATION_STRING_LIST HAS BEEN GIVEN
315 if [[ "$activation_string_list" = "" ]]
316 then
317    printf "\n\n  +++ no activation string list given: "
318    printf "\n        please set palmrun option \"-a\" "
319    locat=palmrun_option; exit 
320 fi
321
322
323    # SET VARIABLE TO ACTIVATE PALM BINARY OUTPUT FOR RESTARTS
324 if [[ $(echo $activation_string_list | grep -c "restart") != 0 ]]
325 then
326    write_binary=true
327 else
328    write_binary=false
329 fi
330
331
332    # READ AND EVALUATE THE CONFIGURATION-FILE
333 [[ $silent = false ]]  &&  printf "\n\n    Reading the configuration file... "
334
335    # READ VARIABLE SETTINGS FROM CONFIG FILE LINE BY LINE
336 while  read line
337 do
338
339       # FIRST REPLACE ENVIRONMENT-VARIABLES BY THEIR RESPECTIVE VALUES
340    eval  line=\"$line\"
341
342
343       # INTERPRET THE LINE
344    if [[ "$(echo $line)" = "" ]]
345    then
346
347          # EMPTY LINE, NO ACTION
348       continue
349
350    elif [[ "$(echo $line | cut -c1)"  =  "#" ]]
351    then
352
353          # LINE IS A COMMENT LINE
354       continue
355
356    elif [[ "$(echo $line | cut -c1)"  =  "%" ]]
357    then
358
359          # LINE DEFINES AN ENVIRONMENT-VARIABLE
360       var=`echo $line | cut -d" " -s -f1 | cut -c2-`
361       value=`echo $line | cut -d" " -s -f2-`
362
363
364          # VALUE FROM THE CONFIGURATION-FILE IS ASSIGNED TO THE
365          # ENVIRONMENT-VARIABLE, BUT ONLY IF NO VALUE HAS BEEN ALREADY
366          # ASSIGNED WITHIN THIS SCRIPT (E.G. BY SCRIPT-OPTIONS).
367          # NON-ASSIGNED VARIABLES HAVE VALUE "" OR 0 (IN CASE OF INTEGER).
368          # HENCE THE GENERAL RULE IS: SCRIPT-OPTION OVERWRITES THE
369          # CONFIGURATION-FILE.
370       if [[ "$(eval echo \$$var)" = ""  ||  "$(eval echo \$$var)" = "0" ]]
371       then
372          eval  export  $var="\$value"
373
374             # TERMINAL OUTPUT OF ENVIRONMENT-VARIABLES, IF TRACEBACK IS SWITCHED on
375          if [[ $do_trace = true ]]
376          then
377             printf "\n*** ENVIRONMENT-VARIABLE $var = $value"
378          fi
379       fi
380
381    elif [[ "$(echo $line | cut -c1-3)" = "BD:" ]]
382    then
383
384          # LINE DEFINES BATCH-DIRECTIVE
385       (( ibd = ibd + 1 ))
386       line=$(echo $line | cut -c4-)
387       batch_directive[$ibd]="$line"
388
389    elif [[ "$(echo $line | cut -c1-4)" = "BDT:" ]]
390    then
391
392          # LINE DEFINES BATCH-DIRECTIVE FOR SENDING BACK THE JOBFILE FROM A
393          # REMOTE TO A LOCAL HOST
394       (( ibdt = ibdt + 1 ))
395       line=$(echo $line | cut -c5-)
396       batch_directive_transfer[$ibdt]="$line"
397
398    elif [[ "$(echo $line | cut -c1-3)" = "EC:" ]]
399    then
400
401          # LINE DEFINES ERROR-COMMAND
402       (( iec = iec + 1 ))
403       line=$(echo $line | cut -c4-)
404       err_command[$iec]="$line"
405
406    elif [[ "$(echo $line | cut -c1-3)" = "IC:" ]]
407    then
408
409          # LINE DEFINES INPUT-COMMAND
410       (( iic = iic + 1 ))
411       line=$(echo $line | cut -c4-)
412       in_command[$iic]="$line"
413
414    elif [[ "$(echo $line | cut -c1-3)" = "OC:" ]]
415    then
416
417          # LINE DEFINES OUTPUT-COMMAND
418       (( ioc = ioc + 1 ))
419       line=$(echo $line | cut -c4-)
420       out_command[$ioc]="$line"
421
422    else
423
424          # SKIP ALL OTHER LINES
425       continue
426
427    fi
428
429 done < $config_file
430
431
432    # CHECK SETTING OF REQUIRED PARAMETERS
433 if [[ "$compiler_name" = "" ]]
434 then
435    printf "\n  +++ no compiler name found in $config_file"
436    printf "\n      Please add line \"compiler_name ...\" to that file."
437    locat=config_file; exit
438 fi
439 if [[ "$compiler_name_ser" = "" ]]
440 then
441    printf "\n  +++ no compiler name for non-paralle compilation found in $config_file"
442    printf "\n      Please add line \"compiler_name_ser ...\" to that file."
443    locat=config_file; exit
444 fi
445 if [[ "$compiler_options" = "" ]]
446 then
447    printf "\n  +++ no compiler options found in $config_file"
448    printf "\n      Please add line \"compiler_options ...\" to that file."
449    locat=config_file; exit
450 fi
451 if [[ "$linker_options" = "" ]]
452 then
453    printf "\n  +++ no linker options found in $config_file"
454    printf "\n      Please add line \"linker_options ...\" to that file."
455    locat=config_file; exit
456 fi
457 if [[ "$execute_command" = "" ]]
458 then
459    printf "\n  +++ no execute command found in $config_file"
460    printf "\n      Please add line \"execute_command ...\" to that file."
461    locat=config_file; exit
462 fi
463
464 if [[ "$hostfile" != "" ]]
465 then
466    if [[ $hostfile != auto  &&  ! -f $hostfile ]]
467    then
468       printf "\n  +++ no hostfile \"$hostfile\" found"
469       printf "\n      Please check line \"hostfile ...\" in $config_file"
470       locat=config_file; exit   
471    fi
472 fi
473
474
475    # DETERMINE THE CALL STATUS
476 if [[ "$return_address" != "" ]]
477 then
478 
479       # I AM RUNNING ON A REMOTE HOST, WHICH ALSO MEANS THAT I AM RUNNING IN
480       # BATCH MODE AND ...
481    running_on_remote=true
482 
483 else
484
485       # I HAVE BEEN CALLED INTERACTIVELY ON THIS HOST
486     if [[ "$remote_ip" != "" ]]
487     then
488
489           # I HAVE TO CREATE A BATCH JOB TO RUN PALM ON THE REMOTE HOST
490        create_remote_batch_job=true
491
492     fi
493     running_on_remote=false
494 fi
495
496
497
498    # READ AND EVALUATE THE I/O-FILE LIST
499 [[ $silent = false ]]  &&  printf "\n    Reading the I/O files... "
500
501    # READ THE FILE CONNECTION FILE LINE BY LINE
502 while  read line
503 do
504
505       # FIRST REPLACE ENVIRONMENT-VARIABLES BY THEIR RESPECTIVE VALUES
506    eval  line=\"$line\"
507
508
509       # INTERPRET THE LINE
510    if [[ "$(echo $line)" = "" ]]
511    then
512          # EMPTY LINE, NO ACTION
513       continue
514
515    elif [[ "$(echo $line | cut -c1)"  =  "#" ]]
516    then
517
518          # LINE IS A COMMENT LINE
519       true
520
521    else
522
523          # LINE DEFINES FILE CONNECTION. READ THE FILE ATTRIBUTES.
524          # s2a: in/out - field
525          # s2b: loc    - field (optional)
526          # s2c: tr/ar  - field (optional)
527       s1=`echo $line | cut -d" " -f1`
528       s2=`echo $line | cut -d" " -s -f2`
529       s2a=$(echo $s2 | cut -d":" -f1)
530       if [[ $(echo $s2 | grep -c ":") = 0 ]]
531       then
532          s2b=""
533          s2c=""
534       else
535          s2b=`echo $s2 | cut -d":" -f2 | sed 's/:/ /g'`
536          s2c=`echo $s2 | cut -d":" -s -f3 | sed 's/:/ /g'`
537       fi
538       s3=`echo $line | cut -d" " -f3`
539       s4=`echo $line | cut -d" " -s -f4`
540       s5=`echo $line | cut -d" " -s -f5`
541       s6=`echo $line | cut -d" " -s -f6`
542
543       
544          # STORE FILE CONNECTION, IF ACTIVATED BY ACTIVATION-STRING FROM
545          # INPUT- OR OUTPUT-LIST.
546          # VARIABLE S3 MAY CONTAIN A LIST OF ACTIVATION STRINGS (FIELD-SEPERATOR ":").
547          # IF EXECUTION IS SCHEDULED FOR A REMOTE-MACHINE AND THE FILE IS ONLY
548          # LOCALLY REQUIRED ON THAT MACHINE (I.E. s2b = loc), THE FILE CONNECTION
549          # IS NOT CHECKED AND STORED.
550       IFSALT="$IFS"; IFS="$IFS:"
551       if [[ "$s2a" = in  &&  ! ( $create_remote_batch_job = true  &&  ( "$s2b" = loc  ||  "$s2b" = locopt ) ) ]]
552       then
553          found=false
554          for  actual  in  $activation_string_list
555          do
556             for  formal  in  $s3
557             do
558                [[ $actual = $formal  ||  "$formal" = "-" ]]  &&  found=true
559             done
560          done
561          if [[ $found = true ]]
562          then
563             (( iin = iin + 1 ))
564             localin[$iin]=$s1; transin[$iin]=$s2b; actionin[$iin]=$s2c;
565             typein[$iin]=$s3; pathin[$iin]=$s4; endin[$iin]=$s5;
566             extin[$iin]=$s6
567          fi
568       elif [[ "$s2a" = out  &&  ! ( $create_remote_batch_job = true  &&  "$s2b" = loc ) ]]
569       then
570          found=false
571          for  actual  in  $activation_string_list
572          do
573             for  formal  in  $s3 
574             do
575                [[ $actual = $formal  ||  "$formal" = "-"  ]]  &&  found=true
576             done
577          done
578          if [[ $found = true ]]
579          then
580             (( iout = iout + 1 ))
581             localout[$iout]=$s1; actionout[$iout]=$s2c; typeout[$iout]=$s3;
582             pathout[$iout]=$s4; endout[$iout]=$s5; extout[$iout]=$s6
583          fi
584       elif [[ "$s2a" != in  &&  "$s2a" != out ]]
585       then
586          printf "\n  +++ I/O-attribute in configuration file $config_file has the invalid"
587          printf "\n      value \"$s2\". Only \"in\" and \"out\" are allowed!"
588          locat=connect; exit
589       fi
590       IFS="$IFSALT"
591    fi
592
593 done < $fileconnection_file
594
595
596
597    # VALUES OF PALMRUN-OPTIONS OVERWRITE THOSE FROM THE CONFIGURATION-FILE
598 [[ $palmrun_memory     != ""   ]]  &&  memory=$palmrun_memory
599 [[ $palmrun_cpumax     != ""   ]]  &&  cpumax=$palmrun_cpumax
600 [[ "$palmrun_cores" != ""  ]]  &&  cores=$palmrun_cores
601 [[ "$max_par_io_str" != "" ]]  &&  maximum_parallel_io_streams=$max_par_io_str
602 [[ "$palmrun_tasks_per_node" != "" ]]  &&  tasks_per_node=$palmrun_tasks_per_node
603
604
605
606      # EVALUATE MODEL COUPLING FEATURES (OPTION -Y)
607 if [[ $run_coupled_model = true ]] 
608 then
609
610    cores_atmos=`echo $coupled_dist | cut -d" " -s -f1`
611    cores_ocean=`echo $coupled_dist | cut -d" " -s -f2`
612
613    if (( $cores_ocean + $cores_atmos != $cores ))
614    then
615
616       printf "\n  +++ number of processors does not fit to specification by \"-Y\"."
617       printf "\n      PEs (total)     : $cores"
618       printf "\n      PEs (atmosphere): $cores_atmos"
619       printf "\n      PEs (ocean)     : $cores_ocean"
620       locat=coupling; exit
621
622    fi
623
624 fi
625
626
627    # IF I AM IN BATCH MODE, CHECK IF EXECUTABLE AND OTHER REQUIRED FILES
628    # HAVE BEEN GENERATED BY PALMBUILD AND STORED IN THE SOURCES_FOR_RUN_...
629    # FOLDER
630 if [[ $running_in_batch_mode = true ]]
631 then
632 
633    if [[ ! -d ${fast_io_catalog}/${sources_for_run_catalog} ]]
634    then
635       printf "\n  +++ directory ${fast_io_catalog}/${sources_for_run_catalog} is missing"
636       printf "\n      Please check the output of the palmrun-call"
637       printf "\n      that you did on your local host."
638       locat=SOURCES_FOR_RUN; exit
639    fi
640
641 else
642
643       # CREATE THE SOURCES_FOR_RUN_... FOLDER, BUT NOT IF I AM PART OF AN
644       # AUTOMATIC RESTART RUN
645       # AUTOMATIC RESTART RUNS JUST ACCESS THE DIRECTORY CREATED BY THE INITIAL RUN
646    if [[ $restart_run = false ]]
647    then
648
649          # COLLECT FILES TO BE COMPILED IN THE SOURCES_FOR_RUN_... FOLDER ON
650          # THE LOCAL HOST
651       if [[ ! -d $source_path ]]
652       then
653          printf "\n\n  +++ source path \"$source_path\" on local host"
654          printf "\n      \"$(hostname)\" does not exist"
655          locat=source_path; exit
656       fi
657
658       rm -rf   $sources_for_run_catalog
659       mkdir -p $sources_for_run_catalog
660
661       if [[ "$source_list" = LM ]]
662       then
663
664             # DETERMINE MODIFIED FILES OF THE SVN WORKING COPY
665          source_list=""
666          cd  $source_path
667
668
669             # CHECK, IF TRUNK-DIRECTORY IS UNDER SVN CONTROL
670          if [[ ! -d ../.svn ]]
671          then
672             printf "\n\n  +++ source directory"
673             printf "\n         \"$source_path\" "
674             printf "\n         is not under control of \"subversion\"."
675             printf "\n         Please do not use palmrun-option \"-s LM\"\n"
676          fi
677
678
679             # LIST ALL MODIFIED SOURCE CODE FILES
680          Filenames=""
681          svn status  >  tmp_svnstatus
682          while  read line
683          do
684             firstc=`echo $line | cut -c1`
685             if [[ $firstc = M  ||  $firstc = "?" ]]
686             then
687                Name=`echo "$line" | cut -c8-`
688                extension=`echo $Name | cut -d. -f2`
689                if [[ "$extension" = f90 || "$extension" = F90 || "$extension" = f || "$extension" = F || "$extension" = c ]]
690                then
691                   Filenames="$Filenames "$Name
692                fi
693             fi
694          done < tmp_svnstatus
695          rm -rf  tmp_svnstatus
696
697
698             # COPY FILES TO SOURCES_FOR_RUN_...
699          for  filename  in  $Filenames
700          do
701             cp  $filename  ${working_directory}/${sources_for_run_catalog}
702             source_list=$source_list"$filename "
703          done
704
705          cd -  > /dev/null
706
707
708          # COPY FILES GIVEN BY OPTION -s TO DIRECTORY SOURCES_FOR_RUN_...
709       elif [[ "$source_list" != "" ]]
710       then
711
712          cd  $source_path
713
714          for  filename  in  $source_list
715          do
716
717                # SOURCE CODE FILE IS NOT ALLOWED TO INCLUDE PATH
718             if [[ $(echo $filename | grep -c "/") != 0 ]]
719             then
720                printf "\n  +++ source code file:  $filename"
721                printf "\n      must not contain (\"/\") "
722                locat=source; exit
723             fi
724
725             if [[ ! -f $filename ]]
726             then
727                printf "\n  +++ source code file:  $filename"
728                printf "\n      does not exist"
729                locat=source; exit
730             else
731                cp  $filename  ${working_directory}/${sources_for_run_catalog}
732             fi
733
734          done
735
736          cd -  > /dev/null
737
738       fi
739
740          # CHECK, IF MAKEFILE EXISTS AND COPY IT TO THE SOURCES_FOR_RUN... DIRECTORY
741       [[ "$makefile" = "" ]]  &&  makefile=$source_path/Makefile
742       if [[ ! -f $makefile ]]
743       then
744          printf "\n  +++ file \"$makefile\" does not exist"
745          locat=make; exit
746       else
747          cp  $makefile  ${sources_for_run_catalog}/Makefile
748       fi
749
750
751          # COPY FILES FROM OPTIONAL SOURCE PATH GIVEN IN THE CONFIGURATION FILE
752       if [[ "$user_source_path" != "" ]]
753       then
754
755             # DOES THE DIRECTORY EXIST?
756          if [[ ! -d $user_source_path ]]
757          then
758
759             printf "\n\n  *** INFORMATIVE: additional source code directory"
760             printf "\n      \"$user_source_path\" "
761             printf "\n      does not exist or is not a directory."
762             printf "\n      No source code will be used from this directory!\n"
763             user_source_path=""
764             if [[ $silent == false ]]
765             then
766                sleep 2
767             fi
768
769          else
770
771             cd $user_source_path
772             found=false
773
774             Names=$(ls -1 *.f90 2>&1)
775             [[ $(echo $Names | grep -c '*.f90') = 0 ]]  &&  AddFilenames="$Names"
776             Names=$(ls -1 *.F90 2>&1)
777             [[ $(echo $Names | grep -c '*.F90') = 0 ]]  &&  AddFilenames="$AddFilenames $Names"
778             Names=$(ls -1 *.F 2>&1)
779             [[ $(echo $Names | grep -c '*.F') = 0   ]]  &&  AddFilenames="$AddFilenames $Names"
780             Names=$(ls -1 *.f 2>&1)
781             [[ $(echo $Names | grep -c '*.f') = 0   ]]  &&  AddFilenames="$AddFilenames $Names"
782             Names=$(ls -1 *.c 2>&1)
783             [[ $(echo $Names | grep -c '*.c') = 0   ]]  &&  AddFilenames="$AddFilenames $Names"
784
785             cd -  > /dev/null
786             cd  $sources_for_run_catalog
787
788                # COPY MAKEFILE IF EXISTING
789             if [[ -f $user_source_path/Makefile ]]
790             then
791                printf "\n\n  *** user Makefile from directory"
792                printf "\n      \"$user_source_path\" is used \n"
793                if [[ $silent == false ]]
794                then
795                   sleep 1
796                fi
797                cp  $user_source_path/Makefile  .
798             fi
799
800             for  filename  in  $AddFilenames
801             do
802                if [[ -f $filename ]]
803                then
804                   printf "\n  +++ source code file \"$filename\" found in additional"
805                   printf "\n      source code directory \"$user_source_path\" "
806                   printf "\n      but was also given with option \"-s\" which means that it should be taken"
807                   printf "\n      from directory \"$source_path\"."
808                   locat=source; exit
809                fi
810
811                cp  $user_source_path/$filename  .
812                source_list="$source_list $filename"
813
814                   # CHECK IF FILE IS CONTAINED IN MAKEFILE
815                if [[ $(grep -c $filename Makefile) = 0 ]]
816                then
817                   printf "\n\n  +++ user file \"$filename\" "
818                   printf "\n      is not listed in Makefile \n"
819                   locat=source; exit
820                else
821
822                   if [[ $found = false ]]
823                   then
824                      found=true
825                      printf "\n\n  *** following user file(s) added to the"
826                      printf " files to be translated:\n      "
827                   fi
828                   printf "$filename  "
829                   if [[ $silent == false ]]
830                   then
831                      sleep 0.5
832                   fi
833
834                fi
835             done
836             [[ $found = true ]]  &&  printf "\n"
837             cd -  > /dev/null
838          fi
839       fi
840
841          # COPY CONFIGURATION FILES
842       cp  $config_file  $sources_for_run_catalog
843       cp  $fileconnection_file  $sources_for_run_catalog
844
845          # COPY SHELLSCRIPTS
846       cp  ${source_path}/../SCRIPTS/palmrun    $sources_for_run_catalog
847       cp  ${source_path}/../SCRIPTS/batch_scp  $sources_for_run_catalog
848
849    fi
850
851 fi
852
853    # GET THE GLOBAL REVISION-NUMBER OF THE SVN-REPOSITORY
854    # (HANDED OVER TO RESTART-RUNS USING OPTION -G)
855 if [[ "$global_revision" = "" ]]
856 then
857    global_revision=`svnversion $source_path  2>/dev/null`
858    global_revision="Rev: $global_revision"
859 fi
860
861
862    # IN CASE OF PARALLEL EXECUTION, CHECK SOME SPECIFICATIONS CONCERNING PROCESSOR NUMBERS
863 if [[ -n $cores ]]
864 then
865
866       # CHECK, IF THE NUMBER OF CORES PER NODE HAS BEEN GIVEN UND IF IT IS AN
867       # INTEGRAL DIVISOR OF THE TOTAL NUMBER OF CORES GIVEN BY OPTION -X
868    if [[ $tasks_per_node = 0 ]]
869    then
870       printf "\n"
871       printf "\n  +++ option \"-T\" (tasks per node) is missing"
872       printf "\n      set -T option or define tasks_per_node in the config file"
873       locat=tasks_per_node; (( iec = 0 )); exit
874    fi
875
876    if (( cores < tasks_per_node ))
877    then
878       printf "\n"
879       printf "\n  +++ tasks per node (-T) cannot exceed total number of cores (-X)"
880       printf "\n      given values: -T $tasks_per_node  -X $cores"
881       locat=tasks_per_node; (( iec = 0 )); exit
882    fi
883
884    (( nodes = cores / ( tasks_per_node * threads_per_task ) ))
885    (( mpi_tasks = cores / threads_per_task ))
886    [[ $mpi_tasks = 0 ]]  &&  (( mpi_tasks = 1 ))
887    (( ii = cores / tasks_per_node ))
888    (( remaining_cores =  cores - ii * tasks_per_node ))
889    if (( remaining_cores > 0 ))
890    then
891       printf "\n"
892       printf "\n  +++ WARNING: tasks per node (option \"-T\") is not an integral"
893       printf "\n      divisor of the total number of cores (option \"-X\")"
894       printf "\n      values of this palmrun-call: \"-T $tasks_per_node\" \"-X $cores\""
895       printf "\n      One of the nodes is filled with $remaining_cores instead of $tasks_per_node tasks"
896       (( nodes = nodes + 1 ))
897    fi
898
899       # SET THE TOTAL NUMBER OF NODES, REQUIRED FOR THE SUBJOB-COMMAND (SEE FURTHER BELOW)
900    if [[ "$tasks_per_node" != "" ]]
901    then
902       TOPT="-T $tasks_per_node"
903    fi
904
905 fi
906
907
908    # SET DEFAULT VALUE FOR THE MAXIMUM NUMBER OF PARALLEL IO STREAMS
909 if [[ "$maximum_parallel_io_streams" = "" ]]
910 then
911    maximum_parallel_io_streams=$cores
912 fi
913
914
915    # SET PORT NUMBER OPTION FOR CALLS OF SSH/SCP AND batch_scp SCRIPT
916 if [[ "$scp_port" != "" ]]
917 then
918    PORTOPT="-P $scp_port"
919    SSH_PORTOPT="-p $scp_port"
920 fi
921
922
923    # DETERMINE THE SSH-OPTION IN CASE THAT AN SSH-KEY IS EXPLICITLY GIVEN IN THE
924    # CONFIG-FILE
925 if [[ "$ssh_key" != "" ]]
926 then
927    ssh_key="-i $HOME/.ssh/$ssh_key"
928 fi
929
930
931    # SET QUEUE, IF NOT GIVEN
932 if [[ $create_batch_job = true  ||  $create_remote_batch_job = true ]]
933 then
934
935    if [[ $queue = none  &&  "$defaultqueue" = "" ]]
936    then
937       printf "\n"
938       printf "\n  +++ no default queue given in configuration file and no queue"
939       printf "\n      given with option -q"
940    fi
941    if [[ $queue = none ]]
942    then
943       queue=$defaultqueue
944    fi
945
946 fi
947
948
949    # GENERATE FULL FILENAMES OF INPUT-FILES, INCLUDING THEIR PATH
950    # CHECK, IF INPUT-FILES EXIST, AND DETERMINE HIGHEST CYCLE NUMBER (IF CYCLES EXIST)
951 (( i = 0 ))
952 while (( i < iin ))
953 do
954    (( i = i + 1 ))
955    (( maxcycle = 0 ))
956
957       # GENERATE PATH AND FULL FILE NAME (then-BRANCH: FIXED FULL NAME IS GIVEN, I.E. THE
958       # FILE IDENTIFIER IS NOT PART OF THE FILENAME))
959    if [[ "${actionin[$i]}" = di ]]
960    then
961       remotepathin[$i]=${pathin[$i]}/${endin[$i]}  # EVALUATE REMOTE-PATH ON THE REMOTE
962                                                    # HOST ONLY
963       eval filename=${pathin[$i]}/${endin[$i]}
964    else
965       remotepathin[$i]=${pathin[$i]}/${fname}${endin[$i]}  # EVALUATE REMOTE-PATH ON THE REMOTE
966                                                             # HOST ONLY
967       eval filename=${pathin[$i]}/${fname}${endin[$i]}
968    fi
969    eval pathname=${pathin[$i]}
970
971       # CHECK IF FILE EXISTS
972    if ! ls $filename* 1>/dev/null 2>&1
973    then
974
975          # FILES WITH ATTRIBUTE locopt ARE OPTIONAL. NO ABORT, IF THEY DO NOT EXIST.
976       if [[ "${transin[$i]}" != "locopt" ]]
977       then
978          printf "\n\n  +++ INPUT-file: "
979          if [[ "${extin[$i]}" = ""  ||  "${extin[$i]}" = " " ]]
980          then
981             printf "\n           $filename"
982          else
983             printf "\n           $filename.${extin[$i]}"
984          fi
985          printf "\n      does not exist\n"
986          locat=input; exit
987       else
988          transin[$i]="unavailable"
989       fi
990    else
991
992          # DETERMINE THE FILE'S CYCLE NUMBER
993       ls -1 -d $filename    >   filelist  2>/dev/null
994       ls -1 -d $filename.*  >>  filelist  2>/dev/null
995       while  read line
996       do
997              # filename without path (i.e. after the last "/")
998           basefilename=$(basename ${line})
999
1000              # check if there is an extension
1001           extension=${basefilename##*.}
1002           if [[ "$extension" = "${extin[$i]}" ]]
1003           then
1004              basefilename=${basefilename%.*}
1005           fi
1006
1007              # check for an existing cycle number
1008           cycle=${basefilename##*.}
1009           if [[ $cycle =~ ^-?[0-9]+$ ]]
1010           then
1011              (( icycle = $cycle ))
1012           else
1013              (( icycle = 0 ))
1014           fi
1015
1016           if (( icycle > maxcycle ))
1017           then
1018              (( maxcycle = icycle ))
1019           fi
1020
1021       done <filelist
1022       rm filelist
1023
1024          # APPEND CYCLE NUMBER TO FILENAME
1025       if (( maxcycle > 0 ))
1026       then
1027          if [[ "${extin[$i]}" != " "  &&   "${extin[$i]}" != "" ]]
1028          then
1029             filename=${filename}.$maxcycle.${extin[$i]}
1030          else
1031             filename=${filename}.$maxcycle
1032          fi
1033       else
1034          if [[ "${extin[$i]}" != " "  &&   "${extin[$i]}" != "" ]]
1035          then
1036             filename=${filename}.${extin[$i]}
1037          fi
1038       fi
1039       
1040          # STORE FILENAME WITHOUT PATH BUT WITH CYCLE NUMBER,
1041          # IS LATER USED FOR TRANSFERRING FILES WIHIN THE JOB (SEE END OF FILE)
1042       absnamein[$i]=$filename
1043       if (( maxcycle > 0 ))
1044       then
1045          if [[ "${actionin[$i]}" = di ]]
1046          then
1047             frelin[$i]=${endin[$i]}.$maxcycle
1048          else
1049             frelin[$i]=${fname}${endin[$i]}.$maxcycle
1050          fi
1051       else
1052          if [[ "${actionin[$i]}" = di ]]
1053          then
1054             frelin[$i]=${endin[$i]}
1055          else
1056             frelin[$i]=${fname}${endin[$i]}
1057          fi
1058       fi
1059
1060    fi
1061 done
1062
1063   
1064    # GENERATE FULL FILENAMES OF OUTPUT-FILES (WITHOUT $ OR ~),
1065    # CHECK, IF OUTPUT-FILES EXIST, AND DETERMINE HIGHEST CYCLE NUMBER (IF CYCLES EXIST),
1066    # OR, IN CASE THAT FILE DOES NOT EXIST, CHECK, IF IT CAN BE CREATED 
1067    # THESE ACTIONS ARE NOT CARRIED OUT, IF FILES SHALL BE TRASFERRED FROM THE REMOTE TO
1068    # THE LOCAL HOST (BECAUSE THEIR IS NO DIRECT ACCESS TO THE LOCAL DIRECTORIES FROM THE
1069    # REMOTE HOST)
1070 (( i = 0 ))
1071 while (( i < iout ))
1072 do
1073    (( i = i + 1 ))
1074    if [[ ! ( $running_on_remote = true  &&  ( "${actionout[$i]}" = tr || "${actionout[$i]}" = tra || "${actionout[$i]}" = trpe ) ) ]]
1075    then
1076       if [[ "${actionout[$i]}" = tr ]]
1077       then
1078          actionout[$i]=""
1079       elif [[ "${actionout[$i]}" = trpe ]]
1080       then
1081          actionout[$i]=pe
1082       elif [[ "${actionout[$i]}" = tra ]]
1083       then
1084          actionout[$i]=a
1085       fi
1086       (( maxcycle = 0 ))
1087       eval filename=${pathout[$i]}/${fname}${endout[$i]}
1088       eval catalogname=${pathout[$i]}
1089       if ! ls $filename* 1>/dev/null 2>&1
1090       then
1091     
1092             # IF OUTPUT-FILE DOES NOT EXIST CHECK, IF IT CAN BE CREATED
1093          if  cat /dev/null > $filename 
1094          then
1095             rm  $filename
1096          else
1097
1098                # CHECK, IF THE DIRECTORY WHERE FILE SHALL BE COPIED TO EXISTS
1099                # IF IT DOES NOT EXIST, TRY TO CREATE IT
1100             if [[ ! -d $catalogname ]]
1101             then
1102                if  mkdir -p  $catalogname
1103                then
1104                   printf "\n\n  *** directory:"
1105                   printf "\n           $catalogname"
1106                   printf "\n      was created\n"
1107                else
1108                   printf "\n\n  +++ OUTPUT-file:"
1109                   printf "\n           $filename"
1110                   printf "\n      cannot be created, because directory does not exist"
1111                   printf "\n      and cannot be created either"
1112                   printf "\n"
1113                   locat=output  ; exit
1114                fi 2>/dev/null
1115             else
1116                printf "\n\n  +++ OUTPUT-file:"
1117                printf "\n           $filename"
1118                printf "\n      cannot be created, although directory exists"
1119                printf "\n"
1120                locat=output  ; exit
1121             fi
1122          fi 2>/dev/null
1123       else
1124
1125             # DETERMINE THE CYCLE NUMBER
1126          ls -1 -d $filename    >   filelist  2>/dev/null
1127          ls -1 -d $filename.*  >>  filelist  2>/dev/null
1128          while  read line
1129          do
1130
1131                # filename without path (i.e. after the last "/")
1132             basefilename=$(basename ${line})
1133
1134                # check if there is an extension
1135             extension=${basefilename##*.}
1136             if [[ "$extension" = "${extout[$i]}" ]]
1137             then
1138                basefilename=${basefilename%.*}
1139             fi
1140
1141                # check for an existing cycle number
1142             cycle=${basefilename##*.}
1143             if [[ $cycle =~ ^-?[0-9]+$ ]]
1144             then
1145                (( icycle = $cycle + 1 ))
1146             else
1147                (( icycle = 1 ))
1148             fi
1149
1150             if (( icycle > maxcycle ))
1151             then
1152                (( maxcycle = icycle ))
1153             fi
1154
1155          done <filelist
1156          rm filelist
1157       fi
1158
1159          # APPEND CYCLE NUMBER TO FILENAME AND CHECK, IF FILE CAN BE CREATED
1160          # IN CASE OF FILE-APPEND, FILE MUST BE APPENDED TO THE ONE WITH HIGHEST CYCLE NUMBER
1161       if [[ "${actionout[$i]}" != a ]]
1162       then
1163          if (( maxcycle > 0 ))
1164          then
1165             filename_tmp=${filename}.$maxcycle
1166             if  cat /dev/null > $filename_tmp 
1167             then
1168                rm  $filename_tmp
1169             else
1170                printf "\n  +++ OUTPUT-file:"
1171                printf "\n           $filename_tmp"
1172                printf "\n      cannot be created"
1173                locat=output  ; exit
1174             fi
1175          fi
1176       else
1177          (( maxcycle = maxcycle - 1 ))
1178       fi
1179       
1180       (( cycnum[$i] = maxcycle ))
1181       pathout[$i]=$filename
1182
1183    fi
1184 done
1185
1186
1187    # DETERMINE THE NAME OF PALMRUN'S TEMPORARY WORKING DIRECTORY
1188 if [[ $running_in_batch_mode = false ]]
1189 then
1190    run_id=$RANDOM
1191    job_id=${fname}.$run_id
1192
1193    tempdir=$fast_io_catalog/$job_id
1194 fi
1195
1196
1197    # CHECK SETTINGS REQUIRED FOR BATCH JOBS
1198 if [[ $create_batch_job = true  ||  $create_remote_batch_job = true ]]
1199 then
1200
1201       # CHECK, IF JOB DIRECTIVES HAVE BEEN GIVEN IN CONFIGURATION FILE
1202    if [[ $ibd = 0 ]]
1203    then
1204       printf "\n"
1205       printf "\n  +++ no batch directives found in configuration file"
1206       locat=config_file_batch_directives; (( iec = 0 )); exit
1207    fi
1208
1209       # CHECK IF CPUTIME IS GIVEN FOR JOB
1210    done=false
1211    cputime=$cpumax
1212    while [[ $done = false ]]
1213    do
1214       if (( cputime == 0 ))
1215       then
1216          printf "\n  +++ cpu-time is undefined"
1217          printf "\n  >>> Please type CPU-time in seconds as INTEGER:"
1218          printf "\n  >>> "
1219          read  cputime   1>/dev/null  2>&1
1220       else
1221          done=true
1222       fi
1223    done
1224    cpumax=$cputime
1225
1226       # CHECK THE MEMORY DEMAND
1227    done=false
1228    while [[ $done = false ]]
1229    do
1230       if (( memory == 0 ))
1231       then
1232          printf "\n  +++ memory demand is undefined"
1233          printf "\n  >>> Please type memory in  MByte per process  as INTEGER:"
1234          printf "\n  >>> "
1235          read  memory  1>/dev/null  2>&1
1236       else
1237          done=true
1238       fi
1239    done
1240
1241       # IN CASE OF REMOTE-JOBS CHECK, IF A USERNAME FOR THE REMOTE HOST IS GIVEN
1242    if [[ $create_remote_batch_job = true  &&  -z $remote_username ]]
1243    then
1244       while [[ -z $remote_username ]]
1245       do
1246          printf "\n  +++ username on remote host with IP \"$remote_ip\" is undefined"
1247          printf "\n  >>> Please type username:"
1248          printf "\n  >>> "
1249          read  remote_username
1250       done
1251    fi
1252
1253 else
1254
1255    if [[ $running_in_batch_mode = false ]]
1256    then
1257       cputime=10000000  # NO LIMT FOR INTERACTIVE RUNS
1258       cpumax=$cputime
1259    else
1260       cputime=$cpumax
1261    fi
1262
1263 fi
1264
1265
1266    # CALCULATE HOURS/MINUTES/SECONDS, E.G. FOR BATCH-DIRECTIVES
1267 (( cpu_hours  = cputime / 3600 ))
1268 (( resttime = cputime - cpu_hours * 3600 ))
1269 (( cpu_minutes  = resttime / 60 ))
1270 (( cpu_seconds = resttime - cpu_minutes * 60 ))
1271 timestring=${cpu_hours}:${cpu_minutes}:${cpu_seconds}
1272
1273
1274    # OUTPUT OF THE PALMRUN-HEADER
1275 calltime=$(date)
1276 printf "\n"
1277 printf "#------------------------------------------------------------------------# \n"
1278 printf "| %-35s%35s | \n" "$version" "$calltime"
1279 printf "|                                                                        | \n"
1280 column1="called on:"; column2=$(hostname)
1281 printf "| %-25s%-45s | \n" "$column1" "$column2"
1282 if [[ $create_remote_batch_job = true ]]
1283 then
1284    column1="execution on:"; column2="$host_configuration (username: $remote_username)"
1285 else
1286    if [[ $running_on_remote = true ]]
1287    then
1288       column1="execution on:"; column2="$host_configuration (IP:$remote_ip)"
1289    else
1290       column1="execution on:"; column2="$host_configuration (IP:$local_ip)"
1291    fi
1292 fi
1293 printf "| %-25s%-45s | \n" "$column1" "$column2"
1294
1295 column1="running in:"
1296 if [[ $running_in_batch_mode = true ]]
1297 then
1298    column2="batch job mode"
1299 else
1300    if [[ $create_batch_job = true  ||  $create_remote_batch_job = true ]]
1301    then
1302       column2="job creation mode"
1303    else
1304       column2="interactive run mode"
1305    fi
1306 fi
1307 printf "| %-25s%-45s | \n" "$column1" "$column2"
1308
1309 if  [[ $running_in_batch_mode = true  ||  $create_batch_job = true  ||  $create_remote_batch_job = true ]]
1310 then
1311    if [[ "$project_account" != "" ]]
1312    then
1313       column1="project account number:"
1314       column2="$project_account"
1315       printf "| %-25s%-45s | \n" "$column1" "$column2"
1316    fi
1317 fi
1318
1319 if [[ -n $cores ]]
1320 then
1321    if [[ $run_coupled_model = false ]]
1322    then
1323       column1="number of cores:"; column2=$cores
1324    else
1325       column1="number of cores:"; column2="$cores  (atmosphere: $cores_atmos, ocean: $cores_ocean)"
1326    fi
1327    printf "| %-25s%-45s | \n" "$column1" "$column2"
1328 fi
1329 if [[ -n $tasks_per_node ]]
1330 then
1331    column1="tasks per node:"; column2="$tasks_per_node (number of nodes: $nodes)"
1332    printf "| %-25s%-45s | \n" "$column1" "$column2"
1333    if (( remaining_cores > 0 ))
1334    then
1335       column1=" "; column2="one of the nodes only filled with $remaining_cores tasks"
1336       printf "| %-25s%-45s | \n" "$column1" "$column2"
1337    fi
1338 fi
1339 if [[ $maximum_parallel_io_streams != $cores ]]
1340 then
1341    column1="max par io streams:"; column2="$maximum_parallel_io_streams"
1342    printf "| %-25s%-45s | \n" "$column1" "$column2"
1343 fi
1344 if [[ $use_openmp = true ]]
1345 then
1346    column1="threads per task:"; column2="$threads_per_task"
1347    printf "| %-25s%-45s | \n" "$column1" "$column2"
1348 fi
1349 if [[ $create_batch_job = true  ||  $create_remote_batch_job = true  ||  $running_in_batch_mode = true ]]
1350 then
1351    column1="memory demand / PE":; column2="$memory MB"
1352    printf "| %-25s%-45s | \n" "$column1" "$column2"
1353    column1="job cpu time (h:m:s):"; column2="$timestring"
1354    printf "| %-25s%-45s | \n" "$column1" "$column2"
1355 fi
1356 printf "|                                                                        | \n"
1357 if [[ "$source_list" != "" ]]
1358 then
1359    if [[ "$make_options" != "" ]]
1360    then
1361       column1="make options:"; column2=$(echo "$make_options" | cut -c-45)
1362       printf "| %-25s%-45s | \n" "$column1" "$column2"
1363       line=$(echo "$make_options" | cut -c46-)
1364       while [[ "$line" != "" ]]
1365       do
1366          column1=""
1367          column2=$(echo "$line" | cut -c-45)
1368          printf "| %-25s%-45s | \n" "$column1" "$column2"
1369          line=$(echo "$line" | cut -c46-)
1370       done
1371    fi
1372 fi
1373
1374 column1="cpp directives:"; column2=$(echo "$cpp_options" | cut -c-45)
1375 printf "| %-25s%-45s | \n" "$column1" "$column2"
1376 line=$(echo "$cpp_options" | cut -c46-)
1377 while [[ "$line" != "" ]]
1378 do
1379    column1=""
1380    column2=$(echo "$line" | cut -c-45)
1381    printf "| %-25s%-45s | \n" "$column1" "$column2"
1382    line=$(echo "$line" | cut -c46-)
1383 done
1384
1385 column1="compiler options:"; column2=$(echo "$compiler_options" | cut -c-45)
1386 printf "| %-25s%-45s | \n" "$column1" "$column2"
1387 line=$(echo "$compiler_options" | cut -c46-)
1388 while [[ "$line" != "" ]]
1389 do
1390    column1=""
1391    column2=$(echo "$line" | cut -c-45)
1392    printf "| %-25s%-45s | \n" "$column1" "$column2"
1393    line=$(echo "$line" | cut -c46-)
1394 done
1395
1396 column1="linker options:"; column2=$(echo "$linker_options" | cut -c-45)
1397 printf "| %-25s%-45s | \n" "$column1" "$column2"
1398 line=$(echo "$linker_options" | cut -c46-)
1399 while [[ "$line" != "" ]]
1400 do
1401    column1=""
1402    column2=$(echo "$line" | cut -c-45)
1403    printf "| %-25s%-45s | \n" "$column1" "$column2"
1404    line=$(echo "$line" | cut -c46-)
1405 done
1406
1407 if [[ "$login_init_cmd" != "" ]]
1408 then
1409    column1="login init commands:"; column2=$(echo "$login_init_cmd" | cut -c-45)
1410    printf "| %-25s%-45s | \n" "$column1" "$column2"
1411    line=$(echo "$login_init_cmd" | cut -c46-)
1412    while [[ "$line" != "" ]]
1413    do
1414       column1=""
1415       column2=$(echo "$line" | cut -c-45)
1416       printf "| %-25s%-45s | \n" "$column1" "$column2"
1417       line=$(echo "$line" | cut -c46-)
1418    done
1419 fi
1420
1421 if [[ "$module_commands" != "" ]]
1422 then
1423    column1="module commands:"; column2=$(echo "$module_commands" | cut -c-45)
1424    printf "| %-25s%-45s | \n" "$column1" "$column2"
1425    line=$(echo "$module_commands" | cut -c46-)
1426    while [[ "$line" != "" ]]
1427    do
1428       column1=""
1429       column2=$(echo "$line" | cut -c-45)
1430       printf "| %-25s%-45s | \n" "$column1" "$column2"
1431       line=$(echo "$line" | cut -c46-)
1432    done
1433 fi
1434 printf "|                                                                        | \n"
1435 column1="base name of files:"; column2=$fname
1436 printf "| %-25s%-45s | \n" "$column1" "$column2"
1437 column1="activation string list:"; column2=$(echo $activation_string_list)
1438 printf "| %-25s%-45s | \n" "$column1" "$column2"
1439
1440 if [[ "$ocean_file_appendix" = true ]]
1441 then
1442    printf "| %-35s%-35s | \n" "suffix \"_O\" is added to local files" " "
1443 fi
1444
1445 if [[ "$source_list" != "" ]]
1446 then
1447    printf "|                                                                        | \n"
1448    printf "| Files to be compiled:                                                  | \n"
1449    line=$source_list
1450    while [[ "$line" != "" ]]
1451    do
1452       linestart=$(echo $line | cut -c-70)
1453       printf "| %-70s | \n" "$linestart"
1454       line=$(echo "$line" | cut -c71-)
1455    done
1456 fi
1457 printf "#------------------------------------------------------------------------#"
1458
1459
1460
1461    # OUTPUT OF FILE CONNECTIONS IN CASE OF TRACEBACK
1462 if [[ $do_trace = true ]]
1463 then
1464    (( i = 0 ))
1465    while (( i < iin ))
1466    do
1467       (( i = i + 1 ))
1468       if (( i == 1 ))
1469       then
1470          printf "\n\n >>> INPUT-file assignments:\n"
1471       fi
1472       printf "\n     ${localin[$i]} :  ${absnamein[$i]}"
1473    done
1474    (( i = 0 ))
1475    while (( i < iout ))
1476    do
1477       (( i = i + 1 ))
1478       if (( i == 1 ))
1479       then
1480          printf "\n\n >>> OUTPUT-file assignments:\n"
1481       fi
1482       printf "\n     ${localout[$i]} :  ${pathout[$i]}"
1483    done
1484    (( i = 0 ))
1485    while (( i < iic ))
1486    do
1487       (( i = i + 1 ))
1488       if (( i == 1 ))
1489       then
1490          printf "\n\n >>> INPUT-commands:\n"
1491       fi
1492       printf "\n     ${in_command[$i]}" 
1493    done
1494    (( i = 0 ))
1495    while (( i < ioc ))
1496    do
1497       (( i = i + 1 ))
1498       if (( i == 1 ))
1499       then
1500          printf "\n\n >>> OUTPUT-commands:\n"
1501       fi
1502       printf "\n     ${out_command[$i]}" 
1503    done
1504 fi
1505
1506    # QUERY FOR CONTINUE
1507 if [[ $silent = false  &&  $running_in_batch_mode = false ]]
1508 then
1509    antwort=dummy
1510    printf "\n\n"
1511    printf " >>> everything o.k. (y/n) ?  "
1512    while  read antwort
1513    do
1514       if [[ "$antwort" != y  &&  "$antwort" != Y  &&  "$antwort" != n  &&  "$antwort" != N ]]
1515       then
1516          printf " >>> everything o.k. (y/n) ?  "
1517       else
1518          break
1519       fi
1520    done
1521    if [[ $antwort = n  ||  $antwort = N ]]
1522    then
1523       locat=user_abort; (( iec = 0 )); exit
1524    fi
1525    if [[ $create_batch_job = true  ||  $create_remote_batch_job = true ]]
1526    then
1527       printf "\n ***  batch-job will be created and submitted"
1528    else
1529       printf "\n ***  PALMRUN will now continue to execute on this machine"
1530    fi
1531 fi
1532
1533 
1534
1535    # PROVIDE FILES TO EXECUTE PALM AND CREATE THE EXECUTABLE
1536 if [[ $restart_run = false  &&  $running_in_batch_mode = false ]]
1537 then
1538
1539    if [[ $create_batch_job = true  ||  $create_remote_batch_job  = true ]]
1540    then
1541       printf "\n\n  *** creating executable and other sources for the remote host\n"
1542    else
1543       printf "\n\n  *** creating executable and other sources for the local host\n"
1544    fi
1545
1546       # FIRST CHECK, IF A MAKE DEPOSITORY EXISTS, AND IF NOT, ASK THE USER IF
1547       # IT SHALL BE CREATED
1548    ask_for_make_depository=false
1549    if [[ $create_remote_batch_job = true ]]
1550    then
1551
1552       line=`grep %base_directory $config_file`
1553       make_depository=`echo $line | cut -d" " -s -f2`/MAKE_DEPOSITORY_${host_configuration}
1554       echo  "[[ ! -d ${make_depository} ]]  &&  echo depository not found" | ssh  -q  $ssh_key  ${remote_username}@${remote_ip} 2>&1  | tee ${host_configuration}_last_make_protokoll
1555
1556       if [[ $(grep -c "depository not found" ${host_configuration}_last_make_protokoll) != 0 ]]
1557       then
1558          printf "\n\n  +++ make depository \"${make_depository}\""
1559          printf "\n      on remote host not found!"
1560          ask_for_make_depository=true
1561       fi
1562       rm ${host_configuration}_last_make_protokoll
1563
1564    else
1565
1566          # CHECK FOR MAKE_DEPOSITORY ON THE LOCAL HOST
1567       make_depository=${base_directory}/MAKE_DEPOSITORY_${host_configuration}
1568       if [[ ! -d ${make_depository} ]]
1569       then
1570          printf "\n\n  +++ make depository \"${make_depository}\""
1571          printf "\n      on local host not found!"
1572          ask_for_make_depository=true
1573       fi
1574
1575    fi
1576
1577    if [[ $ask_for_make_depository = true ]]
1578    then
1579
1580       antwort=dummy
1581       printf "\n\n"
1582       printf "  >>> Create a new one (y/n) ?  "
1583       while  read antwort
1584       do
1585          if [[ "$antwort" != y  &&  "$antwort" != Y  &&  "$antwort" != n  &&  "$antwort" != N ]]
1586          then
1587             printf "  >>> Create a new one (y/n) ?  "
1588          else
1589             break
1590          fi
1591       done
1592       if [[ $antwort = n  ||  $antwort = N ]]
1593       then
1594          locat=user_abort; (( iec = 0 )); exit
1595       fi
1596
1597       if [[ $do_trace = true ]]
1598       then
1599          palmbuild  -h $host_configuration
1600       else
1601          palmbuild  -v  -h $host_configuration
1602       fi
1603
1604       if [[ $? != 0 ]]
1605       then
1606   
1607              # ABORT IN CASE OF COMPILATION PROBLEMS
1608          printf "\n  +++ error while compiling for the MAKE_DEPOSITORY"
1609          locat=make_depository
1610          exit
1611       else
1612          echo "  *** now continue with creating executable and other sources"
1613       fi
1614
1615    fi
1616
1617       # NOW CREATE THE SOURCES_FOR_RUN FOLDER
1618    palmbuild  -v  $use_existing_sources_folder  -h $host_configuration  -d $fname
1619
1620    if [[ $? != 0 ]]
1621    then
1622
1623           # ABORT IN CASE OF COMPILATION PROBLEMS
1624       printf "\n  +++ error while creating executable and/or other sources"
1625       locat=execution
1626       rm -rf  $sources_for_run_catalog
1627       exit
1628
1629    else
1630
1631       printf "  *** executable and other sources created\n"
1632       rm -rf  $sources_for_run_catalog
1633
1634    fi
1635
1636 fi
1637
1638
1639    # NOW PERFORM THOSE ACTIONS REQUIRED TO EXECUTE THE PROGRAM (PALM) ON THIS MACHINE
1640    # (COMPILING/LINKING, EXECUTING, COPYING I/O FILES)
1641 if [[ $create_batch_job = false  &&  $create_remote_batch_job = false ]]
1642 then
1643
1644       # CHANGE TO THE TEMPORARY WORKING DIRECTORY
1645    if [[ $running_in_batch_mode = false ]]
1646    then
1647          # CREATE THE DIRECTORY AND COPY FILES FROM SOURCES_FOR_RUN_... TO THAT
1648          # FOLDER
1649       mkdir -p  $tempdir
1650       chmod  go+rx  $tempdir
1651       cd  $tempdir
1652       cp  ${fast_io_catalog}/${sources_for_run_catalog}/{*,.[!.]*}  $tempdir
1653       printf "\n  *** changed to temporary directory: $tempdir"
1654
1655    else
1656
1657          # IN BATCH MODE PALMRUN IS CALLED FROM TEMPDIR
1658       printf "\n  *** running in temporary directory: $tempdir"
1659
1660    fi
1661
1662
1663       # PROVIDE THE INPUT FILES
1664       # LOOP OVER ALL ACTIVATED FILES (LISTED IN THE CONFIGURATION FILE)
1665    (( i = 0 ))
1666    while (( i < iin ))
1667    do
1668       (( i = i + 1 ))
1669       if (( i == 1 ))
1670       then
1671          printf "\n\n  *** providing INPUT-files:\n$dashes"
1672       fi
1673
1674
1675          # SKIP OPTIONAL FILES, IF THEY DO NOT EXIST
1676       if [[ "${transin[$i]}" = unavailable ]]
1677       then
1678          if [[ "${extin[$i]}" = ""  ||  "${extin[$i]}" = " " ]]
1679          then
1680             printf "\n  *** INFORMATIVE: input file \"${pathin[$i]}/${fname}${endin[$i]}\" "
1681             printf "\n                   is not available!"
1682          else
1683             printf "\n  *** INFORMATIVE: input file \"${pathin[$i]}/${fname}${endin[$i]}.${extin[$i]}\" "
1684             printf "\n                   is not available!"
1685          fi
1686          continue
1687       fi
1688
1689          # CHECK FOR SINGLE FILE (SERIAL RUN) OR DIRECTORY (ONE FILE PER CORE FOR PARELLEL EXECUTION)
1690       files_for_cores=false; filetype=file
1691       if [[ "${actionin[$i]}" = pe  &&  -n $cores ]]
1692       then
1693          files_for_cores=true; filetype=files
1694          actionin[$i]=""
1695       elif [[ "${actionin[$i]}" = pe  &&  ! -n $cores ]]
1696       then
1697          actionin[$i]=""
1698       elif [[ "${actionin[$i]}" = lnpe  &&  -n $cores ]]
1699       then
1700          files_for_cores=true; filetype=files
1701          actionin[$i]="ln"
1702       elif [[ "${actionin[$i]}" = lnpe  &&  ! -n $cores ]]
1703       then
1704          actionin[$i]="ln"
1705       fi
1706
1707       if [[ $files_for_cores = true ]]
1708       then
1709          printf "\n  >>> INPUT: ${absnamein[$i]}/....  to  ${localin[$i]}"
1710       else
1711          printf "\n  >>> INPUT: ${absnamein[$i]}  to  ${localin[$i]}"
1712       fi
1713
1714          # INPUT-FILES TO BE LINKED
1715       if [[ "${actionin[$i]}" = ln ]]
1716       then
1717
1718          printf "\n      $filetype will be linked"
1719          if [[ $files_for_cores = false ]]
1720          then
1721             if [[ -f "${absnamein[$i]}" ]]
1722             then
1723                ln  ${absnamein[$i]}  ${localin[$i]}
1724                got_tmp[$i]=true
1725             fi
1726          else
1727             if [[ -d "${absnamein[$i]}" ]]
1728             then
1729                mkdir -p ${localin[$i]}
1730                cd ${absnamein[$i]}
1731                for file in $(ls *)
1732                do
1733                   ln $file $tempdir/${localin[$i]}
1734                done >|/dev/null 2>&1
1735                cd $tempdir
1736             fi
1737
1738                # IF "ln -f" HAS FAILED DO A NORMAL COPY "cp -r"
1739             if [[ ! -f "${localin[$i]}/_000000" ]]
1740             then
1741                printf "\n  --- WARNING: ln failed, using cp instead (might be time consuming...)"
1742                cp -r  ${absnamein[$i]}/*  ${localin[$i]}
1743             fi
1744
1745             got_tmp[$i]=true
1746          fi
1747       fi
1748
1749          # FILE IS STORED IN THE RESPECTIVE DIRECTORY GIVEN IN THE CONFIGURATION FILE
1750       if [[ "${actionin[$i]}" = ""  ||  "${actionin[$i]}" = "di"  ||  "${actionin[$i]}" = "npe" ]]
1751       then
1752
1753          if [[ "${actionin[$i]}" = "npe"  &&  -n $cores ]]
1754          then
1755
1756                # FILE COPIES ARE PROVIDED FOR ALL CORES
1757                # EACH FILE GETS A UNIQUE FILENAME WITH A FOUR DIGIT NUMBER
1758             printf "\n      file will be provided for $cores processors"
1759             mkdir -p ${localin[$i]}
1760             ival=$cores
1761             (( ii = 0 ))
1762             while (( ii <= ival-1 ))
1763             do
1764                if (( ii < 10 ))
1765                then
1766                   cp  ${absnamein[$i]}  ${localin[$i]}/_000$ii
1767                elif (( ii < 100 ))
1768                then
1769                   cp  ${absnamein[$i]}  ${localin[$i]}/_00$ii
1770                elif (( ii < 1000 ))
1771                then
1772                   cp  ${absnamein[$i]}  ${localin[$i]}/_0$ii
1773                else
1774                   cp  ${absnamein[$i]}  ${localin[$i]}/_$ii
1775                fi
1776                (( ii = ii + 1 ))
1777             done
1778
1779          else
1780
1781             if [[ $files_for_cores = true ]]
1782             then
1783
1784                   # PROVIDE FILES FOR EACH CORE
1785                   # FIRST CREATE THE LOCAL DIRECTORY, THEN COPY FILES
1786                   # FROM THE PERMANENT DIRECTORY BY LINKING THEM TO THE LOCAL ONE
1787                printf "\n      providing $cores files for the respective cores"
1788                mkdir -p ${localin[$i]}
1789                        if [[ $link_local_input = true ]]
1790                              then
1791                                 printf "      files will be linked\n"
1792                                 cd ${absnamein[$i]}
1793                                 for file in $(ls *)
1794                                 do
1795                                    ln -f $file  ${localin[$i]}
1796                                 done
1797                                 cd $tempdir
1798                              fi
1799
1800                   # IF "ln -f" FAILED OR IF "$link_local_input = false" DO A NORMAL "cp -r"
1801                              if [[ ! -f "${localin[$i]}/_000000" ]]
1802                              then
1803                                 if [[ $link_local_input = true ]]
1804                                        then
1805                                        printf "\n  --- WARNING: ln failed, using cp instead (might be time consuming...)"
1806                                 fi
1807                                 cp -r  ${absnamein[$i]}/*  ${localin[$i]}
1808                              fi
1809
1810             else
1811
1812                   # PROVIDE FILE FOR RUNS ON A SINGLE CORE
1813                        if [[ $link_local_input = true ]]
1814                        then
1815                                 printf "      file will be linked\n"
1816                                 ln -f  ${absnamein[$i]}  ${localin[$i]}
1817                        fi
1818                                # If "ln -f" fails of if "$link_local_input = false" do a normal "cp"
1819                        if [[ ! -f "${localin[$i]}" ]]
1820                then
1821                                 if [[ $link_local_input = true ]]
1822                          then
1823                      printf "\n  --- WARNING: ln failed, using cp instead (might be time consuming...)"
1824                                 fi
1825                                 cp  ${absnamein[$i]}  ${localin[$i]}
1826                fi
1827             fi
1828          fi
1829       fi
1830
1831    done
1832    if (( i != 0 ))
1833    then
1834       printf "\n$dashes\n  *** all INPUT-files provided \n"
1835    fi
1836
1837
1838       # EXECUTE INPUT-COMMANDS GIVEN IN THE CONFIGURATION FILE
1839    (( i = 0 ))
1840    while (( i < iic ))
1841    do
1842       (( i = i + 1 ))
1843       if (( i == 1 ))
1844       then
1845          printf "\n\n  *** execution of INPUT-commands:\n$dashes"
1846       fi
1847       printf "\n  >>> ${in_command[$i]}"
1848       eval  ${in_command[$i]}
1849       if (( i == iic ))
1850       then
1851          printf "\n$dashes\n"
1852       fi
1853    done
1854
1855
1856       # CREATE THE NAMELIST-FILE WITH VALUES OF ENVIRONMENT-VARIABLES REQUIRED BY PALM
1857       # (FILE ENVPAR WILL BE READ BY PALM)
1858    cat  >  ENVPAR  <<  EOF
1859 &envpar  run_identifier = '$fname', host = '$host_configuration',
1860          write_binary = .${write_binary}., tasks_per_node = $tasks_per_node,
1861          maximum_parallel_io_streams = $maximum_parallel_io_streams,
1862          maximum_cpu_time_allowed = ${cpumax}.,
1863          revision = '$global_revision',
1864          batch_job = .${running_in_batch_mode}. /
1865
1866EOF
1867
1868
1869       # STARTING THE EXECUTABLE
1870    printf "\n\n  *** execution starts in directory\n      \"`pwd`\"\n$dashes\n"
1871    PATH=$PATH:$tempdir
1872
1873
1874       # REPLACE PARAMETERS IN THE EXECUTION COMMAND WITH REAL VALUES
1875    line=`echo  "${execute_command}" | sed 's/{{MPI_TASKS}}/$mpi_tasks/g' | sed 's/{{TASKS_PER_NODE}}/$tasks_per_node/g'`
1876    line2=`echo  "${execute_command}" | sed 's/{{MPI_TASKS}}/1/g' | sed 's/{{TASKS_PER_NODE}}/1/g' | sed 's/palm/combine_plot_fields.x/g'`
1877    eval line=\"$line\"
1878    execute_command="$line"
1879
1880
1881       # EXECUTION COMMAND FOR COMBINE_PLOT_FIELDS
1882    if [[ "$execute_command_for_combine" = "" ]]
1883    then
1884       eval line2=\"$line2\"
1885       execute_command_for_combine="$line2"
1886    fi
1887   
1888
1889
1890       # PROVIDE A HOSTFILE, IF REQUIRED
1891    if [[ "$hostfile" != "" ]]
1892    then
1893
1894       if [[ $hostfile = auto ]]
1895       then
1896             # CREATE A NEW HOSTFILE
1897          (( ii = 1 ))
1898          while (( ii <= cores / threads_per_task ))
1899          do
1900             echo  $(hostname)  >>  hostfile
1901             (( ii = ii + 1 ))
1902          done
1903          if (( cores / threads_per_task == 0 ))
1904          then
1905             echo  $(hostname)  >>  hostfile
1906          fi
1907       
1908       else
1909          cp  $hostfile  hostfile
1910       fi
1911       eval line=\"`head -n $ii  hostfile`\"
1912       printf "\n  *** running on: $line"
1913    fi
1914
1915
1916
1917       # SET THE NUMBER OF OPENMP-THREADS
1918    if [[ $use_openmp = true ]]
1919    then
1920       export OMP_NUM_THREADS=$threads_per_task
1921       printf "\n  *** number of OpenMP threads per MPI-task: $OMP_NUM_THREADS"
1922    else
1923       export OMP_NUM_THREADS=1
1924    fi
1925
1926
1927       # PROVIDE DATA FOR
1928    if [[ $run_coupled_model = false ]]
1929    then
1930       if [[ "$ocean_file_appendix" = true ]]
1931       then
1932          echo "precursor_ocean"  >  coupling_steering
1933       else
1934          echo "precursor_atmos"  >  coupling_steering
1935      fi
1936    else
1937       (( iia = $cores_atmos / $threads_per_task ))
1938       (( iio = $cores_ocean / $threads_per_task ))
1939       printf "\n      coupled run ($iia atmosphere, $iio ocean)"
1940       printf "\n\n"
1941       echo "coupled_run $iia $iio"  >  coupling_steering
1942    fi
1943
1944    printf "\n  *** execute command:"
1945    printf "\n      \"$execute_command\" \n\n"
1946
1947    $execute_command  <  coupling_steering
1948
1949    if [[ $? != 0 ]]
1950    then
1951
1952           # ABORT IN CASE OF RUNTIME ERRORS
1953       printf "\n  +++ runtime error occured"
1954       locat=execution
1955       exit
1956
1957    else
1958
1959       printf "\n$dashes\n  *** execution finished \n"
1960
1961    fi
1962
1963
1964       # CALL OF combine_plot_fields IN ORDER TO MERGE SINGLE FILES WRITTEN
1965       # BY EACH CORE INTO ONE FILE
1966   if [[ ! -f combine_plot_fields.x ]]
1967   then
1968
1969      printf "\n\n\n  +++ WARNING: no combine_plot_fields found"
1970      printf "\n      2d- and/or 3d-data may be incomplete!"
1971      printf "\n      Your previous palmbuild may have failed. Please check.\n"
1972
1973   elif [[ "$combine_plot_fields" == true ]]
1974   then
1975
1976      printf "\n\n\n *** post-processing: now executing \"$execute_command_for_combine\" ..."
1977      $execute_command_for_combine
1978
1979   else
1980
1981         # TEMPORARY SOLUTION TO SKIP combine_plot_fields. THIS IS REQUIRED IN CASE OF HUGE AMOUNT OF
1982         # DATA OUTPUT. TO DO: EXTEND THIS BRANCH BY CREATING A BATCH JOB for combine_plot_fields.
1983         # ??? koennen wir das streichen ???
1984      printf "\n\n\n *** post-processing: skipping combine_plot_fields (-Z option set) ..."
1985   fi
1986
1987
1988
1989       # EXECUTE OUTPUT-COMMANDS GIVEN IN THE CONFIGURATION FILE
1990    (( i = 0 ))
1991    while (( i < ioc ))
1992    do
1993       (( i = i + 1 ))
1994       if (( i == 1 ))
1995       then
1996          printf "\n\n  *** execution of OUTPUT-commands:\n$dashes"
1997       fi
1998       printf "\n  >>> ${out_command[$i]}"
1999       eval  ${out_command[$i]}
2000       if (( i == ioc ))
2001       then
2002          printf "\n$dashes\n"
2003       fi
2004    done
2005
2006
2007       # COPY LOCAL OUTPUT-FILES TO THEIR PERMANENT DESTINATIONS
2008    (( i = 0 ))
2009    while (( i < iout ))
2010    do
2011       (( i = i + 1 ))
2012       if (( i == 1 ))
2013       then
2014          printf "\n\n  *** saving OUTPUT-files:"
2015
2016             # GET RUN NUMBER ASSIGNED BY PALM
2017          if [[ -f RUN_NUMBER ]]
2018          then
2019              read  run_number  <  RUN_NUMBER
2020              printf "\n  *** PALM generated run_number = "$run_number" will be used as unified cycle number for all output files"
2021              usecycle_option="-U $run_number"
2022          else
2023              run_number=0
2024              usecycle_option=""
2025          fi
2026          if [[ $running_on_remote = true  &&  "$remote_loginnode" != "" ]]
2027          then
2028             printf "\n  *** in case of SCP transfers to local host"
2029             printf "\n      they will be done via remote login-node \"$remote_loginnode\" "
2030          fi
2031          printf "\n$dashes"
2032       fi
2033
2034          # ADD CYCLE NUMBER TO FILENAME
2035       if [[ ! ( $running_on_remote = true  &&  ( "${actionout[$i]}" = tr || "${actionout[$i]}" = tra || "${actionout[$i]}" = trpe ) ) ]]
2036       then
2037
2038              # IN APPEND MODE, FILES KEEP THEIR CURRENT CYCLE NUMBER
2039          if [[ "${actionout[$i]}" != "a" ]]
2040          then
2041                # SET RUN NUMBER AS CYCLE NUMBER, IF THERE IS NOT A CONFLICT
2042                # WITH AN EXISTING CYCLE NUMBER
2043             if (( run_number >= cycnum[$i] ))
2044             then
2045                (( cycnum[$i] = run_number ))
2046             else
2047                if (( run_number > 0 ))
2048                then
2049                   printf "\n  --- INFORMATIVE: The following file cannot get a unified cycle number"
2050                fi
2051             fi
2052          fi
2053          if (( cycnum[$i] > 0 ))
2054          then
2055             pathout[$i]=${pathout[$i]}.${cycnum[$i]}
2056          fi
2057       fi           
2058
2059          # CHECK FOR SINGLE FILE (SERIAL RUN) OR DIRECTORY (ONE FILE PER CORE FOR PARELLEL EXECUTION)
2060       files_for_cores=false; filetype=file
2061       link_local_output=false
2062       if [[ "${actionout[$i]}" = pe  &&  -n $cores ]]
2063       then
2064          files_for_cores=true; filetype=directory
2065          actionout[$i]=""
2066       elif [[ "${actionout[$i]}" = pe  &&  ! -n $cores ]]
2067       then
2068          actionout[$i]=""
2069       elif [[ "${actionout[$i]}" = lnpe  &&  -n $cores ]]
2070       then
2071          files_for_cores=true; filetype=directory
2072          link_local_output=true
2073          actionout[$i]=""
2074       elif [[ "${actionout[$i]}" = lnpe  &&  ! -n $cores ]]
2075       then
2076          link_local_output
2077          actionout[$i]=""
2078       elif [[ "${actionout[$i]}" = trpe  &&  -n $cores ]]
2079       then
2080          files_for_cores=true; filetype=directory
2081          actionout[$i]="tr"
2082       elif [[ "${actionout[$i]}" = trpe  &&  ! -n $cores ]]
2083       then
2084          actionout[$i]="tr"
2085       fi
2086
2087       if [[ ! -f ${localout[$i]}  &&  $files_for_cores = false ]]
2088       then
2089          printf "\n  +++ temporary OUTPUT-file  ${localout[$i]}  does not exist\n"
2090       elif [[ ! -d ${localout[$i]}  &&  $files_for_cores = true ]]
2091       then
2092          printf "\n  +++ temporary OUTPUT-file  ${localout[$i]}/....  does not exist\n"
2093       else
2094
2095
2096             # COPY VIA SCP TO LOCAL HOST (ALWAYS IN BINARY MODE USING batch_scp option -m)
2097             # IF TARGET DIRECTORY DOES NOT EXISTS, TRY TO CREATE IT
2098          if [[ "${actionout[$i]}" = tr  ||  "${actionout[$i]}" = tra ]]
2099          then
2100             if [[ $running_on_remote = true ]]
2101             then
2102
2103                   # SET OPTIONS FOR TRANSFER
2104                if [[ "${actionout[$i]}" = tr ]]
2105                then
2106                   if [[ $files_for_cores = false ]]
2107                   then
2108                      catalog_option=""
2109                      catalog_string=""
2110                   else
2111                      catalog_option="-c"
2112                      catalog_string="/"
2113                   fi
2114                   append_option=""
2115                   append_string=""
2116                else
2117                   append_option="-A"
2118                   append_string="append"
2119                fi
2120
2121                transfer_failed=false
2122                printf "\n  >>> OUTPUT: ${localout[$i]}$catalog_string  $append_string by SCP to"
2123                printf "\n              ${pathout[$i]}/${host_configuration}_${fname}${endout[$i]}$catalog_string\n"
2124
2125                   # TRANSFER VIA SCP
2126                if [[ "$remote_loginnode" != "" ]]
2127                then
2128                   echo "cd $tempdir; ${fast_io_catalog}/${sources_for_run_catalog}/batch_scp $PORTOPT $catalog_option $append_option -b -m $usecycle_option -u $local_username $return_address  ${localout[$i]} \"${pathout[$i]}\" ${host_configuration}_${fname}${endout[$i]}  ${extout[$i]}"  |  ssh -q $remote_username@$remote_loginnode
2129                else
2130                   batch_scp $PORTOPT $catalog_option $append_option -b -m $usecycle_option -u $local_username $return_address  ${localout[$i]} "${pathout[$i]}" ${host_configuration}_${fname}${endout[$i]}  ${extout[$i]}
2131                fi
2132                [[ $? != 0 ]]  &&  transfer_failed=true
2133
2134
2135                   # IF TRANSFER FAILED, CREATE BACKUP COPY ON THIS MACHINE
2136                if [[ $transfer_failed = true ]]
2137                then
2138                   printf "  +++ transfer failed. Trying to save a copy on this host under:\n"
2139                   printf "      ${pathout[$i]}/${host_configuration}_${fname}${endout[$i]}_$run_id\n"
2140
2141                      # FIRST CHECK, IF DIRECTORY EXISTS, AND CREATE IT, IF NECESSARY
2142                   eval  local_catalog=${pathout[$i]}
2143                   if [[ ! -d $local_catalog ]]
2144                   then
2145                      printf "  *** local directory does not exist. Trying to create:\n"
2146                      printf "      $local_catalog \n"
2147                      mkdir -p  $local_catalog
2148                   fi
2149                   eval  cp  ${localout[$i]}  ${pathout[$i]}/${host_configuration}_${fname}${endout[$i]}_$run_id
2150                   transfer_problems=true
2151                fi
2152
2153             else
2154
2155                   # UNSET actionout. DUE TO THIS SETTING, FILE WILL LATER JUST
2156                   # BE COPIED OR APPENDED ON THIS MACHINE
2157                if [[ "${actionout[$i]}" = tr ]]
2158                then
2159                   actionout[$i]=""
2160                else
2161                   actionout[$i]="a"
2162                fi
2163             fi
2164          fi
2165
2166
2167             # APPEND ON THIS MACHINE
2168          if [[ "${actionout[$i]}" = "a" ]]
2169          then
2170             if [[ "${extout[$i]}" != " "  &&  "${extout[$i]}" != "" ]]
2171             then
2172                printf "\n  >>> OUTPUT: ${localout[$i]}  append to"
2173                printf "\n              ${pathout[$i]}.${extout[$i]}\n"
2174                cat  ${localout[$i]}  >>  ${pathout[$i]}.${extout[$i]}
2175             else
2176                printf "\n  >>> OUTPUT: ${localout[$i]}  append to"
2177                printf "\n              ${pathout[$i]}\n"
2178                cat  ${localout[$i]}  >>  ${pathout[$i]}
2179             fi
2180          fi
2181
2182             # COPY ON THIS MACHINE
2183             # COPY HAS TO BE USED, BECAUSE MOVE DOES NOT WORK IF FILE-ORIGIN AND TARGET ARE
2184             # ON DIFFERENT FILE-SYSTEMS
2185          if [[ "${actionout[$i]}" = ""  &&  $files_for_cores = false ]]
2186          then
2187
2188                # COPY IN CASE OF RUNS ON SINGLE CORES
2189             if [[ "${extout[$i]}" != " "  &&  "${extout[$i]}" != "" ]]
2190             then
2191                printf "\n  >>> OUTPUT: ${localout[$i]}  to"
2192                printf "\n              ${pathout[$i]}.${extout[$i]}\n"
2193                              if [[ $link_local_output = true ]]
2194                              then
2195                                 printf "      file will be linked\n"
2196                                 ln -f  ${localout[$i]}  ${pathout[$i]}.${extout[$i]}
2197                              fi
2198                                 # If "ln -f" fails of if "$link_local_output = false" do a normal "cp"
2199                              if [[ ! -f "${pathout[$i]}.${extout[$i]}" ]]
2200                then
2201                                 if [[ $link_local_output = true ]]
2202                          then
2203                      printf "  --- WARNING: ln failed, using cp instead (might be time consuming...)\n"
2204                                 fi
2205                                 cp  ${localout[$i]}  ${pathout[$i]}.${extout[$i]}
2206                              else
2207                   printf "+++ no copy because file ${pathout[$i]}.${extout[$i]} exists\n"
2208                fi
2209             else
2210                printf "\n  >>> OUTPUT: ${localout[$i]}  to"
2211                printf "\n              ${pathout[$i]}\n"
2212                              if [[ $link_local_output = true ]]
2213                              then
2214                                 printf "      file will be linked\n"
2215                                 ln -f  ${localout[$i]}  ${pathout[$i]}
2216                              fi
2217                                 # If "ln -f" fails of if "$link_local_output = false" do a normal "cp"
2218                        if [[ ! -f "${pathout[$i]}" ]]
2219                then
2220                                 if [[ $link_local_output = true ]]
2221                          then
2222                      printf "  --- WARNING: ln failed, using cp instead (might be time consuming...)\n"
2223                                 fi
2224                                 cp  ${localout[$i]}  ${pathout[$i]}
2225                              else
2226                                 printf "+++ no copy because file ${pathout[$i]} exists\n"
2227                fi
2228             fi
2229
2230          elif [[ "${actionout[$i]}" = ""  &&  $files_for_cores = true ]]
2231          then
2232
2233                # FILES FROM THE DIFFERENT CORES ARE MOVED WITH ln-COMMAND TO THE PERMANENT DIRECTORY
2234                # AS A FIRST STEP, THE PERMANENT DIRECTORY IS CREATED
2235             printf "\n  >>> OUTPUT: ${localout[$i]}/_....  to"
2236             printf "\n              ${pathout[$i]}\n"
2237                    if [[ $link_local_output = true ]]
2238                    then
2239                              printf "      files will be linked\n"
2240                              mkdir -p ${pathout[$i]}
2241                              cd ${localout[$i]}
2242                              for file in $(ls *)
2243                              do
2244                                 ln -f $file  ${pathout[$i]}
2245                              done >|/dev/null 2>&1
2246                              cd $tempdir
2247                    fi
2248
2249                # IF "ln -f" HAS FAILED OR IF "$link_local_output = false" DO A NORMAL COPY "cp -r"
2250                    if [[ ! -f "${pathout[$i]}/_000000" ]]
2251             then
2252                              if [[ $link_local_output = true ]]
2253                              then
2254                   printf "  --- WARNING: ln failed, using cp instead (might be time consuming...)\n"
2255                              fi
2256                              cp -r  ${localout[$i]}/*  ${pathout[$i]}
2257             fi
2258
2259          fi
2260       fi
2261    done
2262
2263    if (( i != 0 ))
2264    then
2265       if [[ $transfer_problems = true ]]
2266       then
2267          printf "\n$dashes\n  *** OUTPUT-files saved"
2268          printf "\n  +++ WARNING: some data transfers failed! \n"
2269       else
2270          printf "\n$dashes\n  *** all OUTPUT-files saved \n"
2271       fi
2272    fi
2273
2274
2275       # IF REQUIRED, START A RESTART-JOB
2276       # FILE CONTINUE_RUN MUST HAVE BEEN CREATED BY THE EXECUTABLE (PALM)
2277    if [[ -f CONTINUE_RUN ]]
2278    then
2279
2280          # ADD RESTART-OPTIONS TO THE PALMRUN-CALL (IF THEY ARE NOT USED ALREADY):
2281          # -C TELLS PALMRUN THAT IT IS A RESTART-RUN
2282          # -v SILENT MODE WITHOUT INTERACTIVE QUERIES
2283          # -b START A BATCH JOB
2284       [[ $(echo $prc | grep -c "\-C") = 0 ]]  &&  prc="$prc -C"
2285       [[ $(echo $prc | grep -c "\-v") = 0 ]]  &&  prc="$prc -v"
2286       [[ $(echo $prc | grep -c "\-b") = 0 ]]  &&  prc="$prc -b"
2287
2288
2289          # REPLACE THE HASH IN THE ACTIVATION STRINGS (GIVEN WITH OPTION -a)
2290          # SO THAT RESTARTS ACCESS DIFFERENT FILES THAN THE INITIAL RUN
2291       if [[ $(echo $prc | grep -c "#") != 0 ]]
2292       then
2293          prc=`echo $prc | sed 's/#/r/g'`
2294       fi
2295
2296
2297          # START THE RESTART-JOB
2298       printf "\n\n  *** initiating restart-run on \"$local_ip\" using command:\n"
2299       echo "      $prc"
2300       printf "\n$dashes\n"
2301       if [[ $running_on_remote = true ]]
2302       then
2303
2304          echo "*** ssh will be used to initiate restart-runs!"
2305          echo "    return_address=\"$return_address\" "
2306          echo "    return_username=\"$local_username\" "
2307
2308          if [[ "$remote_loginnode" != "" ]]
2309          then
2310             echo "echo \" PATH=\\\$PATH:$LOCAL_PALMRUN_PATH; cd $LOCAL_PWD; $prc\" |  ssh -q $SSH_PORTOPT  $local_username@$return_address  " |  ssh -q $remote_username@$remote_loginnode
2311          else
2312             echo \" PATH=\\\$PATH:$LOCAL_PALMRUN_PATH; cd $LOCAL_PWD; $prc\" |  ssh -q $SSH_PORTOPT  $local_username@$return_address
2313          fi
2314
2315             # WAIT TO ALLOW THE RESTART-JOB TO BE QUEUED, BEFORE THE CURRENT JOB IS FINISHED
2316          sleep 30
2317
2318       else
2319
2320             # START THE RESTART JOB ON THE LOCAL HOST
2321          eval  $prc                # THE ' MUST BE EVALUATED
2322          cd -  > /dev/null
2323
2324       fi
2325       printf "\n$dashes\n  *** restart-run initiated \n"
2326
2327
2328          # DELETE INPUT-(RESTART)FILES, WHICH HAVE BEEN FETCHED FROM THE TEMPORARY DATA
2329          # DIRECTORY, BACAUSE THEY ARE NOT REQUIRED BY THE RESTART-JOB.
2330          # THIS IS DONE IN ORDER TO AVOID EXCEEDING DISC QUOTAS OR DISC SPACE (RESTART-FILES
2331          # MAY BE VERY HUGE)
2332       (( i = 0 ))
2333       while (( i < iin ))
2334       do
2335          (( i = i + 1 ))
2336          if [[ "${got_tmp[$i]}" = true   &&  $keep_data_from_previous_run = false ]]
2337          then
2338             rm -r  ${absnamein[$i]}
2339          fi
2340       done
2341
2342    fi
2343
2344
2345       # ALL ACTIONS FINISHED, TEMPORARY WORKING-DIRECTORY CAN BE DELETED
2346    cd  $HOME
2347    [[ $delete_temporary_catalog = true ]]  &&  rm -rf $tempdir
2348
2349
2350 else
2351
2352
2353       # PREPARING ACTIONS,
2354       # IF A BATCH-JOB IS TO BE GENERATED AND TO BE STARTED ON A LOCAL OR REMOTE-MACHINE
2355
2356       # BUILD THE PALMRUN-COMMAND TO BE CALLED IN THE BATCH-JOB
2357    palmrun_com="$palmrun_script_name -d $fname -h $host_configuration -m $memory -t $cpumax -q $queue -r $run_id -U $local_username"
2358    [[ "$activation_string_list" != "" ]]  &&  palmrun_com=${palmrun_com}" -a \"$activation_string_list\""
2359    [[ "$global_revision" != "" ]]  &&  palmrun_com=${palmrun_com}" -G \"$global_revision\""
2360    [[ $keep_data_from_previous_run = true ]]  &&  palmrun_com=${palmrun_com}" -k"
2361    [[ $do_trace = true ]]        &&  palmrun_com=${palmrun_com}" -x"
2362    [[ "$cores" != "" ]]       &&  palmrun_com=${palmrun_com}" -X $cores"
2363    [[ $use_openmp = true ]]  &&  palmrun_com=${palmrun_com}" -O $threads_per_task"
2364    [[ $tasks_per_node != 0 ]]  &&  palmrun_com=${palmrun_com}" -T $tasks_per_node"
2365    [[ $delete_temporary_catalog = false ]]  &&  palmrun_com=${palmrun_com}" -B"
2366    [[ "$ocean_file_appendix" = true ]]  &&  palmrun_com=${palmrun_com}" -y"
2367    [[ $run_coupled_model = true ]]  &&  palmrun_com=${palmrun_com}" -Y \"$coupled_dist\""
2368    [[ "$combine_plot_fields" = false ]]  &&  palmrun_com=${palmrun_com}" -Z"
2369    [[ "$max_par_io_str" != "" ]]  &&  palmrun_com=${palmrun_com}" -w $max_par_io_str"
2370    [[ "$project_account" != "" ]]  &&  palmrun_com=${palmrun_com}" -A $project_account"
2371    if [[ $create_remote_batch_job = true ]]
2372    then
2373       palmrun_com=${palmrun_com}" -j -u $remote_username -R $local_ip"
2374       if [[ $do_trace = true ]]
2375       then
2376          printf "\n *** PALMRUN-command on remote host:\n     $palmrun_com \n"
2377       fi
2378    elif [[ $create_batch_job = true ]]
2379    then
2380       palmrun_com=${palmrun_com}" -j"
2381       if [[ $do_trace = true ]]
2382       then
2383          printf "\n *** PALMRUN-command on local host:\n     $palmrun_com \n"
2384       fi
2385    fi
2386
2387
2388       # DETERMINE THE FULL PATHS FOR THE JOB PROTOCOL FILES ON THE LOCAL AND
2389       # REMOTE HOST
2390    job_protocol_file_local=${local_jobcatalog}/${host_configuration}_${job_id}
2391    job_protocol_file=$job_protocol_file_local
2392    if [[ $create_remote_batch_job = true ]]
2393    then
2394       job_protocol_file_remote=${remote_jobcatalog}/${host_configuration}_${job_id}
2395       job_protocol_file=$job_protocol_file_remote
2396       job_transfer_protocol_file=${remote_jobcatalog}/last_job_transfer_protocol
2397       scpjob_file=${remote_jobcatalog}/scpjob.$run_id
2398    fi
2399
2400
2401       # BUILD THE JOB-SCRIPTS ON FILE jobfile
2402    jobfile=jobfile.$run_id
2403
2404
2405       # FIRST CREATE THE BATCH DIRECTIVES
2406    (( i = 0 ))
2407    while (( i < ibd ))
2408    do
2409       (( i = i + 1 ))
2410       line=`echo  "${batch_directive[$i]}" | sed 's/{{JOB_ID}}/$job_id/g' | sed 's/{{JOBFILE}}/$job_protocol_file/g' | sed 's/{{CPU_HOURS}}/$cpu_hours/g' | sed 's/{{CPU_MINUTES}}/$cpu_minutes/g' | sed 's/{{CPU_SECONDS}}/$cpu_seconds/g' | sed 's/{{NODES}}/$nodes/g' | sed 's/{{CORES}}/$cores/g' | sed 's/{{TASKS_PER_NODE}}/$tasks_per_node/g' | sed 's/{{HOST_CONFIGURATION}}/${host_configuration}/g' | sed 's/{{FNAME}}/$fname/g' | sed 's/{{QUEUE}}/$queue/g' | sed 's/{{MEMORY}}/$memory/g' | sed 's/{{PROJECT_ACCOUNT}}/$project_account/g' | sed 's/{{PREVIOUS_JOB}}/$previous_job/g' | sed 's/{{TEMPDIR}}/$tempdir/g'`
2411       eval line=\"$line\"
2412       echo  "$line"                               >>  $jobfile
2413    done
2414    echo " "                                       >>  $jobfile
2415
2416
2417       # FOR BATCH JOBS ON REMOTE HOSTS, ADD THE JOBFILE TO SEND BACK THE JOB
2418       # PROTOCOL
2419    if [[ $create_remote_batch_job = true ]]
2420    then
2421       echo "set +vx"                              >>  $jobfile
2422       echo "trap '"                               >>  $jobfile
2423       echo "set +vx"                              >>  $jobfile
2424       echo "cd ${remote_jobcatalog}"              >>  $jobfile
2425       echo "cat >  scpjob.$run_id << %%END%%"     >>  $jobfile
2426
2427          # ADD THE BATCH DIRECTIVES
2428       (( i = 0 ))
2429       while (( i < ibdt ))
2430       do
2431          (( i = i + 1 ))
2432          line=`echo  "${batch_directive_transfer[$i]}" | sed 's/{{JOB_ID}}/$job_id/g' | sed 's/{{JOBFILE}}/$job_protocol_file/g' | sed 's/{{JOB_TRANSFER_PROTOCOL_FILE}}/$job_transfer_protocol_file/g' | sed 's/{{CPU_HOURS}}/$cpu_hours/g' | sed 's/{{CPU_MINUTES}}/$cpu_minutes/g' | sed 's/{{CPU_SECONDS}}/$cpu_seconds/g' | sed 's/{{NODES}}/$nodes/g' | sed 's/{{TASKS_PER_NODE}}/$tasks_per_node/g' | sed 's/{{HOST_CONFIGURATION}}/${host_configuration}/g' | sed 's/{{FNAME}}/$fname/g' | sed 's/{{PROJECT_ACCOUNT}}/$project_account/g'`
2433          eval line=\"$line\"
2434          echo  "$line"                            >>  $jobfile
2435       done
2436       echo " "                                    >>  $jobfile
2437
2438       echo "set -x"                               >>  $jobfile
2439       echo "${fast_io_catalog}/${sources_for_run_catalog}/batch_scp  $PORTOPT  -d  -w 10  -u $local_username $local_ip  $job_protocol_file_remote  \"$local_jobcatalog\"  ${host_configuration}_${fname}"  >>  $jobfile
2440       echo "%%END%%"                              >>  $jobfile
2441       echo "echo \" *** submitting job for transfering the job protocol file to $local_ip\" "  >>  $jobfile
2442       echo "$submit_command  $scpjob_file"        >>  $jobfile
2443       echo "rm $scpjob_file"                      >>  $jobfile
2444       echo "rm -rf $job_transfer_protocol_file"   >>  $jobfile
2445       echo "set -x"                               >>  $jobfile
2446       echo "     ' exit"                          >>  $jobfile
2447    fi
2448
2449
2450       # ACTIVATE ERROR-TRACEBACK
2451    if [[ $do_trace = true ]]
2452    then
2453       echo  "set -x"                                    >>  $jobfile
2454    else
2455       echo  "set +vx"                                   >>  $jobfile
2456    fi
2457
2458
2459       # INITIALIZE THE ENVIRONMENT AND LOAD MODULES
2460    if [[ "$login_init_cmd" != "" ]]
2461    then
2462       echo  "$login_init_cmd"        >>  $jobfile
2463    fi
2464    if [[ "$module_commands" != "" ]]
2465    then
2466       echo  "$module_commands"     >>  $jobfile
2467    fi
2468
2469
2470       # CREATE TEMPORARY DIRECTORY AND SWITCH TO IT
2471    if [[ $create_remote_batch_job = true ]]
2472    then
2473       echo  "mkdir  $tempdir"           >>  $jobfile
2474       echo  "chmod  go+rx  $tempdir"    >>  $jobfile
2475    else
2476          # DIRECTORY FOR LOCAL BATCH JOBS IS CREATED NOW, DUE TO A
2477          # REQUIREMENT OF THE GRID ENGINE BATCH SYSTEM (WORKING DIR IS GIVEN IN
2478          # BATCH DIRECTIVE -wd AND MUST ALREADY EXIST WHEN THE JOB IS SUBMITTED)
2479       mkdir  $tempdir
2480       chmod  go+rx  $tempdir
2481    fi
2482    echo  "cd  $tempdir"                 >>  $jobfile
2483    echo  "export tempdir=$tempdir"      >>  $jobfile
2484    echo  "cp  ${fast_io_catalog}/${sources_for_run_catalog}/{*,.[!.]*}  ."  >>  $jobfile
2485    echo  "export PATH=.:\$PATH"         >>  $jobfile
2486    echo  "export execute_palmrun=true"  >>  $jobfile
2487
2488
2489       # GET REQUIRED INPUT-FILES BY SCP OR BY SENDING THEM WITH THE JOB AS HERE-DOCUMENT
2490       # PUT THESE FILES INTO THE USER'S RESPECTIVE PERMANENT DIRECTORIES ON THE REMOTE-HOST
2491       # IF THE DIRECTORIES DO NOT EXIST, TRY TO CREATE THEM
2492    if [[ $create_remote_batch_job = true ]]
2493    then
2494       (( i = 0 ))
2495       while (( i < iin ))
2496       do
2497          (( i = i + 1 ))
2498          echo  "[[ ! -d ${pathin[$i]} ]]  &&  mkdir -p  ${pathin[$i]}"  >>  $jobfile
2499          if [[ "${transin[$i]}" = job ]]
2500          then
2501             echo  "cat > ${remotepathin[$i]} <<\"%END%\""    >>  $jobfile
2502             eval cat   ${pathin[$i]}/${frelin[$i]}           >>  $jobfile
2503             echo  " "                                        >>  $jobfile
2504             echo  "%END%"                                    >>  $jobfile
2505          else
2506             echo  "batch_scp $PORTOPT -b -o -g -s -u $local_username $return_address ${remotepathin[$i]} \"${pathin[$i]}\" ${frelin[$i]}" >>  $jobfile
2507          fi
2508
2509             # CHECK, IF FILE COULD BE CREATED
2510          echo  "if [[ \$? = 1 ]]"                    >>  $jobfile
2511          echo  "then"                                >>  $jobfile
2512          echo  "   echo \" \" "                      >>  $jobfile
2513          echo  "   echo \"+++ file ${remotepathin[$i]} could not be created\" "   >>  $jobfile
2514          echo  "   echo \"    please check, if directory exists on $host_configuration!\" "  >>  $jobfile
2515          echo  "   echo \"+++ PALMRUN will not be continued\" "  >>  $jobfile
2516          echo  "   execute_palmrun=false"            >>  $jobfile
2517          echo  "fi"                                  >>  $jobfile
2518       done
2519    fi
2520
2521
2522       # PROVIDE NAME OF THE CURRENT WORKING-DIRECTORY ON THE LOCAL MACHINE (FROM WHERE THE JOB IS
2523       # STARTED) BY SETTING AN ENVIRONMENT-VARIABLE. THIS INFORMATION IS USED IN THE JOB BY PALMRUN
2524       # IN CASE THAT RESTART-RUNS HAVE TO BE GENERATED
2525    echo  "LOCAL_PWD=$working_directory"                >>  $jobfile
2526    echo  "export LOCAL_PWD"                            >>  $jobfile
2527
2528
2529       # PROVIDE THE PATH OF THE LOCAL PALMRUN-SCRIPT FOR THE SAME REASON
2530    echo  "LOCAL_PALMRUN_PATH=${source_path}/../SCRIPTS"   >>  $jobfile
2531    echo  "export LOCAL_PALMRUN_PATH"                      >>  $jobfile
2532
2533
2534       # CALL PALMRUN WITHIN THE JOB
2535       # AS FINAL ACTION, REMOVE THE TEMPORARY DIRECTORY CREATED AT THE BEGINNING OF THE JOB
2536    echo  "set -x"                                              >>  $jobfile
2537    echo  "[[ \$execute_palmrun = true ]]  &&  $palmrun_com"    >>  $jobfile
2538
2539
2540       # TRANSFER JOBFILE TO THE TARGET HOST
2541    if [[ $create_jobfile_only = false ]]
2542    then
2543
2544       if [[ $create_remote_batch_job = true ]]
2545       then
2546
2547          echo " "
2548          echo " *** transfer of job to remote host via scp"
2549          if [[ $do_trace = true ]]
2550          then
2551             echo "     scp $ssh_key $PORTOPT $jobfile ${remote_username}@${remote_ip}:${remote_jobcatalog}/${host_configuration}_${job_id}"
2552          fi
2553          scp $ssh_key $PORTOPT $jobfile ${remote_username}@${remote_ip}:${remote_jobcatalog}/${host_configuration}_${job_id}  >  /dev/null
2554
2555          printf " *** submit the job (output of submit command, e.g. the job-id, may follow)"
2556          if [[ $do_trace = true ]]
2557          then
2558             echo "     cd $remote_jobcatalog; $submit_command ${host_configuration}_${job_id}; rm ${host_configuration}_${job_id}  |  ssh  -q  $ssh_key $SSH_PORTOPT  ${remote_username}@${remote_ip}  2>&1"
2559          fi
2560          echo "cd $remote_jobcatalog; $submit_command ${host_configuration}_${job_id}; rm ${host_configuration}_${job_id}"  |  ssh  -q  $ssh_key $SSH_PORTOPT  ${remote_username}@${remote_ip}  2>&1
2561
2562       elif [[ $create_batch_job = true ]]
2563       then
2564
2565          eval  local_jobcatalog=$local_jobcatalog
2566          cp  $jobfile  ${local_jobcatalog}/${host_configuration}_${job_id}
2567          cd $local_jobcatalog
2568          echo " "
2569          echo " *** submit the job"
2570          if [[ $do_trace = true ]]
2571          then
2572             echo "$submit_command ${host_configuration}_${job_id}"
2573          fi
2574          $submit_command ${host_configuration}_${job_id}
2575          rm ${host_configuration}_${job_id}
2576          cd -  > /dev/null
2577
2578       fi
2579
2580       rm -rf  $jobfile
2581
2582    else
2583
2584       printf "\n *** jobfile created under name \"$jobfile\" "
2585       printf "\n     no batch-job has been sent!"
2586
2587    fi
2588
2589 fi  # END OF REMOTE-PART
Note: See TracBrowser for help on using the repository browser.