Пример #1
0
 def testExscan(self):
     size = self.COMM.Get_size()
     rank = self.COMM.Get_rank()
     for array, typecode in arrayimpl.loop():
         for op in (MPI.SUM, MPI.PROD, MPI.MAX, MPI.MIN):
             if skip_op(typecode, op): continue
             buf = array(range(size), typecode)
             StartWaitFree(
             self.COMM.Exscan_init(MPI.IN_PLACE,
                                   buf.as_mpi(),
                                   op)
             )
             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)
Пример #2
0
 def testReduce(self):
     size = self.COMM.Get_size()
     rank = self.COMM.Get_rank()
     for array, typecode in arrayimpl.loop():
         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()
                 StartWaitFree(
                 self.COMM.Reduce_init(sbuf, rbuf, op, root)
                 )
                 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)
Пример #3
0
 def testGatherv3(self):
     size = self.COMM.Get_size()
     rank = self.COMM.Get_rank()
     for array, typecode in arrayimpl.loop():
         for root in range(size):
             for count in range(size + 1):
                 #
                 sbuf = array(root, typecode, count).as_raw()
                 rbuf = array(-1, typecode, count * size).as_raw()
                 sendbuf = sbuf
                 recvbuf = [rbuf, count]
                 if rank != root: recvbuf = None
                 StartWaitFree(
                     self.COMM.Gatherv_init(sendbuf, recvbuf, root))
                 if recvbuf is not None:
                     for v in rbuf:
                         self.assertEqual(v, root)
                 #
                 sbuf = array(root, typecode, count).as_raw()
                 if rank == root:
                     rbuf = array(-1, typecode, count * size).as_raw()
                 else:
                     rbuf = None
                 StartWaitFree(self.COMM.Gatherv_init(sbuf, rbuf, root))
                 if rank == root:
                     for v in rbuf:
                         self.assertEqual(v, root)
Пример #4
0
 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)
Пример #5
0
 def testScatterv3(self):
     size = self.COMM.Get_size()
     rank = self.COMM.Get_rank()
     for array, typecode in arrayimpl.loop():
         for root in range(size):
             for count in range(size + 1):
                 #
                 sbuf = array(root, typecode, count * size).as_raw()
                 rbuf = array(-1, typecode, count).as_raw()
                 sendbuf = [sbuf, count]
                 recvbuf = rbuf
                 if rank != root: sendbuf = None
                 StartWaitFree(
                     self.COMM.Scatterv_init(sendbuf, recvbuf, root))
                 for v in rbuf:
                     self.assertEqual(v, root)
                 #
                 if rank == root:
                     sbuf = array(root, typecode, count * size).as_raw()
                 else:
                     sbuf = None
                 rbuf = array(-1, typecode, count).as_raw()
                 StartWaitFree(self.COMM.Scatterv_init(sbuf, rbuf, root))
                 for v in rbuf:
                     self.assertEqual(v, root)
Пример #6
0
 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)
Пример #7
0
 def testNeighborAlltoall(self):
     for comm in create_topo_comms(self.COMM):
         rsize, ssize = get_neighbors_count(comm)
         for array, typecode in arrayimpl.loop():
             for v in range(3):
                 sbuf = array(v, typecode, (ssize, 3))
                 rbuf = array(-1, typecode, (rsize, 3))
                 comm.Neighbor_alltoall(sbuf.as_mpi(), rbuf.as_mpi_c(3))
                 for value in rbuf.flat:
                     self.assertEqual(value, v)
                 sbuf = array(v, typecode, (ssize, 3))
                 rbuf = array(-1, typecode, (rsize, 3))
                 comm.Neighbor_alltoall(sbuf.as_mpi(), rbuf.as_mpi())
                 for value in rbuf.flat:
                     self.assertEqual(value, v)
                 sbuf = array(v, typecode, (ssize, 3))
                 rbuf = array(-1, typecode, (rsize, 3))
                 comm.Neighbor_alltoallv(sbuf.as_mpi_c(3), rbuf.as_mpi_c(3))
                 for value in rbuf.flat:
                     self.assertEqual(value, v)
                 sbuf = array(v, typecode, (ssize, 3))
                 rbuf = array(-1, typecode, (rsize, 3))
                 comm.Ineighbor_alltoall(sbuf.as_mpi(),
                                         rbuf.as_mpi()).Wait()
                 for value in rbuf.flat:
                     self.assertEqual(value, v)
                 sbuf = array(v, typecode, (ssize, 3))
                 rbuf = array(-1, typecode, (rsize, 3))
                 comm.Ineighbor_alltoallv(sbuf.as_mpi_c(3),
                                          rbuf.as_mpi_c(3)).Wait()
                 for value in rbuf.flat:
                     self.assertEqual(value, v)
         comm.Free()
