4 import generator_utils as gen
6 template = """// @{generatedby}@
7 /* ///////////////////////// The MPI Bugs Initiative ////////////////////////
11 Description: @{shortdesc}@
14 Version of MPI: Conforms to MPI 1.1, does not require MPI 2 implementation
18 P2P!nonblocking: Lacking
19 P2P!persistent: Lacking
20 COLL!basic: @{collfeature}@
21 COLL!nonblocking: @{icollfeature}@
22 COLL!persistent: Lacking
23 COLL!tools: @{toolfeature}@
32 ////////////////////// End of MBI headers /////////////////// */
40 int main(int argc, char **argv) {
44 int size = 1, j=0, color=0;
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);
52 printf("MBI ERROR: This test needs at least 2 processes to produce a bug!\\n");
54 MPI_Comm newcom = MPI_COMM_WORLD;
56 MPI_Datatype type = MPI_INT;
58 int dbs = sizeof(int)*nprocs; /* Size of the dynamic buffers for alltoall and friends */
64 @{operation}@ /* MBIERROR2 */
69 printf("Rank %d finished normally\\n", rank);
74 #####################################################
75 # Generate code with color mismatch in MPI_Comm_split
76 #####################################################
78 for c in gen.tcoll4color:
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 gen.tcoll4color else 'Lacking'
86 patterns['init'] = gen.init[c]("1")
87 patterns['start'] = gen.start[c]("1")
88 patterns['operation'] = gen.operation[c]("1")
89 patterns['fini'] = gen.fini[c]("1")
90 patterns['free'] = gen.free[c]("1")
91 patterns['change_arg'] = ''
93 # Generate the code with invalid color
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 gen.make_file(template, f'InvalidParam_OtherArg_{c}_nok.c', replace)
103 ##################################
104 # Generate code with root mismatch
105 ##################################
107 for c in gen.coll4root + gen.icoll4root:
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 gen.coll4root else 'Lacking'
112 patterns['icollfeature'] = 'Yes' if c in gen.icoll4root else 'Lacking'
113 patterns['toolfeature'] = 'Lacking'
115 patterns['init'] = gen.init[c]("1")
116 patterns['start'] = gen.start[c]("1")
117 patterns['fini'] = gen.fini[c]("1")
118 patterns['free'] = gen.free[c]("1")
119 patterns['operation'] = gen.operation[c]("1")
120 patterns['change_arg'] = ''
122 # Generate an incorrect root matching (root mismatch)
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 gen.make_file(template, f'ParamMatching_Root_{c}_nok.c', replace)
131 # Generate the call with root=-1 (invalid root)
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 gen.make_file(template, f'InvalidParam_RootNeg_{c}_nok.c', replace)
140 # Generate the call with root=2 (root not in communicator)
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 gen.make_file(template, f'InvalidParam_RootTooLarge_{c}_nok.c', replace)
150 ##################################
151 # Generate code with type mismatch
152 ##################################
154 for c in gen.coll + gen.icoll:
155 if c != 'MPI_Barrier': # Barrier has no Data to mismatch or to nullify
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 gen.coll else 'Lacking'
160 patterns['icollfeature'] = 'Yes' if c in gen.icoll + gen.ibarrier else 'Lacking'
161 patterns['toolfeature'] = 'Lacking'
163 patterns['init'] = gen.init[c]("1")
164 patterns['start'] = gen.start[c]("1")
165 patterns['fini'] = gen.fini[c]("1")
166 patterns['operation'] = gen.operation[c]("1")
167 patterns['free'] = gen.free[c]("1")
168 patterns['change_arg'] = ''
170 # Generate the incorrect matching (datatype Mmismatch)
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 gen.make_file(template, f'ParamMatching_Data_{c}_nok.c', replace)
179 # Generate the call with null type (invalid datatype)
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 gen.make_file(template, f'InvalidParam_DataNull_{c}_nok.c', replace)
189 ##################################
190 # Generate code with Op mismatch
191 ##################################
193 for c in gen.coll4op + gen.icoll4op:
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 gen.coll4op else 'Lacking'
198 patterns['icollfeature'] = 'Yes' if c in gen.icoll4op else 'Lacking'
199 patterns['toolfeature'] = 'Lacking'
201 patterns['init'] = gen.init[c]("1")
202 patterns['start'] = gen.start[c]("1")
203 patterns['fini'] = gen.fini[c]("1")
204 patterns['operation'] = gen.operation[c]("1")
205 patterns['free'] = gen.free[c]("1")
206 patterns['change_arg'] = ''
208 # Generate the incorrect matching (op mismatch)
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 gen.make_file(template, f'ParamMatching_Op_{c}_nok.c', replace)
217 # Generate the call with Op=MPI_OP_NULL (invalid op)
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 gen.make_file(template, f'InvalidParam_OpNull_{c}_nok.c', replace)