How to use the mpi4py.MPI.COMM_WORLD 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 Parallel-in-Time / pySDC / pySDC / playgrounds / mpifft / AC_benchmark_C.py View on Github external
def run_simulation(name=''):
    """
    A simple test program to do PFASST runs for the AC equation
    """

    # set MPI communicator
    comm = MPI.COMM_WORLD

    world_rank = comm.Get_rank()
    world_size = comm.Get_size()

    # split world communicator to create space-communicators
    if len(sys.argv) >= 2:
        color = int(world_rank / int(sys.argv[1]))
    else:
        color = int(world_rank / 1)
    space_comm = comm.Split(color=color)
    # space_size = space_comm.Get_size()
    space_rank = space_comm.Get_rank()

    # split world communicator to create time-communicators
    if len(sys.argv) >= 2:
        color = int(world_rank % int(sys.argv[1]))
github espressopp / espressopp / contrib / mpi4py / mpi4py-1.3 / demo / nxtval / nxtval-threads.py View on Github external
def test_thread_level():
    import sys
    flag = (MPI.Query_thread() == MPI.THREAD_MULTIPLE)
    flag = MPI.COMM_WORLD.bcast(flag, root=0)
    if not flag:
        if MPI.COMM_WORLD.Get_rank() == 0:
            sys.stderr.write("MPI does not provide enough thread support\n")
        sys.exit(0)
github gautelinga / BERNAISE / postprocess.py View on Github external
info_cyan, info_split, info_on_red, info_red, info_yellow
import os
import glob
import numpy as np
from mpi4py import MPI
from utilities import get_methods, get_help


"""
BERNAISE: Post-processing tool.

This module is used to read and analyze simulated data.

"""

comm = MPI.COMM_WORLD
rank = comm.Get_rank()
size = comm.Get_size()


def compute_norms(err, vector_norms=["l2", "linf"],
                  function_norms=["L2", "H1"], show=True,
                  tablefmt="simple", save=False):
    """ Compute norms, output to terminal, etc. """
    info_split("Vector norms:", ", ".join(vector_norms))
    info_split("Function norms:", ", ".join(function_norms))

    headers = ["Fields"] + vector_norms + function_norms

    table = []
    for field in err.keys():
        row = [field]
github hpddm / hpddm / examples / schwarz.py View on Github external
You should have received a copy of the GNU Lesser General Public License
   along with HPDDM.  If not, see .
