Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Merge branch 'master' of framagit.org:simgrid/simgrid
[simgrid.git] / teshsuite / smpi / MBI / P2PMessageRaceTagsGenerator.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 3 ${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 #define N 10
39
40 int main(int argc, char **argv) {
41   int nprocs = -1;
42   int rank = -1;
43   int dest, src;
44   int i=0;
45   int root = 0;
46   int stag = 0, rtag = 0;
47   int buff_size = 1;
48
49   MPI_Init(&argc, &argv);
50   MPI_Comm_size(MPI_COMM_WORLD, &nprocs);
51   MPI_Comm_rank(MPI_COMM_WORLD, &rank);
52   printf("Hello from rank %d \\n", rank);
53
54   if (nprocs < 3)
55     printf("MBI ERROR: This test needs at least 3 processes to produce a bug!\\n");
56
57   int dbs = sizeof(int)*nprocs; /* Size of the dynamic buffers for alltoall and friends */
58   MPI_Comm newcom = MPI_COMM_WORLD;
59   MPI_Datatype type = MPI_INT;
60   MPI_Op op = MPI_SUM;
61
62   @{init0}@
63   @{init1a}@
64   @{init1b}@
65   @{init2}@
66
67   if (rank == 0) {
68     dest = 1; stag = 1;
69     @{operation0}@
70     @{fini0}@
71   } else if (rank == 1) {
72     src = MPI_ANY_SOURCE;
73     rtag = @{tag1}@;
74     @{operation1a}@
75     @{fini1a}@
76     rtag = @{tag2}@;
77     @{operation1b}@ @{tagerror}@
78     @{fini1b}@
79   } else if (rank == 2) {
80     dest = 1; stag = 2;
81     @{operation2}@
82     @{fini2}@
83   }
84
85   @{free0}@
86   @{free1a}@
87   @{free1b}@
88   @{free2}@
89
90   MPI_Finalize();
91   printf("Rank %d finished normally\\n", rank);
92   return 0;
93 }
94 """
95
96 # To be correct, this benchmark must be use wildcard on second recv
97 # tag, or no wildcard on first recv tag and second recv tag must be
98 # different.
99 #
100 # |-----+-----+----+----|
101 # | x\y | ANY | 1  | 2  |
102 # |-----+-----+----+----|
103 # | ANY | OK  |  - |  - |
104 # |   1 | OK  |  - | OK |
105 # |   2 | OK  | OK |  - |
106 # |-----+-----+----+----|
107
108 for s in gen.send:
109     for r in gen.recv:
110         for x, y in [('MPI_ANY_TAG', 'MPI_ANY_TAG'), # OK
111                      ('MPI_ANY_TAG', '1'),           # NOK
112                      ('1', 'MPI_ANY_TAG'),           # OK
113                      ('1', '2'),                     # OK
114                      ('2', '2')]:                    # NOK
115             patterns = {}
116             patterns['generatedby'] = f'DO NOT EDIT: this file was generated by {os.path.basename(sys.argv[0])}. DO NOT EDIT.'
117             patterns['p2pfeature'] = 'Yes' if s in gen.send or r in gen.recv else 'Lacking'
118             patterns['ip2pfeature'] = 'Yes' if s in gen.isend or r in gen.irecv else 'Lacking'
119             patterns['s'] = s
120             patterns['r'] = r
121
122             patterns['tag1'] = x
123             patterns['tag2'] = y
124
125             patterns['init0'] = gen.init[s]("0")
126             patterns['operation0'] = gen.operation[s]("0")
127             patterns['fini0'] = gen.fini[s]("0")
128             patterns['free0'] = gen.free[s]("0")
129
130             patterns['init1a'] = gen.init[r]("1a")
131             patterns['init1b'] = gen.init[r]("1b")
132             patterns['operation1a'] = gen.operation[r]("1a")
133             patterns['operation1b'] = gen.operation[r]("1b")
134             patterns['fini1a'] = gen.fini[r]("1a")
135             patterns['fini1b'] = gen.fini[r]("1b")
136             patterns['free1a'] = gen.free[r]("1a")
137             patterns['free1b'] = gen.free[r]("1b")
138
139             patterns['init2'] = gen.init[s]("2")
140             patterns['operation2'] = gen.operation[s]("2")
141             patterns['fini2'] = gen.fini[s]("2")
142             patterns['free2'] = gen.free[s]("2")
143             patterns['tagerror'] = '/* MBIERROR */'
144
145             if y == 'MPI_ANY_TAG' or (x != 'MPI_ANY_TAG' and x != y):
146                 # Generate the correct matching because of the conditional
147                 replace = patterns.copy()
148                 replace['shortdesc'] = 'Message race'
149                 replace['longdesc'] = 'Correct code without message race.'
150                 replace['outcome'] = 'OK'
151                 replace['errormsg'] = 'OK'
152                 replace['tagerror'] = ''
153                 gen.make_file(template, f'MessageRace_tag_{x}_{y}_{s}_{r}_ok.c', replace)
154             else:
155                 # Generate the incorrect matching because of the conditional
156                 replace = patterns.copy()
157                 replace['shortdesc'] = 'Message race'
158                 replace['longdesc'] = 'Message race in @{r}@ with @{s}@.'
159                 replace['outcome'] = 'ERROR: MessageRace'
160                 replace['errormsg'] = 'Message race. The use of wildcard receive calls @{r}@ at @{filename}@:@{line:MBIERROR}@ and incorrect tag matching.'
161                 gen.make_file(template, f'MessageRace_tag_{x}_{y}_{s}_{r}_nok.c', replace)