source: palm/trunk/SCRIPTS/palmrun @ 2605

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

input files are not sent with remote batch job file any more

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