Example #1
0
    def batch_accounting(self,*args,**kwargs):
        spec=tools.make_dict_from(args,kwargs)
        space=self.indent_text
        sio=StringIO()

        if 'queue' in spec:
            sio.write(f'#SBATCH -p {spec["queue"]!s}\n')
        if 'project' in spec:
            sio.write(f'#SBATCH -A {spec["project"]!s}\n')
        if 'account' in spec:
            sio.write(f'#SBATCH -A {spec["account"]!s}\n')
        if 'partition' in spec and spec['partition']: #slurm treat 'partition' same as 'queue'
            sio.write(f'#SBATCH -p partition={spec["partition"]!s}\n')
        if 'jobname' in spec:
            sio.write(f'#SBATCH -J {spec["jobname"]}\n')
#        if 'reservation' in spec:
#            sio.write(f'#PBS -l flags=ADVRES:{spec["reservation"]}\n')
        if 'outerr' in spec:
            sio.write(f'#SBATCH -e {spec["outerr"]}\n')
        else:
            if 'stdout' in spec:
                sio.write('#SBATCH -o {spec["stdout"]}\n')
            if 'stderr' in spec:
                sio.write('#SBATCH -e {spec["stderr"]}\n')

        ret=sio.getvalue()
        sio.close()
        return ret
Example #2
0
 def rocoto_accounting(self,*args,indent=0,**kwargs):
     spec=tools.make_dict_from(args,kwargs)
     space=self.indent_text
     sio=StringIO()
     if 'queue' in spec:
         sio.write(f'{indent*space}<queue>{spec["queue"]}</queue>\n')
     if 'partition' in spec:
         sio.write(f'{indent*space}<native>--partition={spec["partition"]!s}</native>\n')
     if 'account' in spec:
         sio.write(f'{indent*space}<account>{spec["account"]!s}</account>\n')
     elif 'project' in spec:
         sio.write(f'{indent*space}<account>{spec["project"]!s}</account>\n')
     if 'jobname' in spec:
         sio.write(f'{indent*space}<jobname>{spec["jobname"]!s}</jobname>\n')
     if 'reservation' in spec:
         sio.write(f'{indent*space}<native>-l flags=ADVRES:{spec["reservation"]}</native>\n')
     if 'outerr' in spec:
         sio.write(f'{indent*space}<join>{spec["outerr"]}</join>\n')
     else:
         if 'stdout' in spec:
             sio.write('{indent*space}<stdout>{spec["stdout"]}</stdout>\n')
         if 'stderr' in spec:
             sio.write('{indent*space}<stderr>{spec["stderr"]}</stderr>\n')
     ret=sio.getvalue()
     sio.close()
     return ret
