Example #1
0
    def __init__(self, comm, seed, N):

        RandomState.__init__(self, seed=seed)

        # the number of seeds to generate N particles
        n_seeds = N // N_PER_SEED
        if N % N_PER_SEED: n_seeds += 1

        self.comm = comm
        self.global_seed = seed
        self.N = N

        start = N * comm.rank // comm.size
        stop = N * (comm.rank + 1) // comm.size
        self.size = stop - start

        # generate the full set of seeds from the global seed
        rng = numpy.random.RandomState(seed=seed)
        self._seeds = rng.randint(0, high=0xffffffff, size=n_seeds)

        # sizes of each chunk
        sizes = [N_PER_SEED] * (N // N_PER_SEED)
        if N % N_PER_SEED: sizes.append(N % N_PER_SEED)

        # the local chunks this rank is responsible for
        cumsizes = numpy.insert(numpy.cumsum(sizes), 0, 0)
        chunk_range = numpy.searchsorted(cumsizes[1:], [start, stop])
        self._chunks = list(range(chunk_range[0], chunk_range[1] + 1))

        # and the slices for each local chunk
        self._slices = []
        for chunk in self._chunks:
            start_size = cumsizes[chunk]
            sl = (max(start - start_size,
                      0), min(stop - start_size, sizes[chunk]))
            self._slices.append(sl)
Example #2
0
 def __init__(self, seed=None):
     RandomState.__init__(self, seed)
     self.constants = Constants()
Example #3
0
 def __init__(self, seed):
     RandomState.__init__(self, seed)