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
21 COLL!nonblocking: Lacking
22 COLL!persistent: Lacking
23 COLL!tools: @{toolfeature}@
32 ////////////////////// End of MBI headers /////////////////// */
40 int main(int argc, char **argv) {
44 MPI_Init(&argc, &argv);
45 MPI_Comm_size(MPI_COMM_WORLD, &nprocs);
46 MPI_Comm_rank(MPI_COMM_WORLD, &rank);
47 printf("Hello from rank %d \\n", rank);
50 printf("MBI ERROR: This test needs at least 2 processes to produce a bug!\\n");
53 int dims[2], periods[2], coords[2];
62 MPI_Cart_create(MPI_COMM_WORLD, 2, dims, periods, 0, &newcom); /* create a cartesian communicator */
67 @{operation}@ /* MBIERROR2 */
70 if (newcom != MPI_COMM_NULL)
71 MPI_Comm_free(&newcom);
74 printf("Rank %d finished normally\\n", rank);
79 for c in gen.tcoll4topo:
82 patterns['generatedby'] = f'DO NOT EDIT: this file was generated by {os.path.basename(sys.argv[0])}. DO NOT EDIT.'
83 patterns['toolfeature'] = 'Yes' if c in gen.tcoll4topo else 'Lacking'
85 patterns['init'] = gen.init[c]("1")
86 patterns['fini'] = gen.fini[c]("1")
87 patterns['operation'] = gen.operation[c]("1")
88 patterns['change_dims'] = '/* No error injected here */'
90 # Generate the correct code
91 replace = patterns.copy()
92 replace['shortdesc'] = 'Function @{c}@ with correct arguments'
93 replace['longdesc'] = f'All ranks in comm call {c} with correct arguments'
94 replace['outcome'] = 'OK'
95 replace['errormsg'] = ''
96 replace['change_com'] = '/* No error injected here */'
97 replace['change_dims'] = '/* No error injected here */'
98 gen.make_file(template, f'InvalidParam_{c}_ok.c', replace)
100 # Generate the incorrect code
101 replace = patterns.copy()
102 replace['shortdesc'] = 'The code tries to get cartesian information of MPI_COMM_WORLD.'
103 replace['longdesc'] = 'The code creates a cartesian communicator, and tries to get cartesian information of MPI_COMM_WORLD.'
104 replace['outcome'] = 'ERROR: InvalidCommunicator'
105 replace['errormsg'] = 'Invalid Communicator in a collective. @{c}@ at @{filename}@:@{line:MBIERROR2}@ tries to get cartesian information of MPI_COMM_WORLD.'
106 replace['change_com'] = 'newcom = MPI_COMM_WORLD; /* MBIERROR1 */'
107 gen.make_file(template, f'InvalidParam_Com_{c}_nok.c', replace)
109 # Generate the code with newcom=MPI_COMM_NULL
110 replace = patterns.copy()
111 replace['shortdesc'] = 'Function @{c}@ called with comm=MPI_COMM_NULL'
112 replace['longdesc'] = 'Function @{c}@ called with comm=MPI_COMM_NULL'
113 replace['outcome'] = 'ERROR: InvalidCommunicator'
114 replace['errormsg'] = 'Invalid communicator. @{c}@ at @{filename}@:@{line:MBIERROR2}@ has MPI_COMM_NULL as a communicator.'
115 replace['change_com'] = 'newcom = MPI_COMM_NULL; /* MBIERROR1 */'
116 gen.make_file(template, f'InvalidParam_ComNull_{c}_nok.c', replace)
118 # Generate the code with invalid dimension
119 replace = patterns.copy()
120 replace['shortdesc'] = 'Creates a cartesian communicator with a negative entry in the dims attribute'
121 replace['longdesc'] = 'Creates a cartesian communicator with a negative entry in the dims attribute, which is a usage error'
122 replace['outcome'] = 'ERROR: InvalidOtherArg'
123 replace['errormsg'] = 'Invalid Argument. MPI_Cart_create has invalid dimensions.'
124 replace['change_com'] = ""
125 replace['change_dims'] = 'dims[0] = -2; dims[1] = -1; /* MBIERROR1 */'
126 gen.make_file(template, 'InvalidParam_Dim_MPI_Cart_create_nok.c', replace)