Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Add new entry in Release_Notes.
[simgrid.git] / teshsuite / smpi / MBI / P2PArgGenerator.py
1 #! /usr/bin/python3
2 import os
3 import sys
4 import generator_utils as gen
5
6 template = """// @{generatedby}@
7 /* ///////////////////////// The MPI Bugs Initiative ////////////////////////
8
9   Origin: MBI
10
11   Description: @{shortdesc}@
12     @{longdesc}@
13
14    Version of MPI: Conforms to MPI 1.1, does not require MPI 2 implementation
15
16 BEGIN_MPI_FEATURES
17   P2P!basic: @{p2pfeature}@
18   P2P!nonblocking: @{ip2pfeature}@
19   P2P!persistent: @{persfeature}@
20   COLL!basic: Lacking
21   COLL!nonblocking: Lacking
22   COLL!persistent: Lacking
23   COLL!tools: Lacking
24   RMA: Lacking
25 END_MPI_FEATURES
26
27 BEGIN_MBI_TESTS
28   $ mpirun -np 2 ${EXE}
29   | @{outcome}@
30   | @{errormsg}@
31 END_MBI_TESTS
32 //////////////////////       End of MBI headers        /////////////////// */
33
34 #include <mpi.h>
35 #include <stdio.h>
36 #include <stdlib.h>
37
38
39 int main(int argc, char **argv) {
40   int nprocs = -1;
41   int rank = -1;
42   int src=0, dest=1;
43   int stag=0, rtag=0;
44   int buff_size = 1;
45
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);
50
51   if (nprocs < 2)
52     printf("MBI ERROR: This test needs at least 2 processes to produce a bug!\\n");
53
54   MPI_Comm newcom = MPI_COMM_WORLD;
55   MPI_Datatype type = MPI_INT;
56
57   @{change_arg}@
58
59   @{init1}@
60   @{init2}@
61   if (rank == 0) {
62     @{operation1}@ /* MBIERROR1 */
63     @{start1}@
64     @{fini1}@
65   }else if (rank == 1) {
66     @{operation2}@ /* MBIERROR2 */
67     @{start2}@
68     @{fini2}@
69   }
70   @{free1}@
71   @{free2}@
72
73   MPI_Finalize();
74   printf("Rank %d finished normally\\n", rank);
75   return 0;
76 }
77 """
78
79 ##################################
80 # Generate code with type mismatch
81 ##################################
82
83 for p1 in gen.allsend:
84     for p2 in gen.allrecv:
85         patterns = {}
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'
91         patterns['p1'] = p1
92         patterns['p2'] = p2
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")
103
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)
112
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)
121
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)
130
131 #################################
132 # Generate code with tag mismatch
133 #################################
134
135 for p1 in gen.allsend:
136     for p2 in gen.allrecv:
137         patterns = {}
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'
143         patterns['p1'] = p1
144         patterns['p2'] = p2
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'] = ""
156
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)
165
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)
174
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)