当前位置: 首页>>代码示例>>Python>>正文


Python MPI._addressof方法代码示例

本文整理汇总了Python中mpi4py.MPI._addressof方法的典型用法代码示例。如果您正苦于以下问题:Python MPI._addressof方法的具体用法?Python MPI._addressof怎么用?Python MPI._addressof使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在mpi4py.MPI的用法示例。


在下文中一共展示了MPI._addressof方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: ncmpi_open

# 需要导入模块: from mpi4py import MPI [as 别名]
# 或者: from mpi4py.MPI import _addressof [as 别名]
def ncmpi_open(name):
    comm_ptr = MPI._addressof(MPI.COMM_WORLD)
    comm_val = MPI_Comm.from_address(comm_ptr)
    info_ptr = MPI._addressof(MPI.INFO_NULL)
    info_val = MPI_Comm.from_address(info_ptr)
    ncid = c_int()
    retval = _ncmpi_open(comm_val, name, NC_NOWRITE, info_val, byref(ncid))
    errcheck(retval)
    return ncid.value
开发者ID:abhinavvishnu,项目名称:matex,代码行数:11,代码来源:pnetcdf.py

示例2: testHandleAdress

# 需要导入模块: from mpi4py import MPI [as 别名]
# 或者: from mpi4py.MPI import _addressof [as 别名]
 def testHandleAdress(self):
     typemap = {ctypes.sizeof(ctypes.c_int): ctypes.c_int,
                ctypes.sizeof(ctypes.c_void_p): ctypes.c_void_p}
     for obj in self.objects:
         handle_t = typemap[MPI._sizeof(obj)]
         oldobj = obj
         newobj = type(obj)()
         handle_old = handle_t.from_address(MPI._addressof(oldobj))
         handle_new = handle_t.from_address(MPI._addressof(newobj))
         handle_new.value = handle_old.value
         self.assertEqual(obj, newobj)
开发者ID:benkirk,项目名称:mpi_playground,代码行数:13,代码来源:test_ctypes.py

示例3: ncmpi_open

# 需要导入模块: from mpi4py import MPI [as 别名]
# 或者: from mpi4py.MPI import _addressof [as 别名]
def ncmpi_open(name):
    if sys.version_info >= (3,0,0):
        name = bytes(name, 'utf-8')
    comm_ptr = MPI._addressof(MPI.COMM_WORLD)
    comm_val = MPI_Comm.from_address(comm_ptr)
    info_ptr = MPI._addressof(MPI.INFO_NULL)
    info_val = MPI_Info.from_address(info_ptr)
    ncid = c_int()
    retval = _ncmpi_open(comm_val, name, NC_NOWRITE, info_val, byref(ncid))
    # print("TEST")
    errcheck(retval)
    # print("TEST")
    return ncid.value
开发者ID:abhinavvishnu,项目名称:matex,代码行数:15,代码来源:pnetcdf.py

示例4: __init__

# 需要导入模块: from mpi4py import MPI [as 别名]
# 或者: from mpi4py.MPI import _addressof [as 别名]
 def __init__(self, comm=None):
     if comm is None:
         # Should only end up here upon unpickling
         comm = MPI.COMM_WORLD
     comm_ptr = MPI._addressof(comm)
     comm_val = self.dtype.from_address(comm_ptr)
     self.value = comm_val
开发者ID:opesci,项目名称:devito,代码行数:9,代码来源:distributed.py

示例5: testHandleValue

# 需要导入模块: from mpi4py import MPI [as 别名]
# 或者: from mpi4py.MPI import _addressof [as 别名]
 def testHandleValue(self):
     typemap = {ctypes.sizeof(ctypes.c_uint32): ctypes.c_uint32,
                ctypes.sizeof(ctypes.c_uint64): ctypes.c_uint64}
     for obj in self.objects:
         uintptr_t = typemap[MPI._sizeof(obj)]
         handle = uintptr_t.from_address(MPI._addressof(obj))
         self.assertEqual(handle.value, MPI._handleof(obj))
开发者ID:benkirk,项目名称:mpi_playground,代码行数:9,代码来源:test_ctypes.py

示例6: testHandleValue

# 需要导入模块: from mpi4py import MPI [as 别名]
# 或者: from mpi4py.MPI import _addressof [as 别名]
 def testHandleValue(self):
     ffi = cffi.FFI()
     typemap = {ffi.sizeof('uint32_t'): 'uint32_t',
                ffi.sizeof('uint64_t'): 'uint64_t',}
     for obj in self.objects:
         uintptr_t = typemap[MPI._sizeof(obj)]
         handle = ffi.cast(uintptr_t+'*', MPI._addressof(obj))[0]
         self.assertEqual(handle, MPI._handleof(obj))
开发者ID:benkirk,项目名称:mpi_playground,代码行数:10,代码来源:test_cffi.py

示例7: testHandleAddress

