Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
teshsuite: smpi: MBI: Merge change form MBI.
[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   | @{outcome1}@
29   | @{errormsg1}@
30   $ mpirun -np 4 $infty_buffer ${EXE}
31   | @{outcome1}@
32   | @{errormsg1}@
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['outcome1'] = 'ERROR: BufferingHazard'
127         replace['errormsg1'] = f'Buffering Hazard. Possible deadlock depending the buffer size of MPI implementation and system environment cause by two processes call {s} before {r}.'
128         gen.make_file(template, f'P2PBuffering_{s}_{r}_{s}_{r}_nok.c', replace)
129
130         # Generate the incorrect matching with send message to the same process depending on the buffering mode (send + recv)
131         replace = patterns.copy().copy()
132         replace['origin'] = 'RTED'
133         replace['src1'] = '0'
134         replace['dest1'] = '0'
135         replace['src2'] = '1'
136         replace['dest2'] = '1'
137         replace['shortdesc'] = 'Point to point @{s}@ and @{r}@ may not be matched'
138         replace['longdesc'] = 'Processes 0 and 1 both call @{s}@ and @{r}@. This results in a deadlock depending on the buffering mode'
139         replace['outcome1'] = 'ERROR: BufferingHazard'
140         replace['errormsg1'] = f'Buffering Hazard. Possible deadlock depending the buffer size of MPI implementation and system environment cause Send message to the same process.'
141         gen.make_file(template, f'P2PBuffering_SameProcess_{s}_{r}_nok.c', replace)
142
143         # Generate the incorrect matching with circular send message depending on the buffering mode (send + recv)
144         replace = patterns.copy().copy()
145         replace['origin'] = 'RTED'
146         replace['src1'] = '(nprocs - 1)'
147         replace['dest1'] = '1'
148         replace['src2'] = '0'
149         replace['dest2'] = '2'
150         replace['src3'] = '(rank - 1)'
151         replace['dest3'] = '((rank + 1) % nprocs)'
152         replace['fini1c'] = gen.fini[s]("1")
153         replace['fini2c'] = gen.fini[r]("2")
154         replace['operation1c'] = gen.operation[s]("1") + ' /* MBIERROR3 */'
155         replace['operation2c'] = gen.operation[r]("2")
156         replace['shortdesc'] = 'Point to point @{s}@ and @{r}@ may not be matched'
157         replace['longdesc'] = 'Processes 0 and 1 both call @{s}@ and @{r}@. This results in a deadlock depending on the buffering mode'
158         replace['outcome1'] = 'ERROR: BufferingHazard'
159         replace['errormsg1'] = f'Buffering Hazard. Possible deadlock depending the buffer size of MPI implementation and system environment cause circular send message.'
160         gen.make_file(template, f'P2PBuffering_Circular_{s}_{r}_nok.c', replace)
161
162         # Generate the incorrect matching depending on the buffering mode (recv + send)
163         replace = patterns.copy()
164         replace['shortdesc'] = 'Point to point @{s}@ and @{r}@ are not matched'
165         replace['longdesc'] = 'Processes 0 and 1 both call @{r}@ and @{s}@. This results in a deadlock'
166         replace['outcome1'] = 'ERROR: CallMatching'
167         replace['errormsg1'] = 'ERROR: CallMatching'
168         replace['operation1a'] = gen.operation[r]("2")
169         replace['fini1a'] = gen.fini[r]("2")
170         replace['operation2a'] = gen.operation[s]("1")
171         replace['fini2a'] = gen.fini[s]("1")
172         replace['operation1b'] = gen.operation[r]("2")
173         replace['fini1b'] = gen.fini[r]("2")
174         replace['operation2b'] = gen.operation[s]("1")
175         replace['fini2b'] = gen.fini[s]("1")
176         gen.make_file(template, f'P2PCallMatching_{r}_{s}_{r}_{s}_nok.c', replace)
177
178         # Generate the correct matching
179         replace = patterns.copy()
180         replace['shortdesc'] = 'Point to point @{s}@ and @{r}@ are correctly  matched'
181         replace['longdesc'] = 'Process 0 calls @{s}@ and process 1 calls @{r}@.'
182         replace['outcome1'] = 'OK'
183         replace['errormsg1'] = 'OK'
184         replace['fini1a'] = gen.fini[s]("1")
185         replace['fini2a'] = gen.fini[r]("2")
186         replace['operation1a'] = gen.operation[s]("1")
187         replace['operation2a'] = gen.operation[r]("2")
188         gen.make_file(template, f'P2PCallMatching_{s}_{r}_{r}_{s}_ok.c', replace)