submitjob.sh 6.05 KB
Newer Older
1 2 3 4 5 6 7
#!/bin/bash 


#-------------------------------------------------------------------------------
#  namelist of the experiment
#-------------------------------------------------------------------------------

8 9 10 11
. ./common_definitions.sh
. ./namelist_period.sh
. ./namelist_exp.sh
. ./${COMPUTER}.env
12 13


14
[ ! -d ${JOBDIR_ROOT} ] && mkdir -p ${JOBDIR_ROOT}  # for the first submitjob.sh call
15

16 17 18
cd ${JOBDIR_ROOT} 
ls ${jobname}  > /dev/null  2>&1 
if [ "$?" -eq "0" ] ; then
19 20
   printf "\n\n\n\n  Un fichier ${jobname} existe deja  dans  ${JOBDIR_ROOT} \n             => exit."
   printf "\n\n  Si la simu n'est pas en attente ou en cours d'execution, Nettoyer puis relancer ./submitjob.sh\n\n\n\n"; exit
21 22
fi
cd -
23

24 25 26
#-------------------------------------------------------------------------------
# calendar computations (to check dates consistency)
#-------------------------------------------------------------------------------
27 28 29 30 31 32 33 34 35 36 37
if ${USE_CPL} ; then
  if [ $(( ${CPL_FREQ} % ${TSP_ATM} )) -ne 0 ] || \
     [ $(( ${CPL_FREQ} % ${TSP_OCE} )) -ne 0 ] || \
     [ $(( ${CPL_FREQ} % ${TSP_ICE} )) -ne 0 ] ; then
     printf "\n\n Problem of consistency between Coupling Frequency and Time Step, we stop...\n\n" && exit 1
  fi
fi

. ./caltools.sh

#-------------------------------------------------------------------------------
38
# save ascii dir
39 40
#-------------------------------------------------------------------------------

41 42
cd ${JOBDIR_ROOT} 

43
if ${MODE_TEST} ; then 
44 45 46
   ! [ -d ${ASCII_DIR_IMG}/compile ] && mkdir -p ${ASCII_DIR_IMG}/compile
   rsync -a ${SCRIPTDIR} ${PARAMDIR} ${ASCII_DIR_IMG}
#  info :  ${ASCII_DIR_IMG} renamed ${JOBDIR}/${ASCII_DIR_IMG_ROOT} in the beginning of the job.base.sh file
47
else
48
   if [ "${DATE_BEGIN_EXP}" == "${DATE_BEGIN_JOB}" ]; then
49 50 51 52
      rm -rf ${ASCII_DIR_IMG}
      ! [ -d ${ASCII_DIR_IMG}/compile ] && mkdir -p ${ASCII_DIR_IMG}/compile
      rsync -a ${SCRIPTDIR} ${PARAMDIR} ${ASCII_DIR_IMG}
   else
53 54
      test_diff2=`diff -r -x namelist_period.sh -x *.swp ${SCRIPTDIR} ${JOBDIR_ROOT}/${ASCII_DIR_IMG}/scripts`
      test_diff2="${test_diff2}`diff -r -x *.swp ${PARAMDIR} ${JOBDIR_ROOT}/${ASCII_DIR_IMG}/param_inputs`"
55
      test_diff2="${test_diff2}`diff -r -x *.swp -x croco_compile_listing.txt ${COMPDIR}/croco ${JOBDIR_ROOT}/${ASCII_DIR_IMG}/compile/${MODEL_OCE}`"
56
      if [ "${test_diff2}" != "" ]; then
57 58 59 60
         printf "\n\n\n\n"
         echo "                      STOP! "
         printf "\n\n\n\n"
         echo "######################################################################"
61
         echo " Differences with last job :"
62
         echo "######################################################################"
63
         echo "${test_diff2}"         
64 65
         echo "######################################################################"
         printf "\n\n\n\n"
66
         if ( [ "$#" -ge "1" ] && [ "$1" == "forced" ] ) ; then
67 68 69 70 71 72 73
            printf "\n\n\n\n"
            echo "                      FORCED => continue... ! "
            printf "\n\n\n\n"
            printf "\n\n\n\n changes saved in ${JOBDIR_ROOT}/${ASCII_DIR_IMG} directory\n\n"
            rm -f ${ASCII_DIR_IMG}
            ! [ -d ${ASCII_DIR_IMG}/compile ] && mkdir -p ${ASCII_DIR_IMG}/compile
            rsync -a ${SCRIPTDIR} ${PARAMDIR} ${ASCII_DIR_IMG}
