source: palm/trunk/SCRIPTS/palmrun @ 2602

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

small changes concerning r2599, cycle number are now three digits wide

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