"""

from __future__ import print_function
from mpi4py import MPI
import sys
sys.path.append('interface')
import ctypes
import numpy
import hpddm
from generate import *

rankWorld = MPI.COMM_WORLD.Get_rank()
sizeWorld = MPI.COMM_WORLD.Get_size()
opt = hpddm.optionGet()
args = ctypes.create_string_buffer(' '.join(sys.argv[1:]).encode('ascii', 'ignore'))
hpddm.optionParse(opt, args, rankWorld == 0)
def appArgs():
    val = (ctypes.c_char_p * 4)()
    (val[0], val[1], val[2], val[3]) = [ b'Nx=<100>', b'Ny=<100>', b'overlap=<1>', b'generate_random_rhs=<0>' ]
    desc = (ctypes.c_char_p * 4)()
    (desc[0], desc[1], desc[2], desc[3]) = [ b'Number of grid points in the x-direction.', b'Number of grid points in the y-direction.', b'Number of grid points in the overlap.', b'Number of generated random right-hand sides.' ]
    hpddm.optionParseInts(opt, args, 4, ctypes.cast(val, ctypes.POINTER(ctypes.c_char_p)), ctypes.cast(desc, ctypes.POINTER(ctypes.c_char_p)))
    (val[0], val[1]) = [ b'symmetric_csr=(0|1)', b'nonuniform=(0|1)' ]
    (desc[0], desc[1]) = [ b'Assemble symmetric matrices.', b'Use a different number of eigenpairs to compute on each subdomain.' ]
    hpddm.optionParseArgs(opt, args, 2, ctypes.cast(val, ctypes.POINTER(ctypes.c_char_p)), ctypes.cast(desc, ctypes.POINTER(ctypes.c_char_p)))
    val = None
    desc = None
appArgs()
o, connectivity, dof, Mat, MatNeumann, d, f, sol, mu = generate(rankWorld, sizeWorld)
github deephyper / deephyper / deephyper / searches / nas / utils / 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 self.use_mpi:
            MPI.COMM_WORLD.Allreduce(addvec, totalvec, op=MPI.SUM)
        else:
            totalvec = addvec
        self.incfiltparams(totalvec[0:n].reshape(self.shape), totalvec[n:2*n].reshape(self.shape), totalvec[2*n])
github jaredwo / topowx / twx / interp / mpi_gwr_interp_norm.py View on Github external
ds_out.createDimension('lat',lats.size)
    ds_out.createDimension('lon',lons.size)
    vlat = ds_out.createVariable('lat','f8',('lat',),fill_value=False)
    vlon = ds_out.createVariable('lon','f8',('lon',),fill_value=False)
    vlat[:] = lats
    vlon[:] = lons
    vnorm = ds_out.createVariable("norm",'f8',('lat','lon',),fill_value=netCDF4.default_fillvals['f8'])
    vse = ds_out.createVariable("se",'f8',('lat','lon',),fill_value=netCDF4.default_fillvals['f8'])
    #(row,col,norm,se)
    interp_tair = np.zeros(4)
    
    stat_chk = StatusCheck(n_interps,5000)
    
    while 1:
        
        MPI.COMM_WORLD.Recv([interp_tair,MPI.DOUBLE],source=MPI.ANY_SOURCE,tag=MPI.ANY_TAG,status=status)
                
        if status.tag == TAG_STOPWORK:
            
            nwrkrs_done+=1
            if nwrkrs_done == nwrkers:
                
                ds_out.sync()
                ds_out.close()
                
                print "Writer: Finished"
                return 0
        else:

            r,c = interp_tair[0:2].astype(np.int)
            vnorm[r,c] = interp_tair[2]
            vse[r,c] = interp_tair[3]
github gautelinga / BERNAISE / common / cmd.py View on Github external
from __future__ import print_function
import sys
import json
# from dolfin import MPI
import os
import mpi4py.MPI as MPI

MPI_rank = MPI.COMM_WORLD.Get_rank()
MPI_size = MPI.COMM_WORLD.Get_size()

RED = "\033[1;37;31m{s}\033[0m"
BLUE = "\033[1;37;34m{s}\033[0m"
GREEN = "\033[1;37;32m{s}\033[0m"
YELLOW = "\033[1;37;33m{s}\033[0m"
CYAN = "\033[1;37;36m{s}\033[0m"
NORMAL = "{s}"
ON_RED = "\033[41m{s}\033[0m"


__all__ = ["convert", "str2list", "parseval", "parse_command_line",
           "info_style", "info_red", "info_blue", "info_yellow",
           "info_green", "info_cyan", "info", "info_on_red",
           "info_split_style", "info_split", "info_warning",
           "info_error",
           "print_dir", "print_recipe", "help_menu"]
github hpcugent / hanythingondemand / hod / mpiservice.py View on Github external
def _check_comm(comm, txt):
    """Report details about communicator"""
    if comm == MPI.COMM_NULL:
        _log.debug("%scomm %s", txt, comm)
    else:
        myrank = comm.Get_rank()
        mysize = comm.Get_size()
        if comm == MPI.COMM_WORLD:
            _log.debug("%s comm WORLD %s size %d rank %d",
                           txt, comm, mysize, myrank)
        else:
            _log.debug("%scomm %s size %d rank %d", txt, comm, mysize, myrank)
github Pyomo / pyomo / pyomo / contrib / bb / knapsack / tp_mpi2.py View on Github external
# Serial knapsack
  
from mpi4py import MPI
from mpi4py.futures import MPICommExecutor

if __name__ == '__main__':
    import sys
    from pyomo.contrib.bb.knapsack.knapsack import Knapsack
    from pyomo.contrib.bb import ParallelBBSolver_mpi_async as PBB

    problem = Knapsack(filename='scor-500-1.txt')
    solver = PBB()

    rank = MPI.COMM_WORLD.Get_rank()
    size = MPI.COMM_WORLD.Get_size()
    #print("rank=%d size=%d" % (rank, size))

    #print("FOO")
    with MPICommExecutor(MPI.COMM_WORLD, 0) as executor:
        if executor is not None:
            #print("RUNNING rank=%d size=%d" % (rank, size))
            value, solution = solver.solve(problem=problem, executor=executor)
            print(value)
            problem.print_solution(solution)
github su2code / SU2 / SU2_PY / fsi_computation.py View on Github external
def main():

  comm = MPI.COMM_WORLD
  myid = comm.Get_rank()
  numberPart = comm.Get_size()
 
  rootProcess = 0

  # --- Set the working directory --- #
  if myid == rootProcess:
      if os.getcwd() not in sys.path:
          sys.path.append(os.getcwd())
	  print("Setting working directory : {}".format(os.getcwd()))
      else: 
	  print ("Working directory is set to {}".format(os.getcwd()))

  # starts timer
  start = timer.time()