def __evaluate_fail_by_exit_value__(fail_by_exit_value): context.set_pycompss_context(context.MASTER) kwargs = { "decorator_name": DECORATOR_NAME, "fail_by_exit_value": fail_by_exit_value } resolve_fail_by_exit_value(kwargs) my_deco = PyCOMPSsDecorator(**kwargs) context.set_pycompss_context(context.OUT_OF_SCOPE) assert my_deco.kwargs["fail_by_exit_value"] == str( fail_by_exit_value), "Wrong fail_by_exit_value value (%s != %s)" % ( my_deco.kwargs["fail_by_exit_value"], str(fail_by_exit_value))
def test_decorator_resolve_fail_by_exit_value_exception(): context.set_pycompss_context(context.MASTER) fail_by_exit_value = [1, 2] # any object kwargs = { "decorator_name": DECORATOR_NAME, "fail_by_exit_value": fail_by_exit_value } raised = False try: resolve_fail_by_exit_value(kwargs) except Exception: # noqa raised = True _ = PyCOMPSsDecorator(**kwargs) context.set_pycompss_context(context.OUT_OF_SCOPE) assert ( raised), "Expected exception with wrong fail_by_exit_value not raised."
def __configure_core_element__(self, kwargs): # type: (dict) -> None """ Include the registering info related to @mpmd_mpi. IMPORTANT! Updates self.kwargs[CORE_ELEMENT_KEY]. :param kwargs: Keyword arguments received from call. :return: None """ if __debug__: logger.debug("Configuring @mpmd_mpi core element.") # Resolve @mpmd_mpi specific parameters impl_type = "MPMDMPI" runner = self.kwargs[RUNNER] # Resolve the working directory resolve_working_dir(self.kwargs) # Resolve the fail by exit value resolve_fail_by_exit_value(self.kwargs) ppn = str(self.kwargs.get(PROCESSES_PER_NODE, 1)) impl_signature = '.'.join((impl_type, str(ppn))) prog_params = self.__get_programs_params__() impl_args = [ runner, self.kwargs[WORKING_DIR], ppn, self.kwargs[FAIL_BY_EXIT_VALUE] ] impl_args.extend(prog_params) if CORE_ELEMENT_KEY in kwargs: kwargs[CORE_ELEMENT_KEY].set_impl_type(impl_type) kwargs[CORE_ELEMENT_KEY].set_impl_signature(impl_signature) kwargs[CORE_ELEMENT_KEY].set_impl_type_args(impl_args) else: core_element = CE() core_element.set_impl_type(impl_type) core_element.set_impl_signature(impl_signature) core_element.set_impl_type_args(impl_args) kwargs[CORE_ELEMENT_KEY] = core_element # Set as configured self.core_element_configured = True
def __configure_core_element__(self, kwargs): # type: (dict) -> None """ Include the registering info related to @ompss. IMPORTANT! Updates self.kwargs[CORE_ELEMENT_KEY]. :param kwargs: Keyword arguments received from call. :return: None """ if __debug__: logger.debug("Configuring @ompss core element.") # Resolve @ompss specific parameters binary = self.kwargs[BINARY] # Resolve the working directory resolve_working_dir(self.kwargs) # Resolve the fail by exit value resolve_fail_by_exit_value(self.kwargs) impl_type = IMPL_OMPSS impl_signature = "".join((IMPL_OMPSS, ".", binary)) impl_args = [binary, self.kwargs[WORKING_DIR], self.kwargs[FAIL_BY_EXIT_VALUE]] if CORE_ELEMENT_KEY in kwargs: # Core element has already been created in a higher level decorator # (e.g. @constraint) kwargs[CORE_ELEMENT_KEY].set_impl_type(impl_type) kwargs[CORE_ELEMENT_KEY].set_impl_signature(impl_signature) kwargs[CORE_ELEMENT_KEY].set_impl_type_args(impl_args) else: # @binary is in the top of the decorators stack. # Instantiate a new core element object, update it and include # it into kwarg core_element = CE() core_element.set_impl_type(impl_type) core_element.set_impl_signature(impl_signature) core_element.set_impl_type_args(impl_args) kwargs[CORE_ELEMENT_KEY] = core_element # Set as configured self.core_element_configured = True
def __configure_core_element__(self, kwargs): # type: (dict) -> None """ Include the registering info related to @binary. IMPORTANT! Updates self.kwargs[CORE_ELEMENT_KEY]. :param kwargs: Keyword arguments received from call. :return: None """ if __debug__: logger.debug("Configuring @binary core element.") # Resolve the working directory resolve_working_dir(self.kwargs) _working_dir = self.kwargs[WORKING_DIR] # Resolve the fail by exit value resolve_fail_by_exit_value(self.kwargs) _fail_by_ev = self.kwargs[FAIL_BY_EXIT_VALUE] # Resolve binary _binary = str(self.kwargs[BINARY]) if CORE_ELEMENT_KEY in kwargs and \ kwargs[CORE_ELEMENT_KEY].get_impl_type() == IMPL_CONTAINER: # @container decorator sits on top of @binary decorator # Note: impl_type and impl_signature are NOT modified # (IMPL_CONTAINER and "CONTAINER.function_name" respectively) impl_args = kwargs[CORE_ELEMENT_KEY].get_impl_type_args() _engine = impl_args[0] _image = impl_args[1] impl_args = [ _engine, # engine _image, # image IMPL_CET_BINARY, # internal_type _binary, # internal_binary UNASSIGNED, # internal_func _working_dir, # working_dir _fail_by_ev ] # fail_by_ev kwargs[CORE_ELEMENT_KEY].set_impl_type_args(impl_args) else: # @container decorator does NOT sit on top of @binary decorator _binary = str(self.kwargs[BINARY]) impl_type = IMPL_BINARY impl_signature = ".".join((impl_type, _binary)) impl_args = [ _binary, # internal_binary _working_dir, # working_dir self.kwargs.get('params', UNASSIGNED), # params _fail_by_ev ] # fail_by_ev if CORE_ELEMENT_KEY in kwargs: # Core element has already been created in a higher level # decorator (e.g. @constraint) kwargs[CORE_ELEMENT_KEY].set_impl_type(impl_type) kwargs[CORE_ELEMENT_KEY].set_impl_signature(impl_signature) kwargs[CORE_ELEMENT_KEY].set_impl_type_args(impl_args) else: # @binary is in the top of the decorators stack. # Instantiate a new core element object, update it and include # it into kwarg core_element = CE() core_element.set_impl_type(impl_type) core_element.set_impl_signature(impl_signature) core_element.set_impl_type_args(impl_args) kwargs[CORE_ELEMENT_KEY] = core_element # Set as configured self.core_element_configured = True
def __configure_core_element__(self, kwargs): # type: (dict) -> None """ Include the registering info related to @decaf. IMPORTANT! Updates self.kwargs[CORE_ELEMENT_KEY]. :param kwargs: Keyword arguments received from call. :return: None """ if __debug__: logger.debug("Configuring @decaf core element.") # Resolve @decaf specific parameters if RUNNER in self.kwargs: runner = self.kwargs[RUNNER] else: runner = "mpirun" if LEGACY_DF_SCRIPT in self.kwargs: df_script = self.kwargs[LEGACY_DF_SCRIPT] else: df_script = self.kwargs[DF_SCRIPT] if DF_EXECUTOR in self.kwargs: df_executor = self.kwargs[DF_EXECUTOR] elif LEGACY_DF_EXECUTOR in self.kwargs: df_executor = self.kwargs[LEGACY_DF_EXECUTOR] else: df_executor = UNASSIGNED # Empty or UNASSIGNED if DF_LIB in self.kwargs: df_lib = self.kwargs[DF_LIB] elif LEGACY_DF_LIB in self.kwargs: df_lib = self.kwargs[LEGACY_DF_LIB] else: df_lib = UNASSIGNED # Empty or UNASSIGNED # Resolve the working directory resolve_working_dir(self.kwargs) # Resolve the fail by exit value resolve_fail_by_exit_value(self.kwargs) impl_type = IMPL_DECAF impl_signature = ".".join((impl_type, df_script)) impl_args = [ df_script, df_executor, df_lib, self.kwargs[WORKING_DIR], runner, self.kwargs[FAIL_BY_EXIT_VALUE] ] if CORE_ELEMENT_KEY in kwargs: # Core element has already been created in a higher level decorator # (e.g. @constraint) kwargs[CORE_ELEMENT_KEY].set_impl_type(impl_type) kwargs[CORE_ELEMENT_KEY].set_impl_signature(impl_signature) kwargs[CORE_ELEMENT_KEY].set_impl_type_args(impl_args) else: # @binary is in the top of the decorators stack. # Instantiate a new core element object, update it and include # it into kwarg core_element = CE() core_element.set_impl_type(impl_type) core_element.set_impl_signature(impl_signature) core_element.set_impl_type_args(impl_args) kwargs[CORE_ELEMENT_KEY] = core_element # Set as configured self.core_element_configured = True
def __configure_core_element__(self, kwargs): # type: (dict) -> None """ Include the registering info related to @compss. IMPORTANT! Updates self.kwargs[CORE_ELEMENT_KEY]. :param kwargs: Keyword arguments received from call. :return: None """ if __debug__: logger.debug("Configuring @compss core element.") # Resolve @compss specific parameters if RUNCOMPSS in self.kwargs: runcompss = self.kwargs[RUNCOMPSS] else: runcompss = UNASSIGNED # Empty or UNASSIGNED if FLAGS in self.kwargs: flags = self.kwargs[FLAGS] else: flags = UNASSIGNED # Empty or UNASSIGNED if WORKER_IN_MASTER in self.kwargs: worker_in_master = self.kwargs[WORKER_IN_MASTER] elif LEGACY_WORKER_IN_MASTER in self.kwargs: worker_in_master = self.kwargs[LEGACY_WORKER_IN_MASTER] else: worker_in_master = "true" # Empty or UNASSIGNED if LEGACY_APP_NAME in self.kwargs: app_name = self.kwargs[LEGACY_APP_NAME] else: app_name = self.kwargs[APP_NAME] # Resolve the working directory resolve_working_dir(self.kwargs) # Resolve the fail by exit value resolve_fail_by_exit_value(self.kwargs) impl_type = IMPL_COMPSs impl_signature = ".".join((impl_type, app_name)) impl_args = [ runcompss, flags, app_name, worker_in_master, self.kwargs[WORKING_DIR], self.kwargs[FAIL_BY_EXIT_VALUE] ] if CORE_ELEMENT_KEY in kwargs: # Core element has already been created in a higher level decorator # (e.g. @constraint) kwargs[CORE_ELEMENT_KEY].set_impl_type(impl_type) kwargs[CORE_ELEMENT_KEY].set_impl_signature(impl_signature) kwargs[CORE_ELEMENT_KEY].set_impl_type_args(impl_args) else: # @binary is in the top of the decorators stack. # Instantiate a new core element object, update it and include # it into kwarg core_element = CE() core_element.set_impl_type(impl_type) core_element.set_impl_signature(impl_signature) core_element.set_impl_type_args(impl_args) kwargs[CORE_ELEMENT_KEY] = core_element # Set as configured self.core_element_configured = True
def __configure_core_element__(self, kwargs): # type: (dict) -> None """ Include the registering info related to @mpi. IMPORTANT! Updates self.kwargs[CORE_ELEMENT_KEY]. :param kwargs: Keyword arguments received from call. :return: None """ if __debug__: logger.debug("Configuring @mpi core element.") # Resolve @mpi specific parameters if BINARY in self.kwargs: binary = self.kwargs[BINARY] impl_type = IMPL_MPI else: binary = UNASSIGNED impl_type = IMPL_PYTHON_MPI self.task_type = impl_type runner = self.kwargs[RUNNER] if FLAGS in self.kwargs: flags = self.kwargs[FLAGS] else: flags = UNASSIGNED # Empty or UNASSIGNED # Check if scale by cu is defined scale_by_cu_str = self.__resolve_scale_by_cu__() # Resolve the working directory resolve_working_dir(self.kwargs) # Resolve the fail by exit value resolve_fail_by_exit_value(self.kwargs) # Resolve parameter collection layout collection_layout_params = self.__resolve_collection_layout_params__() if "processes" in self.kwargs: proc = self.kwargs["processes"] elif "computing_nodes" in self.kwargs: proc = self.kwargs["computing_nodes"] elif "computingNodes" in self.kwargs: proc = self.kwargs["computingNodes"] else: proc = "1" if "processes_per_node" in self.kwargs: ppn = str(self.kwargs["processes_per_node"]) else: ppn = "1" if binary == UNASSIGNED: impl_signature = impl_type + '.' else: impl_signature = '.'.join((impl_type, str(proc), binary)) impl_args = [ binary, self.kwargs[WORKING_DIR], runner, ppn, flags, scale_by_cu_str, self.kwargs.get("params", UNASSIGNED), self.kwargs[FAIL_BY_EXIT_VALUE] ] if impl_type == IMPL_PYTHON_MPI: impl_args = impl_args + collection_layout_params if CORE_ELEMENT_KEY in kwargs: # Core element has already been created in a higher level decorator # (e.g. @constraint) kwargs[CORE_ELEMENT_KEY].set_impl_type(impl_type) kwargs[CORE_ELEMENT_KEY].set_impl_signature(impl_signature) kwargs[CORE_ELEMENT_KEY].set_impl_type_args(impl_args) else: # @binary is in the top of the decorators stack. # Instantiate a new core element object, update it and include # it into kwarg core_element = CE() core_element.set_impl_type(impl_type) core_element.set_impl_signature(impl_signature) core_element.set_impl_type_args(impl_args) kwargs[CORE_ELEMENT_KEY] = core_element # Set as configured self.core_element_configured = True