source: palm/trunk/SCRIPTS/palmrun @ 2422

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

new palm-scripts set to version number 1.0, further check for consistent restart settings

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