Example #1
0
    def __parse_chunk_size__(chunk_size):
        # type: (str) -> int
        """ Parses chunk size as string and returns its value as integer.

        :param chunk_size: Chunk size as string.
        :return: Chunk size as integer.
        :raises PyCOMPSsException: Can not cast string to int error.
        """
        # Check if it is an environment variable to be loaded
        if chunk_size.strip().startswith("$"):
            # Chunk size is an ENV variable, load it
            env_var = chunk_size.strip()[1:]  # Remove $
            if env_var.startswith("{"):
                env_var = env_var[1:-1]  # remove brackets
            try:
                parsed_chunk_size = int(os.environ[env_var])
            except ValueError:
                raise PyCOMPSsException(cast_env_to_int_error(CHUNK_SIZE))
        else:
            # ChunkSize is in string form, cast it
            try:
                parsed_chunk_size = int(chunk_size)
            except ValueError:
                raise PyCOMPSsException(cast_string_to_int_error(CHUNK_SIZE))
        return parsed_chunk_size
Example #2
0
    def __init__(self, *args, **kwargs):
        """
        Store arguments passed to the decorator
        # self = itself.
        # args = not used.
        # kwargs = dictionary with the given COMPSs parameters

        :param args: Arguments
        :param kwargs: Keyword arguments
        """
        self.args = args
        self.kwargs = kwargs
        self.registered = False
        self.scope = context.in_pycompss()
        if self.scope:
            if __debug__:
                logger.debug("Init @compss decorator...")

            # Check the arguments
            check_arguments(MANDATORY_ARGUMENTS,
                            DEPRECATED_ARGUMENTS,
                            SUPPORTED_ARGUMENTS | DEPRECATED_ARGUMENTS,
                            list(kwargs.keys()),
                            "@compss")

            # Get the computing nodes: This parameter will have to go down
            # until execution when invoked.
            if 'computing_nodes' not in self.kwargs and \
                    'computingNodes' not in self.kwargs:
                self.kwargs['computing_nodes'] = 1
            else:
                if 'computingNodes' in self.kwargs:
                    self.kwargs['computing_nodes'] = \
                        self.kwargs.pop('computingNodes')
                computing_nodes = self.kwargs['computing_nodes']
                if isinstance(computing_nodes, int):
                    # Nothing to do
                    pass
                elif isinstance(computing_nodes, str):
                    # Check if it is an environment variable to be loaded
                    if computing_nodes.strip().startswith('$'):
                        # Computing nodes is an ENV variable, load it
                        env_var = computing_nodes.strip()[1:]  # Remove $
                        if env_var.startswith('{'):
                            env_var = env_var[1:-1]  # remove brackets
                        try:
                            self.kwargs['computing_nodes'] = \
                                int(os.environ[env_var])
                        except ValueError:
                            raise Exception(
                                cast_env_to_int_error('ComputingNodes'))
                    else:
                        # ComputingNodes is in string form, cast it
                        try:
                            self.kwargs['computing_nodes'] = \
                                int(computing_nodes)
                        except ValueError:
                            raise Exception(
                                cast_string_to_int_error('ComputingNodes'))
                else:
                    raise Exception("ERROR: Wrong Computing Nodes value at" +
                                    " @COMPSs decorator.")
            if __debug__:
                logger.debug("This COMPSs task will have " +
                             str(self.kwargs['computing_nodes']) +
                             " computing nodes.")
        else:
            pass
Example #3
0
def test_err_msgs_cast_string_to_int_error():
    what = DECORATOR_NAME
    expected = "ERROR: %s value cannot be cast from string to int" % what
    error = cast_string_to_int_error(what=what)
    assert error == expected, "Received wrong Cast string to int error message."
Example #4
0
def test_err_msgs_cast_string_to_int_error():
    what = "@unittest"
    expected = "ERROR: %s value cannot be cast from string to int" % what
    error = cast_string_to_int_error(what=what)
    assert error == expected,\
        "Received wrong error message."