當前位置: 首頁>>代碼示例>>Python>>正文


Python MPI.MIN屬性代碼示例

本文整理匯總了Python中mpi4py.MPI.MIN屬性的典型用法代碼示例。如果您正苦於以下問題:Python MPI.MIN屬性的具體用法?Python MPI.MIN怎麽用?Python MPI.MIN使用的例子?那麽, 這裏精選的屬性代碼示例或許可以為您提供幫助。您也可以進一步了解該屬性所在mpi4py.MPI的用法示例。


在下文中一共展示了MPI.MIN屬性的12個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: _get_minmax_coordinates_mesh

# 需要導入模塊: from mpi4py import MPI [as 別名]
# 或者: from mpi4py.MPI import MIN [as 別名]
def _get_minmax_coordinates_mesh(self, axis=0):
        """ Return the minimum and maximum coordinates along axis

        parameter:
        ----------
            axis:
                axis

        returns:
        -------
            tuple: minV, maxV

        """
        maxVal = np.zeros((1))
        minVal = np.zeros((1))
        maxVal[0] = self.Model.mesh.data[:, axis].max()
        minVal[0] = self.Model.mesh.data[:, axis].min()

        comm.Barrier()
        comm.Allreduce(_MPI.IN_PLACE, maxVal, op=_MPI.MAX)
        comm.Allreduce(_MPI.IN_PLACE, minVal, op=_MPI.MIN)
        comm.Barrier()

        return minVal, maxVal 
開發者ID:underworldcode,項目名稱:UWGeodynamics,代碼行數:26,代碼來源:_mesh_advector.py

示例2: mpi_statistics_scalar

# 需要導入模塊: from mpi4py import MPI [as 別名]
# 或者: from mpi4py.MPI import MIN [as 別名]
def mpi_statistics_scalar(x, with_min_and_max=False):
    """
    Get mean/std and optional min/max of scalar x across MPI processes.

    Args:
        x: An array containing samples of the scalar to produce statistics
            for.

        with_min_and_max (bool): If true, return min and max of x in 
            addition to mean and std.
    """
    x = np.array(x, dtype=np.float32)
    global_sum, global_n = mpi_sum([np.sum(x), len(x)])
    mean = global_sum / global_n

    global_sum_sq = mpi_sum(np.sum((x - mean)**2))
    std = np.sqrt(global_sum_sq / global_n)  # compute global std

    if with_min_and_max:
        global_min = mpi_op(np.min(x) if len(x) > 0 else np.inf, op=MPI.MIN)
        global_max = mpi_op(np.max(x) if len(x) > 0 else -np.inf, op=MPI.MAX)
        return mean, std, global_min, global_max
    return mean, std 
開發者ID:openai,項目名稱:spinningup,代碼行數:25,代碼來源:mpi_tools.py

示例3: mpi_statistics_scalar

# 需要導入模塊: from mpi4py import MPI [as 別名]
# 或者: from mpi4py.MPI import MIN [as 別名]
def mpi_statistics_scalar(x, with_min_and_max=False):
    """
    Get mean/std and optional min/max of scalar x across MPI processes.

    Args:
        x: An array containing samples of the scalar to produce statistics
            for.

        with_min_and_max (bool): If true, return min and max of x in
            addition to mean and std.
    """
    x = np.array(x, dtype=np.float32)
    global_sum, global_n = mpi_sum([np.sum(x), len(x)])
    mean = global_sum / global_n

    global_sum_sq = mpi_sum(np.sum((x - mean) ** 2))
    std = np.sqrt(global_sum_sq / global_n)  # compute global std

    if with_min_and_max:
        global_min = mpi_op(np.min(x) if len(x) > 0 else np.inf, op=MPI.MIN)
        global_max = mpi_op(np.max(x) if len(x) > 0 else -np.inf, op=MPI.MAX)
        return mean, std, global_min, global_max
    return mean, std 
開發者ID:kashif,項目名稱:firedup,代碼行數:25,代碼來源:mpi_tools.py

