source: palm/trunk/SCRIPTS/palmrun @ 2420

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

PALM_BIN setting removed from new scripts

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