1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60
|
from mpi4py import MPI
import mpiunittest as unittest
try:
import ctypes
except ImportError:
ctypes = None
@unittest.skipIf(ctypes is None, 'ctypes')
class TestCTYPES(unittest.TestCase):
objects = [
MPI.DATATYPE_NULL,
MPI.INT,
MPI.DOUBLE,
MPI.REQUEST_NULL,
MPI.INFO_NULL,
MPI.INFO_ENV,
MPI.ERRHANDLER_NULL,
MPI.ERRORS_RETURN,
MPI.ERRORS_ARE_FATAL,
MPI.GROUP_NULL,
MPI.GROUP_EMPTY,
MPI.WIN_NULL,
MPI.OP_NULL,
MPI.SUM,
MPI.MIN,
MPI.MAX,
MPI.FILE_NULL,
MPI.MESSAGE_NULL,
MPI.MESSAGE_NO_PROC,
MPI.COMM_NULL,
MPI.COMM_SELF,
MPI.COMM_WORLD,
]
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)
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))
if __name__ == '__main__':
unittest.main()
|