示例#1
0
def main(argv, pkg):
    """
    Main function.
    """

    # Use alternate compute (back-end) package if defined

    batch = cs_batch.batch(pkg)

    submit_cmd = batch.submit_command_prefix()

    if not submit_cmd:
        submit_cmd = get_shell_type()

    epilog = ("Options not listed above are passed to the batch "
              "submission commands; see your batch documentation for this.")

    run_parser = cs_run.arg_parser(argv, pkg)
    parser = ArgumentParser(
        parents=[run_parser],
        description="Submit a case or specified run stages.",
        usage='%(prog)s [run options] [batch options]',
        epilog=epilog,
        conflict_handler='resolve')

    run_args, submit_args = parser.parse_known_args(argv)

    retcode, result_path, r_c = cs_run.run(pkg=pkg,
                                           run_args=run_args,
                                           submit_args=submit_args)

    # Now prepare runcase for submission

    if retcode != 0 or not result_path:
        err_str = ' run not staged due to prior error.'
        raise Exception(err_str)

    runcase_path = os.path.join(result_path, 'runcase')
    runcase = cs_runcase.runcase(runcase_path,
                                 package=pkg,
                                 submit=True,
                                 job_header=r_c['job_header'],
                                 prologue=r_c['run_prologue'],
                                 epilogue=r_c['run_epilogue'])
    runcase.save()

    # Now submit case

    save_wd = os.getcwd()
    os.chdir(result_path)

    if r_c['job_parameters']:
        submit_cmd += ' ' + r_c['job_parameters']

    submit_cmd += ' ./runcase'

    return subprocess.call(submit_cmd, shell=True)

    os.chdir(save_wd)
示例#2
0
    def __init__(self, path=None, pkg=None, import_legacy=False):
        """
        Constructor.
        """

        self.pkg = pkg
        if self.pkg == None:
            from code_saturne.cs_package import package
            pkg = package()

        self.run_conf = None
        self.path = path

        # Configuration-based information

        i_c = cs_run_conf.get_install_config_info(self.pkg)

        self.resource_name = cs_run_conf.get_resource_name(i_c)
        self.compute_builds = i_c['compute_builds']

        self.batch = cs_batch.batch(self.pkg)

        # Convert from legacy runcase if not updated yet
        # (delaying application of file changes to save).
        # in this case, the run_conf object is pre-loaded so that
        # the "save" operation can apply the (conversion) changes
        # even when the configuration file has not been loaded.

        self.runcase_path = None
        if self.path:
            if import_legacy and not os.path.isfile(self.path):
                dirname = os.path.dirname(self.path)
                if os.path.basename(dirname) == 'DATA':
                    dirname = os.path.join(os.path.basename(dirname), 'SCRIPTS')
                runcase_path = os.path.join(dirname, 'runcase')
                if os.path.isfile(runcase_path):
                    self.runcase_path = runcase_path

        if self.runcase_path:
            from code_saturne import cs_runcase
            runcase = cs_runcase.runcase(runcase_path,
                                         package=self.pkg)
            sections = runcase.run_conf_sections(resource_name=self.resource_name,
                                                 batch_template=i_c['batch'])

            self.run_conf = cs_run_conf.run_conf(self.path,
                                                 package=self.pkg,
                                                 create_if_missing=True)
            for sn in sections:
                if not sn in self.run_conf.sections:
                    run_conf.sections[sn] = {}
                for kw in sections[sn]:
                    self.run_conf.sections[sn][kw] = sections[sn][kw]
示例#3
0
def main(argv, pkg):
    """
    Main function.
    """

    # Use alternate compute (back-end) package if defined

    batch = cs_batch.batch(pkg)

    submit_cmd = batch.submit_command_prefix

    if not submit_cmd:
        submit_cmd = get_shell_type()

    submit_args = []
    for a in argv:
        submit_args.append(a)

    retcode, result_path, r_c = cs_run.run(pkg=pkg, submit_args=submit_args)

    # Now prepare runcase for submission

    if retcode != 0 or not result_path:
        err_str = ' run not staged due to prior error.'
        raise Exception(err_str)

    runcase_path = os.path.join(result_path, 'runcase')
    runcase = cs_runcase.runcase(runcase_path,
                                 package=pkg,
                                 submit=True,
                                 job_header = r_c['job_header'],
                                 prologue = r_c['run_prologue'],
                                 epilogue = r_c['run_epilogue'])
    runcase.save()

    # Now submit case

    save_wd = os.getcwd()
    os.chdir(result_path)

    if r_c['job_parameters']:
        submit_cmd += ' ' + r_c['job_parameters']

    submit_cmd += ' ./runcase'

    return subprocess.call(submit_cmd, shell=True)

    os.chdir(save_wd)
