Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
[MBI] Make a real copy of 'patterns' into 'replace'.
[simgrid.git] / teshsuite / smpi / MBI / CollP2PMessageRaceGenerator.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: @{collfeature}@
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 4 ${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 dest, src;
43   int root = 0;
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 != 4)
53     printf("MBI ERROR: This test needs 4 processes to produce a bug!\\n");
54
55   int dbs = sizeof(int)*nprocs; /* Size of the dynamic buffers for alltoall and friends */
56   MPI_Comm newcom = MPI_COMM_WORLD;
57   MPI_Datatype type = MPI_INT;
58   MPI_Op op = MPI_SUM;
59
60
61   @{init1}@
62   @{init2}@
63   @{init3}@
64   @{init4}@
65   if (rank == 0) {
66     dest=1;
67     @{operation1}@
68     @{fini1}@
69     @{operation2}@
70     @{fini2}@
71   }else if (rank==2) {
72     dest=1;
73     @{operation1}@
74     @{fini1}@
75     @{operation2}@
76     @{fini2}@
77   }else if (rank==1) {
78     src = MPI_ANY_SOURCE;
79     rtag = MPI_ANY_TAG;
80     @{operation3}@ /* MBIERROR1 */
81     @{operation1}@
82     @{fini1}@
83     src = 0;
84     @{operation4}@ /* MBIERROR2 */
85     @{fini3}@
86     @{fini4}@
87   }else if (rank==3) {
88     @{operation1}@
89     @{fini1}@
90   }
91
92   @{free1}@
93   @{free2}@
94   @{free3}@
95   @{free4}@
96
97   MPI_Finalize();
98   printf("Rank %d finished normally\\n", rank);
99   return 0;
100 }
101 """
102
103
104 for s in gen.send + gen.isend:
105     for r in gen.irecv:
106         for c in gen.coll:
107             patterns = {}
108             patterns = {'s': s, 'r': r, 'c': c}
109             patterns['generatedby'] = f'DO NOT EDIT: this file was generated by {os.path.basename(sys.argv[0])}. DO NOT EDIT.'
110             patterns['p2pfeature'] = 'Yes' if s in gen.send or r in gen.recv else 'Lacking'
111             patterns['ip2pfeature'] = 'Yes' if s in gen.isend or r in gen.irecv else 'Lacking'
112             patterns['collfeature'] = 'Yes' if c in gen.coll else 'Lacking'
113             patterns['s'] = s
114             patterns['r'] = r
115             patterns['c'] = c
116             patterns['init1'] = gen.init[c]("1")
117             patterns['init2'] = gen.init[s]("2")
118             patterns['init3'] = gen.init[r]("3")
119             patterns['init4'] = gen.init[r]("4")
120             patterns['fini1'] = gen.fini[c]("1")
121             patterns['fini2'] = gen.fini[s]("2")
122             patterns['fini3'] = gen.fini[r]("3")
123             patterns['fini4'] = gen.fini[r]("4")
124             patterns['free1'] = gen.free[c]("1")
125             patterns['free2'] = gen.free[s]("2")
126             patterns['free3'] = gen.free[r]("3")
127             patterns['free4'] = gen.free[r]("4")
128             patterns['operation1'] = gen.operation[c]("1")
129             patterns['operation2'] = gen.operation[s]("2")
130             patterns['operation3'] = gen.operation[r]("3")
131             patterns['operation4'] = gen.operation[r]("4")
132
133             # Generate the incorrect matching because of the conditional
134             replace = patterns.copy()
135             replace['shortdesc'] = 'Message race'
136             replace['longdesc'] = 'Message race in @{r}@ with @{c}@.'
137             replace['outcome'] = 'ERROR: MessageRace'
138             replace['errormsg'] = 'Message race. The use of wildcard receive calls (@{r}@ at @{filename}@:@{line:MBIERROR1}@ and @{r}@ at @{filename}@:@{line:MBIERROR2}@) leads to nondeterministic matching.'
139             gen.make_file(template, f'MessageRace_{c}_{s}_{r}_nok.c', replace)