Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
teshsuite: smpi: MBI: Merge change form MBI.
[simgrid.git] / teshsuite / smpi / MBI / InputHazardGenerator.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: @{collfeature}@
21   COLL!nonblocking: @{icollfeature}@
22   COLL!persistent: Lacking
23   COLL!tools: Lacking
24   RMA: Lacking
25 END_MPI_FEATURES
26
27 BEGIN_MBI_TESTS
28   $ mpirun -np 2 ${EXE} 1
29   | @{outcome}@
30   | @{errormsg}@
31   $ mpirun -np 2 ${EXE} 2
32   | @{outcome}@
33   | @{errormsg}@
34 END_MBI_TESTS
35 //////////////////////       End of MBI headers        /////////////////// */
36
37 #include <mpi.h>
38 #include <stdio.h>
39 #include <stdlib.h>
40
41 #define N 10
42
43 int main(int argc, char **argv) {
44   int nprocs = -1;
45   int rank = -1;
46   MPI_Status sta;
47   int src,dest;
48   int i=0;
49   int root = 0;
50   int stag=0, rtag=0;
51   int buff_size = N;
52
53   MPI_Init(&argc, &argv);
54   MPI_Comm_size(MPI_COMM_WORLD, &nprocs);
55   MPI_Comm_rank(MPI_COMM_WORLD, &rank);
56   printf("Hello from rank %d \\n", rank);
57
58   if (nprocs < 2)
59     printf("MBI ERROR: This test needs at least 2 processes to produce a bug!\\n");
60
61   if (argc < 2)
62     printf("MBI ERROR: This test needs at least 1 argument to produce a bug!\\n");
63
64   int dbs = sizeof(int)*nprocs; /* Size of the dynamic buffers for alltoall and friends */
65   MPI_Comm newcom = MPI_COMM_WORLD;
66   MPI_Datatype type = MPI_INT;
67   MPI_Op op = MPI_SUM;
68
69   int n = atoi(argv[1]);
70   int buffer[N] = {42};
71
72   @{init1}@
73   @{init2}@
74
75   if (rank == 0) {
76     dest=1, src=1;
77     if ((n % 2) == 0) { @{errorcond}@
78       @{operation1b}@
79       @{fini1b}@
80     } else {
81       @{operation1a}@
82       @{fini1a}@
83     }
84   } else @{addcond}@ {
85     dest=0, src=0;
86     @{operation2}@
87     @{fini2}@
88   }
89
90   @{free1}@
91   @{free2}@
92
93   MPI_Finalize();
94
95   printf("Rank %d finished normally\\n", rank);
96   return 0;
97 }
98 """
99
100 # P2P
101 for s in gen.send + gen.isend:
102     for r in gen.recv + gen.irecv:
103         patterns = {}
104         patterns = {'s': s, 'r': r}
105         patterns['generatedby'] = f'DO NOT EDIT: this file was generated by {os.path.basename(sys.argv[0])}. DO NOT EDIT.'
106         patterns['p2pfeature'] = 'Yes' if s in gen.send or r in gen.recv else 'Lacking'
107         patterns['ip2pfeature'] = 'Yes' if s in gen.isend or r in gen.irecv else 'Lacking'
108         patterns['collfeature'] = 'Lacking'
109         patterns['icollfeature'] = 'Lacking'
110         patterns['s'] = s
111         patterns['r'] = r
112
113         patterns['init1'] = gen.init[s]("1")
114         patterns['operation1a'] = gen.operation[s]("1").replace("buf1", "buffer")
115         patterns['operation1b'] = gen.operation[s]("1").replace("buf1", "buffer")
116         patterns['fini1a'] = gen.fini[s]("1")
117         patterns['fini1b'] = gen.fini[s]("1")
118         patterns['free1'] = gen.free[s]("1")
119
120         patterns['init2'] = gen.init[r]("2")
121         patterns['operation2'] = gen.operation[r]("2").replace("buf2", "buffer")
122         patterns['fini2'] = gen.fini[r]("2")
123         patterns['free2'] = gen.free[r]("2")
124
125         patterns['errorcond'] = ''
126         patterns['addcond'] = 'if (rank == 1)'
127
128         # Generate a correct matching
129         replace = patterns.copy()
130         replace['shortdesc'] = 'Correct call ordering.'
131         replace['longdesc'] = 'Correct call ordering.'
132         replace['outcome'] = 'OK'
133         replace['errormsg'] = 'OK'
134         gen.make_file(template, f'InputHazardCallOrdering_{r}_{s}_ok.c', replace)
135
136         # Generate the incorrect matching
137         replace = patterns.copy()
138         replace['shortdesc'] = 'Missing Send function.'
139         replace['longdesc'] = 'Missing Send function call for a path depending to input, a deadlock is created.'
140         replace['outcome'] = 'ERROR: IHCallMatching'
141         replace['errormsg'] = 'P2P mistmatch. Missing @{r}@ at @{filename}@:@{line:MBIERROR}@.'
142         replace['errorcond'] = '/* MBIERROR */'
143         replace['operation1b'] = ''
144         replace['fini1b'] = ''
145         gen.make_file(template, f'InputHazardCallOrdering_{r}_{s}_nok.c', replace)
146
147 # COLLECTIVE
148 for c in gen.coll:
149     patterns = {}
150     patterns = {'c': c}
151     patterns['generatedby'] = f'DO NOT EDIT: this file was generated by {os.path.basename(sys.argv[0])}. DO NOT EDIT.'
152     patterns['p2pfeature'] = 'Lacking'
153     patterns['ip2pfeature'] = 'Lacking'
154     patterns['collfeature'] = 'Yes' if c in gen.coll else 'Lacking'
155     patterns['icollfeature'] = 'Yes' if c in gen.icoll else 'Lacking'
156     patterns['c'] = c
157
158     patterns['init1'] = gen.init[c]("1")
159     patterns['operation1a'] = gen.operation[c]("1")
160     patterns['operation1b'] = gen.operation[c]("1")
161     patterns['fini1a'] = gen.fini[c]("1")
162     patterns['fini1b'] = gen.fini[c]("1")
163     patterns['free1'] = gen.free[c]("1")
164
165     patterns['init2'] = gen.init[c]("2")
166     patterns['operation2'] = gen.operation[c]("2")
167     patterns['fini2'] = gen.fini[c]("2")
168     patterns['free2'] = gen.free[c]("2")
169
170     patterns['errorcond'] = ''
171     patterns['addcond'] = ''
172
173     # Generate a correct matching
174     replace = patterns.copy()
175     replace['shortdesc'] = 'Correct call ordering.'
176     replace['longdesc'] = 'Correct call ordering.'
177     replace['outcome'] = 'OK'
178     replace['errormsg'] = 'OK'
179     gen.make_file(template, f'InputHazardCallOrdering_{c}_ok.c', replace)
180
181     # Generate the incorrect matching
182     replace = patterns.copy()
183     replace['shortdesc'] = 'Missing collective function call.'
184     replace['longdesc'] = 'Missing collective function call for a path depending to input, a deadlock is created.'
185     replace['outcome'] = 'ERROR: IHCallMatching'
186     replace['errormsg'] = 'P2P mistmatch. Missing @{c}@ at @{filename}@:@{line:MBIERROR}@.'
187     replace['errorcond'] = '/* MBIERROR */'
188     replace['operation1b'] = ''
189     replace['fini1b'] = ''
190     gen.make_file(template, f'InputHazardCallOrdering_{c}_nok.c', replace)