コード例 #1
0
    def rebuild_resource(self):
        """
        Rebuild dictionnary using reference templates
        """

        i_c = get_install_config_info(self.package)
        resource_name = get_resource_name(i_c)

        if not resource_name in self.sections:
            self.sections[resource_name] = OrderedDict()

        # Determine or build default job name for batch

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

        job_name = studydir.lower()
        if casedir:
            job_name += '_' + casedir.lower()

        job_lines = cs_batch.generate_header(job_name=job_name,
                                             package=self.package)

        if job_lines:
            self.sections[resource_name]['job_header'] = os.linesep.join(job_lines)
        else:
            self.sections[resource_name]['n_procs'] = ''
            self.sections[resource_name]['n_threads'] = ''

        return
コード例 #2
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