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

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

PEM:

  • Correct management of H2O ice tendency in 1D when there is not enough ice anymore.
  • Clean initialization of allocatable module arrays (especially needed when no slope)
  • One more renaming for consistency + few small updates thoughout the code.

JBC

  • Property svn:executable set to *
File size: 5.8 KB
RevLine 
[3349]1#!/bin/bash
2########################################################################
[4072]3#### Workflow script for a chained simulation of PEM and PCM runs  #####
[3349]4########################################################################
5# This script can take an argument:
[3938]6#     1) None: to start a simulation from scratch;
[4072]7#     2) 're': to resume a simulation from a starting point (interactive prompt).
[3349]8########################################################################
[3579]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
[3349]11
12
13########################################################################
14# Modify here the parameters for the simulation
15###############################################
[4065]16# Set the number of years to be simulated, either Planetary or Earth years (> 0):
17n_planetary_years=100.
[3498]18#n_earth_years=300.
[3349]19
[3958]20# Set the number of initial PCM years (>= 2):
[4072]21n_pcm_runs_ini=3
[3349]22
[3958]23# Set the number of PCM years between each PEM run (>= 2):
[4072]24n_pcm_runs=2
[3391]25
[4072]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
[3349]28########################################################################
29
30
31dir=`pwd`
32machine=`hostname`
33user=`whoami`
[4072]34if [ ! -f "pem_workflow_lib.sh" ]; then
35    echo "Error: file \"pem_workflow_lib.sh\" does not exist in $dir!"
[3349]36    echo "It can be found in the PEM deftank."
37    exit 1
38fi
39
[4072]40source pem_workflow_lib.sh
41export exec_mode
[3349]42
[3355]43if [ $# -eq 0 ]; then
44    # Starting from scratch
[4072]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."
[3349]49    date
[4072]50    check_workflow
51    ini_workflow
52    submit_cycle $exec_mode $n_pcm_runs_ini
[3355]53
[3349]54else
[3355]55    # Starting a new cycle
56    if [ $1 = "new" ]; then
[4072]57        exec >> pem_workflow.log 2>&1
[3355]58        echo
[4072]59        echo "This is a new cycle of the PEM worflow."
[3349]60        date
[4072]61        if [ $exec_mode -ne 0 ]; then
62            detect_scheduler
[3639]63            if command -v squeue &> /dev/null; then
64                unset SLURM_MEM_PER_CPU SLURM_MEM_PER_GPU SLURM_MEM_PER_NODE
65            fi
[3419]66        fi
[4072]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
[3355]69
[4074]70    # Starting a resumption of the workflow
[3355]71    elif [ $1 = "re" ]; then
[4072]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
[3355]76        fi
[4072]77        echo "The resumption is initialized with a previous successful run to be specified."
[3355]78        while true; do
[4072]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
[3355]82                break
83            else
84                echo "Invalid input. Please enter 'PCM' or 'PEM'."
85            fi
86        done
[4072]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
[3355]88        while true; do
[4072]89            if [ $run_resume = "PCM" ]; then
[3355]90                echo "What is the number of the PCM run?"
[4072]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
[3355]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?"
[4072]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
[3355]103                    break
104                else
105                    echo "Invalid input. Please enter a valid PEM run number."
106                fi
107            fi
108        done
[4072]109        exec >> pem_workflow.log 2>&1
[3355]110        echo
[4072]111        echo "This is a resumption for the PEM workflow from the run \"$run_resume $i_resume\"."
[3355]112        date
[4072]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."
[3386]117        fi
[4072]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."
[3386]120        fi
[4072]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."
[3386]123        fi
[4072]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
[3419]127        fi
[4072]128        if [ $run_resume = "PCM" ]; then
129            resume_from_pcm_run $exec_mode
[3355]130        else
[4072]131            resume_from_pem_run $exec_mode
[3355]132        fi
[3363]133
[4074]134    # Continuing a PEM run
135    # CANNOT BE DONE FOR NOW BECAUSE THE PEM DOES NOT SAVE ITS STATE TO BE ABLE TO RECOVER
136    #elif [ $1 = "cont" ]; then
137    #    exec >> pem_workflow.log 2>&1
138    #    echo
139    #    echo "This is a continuation of the previous PEM run."
140    #    date
141    #    submit_pem_phase $exec_mode
[3363]142
143    # Default case: error
[3349]144    else
[4072]145        echo "Error: given argument '$1' for the PEM workflow script is unknown!"
146        abort_workflow
[3349]147    fi
148fi
Note: See TracBrowser for help on using the repository browser.