1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883
|
#!/usr/bin/env python
# -*- coding: utf-8 -*-
#-------------------------------------------------------------------------------
# This file is part of Code_Saturne, a general-purpose CFD tool.
#
# Copyright (C) 1998-2018 EDF S.A.
#
# This program is free software; you can redistribute it and/or modify it under
# the terms of the GNU General Public License as published by the Free Software
# Foundation; either version 2 of the License, or (at your option) any later
# version.
#
# This program is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
# FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
# details.
#
# You should have received a copy of the GNU General Public License along with
# this program; if not, write to the Free Software Foundation, Inc., 51 Franklin
# Street, Fifth Floor, Boston, MA 02110-1301, USA.
#-------------------------------------------------------------------------------
from __future__ import print_function
try:
import ConfigParser # Python2
configparser = ConfigParser
except Exception:
import configparser # Python3
import sys
import os, os.path, shutil, sys, string, types, re, subprocess
#===============================================================================
# Utility functions
#===============================================================================
def parse_wall_time_slurm(s):
"""
Parse SLURM wall time
"""
t = None
wt0 = s.split('-')
if len(wt0) == 2:
th = int(wt0[0])*3600*24
wt = wt0[1].split(':')
else:
th = 0
wt = wt0[0].split(':')
if len(wt) == 3:
t = th + int(wt[0])*3600 + int(wt[1])*60 + int(wt[2])
elif len(wt) == 2:
if len(wt0) == 2:
t = th + int(wt[0])*3600 + int(wt[1])*60
else:
t = th + int(wt[0])*60 + int(wt[1])
elif len(wt) == 1:
if len(wt0) == 2:
t = th + int(wt[0])*3600
else:
try:
t = th + int(wt[0])*60
except Exception:
pass
return t
#===============================================================================
# Class used to manage batch directives
#===============================================================================
#-------------------------------------------------------------------------------
class batch:
"""
Parse and modify special batch options in text file lines
"""
#---------------------------------------------------------------------------
def __init__(self, package):
"""
Constructor.
"""
self.rm_type = None
self.submit_cmd = ''
self.params = {}
self.params['job_name'] = None
self.params['job_nodes'] = None
self.params['job_ppn'] = None
self.params['job_procs'] = None
self.params['job_threads'] = None
self.params['job_walltime'] = None
self.params['job_class'] = None
self.params['job_account'] = None
self.params['job_wckey'] = None
# Are we using a resource manager ?
self.rm_type = None
self.rm_template = None
if package:
config = configparser.ConfigParser()
config.read(package.get_configfiles())
if config.has_option('install', 'batch'):
self.rm_template = config.get('install', 'batch')
if os.path.isabs(self.rm_template):
i = self.rm_template.rfind(".")
if i > -1:
self.rm_template = self.rm_template[i+1:]
if self.rm_template:
if self.rm_template[0:5] == 'SLURM':
self.rm_type = 'SLURM'
elif self.rm_template[0:3] == 'CCC':
self.rm_type = 'CCC'
elif self.rm_template[0:5] == 'LOADL':
self.rm_type = 'LOADL'
elif self.rm_template[0:3] == 'LSF':
self.rm_type = 'LSF'
elif self.rm_template[0:3] == 'PBS':
self.rm_type = 'PBS'
elif self.rm_template[0:3] == 'SGE':
self.rm_type = 'SGE'
else:
self.rm_type = os.path.basename(rm_template)
#---------------------------------------------------------------------------
def __get_command_output__(self, cmd):
"""
Run a command and return it's standard output.
"""
p = subprocess.Popen(cmd,
shell=True,
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
universal_newlines=True)
lines = []
while True:
l = p.stdout.readline()
lines.append(l.strip())
if len(l) == 0 and p.poll() != None:
break
output = p.communicate()
if p.returncode == 0:
return lines
else:
print(output[1])
return []
#---------------------------------------------------------------------------
def __pre_parse__(self, s):
"""
Pre-parse batch line
"""
r = ' '
i = s.find('#')
if i > -1:
s = s[:i]
s = r.join(s.split())
return s
#---------------------------------------------------------------------------
def __parse_lines_env_vars__(self, lines):
"""
Parse environment variables in batch file lines
"""
batch_lines = lines
for i in range(len(batch_lines)):
j = batch_lines[i].find('#')
if j > -1:
toks = batch_lines[i][:j].split()
else:
toks = batch_lines[i].split()
if len(toks) > 1:
var = None
val = None
if toks[0] in ('set', 'export'):
k = toks[1].find('=')
if k > 1:
var = toks[1][0:k]
val = toks[1][k+1:]
elif toks[0] in ('setenv'):
if len(toks) > 2:
var = toks[1]
val = toks[2]
if var == 'OMP_NUM_THREADS':
try:
self.params['job_threads'] = int(val)
except Exception:
pass
#---------------------------------------------------------------------------
def __update_lines_env_vars__(self, lines):
"""
Update environment variables in batch file lines
"""
if lines:
batch_lines = lines
for i in range(len(batch_lines)):
j = batch_lines[i].find('#')
if j > -1:
toks = batch_lines[i][:j].split()
else:
toks = batch_lines[i].split()
if len(toks) > 1:
var = None
val = None
if toks[0] in ('set', 'export'):
k = toks[1].find('=')
if k > 1:
var = toks[1][0:k]
val = toks[1][k+1:]
elif toks[0] in ('setenv'):
if len(toks) > 2:
var = toks[1]
val = toks[2]
if var == 'OMP_NUM_THREADS' and self.params['job_threads']:
s_threads = str(self.params['job_threads'])
if toks[0] in ('set', 'export'):
s = toks[0] + ' ' + var + '=' + s_threads
elif toks[0] in ('setenv'):
s = toks[0] + ' ' + var + ' ' + s_threads
if j > 1:
s += ' ' + batch_lines[i][j:]
batch_lines[i] = s
#---------------------------------------------------------------------------
def __parse_lines_slurm__(self, lines):
"""
Parse SLURM batch file lines
"""
batch_lines = lines
for i in range(len(batch_lines)):
if batch_lines[i][0:7] == '#SBATCH':
batch_args = self.__pre_parse__(batch_lines[i][7:])
if batch_args[0:2] == '--':
tok = batch_args.split('=')
if len(tok) < 2:
continue
kw = tok[0] + '='
val = tok[1].split(',')[0].strip()
elif batch_args[0] == '-':
kw = batch_args[0:2]
val = batch_args[2:].split(',')[0].strip()
else:
continue
if kw == '--job-name=' or kw == '-J':
self.params['job_name'] = val
elif kw == '--ntasks=' or kw == '-n':
self.params['job_procs'] = val
elif kw == '--nodes=' or kw == '-N':
self.params['job_nodes'] = val
elif kw == '--ntasks-per-node=':
self.params['job_ppn'] = val
elif kw == '--cpus-per-task=':
self.params['job_threads'] = val
elif kw == '--time=' or kw == '-t':
self.params['job_walltime'] = parse_wall_time_slurm(val)
elif kw == '--partition=' or kw == '-p':
self.params['job_class'] = val
elif kw == '--account=' or kw == '-A':
self.params['job_account'] = val
elif kw == '--wckey=':
self.params['job_wckey'] = val
#---------------------------------------------------------------------------
def __update_lines_slurm__(self, lines):
"""
Update the SLURM batch file from dictionary self.params.
"""
batch_lines = lines
for i in range(len(batch_lines)):
if batch_lines[i][0:7] == '#SBATCH':
batch_args = self.__pre_parse__(batch_lines[i][7:])
if batch_args[0:2] == '--':
tok = batch_args.split('=')
if len(tok) < 2:
continue
kw = tok[0] + '='
val = tok[1].split(',')[0].strip()
elif batch_args[0] == '-':
kw = batch_args[0:2]
val = batch_args[2:].split(',')[0].strip()
if kw == '--job-name=' or kw == '-J':
val = str(self.params['job_name'])
elif kw == '--ntasks=' or kw == '-n':
val = str(self.params['job_procs'])
elif kw == '--nodes=' or kw == '-N':
val = str(self.params['job_nodes'])
elif kw == '--ntasks-per-node=':
val = self.params['job_ppn']
elif kw == '--cpus-per-task=':
val = self.params['job_threads']
elif kw == '--time=' or kw == '-t':
wt = self.params['job_walltime']
if wt > 86400: # 3600*24
val = '%d-%d:%02d:%02d' % (wt//86400,
(wt%86400)//3600,
(wt%3600)//60,
wt%60)
else:
val = '%d:%02d:%02d' % (wt//3600,
(wt%3600)//60,
wt%60)
elif kw == '--partition=' or kw == '-p':
val = self.params['job_class']
elif kw == '--account=' or kw == '-A':
val = self.params['job_account']
elif kw == '--wckey=':
val = self.params['job_wckey']
else:
continue
batch_lines[i] = '#SBATCH ' + kw + str(val)
#---------------------------------------------------------------------------
def __parse_lines_ccc__(self, lines):
"""
Parse CCC (CCRT) batch file lines
"""
batch_lines = lines
for i in range(len(batch_lines)):
if batch_lines[i][0:5] == '#MSUB':
batch_args = self.__pre_parse__(batch_lines[i][5:])
tok = batch_args.split()
if len(tok) < 2:
continue
kw = tok[0]
val = tok[1].split(',')[0].strip()
if kw == '-r':
self.params['job_name'] = val
elif kw == '-n':
self.params['job_procs'] = int(val)
elif kw == '-N':
self.params['job_nodes'] = int(val)
elif kw == '-T':
self.params['job_walltime'] = int(val)
elif kw == '-q':
self.params['job_class'] = val
#---------------------------------------------------------------------------
def __update_lines_ccc__(self, lines):
"""
Update the Platform LSF batch file lines
"""
batch_lines = lines
for i in range(len(batch_lines)):
if batch_lines[i][0:5] == '#MSUB':
batch_args = self.__pre_parse__(batch_lines[i][5:])
tok = batch_args.split()
if len(tok) < 2:
continue
kw = tok[0]
if kw == '-r':
val = str(self.params['job_name'])
elif kw == '-n':
val = str(self.params['job_procs'])
elif kw == '-N':
val = str(self.params['job_nodes'])
elif kw == '-T':
val = str(self.params['job_walltime'])
elif kw == '-q':
val = self.params['job_class']
else:
continue
batch_lines[i] = '#MSUB ' + kw + ' ' + str(val)
#---------------------------------------------------------------------------
def __parse_lines_loadl__(self, lines):
"""
Parse LoadLeveler batch file lines
"""
batch_lines = lines
for i in range(len(batch_lines)):
if batch_lines[i][0] == '#':
batch_args = self.__pre_parse__(batch_lines[i][1:])
try:
if batch_args[0] == '@':
kw, val = batch_args[1:].split('=')
kw = kw.strip()
val = val.split(',')[0].strip()
if kw == 'job_name':
self.params['job_name'] = val
elif kw == 'node':
self.params['job_nodes'] = val
elif kw == 'tasks_per_node':
self.params['job_ppn'] = val
elif kw == 'total_tasks':
self.params['job_procs'] = val
elif kw == 'parallel_threads':
self.params['job_threads'] = val
elif kw == 'wall_clock_limit':
wt = (val.split(',')[0].rstrip()).split(':')
if len(wt) == 3:
self.params['job_walltime'] \
= int(wt[0])*3600 + int(wt[1])*60 + int(wt[2])
elif len(wt) == 2:
self.params['job_walltime'] \
= int(wt[0])*60 + int(wt[1])
elif len(wt) == 1:
self.params['job_walltime'] = int(wt[0])
elif kw == 'class':
self.params['job_class'] = val
elif kw == 'group':
self.params['job_account'] = val
except Exception:
pass
#---------------------------------------------------------------------------
def __update_lines_loadl__(self, lines):
"""
Update the LoadLeveler batch file from dictionary self.params.
"""
batch_lines = lines
for i in range(len(batch_lines)):
if batch_lines[i][0] == '#':
batch_args = self.__pre_parse__(batch_lines[i][1:])
try:
if batch_args[0] == '@':
kw, val = batch_args[1:].split('=')
kw = kw.strip()
val = val.split(',')[0].strip()
if kw == 'job_name':
val = self.params['job_name']
elif kw == 'node':
val = self.params['job_nodes']
elif kw == 'tasks_per_node':
val = self.params['job_ppn']
elif kw == 'total_tasks':
val = self.params['job_procs']
elif kw == 'parallel_threads':
val = self.params['job_threads']
elif kw == 'wall_clock_limit':
wt = self.params['job_walltime']
val = '%d:%02d:%02d' % (wt//3600,
(wt%3600)//60,
wt%60)
elif kw == 'class':
val = self.params['job_class']
elif kw == 'group':
val = self.params['job_account']
else:
continue
batch_lines[i] = '# @ ' + kw + ' = ' + str(val)
except Exception:
pass
#---------------------------------------------------------------------------
def __parse_lines_lsf__(self, lines):
"""
Parse Platform LSF batch file lines
"""
batch_lines = lines
for i in range(len(batch_lines)):
if batch_lines[i][0:5] == '#BSUB':
batch_args = self.__pre_parse__(batch_lines[i][5:])
tok = batch_args.split()
kw = tok[0]
val = tok[1].split(',')[0].strip()
if kw == '-J':
self.params['job_name'] = val
elif kw == '-n':
self.params['job_procs'] = int(val)
elif kw == '-W' or kw == '-wt' or kw == '-We':
wt = val.split(':')
if len(wt) == 1:
self.params['job_walltime'] = int(wt[0])*60
elif len(wt) == 2:
self.params['job_walltime'] \
= int(wt[0])*3600 + int(wt[1])*60
elif kw == '-q':
self.params['job_class'] = val
#---------------------------------------------------------------------------
def __update_lines_lsf__(self, lines):
"""
Update the Platform LSF batch file lines
"""
batch_lines = lines
for i in range(len(batch_lines)):
if batch_lines[i][0:5] == '#BSUB':
batch_args = self.__pre_parse__(batch_lines[i][5:])
tok = batch_args.split()
kw = tok[0]
if kw == '-J':
val = str(self.params['job_name'])
elif kw == '-n':
val = str(self.params['job_procs'])
elif kw == '-W' or kw == '-wt' or kw == '-We':
wt = self.params['job_walltime']
val = '%d:%02d' % (wt//3600, (wt%3600)//60)
elif kw == '-q':
val = self.params['job_class']
else:
continue
batch_lines[i] = '#BSUB ' + kw + ' ' + str(val)
#---------------------------------------------------------------------------
def __parse_lines_pbs__(self, lines):
"""
Parse PBS batch file lines
"""
batch_lines = lines
# TODO: specialize for PBS Professional and TORQUE (OpenPBS has not been
# maintained since 2004, so we do not support it).
# The "-l nodes=N:ppn=P" syntax is common to all PBS variants,
# but PBS Pro considers the syntax depecated, and prefers its
# own "-l select=N:ncpus=P:mpiprocs=P" syntax.
# We do not have access to a PBS Professional system, but according to
# its documentation, it has commands such as "pbs-report" or "pbs_probe"
# which are not part of TORQUE, while the latter has "pbsnodelist" or
# #pbs-config". The presence of either could help determine which
# system is available.
for i in range(len(batch_lines)):
if batch_lines[i][0:4] == '#PBS':
batch_args = ' ' + self.__pre_parse__(batch_lines[i][4:])
index = batch_args.rfind(' -')
while index > -1:
arg = batch_args[index+1:]
batch_args = batch_args[0:index]
if arg[0:2] == '-N':
self.params['job_name'] = arg.split()[1]
elif arg[0:9] == '-l nodes=':
arg_tmp = arg[9:].split(':')
self.params['job_nodes'] = arg_tmp[0]
for s in arg_tmp[1:]:
j = s.find('ppn=')
if j > -1:
self.params['job_ppn'] \
= s[j:].split('=')[1]
elif arg[0:10] == '-l select=':
arg_tmp = arg[10:].split(':')
self.params['job_nodes'] = arg_tmp[0]
for s in arg_tmp[1:]:
j = s.find('ncpus=')
if j > -1:
self.params['job_ppn'] \
= s[j:].split('=')[1]
elif arg[0:12] == '-l walltime=':
wt = (arg.split('=')[1]).split(':')
if len(wt) == 3:
self.params['job_walltime'] \
= int(wt[0])*3600 + int(wt[1])*60 + int(wt[2])
elif len(wt) == 2:
self.params['job_walltime'] \
= int(wt[0])*60 + int(wt[1])
elif len(wt) == 1:
self.params['job_walltime'] \
= int(wt[0])
elif arg[0:2] == '-q':
self.params['job_class'] = arg.split()[1]
index = batch_args.rfind(' -')
#---------------------------------------------------------------------------
def __update_lines_pbs__(self, lines):
"""
Update the PBS batch file from dictionary self.params.
"""
batch_lines = lines
for i in range(len(batch_lines)):
if batch_lines[i][0:4] == '#PBS':
ch = ''
batch_args = ' ' + self.__pre_parse__(batch_lines[i][4:])
index = batch_args.rfind(' -')
while index > -1:
arg = batch_args[index+1:]
batch_args = batch_args[0:index]
if arg[0:2] == '-N':
ch = ' -N ' + self.params['job_name'] + ch
elif arg[0:9] == '-l nodes=':
arg_tmp = arg[9:].split(':')
ch1 = ' -l nodes=' + self.params['job_nodes']
for s in arg_tmp[1:]:
j = s.find('ppn=')
if j > -1:
ch1 += ':' + s[0:j] \
+ 'ppn=' + self.params['job_ppn']
else:
ch1 += ':' + s
ch = ch1 + ch
elif arg[0:10] == '-l select=':
arg_tmp = arg[10:].split(':')
ch1 = ' -l select=' + self.params['job_nodes']
for s in arg_tmp[1:]:
j = s.find('ncpus=')
if j > -1:
ch1 += ':' + s[0:j] \
+ 'ncpus=' + self.params['job_ppn']
else:
ch1 += ':' + s
ch = ch1 + ch
elif arg[0:12] == '-l walltime=':
wt = self.params['job_walltime']
s_wt = '%d:%02d:%02d' % (wt//3600,
(wt%3600)//60,
wt%60)
ch = ' -l walltime=' + s_wt + ch
elif arg[0:2] == '-q':
ch = ' -q ' + self.params['job_class'] + ch
else:
ch = ' ' + arg + ch
index = batch_args.rfind(' -')
ch = '#PBS' + ch
batch_lines[i] = ch
#---------------------------------------------------------------------------
def __parse_lines_sge__(self, lines):
"""
Parse Sun Grid Engine batch file lines
"""
batch_lines = lines
for i in range(len(batch_lines)):
if batch_lines[i][0:2] == '#$':
batch_args = ' ' + self.__pre_parse__(batch_lines[i][2:])
index = batch_args.rfind(' -')
while index > -1:
arg = batch_args[index+1:]
batch_args = batch_args[0:index]
if arg[0:2] == '-N':
self.params['job_name'] = arg.split()[1]
elif arg[0:3] == '-pe':
try:
arg_tmp = arg[3:].split(' ')
self.params['job_procs'] = arg_tmp[2]
except Exception:
pass
elif arg[0:8] == '-l h_rt=':
wt = (arg.split('=')[1]).split(':')
if len(wt) == 3:
self.params['job_walltime'] \
= int(wt[0])*3600 + int(wt[1])*60 + int(wt[2])
elif len(wt) == 2:
self.params['job_walltime'] \
= int(wt[0])*60 + int(wt[1])
elif len(wt) == 1:
self.params['job_walltime'] = int(wt[0])
elif arg[0:2] == '-q':
self.params['job_class'] = arg.split()[1]
index = batch_args.rfind(' -')
#---------------------------------------------------------------------------
def __update_lines_sge__(self, lines):
"""
Update the Sun Grid Engine batch file lines
"""
batch_lines = lines
for i in range(len(batch_lines)):
if batch_lines[i][0:2] == '#$':
ch = ''
batch_args = ' ' + self.__pre_parse__(batch_lines[i][2:])
index = batch_args.rfind(' -')
while index > -1:
arg = batch_args[index+1:]
batch_args = batch_args[0:index]
if arg[0:2] == '-N':
ch = ' -N ' + self.params['job_name'] + ch
elif arg[0:3] == '-pe':
try:
arg_tmp = arg[3:].split(' ')
ch = ' -pe ' + arg_tmp[1] + ' ' \
+ str(self.params['job_procs']) + ch
except Exception:
pass
elif arg[0:8] == '-l h_rt=':
wt = self.params['job_walltime']
s_wt = '%d:%02d:%02d' % (wt//3600,
(wt%3600)//60,
wt%60)
ch = ' -l h_rt=' + s_wt + ch
elif arg[0:2] == '-q':
ch = ' -q ' + self.params['job_class'] + ch
else:
ch = ' ' + arg + ch
index = batch_args.rfind(' -')
ch = '#$' + ch
batch_lines[i] = ch
#---------------------------------------------------------------------------
def parse_lines(self, lines):
"""
Fill self.params reading the job file.
"""
if self.rm_type:
if self.rm_type == 'SLURM':
self.__parse_lines_slurm__(lines)
elif self.rm_type == 'CCC':
self.__parse_lines_ccc__(lines)
elif self.rm_type == 'LOADL':
self.__parse_lines_loadl__(lines)
elif self.rm_type == 'LSF':
self.__parse_lines_lsf__(lines)
elif self.rm_type == 'PBS':
self.__parse_lines_pbs__(lines)
elif self.rm_type == 'SGE':
self.__parse_lines_sge__(lines)
self.__parse_lines_env_vars__(lines)
#---------------------------------------------------------------------------
def update_lines(self, lines, keyword=None):
"""
Update the batch file from reading dictionary self.params.
If keyword == None, all keywords are updated
If keyword == key, only key is updated.
"""
l = list(self.params.keys())
l.append(None) # Add 'None' when no keyword is specified in argument.
for k in list(self.params.keys()):
if self.params[k] == 'None':
self.params[k] = None
if keyword not in l:
msg = str(keyword) + " is not in list " + str(l) + "\n"
raise ValueError(msg)
if self.rm_type:
if self.rm_type == 'SLURM':
self.__update_lines_slurm__(lines)
elif self.rm_type == 'CCC':
self.__update_lines_ccc__(lines)
elif self.rm_type == 'LOADL':
self.__update_lines_loadl__(lines)
elif self.rm_type == 'LSF':
self.__update_lines_lsf__(lines)
elif self.rm_type == 'PBS':
self.__update_lines_pbs__(lines)
elif self.rm_type == 'SGE':
self.__update_lines_sge__(lines)
self.__update_lines_env_vars__(lines)
#---------------------------------------------------------------------------
def submit_command_prefix(self):
"""
Return the command prefix used to submit a job.
"""
cmd_prefix = ''
rm_type = self.rm_type
if rm_type == 'SLURM':
cmd_prefix = 'sbatch '
elif rm_type == 'CCC':
cmd_prefix = 'ccc_msub '
elif rm_type == 'LOADL':
cmd_prefix = 'llsubmit '
elif rm_type == 'LSF':
cmd_prefix = 'bsub < '
elif rm_type == 'OAR':
cmd_prefix = 'oarsub'
elif rm_type == 'PBS' or rm_type == 'SGE':
cmd_prefix = 'qsub '
else:
pass
return cmd_prefix
#---------------------------------------------------------------------------
def get_class_list(self):
"""
Return the list of available classes
"""
class_list = []
try:
rm_type = self.rm_type
if rm_type == 'SLURM':
output = self.__get_command_output__('sinfo -s')
for l in output[1:]:
if len(l) == 0:
break
else:
name = l.split(' ')[0]
if name[-1:] == '*':
name = name[:-1]
class_list.append(name)
elif rm_type == 'CCC':
output = self.__get_command_output__('class')
for l in output[1:]:
if len(l) == 0:
break
else:
class_list.append(l.split(' ')[0])
elif rm_type == 'LOADL':
output = self.__get_command_output__('llclass')
ignore = True
for l in output:
if l[0:3] == '---':
ignore = not ignore
elif ignore == False:
class_list.append(l.split(' ')[0])
elif rm_type == 'LSF':
output = self.__get_command_output__('bqueues')
ignore = True
for l in output[1:]:
if len(l) == 0:
break
else:
class_list.append(l.split(' ')[0])
elif rm_type == 'PBS':
output = self.__get_command_output__('qstat -q')
ignore = True
for l in output:
if l[0:3] == '---':
ignore = not ignore
elif ignore == False:
class_list.append(l.split(' ')[0])
elif self.case['batch_type'][0:3] == 'SGE':
output = self.__get_command_output__('qconf -sc')
for l in output:
if l[0:1] != '#':
class_list.append(l.split(' ')[0])
except Exception:
import traceback
exc_info = sys.exc_info()
bt = traceback.format_exception(*exc_info)
print(bt)
pass
return class_list
#-------------------------------------------------------------------------------
# End
#-------------------------------------------------------------------------------
|