source: trunk/LMDZ.COMMON/libf/evolution/deftank/launchPEM.sh @ 3792

Last change on this file since 3792 was 3639, checked in by jbclement, 4 months ago

PEM:
Unset inherited SLURM memory env variables to prevent conflicts in chained job re-launch (it happenned on MCMeSU).
JBC

  • Property svn:executable set to *
File size: 5.7 KB
Line 
1#!/bin/bash
2########################################################################
3#### Launching script for a chained simulation of PEM and PCM runs  ####
4########################################################################
5# This script can take an argument:
6#   - If there is no argument, then the script initiates a PEM simulation from scratch.
7#   - If the argument is 're', then the script relaunches an existing PEM simulation.
8#     It will ask for parameters to know the starting point that you want to.
9########################################################################
10set -e
11trap 'echo -e "\033[31mError: an issue occurred in the script on line $LINENO! Please review the command and try again.\033[0m"' ERR
12
13
14########################################################################
15# Modify here the parameters for the simulation
16###############################################
17# Set the number of years to be simulated, either Martian or Earth years:
18n_mars_years=100.
19#n_earth_years=300.
20
21# Set the number of initial PCM runs (>= 2):
22nPCM_ini=3
23
24# Set the number of PCM runs between each PEM run (>= 2):
25nPCM=2
26
27# Set the counting method for the number of years to be simulated (0 = "only PEM runs count"; any other values = "PCM runs are taken into account"):
28counting=0
29
30# Set the launching 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:
31mode=1
32########################################################################
33
34
35dir=`pwd`
36machine=`hostname`
37user=`whoami`
38if [ ! -f "lib_launchPEM.sh" ]; then
39    echo "Error: file \"lib_launchPEM.sh\" does not exist in $dir!"
40    echo "It can be found in the PEM deftank."
41    exit 1
42fi
43
44source lib_launchPEM.sh
45export counting mode
46
47if [ $# -eq 0 ]; then
48    # Starting from scratch
49    echo "The launching script is starting!"
50    echo "The output file is \"log_launchPEM.txt\"."
51    exec > log_launchPEM.txt 2>&1
52    echo "Beginning of the launching script for the PEM simulation."
53    date
54    checklaunch
55    initlaunch
56    cyclelaunch $mode $counting $nPCM_ini
57
58else
59    # Starting a new cycle
60    if [ $1 = "new" ]; then
61        exec >> log_launchPEM.txt 2>&1
62        echo
63        echo "This is a new cycle for the PEM simulation."
64        date
65        if [ $mode -ne 0 ]; then
66            job_scheduler
67            if command -v squeue &> /dev/null; then
68                unset SLURM_MEM_PER_CPU SLURM_MEM_PER_GPU SLURM_MEM_PER_NODE
69            fi
70        fi
71        read i_myear n_myear convert_years iPCM iPEM nPCM nPCM_ini < info_PEM.txt
72        cyclelaunch $mode $counting $nPCM
73
74    # Starting a relaunch
75    elif [ $1 = "re" ]; then
76        if [ ! -f "info_PEM.txt" ]; then
77            echo "Error: file \"info_PEM.txt\" does not exist in $dir!"
78            echo "It is necessary to relaunch a PEM simulation."
79            errlaunch
80        fi
81        echo "The relaunch is initialized with a specific previous successful run."
82        while true; do
83            echo "Do you want to relaunch from a 'PCM' or 'PEM' run?"
84            read relaunch
85            if [ $relaunch = "PCM" ] || [ $relaunch = "PEM" ]; then
86                break
87            else
88                echo "Invalid input. Please enter 'PCM' or 'PEM'."
89            fi
90        done
91        read i_myear n_myear_old convert_years iPCM iPEM nPCM_old nPCM_ini_old < info_PEM.txt
92        while true; do
93            if [ $relaunch = "PCM" ]; then
94                echo "What is the number of the PCM run?"
95                echo "It should be between 1 and $(( $((iPCM - 1)) > 1 ? $((iPCM - 1)) : 1 ))."
96                read irelaunch
97                if [ 1 -le $irelaunch ] && [ $irelaunch -le $(( $((iPCM - 1)) > 1 ? $((iPCM - 1)) : 1 )) ]; then
98                    break
99                else
100                    echo "Invalid input. Please enter a valid PCM run number."
101                fi
102            else
103                echo "What is the number of the PEM run?"
104                echo "It should be between 1 and $(( $((iPEM - 1)) > 1 ? $((iPEM - 1)) : 1 ))."
105                read irelaunch
106                if [ 1 -le $irelaunch ] && [ $irelaunch -le $(( $((iPEM - 1)) > 1 ? $((iPEM - 1)) : 1 )) ]; then
107                    break
108                else
109                    echo "Invalid input. Please enter a valid PEM run number."
110                fi
111            fi
112        done
113        exec >> log_launchPEM.txt 2>&1
114        echo
115        echo "This is a relaunch for the PEM simulation from the run \"$relaunch $irelaunch\"."
116        date
117        checklaunch
118        convertyears
119        if [ $nPCM_ini -ne $nPCM_ini_old ]; then
120            echo "The number of initial PCM runs has been modified from $nPCM_ini_old to $nPCM_ini."
121        fi
122        if [ $nPCM -ne $nPCM_old ]; then
123            echo "The number of PCM runs between each PEM run has been modified from $nPCM_old to $nPCM."
124        fi
125        if [ "$(echo "$n_myear != $n_myear_old" | bc)" -eq 1 ]; then
126            echo "The number of initial PCM runs has been modified from $n_myear_old to $n_myear."
127        fi
128        sed -i "1s/.*/$i_myear $n_myear $convert_years $iPCM $iPEM $nPCM $nPCM_ini/" info_PEM.txt
129        if [ -f "kill_launchPEM.sh" ]; then
130            ./kill_launchPEM.sh
131        fi
132        if [ $relaunch = "PCM" ]; then
133            relaunchPCM $mode $counting
134        else
135            relaunchPEM $mode $counting
136        fi
137
138    # Continuing the PEM run
139    elif [ $1 = "cont" ]; then
140        exec >> log_launchPEM.txt 2>&1
141        echo
142        echo "This is a continuation of the previous PEM run."
143        date
144        submitPEM $mode
145
146    # Default case: error
147    else
148        echo "Error: given argument '$1' for the launching script is unknown!"
149        errlaunch
150    fi
151fi
Note: See TracBrowser for help on using the repository browser.