コード例 #1
0
    def __init__(self, *args, **kwargs):
        """
        Store arguments passed to the decorator
        # self = itself.
        # args = not used.
        # kwargs = dictionary with the given implement parameters.

        :param args: Arguments
        :param kwargs: Keyword arguments
        """

        self.args = args
        self.kwargs = kwargs
        self.scope = within_scope()
        if self.scope and __debug__:
            logger.debug("Init @implement decorator...")
コード例 #2
0
    def __init__(self, *args, **kwargs):
        """
        Store arguments passed to the decorator
        # self = itself.
        # args = not used.
        # kwargs = dictionary with the given constraints.

        :param args: Arguments
        :param kwargs: Keyword arguments
        """

        self.args = args
        self.kwargs = kwargs
        self.scope = within_scope()
        if self.scope:
            if __debug__:
                logger.debug("Init @decaf decorator...")

            # Get the computing nodes: This parameter will have to go down
            # until execution when invoked.
            if 'computingNodes' not in self.kwargs:
                self.kwargs['computingNodes'] = 1
            else:
                computing_nodes = kwargs['computingNodes']
                if isinstance(computing_nodes, int):
                    self.kwargs['computingNodes'] = kwargs['computingNodes']
                elif isinstance(
                        computing_nodes,
                        str) and computing_nodes.strip().startswith('$'):
                    env_var = computing_nodes.strip()[1:]  # Remove $
                    if env_var.startswith('{'):
                        env_var = env_var[1:-1]  # remove brackets
                    self.kwargs['computingNodes'] = int(os.environ[env_var])
                else:
                    raise Exception(
                        "Wrong Computing Nodes value at DECAF decorator.")
            if __debug__:
                logger.debug("This DECAF task will have " +
                             str(self.kwargs['computingNodes']) +
                             " computing nodes.")
        else:
            pass
コード例 #3
0
def local(input_function):
    """
    Local decorator

    :param input_function: Input function
    :return: Wrapped function
    """

    if not within_scope():

        # Return dummy local decorator
        def wrapped_function(*args, **kwargs):
            return input_function(*args, **kwargs)

        return wrapped_function

    else:

        from pycompss.runtime.binding import get_object_id, pending_to_synchronize

        def must_sync(obj):
            return get_object_id(obj) in pending_to_synchronize

        def sync_if_needed(obj):
            if must_sync(obj):
                new_val = compss_wait_on(obj)
                replace(obj, new_val)

        def wrapped_function(*args, **kwargs):
            gc.collect()
            _args = []
            _kwargs = {}
            for arg in args:
                sync_if_needed(arg)
                _args.append(arg)
            for (key, value) in kwargs.items():
                sync_if_needed(value)
                _kwargs[key] = value

            return input_function(*_args, **_kwargs)

        return wrapped_function