def testReadWriteOrderedBeginEnd(self): comm = self.COMM size = comm.Get_size() rank = comm.Get_rank() fh = self.FILE for array, typecode in arrayimpl_loop_io(): with arrayimpl.test(self): etype = array.TypeMap[typecode] fh.Set_size(0) fh.Set_view(0, etype) count = 13 wbuf = array(rank % 42, typecode, count) fh.Seek_shared(0, MPI.SEEK_SET) fh.Write_ordered_begin(wbuf.as_raw()) fh.Write_ordered_end(wbuf.as_raw()) fh.Sync() comm.Barrier() fh.Sync() rbuf = array(-1, typecode, count + 1) fh.Seek_shared(0, MPI.SEEK_SET) fh.Read_ordered_begin(rbuf.as_mpi_c(count)) fh.Read_ordered_end(rbuf.as_raw()) for value in rbuf[:-1]: self.assertEqual(value, rank % 42) self.assertEqual(rbuf[-1], -1) comm.Barrier()
def testReadWrite(self): comm = self.COMM size = comm.Get_size() rank = comm.Get_rank() fh = self.FILE for array, typecode in arrayimpl_loop_io(): with arrayimpl.test(self): etype = array.TypeMap[typecode] fh.Set_size(0) fh.Set_view(0, etype) count = 13 wbuf = array(42, typecode, count) for r in range(size): if r == rank: fh.Seek(0, MPI.SEEK_SET) fh.Write(wbuf.as_raw()) fh.Sync() comm.Barrier() fh.Sync() for n in range(0, len(wbuf)): rbuf = array(-1, typecode, n + 1) fh.Seek(0, MPI.SEEK_SET) fh.Read(rbuf.as_mpi_c(n)) for value in rbuf[:-1]: self.assertEqual(value, 42) self.assertEqual(rbuf[-1], -1) comm.Barrier()
def testAccumulate(self): group = self.WIN.Get_group() size = group.Get_size() group.Free() for array, typecode in arrayimpl.loop(): with arrayimpl.test(self): if unittest.is_mpi_gpu('openmpi', array): continue if unittest.is_mpi_gpu('mvapich2', array): continue if typecode in 'FDG': continue for count in range(self.COUNT_MIN, 10): for rank in range(size): with self.subTest(rank=rank, count=count): ones = array([1]*count, typecode) sbuf = array(range(count), typecode) rbuf = array(-1, typecode, count+1) for op in ( MPI.SUM, MPI.PROD, MPI.MAX, MPI.MIN, MPI.REPLACE, ): self.WIN.Lock(rank) self.WIN.Put(ones.as_mpi(), rank) self.WIN.Flush(rank) r = self.WIN.Raccumulate(sbuf.as_mpi(), rank, op=op) r.Wait() self.WIN.Flush(rank) r = self.WIN.Rget(rbuf.as_mpi_c(count), rank) r.Wait() self.WIN.Unlock(rank) # for i in range(count): self.assertEqual(sbuf[i], i) self.assertEqual(rbuf[i], op(1, i)) self.assertEqual(rbuf[-1], -1)
def testIReadIWriteShared(self): comm = self.COMM size = comm.Get_size() rank = comm.Get_rank() fh = self.FILE for array, typecode in arrayimpl_loop_io(): with arrayimpl.test(self): etype = array.TypeMap[typecode] fh.Set_size(0) fh.Set_view(0, etype) count = 13 wbuf = array(rank % 42, typecode, count) fh.Seek_shared(0, MPI.SEEK_SET) fh.Iwrite_shared(wbuf.as_raw()).Wait() fh.Sync() comm.Barrier() fh.Sync() rbuf = array(-1, typecode, count + 1) fh.Seek_shared(0, MPI.SEEK_SET) fh.Iread_shared(rbuf.as_mpi_c(count)).Wait() for value in rbuf[:-1]: self.assertTrue(0 <= value < 42) self.assertEqual(value, rbuf[0]) self.assertEqual(rbuf[-1], -1) comm.Barrier()
def testIReadIWriteAll(self): comm = self.COMM size = comm.Get_size() rank = comm.Get_rank() fh = self.FILE for array, typecode in arrayimpl_loop_io(): with arrayimpl.test(self): try: # MPI 3.1 etype = array.TypeMap[typecode] fh.Set_size(0) fh.Set_view(0, etype) count = 13 wbuf = array(42, typecode, count) fh.Seek(count * rank, MPI.SEEK_SET) fh.Iwrite_all(wbuf.as_raw()).Wait() fh.Sync() comm.Barrier() fh.Sync() rbuf = array(-1, typecode, count + 1) fh.Seek(count * rank, MPI.SEEK_SET) fh.Iread_all(rbuf.as_mpi_c(count)).Wait() for value in rbuf[:-1]: self.assertEqual(value, 42) self.assertEqual(rbuf[-1], -1) comm.Barrier() except NotImplementedError: if MPI.Get_version() >= (3, 1): raise self.skipTest('mpi-iwrite_all')
def testISendrecv(self): size = self.COMM.Get_size() rank = self.COMM.Get_rank() dest = (rank + 1) % size source = (rank - 1) % size try: self.COMM.Isendrecv( bytearray(1), dest, 0, bytearray(1), source, 0, ).Wait() except NotImplementedError: if MPI.Get_version() >= (4, 0): raise raise unittest.SkipTest("mpi-isendrecv") for array, typecode in arrayimpl.loop(): with arrayimpl.test(self): for s in range(0, size + 1): with self.subTest(s=s): sbuf = array(s, typecode, s) rbuf = array(-1, typecode, s + 1) self.COMM.Isendrecv( sbuf.as_mpi(), dest, 0, rbuf.as_mpi(), source, 0, ).Wait() for value in rbuf[:-1]: self.assertEqual(value, s) self.assertEqual(rbuf[-1], -1)
def testGetAccumulate(self): group = self.WIN.Get_group() size = group.Get_size() rank = group.Get_rank() group.Free() self.WIN.Fence() obuf = MPI.Alloc_mem(1) memzero(obuf) rbuf = MPI.Alloc_mem(1) memzero(rbuf) try: try: self.WIN.Get_accumulate([obuf, 0, MPI.BYTE], [rbuf, 0, MPI.BYTE], rank) self.WIN.Fence() finally: MPI.Free_mem(obuf) MPI.Free_mem(rbuf) except NotImplementedError: self.skipTest('mpi-win-get_accumulate') self.WIN.Fence() for array, typecode in arrayimpl.loop(): with arrayimpl.test(self): if unittest.is_mpi_gpu('openmpi', array): continue if unittest.is_mpi_gpu('mvapich2', array): continue if typecode in 'FDG': continue for count in range(10): for rank in range(size): with self.subTest(rank=rank, count=count): ones = array([1] * count, typecode) sbuf = array(range(count), typecode) rbuf = array(-1, typecode, count + 1) gbuf = array(-1, typecode, count + 1) for op in ( MPI.SUM, MPI.PROD, MPI.MAX, MPI.MIN, MPI.REPLACE, MPI.NO_OP, ): self.WIN.Lock(rank) self.WIN.Put(ones.as_mpi(), rank) self.WIN.Flush(rank) self.WIN.Get_accumulate(sbuf.as_mpi(), rbuf.as_mpi_c(count), rank, op=op) self.WIN.Flush(rank) self.WIN.Get(gbuf.as_mpi_c(count), rank) self.WIN.Flush(rank) self.WIN.Unlock(rank) # for i in range(count): self.assertEqual(sbuf[i], i) self.assertEqual(rbuf[i], 1) self.assertEqual(gbuf[i], op(1, i)) self.assertEqual(rbuf[-1], -1) self.assertEqual(gbuf[-1], -1)
def testSendRecv(self): size = self.COMM.Get_size() rank = self.COMM.Get_rank() for array, typecode in arrayimpl.loop(): with arrayimpl.test(self): if unittest.is_mpi_gpu('openmpi', array): continue if unittest.is_mpi_gpu('mvapich2', array): continue for s in range(0, size + 1): with self.subTest(s=s): # sbuf = array(s, typecode, s) rbuf = array(-1, typecode, s) mem = array(0, typecode, 2 * (s + MPI.BSEND_OVERHEAD)).as_raw() if size == 1: MPI.Attach_buffer(mem) rbuf = sbuf MPI.Detach_buffer() elif rank == 0: MPI.Attach_buffer(mem) self.COMM.Ibsend(sbuf.as_mpi(), 1, 0).Wait() self.COMM.Bsend(sbuf.as_mpi(), 1, 0) MPI.Detach_buffer() self.COMM.Send(sbuf.as_mpi(), 1, 0) self.COMM.Ssend(sbuf.as_mpi(), 1, 0) self.COMM.Recv(rbuf.as_mpi(), 1, 0) self.COMM.Recv(rbuf.as_mpi(), 1, 0) self.COMM.Recv(rbuf.as_mpi(), 1, 0) self.COMM.Recv(rbuf.as_mpi(), 1, 0) elif rank == 1: self.COMM.Recv(rbuf.as_mpi(), 0, 0) self.COMM.Recv(rbuf.as_mpi(), 0, 0) self.COMM.Recv(rbuf.as_mpi(), 0, 0) self.COMM.Recv(rbuf.as_mpi(), 0, 0) MPI.Attach_buffer(mem) self.COMM.Ibsend(sbuf.as_mpi(), 0, 0).Wait() self.COMM.Bsend(sbuf.as_mpi(), 0, 0) MPI.Detach_buffer() self.COMM.Send(sbuf.as_mpi(), 0, 0) self.COMM.Ssend(sbuf.as_mpi(), 0, 0) else: rbuf = sbuf for value in rbuf: self.assertEqual(value, s) # rank = self.COMM.Get_rank() sbuf = array(s, typecode, s) rbuf = array(-1, typecode, s) rreq = self.COMM.Irecv(rbuf.as_mpi(), rank, 0) self.COMM.Rsend(sbuf.as_mpi(), rank, 0) rreq.Wait() for value in rbuf: self.assertEqual(value, s) rbuf = array(-1, typecode, s) rreq = self.COMM.Irecv(rbuf.as_mpi(), rank, 0) self.COMM.Irsend(sbuf.as_mpi(), rank, 0).Wait() rreq.Wait() for value in rbuf: self.assertEqual(value, s)
def testPackSize(self): for array, typecode in arrayimpl.loop(): with arrayimpl.test(self): if typecode in self.skipdtype: continue datatype = array.TypeMap[typecode] itemsize = datatype.Get_size() overhead = datatype.Pack_external_size(EXT32, 0) for count in range(10): with self.subTest(count=count): pack_size = datatype.Pack_external_size(EXT32, count) real_size = pack_size - overhead
def testPackSize(self): for array, typecode in arrayimpl.loop(): with arrayimpl.test(self): if typecode in self.skipdtype: continue datatype = array.TypeMap[typecode] itemsize = datatype.Get_size() overhead = datatype.Pack_size(0, self.COMM) for count in range(10): with self.subTest(count=count): pack_size = datatype.Pack_size(count, self.COMM) self.assertEqual(pack_size - overhead, count * itemsize)
def testFetchAndOp(self): typemap = MPI._typedict group = self.WIN.Get_group() size = group.Get_size() rank = group.Get_rank() group.Free() self.WIN.Fence() blen = MPI.INT.Get_size() obuf = MPI.Alloc_mem(blen) memzero(obuf) rbuf = MPI.Alloc_mem(blen) memzero(rbuf) try: try: self.WIN.Fetch_and_op([obuf, 1, MPI.INT], [rbuf, 1, MPI.INT], rank) self.WIN.Fence() finally: MPI.Free_mem(obuf) MPI.Free_mem(rbuf) except NotImplementedError: self.skipTest('mpi-win-fetch_and_op') self.WIN.Fence() for array, typecode in arrayimpl.loop(): with arrayimpl.test(self): if unittest.is_mpi_gpu('openmpi', array): continue if unittest.is_mpi_gpu('mvapich2', array): continue if typecode in 'FDG': continue obuf = array(+1, typecode) rbuf = array(-1, typecode, 2) datatype = typemap[typecode] for op in ( MPI.SUM, MPI.PROD, MPI.MAX, MPI.MIN, MPI.REPLACE, MPI.NO_OP, ): for rank in range(size): for disp in range(3): with self.subTest(disp=disp, rank=rank): self.WIN.Lock(rank) self.WIN.Fetch_and_op(obuf.as_mpi(), rbuf.as_mpi_c(1), rank, disp * datatype.size, op=op) self.WIN.Unlock(rank) self.assertEqual(rbuf[1], -1)
def testPutGet(self): typemap = MPI._typedict group = self.WIN.Get_group() size = group.Get_size() group.Free() for array, typecode in arrayimpl.loop(): with arrayimpl.test(self): if unittest.is_mpi_gpu('mvapich2', array): continue for count in range(10): for rank in range(size): with self.subTest(rank=rank, count=count): sbuf = array(range(count), typecode) rbuf = array(-1, typecode, count + 1) # self.WIN.Fence() self.WIN.Put(sbuf.as_mpi(), rank) self.WIN.Fence() self.WIN.Get(rbuf.as_mpi_c(count), rank) self.WIN.Fence() for i in range(count): self.assertEqual(sbuf[i], i) self.assertNotEqual(rbuf[i], -1) self.assertEqual(rbuf[-1], -1) # sbuf = array(range(count), typecode) rbuf = array(-1, typecode, count + 1) target = sbuf.itemsize self.WIN.Fence() self.WIN.Put(sbuf.as_mpi(), rank, target) self.WIN.Fence() self.WIN.Get(rbuf.as_mpi_c(count), rank, target) self.WIN.Fence() for i in range(count): self.assertEqual(sbuf[i], i) self.assertNotEqual(rbuf[i], -1) self.assertEqual(rbuf[-1], -1) # sbuf = array(range(count), typecode) rbuf = array(-1, typecode, count + 1) datatype = typemap[typecode] target = (sbuf.itemsize, count, datatype) self.WIN.Fence() self.WIN.Put(sbuf.as_mpi(), rank, target) self.WIN.Fence() self.WIN.Get(rbuf.as_mpi_c(count), rank, target) self.WIN.Fence() for i in range(count): self.assertEqual(sbuf[i], i) self.assertNotEqual(rbuf[i], -1) self.assertEqual(rbuf[-1], -1)
def testSendrecvReplace(self): size = self.COMM.Get_size() rank = self.COMM.Get_rank() dest = (rank + 1) % size source = (rank - 1) % size for array, typecode in arrayimpl.loop(): with arrayimpl.test(self): for s in range(0, size + 1): with self.subTest(s=s): buf = array(rank, typecode, s) self.COMM.Sendrecv_replace(buf.as_mpi(), dest, 0, source, 0) for value in buf: self.assertEqual(value, source)
def testSendrecv(self): size = self.COMM.Get_size() rank = self.COMM.Get_rank() dest = (rank + 1) % size source = (rank - 1) % size for array, typecode in arrayimpl.loop(): with arrayimpl.test(self): for s in range(0, size + 1): with self.subTest(s=s): sbuf = array(s, typecode, s) rbuf = array(-1, typecode, s + 1) self.COMM.Sendrecv(sbuf.as_mpi(), dest, 0, rbuf.as_mpi(), source, 0) for value in rbuf[:-1]: self.assertEqual(value, s) self.assertEqual(rbuf[-1], -1)
def testCompareAndSwap(self): typemap = MPI._typedict group = self.WIN.Get_group() size = group.Get_size() rank = group.Get_rank() group.Free() self.WIN.Fence() obuf = MPI.Alloc_mem(1) memzero(obuf) cbuf = MPI.Alloc_mem(1) memzero(cbuf) rbuf = MPI.Alloc_mem(1) memzero(rbuf) try: try: self.WIN.Compare_and_swap([obuf, 1, MPI.BYTE], [cbuf, 1, MPI.BYTE], [rbuf, 1, MPI.BYTE], rank, 0) self.WIN.Fence() finally: MPI.Free_mem(obuf) MPI.Free_mem(cbuf) MPI.Free_mem(rbuf) except NotImplementedError: self.skipTest('mpi-win-compare_and_swap') self.WIN.Fence() for array, typecode in arrayimpl.loop(): with arrayimpl.test(self): if unittest.is_mpi_gpu('openmpi', array): continue if unittest.is_mpi_gpu('mvapich2', array): continue if typecode in 'fdg': continue if typecode in 'FDG': continue obuf = array(+1, typecode) cbuf = array(0, typecode) rbuf = array(-1, typecode, 2) datatype = typemap[typecode] for rank in range(size): for disp in range(3): with self.subTest(disp=disp, rank=rank): self.WIN.Lock(rank) self.WIN.Compare_and_swap(obuf.as_mpi(), cbuf.as_mpi(), rbuf.as_mpi_c(1), rank, disp * datatype.size) self.WIN.Unlock(rank) self.assertEqual(rbuf[1], -1)
def testRing(self): size = self.COMM.Get_size() rank = self.COMM.Get_rank() dest = (rank + 1) % size source = (rank - 1) % size for array, typecode in arrayimpl.loop(): with arrayimpl.test(self): for s in range(0, size): for p in range(1, 4): with self.subTest(p=p, s=s): sbuf = array(s, typecode, s * p) rbuf = array(-1, typecode, s * p) sreq = self.COMM.Psend_init( sbuf.as_mpi(), p, dest, 0) rreq = self.COMM.Precv_init( rbuf.as_mpi(), p, source, 0) for _ in range(3): self.COMM.Barrier() rreq.Start() for i in range(p): flag = rreq.Parrived(i) self.assertFalse(flag) self.COMM.Barrier() sreq.Start() for i in range(p): sreq.Pready(i) self.COMM.Barrier() for i in range(p): while not rreq.Parrived(i): pass flag = rreq.Parrived(i) self.assertTrue(flag) rreq.Wait() sreq.Wait() self.assertNotEqual(sreq, MPI.REQUEST_NULL) self.assertNotEqual(rreq, MPI.REQUEST_NULL) self.COMM.Barrier() for value in rbuf: self.assertEqual(value, s) rreq.Free() sreq.Free() self.assertEqual(sreq, MPI.REQUEST_NULL) self.assertEqual(rreq, MPI.REQUEST_NULL)
def testPackUnpackExternal(self): for array, typecode1 in arrayimpl.loop(): with arrayimpl.test(self): if unittest.is_mpi_gpu('mpich', array): continue if unittest.is_mpi_gpu('openmpi', array): continue if unittest.is_mpi_gpu('mvapich2', array): continue if typecode1 in self.skipdtype: continue for typecode2 in array.TypeMap: if typecode2 in self.skipdtype: continue datatype1 = array.TypeMap[typecode1] datatype2 = array.TypeMap[typecode2] for count in range(1, 10): with self.subTest(count=count, typecode=(typecode1, typecode2)): # input and output arrays val = 127 if typecode1 == 'b' else 255 iarray1 = array(val, typecode1, count).as_raw() iarray2 = array(range(count), typecode2).as_raw() oarray1 = array(-1, typecode1, count).as_raw() oarray2 = array(-1, typecode2, count).as_raw() # temp array for packing size1 = datatype1.Pack_external_size( EXT32, len(iarray1)) size2 = datatype2.Pack_external_size( EXT32, len(iarray2)) tmpbuf = array(0, 'b', size1 + size2 + 1).as_raw() # pack input arrays position = 0 position = datatype1.Pack_external( EXT32, iarray1, tmpbuf, position) position = datatype2.Pack_external( EXT32, iarray2, tmpbuf, position) # unpack output arrays position = 0 position = datatype1.Unpack_external( EXT32, tmpbuf, position, oarray1) position = datatype2.Unpack_external( EXT32, tmpbuf, position, oarray2) # test result self.assertTrue(allclose(iarray1, oarray1)) self.assertTrue(allclose(iarray2, oarray2))
def testIReadIWriteAt(self): comm = self.COMM size = comm.Get_size() rank = comm.Get_rank() fh = self.FILE for array, typecode in arrayimpl_loop_io(): with arrayimpl.test(self): etype = array.TypeMap[typecode] fh.Set_size(0) fh.Set_view(0, etype) count = 13 wbuf = array(42, typecode, count) fh.Iwrite_at(count * rank, wbuf.as_raw()).Wait() fh.Sync() comm.Barrier() fh.Sync() rbuf = array(-1, typecode, count + 1) fh.Iread_at(count * rank, rbuf.as_mpi_c(count)).Wait() for value in rbuf[:-1]: self.assertEqual(value, 42) self.assertEqual(rbuf[-1], -1) comm.Barrier()
def testPackUnpack(self): for array, typecode1 in arrayimpl.loop(): with arrayimpl.test(self): if typecode1 in self.skipdtype: continue for typecode2 in array.TypeMap: if typecode2 in self.skipdtype: continue datatype1 = array.TypeMap[typecode1] datatype2 = array.TypeMap[typecode2] for count in range(10): with self.subTest(typecode=(typecode1, typecode2), count=count): # input and output arrays iarray1 = array(range(count), typecode1).as_raw() iarray2 = array(range(count), typecode2).as_raw() oarray1 = array(count, typecode1, count).as_raw() oarray2 = array(count, typecode2, count).as_raw() # temp array for packing size1 = datatype1.Pack_size( len(iarray1), self.COMM) size2 = datatype2.Pack_size( len(iarray2), self.COMM) tmpbuf = array(0, 'b', size1 + size2 + 1).as_raw() # pack input arrays position = 0 position = datatype1.Pack(iarray1, tmpbuf, position, self.COMM) position = datatype2.Pack(iarray2, tmpbuf, position, self.COMM) # unpack output arrays position = 0 position = datatype1.Unpack( tmpbuf, position, oarray1, self.COMM) position = datatype2.Unpack( tmpbuf, position, oarray2, self.COMM) # test self.assertTrue(allclose(iarray1, oarray1)) self.assertTrue(allclose(iarray2, oarray2))
def testPutGet(self): group = self.WIN.Get_group() size = group.Get_size() group.Free() for array, typecode in arrayimpl.loop(): with arrayimpl.test(self): if unittest.is_mpi_gpu('mvapich2', array): continue for count in range(self.COUNT_MIN, 10): for rank in range(size): with self.subTest(rank=rank, count=count): sbuf = array([rank]*count, typecode) rbuf = array(-1, typecode, count+1) self.WIN.Fence() self.WIN.Lock(rank) r = self.WIN.Rput(sbuf.as_mpi(), rank) r.Wait() self.WIN.Flush(rank) r = self.WIN.Rget(rbuf.as_mpi_c(count), rank) r.Wait() self.WIN.Unlock(rank) for i in range(count): self.assertEqual(sbuf[i], rank) self.assertEqual(rbuf[i], rank) self.assertEqual(rbuf[-1], -1)
def testAccumulate(self): group = self.WIN.Get_group() size = group.Get_size() group.Free() for array, typecode in arrayimpl.loop(): with arrayimpl.test(self): if unittest.is_mpi_gpu('openmpi', array): continue if unittest.is_mpi_gpu('mvapich2', array): continue if typecode in 'FDG': continue for count in range(10): for rank in range(size): with self.subTest(rank=rank, count=count): sbuf = array(range(count), typecode) rbuf = array(-1, typecode, count + 1) for op in (MPI.SUM, MPI.PROD, MPI.MAX, MPI.MIN): self.WIN.Fence() self.WIN.Accumulate(sbuf.as_mpi(), rank, op=op) self.WIN.Fence() self.WIN.Get(rbuf.as_mpi_c(count), rank) self.WIN.Fence() for i in range(count): self.assertEqual(sbuf[i], i) self.assertNotEqual(rbuf[i], -1) self.assertEqual(rbuf[-1], -1)
def testProbeRecv(self): comm = self.COMM size = comm.Get_size() rank = comm.Get_rank() for array, typecode in arrayimpl.loop(): with arrayimpl.test(self): for s in range(0, size+1): with self.subTest(s=s): sbuf = array( s, typecode, s) rbuf = array(-1, typecode, s) if size == 1: n = comm.Improbe(0, 0) self.assertEqual(n, None) sr = comm.Isend(sbuf.as_mpi(), 0, 0) m = comm.Mprobe(0, 0) self.assertTrue(isinstance(m, MPI.Message)) self.assertTrue(m) rr = m.Irecv(rbuf.as_raw()) self.assertFalse(m) self.assertTrue(sr) self.assertTrue(rr) MPI.Request.Waitall([sr,rr]) self.assertFalse(sr) self.assertFalse(rr) # n = comm.Improbe(0, 0) self.assertEqual(n, None) r = comm.Isend(sbuf.as_mpi(), 0, 0) m = MPI.Message.Probe(comm, 0, 0) self.assertTrue(isinstance(m, MPI.Message)) self.assertTrue(m) m.Recv(rbuf.as_raw()) self.assertFalse(m) r.Wait() # n = MPI.Message.Iprobe(comm, 0, 0) self.assertEqual(n, None) r = comm.Isend(sbuf.as_mpi(), 0, 0) comm.Probe(0, 0) m = MPI.Message.Iprobe(comm, 0, 0) self.assertTrue(isinstance(m, MPI.Message)) self.assertTrue(m) m.Recv(rbuf.as_raw()) self.assertFalse(m) r.Wait() # n = MPI.Message.Iprobe(comm, 0, 0) self.assertEqual(n, None) r = comm.Isend(sbuf.as_mpi(), 0, 0) m = comm.Mprobe(0, 0) self.assertTrue(isinstance(m, MPI.Message)) self.assertTrue(m) m.Recv(rbuf.as_raw()) self.assertFalse(m) r.Wait() elif rank == 0: n = comm.Improbe(0, 0) self.assertEqual(n, None) # comm.Send(sbuf.as_mpi(), 1, 0) m = comm.Mprobe(1, 0) self.assertTrue(m) m.Recv(rbuf.as_raw()) self.assertFalse(m) # n = comm.Improbe(0, 0) self.assertEqual(n, None) comm.Send(sbuf.as_mpi(), 1, 1) m = None while not m: m = comm.Improbe(1, 1) m.Irecv(rbuf.as_raw()).Wait() elif rank == 1: n = comm.Improbe(1, 0) self.assertEqual(n, None) # m = comm.Mprobe(0, 0) self.assertTrue(m) m.Recv(rbuf.as_raw()) self.assertFalse(m) # n = comm.Improbe(1, 0) self.assertEqual(n, None) comm.Send(sbuf.as_mpi(), 0, 0) m = None while not m: m = comm.Improbe(0, 1) m.Irecv(rbuf.as_mpi()).Wait() comm.Send(sbuf.as_mpi(), 0, 1) else: rbuf = sbuf for value in rbuf: self.assertEqual(value, s)
def testPersistent(self): size = self.COMM.Get_size() rank = self.COMM.Get_rank() dest = (rank + 1) % size source = (rank - 1) % size for array, typecode in arrayimpl.loop(): with arrayimpl.test(self): if unittest.is_mpi_gpu('openmpi', array): continue if unittest.is_mpi_gpu('mvapich2', array): continue for s, xs in itertools.product(range(size + 1), range(3)): with self.subTest(s=s, xs=xs): # sbuf = array(s, typecode, s) rbuf = array(-1, typecode, s + xs) sendreq = self.COMM.Send_init(sbuf.as_mpi(), dest, 0) recvreq = self.COMM.Recv_init(rbuf.as_mpi(), source, 0) sendreq.Start() recvreq.Start() sendreq.Wait() recvreq.Wait() self.assertNotEqual(sendreq, MPI.REQUEST_NULL) self.assertNotEqual(recvreq, MPI.REQUEST_NULL) sendreq.Free() recvreq.Free() self.assertEqual(sendreq, MPI.REQUEST_NULL) self.assertEqual(recvreq, MPI.REQUEST_NULL) for value in rbuf[:s]: self.assertEqual(value, s) for value in rbuf[s:]: self.assertEqual(value, -1) # sbuf = array(s, typecode, s) rbuf = array(-1, typecode, s + xs) sendreq = self.COMM.Send_init(sbuf.as_mpi(), dest, 0) recvreq = self.COMM.Recv_init(rbuf.as_mpi(), source, 0) reqlist = [sendreq, recvreq] MPI.Prequest.Startall(reqlist) index1 = MPI.Prequest.Waitany(reqlist) self.assertTrue(index1 in [0, 1]) self.assertNotEqual(reqlist[index1], MPI.REQUEST_NULL) index2 = MPI.Prequest.Waitany(reqlist) self.assertTrue(index2 in [0, 1]) self.assertNotEqual(reqlist[index2], MPI.REQUEST_NULL) self.assertTrue(index1 != index2) index3 = MPI.Prequest.Waitany(reqlist) self.assertEqual(index3, MPI.UNDEFINED) for preq in reqlist: self.assertNotEqual(preq, MPI.REQUEST_NULL) preq.Free() self.assertEqual(preq, MPI.REQUEST_NULL) for value in rbuf[:s]: self.assertEqual(value, s) for value in rbuf[s:]: self.assertEqual(value, -1) # sbuf = array(s, typecode, s) rbuf = array(-1, typecode, s + xs) sendreq = self.COMM.Ssend_init(sbuf.as_mpi(), dest, 0) recvreq = self.COMM.Recv_init(rbuf.as_mpi(), source, 0) sendreq.Start() recvreq.Start() sendreq.Wait() recvreq.Wait() self.assertNotEqual(sendreq, MPI.REQUEST_NULL) self.assertNotEqual(recvreq, MPI.REQUEST_NULL) sendreq.Free() recvreq.Free() self.assertEqual(sendreq, MPI.REQUEST_NULL) self.assertEqual(recvreq, MPI.REQUEST_NULL) for value in rbuf[:s]: self.assertEqual(value, s) for value in rbuf[s:]: self.assertEqual(value, -1) # mem = array(0, typecode, s + MPI.BSEND_OVERHEAD).as_raw() sbuf = array(s, typecode, s) rbuf = array(-1, typecode, s + xs) MPI.Attach_buffer(mem) sendreq = self.COMM.Bsend_init(sbuf.as_mpi(), dest, 0) recvreq = self.COMM.Recv_init(rbuf.as_mpi(), source, 0) sendreq.Start() recvreq.Start() sendreq.Wait() recvreq.Wait() MPI.Detach_buffer() self.assertNotEqual(sendreq, MPI.REQUEST_NULL) self.assertNotEqual(recvreq, MPI.REQUEST_NULL) sendreq.Free() recvreq.Free() self.assertEqual(sendreq, MPI.REQUEST_NULL) self.assertEqual(recvreq, MPI.REQUEST_NULL) for value in rbuf[:s]: self.assertEqual(value, s) for value in rbuf[s:]: self.assertEqual(value, -1) # rank = self.COMM.Get_rank() sbuf = array(s, typecode, s) rbuf = array(-1, typecode, s + xs) recvreq = self.COMM.Recv_init(rbuf.as_mpi(), rank, 0) sendreq = self.COMM.Rsend_init(sbuf.as_mpi(), rank, 0) recvreq.Start() sendreq.Start() recvreq.Wait() sendreq.Wait() self.assertNotEqual(sendreq, MPI.REQUEST_NULL) self.assertNotEqual(recvreq, MPI.REQUEST_NULL) sendreq.Free() recvreq.Free() self.assertEqual(sendreq, MPI.REQUEST_NULL) self.assertEqual(recvreq, MPI.REQUEST_NULL) for value in rbuf[:s]: self.assertEqual(value, s) for value in rbuf[s:]: self.assertEqual(value, -1)