def __init__(self, *args, **kwargs): """ Store arguments passed to the decorator # self = itself. # args = not used. # kwargs = dictionary with the given ompss parameters :param args: Arguments :param kwargs: Keyword arguments """ self.args = args self.kwargs = kwargs self.scope = i_am_within_scope() if self.scope: if __debug__: logger.debug("Init @ompss 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: cNs = kwargs['computingNodes'] if isinstance(cNs, int): self.kwargs['computingNodes'] = kwargs['computingNodes'] elif isinstance(cNs, str) and cNs.strip().startswith('$'): envVar = cNs.strip()[1:] # Remove $ if envVar.startswith('{'): envVar = envVar[1:-1] # remove brackets self.kwargs['computingNodes'] = int(os.environ[envVar]) else: raise Exception("Wrong Computing Nodes value at MPI decorator.") if __debug__: logger.debug("This OMPSs task will have " + str(self.kwargs['computingNodes']) + " computing nodes.") else: pass
def local(input_function): if not i_am_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
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 = i_am_within_scope() if self.scope and __debug__: logger.debug("Init @implement decorator...")
def __init__(self, *args, **kwargs): """ If there are decorator arguments, the function to be decorated is not passed to the constructor! """ from pycompss.util.location import i_am_within_scope # Check if under the PyCOMPSs scope if i_am_within_scope(): from pycompss.util.location import i_am_at_master from pycompss.api.parameter import IN self.scope = True if __debug__: logger.debug("Init @task decorator...") # Defaults self.args = args # Not used self.kwargs = kwargs # The only ones actually used: (decorators) # Pre-process decorator arguments # Reserved PyCOMPSs keywords and default values reserved_keywords = { 'isModifier': True, 'returns': False, 'priority': False, 'isReplicated': False, 'isDistributed': False, 'varargsType': IN } # Set reserved keyword default values in self.kwargs for (reserved_keyword, default_value) in reserved_keywords.items(): if reserved_keyword not in self.kwargs: self.kwargs[reserved_keyword] = default_value # Remove old args for old_vararg in [ x for x in self.kwargs.keys() if x.startswith('*args') ]: self.kwargs.pop(old_vararg) if i_am_at_master(): for arg_name in self.kwargs.keys(): if arg_name not in reserved_keywords.keys(): # Prevent p.value from being overwritten later by ensuring # each Parameter is a separate object p = self.kwargs[arg_name] pcopy = copy.copy(p) # shallow copy self.kwargs[arg_name] = pcopy if __debug__: logger.debug("Init @task decorator finished.") else: # Not under the PyCOMPSs scope self.scope = False # Defaults self.args = args self.kwargs = kwargs