Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Add the remaining MBI generators
[simgrid.git] / teshsuite / smpi / MBI / CollP2PMatchingGenerator.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 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 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 < 2)
53     printf("MBI ERROR: This test needs at least 2 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   @{init1}@
61   @{init2}@
62   @{init3}@
63         if (rank == 0) {
64                 dest=1;src=1;
65         @{operation3}@ /* MBIERROR1 */
66                 @{fini3}@
67         @{operation1}@ 
68                 @{fini1}@
69         }else if (rank==1) {
70                 dest=0;src=0;
71         @{operation2}@ /* MBIERROR2 */
72                 @{fini2}@
73         @{operation3}@ 
74                 @{fini3}@
75         }
76
77         @{free1}@
78         @{free2}@
79         @{free3}@
80   
81         MPI_Finalize();
82   printf("Rank %d finished normally\\n", rank);
83   return 0;
84 }
85 """
86
87
88 for s in send + isend:
89     for r in recv + irecv:
90         for c in coll:
91             patterns = {}
92             patterns = {'s': s, 'r': r, 'c': c}
93             patterns['generatedby'] = f'DO NOT EDIT: this file was generated by {os.path.basename(sys.argv[0])}. DO NOT EDIT.'
94             patterns['p2pfeature'] = 'Yes' if s in send or r in recv else 'Lacking'
95             patterns['ip2pfeature'] = 'Yes' if s in isend or r in irecv else 'Lacking'
96             patterns['collfeature'] = 'Yes' if c in coll else 'Lacking'
97             patterns['s'] = s
98             patterns['r'] = r
99             patterns['c'] = c
100             patterns['init1'] = init[s]("1")
101             patterns['init2'] = init[r]("2")
102             patterns['init3'] = init[c]("3")
103             patterns['fini1'] = fini[s]("1")
104             patterns['fini2'] = fini[r]("2")
105             patterns['fini3'] = fini[c]("3")
106             patterns['free1'] = free[s]("1")
107             patterns['free2'] = free[r]("2")
108             patterns['free3'] = free[c]("3")
109             patterns['operation1'] = operation[s]("1")
110             patterns['operation2'] = operation[r]("2")
111             patterns['operation3'] = operation[c]("3")
112
113             # Generate the incorrect matching because of the conditional
114             replace = patterns 
115             replace['shortdesc'] = 'Point to point & collective mismatch'
116             replace['longdesc'] = 'Point to point @{r}@ is matched with @{c}@ which causes a deadlock.' 
117             replace['outcome'] = 'ERROR: CallMatching' 
118             replace['errormsg'] = 'P2P & Collective mistmatch. @{r}@ at @{filename}@:@{line:MBIERROR2}@ is matched with @{c}@ at @{filename}@:@{line:MBIERROR1}@ wich causes a deadlock.'
119             make_file(template, f'CallOrdering_{r}_{s}_{c}_nok.c', replace)
120
121             # Generate the incorrect code depending on buffering
122             #  replace = patterns 
123             #  replace['shortdesc'] = 'Point to point & collective mismatch'
124             #  replace['longdesc'] = 'Point to point @{s}@ is matched with @{c}@ which causes a deadlock depending on the buffering mode.' 
125             #  replace['outcome'] = 'ERROR: BufferingHazard' 
126             #  replace['errormsg'] = 'P2P & Collective mistmatch. @{s}@ at @{filename}@:@{line:MBIERROR2}@ is matched with @{c}@ at @{filename}@:@{line:MBIERROR1}@ wich causes a deadlock.'
127             #  replace['init1'] = init[s]("1") 
128             #  replace['init2'] = init[r]("2") 
129             #  replace['operation1'] = operation[r]("2")
130             #  replace['operation2'] = operation[s]("1")
131             #  replace['fini1'] = fini[r]("2") 
132             #  replace['fini2'] = fini[s]("1") 
133             #  make_file(template, f'CollP2PBuffering_{r}_{s}_{c}_nok.c', replace)
134