def compss_wait_on(obj, to_write = True):
    #print "Waiting on", obj
    if to_write:
        mode = 'r+'
    else:
        mode = 'r'
    compss_mode = get_compss_mode(mode)
    return synchronize(obj, compss_mode)
Example #2
0
def compss_open(file_name, mode='r'):
    """
    Open a file -> Calls runtime.
    @param file_name: File name.
    @param mode: Open mode. Options = [w, r+ or a , r or empty]. Default = r
    @return: An object of 'file' type.
    @raise IOError: If the file can not be opened.
    """
    compss_mode = get_compss_mode(mode)
    compss_name = get_file(file_name, compss_mode)
    return open(compss_name, mode)
Example #3
0
        def _compss_wait_on(obj, to_write=False):
            """
            Waits on an object.

            :param obj: Object to wait on.
            :param to_write: Write enable?. Options = [True, False]. Default = True
            :return: An object of 'file' type.
            """

            # print("Waiting on", obj)
            if to_write:
                mode = 'r+'
            else:
                mode = 'r'
            compss_mode = get_compss_mode(mode)

            # Private function used below (recursively)
            def wait_on_iterable(iter_obj):
                """
                Wait on an iterable object.
                Currently supports lists and dictionaries (syncs the values).
                :param iter_obj: iterable object
                :return: synchronized object
                """
                # check if the object is in our pending_to_synchronize dictionary
                from pycompss.runtime.binding import get_object_id
                obj_id = get_object_id(iter_obj)
                if obj_id in pending_to_synchronize:
                    return synchronize(iter_obj, compss_mode)
                else:
                    if type(iter_obj) == list:
                        return [wait_on_iterable(x) for x in iter_obj]
                    elif type(iter_obj) == dict:
                        return {
                            k: wait_on_iterable(v)
                            for k, v in iter_obj.items()
                        }
                    else:
                        return synchronize(iter_obj, compss_mode)

            if isinstance(obj, Future) or not (isinstance(obj, listType)
                                               or isinstance(obj, dictType)):
                return synchronize(obj, compss_mode)
            else:
                if len(obj) == 0:  # FUTURE OBJECT
                    return synchronize(obj, compss_mode)
                else:
                    # Will be a iterable object
                    res = wait_on_iterable(obj)
                    return res
Example #4
0
    def _compss_wait_on(obj, to_write=False):
        """
        Waits on an object.
        @param obj: Object to wait on.
        @param to_write: Write enable?. Options = [True, False]. Default = True
        @return: An object of 'file' type.
        """
        # print "Waiting on", obj
        if to_write:
            mode = 'r+'
        else:
            mode = 'r'
        compss_mode = get_compss_mode(mode)

        pending_to_synchronize = get_pending_to_synchronize()

        # Private function used below (recursively)
        def wait_on_list(l):
            # check if the object is in our pending_to_synchronize dictionary
            from pycompss.runtime.binding import get_object_id
            obj_id = get_object_id(l)
            if obj_id in pending_to_synchronize:
                return synchronize(l, compss_mode)
            else:
                if type(l) == list:
                    return [wait_on_list(x) for x in l]
                else:
                    return synchronize(l, compss_mode)

        if isinstance(obj, Future) or not isinstance(obj, types.ListType):
            return synchronize(obj, compss_mode)
        else:
            if len(obj) == 0:  # FUTURE OBJECT
                return synchronize(obj, compss_mode)
            else:
                # Will be a List
                res = wait_on_list(obj)
                return res
def compss_open(file_name, mode = 'r'):
    compss_mode = get_compss_mode(mode)
    compss_name = get_file(file_name, compss_mode)
    return open(compss_name, mode)