74
         else
75
            printf "\n  changes since last job =>  we stop...\n\n"
76 77 78
            printf "    If you want to continue, relaunch with \"submitjob.sh forced\" \n" 
            printf "    If you want to restart from scratch, delete the ../jobs/${ASCII_DIR_IMG} directory & relaunch with \"submitjob.sh\" \n\n\n\n" && exit 1
         fi
79
      fi
80
   fi
81
fi
82 83 84

cd -

85
#-------------------------------------------------------------------------------
86
# create job 
87
#-------------------------------------------------------------------------------
88 89
if ${USE_XIOS} ; then export NXIOS2=${NXIOS}; else export NXIOS2=0; fi

90
sed -e "s/<exp>/${ROOT_NAME_1}/g" \
91
    -e "s/<exp_lst>/${listing_root_name}/" \
92
    -e "s/<mpi_task>/$(( ${NPROC_X} * ${NPROC_Y} * ${CPU_PER_TASK} + ${NXIOS2} ))/" \
93
    -e "s/<cpu_per_task>/${CPU_PER_TASK}/" \
94 95 96 97 98 99 100 101 102
    -e "s/<max_cpu_time>/${MAX_CPU_TIME}/" \
    ./${COMPUTER}.header > HEADER_tmp1

if [ ${COMPUTER} == "JEANZAY" ] ; then
   sed -e "s/<qos>/${QOS}/" \
    HEADER_tmp1 > HEADER_tmp
fi

    cat HEADER_tmp ./${COMPUTER}.module ./common_definitions.sh ./namelist_exp.sh ./namelist_period.sh ./${COMPUTER}.env job.base.sh > ${JOBDIR_ROOT}/${jobname}
103 104
    \rm HEADER_tmp

105
chmod 755 ${JOBDIR_ROOT}/${jobname}
106
   
107 108 109 110 111 112 113 114 115 116 117 118



#-------------------------------------------------------------------------------
# compile model? 
#-------------------------------------------------------------------------------


printf "\n\n ============================== Compiling ... \n"
${USE_OCE} && ./compile_oce.sh
printf " ============================== Compiling end \n\n"

119 120 121 122 123 124
# sav model dir 
printf "rsync -a ${COMPDIR}/croco ${COMPDIR}/xios ${JOBDIR_ROOT}/${ASCII_DIR_IMG}/compile\n\n"
        rsync -a ${COMPDIR}/croco ${COMPDIR}/xios ${JOBDIR_ROOT}/${ASCII_DIR_IMG}/compile

if ! [ -f ${COMPDIR}/croco/${MODEL_OCE}_${COMPUTER}.exe ] ; then
   printf "\n\n\n\n  ${MODEL_OCE}_${COMPUTER}.exe not found   => exit. \n\n"; exit
125 126 127 128 129 130 131 132 133
fi



#-------------------------------------------------------------------------------
# submit job
#-------------------------------------------------------------------------------
cd ${JOBDIR_ROOT}

134 135 136 137 138
printf "\n  HOSTNAME: `hostname`\n     =>    COMPUTER: ${COMPUTER}\n"  
printf "\n  MODEL_OCE: ${MODEL_OCE}\n"  
printf "\n  CONFIG: ${CONFIG}\n"  
printf   "  EXP_NAME: ${EXP_NAME}\n"  
printf "\n  jobname: ${jobname}\n\n"  
139
   
140 141 142 143 144 145 146
 printf "  ROOT_NAME_1: ${ROOT_NAME_1}\n"  
 printf "  ROOT_NAME_2: ${ROOT_NAME_2}\n"  
 printf "  ROOT_NAME_3: ${ROOT_NAME_3}\n"  
 printf "  EXEDIR: ${EXEDIR}\n"  
 printf "  OUTDIR: ${OUTDIR}\n"  
 printf "  RSTDIR_OUT: ${RSTDIR_OUT}\n"  
 printf "  JOBDIR: ${JOBDIR}\n\n"  
147 148

   
149 150
if ${TEST_SCRIPT} ; then
   printf "\n\n\n\n  TEST_SCRIPT=${TEST_SCRIPT}  Mode script debug => no submission\n\n\n\n"
151 152 153
else
   ${QSUB} ${jobname}
   if  ${MODE_TEST} ; then
154
      printf "\n\n\n\n  MODE_TEST=${MODE_TEST}   (${TEST_NAME})  => run just one job \n\n\n\n"
155
   fi
156
fi
157