Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
teshsuite: smpi: MBI: Merge change form MBI.
[simgrid.git] / teshsuite / smpi / MBI / P2PProbeGenerator.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: Lacking
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   MPI_Status sta;
43   int src,dest;
44   int stag=0, rtag=0;
45   int buff_size = 1;
46
47   MPI_Init(&argc, &argv);
48   MPI_Comm_size(MPI_COMM_WORLD, &nprocs);
49   MPI_Comm_rank(MPI_COMM_WORLD, &rank);
50   printf("Hello from rank %d \\n", rank);
51
52   if (nprocs < 2)
53     printf("MBI ERROR: This test needs at least 2 processes to produce a bug!\\n");
54
55   MPI_Comm newcom = MPI_COMM_WORLD;
56   MPI_Datatype type = MPI_INT;
57
58   @{init1a}@
59   @{init1b}@
60   @{init1c}@
61   @{init2a}@
62   @{init2b}@
63   @{init2c}@
64
65   if (rank == 0) {
66     dest=1, src=1;
67     @{operation1a}@ /* MBIERROR1 */
68     @{operation1b}@
69     @{operation1c}@
70     @{fini1a}@
71     @{fini1b}@
72     @{fini1c}@
73   }else if (rank == 1){
74     dest=0, src=0;
75     @{operation2a}@ /* MBIERROR2 */
76     @{operation2b}@
77     @{operation2c}@
78     @{fini2a}@
79     @{fini2b}@
80     @{fini2c}@
81   }
82   @{free1a}@
83   @{free1b}@
84   @{free1c}@
85   @{free2a}@
86   @{free2b}@
87   @{free2c}@
88
89   MPI_Finalize();
90   printf("Rank %d finished normally\\n", rank);
91   return 0;
92 }
93 """
94
95
96 for p in gen.probe:
97     for s in gen.send + gen.isend:
98         for r in gen.recv + gen.irecv:
99             patterns = {}
100             patterns = {'p':p, 's': s, 'r': r}
101             patterns['generatedby'] = f'DO NOT EDIT: this file was generated by {os.path.basename(sys.argv[0])}. DO NOT EDIT.'
102             patterns['p2pfeature'] = 'Yes' if s in gen.send or r in gen.recv else 'Lacking'
103             patterns['ip2pfeature'] = 'Yes' if s in gen.isend or r in gen.irecv else 'Lacking'
104             patterns['s'] = s
105             patterns['r'] = r
106             patterns['p'] = p
107             patterns['init1a'] = gen.init[p]("1")
108             patterns['init1b'] = gen.init[s]("1")
109             patterns['init1c'] = gen.init[r]("2")
110             patterns['init2a'] = gen.init[p]("1")
111             patterns['init2b'] = gen.init[r]("3")
112             patterns['init2c'] = gen.init[s]("4")
113             patterns['fini1a'] = gen.fini[p]("1")
114             patterns['fini1b'] = gen.fini[s]("1")
115             patterns['fini1c'] = gen.fini[r]("2")
116             patterns['fini2a'] = gen.fini[p]("1")
117             patterns['fini2b'] = gen.fini[r]("3")
118             patterns['fini2c'] = gen.fini[s]("4")
119             patterns['free1a'] = gen.free[p]("1")
120             patterns['free1b'] = gen.free[s]("1")
121             patterns['free1c'] = gen.free[r]("2")
122             patterns['free2a'] = gen.free[p]("1")
123             patterns['free2b'] = gen.free[r]("3")
124             patterns['free2c'] = gen.free[s]("4")
125             patterns['operation1a'] = gen.operation[p]("1")
126             patterns['operation1b'] = gen.operation[s]("1")
127             patterns['operation1c'] = gen.operation[r]("2")
128             patterns['operation2a'] = gen.operation[p]("1")
129             patterns['operation2b'] = gen.operation[r]("3")
130             patterns['operation2c'] = gen.operation[s]("4")
131
132             # Generate the incorrect matching
133             replace = patterns.copy()
134             replace['shortdesc'] = 'MPI_Probe is called before MPI_Recv.'
135             replace['longdesc'] = 'MPI_Probe is a blocking call that returns only after a matching message has been found. By calling MPI_Probe before MPI_Recv, a deadlock is created.'
136             replace['outcome'] = 'ERROR: CallMatching'
137             replace['errormsg'] = 'P2P mistmatch. @{p}@ at @{filename}@:@{line:MBIERROR1}@ and @{filename}@:@{line:MBIERROR2}@ are called before @{r}@.'
138             gen.make_file(template, f'CallOrdering_{p}_{r}_{s}_nok.c', replace)
139
140             # Generate a correct matching
141             replace = patterns.copy()
142             replace['shortdesc'] = 'Correct use of MPI_Probe.'
143             replace['longdesc'] = 'Correct use of MPI_Probe.'
144             replace['outcome'] = 'OK'
145             replace['errormsg'] = 'OK'
146             replace['operation1a'] = gen.operation[s]("1")
147             replace['operation1b'] = gen.operation[p]("1")
148             gen.make_file(template, f'CallOrdering_{p}_{r}_{s}_ok.c', replace)