3 # Copyright 2021-2022. The MBI project. All rights reserved.
4 # This program is free software; you can redistribute it and/or modify it under the terms of the license (GNU GPL).
8 import generator_utils as gen
10 template = """// @{generatedby}@
11 /* ///////////////////////// The MPI Bugs Initiative ////////////////////////
15 Description: @{shortdesc}@
18 Version of MPI: Conforms to MPI 1.1, does not require MPI 2 implementation
22 P2P!nonblocking: Lacking
23 P2P!persistent: Lacking
25 COLL!nonblocking: Lacking
26 COLL!persistent: Lacking
27 COLL!tools: @{toolfeature}@
36 ////////////////////// End of MBI headers /////////////////// */
41 #define ITERATIONS 100
42 #define PARAM_PER_ITERATION 3
43 #define PARAM_LOST_PER_ITERATION 1
45 static void myOp(int *invec, int *inoutvec, int *len, MPI_Datatype *dtype) {
46 for (int i = 0; i < *len; i++)
47 inoutvec[i] += invec[i];
50 int main(int argc, char **argv) {
57 MPI_Init(&argc, &argv);
58 MPI_Comm_size(MPI_COMM_WORLD, &nprocs);
59 MPI_Comm_rank(MPI_COMM_WORLD, &rank);
60 printf("Hello from rank %d \\n", rank);
63 printf("MBI ERROR: This test needs at least 2 processes to produce a bug!\\n");
76 printf("Rank %d finished normally\\n", rank);
81 # Generate code with one collective
82 for call in gen.tcoll:
84 patterns = {'call': call}
85 patterns['generatedby'] = f'DO NOT EDIT: this file was generated by {os.path.basename(sys.argv[0])}. DO NOT EDIT.'
86 patterns['toolfeature'] = 'Yes'
87 patterns['call'] = call
88 patterns['operation'] = gen.operation[call]("1")
89 patterns['init'] = gen.init[call]("1")
90 patterns['fini'] = gen.fini[call]("1")
91 patterns['free'] = gen.free[call]("1")
92 missing = patterns['fini']
95 patterns['change_size'] = ''
98 # Generate the correct code
99 replace = patterns.copy()
100 replace['shortdesc'] = '@{call}@ is correctly used'
101 replace['longdesc'] = f'{call} correctly used'
102 replace['outcome'] = 'OK'
103 replace['errormsg'] = ''
104 gen.make_file(template, f'ResLeak_{call}_ok.c', replace)
106 # Generate the resleak
107 replace = patterns.copy()
108 replace['shortdesc'] = '@{call}@ has no free'
109 replace['longdesc'] = '@{call}@ has no free'
110 replace['outcome'] = f'ERROR: {gen.error[call]}'
111 replace['errormsg'] = 'Resleak. @{call}@ at @{filename}@:@{line:MBIERROR}@ has no free.'
112 replace['fini'] = ' /* MBIERROR MISSING: ' + missing + ' */'
113 gen.make_file(template, f'ResLeak_{call}_nok.c', replace)
115 # Generate multiple resleak
116 replace = patterns.copy()
117 replace['shortdesc'] = '@{call}@ lacks several free'
118 replace['longdesc'] = '@{call}@ lacks several free'
119 replace['outcome'] = f'ERROR: {gen.error[call]}'
120 replace['errormsg'] = 'Resleak. @{call}@ at @{filename}@:@{line:MBIERROR}@ lacks several free.'
121 replace['change_size'] = 'size=PARAM_PER_ITERATION;'
122 replace['loop'] = 'for (i = 0; i < ITERATIONS; i++) {\n for (j = 0; j < PARAM_PER_ITERATION; j++) {'
123 replace['cond'] = ' if (j < PARAM_PER_ITERATION - PARAM_LOST_PER_ITERATION) {'
124 replace['fini'] = gen.fini[call]("1") + ' /* MBIERROR */'
125 replace['end'] = ' }\n }\n }'
126 gen.make_file(template, f'ResLeak_multiple_{call}_nok.c', replace)