def test_xcase_submit(self): test_root = MACHINE.get_value("CIME_OUTPUT_ROOT") machine = MACHINE.get_machine_name() compiler = MACHINE.get_default_compiler() test_name = get_full_test_name("PFS_I0",grid="f19_g16", compset="X", machine=machine, compiler=compiler) expected_dir = os.path.join(test_root, "{}.test_lbt".format(test_name), "timing") if not os.path.isdir(expected_dir): with tempfile.NamedTemporaryFile('w+') as tfile, tempfile.NamedTemporaryFile('w+') as xfile: tfile.write(PES_XML) tfile.flush() xfile.write(X_OPTIONS) xfile.flush() cmd = "./load_balancing_submit.py --pesfile {} --res f19_g16 --compset X --test-id test_lbt --extra-options-file {} --test-root {}".format(tfile.name, xfile.name, test_root) if MACHINE.has_batch_system(): sys.stdout.write("Jobs will be submitted to queue. Rerun " "load_balancing_test.py after jobs have " "finished.") else: cmd += " --force-purge" output = run_cmd_no_fail(cmd, from_dir=CODE_DIR) self.assertTrue(output.find("Timing jobs submitted") >= 0, "Expected 'Timing jobs submitted' in output") if os.path.isdir(expected_dir): cmd = "./load_balancing_solve.py --total-tasks 32 --blocksize 1 --test-id test_lbt --print-models --test-root {} --layout IceLndAtmOcn".format(test_root) output = run_cmd_no_fail(cmd, from_dir=CODE_DIR) self.assertTrue(output.find("***ATM***") > 0, "--print-models failed to print ATM data") self._check_solution(output, "NTASKS_ATM", 31)
def _translate_test_names_for_new_pecount(test_names, force_procs, force_threads): ############################################################################### new_test_names = [] caseopts = [] for test_name in test_names: testcase, caseopts, grid, compset, machine, compiler, testmod = parse_test_name( test_name) rewrote_caseopt = False if caseopts is not None: for idx, caseopt in enumerate(caseopts): if caseopt.startswith("P"): caseopt = caseopt[1:] if "x" in caseopt: old_procs, old_thrds = caseopt.split("x") else: old_procs, old_thrds = caseopt, None new_procs = force_procs if force_procs is not None else old_procs new_thrds = force_threads if force_threads is not None else old_thrds newcaseopt = ( "P{}".format(new_procs)) if new_thrds is None else ( "P{}x{}".format(new_procs, new_thrds)) caseopts[idx] = newcaseopt rewrote_caseopt = True break if not rewrote_caseopt: force_procs = "M" if force_procs is None else force_procs newcaseopt = ( "P{}".format(force_procs)) if force_threads is None else ( "P{}x{}".format(force_procs, force_threads)) if caseopts is None: caseopts = [newcaseopt] else: caseopts.append(newcaseopt) new_test_name = get_full_test_name(testcase, caseopts=caseopts, grid=grid, compset=compset, machine=machine, compiler=compiler, testmod=testmod) new_test_names.append(new_test_name) return new_test_names
def _translate_test_names_for_new_pecount(test_names, force_procs, force_threads): ############################################################################### new_test_names = [] for test_name in test_names: testcase, caseopts, grid, compset, machine, compiler, testmod = parse_test_name( test_name) rewrote_caseopt = False if caseopts is not None: for idx, caseopt in enumerate(caseopts): if caseopt.startswith("P"): caseopt = caseopt[1:] if "x" in caseopt: old_procs, old_thrds = caseopt.split("x") else: old_procs, old_thrds = caseopt, None new_procs = force_procs if force_procs is not None else old_procs new_thrds = force_threads if force_threads is not None else old_thrds newcaseopt = ("P%s" % new_procs) if new_thrds is None else ( "P%sx%s" % (new_procs, new_thrds)) # No idea why pylint thinks this is unsubscriptable caseopts[idx] = newcaseopt # pylint: disable=unsubscriptable-object rewrote_caseopt = True break if not rewrote_caseopt: force_procs = "M" if force_procs is None else force_procs newcaseopt = ("P%s" % force_procs) if force_threads is None else ( "P%sx%s" % (force_procs, force_threads)) if caseopts is None: caseopts = [newcaseopt] else: caseopts.append(newcaseopt) new_test_name = get_full_test_name(testcase, caseopts=caseopts, grid=grid, compset=compset, machine=machine, compiler=compiler, testmod=testmod) new_test_names.append(new_test_name) return new_test_names
def _translate_test_names_for_new_pecount(test_names, force_procs, force_threads): ############################################################################### new_test_names = [] caseopts = [] for test_name in test_names: testcase, caseopts, grid, compset, machine, compiler, testmod = parse_test_name(test_name) rewrote_caseopt = False if caseopts is not None: for idx, caseopt in enumerate(caseopts): if caseopt.startswith("P"): caseopt = caseopt[1:] if "x" in caseopt: old_procs, old_thrds = caseopt.split("x") else: old_procs, old_thrds = caseopt, None new_procs = force_procs if force_procs is not None else old_procs new_thrds = force_threads if force_threads is not None else old_thrds newcaseopt = ("P{}".format(new_procs)) if new_thrds is None else ("P{}x{}".format(new_procs, new_thrds)) caseopts[idx] = newcaseopt rewrote_caseopt = True break if not rewrote_caseopt: force_procs = "M" if force_procs is None else force_procs newcaseopt = ("P{}".format(force_procs)) if force_threads is None else ("P{}x{}".format(force_procs, force_threads)) if caseopts is None: caseopts = [newcaseopt] else: caseopts.append(newcaseopt) new_test_name = get_full_test_name(testcase, caseopts=caseopts, grid=grid, compset=compset, machine=machine, compiler=compiler, testmod=testmod) new_test_names.append(new_test_name) return new_test_names
def load_balancing_submit(compset, res, pesfile, mpilib, compiler, project, machine, extra_options_file, test_id, force_purge, test_root): ################################################################################ # Read in list of pes from given file if not os.access(pesfile, os.R_OK): logger.critical('ERROR: File %s not found', pesfile) raise SystemExit(1) logger.info('Reading XML file %s. Searching for pesize entries:', pesfile) try: pesobj = Pes(pesfile) except ParseError: logger.critical('ERROR: File %s not parseable', pesfile) raise SystemExit(1) pesize_list = [] for node in pesobj.get_nodes('pes'): pesize = node.get('pesize') if not pesize: logger.critical('No pesize for pes node in file %s', pesfile) if pesize in pesize_list: logger.critical('pesize %s duplicated in file %s', pesize, pesfile) pesize_list.append(pesize) if not pesize_list: logger.critical('ERROR: No grid entries found in pes file %s', pesfile) raise SystemExit(1) machobj = Machines(machine=machine) if test_root is None: test_root = machobj.get_value("CIME_OUTPUT_ROOT") if machine is None: machine = machobj.get_machine_name() print "machine is {}".format(machine) if compiler is None: compiler = machobj.get_default_compiler() print "compiler is {}".format(compiler) if mpilib is None: mpilib = machobj.get_default_MPIlib({"compiler": compiler}) test_names = [] for i in xrange(len(pesize_list)): test_names.append( get_full_test_name("PFS_I{}".format(i), grid=res, compset=compset, machine=machine, compiler=compiler)) casedir = os.path.join(test_root, test_names[-1] + "." + test_id) print "casedir is {}".format(casedir) if os.path.isdir(casedir): if force_purge: logger.info('Removing directory %s', casedir) shutil.rmtree(casedir) else: expect( False, "casedir {} already exists, use the --force-purge option, --test-root or" " --test-id options".format(casedir)) tests = TestScheduler(test_names, no_setup=True, compiler=compiler, machine_name=machine, mpilib=mpilib, test_root=test_root, test_id=test_id, project=project) success = tests.run_tests(wait=True) expect(success, "Error in creating cases") testnames = [] for test in tests.get_testnames(): testname = os.path.join(test_root, test + "." + test_id) testnames.append(testname) logger.info("test is {}".format(testname)) with Case(testname) as case: pes_ntasks, pes_nthrds, pes_rootpe, _ = \ pesobj.find_pes_layout('any', 'any', 'any', pesize_opts=pesize_list.pop(0)) for key in pes_ntasks: case.set_value(key, pes_ntasks[key]) for key in pes_nthrds: case.set_value(key, pes_nthrds[key]) for key in pes_rootpe: case.set_value(key, pes_rootpe[key])
def load_balancing_submit(compset, res, pesfile, mpilib, compiler, project, machine, extra_options_file, test_id, force_purge, test_root): ################################################################################ # Read in list of pes from given file expect(os.access(pesfile, os.R_OK), 'ERROR: File %s not found', pesfile) logger.info('Reading XML file %s. Searching for pesize entries:', pesfile) try: pesobj = Pes(pesfile) except ParseError: expect(False, 'ERROR: File %s not parseable', pesfile) pesize_list = [] grid_nodes = pesobj.get_children("grid") for gnode in grid_nodes: mach_nodes = pesobj.get_children("mach", root=gnode) for mnode in mach_nodes: pes_nodes = pesobj.get_children("pes", root=mnode) for pnode in pes_nodes: pesize = pesobj.get(pnode, 'pesize') if not pesize: logger.critical('No pesize for pes node in file %s', pesfile) if pesize in pesize_list: logger.critical('pesize %s duplicated in file %s', pesize, pesfile) pesize_list.append(pesize) expect(pesize_list, 'ERROR: No grid entries found in pes file {}'.format(pesfile)) machobj = Machines(machine=machine) if test_root is None: test_root = machobj.get_value("CIME_OUTPUT_ROOT") if machine is None: machine = machobj.get_machine_name() print "machine is {}".format(machine) if compiler is None: compiler = machobj.get_default_compiler() print "compiler is {}".format(compiler) if mpilib is None: mpilib = machobj.get_default_MPIlib({"compiler":compiler}) test_names = [] for i in xrange(len(pesize_list)): test_names.append(get_full_test_name("PFS_I{}".format(i),grid=res, compset=compset, machine=machine, compiler=compiler)) casedir = os.path.join(test_root, test_names[-1] + "." + test_id) print "casedir is {}".format(casedir) if os.path.isdir(casedir): if force_purge: logger.info('Removing directory %s', casedir) shutil.rmtree(casedir) else: expect(False, "casedir {} already exists, use the --force-purge option, --test-root or" " --test-id options".format(casedir)) tests = TestScheduler(test_names, no_setup = True, compiler=compiler, machine_name=machine, mpilib=mpilib, test_root=test_root, test_id=test_id, project=project) success = tests.run_tests(wait=True) expect(success, "Error in creating cases") testnames = [] for test in tests.get_testnames(): testname = os.path.join(test_root, test + "." + test_id) testnames.append( testname) logger.info("test is {}".format(testname)) with Case(testname) as case: pes_ntasks, pes_nthrds, pes_rootpe, _, _, _ = \ pesobj.find_pes_layout('any', 'any', 'any', pesize_opts=pesize_list.pop(0)) for key in pes_ntasks: case.set_value(key, pes_ntasks[key]) for key in pes_nthrds: case.set_value(key, pes_nthrds[key]) for key in pes_rootpe: case.set_value(key, pes_rootpe[key]) if extra_options_file is not None: try: extras = open(extra_options_file, 'r') for line in extras.readlines(): split = line.split('=') if len(split) == 2: logger.info('setting %s=%s', split[0], split[1]) case.set_value(split[0], split[1]) else: logger.debug('ignoring line in {}: {}'.format( extra_options_file, line)) extras.close() except IOError: expect(False, "ERROR: Could not read file {}".format(extra_options_file)) tests = TestScheduler(test_names, use_existing=True, test_root=test_root, test_id=test_id) success = tests.run_tests(wait=False) expect(success, "Error in running cases") # need to fix logger.info('Timing jobs submitted. After jobs completed, run to optimize ' 'pe layout:\n load_balancing_solve --test-id {} --test-root {}'. format(test_id, test_root))