本文整理汇总了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
示例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)
示例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
示例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
示例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))
示例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))
示例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)
示例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
示例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
示例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
示例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()
示例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
示例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))
示例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)
示例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: