(self, size_var, lhs, scope, loc)
return out, new_size_var
divides array sizes and assign its sizes/starts/counts attributes
        returns generated nodes and the new size variable to enable update of
        the alloc call.
divides array sizes and assign its sizes/starts/counts attributes
        returns generated nodes and the new size variable to enable update of
        the alloc call.
divides array sizes and assign its sizes / starts / counts attributes returns generated nodes and the new size variable to enable update of the alloc call .
def _run_alloc(self, size_var, lhs, scope, loc):
        """ divides array sizes and assign its sizes/starts/counts attributes
        returns generated nodes and the new size variable to enable update of
        the alloc call.
        """
        out = []
        new_size_var = None

        # size is single int var
        if isinstance(size_var, ir.Var) and isinstance(self.state.typemap[size_var.name], types.Integer):
            self._array_sizes[lhs] = [size_var]
            out, start_var, end_var = self._gen_1D_div(size_var, scope, loc,
                                                       "$alloc", "get_node_portion", distributed_api.get_node_portion)
            self._array_starts[lhs] = [start_var]
            self._array_counts[lhs] = [end_var]
            new_size_var = end_var
            return out, new_size_var

        # tuple variable of ints
        if isinstance(size_var, ir.Var):
            # see if size_var is a 1D array's shape
            # it is already the local size, no need to transform
            var_def = guard(get_definition, self.state.func_ir, size_var)
            oned_varnames = set(v for v in self._dist_analysis.array_dists
                                if self._dist_analysis.array_dists[v] == Distribution.OneD)
            if (isinstance(var_def, ir.Expr) and var_def.op == 'getattr'
                    and var_def.attr == 'shape' and var_def.value.name in oned_varnames):
                prev_arr = var_def.value.name
                self._array_starts[lhs] = self._array_starts[prev_arr]
                self._array_counts[lhs] = self._array_counts[prev_arr]
                self._array_sizes[lhs] = self._array_sizes[prev_arr]
                return out, size_var

            # size should be either int or tuple of ints
            #assert size_var.name in self._tuple_table
            # self._tuple_table[size_var.name]
            size_list = self._get_tuple_varlist(size_var, out)
            size_list = [ir_utils.convert_size_to_var(s, self.state.typemap, scope, loc, out)
                         for s in size_list]
        # tuple of int vars
        else:
            assert isinstance(size_var, (tuple, list))
            size_list = list(size_var)

        self._array_sizes[lhs] = size_list
        gen_nodes, start_var, end_var = self._gen_1D_div(size_list[0], scope, loc,
                                                         "$alloc", "get_node_portion", distributed_api.get_node_portion)
        out += gen_nodes
        ndims = len(size_list)
        new_size_list = copy.copy(size_list)
        new_size_list[0] = end_var
        tuple_var = ir.Var(scope, mk_unique_var("$tuple_var"), loc)
        self.state.typemap[tuple_var.name] = types.containers.UniTuple(
            types.intp, ndims)
        tuple_call = ir.Expr.build_tuple(new_size_list, loc)
        tuple_assign = ir.Assign(tuple_call, tuple_var, loc)
        out.append(tuple_assign)
        self.state.func_ir._definitions[tuple_var.name] = [tuple_call]
        self._array_starts[lhs] = [self._set0_var] * ndims
        self._array_starts[lhs][0] = start_var
        self._array_counts[lhs] = new_size_list
        new_size_var = tuple_var
        return out, new_size_var
def _run_alloc ( self , size_var , lhs , scope , loc ) : out = [ ] new_size_var = None # size is single int var if isinstance ( size_var , ir . Var ) and isinstance ( self . state . typemap [ size_var . name ] , types . Integer ) : self . _array_sizes [ lhs ] = [ size_var ] out , start_var , end_var = self . _gen_1D_div ( size_var , scope , loc , "$alloc" , "get_node_portion" , distributed_api . get_node_portion ) self . _array_starts [ lhs ] = [ start_var ] self . _array_counts [ lhs ] = [ end_var ] new_size_var = end_var return out , new_size_var # tuple variable of ints if isinstance ( size_var , ir . Var ) : # see if size_var is a 1D array's shape # it is already the local size, no need to transform var_def = guard ( get_definition , self . state . func_ir , size_var ) oned_varnames = set ( v for v in self . _dist_analysis . array_dists if self . _dist_analysis . array_dists [ v ] == Distribution . OneD ) if ( isinstance ( var_def , ir . Expr ) and var_def . op == 'getattr' and var_def . attr == 'shape' and var_def . value . name in oned_varnames ) : prev_arr = var_def . value . name self . _array_starts [ lhs ] = self . _array_starts [ prev_arr ] self . _array_counts [ lhs ] = self . _array_counts [ prev_arr ] self . _array_sizes [ lhs ] = self . _array_sizes [ prev_arr ] return out , size_var # size should be either int or tuple of ints #assert size_var.name in self._tuple_table # self._tuple_table[size_var.name] size_list = self . _get_tuple_varlist ( size_var , out ) size_list = [ ir_utils . convert_size_to_var ( s , self . state . typemap , scope , loc , out ) for s in size_list ] # tuple of int vars else : assert isinstance ( size_var , ( tuple , list ) ) size_list = list ( size_var ) self . _array_sizes [ lhs ] = size_list gen_nodes , start_var , end_var = self . _gen_1D_div ( size_list [ 0 ] , scope , loc , "$alloc" , "get_node_portion" , distributed_api . get_node_portion ) out += gen_nodes ndims = len ( size_list ) new_size_list = copy . copy ( size_list ) new_size_list [ 0 ] = end_var tuple_var = ir . Var ( scope , mk_unique_var ( "$tuple_var" ) , loc ) self . state . typemap [ tuple_var . name ] = types . containers . UniTuple ( types . intp , ndims ) tuple_call = ir . Expr . build_tuple ( new_size_list , loc ) tuple_assign = ir . Assign ( tuple_call , tuple_var , loc ) out . append ( tuple_assign ) self . state . func_ir . _definitions [ tuple_var . name ] = [ tuple_call ] self . _array_starts [ lhs ] = [ self . _set0_var ] * ndims self . _array_starts [ lhs ] [ 0 ] = start_var self . _array_counts [ lhs ] = new_size_list new_size_var = tuple_var return out , new_size_var