Example #1
0
    def _GetTarget(self, context):
        """Return a target instance suitable to run the test executable.
        The choice of implementations is determined from the current context.

        The global context may have provided a 'CompilationTest.target' variable 
        to indicate the Host subclass to use. In addition, we consider the
        value of the 'ParallelActivator.num_processors' variable that may have
        been set by the ParallelActivator resource.

        If a value of num_processors > 1 is requested, we attempt to run the 
        executable using a command determined from the 'par_service.run' 
        variable. (This is typically 'mpirun'.)

        If the requested target is LocalHost, we replace it
        by CommandHost (which was designed precisely for such use-cases).

        If it is a CommandHost or any other host instance that is known
        to support injecting commands, we attempt to modify its arguments
        appropriately.

        Requesting num_processors > 1 with an unsupported host is an error
        and yields an exception."""

        # We can't use a regular import for LocalHost, as that wouldn't
        # match the type found via 'get_extension_class'.
        local_host = get_extension_class('local_host.LocalHost', 'host',
                                         get_database())
        target_desc = context.get('CompilationTest.target')
        if target_desc is None:
            host_class, arguments = local_host, {}
        else:
            f = lambda n: get_extension_class(n, 'host', get_database())
            host_class, arguments = parse_descriptor(target_desc.strip(), f)
        num_processors = context.get('ParallelActivator.num_processors', 1)

        if num_processors > 1:
            if host_class is local_host:
                host_class = CommandHost
                arguments['command'] = context.get('par_service.run')
                arguments['command_args'] = ['-np', str(num_processors)]
            elif host_class is CommandHost:
                # Assume that the command is required to invoke any
                # executable on this machine. Prepend the mpirun command
                # simply as an argument in that case.
                arguments['command_args'] = [
                    context.get('par_service.run'), '-np',
                    str(num_processors)
                ]

            elif host_class is RemoteHost:
                pass  # ...
            else:
                raise Exception(
                    'target "%s" does not support parallel execution' %
                    target_desc)

            path = context.get('par_service.run')

        return host_class(arguments)
Example #2
0
    def _GetTarget(self, context):
        """Return a target instance suitable to run the test executable.
        The choice of implementations is determined from the current context.

        The global context may have provided a 'CompilationTest.target' variable 
        to indicate the Host subclass to use. In addition, we consider the
        value of the 'ParallelActivator.num_processors' variable that may have
        been set by the ParallelActivator resource.

        If a value of num_processors > 1 is requested, we attempt to run the 
        executable using a command determined from the 'par_service.run' 
        variable. (This is typically 'mpirun'.)

        If the requested target is LocalHost, we replace it
        by CommandHost (which was designed precisely for such use-cases).

        If it is a CommandHost or any other host instance that is known
        to support injecting commands, we attempt to modify its arguments
        appropriately.

        Requesting num_processors > 1 with an unsupported host is an error
        and yields an exception."""




        # We can't use a regular import for LocalHost, as that wouldn't
        # match the type found via 'get_extension_class'.
        local_host = get_extension_class('local_host.LocalHost', 'host', get_database())
        target_desc = context.get('CompilationTest.target')
        if target_desc is None:
            host_class, arguments = local_host, {}
        else:
            f = lambda n: get_extension_class(n, 'host', get_database())
            host_class, arguments = parse_descriptor(target_desc.strip(), f)
        num_processors = context.get('ParallelActivator.num_processors', 1)

        if num_processors > 1:
            if host_class is local_host:
                host_class = CommandHost
                arguments['command'] = context.get('par_service.run')
                arguments['command_args'] = ['-np', str(num_processors)]
            elif host_class is CommandHost:
                # Assume that the command is required to invoke any
                # executable on this machine. Prepend the mpirun command
                # simply as an argument in that case.
                arguments['command_args'] = [context.get('par_service.run'),
                                             '-np', str(num_processors)]

            elif host_class is RemoteHost:
                pass # ...
            else:
                raise Exception('target "%s" does not support parallel execution'%target_desc)

            path = context.get('par_service.run')

        return host_class(arguments)
def _get_host(context, variable):
    """Get a host instance according to a particular context variable.
    Return a default 'LocalHost' host if the variable is undefined.

    'context' -- The context to read the host descriptor from.

    'variable' -- The name to which the host descriptor is bound.

    returns -- A Host instance.

    """

    target_desc = context.get(variable)
    if target_desc is None:
        target = LocalHost({})
    else:
        f = lambda n: get_extension_class(n, "host", get_database())
        host_class, arguments = parse_descriptor(target_desc.strip(), f)
        target = host_class(arguments)
    return target
def _get_host(context, variable):
    """Get a host instance according to a particular context variable.
    Return a default 'LocalHost' host if the variable is undefined.

    'context' -- The context to read the host descriptor from.

    'variable' -- The name to which the host descriptor is bound.

    returns -- A Host instance.

    """

    target_desc = context.get(variable)
    if target_desc is None:
        target = LocalHost({})
    else:
        f = lambda n: get_extension_class(n, "host", get_database())
        host_class, arguments = parse_descriptor(target_desc.strip(), f)
        target = host_class(arguments)
    return target