Example #3
0
    def batch_resources(self,*args,**kwargs):
        spec=tools.make_dict_from(args,kwargs)
        space=self.indent_text
        sio=StringIO()
        if not isinstance(spec,JobResourceSpec):
            spec=JobResourceSpec(spec)
            
        result=''
        if spec[0].get('walltime',''):
            dt=tools.to_timedelta(spec[0]['walltime'])
            dt=dt.total_seconds()
            hours=int(dt//3600)
            minutes=int((dt%3600)//60)
            seconds=int(math.floor(dt%60))
            sio.write(f'#SBATCH -t {hours:02d}:{minutes:02d}'
                      f':{seconds:02d}\n')

        megabytes=self.get_memory_from_resource_spec(spec)
        if megabytes is not None:
            sio.write(f'#SBATCH --mem={megabytes:d}M\n')

        if spec[0].get('outerr',''):
            sio.write(f'#SBATCH -e {spec[0]["outerr"]}\n')
        else:
            if spec[0].get('stdout',''):
                sio.write('#SBATCH -o {spec[0]["stdout"]}\n')
            if spec[0].get('stderr',''):
                sio.write('#SBATCH -e {spec[0]["stderr"]}\n')
        if spec[0].get('jobname'):
            sio.write('#SBATCH -J {spec[0]["jobname"]}\n')

        # --------------------------------------------------------------
        # Request processors.
        if spec.is_pure_serial():
            if spec[0].is_exclusive() in [True,None]:
                sio.write('#SBATCH -N 1 -n 2\n')
            else:
                sio.write('#SBATCH -n 1\n')
        elif spec.is_pure_openmp():
            # Pure threaded.  Treat as exclusive serial.
            sio.write('#SBATCH -N 1 -n 2\n')
        else:
            # This is an MPI program.

            # Split into (nodes,ranks_per_node) pairs.  Ignore
            # differing executables between ranks while merging them
            # (del_exe):
            nodes_ranks=self.nodes.to_nodes_ppn(
                spec,can_merge_ranks=self.nodes.same_except_exe)
            sio.write('#SBATCH -N ')
            sio.write('+'.join([f'{n} -n {p}' for n,p in nodes_ranks ]))
            sio.write('\n')
        ret=sio.getvalue()
        sio.close()
        return ret
Example #4
0
    def rocoto_resources(self, *args, indent=0, **kwargs):
        spec = tools.make_dict_from(args, kwargs)
        sio = StringIO()
        space = self.indent_text
        if not isinstance(spec, JobResourceSpec):
            spec = JobResourceSpec(spec)

        if spec[0].get('walltime', ''):
            dt = tools.to_timedelta(spec[0]['walltime'])
            dt = dt.total_seconds()
            hours = int(dt // 3600)
            minutes = int((dt % 3600) // 60)
            seconds = int(math.floor(dt % 60))
            sio.write(
                f'{indent*space}<walltime>{hours}:{minutes:02d}:{seconds:02d}</walltime>\n'
            )

        megabytes = self.get_memory_from_resource_spec(spec)
        if megabytes is not None:
            sio.write(f'{indent*space}<memory>{megabytes:d}M</memory>\n')

        if 'outerr' in spec:
            sio.write(f'{indent*space}<join>{spec["outerr"]}</join>\n')
        else:
            if 'stdout' in spec:
                sio.write('{indent*space}<stdout>{spec["stdout"]}</stdout>\n')
            if 'stderr' in spec:
                sio.write('{indent*space}<stderr>{spec["stderr"]}</stderr>\n')

        if spec.is_pure_serial():
            if spec[0].is_exclusive() in [True, None]:
                sio.write(indent * space + '<nodes>1:ppn=2</nodes>\n')
            else:
                sio.write(indent * space + '<cores>1</cores>\n')
        elif spec.is_pure_openmp():
            # Pure threaded.  Treat as exclusive serial.
            sio.write(indent * space + '<nodes>1:ppn=2</nodes>\n')
        else:
            # This is an MPI program.

            # Split into (nodes,ranks_per_node) pairs.  Ignore differing
            # executables between ranks while merging them (del_exe):
            nodes_ranks = self.nodes.to_nodes_ppn(
                spec, can_merge_ranks=self.nodes.same_except_exe)

            sio.write(indent*space+'<nodes>' \
                + '+'.join([f'{n}:ppn={p}' for n,p in nodes_ranks ]) \
                + '</nodes>\n')
        ret = sio.getvalue()
        sio.close()
        return ret
Example #5
0
 def batch_accounting(self, *args, **kwargs):
     spec = tools.make_dict_from(args, kwargs)
     space = self.indent_text
     sio = StringIO()
     if 'queue' in spec:
         sio.write(f'#BSUB -q {spec["queue"]!s}\n')
     if 'project' in spec:
         sio.write(f'#BSUB -P {spec["project"]!s}\n')
     if 'account' in spec:
         sio.write(f'#BSUB -P {spec["account"]!s}\n')
     if 'jobname' in spec:
         sio.write(f'#BSUB -J {spec["jobname"]!s}\n')
     self._batch_stdout_stderr(spec, sio)
     ret = sio.getvalue()
     sio.close()
     return ret
Example #6
0
 def rocoto_accounting(self, *args, indent=0, **kwargs):
     spec = tools.make_dict_from(args, kwargs)
     space = self.indent_text
     sio = StringIO()
     if 'queue' in spec:
         sio.write(f'{indent*space}<queue>{spec["queue"]!s}</queue>\n')
     if 'account' in spec:
         sio.write(
             f'{indent*space}<account>{spec["account"]!s}</account>\n')
     if 'project' in spec:
         sio.write(
             f'{indent*space}<account>{spec["project"]!s}</account>\n')
     if 'account' in spec:
         sio.write(
             f'{indent*space}<account>{spec["account"]!s}</account>\n')
     if 'jobname' in spec:
         sio.write(
             f'{indent*space}<jobname>{spec["jobname"]!s}</jobname>\n')
     self._rocoto_stdout_stderr(spec, indent, space, sio)
     ret = sio.getvalue()
     sio.close()
     return ret