# 需要导入模块: from mpi4py import MPI [as 别名]
# 或者: from mpi4py.MPI import _addressof [as 别名]
 def testHandleAddress(self):
     ffi = cffi.FFI()
     typemap = {ffi.sizeof('int'): 'int',
                ffi.sizeof('void*'): 'void*'}
     typename = lambda t: t.__name__.rsplit('.', 1)[-1]
     for tp in self.mpitypes:
         handle_t = typemap[MPI._sizeof(tp)]
         mpi_t = 'MPI_' + typename(tp)
         ffi.cdef("typedef %s %s;" % (handle_t, mpi_t))
     for obj in self.objects:
         if isinstance(obj, MPI.Comm):
             mpi_t = 'MPI_Comm'
         else:
             mpi_t = 'MPI_' + typename(type(obj))
         oldobj = obj
         newobj = type(obj)()
         handle_old = ffi.cast(mpi_t+'*', MPI._addressof(oldobj))
         handle_new = ffi.cast(mpi_t+'*', MPI._addressof(newobj))
         handle_new[0] = handle_old[0]
         self.assertEqual(oldobj, newobj)
开发者ID:benkirk,项目名称:mpi_playground,代码行数:22,代码来源:test_cffi.py

示例8: get_task_comm

# 需要导入模块: from mpi4py import MPI [as 别名]
# 或者: from mpi4py.MPI import _addressof [as 别名]
def get_task_comm():
    import os,sys
    print("gtc");sys.stdout.flush()
    from mpi4py import MPI
    print("gtc2");sys.stdout.flush()
    import ctypes
    task_comm_string = os.getenv("task_comm")
    print("task_comm_string: " + task_comm_string)
    task_comm_int = int(task_comm_string)
    MPI_Comm = ctypes.c_int
    MPI_Comm.from_address(task_comm_int)
    newcomm = MPI.Intracomm()
    newcomm_ptr = MPI._addressof(newcomm)
    comm_val = MPI_Comm.from_address(newcomm_ptr)
    # comm_val.value = task_comm_int
    print("gtc3");sys.stdout.flush()
    # newcomm.barrier()
    print("gtc4");sys.stdout.flush()
    return newcomm
开发者ID:swift-lang,项目名称:swift-work,代码行数:21,代码来源:test_6.py

示例9: init

# 需要导入模块: from mpi4py import MPI [as 别名]
# 或者: from mpi4py.MPI import _addressof [as 别名]
    def init(self, calling_realm):

        # Build a communicator mpi4py python object from the
        # handle returned by the CPL_init function.
        if MPI._sizeof(MPI.Comm) == ctypes.sizeof(c_int):
            MPI_Comm = c_int
        else:
            MPI_Comm = c_void_p

        # Call create comm
        returned_realm_comm = c_int()
        self._py_init(calling_realm, byref(returned_realm_comm))

        # Use an intracomm object as the template and override value
        newcomm = MPI.Intracomm()
        newcomm_ptr = MPI._addressof(newcomm)
        comm_val = MPI_Comm.from_address(newcomm_ptr)
        comm_val.value = returned_realm_comm.value

        return newcomm
开发者ID:Crompulence,项目名称:cpl-library,代码行数:22,代码来源:cplpy.py

示例10: say_hello

# 需要导入模块: from mpi4py import MPI [as 别名]
# 或者: from mpi4py.MPI import _addressof [as 别名]
def say_hello(comm):
    r"""Given a communicator, have each process in the communicator call
    say_hello().

    This Python function will be executed by each MPI process. Each will create
    its own copy of the data array `a` and send that array to the C function
    `say_hello()`.

    """
    comm_ptr = MPI._addressof(comm)
    comm_val = MPI_Comm.from_address(comm_ptr)

    N = 8
    a = numpy.ascontiguousarray(numpy.zeros(N, dtype=numpy.double))
    libhello.say_hello(a.ctypes.data, N, comm_val)

    print '%d ---- test: %s'%(comm.rank, a)
    if (comm.rank == 0):
        return a
    else:
        return None
开发者ID:AbhishekKapoor,项目名称:lectures,代码行数:23,代码来源:hello.py

示例11: go

# 需要导入模块: from mpi4py import MPI [as 别名]
# 或者: from mpi4py.MPI import _addressof [as 别名]
def go(comm_int):
    print("go(%i) ..." % comm_int)
    comm = MPI.COMM_WORLD
    print("size: %i" % comm.Get_size())
    comm.barrier()

    # MPICH mode:
    # MPI_Comm = ctypes.c_int
    # MPI_Comm.from_address(comm_int)
    # newcomm = MPI.Intracomm()
    # newcomm_ptr = MPI._addressof(newcomm)
    # comm_val = MPI_Comm.from_address(newcomm_ptr)
    # comm_val.value = comm_int
    # newcomm.barrier()
    # sys.stdout.flush()

    # OpenMPI mode (from Zaki)
    comm_pointer = ctypes.c_void_p
    mpi4py_comm = MPI.Intracomm()
    handle = comm_pointer.from_address(MPI._addressof(mpi4py_comm))
    handle.value = comm_int
    mpi4py_comm.barrier()
开发者ID:swift-lang,项目名称:swift-work,代码行数:24,代码来源:test_3.py

示例12: heat_parallel

