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
17 P2P!basic: @{p2pfeature}@
18 P2P!nonblocking: @{ip2pfeature}@
19 P2P!persistent: @{persfeature}@
21 COLL!nonblocking: Lacking
22 COLL!persistent: Lacking
32 ////////////////////// End of MBI headers /////////////////// */
39 int main(int argc, char **argv) {
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;
55 MPI_Datatype type = MPI_INT;
62 @{operation1}@ /* MBIERROR1 */
65 }else if (rank == 1) {
66 @{operation2}@ /* MBIERROR2 */
74 printf("Rank %d finished normally\\n", rank);
79 ##################################
80 # Generate code with type mismatch
81 ##################################
83 for p1 in gen.allsend:
84 for p2 in gen.allrecv:
86 patterns = {'p1': p1, 'p2': p2}
87 patterns['generatedby'] = f'DO NOT EDIT: this file was generated by {os.path.basename(sys.argv[0])}. DO NOT EDIT.'
88 patterns['p2pfeature'] = 'Yes' if p1 in gen.send + gen.ssend + gen.bsend or p2 in gen.recv else 'Lacking'
89 patterns['ip2pfeature'] = 'Yes' if p1 in gen.isend or p2 in gen.irecv else 'Lacking'
90 patterns['persfeature'] = 'Yes' if p1 in gen.psend or p2 in gen.precv else 'Lacking'
93 patterns['init1'] = gen.init[p1]("1")
94 patterns['init2'] = gen.init[p2]("2")
95 patterns['start1'] = gen.start[p1]("1")
96 patterns['start2'] = gen.start[p2]("2")
97 patterns['fini1'] = gen.fini[p1]("1")
98 patterns['fini2'] = gen.fini[p2]("2")
99 patterns['operation1'] = gen.operation[p1]("1") #send
100 patterns['operation2'] = gen.operation[p2]("2") #recv
101 patterns['free1'] = gen.free[p1]("1")
102 patterns['free2'] = gen.free[p2]("2")
104 # Generate the incorrect matching
105 replace = patterns.copy()
106 replace['shortdesc'] = 'Point to point @{p1}@ and @{p2}@ have a datatype mismatch'
107 replace['longdesc'] = 'Process 0 uses MPI_FLOAT as the datatype while process 1 uses MPI_INT.'
108 replace['outcome'] = 'ERROR: DatatypeMatching'
109 replace['errormsg'] = 'P2P Datatype mismatch. @{p1}@ at @{filename}@:@{line:MBIERROR1}@ and @{p2}@ at @{filename}@:@{line:MBIERROR2}@ have MPI_INT and MPI_FLOAT as a datatype'
110 replace['change_arg'] = 'if (rank == 0)\n type = MPI_FLOAT; /* MBIERROR3 */'
111 gen.make_file(template, f'ParamMatching_Data_{p1}_{p2}_nok.c', replace)
113 # Generate code with a null type
114 replace = patterns.copy()
115 replace['shortdesc'] = 'Use of invalid datatype in point-to-point communication'
116 replace['longdesc'] = 'Point to point @{p1}@ and @{p2}@ have MPI_DATATYPE_NULL as a type'
117 replace['outcome'] = 'ERROR: InvalidDatatype'
118 replace['errormsg'] = 'Invalid datatype in P2P. @{p1}@ at @{filename}@:@{line:MBIERROR1}@ and @{p2}@ at @{filename}@:@{line:MBIERROR2}@ have MPI_DATATYPE_NULL as a type'
119 replace['change_arg'] = 'type = MPI_DATATYPE_NULL; /* MBIERROR3 */'
120 gen.make_file(template, f'InvalidParam_DatatypeNull_{p1}_{p2}_nok.c', replace)
122 # Generate code with an invalid datatype
123 replace = patterns.copy()
124 replace['shortdesc'] = 'Use of invalid datatype in point-to-point communication'
125 replace['longdesc'] = 'Point to point @{p1}@ and @{p2}@ have an invalid datatype'
126 replace['outcome'] = 'ERROR: InvalidDatatype'
127 replace['errormsg'] = 'Invalid datatype in P2P. @{p1}@ at @{filename}@:@{line:MBIERROR1}@ and @{p2}@ at @{filename}@:@{line:MBIERROR2}@ have an invalid datatype'
128 replace['change_arg'] = 'MPI_Type_contiguous (2, MPI_INT, &type); MPI_Type_commit(&type);MPI_Type_free(&type); /* MBIERROR3 */'
129 gen.make_file(template, f'InvalidParam_Datatype_{p1}_{p2}_nok.c', replace)
131 #################################
132 # Generate code with tag mismatch
133 #################################
135 for p1 in gen.allsend:
136 for p2 in gen.allrecv:
138 patterns = {'p1': p1, 'p2': p2}
139 patterns['generatedby'] = f'DO NOT EDIT: this file was generated by {os.path.basename(sys.argv[0])}. DO NOT EDIT.'
140 patterns['p2pfeature'] = 'Yes' if p1 in gen.send + gen.ssend + gen.bsend or p2 in gen.recv else 'Lacking'
141 patterns['ip2pfeature'] = 'Yes' if p1 in gen.isend or p2 in gen.irecv else 'Lacking'
142 patterns['persfeature'] = 'Yes' if p1 in gen.psend or p2 in gen.precv else 'Lacking'
145 patterns['init1'] = gen.init[p1]("1")
146 patterns['init2'] = gen.init[p2]("2")
147 patterns['start1'] = gen.start[p1]("1")
148 patterns['start2'] = gen.start[p2]("2")
149 patterns['fini1'] = gen.fini[p1]("1")
150 patterns['fini2'] = gen.fini[p2]("2")
151 patterns['operation1'] = gen.operation[p1]("1") #send
152 patterns['operation2'] = gen.operation[p2]("2") #recv
153 patterns['free1'] = gen.free[p1]("1")
154 patterns['free2'] = gen.free[p2]("2")
155 patterns['change_arg'] = ""
157 # Generate the incorrect tag matching
158 replace = patterns.copy()
159 replace['shortdesc'] = 'Point to point @{p1}@ and @{p2}@ have a tag mismatch'
160 replace['longdesc'] = 'Point to point @{p1}@ and @{p2}@ have a tag mismatch.'
161 replace['outcome'] = 'ERROR: TagMatching'
162 replace['errormsg'] = 'P2P tag mismatch. @{p1}@ at @{filename}@:@{line:MBIERROR1}@ and @{p2}@ at @{filename}@:@{line:MBIERROR2}@ use different tag.'
163 replace['change_arg'] = 'stag=0; rtag=1;/* MBIERROR */'
164 gen.make_file(template, f'ParamMatching_Tag_{p1}_{p2}_nok.c', replace)
166 # Generate the code with an invalid tag
167 replace = patterns.copy()
168 replace['shortdesc'] = 'Point to point @{p1}@ and @{p2}@ have an invalid tag'
169 replace['longdesc'] = 'Point to point @{p1}@ and @{p2}@ have an invalid tag.'
170 replace['outcome'] = 'ERROR: InvalidTag'
171 replace['errormsg'] = 'Invalid Tag. @{p1}@ at @{filename}@:@{line:MBIERROR1}@ and @{p2}@ at @{filename}@:@{line:MBIERROR2}@ use an invalid tag.'
172 replace['change_arg'] = 'stag=-1; rtag=-2;/* MBIERROR */'
173 gen.make_file(template, f'InvalidParam_Tag_{p1}_{p2}_nok.c', replace)
175 # Generate a correct code using MPI_ANY_TAG
176 replace = patterns.copy()
177 replace['shortdesc'] = 'Correct code'
178 replace['longdesc'] = 'Correct code'
179 replace['outcome'] = 'OK'
180 replace['errormsg'] = 'OK'
181 replace['change_arg'] = 'rtag=MPI_ANY_TAG;'
182 gen.make_file(template, f'ParamMatching_Tag_{p1}_{p2}_ok.c', replace)