Ejemplo n.º 1
0
    def resolve(self):
        """
        Return a copy of the original object wrapped by this :class:`Proxy`.

        :rtype: object
        """
        data = serialize((RESOLVE, self.capsule, None, None, None))
        result = rpc(self.owner, data)
        return deserialize(result)
Ejemplo n.º 2
0
    def __getattr__(self, name):
        """
        Get a copy of a remote attribute.

        :param name: the attribute name
        :type name: string
        """
        data = serialize((GETATTR, self.capsule, name, None, None))
        result = rpc(self.owner, data)
        answer = deserialize(result)
        return answer
Ejemplo n.º 3
0
    def broadcast(self, obj, from_rank=0):
        """
        Broadcast copies of the given object. This is a collective operation.

        :param obj: the object to be copied.
        :type obj: object
        :param from_rank: the thread wishing to copy `obj`.
        :type from_rank: int
        :returns: A copy of the given object.
        """
        data = serialize(obj) if self.myrank() == from_rank else None
        answer = gasnet.broadcast(self._team_id, data, from_rank)
        return deserialize(answer)
Ejemplo n.º 4
0
    def __setattr__(self, name, value):
        """
        Set a remote attribute to a copy of a local object.

        :param name: the attribute name
        :type name: string
        :param value: the new attribute value
        :type value: object
        :rtype: None
        """
        data = serialize((SETATTR, self.capsule, name, [value], None))
        result = rpc(self.owner, data)
        return deserialize(result)
Ejemplo n.º 5
0
    def __call__(self, *args, **kwargs):
        """
        Invoke the `__call__` method on the original object and
        return a copy of the result.

        :param args: positional arguments
        :type args: tuple
        :param kwargs: keyword arguments
        :type args: dictionary
        :rtype: object
        """
        data = serialize((CALL, self.capsule, '__call__', args, kwargs))
        result = rpc(self.owner, data)
        return deserialize(result)
Ejemplo n.º 6
0
def _rpc_handler(data):
    """
    This handler is invoked asynchronously on remote interpreters to implement
    one-sided operations.
    """
    op, capsule, name, args, kwargs = deserialize(data)
    obj = gasnet._capsule_to_obj(capsule) if capsule else __builtins__
    if op is GETATTR:
        result = getattr(obj,name)
    elif op is SETATTR:
        result = setattr(obj, name, args[0])
    elif op is CALL:
        result = getattr(obj,name)(*args,**kwargs)
    elif op is RESOLVE:
        result = obj
    else:
        raise NotImplementedError("Cannot apply op: %s" % op)
    return serialize(result)