コード例 #1
0
ファイル: test_mpi.py プロジェクト: ghisvail/pyoperators
 def func(x, xs, op):
     op_py = OP_PY_MAP[op]
     op_mpi = OP_MPI_MAP[op]
     actual = np.empty_like(x)
     comm.Allreduce(as_mpi(x), as_mpi(actual), op=op_mpi)
     expected = op_py(xs)
     assert_equal(actual, expected)
コード例 #2
0
 def func(x, xs, op):
     op_py = OP_PY_MAP[op]
     op_mpi = OP_MPI_MAP[op]
     actual = np.empty_like(x)
     comm.Allreduce(as_mpi(x), as_mpi(actual), op=op_mpi)
     expected = op_py(xs)
     assert_equal(actual, expected)
コード例 #3
0
ファイル: test_mpi.py プロジェクト: ghisvail/pyoperators
 def func(nglobal):
     d = np.array(comm.rank)
     with filter_comm(comm.rank < nglobal, comm) as newcomm:
         if newcomm is not None:
             newcomm.Allreduce(MPI.IN_PLACE, as_mpi(d))
     d = comm.bcast(d)
     n = min(comm.size, nglobal)
     assert d == n * (n - 1) // 2
コード例 #4
0
 def func(nglobal):
     d = np.array(comm.rank)
     with filter_comm(comm.rank < nglobal, comm) as newcomm:
         if newcomm is not None:
             newcomm.Allreduce(MPI.IN_PLACE, as_mpi(d))
     d = comm.bcast(d)
     n = min(comm.size, nglobal)
     assert d == n * (n - 1) // 2
コード例 #5
0
ファイル: acquisition.py プロジェクト: LorenzoMele/qubic
    def get_hitmap(self, nside=None):
        """
        Return a healpy map whose values are the number of times a pointing
        hits the pixel.

        """
        if nside is None:
            nside = self.scene.nside
        ipixel = self.sampling.healpix(nside)
        npixel = 12 * nside**2
        hit = np.histogram(ipixel, bins=npixel, range=(0, npixel))[0]
        self.sampling.comm.Allreduce(MPI.IN_PLACE, as_mpi(hit), op=MPI.SUM)
        return hit
コード例 #6
0
ファイル: acquisition.py プロジェクト: MStolpovskiy/qubic
    def get_hitmap(self, nside=None):
        """
        Return a healpy map whose values are the number of times a pointing
        hits the pixel.

        """
        if nside is None:
            nside = self.scene.nside
        ipixel = self.sampling.healpix(nside)
        npixel = 12 * nside**2
        hit = np.histogram(ipixel, bins=npixel, range=(0, npixel))[0]
        self.sampling.comm.Allreduce(MPI.IN_PLACE, as_mpi(hit), op=MPI.SUM)
        return hit
コード例 #7
0
ファイル: samplings.py プロジェクト: satorchi/pysimulators
    def get_center(self):
        """
        Return the average pointing direction.

        """
        if isscalarlike(self.masked) and self.masked:
            n = 0
            coords = np.zeros((1, 3))
        else:
            coords = self.cartesian
            if not isscalarlike(self.masked):
                valid = 1 - self.masked
                coords *= valid[:, None]
                n = np.sum(valid)
            else:
                n = len(self)
        n = np.asarray(n)
        center = np.sum(coords, axis=0)
        self.comm.Allreduce(MPI.IN_PLACE, as_mpi(n))
        self.comm.Allreduce(MPI.IN_PLACE, as_mpi(center))
        if n == 0:
            raise ValueError('There is no valid pointing.')
        center /= n
        return self.cartesian2spherical(center)
コード例 #8
0
ファイル: samplings.py プロジェクト: pchanial/pysimulators
    def get_center(self):
        """
        Return the average pointing direction.

        """
        if isscalarlike(self.masked) and self.masked:
            n = 0
            coords = np.zeros((1, 3))
        else:
            coords = self.cartesian
            if not isscalarlike(self.masked):
                valid = 1 - self.masked
                coords *= valid[:, None]
                n = np.sum(valid)
            else:
                n = len(self)
        n = np.asarray(n)
        center = np.sum(coords, axis=0)
        self.comm.Allreduce(MPI.IN_PLACE, as_mpi(n))
        self.comm.Allreduce(MPI.IN_PLACE, as_mpi(center))
        if n == 0:
            raise ValueError('There is no valid pointing.')
        center /= n
        return self.cartesian2spherical(center)
コード例 #9
0
def test_diff():
    shape = np.array((4,8,4))
    for r in range(1,shape.size+1):
        for axis in range(r):
            a=np.random.random_integers(1, 10, size=shape[0:r]).astype(float)
            MPI.COMM_WORLD.Bcast(as_mpi(a), root=0)
            distribution = DistributionGlobalOperator(shape[0:r],
                                                      commout=MPI.COMM_WORLD)
            for f in (u.diff, u.diffT, u.diffTdiff):
                ref = a.copy()
                f(ref, ref, axis=axis, comm=MPI.COMM_SELF)
                reflocal = distribution(ref)
                local = distribution(a)
                dlocal = np.empty_like(local)
                f(local, dlocal, axis=axis)
                yield assert_equal, dlocal, reflocal, 'r={0}, axis={1}, f={2}, rank={3}, size={4}'.format(r, axis, f.__name__, rank, size)
                f(local, local, axis=axis)
                yield assert_equal, local, reflocal, 'r={0}, axis={1}, f={2}, rank={3}, size={4}'.format(r, axis, f.__name__, rank, size)
コード例 #10
0
def test_diff():
    shape = np.array((4, 8, 4))
    for r in range(1, shape.size + 1):
        for axis in range(r):
            a = np.random.random_integers(1, 10, size=shape[0:r]).astype(float)
            MPI.COMM_WORLD.Bcast(as_mpi(a), root=0)
            distribution = DistributionGlobalOperator(shape[0:r],
                                                      commout=MPI.COMM_WORLD)
            for f in (u.diff, u.diffT, u.diffTdiff):
                ref = a.copy()
                f(ref, ref, axis=axis, comm=MPI.COMM_SELF)
                reflocal = distribution(ref)
                local = distribution(a)
                dlocal = np.empty_like(local)
                f(local, dlocal, axis=axis)
                yield assert_equal, dlocal, reflocal, 'r={0}, axis={1}, f={2}, rank={3}, size={4}'.format(
                    r, axis, f.__name__, rank, size)
                f(local, local, axis=axis)
                yield assert_equal, local, reflocal, 'r={0}, axis={1}, f={2}, rank={3}, size={4}'.format(
                    r, axis, f.__name__, rank, size)