File: test_p2p_buf_part.py

package info (click to toggle)
mpi4py 4.1.0-4
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 4,540 kB
  • sloc: python: 34,465; ansic: 16,475; makefile: 614; sh: 325; cpp: 193; f90: 178
file content (206 lines) | stat: -rw-r--r-- 8,449 bytes parent folder | download | duplicates (2)
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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
import arrayimpl
import mpiunittest as unittest

from mpi4py import MPI


class BaseTestP2PBufPart:
    #
    COMM = MPI.COMM_NULL

    def testSelf(self):
        size = self.COMM.Get_size()
        rank = self.COMM.Get_rank()
        for array, typecode in arrayimpl.loop():
            with arrayimpl.test(self):
                for s in range(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, rank, 0
                            )
                            rreq = self.COMM.Precv_init(
                                rbuf.as_mpi(), p, rank, 0
                            )
                            for _ in range(3):
                                rreq.Start()
                                for i in range(p):
                                    flag = rreq.Parrived(i)
                                    self.assertFalse(flag)
                                sreq.Start()
                                for i in range(p):
                                    sreq.Pready(i)
                                    for j in range(i + 1, p):
                                        flag = rreq.Parrived(j)
                                        self.assertFalse(flag)
                                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)
                                check = arrayimpl.scalar(s)
                                for value in rbuf:
                                    self.assertEqual(value, check)
                            rreq.Free()
                            sreq.Free()
                            self.assertEqual(sreq, MPI.REQUEST_NULL)
                            self.assertEqual(rreq, MPI.REQUEST_NULL)

    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(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()
                                check = arrayimpl.scalar(s)
                                for value in rbuf:
                                    self.assertEqual(value, check)
                            rreq.Free()
                            sreq.Free()
                            self.assertEqual(sreq, MPI.REQUEST_NULL)
                            self.assertEqual(rreq, MPI.REQUEST_NULL)

    def testRingRangeList(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(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 case in range(4):
                                self.COMM.Barrier()
                                rreq.Start()
                                for i in range(p):
                                    flag = rreq.Parrived(i)
                                    self.assertFalse(flag)
                                self.COMM.Barrier()
                                sreq.Start()
                                if p > 1 and case % 2 == 0:
                                    sreq.Pready_range(0, p // 2 - 1)
                                    sreq.Pready_range(p // 2, p - 1)
                                else:
                                    sreq.Pready_list(list(range(p // 2)))
                                    sreq.Pready_list(list(range(p // 2, p)))
                                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()
                                check = arrayimpl.scalar(s)
                                for value in rbuf:
                                    self.assertEqual(value, check)
                            rreq.Free()
                            sreq.Free()
                            self.assertEqual(sreq, MPI.REQUEST_NULL)
                            self.assertEqual(rreq, MPI.REQUEST_NULL)


class TestP2PBufPartSelf(BaseTestP2PBufPart, unittest.TestCase):
    #
    COMM = MPI.COMM_SELF


class TestP2PBufPartWorld(BaseTestP2PBufPart, unittest.TestCase):
    #
    COMM = MPI.COMM_WORLD


class TestP2PBufPartSelfDup(TestP2PBufPartSelf):
    #
    def setUp(self):
        self.COMM = MPI.COMM_SELF.Dup()

    def tearDown(self):
        self.COMM.Free()


class TestP2PBufPartWorldDup(TestP2PBufPartWorld):
    #
    def setUp(self):
        self.COMM = MPI.COMM_WORLD.Dup()

    def tearDown(self):
        self.COMM.Free()


def have_feature():
    info = MPI.Get_library_version()
    if "MPICH" in info and "ch3:" in info:
        raise NotImplementedError
    sreq = MPI.COMM_SELF.Psend_init(bytearray(1), 1, 0, 0)
    rreq = MPI.COMM_SELF.Precv_init(bytearray(1), 1, 0, 0)
    sreq.Start()
    rreq.Start()
    sreq.Pready(0)
    rreq.Parrived(0)
    rreq.Wait()
    rreq.Free()
    del rreq
    sreq.Wait()
    sreq.Free()
    del sreq


try:
    have_feature()
except NotImplementedError:
    unittest.disable(BaseTestP2PBufPart, "mpi-p2p-part")

if __name__ == "__main__":
    unittest.main()