source: palm/trunk/SCRIPTS/palmrun @ 2384

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

small changes and bugfixes for new palm-scripts

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