source: palm/trunk/SCRIPTS/palmrun @ 2499

Last change on this file since 2499 was 2499, checked in by kanani, 6 years ago

minor bugfixes

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