Example #1
0
def main(argv):
    experiment.name('nbody')
    logger.log('# Experiment: {}'.format(experiment.name()))

    prun = host.whichl(['srun', 'mpiexec'])
    if prun is None:
        sys.exit('Cannot find a parallel launcher...')
    app = '/nbody/nbody-mpi'

    # The seemingly strange use of {{}} allows us to first format the string
    # with arguments (the {}) and then generate strings with values passed to -n
    # from the output of range() (the {{}}).
    runcmds = experiment.generate('{} -n {{}}'.format(prun), range(1, 3))

    etimes = list()
    for r in runcmds:
        stime = utils.now()
        # TODO(skg) FIXME
        container.prun(r, app)
        etime = utils.now()

        telapsed = etime - stime
        etimes.append(telapsed)
        logger.log(F'# Execution Time: {telapsed}\n')
        # Take a break between runs.
        time.sleep(1)

    logger.log('# Report')
    logger.log('# Command, Execution Time')
    for i in zip(runcmds, etimes):
        logger.log('{}, {}'.format(*i))
Example #2
0
def _runi(cmds: List[str],
          echo: bool = True,
          preaction: ActionCb = None,
          postaction: ActionCb = None,
          user_data: Any = None) -> None:
    '''
    Private run dispatch.
    '''
    capture = postaction is not None

    cmdstr = ' '.join(cmds)

    if preaction is not None:
        preargs = {'command': cmdstr, 'user_data': user_data}
        preaction(**preargs)

    stime = utils.now()
    coutput = cntrimg.activator().run(cmds, echo=echo, capture=capture)
    etime = utils.now()

    if postaction is not None:
        postargs = {
            'command': cmdstr,
            'exectime': etime - stime,
            'output': coutput,
            'user_data': user_data
        }
        postaction(**postargs)
Example #3
0
    def start(self) -> None:
        logger.emlog('# Starting {} at {}'.format(self.prog, utils.nows()))
        logger.log('# $ {}\n'.format(' '.join(sys.argv)))

        try:
            stime = utils.now()
            self._emit_config()
            self._do_build()
            etime = utils.now()

            logger.log('# {} Time {}'.format(self.prog, etime - stime))
            logger.log('# {} Done {}'.format(self.prog, utils.nows()))
        except Exception as exception:
            estr = utils.ehorf()
            estr += 'What: {} error encountered.\n' \
                'Why:  {}'.format(self.prog, exception)
            estr += utils.ehorf()
            raise type(exception)(estr) from exception
Example #4
0
def _runi(  # pylint: disable=too-many-arguments
        cmds: List[str],
        echo: bool = True,
        check_exit_code: bool = True,
        preaction: ActionCb = None,
        postaction: ActionCb = None,
        user_data: Any = None
) -> None:
    '''
    Private run dispatch.
    '''
    capture_output = postaction is not None

    cmdstr = ' '.join(cmds)

    if preaction is not None:
        preargs = {
            'command': cmdstr,
            'user_data': user_data
        }
        preaction(**preargs)

    stime = utils.now()
    coutput = cntrimg.activator().run(
        cmds,
        echo=echo,
        capture=capture_output,
        check_exit_code=check_exit_code
    )
    etime = utils.now()

    if postaction is not None:
        postargs = {
            'command': cmdstr,
            'start_time': stime,
            'end_time': etime,
            'exectime': (etime - stime).total_seconds(),
            'output': coutput,
            'user_data': user_data
        }
        postaction(**postargs)
Example #5
0
    def start(self) -> None:
        logger.emlog(F'# Starting {self.prog} at {utils.nows()}')
        logger.log(F"# $ {' '.join(sys.argv)}\n")

        try:
            stime = utils.now()
            self._emit_config()
            self._build_image_activator()
            self._stage_container_image()
            self._add_container_metadata()
            self._run()
            etime = utils.now()

            logger.log(F'# {self.prog} Time {etime - stime}')
            logger.log(F'# {self.prog} Done {utils.nows()}')

            self._write_metadata()
        except Exception as exception:
            estr = utils.ehorf()
            estr += F'What: {self.prog} error encountered.\n' \
                    F'Why:  {exception}'
            estr += utils.ehorf()
            raise type(exception)(estr)