Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
teshsuite: smpi: MBI: Merge change form MBI.
[simgrid.git] / teshsuite / smpi / MBI / P2PMessageRaceGenerator.py
1 #! /usr/bin/python3
2 import os
3 import sys
4 import generator_utils as gen
5
6 template = """// @{generatedby}@
7 /* ///////////////////////// The MPI Bugs Initiative ////////////////////////
8
9   Origin: MBI
10
11   Description: @{shortdesc}@
12     @{longdesc}@
13
14   Version of MPI: Conforms to MPI 1.1, does not require MPI 2 implementation
15
16 BEGIN_MPI_FEATURES
17   P2P!basic: @{p2pfeature}@
18   P2P!nonblocking: @{ip2pfeature}@
19   P2P!persistent: Lacking
20   COLL!basic: Lacking
21   COLL!nonblocking: Lacking
22   COLL!persistent: Lacking
23   COLL!tools: Lacking
24   RMA: Lacking
25 END_MPI_FEATURES
26
27 BEGIN_MBI_TESTS
28   $ mpirun -np 4 ${EXE}
29   | @{outcome}@
30   | @{errormsg}@
31 END_MBI_TESTS
32 //////////////////////       End of MBI headers        /////////////////// */
33
34 #include <mpi.h>
35 #include <stdio.h>
36 #include <stdlib.h>
37
38 #define N 2
39
40 int main(int argc, char **argv) {
41   int nprocs = -1;
42   int rank = -1;
43   int dest, src;
44   int i=0;
45   int root = 0;
46   int stag = 0, rtag = 0;
47   int buff_size = 1;
48
49   MPI_Init(&argc, &argv);
50   MPI_Comm_size(MPI_COMM_WORLD, &nprocs);
51   MPI_Comm_rank(MPI_COMM_WORLD, &rank);
52   printf("Hello from rank %d \\n", rank);
53
54   if (nprocs != 4)
55     printf("MBI ERROR: This test needs 4 processes to produce a bug!\\n");
56
57   int dbs = sizeof(int)*nprocs; /* Size of the dynamic buffers for alltoall and friends */
58   MPI_Comm newcom = MPI_COMM_WORLD;
59   MPI_Datatype type = MPI_INT;
60   MPI_Op op = MPI_SUM;
61
62   @{init0a}@
63   @{init0b}@
64   @{init0c}@
65   @{init1a}@
66   @{init1b}@
67   @{init3a}@
68   @{init3b}@
69   @{init3c}@
70   @{init3d}@
71
72   if (rank == 0) {
73     src = MPI_ANY_SOURCE; rtag = @{tag}@;
74     for (int i = 0; i < 2 * N; i++) {
75       @{operation0a}@ /* MBIERROR1 */
76       @{fini0a}@
77     }
78     src = 3; rtag = 0;
79     @{operation0b}@ /* MBIERROR2 */
80     @{fini0b}@
81     @{operation0c}@
82     @{fini0c}@
83   } else if (rank == 1 || rank == 2) {
84     dest = 0; stag = @{tag}@;
85     for (int i = 0; i < N; i++) {
86       @{operation1a}@
87       @{fini1a}@
88     }
89     dest = 3; stag = 0;
90     @{operation1b}@
91     @{fini1b}@
92   } else if (rank == 3) {
93     dest = 0; src = 1; rtag= 0; stag = 0;
94     @{operation3a}@
95     @{fini3a}@
96     @{operation3b}@ /* MBIERROR3 */
97     @{fini3b}@
98     src = 2;
99     @{operation3c}@
100     @{fini3c}@
101     @{operation3d}@
102     @{fini3d}@
103   }
104
105   @{free0a}@
106   @{free0b}@
107   @{free0c}@
108   @{free1a}@
109   @{free1b}@
110   @{free3a}@
111   @{free3b}@
112   @{free3c}@
113   @{free3d}@
114
115   MPI_Finalize();
116   printf("Rank %d finished normally\\n", rank);
117   return 0;
118 }
119 """
120
121 basedesc = 'We have 4 processes (p0, p1, p2 and p3). p1 and p2 send N messages to p0 and send a last message to p3. Process p0 recv 2*N messages from p1 and p2 using MPI_ANY_SOURCE and wait messages from p3. p3 wait a message from p1 and send message to p0, before doing the same for p2.'
122
123 for s in gen.send + gen.isend:
124     for r in gen.recv + gen.irecv:
125         patterns = {}
126         patterns = {'s': s, 'r': r}
127         patterns['generatedby'] = f'DO NOT EDIT: this file was generated by {os.path.basename(sys.argv[0])}. DO NOT EDIT.'
128         patterns['p2pfeature'] = 'Yes' if s in gen.send or r in gen.recv else 'Lacking'
129         patterns['ip2pfeature'] = 'Yes' if s in gen.isend or r in gen.irecv else 'Lacking'
130         patterns['s'] = s
131         patterns['r'] = r
132
133         patterns['init0a'] = gen.init[r]("0a")
134         patterns['init0b'] = gen.init[r]("0b")
135         patterns['init0c'] = gen.init[r]("0c")
136         patterns['operation0a'] = gen.operation[r]("0a")
137         patterns['operation0b'] = gen.operation[r]("0b")
138         patterns['operation0c'] = gen.operation[r]("0c")
139         patterns['fini0a'] = gen.fini[r]("0a")
140         patterns['fini0b'] = gen.fini[r]("0b")
141         patterns['fini0c'] = gen.fini[r]("0c")
142         patterns['free0a'] = gen.free[r]("0a")
143         patterns['free0b'] = gen.free[r]("0b")
144         patterns['free0c'] = gen.free[r]("0c")
145
146         patterns['init1a'] = gen.init[s]("1a")
147         patterns['init1b'] = gen.init[s]("1b")
148         patterns['operation1a'] = gen.operation[s]("1a")
149         patterns['operation1b'] = gen.operation[s]("1b")
150         patterns['fini1a'] = gen.fini[s]("1a")
151         patterns['fini1b'] = gen.fini[s]("1b")
152         patterns['free1a'] = gen.free[s]("1a")
153         patterns['free1b'] = gen.free[s]("1b")
154
155         patterns['init3a'] = gen.init[r]("3a")
156         patterns['init3b'] = gen.init[s]("3b")
157         patterns['init3c'] = gen.init[r]("3c")
158         patterns['init3d'] = gen.init[s]("3d")
159         patterns['operation3a'] = gen.operation[r]("3a")
160         patterns['operation3b'] = gen.operation[s]("3b")
161         patterns['operation3c'] = gen.operation[r]("3c")
162         patterns['operation3d'] = gen.operation[s]("3d")
163         patterns['fini3a'] = gen.fini[r]("3a")
164         patterns['fini3b'] = gen.fini[s]("3b")
165         patterns['fini3c'] = gen.fini[r]("3c")
166         patterns['fini3d'] = gen.fini[s]("3d")
167         patterns['free3a'] = gen.free[r]("3a")
168         patterns['free3b'] = gen.free[s]("3b")
169         patterns['free3c'] = gen.free[r]("3c")
170         patterns['free3d'] = gen.free[s]("3d")
171
172         patterns['tag'] = '1'
173
174         # Generate the correct matching because of the conditional
175         replace = patterns.copy()
176         replace['shortdesc'] = 'Message race'
177         replace['longdesc'] = basedesc + ' In this file, different message tag are used to avoid involuntary message race.'
178         replace['outcome'] = 'OK'
179         replace['errormsg'] = 'OK'
180         gen.make_file(template, f'MessageRace_Loop_{s}_{r}_ok.c', replace)
181
182         # Generate the incorrect matching because of the conditional
183         replace = patterns.copy()
184         replace['shortdesc'] = 'Message race'
185         replace['longdesc'] = basedesc + ' If the loop of p1 ending before the loop of p2, p0 could recv a message from process p3 into recv loop destined to message from p1 and p2. In this case, the program deadlock cause by message race at recv at line @{line:MBIERROR2}@.'
186         replace['outcome'] = 'ERROR: MessageRace'
187         replace['errormsg'] = 'Message race. The use of wildcard receive calls @{r}@ at @{filename}@:@{line:MBIERROR1}@ from @{r}@ at @{filename}@:@{line:MBIERROR3}@ and @{r}@ without wildcard at @{filename}@:@{line:MBIERROR2}@) leads to nondeterministic matching.'
188         replace['tag'] = '0'
189         gen.make_file(template, f'MessageRace_Loop_{s}_{r}_nok.c', replace)