How to use the mpi4py.MPI.COMM_WORLD.Allreduce function in mpi4py

To help you get started, we’ve selected a few mpi4py examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github ucbdrive / spc / legacy / ddpg / baselines / her / normalizer.py View on Github external
def _mpi_average(self, x):
        buf = np.zeros_like(x)
        MPI.COMM_WORLD.Allreduce(x, buf, op=MPI.SUM)
        buf /= MPI.COMM_WORLD.Get_size()
        return buf
github behzadanksu / rl-attack / rlattack / common / mpi_running_mean_std.py View on Github external
def update(self, x):
        x = x.astype('float64')
        n = int(np.prod(self.shape))
        totalvec = np.zeros(n*2+1, 'float64')
        addvec = np.concatenate([x.sum(axis=0).ravel(), np.square(x).sum(axis=0).ravel(), np.array([len(x)],dtype='float64')])
        MPI.COMM_WORLD.Allreduce(addvec, totalvec, op=MPI.SUM)
        self.incfiltparams(totalvec[0:n].reshape(self.shape), totalvec[n:2*n].reshape(self.shape), totalvec[2*n])
github kashif / firedup / fireup / utils / mpi_tools.py View on Github external
def allreduce(*args, **kwargs):
    return MPI.COMM_WORLD.Allreduce(*args, **kwargs)
github Sohojoe / MarathonEnvsBaselines / baselines / common / mpi_running_mean_std.py View on Github external
def update(self, x):
        x = x.astype('float64')
        n = int(np.prod(self.shape))
        totalvec = np.zeros(n*2+1, 'float64')
        addvec = np.concatenate([x.sum(axis=0).ravel(), np.square(x).sum(axis=0).ravel(), np.array([len(x)],dtype='float64')])
        if MPI is not None:
            MPI.COMM_WORLD.Allreduce(addvec, totalvec, op=MPI.SUM)
        self.incfiltparams(totalvec[0:n].reshape(self.shape), totalvec[n:2*n].reshape(self.shape), totalvec[2*n])
github Geodels / eSCAPE / eSCAPE / mesher / unstructuredmesh.py View on Github external
def _meshAdvector(self, tectonicX, tectonicY, timer):
        """
        Advect the mesh horizontally and interpolate mesh information
        """

        # Move horizontally coordinates
        XYZ = np.zeros((self.gpoints,3))
        XYZ[:,0] = self.gcoords[:,0] + tectonicX*timer
        XYZ[:,1] = self.gcoords[:,1] + tectonicY*timer

        # Get mesh variables to interpolate
        # Elevation
        elev = np.zeros(self.gpoints)
        elev.fill(-1.e8)
        elev[self.natural2local] = self.hLocal.getArray().copy()
        MPI.COMM_WORLD.Allreduce(MPI.IN_PLACE, elev, op=MPI.MAX)
        interpolator = CloughTocher2DInterpolator(XYZ[:,:2],elev)
        nelev = interpolator(self.lcoords[:,:2])
        id_NaNs = np.isnan(nelev)
        nelev[id_NaNs] = 0.

        # Erosion/deposition
        erodep = np.zeros(self.gpoints)
        erodep.fill(-1.e8)
        erodep[self.natural2local] = self.cumEDLocal.getArray().copy()
        MPI.COMM_WORLD.Allreduce(MPI.IN_PLACE, erodep, op=MPI.MAX)
        interpolator = CloughTocher2DInterpolator(XYZ[:,:2],erodep)
        nerodep = interpolator(self.lcoords[:,:2])
        nerodep[id_NaNs] = 0.

        # Soil thickness
        if self.Ksed > 0.:
github andrewliao11 / gail-tf / gailtf / baselines / trpo_mpi / trpo_mpi.py View on Github external
def allmean(x):
        assert isinstance(x, np.ndarray)
        out = np.empty_like(x)
        MPI.COMM_WORLD.Allreduce(x, out, op=MPI.SUM)
        out /= nworkers
        return out
github Sohojoe / MarathonEnvsBaselines / baselines / trpo_mpi / trpo_mpi.py View on Github external
def allmean(x):
        assert isinstance(x, np.ndarray)
        if MPI is not None:
            out = np.empty_like(x)
            MPI.COMM_WORLD.Allreduce(x, out, op=MPI.SUM)
            out /= nworkers
        else:
            out = np.copy(x)

        return out
github andrewliao11 / gail-tf / gailtf / baselines / common / mpi_moments.py View on Github external
def mpi_moments(x, axis=0):
    x = np.asarray(x, dtype='float64')
    newshape = list(x.shape)
    newshape.pop(axis)
    n = np.prod(newshape,dtype=int)
    totalvec = np.zeros(n*2+1, 'float64')
    addvec = np.concatenate([x.sum(axis=axis).ravel(), 
        np.square(x).sum(axis=axis).ravel(), 
        np.array([x.shape[axis]],dtype='float64')])
    MPI.COMM_WORLD.Allreduce(addvec, totalvec, op=MPI.SUM)
    sum = totalvec[:n]
    sumsq = totalvec[n:2*n]
    count = totalvec[2*n]
    if count == 0:
        mean = np.empty(newshape); mean[:] = np.nan
        std = np.empty(newshape); std[:] = np.nan
    else:
        mean = sum/count
        std = np.sqrt(np.maximum(sumsq/count - np.square(mean),0))
    return mean, std, count
github jsitaraman / tioga / run / tiogaInterface.py View on Github external
def initAMRData(self,gridData):
        ngrids=len(gridData['gridParam'])
        local2global_tmp=np.zeros((ngrids,),'i')
        local2global=np.zeros((ngrids,),'i')
        for i in range(len(gridData['qParam'])):
            local2global_tmp[gridData['qParam'][i][0]]=i
        MPI.COMM_WORLD.Allreduce(local2global_tmp,local2global)
        #
        # these variables are from high-order FE off-body implementation
        # have to see if p=0 defaults work
        #
        nf=3
        qstride=1
        qnodein=0.0
        qnodeinC=arrayToDblPtr(np.array([qnodein,0.0],'d'))
        qnodesize=1

        idata=np.zeros((ngrids*11),'i')
        rdata=np.zeros((ngrids*6),'d')
        for i in range(ngrids):
            m=i*11
            idata[m]   =gridData['gridParam'][i][0] # global id of patch
            idata[m+1] =gridData['gridParam'][i][1] # level number of patch
github kindredresearch / arp / ar_trpo / ar_trpo_mpi.py View on Github external
def allmean(x):
        assert isinstance(x, np.ndarray)
        out = np.empty_like(x)
        MPI.COMM_WORLD.Allreduce(x, out, op=MPI.SUM)
        out /= nworkers
        return out