示例4: _get_minmax_velocity_wall

# 需要導入模塊: from mpi4py import MPI [as 別名]
# 或者: from mpi4py.MPI import MIN [as 別名]
def _get_minmax_velocity_wall(self, wall, axis=0):
        """ Return the minimum and maximum velocity component on the wall

        parameters:
        -----------
            wall: (indexSet)
                The wall.
            axis:
                axis (velocity component).
        """

        # Initialise value to max and min sys values
        maxV = np.ones((1)) * sys.float_info.min
        minV = np.ones((1)) * sys.float_info.max

        # if local domain has wall, get velocities
        if wall.data.size > 0:
            velocities  = self.Model.velocityField.data[wall.data, axis]
            # get local min and max
            maxV[0] = velocities.max()
            minV[0] = velocities.min()

        # reduce operation
        comm.Barrier()
        comm.Allreduce(_MPI.IN_PLACE, maxV, op=_MPI.MAX)
        comm.Allreduce(_MPI.IN_PLACE, minV, op=_MPI.MIN)
        comm.Barrier()

        return minV, maxV 
開發者ID:underworldcode,項目名稱:UWGeodynamics,代碼行數:31,代碼來源:_mesh_advector.py

示例5: __init__

# 需要導入模塊: from mpi4py import MPI [as 別名]
# 或者: from mpi4py.MPI import MIN [as 別名]
def __init__(self, source, fsky, cosmo, bins=None, redshift='Redshift', weight=None):

        # input columns need to be there
        for col in [redshift, weight]:
            if col is not None and col not in source:
                raise ValueError("'%s' column missing from input source in RedshiftHistogram" %col)

        self.comm = source.comm

        # using Scott's rule for binning
        if bins is None:
            h, bins = scotts_bin_width(source.compute(source[redshift]), self.comm)
            if self.comm.rank == 0:
                self.logger.info("using Scott's rule to determine optimal binning; h = %.2e, N_bins = %d" %(h, len(bins)-1))

        # equally spaced bins from min to max val
        elif numpy.isscalar(bins):
            if self.comm.rank == 0:
                self.logger.info("computing %d equally spaced bins" %bins)
            z = source.compute(source[redshift])
            maxval = self.comm.allreduce(z.max(), op=MPI.MAX)
            minval = self.comm.allreduce(z.min(), op=MPI.MIN)
            bins = linspace(minval, maxval, bins + 1, endpoint=True)

        self.source = source
        self.cosmo  = cosmo

        self.attrs = {}
        self.attrs['edges'] = bins
        self.attrs['fsky'] = fsky
        self.attrs['redshift'] = redshift
        self.attrs['weight'] = weight
        self.attrs['cosmo'] = dict(cosmo)

        # and run
        self.run() 
開發者ID:bccp,項目名稱:nbodykit,代碼行數:38,代碼來源:zhist.py

示例6: global_min

# 需要導入模塊: from mpi4py import MPI [as 別名]
# 或者: from mpi4py.MPI import MIN [as 別名]
def global_min(vs, arr, axis=None):
    from mpi4py import MPI
    return _reduce(vs, arr, MPI.MIN, axis=axis) 
開發者ID:team-ocean,項目名稱:veros,代碼行數:5,代碼來源:distributed.py

示例7: sample

# 需要導入模塊: from mpi4py import MPI [as 別名]
# 或者: from mpi4py.MPI import MIN [as 別名]
def sample(self, u):
        '''Evaluate the probes listing the time as t'''
        self.readings_local[:] = np.hstack([f(u) for f in self.probes])    # Get local
        self.comm.Allreduce(self.readings_local, self.readings, op=py_mpi.MIN)  # Sync

        return self.readings.reshape((self.nprobes, -1)) 
開發者ID:jerabaul29,項目名稱:Cylinder2DFlowControlDRL,代碼行數:8,代碼來源:probes.py

示例8: get_best_fitness

