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) {
43 int stag = 0, rtag = 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_Datatype type = MPI_INT;
56 MPI_Comm_split(MPI_COMM_WORLD, 0, nprocs - rank, &newcom);
63 @{operation1}@ /* MBIERROR1 */
66 }else if (rank == 1) {
67 @{operation2}@ /* MBIERROR2 */
74 if(newcom != MPI_COMM_NULL && newcom != MPI_COMM_WORLD)
75 MPI_Comm_free(&newcom);
78 printf("Rank %d finished normally\\n", rank);
84 for p1 in gen.send + gen.isend + gen.psend:
85 for p2 in gen.recv + gen.irecv + gen.precv:
87 patterns = {'p1': p1, 'p2': p2}
88 patterns['origin'] = "MBI"
89 patterns['generatedby'] = f'DO NOT EDIT: this file was generated by {os.path.basename(sys.argv[0])}. DO NOT EDIT.'
90 patterns['p2pfeature'] = 'Yes' if p1 in gen.send or p2 in gen.recv else 'Lacking'
91 patterns['ip2pfeature'] = 'Yes' if p1 in gen.isend or p2 in gen.irecv else 'Lacking'
92 patterns['persfeature'] = 'Yes' if p1 in gen.psend or p2 in gen.precv else 'Lacking'
95 patterns['init1'] = gen.init[p1]("1")
96 patterns['init2'] = gen.init[p2]("2")
97 patterns['start1'] = gen.start[p1]("1")
98 patterns['start2'] = gen.start[p2]("2")
99 patterns['fini1'] = gen.fini[p1]("1")
100 patterns['fini2'] = gen.fini[p2]("2")
101 patterns['operation1'] = gen.operation[p1]("1") #send
102 patterns['operation2'] = gen.operation[p2]("2") #recv
103 patterns['free1'] = gen.free[p1]("1")
104 patterns['free2'] = gen.free[p2]("2")
105 patterns['change_srcdest'] = ""
106 patterns['change_com'] = ""
108 # Generate the incorrect matching
109 replace = patterns.copy()
110 replace['shortdesc'] = 'Point to point @{p1}@ and @{p2}@ have a communicator mismatch'
111 replace['longdesc'] = 'Process 1 uses newcom as the communicator while process 0 uses MPI_COMM_WORLD.'
112 replace['outcome'] = 'ERROR: CommunicatorMatching'
113 replace['errormsg'] = 'P2P Communicator mismatch. @{p1}@ at @{filename}@:@{line:MBIERROR1}@ and @{p2}@ at @{filename}@:@{line:MBIERROR2}@ have newcom or MPI_COMM_WORLD as a communicator.'
114 replace['change_com'] = 'if (rank==0)\n newcom = MPI_COMM_WORLD; /* MBIERROR */'
115 gen.make_file(template, f'ParamMatching_Com_{p1}_{p2}_nok.c', replace)
117 # Generate the code with an invalid communicator
118 replace = patterns.copy()
119 replace['shortdesc'] = 'Point to point @{p1}@ and @{p2}@ have an invalid communicator'
120 replace['longdesc'] = 'Point to point @{p1}@ and @{p2}@ have an invalid communicator.'
121 replace['outcome'] = 'ERROR: InvalidCommunicator'
122 replace['errormsg'] = 'Invalid Communicator. @{p1}@ at @{filename}@:@{line:MBIERROR1}@ and @{p2}@ at @{filename}@:@{line:MBIERROR2}@ use a communicator that is freed line @{line:MBIERROR}@.'
123 replace['change_com'] = 'MPI_Comm_free(&newcom); /* MBIERROR */'
124 gen.make_file(template, f'InvalidParam_Com_{p1}_{p2}_nok.c', replace)
126 # Generate the code with an invalid communicator ==> TO CHECK
127 #replace = patterns.copy()
128 #replace['shortdesc'] = 'Point to point @{p1}@ and @{p2}@ have an invalid communicator'
129 # replace['longdesc'] = 'Point to point @{p1}@ and @{p2}@ have an invalid communicator.'
130 # replace['outcome'] = 'ERROR: InvalidCommunicator'
131 # replace['errormsg'] = 'Invalid Communicator. @{p1}@ at @{filename}@:@{line:MBIERROR1}@ and @{p2}@ at @{filename}@:@{line:MBIERROR2}@ use different communicators'
132 # replace['origin'] = "MPI-Corrbench"
133 # replace['change_com'] = ""
134 # gen.make_file(template, f'InvalidParam_Com_{p1}_{p2}_nok.c', replace)
136 # Generate the code with an invalid dest
137 replace = patterns.copy()
138 replace['origin'] = "MBI"
139 replace['shortdesc'] = 'Point to point @{p1}@ has an invalid argument'
140 replace['longdesc'] = 'Point to point @{p1}@ and @{p2}@ have an invalid communicator.'
141 replace['outcome'] = 'ERROR: InvalidSrcDest'
142 replace['errormsg'] = 'InvalidSrcDest. @{p1}@ at @{filename}@:@{line:MBIERROR1}@ performs a send with a dest not in communicator (dest is changed line @{line:MBIERROR}@).'
143 replace['change_com'] = ""
144 replace['change_srcdest'] = 'dest=4; /* MBIERROR */'
145 gen.make_file(template, f'InvalidParam_Dest_{p1}_{p2}_nok.c', replace)
147 # Generate the code with an invalid src
148 replace = patterns.copy()
149 replace['shortdesc'] = 'Point to point @{p2}@ has an invalid argument'
150 replace['longdesc'] = 'Point to point @{p1}@ and @{p2}@ have an invalid communicator.'
151 replace['outcome'] = 'ERROR: InvalidSrcDest'
152 replace['errormsg'] = 'InvalidSrcDest. @{p2}@ at @{filename}@:@{line:MBIERROR2}@ performs a recv with a negative integer as source (src is changed line @{line:MBIERROR}@).'
153 replace['change_srcdest'] = 'src=-1; /* MBIERROR */'
154 gen.make_file(template, f'InvalidParam_Src_{p1}_{p2}_nok.c', replace)