Пример #8
0
 def testGather(self):
     size = self.COMM.Get_size()
     rank = self.COMM.Get_rank()
     for array, typecode in arrayimpl.loop():
         for root in range(size):
             count = root+3
             if rank == root:
                 sbuf = MPI.IN_PLACE
                 buf = array(-1, typecode, (size, count))
                 #buf.flat[(rank*count):((rank+1)*count)] = \
                 #    array(root, typecode, count)
                 s, e = rank*count, (rank+1)*count
                 for i in range(s, e): buf.flat[i] = root
                 rbuf = buf.as_mpi()
             else:
                 buf = array(root, typecode, count)
                 sbuf = buf.as_mpi()
                 rbuf = None
             self.COMM.Igather(sbuf, rbuf, root=root).Wait()
             for value in buf.flat:
                 self.assertEqual(value, root)
             if rank == root:
                 sbuf = None
             self.COMM.Igather(sbuf, rbuf, root=root).Wait()
             for value in buf.flat:
                 self.assertEqual(value, root)
Пример #9
0
 def testNeighborAlltoallwBottom(self):
     size = self.COMM.Get_size()
     for comm in create_topo_comms(self.COMM):
         rsize, ssize = get_neighbors_count(comm)
         for array, typecode in arrayimpl.loop():
             for n in range(1, 4):
                 for v in range(3):
                     sbuf = array(v, typecode, (ssize, n))
                     rbuf = array(-1, typecode, (rsize, n))
                     saddr = MPI.Get_address(sbuf.as_raw())
                     raddr = MPI.Get_address(rbuf.as_raw())
                     sdt, rdt = sbuf.mpidtype, rbuf.mpidtype
                     sdsp = list(
                         range(0, ssize * n * sdt.extent, n * sdt.extent))
                     rdsp = list(
                         range(0, rsize * n * rdt.extent, n * rdt.extent))
                     sdsp = [saddr + d for d in sdsp]
                     rdsp = [raddr + d for d in rdsp]
                     smsg = [MPI.BOTTOM, ([n] * ssize, sdsp), [sdt] * ssize]
                     rmsg = (MPI.BOTTOM, ([n] * rsize, rdsp), [rdt] * rsize)
                     try:
                         comm.Neighbor_alltoallw(smsg, rmsg)
                     except NotImplementedError:
                         self.skipTest('mpi-neighbor_alltoallw')
                     for value in rbuf.flat:
                         self.assertEqual(value, v)
                     sbuf.flat[:] = array(v + 1, typecode, (ssize, n)).flat
                     try:
                         comm.Ineighbor_alltoallw(smsg, rmsg).Wait()
                     except NotImplementedError:
                         self.skipTest('mpi-neighbor_alltoallw')
                     for value in rbuf.flat:
                         self.assertEqual(value, v + 1)
         comm.Free()
Пример #10
0
 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()
Пример #11
0
 def testAlltoallwBottom(self):
     size = self.COMM.Get_size()
     rank = self.COMM.Get_rank()
     for array, typecode in arrayimpl.loop():
         for n in range(1, size + 1):
             sbuf = array(n, typecode, (size, n))
             rbuf = array(-1, typecode, (size, n))
             saddr = MPI.Get_address(sbuf.as_raw())
             raddr = MPI.Get_address(rbuf.as_raw())
             sdt, rdt = sbuf.mpidtype, rbuf.mpidtype
             stypes = [
                 MPI.Datatype.Create_struct([n], [saddr + d],
                                            [sdt]).Commit()
                 for d in list(
                     range(0, size * n * sdt.extent, n * sdt.extent))
             ]
             rtypes = [
                 MPI.Datatype.Create_struct([n], [raddr + d],
                                            [sdt]).Commit()
                 for d in list(
                     range(0, size * n * rdt.extent, n * rdt.extent))
             ]
             smsg = (MPI.BOTTOM, ([1] * size, [0] * size), stypes)
             rmsg = (MPI.BOTTOM, ([1] * size, [0] * size), rtypes)
             try:
                 self.COMM.Alltoallw(smsg, rmsg)
             except NotImplementedError:
                 self.skipTest('mpi-alltoallw')
             finally:
                 for t in stypes:
                     t.Free()
                 for t in rtypes:
                     t.Free()
             for value in rbuf.flat:
                 self.assertEqual(value, n)
Пример #12
0
 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)
Пример #13
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)
Пример #14
0
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
Пример #15
0
 def testScan(self):
     size = self.COMM.Get_size()
     rank = self.COMM.Get_rank()
     # --
     for array, typecode in arrayimpl.loop():
         for op in (MPI.SUM, MPI.PROD, MPI.MAX, MPI.MIN):
             if skip_op(typecode, op): continue
             sbuf = array(range(size), typecode)
             rbuf = array(0, typecode, size)
             StartWaitFree(
             self.COMM.Scan_init(sbuf.as_mpi(),
                                 rbuf.as_mpi(),
                                 op)
             )
             max_val = maxvalue(rbuf)
             for i, value in enumerate(rbuf):
                 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)
