Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
MBI: Fix P2PBuffering tests
[simgrid.git] / teshsuite / smpi / MBI / P2PBufferingGenerator.py
1 #! /usr/bin/python3
2
3 import os
4 import sys
5 import generator_utils as gen
6
7 template = """// @{generatedby}@
8 /* ///////////////////////// The MPI Bugs Initiative ////////////////////////
9
10   Origin: @{origin}@
11
12   Description: @{shortdesc}@
13     @{longdesc}@
14
15 BEGIN_MPI_FEATURES
16   P2P!basic: @{p2pfeature}@
17   P2P!nonblocking: @{ip2pfeature}@
18   P2P!persistent: Lacking
19   COLL!basic: Lacking
20   COLL!nonblocking: Lacking
21   COLL!persistent: Lacking
22   COLL!tools: Lacking
23   RMA: Lacking
24 END_MPI_FEATURES
25
26 BEGIN_MBI_TESTS
27   $ mpirun -np 4 $zero_buffer ${EXE}
28   | @{outcome_zerob}@
29   | @{errormsg_zerob}@
30   $ mpirun -np 4 $infty_buffer ${EXE}
31   | @{outcome_infty}@
32   | @{errormsg_infty}@
33 END_MBI_TESTS
34 //////////////////////       End of MBI headers        /////////////////// */
35
36 #include <mpi.h>
37 #include <stdio.h>
38 #include <stdlib.h>
39
40
41 int main(int argc, char **argv) {
42   int nprocs = -1;
43   int rank = -1;
44   int dest, src;
45   int stag = 0, rtag = 0;
46   int buff_size = 1;
47
48   MPI_Init(&argc, &argv);
49   MPI_Comm_size(MPI_COMM_WORLD, &nprocs);
50   MPI_Comm_rank(MPI_COMM_WORLD, &rank);
51   printf("Hello from rank %d \\n", rank);
52
53   if (nprocs < 4)
54     printf("MBI ERROR: This test needs at least 4 processes to produce a bug!\\n");
55
56   MPI_Comm newcom = MPI_COMM_WORLD;
57   MPI_Datatype type = MPI_INT;
58
59   @{init1}@
60   @{init2}@
61   if (rank == 0) {
62     src=@{src1}@,dest=@{dest1}@;
63     @{operation1a}@ /* MBIERROR1 */
64     @{fini1a}@
65     @{operation2a}@
66     @{fini2a}@
67   }else if (rank == 1) {
68     src=@{src2}@,dest=@{dest2}@;
69     @{operation1b}@ /* MBIERROR2 */
70     @{fini1b}@
71     @{operation2b}@
72     @{fini2b}@
73   }else{
74     src=@{src3}@,dest=@{dest3}@;
75     @{operation1c}@
76     @{fini1c}@
77     @{operation2c}@
78     @{fini2c}@
79   }
80   @{free1}@
81   @{free2}@
82
83   MPI_Finalize();
84   printf("Rank %d finished normally\\n", rank);
85   return 0;
86 }
87 """
88
89 for s in gen.send + gen.isend:
90     for r in gen.recv + gen.irecv:
91         patterns = {}
92         patterns = {'s': s, 'r': r}
93         patterns['origin'] = 'MBI'
94         patterns['generatedby'] = f'DO NOT EDIT: this file was generated by {os.path.basename(sys.argv[0])}. DO NOT EDIT.'
95         patterns['p2pfeature'] = 'Yes' if s in gen.send or r in gen.recv  else 'Lacking'
96         patterns['ip2pfeature'] = 'Yes' if s in gen.isend or r in gen.irecv  else 'Lacking'
97         patterns['s'] = s
98         patterns['r'] = r
99         patterns['src1'] = '1'
100         patterns['dest1'] = '1'
101         patterns['src2'] = '0'
102         patterns['dest2'] = '0'
103         patterns['src3'] = '0'
104         patterns['dest3'] = '0'
105         patterns['init1'] = gen.init[s]("1")
106         patterns['init2'] = gen.init[r]("2")
107         patterns['fini1a'] = gen.fini[s]("1")
108         patterns['fini1b'] = gen.fini[s]("1")
109         patterns['fini1c'] = ''
110         patterns['fini2a'] = gen.fini[r]("2")
111         patterns['fini2b'] = gen.fini[r]("2")
112         patterns['fini2c'] = ''
113         patterns['free1'] = gen.free[s]("1")
114         patterns['free2'] = gen.free[r]("2")
115         patterns['operation1a'] = gen.operation[s]("1")
116         patterns['operation2a'] = gen.operation[r]("2")
117         patterns['operation1b'] = gen.operation[s]("1")
118         patterns['operation2b'] = gen.operation[r]("2")
119         patterns['operation1c'] = ''
120         patterns['operation2c'] = ''
121
122         # Generate the incorrect matching depending on the buffering mode (send + recv)
123         replace = patterns.copy()
124         replace['shortdesc'] = 'Point to point @{s}@ and @{r}@ may not be matched'
125         replace['longdesc'] = 'Processes 0 and 1 both call @{s}@ and @{r}@. This results in a deadlock depending on the buffering mode'
126         replace['outcome_zerob'] = 'ERROR: BufferingHazard'
127         replace['errormsg_zerob'] = f'Buffering Hazard. Possible deadlock depending the buffer size of MPI implementation and system environment cause by two processes call {s} before {r}.'
128         replace['outcome_infty'] = 'OK'
129         replace['errormsg_infty'] = 'OK'
130         gen.make_file(template, f'P2PBuffering_{s}_{r}_{s}_{r}_nok.c', replace)
131
132         # Generate the incorrect matching with send message to the same process depending on the buffering mode (send + recv)
133         replace = patterns.copy().copy()
134         replace['origin'] = 'RTED'
135         replace['src1'] = '0'
136         replace['dest1'] = '0'
137         replace['src2'] = '1'
138         replace['dest2'] = '1'
139         replace['shortdesc'] = 'Point to point @{s}@ and @{r}@ may not be matched'
140         replace['longdesc'] = 'Processes 0 and 1 both call @{s}@ and @{r}@. This results in a deadlock depending on the buffering mode'
141         replace['outcome_zerob'] = 'ERROR: BufferingHazard'
142         replace['errormsg_zerob'] = f'Buffering Hazard. Possible deadlock depending the buffer size of MPI implementation and system environment cause Send message to the same process.'
143         replace['outcome_infty'] = 'OK'
144         replace['errormsg_infty'] = 'OK'
145         gen.make_file(template, f'P2PBuffering_SameProcess_{s}_{r}_nok.c', replace)
146
147         # Generate the incorrect matching with circular send message depending on the buffering mode (send + recv)
148         replace = patterns.copy().copy()
149         replace['origin'] = 'RTED'
150         replace['src1'] = '(nprocs - 1)'
151         replace['dest1'] = '1'
152         replace['src2'] = '0'
153         replace['dest2'] = '2'
154         replace['src3'] = '(rank - 1)'
155         replace['dest3'] = '((rank + 1) % nprocs)'
156         replace['fini1c'] = gen.fini[s]("1")
157         replace['fini2c'] = gen.fini[r]("2")
158         replace['operation1c'] = gen.operation[s]("1") + ' /* MBIERROR3 */'
159         replace['operation2c'] = gen.operation[r]("2")
160         replace['shortdesc'] = 'Point to point @{s}@ and @{r}@ may not be matched'
161         replace['longdesc'] = 'Processes 0 and 1 both call @{s}@ and @{r}@. This results in a deadlock depending on the buffering mode'
162         replace['outcome_zerob'] = 'ERROR: BufferingHazard'
163         replace['errormsg_zerob'] = f'Buffering Hazard. Possible deadlock depending the buffer size of MPI implementation and system environment cause circular send message.'
164         replace['outcome_infty'] = 'OK'
165         replace['errormsg_infty'] = 'OK'
166         gen.make_file(template, f'P2PBuffering_Circular_{s}_{r}_nok.c', replace)
167
168         # Generate the incorrect matching depending on the buffering mode (recv + send)
169         replace = patterns.copy()
170         replace['shortdesc'] = 'Point to point @{s}@ and @{r}@ are not matched'
171         replace['longdesc'] = 'Processes 0 and 1 both call @{r}@ and @{s}@. This results in a deadlock'
172         replace['outcome_zerob'] = 'ERROR: CallMatching'
173         replace['errormsg_zerob'] = 'ERROR: CallMatching'
174         replace['outcome_infty'] = 'ERROR: CallMatching'
175         replace['errormsg_infty'] = 'ERROR: CallMatching'
176         replace['operation1a'] = gen.operation[r]("2")
177         replace['fini1a'] = gen.fini[r]("2")
178         replace['operation2a'] = gen.operation[s]("1")
179         replace['fini2a'] = gen.fini[s]("1")
180         replace['operation1b'] = gen.operation[r]("2")
181         replace['fini1b'] = gen.fini[r]("2")
182         replace['operation2b'] = gen.operation[s]("1")
183         replace['fini2b'] = gen.fini[s]("1")
184         gen.make_file(template, f'P2PCallMatching_{r}_{s}_{r}_{s}_nok.c', replace)
185
186         # Generate the correct matching
187         replace = patterns.copy()
188         replace['shortdesc'] = 'Point to point @{s}@ and @{r}@ are correctly  matched'
189         replace['longdesc'] = 'Process 0 calls @{s}@ and process 1 calls @{r}@.'
190         replace['outcome_zerob'] = 'OK'
191         replace['errormsg_zerob'] = 'OK'
192         replace['outcome_infty'] = 'OK'
193         replace['errormsg_infty'] = 'OK'
194         patterns['init1'] = gen.init[s]("1")
195         replace['operation1a'] = gen.operation[s]("1")
196         replace['fini1a'] = gen.fini[s]("1")
197         replace['operation2a'] = ''
198         replace['fini2a'] = ''
199         
200         patterns['init2'] = gen.init[r]("2")
201         replace['operation1b'] = gen.operation[r]("2")
202         replace['fini1b'] = gen.fini[r]("2")
203         replace['operation2b'] = ''
204         replace['fini2b'] = ''
205         gen.make_file(template, f'P2PCallMatching_{s}_{r}_{r}_{s}_ok.c', replace)