# 需要导入模块: from mpi4py import MPI [as 别名]
# 或者: from mpi4py.MPI import _addressof [as 别名]
def heat_parallel(uk, dx, Nx, dt, num_steps, comm):
    r"""Solve the heat equation in paralllel. This Python function is executed by
    each spawned process.

    Parameters
    ----------
    uk : array
        Function values for process k.

    Returns
    -------
    uk : array
        The updated function values after heat_parallel()
    """
    if (len(uk) != Nx):
        raise ValueError("Nx should equal the number of grid points.")

    # note that the code below inherently returns a copy of the original input
    uk = numpy.ascontiguousarray(
        numpy.array(uk, dtype=numpy.double)).astype(numpy.double)

    # mpi comm setup
    comm_ptr = MPI._addressof(comm)
    comm_val = c_mpi_comm.from_address(comm_ptr)

    # set function types and evaluate
    try:
        f = homework4library.heat_parallel
        f.restype = None
        f.argtypes = [c_void_p, c_double, c_size_t, c_double,
                      c_size_t, c_mpi_comm]
        f(uk.ctypes.data, dx, Nx, dt, num_steps, comm_val)
    except AttributeError:
        raise AttributeError("Something wrong happened when calling the C "
                             "library function.")
    return uk
开发者ID:boruil,项目名称:homework4,代码行数:38,代码来源:wrappers.py

示例13: print

# 需要导入模块: from mpi4py import MPI [as 别名]
# 或者: from mpi4py.MPI import _addressof [as 别名]
from __future__ import print_function

import pyhenson as h
import numpy as np
from mpi4py import MPI

w = MPI.COMM_WORLD.Dup()
print(w.rank, w.size)

a = MPI._addressof(w)       # required to interface with mpi4py
pm = h.ProcMap(a, [('world', w.size)])
nm = h.NameMap()

sim = h.Puppet('../../examples/simple/simulation', ['1250'], pm, nm)
ana = h.Puppet('../../examples/simple/analysis',   [],       pm, nm)

sim.proceed()
ana.proceed()
while sim.running():
    a = nm.get("data")
    t = nm.get('t')
    print("[%d]: From Python: %d -> %f" % (w.rank, t, np.sum(a)))
    sim.proceed()
    ana.proceed()

t = sim.total_time()
print("Total time:", h.clock_to_string(t))
开发者ID:mrzv,项目名称:henson,代码行数:29,代码来源:test.py

示例14: sayhello

# 需要导入模块: from mpi4py import MPI [as 别名]
# 或者: from mpi4py.MPI import _addressof [as 别名]
def sayhello(comm):
    comm_ptr = MPI._addressof(comm)
    comm_val = MPI_Comm.from_address(comm_ptr)
    _lib.sayhello(comm_val)
开发者ID:carlochess,项目名称:docker.openmpi,代码行数:6,代码来源:helloworld.py

示例15: max

# 需要导入模块: from mpi4py import MPI [as 别名]
# 或者: from mpi4py.MPI import _addressof [as 别名]
     mu = 1
 if hpddm.optionSet(opt, b'schwarz_coarse_correction'):
     nu = ctypes.c_ushort(int(hpddm.optionVal(opt, b'geneo_nu')))
     if nu.value > 0:
         if hpddm.optionApp(opt, b'nonuniform'):
             nu.value += max(int(-hpddm.optionVal(opt, b'geneo_nu') + 1), (-1)**rankWorld * rankWorld)
         threshold = hpddm.underlying(max(0, hpddm.optionVal(opt, b'geneo_threshold')))
         hpddm.schwarzSolveGEVP(A, MatNeumann, ctypes.byref(nu), threshold)
         addr = hpddm.optionAddr(opt, b'geneo_nu')
         addr.contents.value = nu.value
     else:
         nu = 1
         deflation = numpy.ones((dof, nu), order = 'F', dtype = hpddm.scalar)
         hpddm.setVectors(hpddm.schwarzPreconditioner(A), nu, deflation)
     hpddm.initializeCoarseOperator(hpddm.schwarzPreconditioner(A), nu)
     hpddm.schwarzBuildCoarseOperator(A, hpddm.MPI_Comm.from_address(MPI._addressof(MPI.COMM_WORLD)))
 hpddm.schwarzCallNumfact(A)
 if rankWorld != 0:
     hpddm.optionRemove(opt, b'verbosity')
 comm = hpddm.getCommunicator(hpddm.schwarzPreconditioner(A))
 it = hpddm.solve(A, f, sol, comm)
 storage = numpy.empty(2 * mu, order = 'F', dtype = hpddm.underlying)
 hpddm.schwarzComputeError(A, sol, f, storage)
 if rankWorld == 0:
     for nu in xrange(mu):
         if nu == 0:
             print(' --- error = ', end = '')
         else:
             print('             ', end = '')
         print('{:e} / {:e}'.format(storage[1 + 2 * nu], storage[2 * nu]), end = '')
         if mu > 1:
开发者ID:feelpp,项目名称:hpddm,代码行数:33,代码来源:schwarz.py


注:本文中的mpi4py.MPI._addressof方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。