Exemplo n.º 1
0
    def get_distrib_idxs(self):
        """ component declares the local sizes and sets initial values
        for all distributed inputs and outputs"""

        comm = self.mpi.comm
        rank = comm.rank

        self.sizes, self.offsets = evenly_distrib_idxs(comm.size, self.arr_size)
        start = self.offsets[rank]
        end = start + self.sizes[rank]

        #need to re-initialize the variable to have the correct local size
        self.invec = np.ones(self.sizes[rank], dtype=float)
        self.local_outvec = np.empty(self.sizes[rank], dtype=float)

        return {
            'invec': make_idx_array(start, end),
            'outvec': make_idx_array(start, end)
        }
Exemplo n.º 2
0
    def get_distrib_idxs(self):
        """ component declares the local sizes and sets initial values
        for all distributed inputs and outputs. Returns a dict of
        index arrays keyed to variable names.
        """

        comm = self.mpi.comm
        rank = comm.rank

        sizes, offsets = evenly_distrib_idxs(comm.size, self.arr_size)
        start = offsets[rank]
        end = start + sizes[rank]

        self.invec = np.ones(sizes[rank], dtype=float)
        self.outvec = np.ones(sizes[rank], dtype=float)

        return {
            'invec': make_idx_array(start, end),
            'outvec': make_idx_array(start, end)
        }
Exemplo n.º 3
0
 def indices(self, system, name):
     """Return the index array corresponding to a single name."""
     if name not in self._info:
         scope = system.scope
         if isinstance(name, basestring):
             name = scope.name2collapsed[name]
         if name[0].split('[',1)[0] in self._info:
             self._add_subview(scope, name)
             self._add_tuple_members(system, [name])
     _, start, _, size, _ = self._info[name]
     return make_idx_array(start, start+size)
Exemplo n.º 4
0
def merge_idxs(src_idxs, dest_idxs):
    """Return source and destination index arrays, built up from
    smaller index arrays and combined in order of ascending source
    index (to allow us to convert src indices to a slice in some cases).
    """
    assert(len(src_idxs) == len(dest_idxs))

    # filter out any zero length idx array entries
    src_idxs = [i for i in src_idxs if len(i)]
    dest_idxs = [i for i in dest_idxs if len(i)]

    if len(src_idxs) == 0:
        return make_idx_array(0, 0), make_idx_array(0,0)

    src_tups = list(enumerate(src_idxs))

    src_sorted = sorted(src_tups, key=lambda x: x[1].min())

    new_src = [idxs for i, idxs in src_sorted]
    new_dest = [dest_idxs[i] for i,_ in src_sorted]

    return idx_merge(new_src), idx_merge(new_dest)
Exemplo n.º 5
0
    def get_distrib_idxs(self):
        """ component declares the local sizes and sets initial values
        for all distributed inputs and outputs"""

        comm = self.mpi.comm
        rank = comm.rank

        #need to re-initialize the variable to have the correct local size
        if rank == 0:
            size = 8
            start = 0
            end = 8
        else:
            size = 7
            start = 4
            end = 11

        self.invec = np.ones(size, dtype=float)
        self.local_outvec = np.empty(size, dtype=float)

        return {
            'invec': make_idx_array(start, end),
            'outvec': make_idx_array(start, end)
        }