# 需要導入模塊: from mpi4py import MPI [as 別名]
# 或者: from mpi4py.MPI import MIN [as 別名]
def get_best_fitness(self):
        """Gets the fitness of most fit member

        Returns
        -------
         :
            Fitness of best individual in the archipelago
        """
        best_on_proc = self._island.get_best_fitness()
        best_fitness = self.comm.allreduce(best_on_proc, op=MPI.MIN)
        return best_fitness 
開發者ID:nasa,項目名稱:bingo,代碼行數:13,代碼來源:parallel_archipelago.py

示例9: test_op_to_mpi

# 需要導入模塊: from mpi4py import MPI [as 別名]
# 或者: from mpi4py.MPI import MIN [as 別名]
def test_op_to_mpi(self):
        reload(util)
        assert util.op_to_mpi('+') == MPI.SUM
        assert util.op_to_mpi("sum") == MPI.SUM
        assert util.op_to_mpi("add") == MPI.SUM
        assert util.op_to_mpi('*') == MPI.PROD
        assert util.op_to_mpi("prod") == MPI.PROD
        assert util.op_to_mpi("product") == MPI.PROD
        assert util.op_to_mpi("mul") == MPI.PROD
        assert util.op_to_mpi("max") == MPI.MAX
        assert util.op_to_mpi("maximum") == MPI.MAX
        assert util.op_to_mpi("min") == MPI.MIN
        assert util.op_to_mpi("minimum") == MPI.MIN 
開發者ID:mila-iqia,項目名稱:platoon,代碼行數:15,代碼來源:test_util.py

示例10: scotts_bin_width

# 需要導入模塊: from mpi4py import MPI [as 別名]
# 或者: from mpi4py.MPI import MIN [as 別名]
def scotts_bin_width(data, comm):
    r"""
    Return the optimal histogram bin width using Scott's rule,
    defined as:

    .. math::

        h = \sigma \sqrt[3]{\frac{24 * \sqrt{\pi}}{n}}

    .. note::

        This is a collective operation

    Parameters
    ----------
    data : array_like
        the array that we are histograming
    comm :
        the MPI communicator

    Returns
    -------
    dx : float
        the bin spacing
    edges : array_like
        the array holding the bin edges
    """
    # compute the mean
    csum = comm.allreduce(data.sum())
    csize = comm.allreduce(data.size)
    cmean = csum / csize

    # std dev
    rsum = comm.allreduce((abs(data - cmean)**2).sum())
    sigma = (rsum / csize)**0.5

    dx = sigma * (24. * numpy.sqrt(numpy.pi) / csize) ** (1. / 3)
    maxval = comm.allreduce(data.max(), op=MPI.MAX)
    minval = comm.allreduce(data.min(), op=MPI.MIN)

    Nbins = numpy.ceil((maxval - minval) * 1. / dx)
    Nbins = max(1, Nbins)
    edges = minval + dx * numpy.arange(Nbins + 1)
    return dx, edges 
開發者ID:bccp,項目名稱:nbodykit,代碼行數:46,代碼來源:zhist.py

示例11: centerofmass

