本文整理汇总了Python中mpi4py.MPI._sizeof方法的典型用法代码示例。如果您正苦于以下问题:Python MPI._sizeof方法的具体用法?Python MPI._sizeof怎么用?Python MPI._sizeof使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类mpi4py.MPI
的用法示例。
在下文中一共展示了MPI._sizeof方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: testHandleValue
# 需要导入模块: from mpi4py import MPI [as 别名]
# 或者: from mpi4py.MPI import _sizeof [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))
示例2: testHandleValue
# 需要导入模块: from mpi4py import MPI [as 别名]
# 或者: from mpi4py.MPI import _sizeof [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))
示例3: testHandleAdress
# 需要导入模块: from mpi4py import MPI [as 别名]
# 或者: from mpi4py.MPI import _sizeof [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)
示例4: testHandleAddress
# 需要导入模块: from mpi4py import MPI [as 别名]
# 或者: from mpi4py.MPI import _sizeof [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)
示例5: init
# 需要导入模块: from mpi4py import MPI [as 别名]
# 或者: from mpi4py.MPI import _sizeof [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
示例6: OSError
# 需要导入模块: from mpi4py import MPI [as 别名]
# 或者: from mpi4py.MPI import _sizeof [as 别名]
import ctypes
import numpy
import os
from ctypes import c_void_p, c_int, c_long, c_size_t, c_double
from mpi4py import MPI
# try to import the library
try:
path_to_library = os.path.join('lib','libhomework4.so')
homework4library = ctypes.cdll.LoadLibrary(path_to_library)
except OSError:
raise OSError("You need to compile your homework library using 'make'.")
# determine the c-type of an MPI_Comm type
if MPI._sizeof(MPI.Comm) == ctypes.sizeof(c_int):
c_mpi_comm = ctypes.c_int
else:
c_mpi_comm = ctypes.c_void_p
###############################################################################
# function wrappers
###############################################################################
def heat_serial(u, dx, Nx, dt, num_steps):
r"""Solve the heat equation using basic finite difference scheme.
Parameters
----------
u : array
Function values.
示例7: testSizeOf
# 需要导入模块: from mpi4py import MPI [as 别名]
# 或者: from mpi4py.MPI import _sizeof [as 别名]
def testSizeOf(self):
for obj in self.objects:
n1 = MPI._sizeof(obj)
n2 = MPI._sizeof(type(obj))
self.assertEqual(n1, n2)
示例8: __init__
# 需要导入模块: from mpi4py import MPI [as 别名]
# 或者: from mpi4py.MPI import _sizeof [as 别名]
def __init__(self, library=None, style='spherical', dim=3, units='si', path=None, cmdargs=[], comm=None, ptr=None):
# What is ptr used for?
if library:
if not comm.Get_rank():
print("Using " + library + " as a shared library for DEM computations")
else:
if not comm.Get_rank():
print('No library supplies.')
sys.exit()
if not comm:
comm = MPI.COMM_WORLD
try:
self.lib = ctypes.CDLL(library, ctypes.RTLD_GLOBAL)
except:
etype,value,tb = sys.exc_info()
traceback.print_exception(etype,value,tb)
raise RuntimeError("Could not load LIGGGHTS dynamic library")
# if no ptr provided, create an instance of LIGGGHTS
# don't know how to pass an MPI communicator from PyPar
# but we can pass an MPI communicator from mpi4py v2.0.0 and later
# no_mpi call lets LIGGGHTS use MPI_COMM_WORLD
# cargs = array of C strings from args
# if ptr, then are embedding Python in LIGGGHTS input script
# ptr is the desired instance of LIGGGHTS
# just convert it to ctypes ptr and store in self.lmp
if MPI._sizeof(MPI.Comm) == ctypes.sizeof(ctypes.c_int):
MPI_Comm = ctypes.c_int
else:
MPI_Comm = ctypes.c_void_p
if not ptr:
# with mpi4py v2, can pass MPI communicator to LIGGGHTS
# need to adjust for type of MPI communicator object
# allow for int (like MPICH) or void* (like OpenMPI)
narg = 0
cargs = 0
if cmdargs:
cmdargs.insert(0, "liggghts.py")
narg = len(cmdargs)
for i in range(narg):
if isinstance(cmdargs[i], str):
cmdargs[i] = cmdargs[i].encode()
cargs = (ctypes.c_char_p*narg)(*cmdargs)
self.lib.lammps_open.argtypes = [ctypes.c_int, ctypes.c_char_p*narg, \
MPI_Comm, ctypes.c_void_p()]
else:
self.lib.lammps_open.argtypes = [ctypes.c_int, ctypes.c_int, \
MPI_Comm, ctypes.c_void_p()]
self.lib.lammps_open.restype = None
self.opened = 1
self.lmp = ctypes.c_void_p()
comm_ptr = MPI._addressof(comm)
comm_val = MPI_Comm.from_address(comm_ptr)
self.lib.lammps_open(narg,cargs,comm_val,ctypes.byref(self.lmp))
self.opened = True
else:
self.opened = False
if sys.version_info >= (3, 0):
# Python 3 (uses PyCapsule API)
ctypes.pythonapi.PyCapsule_GetPointer.restype = ctypes.c_void_p
ctypes.pythonapi.PyCapsule_GetPointer.argtypes = [ctypes.py_object, ctypes.c_char_p]
self.lmp = ctypes.c_void_p(ctypes.pythonapi.PyCapsule_GetPointer(ptr, None))
else:
# Python 2 (uses PyCObject API)
ctypes.pythonapi.PyCObject_AsVoidPtr.restype = ctypes.c_void_p
ctypes.pythonapi.PyCObject_AsVoidPtr.argtypes = [ctypes.py_object]
self.lmp = ctypes.c_void_p(ctypes.pythonapi.PyCObject_AsVoidPtr(ptr))
示例9: sayhello
# 需要导入模块: from mpi4py import MPI [as 别名]
# 或者: from mpi4py.MPI import _sizeof [as 别名]
from mpi4py import MPI
import cffi
import os
_libdir = os.path.dirname(__file__)
ffi = cffi.FFI()
if MPI._sizeof(MPI.Comm) == ffi.sizeof('int'):
_mpi_comm_t = 'int'
else:
_mpi_comm_t = 'void*'
ffi.cdef("""
typedef %(_mpi_comm_t)s MPI_Comm;
void sayhello(MPI_Comm);
""" % vars())
lib = ffi.dlopen(os.path.join(_libdir, "libhelloworld.so"))
def sayhello(comm):
comm_ptr = MPI._addressof(comm)
comm_val = ffi.cast('MPI_Comm*', comm_ptr)[0]
lib.sayhello(comm_val)