source: palm/trunk/SCRIPTS/palmrun @ 2506

Last change on this file since 2506 was 2506, checked in by raasch, 6 years ago

new options -V and -W plus other small changes in PALM scripts

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