示例#4
0
def main(argv, pkg):
    """
    Main function.
    """

    # Use alternate compute (back-end) package if defined

    batch = cs_batch.batch(pkg)

    submit_cmd = batch.submit_command_prefix()

    if not submit_cmd:
        submit_cmd = get_shell_type()

    runcase_path = process_cmd_line(argv, submit_cmd, pkg)

    if not runcase_path:
        return 1

    scripts_dir = os.path.abspath(os.path.dirname(runcase_path))

    runcase = cs_runcase.runcase(runcase_path)

    # Adjust run command for staging only

    run_args = runcase.get_run_args()

    for a in ['--stage', '--initialize', '--execute', '--finalize']:
        while a in run_args:
            run_args.remove(a)

    run_args.append('--stage')

    retcode, run_id, result_path = cs_run.run(run_args, pkg)

    # Now prepare runcase for submission

    if retcode != 0 or not result_path:
        err_str = ' run not staged due to prior error.'
        raise Exception(err_str)

    run_args = runcase.get_run_args()

    while '--stage' in run_args:
        run_args.remove(a)

    stages = []
    for a in ['--initialize', '--execute', '--finalize']:
        if a in run_args:
            stages.append(a)

    if not stages:
        run_args.append('--initialize')
        run_args.append('--finalize')

    runcase.set_run_args(run_args)
    runcase.set_run_id(run_id=run_id)

    runcase_path = os.path.join(result_path, os.path.basename(runcase_path))

    runcase.save(runcase_path)

    # Now submit case

    save_wd = os.getcwd()
    os.chdir(result_path)

    for a in argv:
        if os.path.isfile(a) and runcase_path:
            submit_cmd += ' ' + enquote_arg(runcase_path)
            runcase_path = None
        else:
            submit_cmd += ' ' + enquote_arg(a)

    return subprocess.call(submit_cmd, shell=True)

    os.chdir(save_wd)
示例#5
0
    def run_conf_sections(self,
                          resource_name='job_defaults',
                          batch_template=None):
        """
        Build "run_conf" sections from an existing runcase.
        """

        sections = {}

        param = self.get_parameters()

        setup_dict = {}
        if param != 'setup.xml':
            setup_dict['param'] = param
        if len(setup_dict) > 0:
            sections['setup'] = setup_dict

        run_dict = {}
        compute_build = self.get_compute_build()
        if compute_build:
            run_dict['compute_build'] = compute_build
        run_id, run_id_prefix, run_id_suffix = self.get_run_id()
        if run_id:
            run_dict['id'] = run_id
        if run_id_prefix:
            run_dict['id_prefix'] = run_id_prefix
        if run_id_suffix:
            run_dict['id_suffix'] = run_id_suffix
        stage_map = {
            'stage': 'stage',
            'initialize': 'preprocess',
            'execute': 'compute',
            'finalize': 'finalize'
        }
        for stage in stage_map.keys():
            if self.get_run_stage(stage):
                run_dict[stage_map[stage]] = True
        if len(run_dict) > 0:
            sections['run'] = run_dict

        resource_dict = {}
        nprocs = self.get_nprocs()
        if nprocs:
            resource_dict['n_procs'] = nprocs
        nthreads = self.get_nthreads()
        if nthreads:
            resource_dict['n_threads'] = nthreads

        # Handle batch info
        if batch_template:
            from code_saturne import cs_batch
            batch_src = cs_batch.batch(self.package)
            batch_src.parse_lines(self.lines)

            topdir, scriptdir = os.path.split(os.path.split(self.path)[0])
            if scriptdir == 'SCRIPTS':
                studydir, casedir = os.path.split(topdir)
                studydir = os.path.split(studydir)[1]
            else:
                casedir = ''
                studydir = scriptdir
            job_name = studydir.lower() + casedir.lower()

            dst_header = cs_batch.generate_header(
                batch_template=batch_template,
                job_name=job_name,
                package=self.package)
            batch_dst = cs_batch.batch(self.package)
            batch_dst.parse_lines(dst_header)
            for k in batch_src.params.keys():
                if batch_src.params[k] != None:
                    batch_dst.params[k] = batch_src.params[k]
            batch_dst.update_lines(dst_header)

            br = os.linesep

            job_header = ''
            for i, l in enumerate(dst_header):
                if i == 0:
                    job_header = l
                else:
                    job_header += br + l

            resource_dict['job_header'] = job_header

        if len(resource_dict) > 0:
            sections[resource_name] = resource_dict

        return sections