[1708] | 1 | import os |
---|
| 2 | import sys |
---|
[1734] | 3 | import subprocess |
---|
[1738] | 4 | import socket |
---|
| 5 | import os.path |
---|
| 6 | from os import path |
---|
[1708] | 7 | |
---|
| 8 | |
---|
[1738] | 9 | from default_param import * |
---|
| 10 | from user_param import * |
---|
| 11 | # load default_param first, variables defines in user_param will overwrite the default value |
---|
[1708] | 12 | |
---|
[1734] | 13 | |
---|
[1738] | 14 | |
---|
[1734] | 15 | def OSinfo(runthis): |
---|
[1737] | 16 | red = lambda text: '\033[0;31m' + text + '\033[0m' |
---|
[1734] | 17 | osstdout = subprocess.Popen(runthis, shell=True, stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, close_fds=True) |
---|
| 18 | theInfo = osstdout.communicate()[0].strip() |
---|
| 19 | if osstdout.returncode!=0: |
---|
[1737] | 20 | print(red(runthis+" FAILED")) |
---|
[1734] | 21 | print >> sys.stderr, osstdout.returncode |
---|
| 22 | sys.exit() |
---|
[1737] | 23 | # else: |
---|
| 24 | # print(runthis+" OK") |
---|
[1734] | 25 | |
---|
| 26 | |
---|
[1738] | 27 | def write_jz_job(configName, nbproc=8): |
---|
| 28 | red = lambda text: '\033[0;31m' + text + '\033[0m' |
---|
| 29 | f=open("jz_job_"+configName+".sh", "w") |
---|
| 30 | f.write("#!/bin/bash\n") |
---|
| 31 | f.write("#SBATCH --ntasks="+repr(nbproc)+" # Nombre total de processus MPI\n") |
---|
| 32 | f.write("#SBATCH --ntasks-per-node=16\n") |
---|
| 33 | f.write("#SBATCH --hint=nomultithread\n") |
---|
| 34 | f.write("#SBATCH -t 00:10:00 # Temps elapsed maximum d'execution\n") |
---|
| 35 | f.write("#SBATCH -o single_config.out # Nom du fichier de sortie\n") |
---|
| 36 | f.write("#SBATCH -e single_config.err # Nom du fichier d'erreur\n") |
---|
| 37 | f.write("#SBATCH --account=psl@cpu\n") |
---|
| 38 | f.write("cd ${SLURM_SUBMIT_DIR}\n") |
---|
| 39 | f.write("module purge\n") |
---|
| 40 | f.write("module load intel-all/19.0.4\n") |
---|
| 41 | f.write("module load netcdf/4.7.0/intel-19.0.4-mpi\n") |
---|
| 42 | f.write("module load netcdf-cxx/4.2/intel-19.0.4-mpi\n") |
---|
| 43 | f.write("module load netcdf-fortran/4.4.5/intel-19.0.4-mpi\n") |
---|
| 44 | f.write("module load gcc/6.5.0/gcc-4.8.5\n") |
---|
| 45 | f.write("module load cmake\n") |
---|
| 46 | f.write("module load cdo\n") |
---|
| 47 | f.write("ulimit -c 0\n") |
---|
| 48 | f.write("export machine_name=jeanzay\n") |
---|
| 49 | f.write("cp ../setup.py ./\n") |
---|
| 50 | f.write("cp ../run_sub_test.sh ./\n") |
---|
| 51 | f.write("mv user_params.def user_params.def_bkp\n") |
---|
| 52 | f.write("cp "+configName+"/setup/user_param.py user_params.def\n") |
---|
| 53 | f.write("python setup.py\n") |
---|
| 54 | f.write("cmake .\n") |
---|
| 55 | f.write("ctest -V #enable all output\n") |
---|
| 56 | f.write("rm -f setup.py run_sub_test.sh\n") |
---|
| 57 | f.write("rm -f run_test_*.py\n") |
---|
| 58 | f.write("rm -f user_param.py.*\n") |
---|
| 59 | f.write("rm -f user_param.def\n") |
---|
| 60 | f.write("mv user_params.def_bkp user_params.def\n") |
---|
| 61 | f.write("\n") |
---|
| 62 | f.close |
---|
| 63 | |
---|
| 64 | |
---|
| 65 | |
---|
| 66 | def write_irene_job(configName, nbproc=8): |
---|
| 67 | red = lambda text: '\033[0;31m' + text + '\033[0m' |
---|
| 68 | f=open("irene_job_"+configName+".sh", "w") |
---|
| 69 | f.write("#!/bin/bash\n") |
---|
| 70 | f.write("#MSUB -r XIOS\n") |
---|
| 71 | f.write("#MSUB -o client_output.out # standard output\n") |
---|
| 72 | f.write("#MSUB -e client_error.err #error output\n") |
---|
| 73 | f.write("#MSUB -eo\n") |
---|
| 74 | f.write("#MSUB -c 1\n") |
---|
| 75 | f.write("#MSUB -n "+ repr(nbproc) + " # Number of MPI tasks (SPMD case) or cores (MPMD case)\n") |
---|
| 76 | f.write("#MSUB -X \n") |
---|
| 77 | f.write("#MSUB -x \n") |
---|
| 78 | f.write("#MSUB -T 600 # Wall clock limit (seconds)\n") |
---|
| 79 | f.write("#MSUB -q skylake # thin nodes\n") |
---|
| 80 | f.write("#MSUB -A devcmip6\n") |
---|
| 81 | f.write("#MSUB -Q test\n") |
---|
| 82 | f.write("#MSUB -m work\n") |
---|
| 83 | f.write("cd $BRIDGE_MSUB_PWD\n") |
---|
| 84 | f.write("module unload netcdf-c netcdf-fortran hdf5 flavor perl hdf5 boost blitz mpi gnu\n") |
---|
| 85 | f.write("module load gnu\n") |
---|
| 86 | f.write("module load mpi/intelmpi/2017.0.6.256\n") |
---|
| 87 | f.write("module load flavor/buildcompiler/intel/17\n") |
---|
| 88 | f.write("module load flavor/hdf5/parallel\n") |
---|
| 89 | f.write("module load netcdf-fortran/4.4.4\n") |
---|
| 90 | f.write("module load hdf5/1.8.20\n") |
---|
| 91 | f.write("module load boost\n") |
---|
| 92 | f.write("module load blitz\n") |
---|
| 93 | f.write("module load feature/bridge/heterogenous_mpmd\n") |
---|
| 94 | f.write("module load nco\n") |
---|
| 95 | f.write("module load cdo\n") |
---|
| 96 | f.write("export KMP_STACKSIZE=3g\n") |
---|
| 97 | f.write("export KMP_LIBRARY=turnaround\n") |
---|
| 98 | f.write("export MKL_SERIAL=YES\n") |
---|
| 99 | f.write("export OMP_NUM_THREADS=${BRIDGE_MSUB_NCORE}\n") |
---|
| 100 | f.write("set -x \n") |
---|
| 101 | f.write("export machine_name=irene\n") |
---|
| 102 | f.write("cp ../setup.py ./\n") |
---|
| 103 | f.write("cp ../run_sub_test.sh ./\n") |
---|
| 104 | f.write("mv user_params.def user_params.def_bkp\n") |
---|
| 105 | f.write("cp "+configName+"/setup/user_param.py user_params.def\n") |
---|
| 106 | f.write("python setup.py\n") |
---|
| 107 | f.write("cmake .\n") |
---|
| 108 | f.write("ctest -V #enable all output\n") |
---|
| 109 | f.write("rm -f setup.py run_sub_test.sh\n") |
---|
| 110 | f.write("rm -f run_test_*.py\n") |
---|
| 111 | f.write("rm -f user_param.py.*\n") |
---|
| 112 | f.write("rm -f user_param.def\n") |
---|
| 113 | f.write("mv user_params.def_bkp user_params.def\n") |
---|
| 114 | f.write("\n") |
---|
| 115 | f.close |
---|
| 116 | |
---|
| 117 | |
---|
| 118 | |
---|
[1708] | 119 | def main(): |
---|
[1720] | 120 | |
---|
| 121 | black = lambda text: '\033[0;30m' + text + '\033[0m' |
---|
| 122 | red = lambda text: '\033[0;31m' + text + '\033[0m' |
---|
| 123 | green = lambda text: '\033[0;32m' + text + '\033[0m' |
---|
| 124 | yellow = lambda text: '\033[0;33m' + text + '\033[0m' |
---|
| 125 | blue = lambda text: '\033[0;34m' + text + '\033[0m' |
---|
| 126 | magenta = lambda text: '\033[0;35m' + text + '\033[0m' |
---|
| 127 | cyan = lambda text: '\033[0;36m' + text + '\033[0m' |
---|
[1721] | 128 | lgray = lambda text: '\033[0;37m' + text + '\033[0m' |
---|
| 129 | dgray = lambda text: '\033[1;30m' + text + '\033[0m' |
---|
| 130 | lred = lambda text: '\033[1;32m' + text + '\033[0m' |
---|
| 131 | lgreen = lambda text: '\033[1;32m' + text + '\033[0m' |
---|
| 132 | lyellow = lambda text: '\033[1;33m' + text + '\033[0m' |
---|
| 133 | lblue = lambda text: '\033[1;34m' + text + '\033[0m' |
---|
| 134 | lpurple = lambda text: '\033[1;35m' + text + '\033[0m' |
---|
| 135 | lcyan = lambda text: '\033[1;36m' + text + '\033[0m' |
---|
| 136 | white = lambda text: '\033[1;37m' + text + '\033[0m' |
---|
[1708] | 137 | |
---|
[1712] | 138 | configNamePattern=[0]*7 |
---|
[1708] | 139 | |
---|
| 140 | f=open("user_param.py", "r") |
---|
| 141 | for line in f: |
---|
| 142 | line = line.strip() |
---|
| 143 | if line.startswith("UsingServer2"): |
---|
| 144 | configNamePattern[0] = '_UsingSrv2=' + UsingServer2 |
---|
| 145 | elif line.startswith("RatioServer2"): |
---|
| 146 | configNamePattern[1] = '_RatioSrv2=' + repr(RatioServer2) |
---|
| 147 | elif line.startswith("NumberPoolsServer2"): |
---|
| 148 | configNamePattern[2] = '_NbPoolsSrv2=' + repr(NumberPoolsServer2) |
---|
| 149 | elif line.startswith("NumberClients"): |
---|
| 150 | configNamePattern[3] = '_NbClients=' + repr(NumberClients) |
---|
| 151 | elif line.startswith("NumberServers"): |
---|
| 152 | configNamePattern[4] = '_NbServers=' + repr(NumberServers) |
---|
| 153 | elif line.startswith("Duration"): |
---|
| 154 | configNamePattern[5] = '_Duration=' + Duration |
---|
[1712] | 155 | elif line.startswith("ATMdomain"): |
---|
| 156 | configNamePattern[5] = '_ATMdomain=' + ATMdomain |
---|
[1708] | 157 | f.close() |
---|
| 158 | |
---|
| 159 | |
---|
[1737] | 160 | |
---|
[1708] | 161 | configName = "config" |
---|
| 162 | defaultConfig = True |
---|
| 163 | |
---|
| 164 | for i in range(len(configNamePattern)): |
---|
| 165 | if configNamePattern[i] != 0: |
---|
| 166 | configName = configName + configNamePattern[i] |
---|
| 167 | defaultConfig = False |
---|
| 168 | |
---|
| 169 | if defaultConfig: |
---|
| 170 | configName = "config_default" |
---|
| 171 | |
---|
[1734] | 172 | check_result=False |
---|
[1708] | 173 | |
---|
[1734] | 174 | |
---|
[1708] | 175 | if not os.path.exists(configName): |
---|
| 176 | os.mkdir(configName) |
---|
[1720] | 177 | print blue("\n ****************************************************************") |
---|
| 178 | print blue(" * Directory " + repr(configName) + " Created ") |
---|
| 179 | print blue(" * Copy results to \'not_validated_reference\' folder") |
---|
| 180 | print blue(" ****************************************************************\n") |
---|
[1708] | 181 | |
---|
[1737] | 182 | OSinfo("mkdir "+configName+'/setup') |
---|
| 183 | OSinfo('mkdir '+configName+'/tmp_reference') |
---|
| 184 | OSinfo('mkdir '+configName+'/xios_output') |
---|
[1708] | 185 | |
---|
[1737] | 186 | OSinfo('mv param.def '+configName+'/setup/') |
---|
| 187 | OSinfo('mv all_param.def '+configName+'/setup/') |
---|
| 188 | OSinfo('mv user_param.py '+configName+'/setup/') |
---|
| 189 | OSinfo('mv iodef.xml '+configName+'/setup/') |
---|
| 190 | OSinfo('cp context_atm.xml '+configName+'/setup/') |
---|
| 191 | OSinfo('cp context_grid_dynamico.xml '+configName+'/setup/') |
---|
| 192 | OSinfo('cp dynamico_grid.nc '+configName+'/setup/') |
---|
| 193 | OSinfo('mv xios_*.out '+configName+'/xios_output/') |
---|
| 194 | OSinfo('mv xios_*.err '+configName+'/xios_output/') |
---|
[1708] | 195 | |
---|
| 196 | |
---|
[1714] | 197 | f=open("checkfile.def", "r") |
---|
| 198 | h=open("report.txt", "a+") |
---|
[1725] | 199 | l=open("report.html", "a+") |
---|
| 200 | h.write("Config : "+configName+"\n") |
---|
| 201 | l.write("<p>Config : "+configName+"</p>") |
---|
[1734] | 202 | endloop=False |
---|
[1714] | 203 | for line in f: |
---|
| 204 | line=line.strip() |
---|
| 205 | line=line.rstrip() |
---|
[1734] | 206 | |
---|
| 207 | if line.startswith("all"): |
---|
| 208 | allfiles = os.listdir(os.getcwd()) |
---|
| 209 | for thisfile in allfiles: |
---|
| 210 | if thisfile.endswith(".nc") and thisfile!="dynamico_grid.nc": |
---|
| 211 | cmd = 'mv '+thisfile + ' '+configName+'/tmp_reference/' |
---|
[1737] | 212 | OSinfo(cmd) |
---|
[1734] | 213 | |
---|
| 214 | h.write("test for "+lpurple("all NC files")+" \t"+yellow('INITIALIZED')+"\n") |
---|
| 215 | l.write("<p>test for <font color=\"purple\">"+"all NC files"+"</font> <font color=\"darkorange\">INITIALIZED</font></p>") |
---|
| 216 | print yellow("\n ****************************************") |
---|
| 217 | print yellow(" ** "+"all NC files"+" is stored as temporal reference !!! **") |
---|
| 218 | print yellow("\n ****************************************") |
---|
| 219 | |
---|
| 220 | break |
---|
| 221 | |
---|
[1714] | 222 | if not line.startswith("#") and len(line) != 0: |
---|
[1726] | 223 | cmd = 'mv '+line + ' '+configName+'/tmp_reference/' |
---|
[1737] | 224 | OSinfo(cmd) |
---|
[1714] | 225 | |
---|
[1725] | 226 | h.write("test for "+lpurple(line)+" \t"+yellow('INITIALIZED')+"\n") |
---|
| 227 | l.write("<p>test for <font color=\"purple\">"+line+"</font> <font color=\"darkorange\">INITIALIZED</font></p>") |
---|
[1720] | 228 | print yellow("\n ****************************************") |
---|
| 229 | print yellow(" ** "+line+" is stored as temporal reference !!! **") |
---|
| 230 | print yellow("\n ****************************************") |
---|
[1714] | 231 | |
---|
| 232 | f.close() |
---|
[1725] | 233 | h.write("\n") |
---|
| 234 | l.write("<br>") |
---|
[1714] | 235 | h.close() |
---|
| 236 | |
---|
| 237 | |
---|
[1708] | 238 | else: |
---|
[1720] | 239 | print blue("\n ********************************************************") |
---|
| 240 | print blue(" * Directory " + repr(configName) + " already exists") |
---|
[1734] | 241 | print blue(" * Start comparing results with references") |
---|
[1720] | 242 | print blue(" ********************************************************\n") |
---|
[1708] | 243 | |
---|
| 244 | tmp_ref = os.path.isdir(configName+'/tmp_reference') |
---|
[1734] | 245 | ref = os.path.isdir(configName+'/reference') and not tmp_ref |
---|
[1708] | 246 | |
---|
| 247 | if ref: |
---|
[1720] | 248 | print blue("\n =====================================") |
---|
| 249 | print blue(" | Comparing results with references |") |
---|
| 250 | print blue(" =====================================\n") |
---|
[1708] | 251 | path = configName+'/reference/' |
---|
| 252 | elif tmp_ref: |
---|
[1720] | 253 | print blue("\n ===================================================") |
---|
| 254 | print blue(" | Comparing results with NON-Validated references |") |
---|
| 255 | print blue(" ===================================================\n") |
---|
[1734] | 256 | path = configName+'/tmp_reference/' |
---|
[1708] | 257 | |
---|
| 258 | f=open("checkfile.def", "r") |
---|
| 259 | h=open("report.txt", "a+") |
---|
[1723] | 260 | l=open("report.html", "a+") |
---|
[1708] | 261 | |
---|
[1714] | 262 | |
---|
[1725] | 263 | h.write("Config : "+configName+"\n") |
---|
| 264 | l.write("<p>Config : "+configName+"</p>") |
---|
[1708] | 265 | for line in f: |
---|
[1714] | 266 | |
---|
[1708] | 267 | line=line.strip() |
---|
| 268 | line=line.rstrip() |
---|
[1714] | 269 | |
---|
[1734] | 270 | if line.startswith("all") : |
---|
| 271 | for thisfile in os.listdir(path): |
---|
| 272 | if thisfile.endswith(".nc"): |
---|
| 273 | cmd = 'cdo -W diffn '+ thisfile +' '+ path + thisfile + ' | tail -1 > diff.txt' |
---|
| 274 | |
---|
| 275 | OSinfo(cmd) |
---|
| 276 | |
---|
| 277 | if os.stat("diff.txt").st_size==0: |
---|
| 278 | h.write("test for "+lpurple(thisfile)+" \t"+green('PASSED')+"\n") |
---|
| 279 | l.write("<p>test for <font color=\"purple\">"+thisfile+"</font> <font color=\"green\">PASSED</font></p>") |
---|
| 280 | print green("\n ****************************************") |
---|
| 281 | print green(" ** "+thisfile+" is valid !!! **") |
---|
| 282 | print green("\n ****************************************") |
---|
[1708] | 283 | |
---|
[1734] | 284 | else: |
---|
| 285 | g=open("diff.txt", "r") |
---|
| 286 | for gline in g: |
---|
| 287 | if gline.strip().startswith("0") or ":" in gline : |
---|
| 288 | h.write("test for "+lpurple(thisfile)+" \t"+green('PASSED')+"\n") |
---|
| 289 | l.write("<p>test for <font color=\"purple\">"+thisfile+"</font> <font color=\"green\">PASSED</font></p>") |
---|
| 290 | print green("\n ****************************************") |
---|
| 291 | print green(" ** "+thisfile+" is valid !!! **") |
---|
| 292 | print green("\n ****************************************") |
---|
| 293 | else: |
---|
| 294 | h.write("test for "+lpurple(thisfile)+" \t"+red('FAILED')+"\n") |
---|
| 295 | l.write("<p>test for <font color=\"purple\">"+thisfile+"</font> <font color=\"red\">FAILED</font></p>") |
---|
| 296 | print red("\n **************************************************") |
---|
| 297 | print red(" ** "+thisfile+" is NOT valid. Please debugging.. **") |
---|
| 298 | print red("\n **************************************************") |
---|
| 299 | g.close() |
---|
[1738] | 300 | |
---|
| 301 | # generate job submission script |
---|
| 302 | hostname=os.getenv('machine_name') |
---|
| 303 | |
---|
| 304 | if hostname.startswith("jeanzay"): |
---|
| 305 | write_jz_job(configName, NumberClients+NumberServers) |
---|
| 306 | |
---|
| 307 | elif hostname.startswith("irene"): |
---|
| 308 | write_irene_job(configName, NumberClients+NumberServers) |
---|
| 309 | |
---|
| 310 | else : |
---|
| 311 | print("machine unknown") |
---|
| 312 | print >> sys.stderr, 1 |
---|
| 313 | sys.exit() |
---|
[1734] | 314 | break |
---|
| 315 | |
---|
| 316 | |
---|
| 317 | elif not line.startswith("#") and len(line) != 0: |
---|
| 318 | cmd = 'cdo -W diffn '+ line +' '+ path + line + ' | tail -1 > diff.txt' |
---|
| 319 | |
---|
| 320 | OSinfo(cmd) |
---|
| 321 | |
---|
[1719] | 322 | if os.stat("diff.txt").st_size==0: |
---|
[1725] | 323 | h.write("test for "+lpurple(line)+" \t"+green('PASSED')+"\n") |
---|
| 324 | l.write("<p>test for <font color=\"purple\">"+line+"</font> <font color=\"green\">PASSED</font></p>") |
---|
[1720] | 325 | print green("\n ****************************************") |
---|
| 326 | print green(" ** "+line+" is valid !!! **") |
---|
| 327 | print green("\n ****************************************") |
---|
[1719] | 328 | |
---|
| 329 | else: |
---|
| 330 | g=open("diff.txt", "r") |
---|
| 331 | for gline in g: |
---|
| 332 | if gline.strip().startswith("0") or ":" in gline : |
---|
[1725] | 333 | h.write("test for "+lpurple(line)+" \t"+green('PASSED')+"\n") |
---|
| 334 | l.write("<p>test for <font color=\"purple\">"+line+"</font> <font color=\"green\">PASSED</font></p>") |
---|
[1720] | 335 | print green("\n ****************************************") |
---|
| 336 | print green(" ** "+line+" is valid !!! **") |
---|
| 337 | print green("\n ****************************************") |
---|
[1719] | 338 | else: |
---|
[1725] | 339 | h.write("test for "+lpurple(line)+" \t"+red('FAILED')+"\n") |
---|
| 340 | l.write("<p>test for <font color=\"purple\">"+line+"</font> <font color=\"red\">FAILED</font></p>") |
---|
[1720] | 341 | print red("\n **************************************************") |
---|
| 342 | print red(" ** "+line+" is NOT valid. Please debugging.. **") |
---|
| 343 | print red("\n **************************************************") |
---|
[1719] | 344 | g.close() |
---|
[1738] | 345 | |
---|
| 346 | # generate job submission script |
---|
| 347 | hostname=os.getenv('machine_name') |
---|
| 348 | |
---|
| 349 | if hostname.startswith("jeanzay"): |
---|
| 350 | write_jz_job(configName, NumberClients+NumberServers) |
---|
| 351 | |
---|
| 352 | elif hostname.startswith("irene"): |
---|
| 353 | write_irene_job(configName, NumberClients+NumberServers) |
---|
| 354 | |
---|
| 355 | else : |
---|
| 356 | print("machine unknown") |
---|
| 357 | print >> sys.stderr, 1 |
---|
| 358 | sys.exit() |
---|
| 359 | |
---|
| 360 | |
---|
[1708] | 361 | f.close() |
---|
[1725] | 362 | h.write("\n") |
---|
| 363 | l.write("<br>") |
---|
[1714] | 364 | h.close() |
---|
[1708] | 365 | |
---|
[1726] | 366 | if not os.path.exists('current_run'): |
---|
[1737] | 367 | OSinfo('mkdir current_run') |
---|
[1708] | 368 | |
---|
[1726] | 369 | if not os.path.exists('current_run/'+configName): |
---|
[1737] | 370 | OSinfo('mkdir current_run/'+configName) |
---|
[1708] | 371 | |
---|
[1737] | 372 | OSinfo('mv -f param.def current_run/'+configName) |
---|
| 373 | OSinfo('mv -f all_param.def current_run/'+configName) |
---|
| 374 | OSinfo('mv -f user_param.py current_run/'+configName) |
---|
| 375 | OSinfo('mv -f iodef.xml current_run/'+configName) |
---|
| 376 | OSinfo('rm -f current_run/'+configName+'/context_atm.xml') |
---|
| 377 | OSinfo('cp -n context_atm.xml current_run/'+configName) |
---|
| 378 | OSinfo('cp -f context_grid_dynamico.xml current_run/'+configName) |
---|
| 379 | OSinfo('cp -f dynamico_grid.nc current_run/'+configName) |
---|
| 380 | OSinfo('mv -f xios_*.out current_run/'+configName) |
---|
| 381 | OSinfo('mv -f xios_*.err current_run/'+configName) |
---|
[1708] | 382 | |
---|
[1734] | 383 | |
---|
| 384 | |
---|
[1737] | 385 | |
---|
[1708] | 386 | if __name__== "__main__": |
---|
[1718] | 387 | main() |
---|