source: palm/trunk/SCRIPTS/palmrun @ 2501

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

default value for number of cores (option -X) set to 1, bugfix for mechanism which overwrites configuration file settings with values provided by palmrun options

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