# 需要導入模塊: from mpi4py import MPI [as 別名]
# 或者: from mpi4py.MPI import MIN [as 別名]
def centerofmass(label, pos, boxsize, comm=MPI.COMM_WORLD):
    """
    Calulate the center of mass of particles of the same label.

    The center of mass is defined as the mean of positions of particles,
    but care has to be taken regarding to the periodic boundary.

    This is a collective operation, and after the call, all ranks
    will have the position of halos.

    Parameters
    ----------
    label : array_like (integers)
        Halo label of particles, >=0
    pos   : array_like (float, 3)
        position of particles.
    boxsize : float or None
        size of the periodic box, or None if no periodic boundary is assumed.
    comm : :py:class:`MPI.Comm`
        communicator for the collective operation.

    Returns
    -------
    hpos : array_like (float, 3)
        the center of mass position of the halos.

    """
    Nhalo0 = max(comm.allgather(label.max())) + 1

    N = numpy.bincount(label, minlength=Nhalo0)
    comm.Allreduce(MPI.IN_PLACE, N, op=MPI.SUM)

    if boxsize is not None:
        posmin = equiv_class(label, pos, op=numpy.fmin, dense_labels=True, identity=numpy.inf,
                        minlength=len(N))
        comm.Allreduce(MPI.IN_PLACE, posmin, op=MPI.MIN)
        dpos = pos - posmin[label]
        for i in range(dpos.shape[-1]):
            bhalf = boxsize[i] * 0.5
            dpos[..., i][dpos[..., i] < -bhalf] += boxsize[i]
            dpos[..., i][dpos[..., i] >= bhalf] -= boxsize[i]
    else:
        dpos = pos
    dpos = equiv_class(label, dpos, op=numpy.add, dense_labels=True, minlength=len(N))

    comm.Allreduce(MPI.IN_PLACE, dpos, op=MPI.SUM)
    dpos /= N[:, None]

    if boxsize is not None:
        hpos = posmin + dpos
        hpos %= boxsize
    else:
        hpos = dpos
    return hpos 
開發者ID:bccp,項目名稱:nbodykit,代碼行數:56,代碼來源:fof.py

示例12: __init__

# 需要導入模塊: from mpi4py import MPI [as 別名]
# 或者: from mpi4py.MPI import MIN [as 別名]
def __init__(self, u, locations):
        # The idea here is that u(x) means: search for cell containing x,
        # evaluate the basis functions of that element at x, restrict
        # the coef vector of u to the cell. Of these 3 steps the first
        # two don't change. So we cache them

        # Locate each point
        mesh = u.function_space().mesh()
        limit = mesh.num_entities(mesh.topology().dim())
        bbox_tree = mesh.bounding_box_tree()
        # In parallel x might not be on process, the cell is None then
        cells_for_x = [None]*len(locations)
        for i, x in enumerate(locations):
            cell = bbox_tree.compute_first_entity_collision(Point(*x))
            from dolfin import info
            if -1 < cell < limit:
                cells_for_x[i] = cell

        V = u.function_space()
        element = V.dolfin_element()

        size = V.ufl_element().value_size()
        # Build the sampling matrix
        evals = []
        for x, cell in zip(locations, cells_for_x):
            # If we own the cell we alloc stuff and precompute basis matrix
            if cell is not None:
                basis_matrix = np.zeros(size*element.space_dimension())
                coefficients = np.zeros(element.space_dimension())

                cell = Cell(mesh, cell)
                vertex_coords, orientation = cell.get_vertex_coordinates(), cell.orientation()
                # Eval the basis once
                element.evaluate_basis_all(basis_matrix, x, vertex_coords, orientation)

                basis_matrix = basis_matrix.reshape((element.space_dimension(), size)).T
                # Make sure foo is bound to right objections
                def foo(u, c=coefficients, A=basis_matrix, elm=cell, vc=vertex_coords):
                    # Restrict for each call using the bound cell, vc ...
                    u.restrict(c, element, elm, vc, elm)
                    # A here is bound to the right basis_matrix
                    return np.dot(A, c)
            # Otherwise we use the value which plays nicely with MIN reduction
            else:
                foo = lambda u, size=size: (np.finfo(float).max)*np.ones(size)

            evals.append(foo)

        self.probes = evals
        # To get the correct sampling on all cpus we reduce the local samples across
        # cpus
        self.comm = V.mesh().mpi_comm().tompi4py()
        self.readings = np.zeros(size*len(locations), dtype=float)
        self.readings_local = np.zeros_like(self.readings)
        # Return the value in the shape of vector/matrix
        self.nprobes = len(locations) 
開發者ID:jerabaul29,項目名稱:Cylinder2DFlowControlDRL,代碼行數:58,代碼來源:probes.py


注:本文中的mpi4py.MPI.MIN屬性示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。