Пример #16
0
 def testReduce(self):
     size = self.COMM.Get_size()
     rank = self.COMM.Get_rank()
     for array, typecode in arrayimpl.loop():
         for op in (MPI.SUM, MPI.PROD, MPI.MAX, MPI.MIN):
             if skip_op(typecode, op): continue
             for root in range(size):
                 sbuf = array(range(size), typecode)
                 rbuf = array(-1, typecode, size)
                 self.COMM.Reduce(sbuf.as_mpi(), rbuf.as_mpi(), op, root)
                 max_val = maxvalue(rbuf)
                 for i, value in enumerate(rbuf):
                     if rank != root:
                         self.assertEqual(value, -1)
                         continue
                     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)
Пример #17
0
 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)
Пример #18
0
 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)
Пример #19
0
 def testReduceScatter(self):
     size = self.COMM.Get_size()
     rank = self.COMM.Get_rank()
     for array, typecode in arrayimpl.loop():
         for op in (MPI.SUM, MPI.MAX, MPI.MIN, MPI.PROD):
             if skip_op(typecode, op): continue
             rcnt = list(range(1, size + 1))
             if op == MPI.PROD:
                 rbuf = array([rank + 1] * sum(rcnt), typecode)
             else:
                 rbuf = array([rank] * sum(rcnt), typecode)
             self.COMM.Reduce_scatter(MPI.IN_PLACE, rbuf.as_mpi(), rcnt, op)
             max_val = maxvalue(rbuf)
             for i, value in enumerate(rbuf):
                 if i >= rcnt[rank]:
                     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)
Пример #20
0
 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)
Пример #21
0
 def testExscan(self):
     size = self.COMM.Get_size()
     rank = self.COMM.Get_rank()
     for array, typecode in arrayimpl.loop():
         for op in (MPI.SUM, MPI.PROD, MPI.MAX, MPI.MIN):
             if skip_op(typecode, op): continue
             sbuf = array(range(size), typecode)
             rbuf = array(0, typecode, size)
             try:
                 self.COMM.Exscan(sbuf.as_mpi(), rbuf.as_mpi(), op)
             except NotImplementedError:
                 self.skipTest('mpi-exscan')
             if rank == 1:
                 for i, value in enumerate(rbuf):
                     self.assertEqual(value, i)
             elif rank > 1:
                 max_val = maxvalue(rbuf)
                 for i, value in enumerate(rbuf):
                     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)
Пример #22
0
 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)
Пример #23
0
 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)
Пример #24
0
 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)
Пример #25
0
 def testAlltoall(self):
     size = self.COMM.Get_size()
     rank = self.COMM.Get_rank()
     for array, typecode in arrayimpl.loop():
         for root in range(size):
             sbuf = array(root, typecode, (size, root+1))
             rbuf = array(  -1, typecode, (size, root+1))
             self.COMM.Ialltoall(sbuf.as_mpi(), rbuf.as_mpi_c(root+1)).Wait()
             for value in rbuf.flat:
                 self.assertEqual(value, root)
Пример #26
0
 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
Пример #27
0
 def testAllgather(self):
     size = self.COMM.Get_size()
     rank = self.COMM.Get_rank()
     for array, typecode in arrayimpl.loop():
         for root in range(size):
             sbuf = array(root, typecode, root+1)
             rbuf = array(  -1, typecode, (size, root+1))
             StartWaitFree(
             self.COMM.Allgather_init(sbuf.as_mpi(), rbuf.as_mpi())
             )
             for value in rbuf.flat:
                 self.assertEqual(value, root)
Пример #28
0
 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)
Пример #29
0
 def testBcast(self):
     size = self.COMM.Get_size()
     rank = self.COMM.Get_rank()
     for array, typecode in arrayimpl.loop():
         for root in range(size):
             if rank == root:
                 buf = array(root, typecode, root)
             else:
                 buf = array(  -1, typecode, root)
             self.COMM.Ibcast(buf.as_mpi(), root=root).Wait()
             for value in buf:
                 self.assertEqual(value, root)
Пример #30
0
 def testScatter(self):
     size = self.COMM.Get_size()
     rank = self.COMM.Get_rank()
     for array, typecode in arrayimpl.loop():
         for root in range(size):
             rbuf = array(-1, typecode, size)
             if rank == root:
                 sbuf = array(root, typecode, (size, size))
             else:
                 sbuf = array([], typecode)
             self.COMM.Scatter(sbuf.as_mpi(), rbuf.as_mpi(), root=root)
             for value in rbuf:
                 self.assertEqual(value, root)