Logo AND Algorithmique Numérique Distribuée

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