source: trunk/LMDZ.COMMON/libf/evolution/deftank/pem_workflow.sh @ 4072

Last change on this file since 4072 was 4072, checked in by jbclement, 2 weeks ago

PEM:
Modify the PEM semantics to standardize file/functions/variable names and avoid ambiguity: workflow = repetion of cycles; cycle = PCM phase + PEM phase; PCM phase = 2+ PCM runs of 1 year each, PEM phase = 1 PEM run of 'x' years.
JBC

  • Property svn:executable set to *
File size: 5.7 KB
Line 
1#!/bin/bash
2########################################################################
3#### Workflow script for a chained simulation of PEM and PCM runs  #####
4########################################################################
5# This script can take an argument:
6#     1) None: to start a simulation from scratch;
7#     2) 're': to resume a simulation from a starting point (interactive prompt).
8########################################################################
9set -e
10trap 'echo -e "\033[31mError: an issue occurred in the script on line $LINENO! Please review the command and try again.\033[0m"' ERR
11
12
13########################################################################
14# Modify here the parameters for the simulation
15###############################################
16# Set the number of years to be simulated, either Planetary or Earth years (> 0):
17n_planetary_years=100.
18#n_earth_years=300.
19
20# Set the number of initial PCM years (>= 2):
21n_pcm_runs_ini=3
22
23# Set the number of PCM years between each PEM run (>= 2):
24n_pcm_runs=2
25
26# Set the execution mode (0 = "processing scripts"; any other values = "submitting jobs"). The former option is usually used to process the script on a local machine while the latter is used to submit jobs on a supercomputer with SLURM or PBS/TORQUE:
27exec_mode=1
28########################################################################
29
30
31dir=`pwd`
32machine=`hostname`
33user=`whoami`
34if [ ! -f "pem_workflow_lib.sh" ]; then
35    echo "Error: file \"pem_workflow_lib.sh\" does not exist in $dir!"
36    echo "It can be found in the PEM deftank."
37    exit 1
38fi
39
40source pem_workflow_lib.sh
41export exec_mode
42
43if [ $# -eq 0 ]; then
44    # Starting from scratch
45    echo "The PEM workflow is starting!"
46    echo "The output file is \"pem_workflow.log\"."
47    exec > pem_workflow.log 2>&1
48    echo "Beginning of log file for the PEM workflow."
49    date
50    check_workflow
51    ini_workflow
52    submit_cycle $exec_mode $n_pcm_runs_ini
53
54else
55    # Starting a new cycle
56    if [ $1 = "new" ]; then
57        exec >> pem_workflow.log 2>&1
58        echo
59        echo "This is a new cycle of the PEM worflow."
60        date
61        if [ $exec_mode -ne 0 ]; then
62            detect_scheduler
63            if command -v squeue &> /dev/null; then
64                unset SLURM_MEM_PER_CPU SLURM_MEM_PER_GPU SLURM_MEM_PER_NODE
65            fi
66        fi
67        read n_yr_sim ntot_yr_sim r_plnt2earth_yr i_pcm_run i_pem_run n_pcm_runs n_pcm_runs_ini < pem_workflow.sts
68        submit_cycle $exec_mode $n_pcm_runs
69
70    # Starting a resume
71    elif [ $1 = "re" ]; then
72        if [ ! -f "pem_workflow.sts" ]; then
73            echo "Error: file \"pem_workflow.sts\" does not exist in $dir!"
74            echo "It is necessary to resume the PEM workflow."
75            abort_workflow
76        fi
77        echo "The resumption is initialized with a previous successful run to be specified."
78        while true; do
79            echo "Do you want to resume from a 'PCM' or 'PEM' run?"
80            read run_resume
81            if [ $run_resume = "PCM" ] || [ $run_resume = "PEM" ]; then
82                break
83            else
84                echo "Invalid input. Please enter 'PCM' or 'PEM'."
85            fi
86        done
87        read n_yr_sim n_year_old r_plnt2earth_yr i_pcm_run i_pem_run nPCM_old nPCM_ini_old < pem_workflow.sts
88        while true; do
89            if [ $run_resume = "PCM" ]; then
90                echo "What is the number of the PCM run?"
91                echo "It should be between 1 and $(( $((i_pcm_run - 1)) > 1 ? $((i_pcm_run - 1)) : 1 ))."
92                read i_resume
93                if [ 1 -le $i_resume ] && [ $i_resume -le $(( $((i_pcm_run - 1)) > 1 ? $((i_pcm_run - 1)) : 1 )) ]; then
94                    break
95                else
96                    echo "Invalid input. Please enter a valid PCM run number."
97                fi
98            else
99                echo "What is the number of the PEM run?"
100                echo "It should be between 1 and $(( $((i_pem_run - 1)) > 1 ? $((i_pem_run - 1)) : 1 ))."
101                read i_resume
102                if [ 1 -le $i_resume ] && [ $i_resume -le $(( $((i_pem_run - 1)) > 1 ? $((i_pem_run - 1)) : 1 )) ]; then
103                    break
104                else
105                    echo "Invalid input. Please enter a valid PEM run number."
106                fi
107            fi
108        done
109        exec >> pem_workflow.log 2>&1
110        echo
111        echo "This is a resumption for the PEM workflow from the run \"$run_resume $i_resume\"."
112        date
113        check_workflow
114        convert_earth2plnt_years
115        if [ $n_pcm_runs_ini -ne $nPCM_ini_old ]; then
116            echo "The number of initial PCM years has been modified from $nPCM_ini_old to $n_pcm_runs_ini."
117        fi
118        if [ $n_pcm_runs -ne $nPCM_old ]; then
119            echo "The number of PCM years between each PEM run has been modified from $nPCM_old to $n_pcm_runs."
120        fi
121        if [ "$(echo "$ntot_yr_sim != $n_year_old" | bc)" -eq 1 ]; then
122            echo "The number of initial PCM years has been modified from $n_year_old to $ntot_yr_sim."
123        fi
124        sed -i "1s/.*/$n_yr_sim $ntot_yr_sim $r_plnt2earth_yr $i_pcm_run $i_pem_run $n_pcm_runs $n_pcm_runs_ini/" pem_workflow.sts
125        if [ -f "kill_pem_workflow.sh" ]; then
126            ./kill_pem_workflow.sh
127        fi
128        if [ $run_resume = "PCM" ]; then
129            resume_from_pcm_run $exec_mode
130        else
131            resume_from_pem_run $exec_mode
132        fi
133
134    # Continuing the PEM run
135    elif [ $1 = "cont" ]; then
136        exec >> pem_workflow.log 2>&1
137        echo
138        echo "This is a continuation of the previous PEM run."
139        date
140        submit_pem_phase $exec_mode
141
142    # Default case: error
143    else
144        echo "Error: given argument '$1' for the PEM workflow script is unknown!"
145        abort_workflow
146    fi
147fi
Note: See TracBrowser for help on using the repository browser.