source: palm/trunk/SCRIPTS/palmrun @ 2551

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

TEMPDIR added as replacement string to be used in batch directives

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