Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Merge branch 'issue105' into 'master'
[simgrid.git] / teshsuite / smpi / MBI / CollArgGenerator.py
1 #! /usr/bin/python3
2 import os
3 import sys
4 from generator_utils import *
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: Lacking
18   P2P!nonblocking: Lacking
19   P2P!persistent: Lacking
20   COLL!basic: @{collfeature}@
21   COLL!nonblocking: @{icollfeature}@
22   COLL!persistent: Lacking
23   COLL!tools: @{toolfeature}@
24   RMA: Lacking
25 END_MPI_FEATURES
26
27 BEGIN_MBI_TESTS
28   $ mpirun -np 2 ${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 buff_size 128
39
40 int main(int argc, char **argv) {
41   int nprocs = -1;
42   int rank = -1;
43   int root = 0;
44   int size = 1, j=0, color=0;
45
46   MPI_Init(&argc, &argv);
47   MPI_Comm_size(MPI_COMM_WORLD, &nprocs);
48   MPI_Comm_rank(MPI_COMM_WORLD, &rank);
49   printf("Hello from rank %d \\n", rank);
50
51   if (nprocs < 2)
52     printf("MBI ERROR: This test needs at least 2 processes to produce a bug!\\n");
53
54   MPI_Comm newcom = MPI_COMM_WORLD;
55   MPI_Op op = MPI_SUM;
56   MPI_Datatype type = MPI_INT;
57
58   int dbs = sizeof(int)*nprocs; /* Size of the dynamic buffers for alltoall and friends */
59
60   @{init}@
61   @{start}@
62
63   @{change_arg}@
64   @{operation}@ /* MBIERROR2 */
65   @{fini}@
66   @{free}@
67
68   MPI_Finalize();
69   printf("Rank %d finished normally\\n", rank);
70   return 0;
71 }
72 """
73
74 #####################################################
75 # Generate code with color mismatch in MPI_Comm_split
76 #####################################################
77
78 for c in tcoll4color:
79     patterns = {}
80     patterns = {'c': c}
81     patterns['generatedby'] = f'DO NOT EDIT: this file was generated by {os.path.basename(sys.argv[0])}. DO NOT EDIT.'
82     patterns['collfeature'] = 'Lacking'
83     patterns['icollfeature'] = 'Lacking'
84     patterns['toolfeature'] = 'Yes' if c in tcoll4color else 'Lacking'
85     patterns['c'] = c
86     patterns['init'] = init[c]("1")
87     patterns['start'] = start[c]("1")
88     patterns['operation'] = operation[c]("1")
89     patterns['fini'] = fini[c]("1")
90     patterns['free'] = free[c]("1")
91     patterns['change_arg'] = ''
92
93     # Generate the code with invalid color
94     replace = patterns
95     replace['shortdesc'] = 'Invalid color in @{c}@'
96     replace['longdesc'] = 'invalid color in @{c}@'
97     replace['outcome'] = 'ERROR: InvalidOtherArg'
98     replace['errormsg'] = 'Invalid Argument in collective. @{c}@ at line @{line:MBIERROR2}@ has an invalid color'
99     replace['change_arg'] = 'color=-10; /* MBIERROR1*/'
100     make_file(template, f'InvalidParam_OtherArg_{c}_nok.c', replace)
101
102
103 ##################################
104 # Generate code with root mismatch
105 ##################################
106
107 for c in coll4root + icoll4root:
108     patterns = {}
109     patterns = {'c': c}
110     patterns['generatedby'] = f'DO NOT EDIT: this file was generated by {os.path.basename(sys.argv[0])}. DO NOT EDIT.'
111     patterns['collfeature'] = 'Yes' if c in coll4root else 'Lacking'
112     patterns['icollfeature'] = 'Yes' if c in icoll4root else 'Lacking'
113     patterns['toolfeature'] = 'Lacking'
114     patterns['c'] = c
115     patterns['init'] = init[c]("1")
116     patterns['start'] = start[c]("1")
117     patterns['fini'] = fini[c]("1")
118     patterns['free'] = free[c]("1")
119     patterns['operation'] = operation[c]("1")
120     patterns['change_arg'] = ''
121
122     # Generate an incorrect root matching (root mismatch)
123     replace = patterns
124     replace['shortdesc'] = 'Collective @{c}@ with a root mismatch'
125     replace['longdesc'] = f'Odd ranks use 0 as a root while even ranks use 1 as a root'
126     replace['outcome'] = 'ERROR: RootMatching'
127     replace['errormsg'] = 'Collective root mistmatch. @{c}@ at @{filename}@:@{line:MBIERROR2}@ has 0 or 1 as a root.'
128     replace['change_arg'] = 'if (rank % 2)\n    root = 1; /* MBIERROR1 */'
129     make_file(template, f'ParamMatching_Root_{c}_nok.c', replace)
130
131     # Generate the call with root=-1 (invalid root)
132     replace = patterns
133     replace['shortdesc'] = f'Collective {c} with root = -1'
134     replace['longdesc'] = f'Collective {c} with root = -1'
135     replace['outcome'] = 'ERROR: InvalidRoot'
136     replace['errormsg'] = 'Invalid collective root.  @{c}@ at @{filename}@:@{line:MBIERROR2}@ has -1 as a root while communicator MPI_COMM_WORLD requires ranks in range 0 to 1.'
137     replace['change_arg'] = 'root = -1; /* MBIERROR1 */'
138     make_file(template, f'InvalidParam_RootNeg_{c}_nok.c', replace)
139
140     # Generate the call with root=2 (root not in communicator)
141     replace = patterns
142     replace['shortdesc'] = f'Collective {c} with root out of the communicator'
143     replace['longdesc'] = f'Collective {c} with root = 2 (there is only 2 ranks)'
144     replace['outcome'] = 'ERROR: InvalidRoot'
145     replace['errormsg'] = 'Invalid collective root.  @{c}@ at @{filename}@:@{line:MBIERROR2}@ has 2 as a root while communicator MPI_COMM_WORLD requires ranks in range 0 to 1.'
146     replace['change_arg'] = 'root = nprocs; /* MBIERROR1 */'
147     make_file(template, f'InvalidParam_RootTooLarge_{c}_nok.c', replace)
148
149
150 ##################################
151 # Generate code with type mismatch
152 ##################################
153
154 for c in coll + icoll:
155   if c != 'MPI_Barrier': # Barrier has no Data to mismatch or to nullify
156     patterns = {}
157     patterns = {'c': c}
158     patterns['generatedby'] = f'DO NOT EDIT: this file was generated by {os.path.basename(sys.argv[0])}. DO NOT EDIT.'
159     patterns['collfeature'] = 'Yes' if c in coll else 'Lacking'
160     patterns['icollfeature'] = 'Yes' if c in icoll + ibarrier else 'Lacking'
161     patterns['toolfeature'] = 'Lacking'
162     patterns['c'] = c
163     patterns['init'] = init[c]("1")
164     patterns['start'] = start[c]("1")
165     patterns['fini'] = fini[c]("1")
166     patterns['operation'] = operation[c]("1")
167     patterns['free'] = free[c]("1")
168     patterns['change_arg'] = ''
169
170     # Generate the incorrect matching (datatype Mmismatch)
171     replace = patterns
172     replace['shortdesc'] = 'Collective @{c}@ with a datatype mismatch'
173     replace['longdesc'] = f'Odd ranks use MPI_INT as the datatype while even ranks use MPI_FLOAT'
174     replace['outcome'] = 'ERROR: DatatypeMatching'
175     replace['errormsg'] = 'Collective datatype mistmatch. @{c}@ at @{filename}@:@{line:MBIERROR2}@ has MPI_INT or MPI_FLOAT as a datatype.'
176     replace['change_arg'] = 'if (rank % 2)\n    type = MPI_FLOAT; /* MBIERROR1 */'
177     make_file(template, f'ParamMatching_Data_{c}_nok.c', replace)
178
179     # Generate the call with null type (invalid datatype)
180     replace = patterns
181     replace['shortdesc'] = 'Collective @{c}@ with an invalid datatype '
182     replace['longdesc'] = 'Collective @{c}@ with an invalid datatype '
183     replace['outcome'] = 'ERROR: InvalidDatatype'
184     replace['errormsg'] = 'Invalid Datatype. @{c}@ at @{filename}@:@{line:MBIERROR2}@ has an invalid datatype.'
185     replace['change_arg'] = 'type=MPI_DATATYPE_NULL; /* MBIERROR1 */'
186     make_file(template, f'InvalidParam_DataNull_{c}_nok.c', replace)
187
188
189 ##################################
190 # Generate code with Op  mismatch
191 ##################################
192
193 for c in coll4op + icoll4op:
194     patterns = {}
195     patterns = {'c': c}
196     patterns['generatedby'] = f'DO NOT EDIT: this file was generated by {os.path.basename(sys.argv[0])}. DO NOT EDIT.'
197     patterns['collfeature'] = 'Yes' if c in  coll4op else 'Lacking'
198     patterns['icollfeature'] = 'Yes' if c in icoll4op else 'Lacking'
199     patterns['toolfeature'] = 'Lacking'
200     patterns['c'] = c
201     patterns['init'] = init[c]("1")
202     patterns['start'] = start[c]("1")
203     patterns['fini'] = fini[c]("1")
204     patterns['operation'] = operation[c]("1")
205     patterns['free'] = free[c]("1")
206     patterns['change_arg'] = ''
207
208     # Generate the incorrect matching (op mismatch)
209     replace = patterns
210     replace['shortdesc'] = 'Collective @{c}@ with an operator  mismatch'
211     replace['longdesc'] = f'Odd ranks use MPI_SUM as the operator while even ranks use MPI_MAX'
212     replace['outcome'] = 'ERROR: OperatorMatching'
213     replace['errormsg'] = 'Collective operator mistmatch. @{c}@ at @{filename}@:@{line:MBIERROR2}@ has MPI_MAX or MPI_SUM as an operator.'
214     replace['change_arg'] = 'if (rank % 2)\n    op = MPI_MAX; /* MBIERROR1 */'
215     make_file(template, f'ParamMatching_Op_{c}_nok.c', replace)
216
217     # Generate the call with Op=MPI_OP_NULL (invalid op)
218     replace = patterns
219     replace['shortdesc'] = 'Collective @{c}@ with an invalid operator '
220     replace['longdesc'] = 'Collective @{c}@ with an invalid operator '
221     replace['outcome'] = 'ERROR: InvalidOperator'
222     replace['errormsg'] = 'Invalid Operator. @{c}@ at @{filename}@:@{line:MBIERROR2}@ has MPI_OP_NULL as an operator.'
223     replace['change_arg'] = 'op = MPI_OP_NULL; /* MBIERROR1 */'
224     make_file(template, f'InvalidParam_OpNull_{c}_nok.c', replace)