def testAccumulate(self): group = self.WIN.Get_group() size = group.Get_size() group.Free() for array, typecode in arrayimpl.subTest(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): 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 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 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 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 arrayimpl_loop_io(): openmpi = unittest.mpi_predicate('openmpi(<5.0.0)') is_i386 = platform.machine() in ('i386', 'i686') for array, typecode in arrayimpl.loop(): if unittest.is_mpi_gpu('mvapich2', array): continue if openmpi and is_i386 and typecode in ('g', 'G'): continue yield array, typecode
def testScan(self): size = self.COMM.Get_size() rank = self.COMM.Get_rank() # -- for array, typecode in arrayimpl.loop(): # segfault as of OpenMPI 4.1.1 if unittest.is_mpi_gpu('openmpi', array): continue for op in (MPI.SUM, MPI.PROD, MPI.MAX, MPI.MIN): if skip_op(typecode, op): continue buf = array(range(size), typecode) self.COMM.Iscan(MPI.IN_PLACE, buf.as_mpi(), op).Wait() max_val = maxvalue(buf) for i, value in enumerate(buf): if op == MPI.SUM: if (i * (rank + 1)) < max_val: self.assertAlmostEqual(value, i * (rank + 1)) elif op == MPI.PROD: if (i ** (rank + 1)) < max_val: self.assertAlmostEqual(value, i ** (rank + 1)) elif op == MPI.MAX: self.assertEqual(value, i) elif op == MPI.MIN: self.assertEqual(value, i)
def testReduceScatterBlock(self): size = self.COMM.Get_size() rank = self.COMM.Get_rank() for array, typecode in arrayimpl.loop(): # segfault as of OpenMPI 4.1.1 if unittest.is_mpi_gpu('openmpi', array): continue for op in (MPI.SUM, MPI.MAX, MPI.MIN, MPI.PROD): if skip_op(typecode, op): continue for rcnt in range(1, size+1): sbuf = array([rank]*rcnt*size, typecode) rbuf = array(-1, typecode, rcnt) if op == MPI.PROD: sbuf = array([rank+1]*rcnt*size, typecode) self.COMM.Ireduce_scatter_block(sbuf.as_mpi(), rbuf.as_mpi(), op).Wait() max_val = maxvalue(rbuf) v_sum = (size*(size-1))/2 v_prod = 1 for i in range(1,size+1): v_prod *= i v_max = size-1 v_min = 0 for i, value in enumerate(rbuf): if op == MPI.SUM: if v_sum <= max_val: self.assertAlmostEqual(value, v_sum) elif op == MPI.PROD: if v_prod <= max_val: self.assertAlmostEqual(value, v_prod) elif op == MPI.MAX: self.assertEqual(value, v_max) elif op == MPI.MIN: self.assertEqual(value, v_min)
def testReduce(self): size = self.COMM.Get_size() rank = self.COMM.Get_rank() for array, typecode in arrayimpl.loop(): # segfault as of OpenMPI 4.1.1 if unittest.is_mpi_gpu('openmpi', array): continue for op in (MPI.SUM, MPI.PROD, MPI.MAX, MPI.MIN): if skip_op(typecode, op): continue for root in range(size): count = size if rank == root: buf = array(range(size), typecode) sbuf = MPI.IN_PLACE rbuf = buf.as_mpi() else: buf = array(range(size), typecode) buf2 = array(range(size), typecode) sbuf = buf.as_mpi() rbuf = buf2.as_mpi() self.COMM.Ireduce(sbuf, rbuf, op, root).Wait() if rank == root: max_val = maxvalue(buf) for i, value in enumerate(buf): if op == MPI.SUM: if (i * size) < max_val: self.assertAlmostEqual(value, i*size) elif op == MPI.PROD: if (i ** size) < max_val: self.assertAlmostEqual(value, i**size) elif op == MPI.MAX: self.assertEqual(value, i) elif op == MPI.MIN: self.assertEqual(value, i)
def testAllreduce(self): size = self.COMM.Get_size() rank = self.COMM.Get_rank() for array, typecode in arrayimpl.loop(): # segfault as of OpenMPI 4.1.1 if unittest.is_mpi_gpu('openmpi', array): continue for op in (MPI.SUM, MPI.MAX, MPI.MIN, MPI.PROD): if skip_op(typecode, op): continue sbuf = array(range(size), typecode) rbuf = array(0, typecode, size) self.COMM.Iallreduce(sbuf.as_mpi(), rbuf.as_mpi(), op).Wait() max_val = maxvalue(rbuf) for i, value in enumerate(rbuf): if op == MPI.SUM: if (i * size) < max_val: self.assertAlmostEqual(value, i*size) elif op == MPI.PROD: if (i ** size) < max_val: self.assertAlmostEqual(value, i**size) elif op == MPI.MAX: self.assertEqual(value, i) elif op == MPI.MIN: self.assertEqual(value, i)
def testReduceScatterBlock(self): size = self.COMM.Get_size() rank = self.COMM.Get_rank() for array, typecode in arrayimpl.loop(): # one of the ranks would fail as of OpenMPI 4.1.1 if unittest.is_mpi_gpu('openmpi', array): continue for op in (MPI.SUM, MPI.MAX, MPI.MIN, MPI.PROD): if skip_op(typecode, op): continue for rcnt in range(size): if op == MPI.PROD: rbuf = array([rank + 1] * rcnt * size, typecode) else: rbuf = array([rank] * rcnt * size, typecode) self.COMM.Reduce_scatter_block(MPI.IN_PLACE, rbuf.as_mpi(), op) max_val = maxvalue(rbuf) for i, value in enumerate(rbuf): if i >= rcnt: if op == MPI.PROD: self.assertEqual(value, rank + 1) else: self.assertEqual(value, rank) else: if op == MPI.SUM: redval = sum(range(size)) if redval < max_val: self.assertAlmostEqual(value, redval) elif op == MPI.PROD: redval = prod(range(1, size + 1)) if redval < max_val: self.assertAlmostEqual(value, redval) elif op == MPI.MAX: self.assertEqual(value, size - 1) elif op == MPI.MIN: self.assertEqual(value, 0)
def testExscan(self): size = self.COMM.Get_size() rank = self.COMM.Get_rank() for array, typecode in arrayimpl.loop(): # segfault as of OpenMPI 4.1.1 if unittest.is_mpi_gpu('openmpi', array): continue for op in (MPI.SUM, MPI.PROD, MPI.MAX, MPI.MIN): if skip_op(typecode, op): continue buf = array(range(size), typecode) try: self.COMM.Iexscan(MPI.IN_PLACE, buf.as_mpi(), op).Wait() except NotImplementedError: self.skipTest('mpi-exscan') if rank == 1: for i, value in enumerate(buf): self.assertEqual(value, i) elif rank > 1: max_val = maxvalue(buf) for i, value in enumerate(buf): if op == MPI.SUM: if (i * rank) < max_val: self.assertAlmostEqual(value, i * rank) elif op == MPI.PROD: if (i ** rank) < max_val: self.assertAlmostEqual(value, i ** rank) elif op == MPI.MAX: self.assertEqual(value, i) elif op == MPI.MIN: self.assertEqual(value, i)
def testNeighborAllgather(self): for comm in create_topo_comms(self.COMM): rsize, ssize = get_neighbors_count(comm) for array, typecode in arrayimpl.loop(): if unittest.is_mpi_gpu('openmpi', array): # segfault as of OpenMPI 4.1.1; TODO(leofang): why? if array.backend == 'numba': continue for v in range(3): sbuf = array(v, typecode, 3) rbuf = array(-1, typecode, (rsize, 3)) comm.Neighbor_allgather(sbuf.as_mpi(), rbuf.as_mpi()) for value in rbuf.flat: self.assertEqual(value, v) sbuf = array(v, typecode, 3) rbuf = array(-1, typecode, (rsize, 3)) comm.Neighbor_allgatherv(sbuf.as_mpi_c(3), rbuf.as_mpi_c(3)) for value in rbuf.flat: self.assertEqual(value, v) sbuf = array(v, typecode, 3) rbuf = array(-1, typecode, (rsize, 3)) comm.Ineighbor_allgather(sbuf.as_mpi(), rbuf.as_mpi()).Wait() for value in rbuf.flat: self.assertEqual(value, v) sbuf = array(v, typecode, 3) rbuf = array(-1, typecode, (rsize, 3)) comm.Ineighbor_allgatherv(sbuf.as_mpi_c(3), rbuf.as_mpi_c(3)).Wait() for value in rbuf.flat: self.assertEqual(value, v) comm.Free()
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 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 testReduceLocalBadCount(self): for array, typecode in arrayimpl.subTest(self): if unittest.is_mpi_gpu('openmpi', array): continue for op in (MPI.SUM, MPI.PROD, MPI.MAX, MPI.MIN): sbuf = array(range(3), typecode) rbuf = array(range(3), typecode) def f(): op.Reduce_local(sbuf.as_mpi_c(2), rbuf.as_mpi_c(3)) self.assertRaises(ValueError, f) def f(): op.Reduce_local([sbuf.as_raw(), 1, MPI.INT], [rbuf.as_raw(), 1, MPI.SHORT]) self.assertRaises(ValueError, f)
def testAccumulate(self): group = self.WIN.Get_group() size = group.Get_size() group.Free() for array, typecode in arrayimpl.subTest(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): 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 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 testReduceScatter(self): size = self.COMM.Get_size() rank = self.COMM.Get_rank() for array, typecode in arrayimpl.loop(): # segfault as of OpenMPI 4.1.1 if unittest.is_mpi_gpu('openmpi', array): continue for op in (MPI.SUM, MPI.MAX, MPI.MIN, MPI.PROD): if skip_op(typecode, op): continue rcnt = list(range(1,size+1)) sbuf = array([rank+1]*sum(rcnt), typecode) rbuf = array(-1, typecode, rank+1) self.COMM.Ireduce_scatter(sbuf.as_mpi(), rbuf.as_mpi(), None, op).Wait() max_val = maxvalue(rbuf) for i, value in enumerate(rbuf): if op == MPI.SUM: redval = sum(range(size))+size if redval < max_val: self.assertAlmostEqual(value, redval) elif op == MPI.PROD: redval = prod(range(1,size+1)) if redval < max_val: self.assertAlmostEqual(value, redval) elif op == MPI.MAX: self.assertEqual(value, size) elif op == MPI.MIN: self.assertEqual(value, 1) rbuf = array(-1, typecode, rank+1) self.COMM.Ireduce_scatter(sbuf.as_mpi(), rbuf.as_mpi(), rcnt, op).Wait() max_val = maxvalue(rbuf) for i, value in enumerate(rbuf): if op == MPI.SUM: redval = sum(range(size))+size if redval < max_val: self.assertAlmostEqual(value, redval) elif op == MPI.PROD: redval = prod(range(1,size+1)) if redval < max_val: self.assertAlmostEqual(value, redval) elif op == MPI.MAX: self.assertEqual(value, size) elif op == MPI.MIN: self.assertEqual(value, 1)
def testReduceLocal(self): for array, typecode in arrayimpl.subTest(self): if unittest.is_mpi_gpu('openmpi', array): continue for op in (MPI.SUM, MPI.PROD, MPI.MAX, MPI.MIN): if skip_op(typecode, op): continue size = 5 sbuf = array(range(1,size+1), typecode) rbuf = array(range(0,size+0), typecode) try: op.Reduce_local(sbuf.as_mpi(), rbuf.as_mpi()) except NotImplementedError: self.skipTest('mpi-op-reduce_local') for i, value in enumerate(rbuf): self.assertEqual(sbuf[i], i+1) if op == MPI.SUM: self.assertAlmostEqual(value, i+(i+1)) elif op == MPI.PROD: self.assertAlmostEqual(value, i*(i+1)) elif op == MPI.MAX: self.assertEqual(value, i+1) elif op == MPI.MIN: self.assertEqual(value, i)
def testPutGet(self): group = self.WIN.Get_group() size = group.Get_size() group.Free() for array, typecode in arrayimpl.subTest(self): if unittest.is_mpi_gpu('mvapich2', array): continue for count in range(self.COUNT_MIN, 10): for rank in range(size): 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 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.subTest(self): if unittest.is_mpi_gpu('mvapich2', array): continue for s in range(size): for xs in range(3): # 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)
from mpi4py import MPI import mpiunittest as unittest import arrayimpl import sys, os, tempfile def subTestIO(case, *args, **kwargs): for array, typecode in arrayimpl.subTest(case, *args, **kwargs): if unittest.is_mpi_gpu('mvapich2', array): continue yield array, typecode class BaseTestIO(object): COMM = MPI.COMM_NULL FILE = MPI.FILE_NULL prefix = 'mpi4py-' def setUp(self): comm = self.COMM fname = None if comm.Get_rank() == 0: fd, fname = tempfile.mkstemp(prefix=self.prefix) os.close(fd) fname = comm.bcast(fname, 0) amode = MPI.MODE_RDWR | MPI.MODE_CREATE amode |= MPI.MODE_DELETE_ON_CLOSE amode |= MPI.MODE_UNIQUE_OPEN info = MPI.INFO_NULL try: