Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
[MBI] Import generator_utils as gen.
[simgrid.git] / teshsuite / smpi / MBI / RMALocalLocalConcurrencyGenerator.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 2, requires MPI 3 implementation (for lock_all/unlock_all epochs)
15
16 BEGIN_MPI_FEATURES
17   P2P!basic: Lacking
18   P2P!nonblocking: Lacking
19   P2P!persistent: Lacking
20   COLL!basic: Lacking
21   COLL!nonblocking: Lacking
22   COLL!persistent: Lacking
23   COLL!tools: Lacking
24   RMA: @{rmafeature}@
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 #define N 1
39
40 int main(int argc, char **argv) {
41   int nprocs = -1;
42   int rank = -1;
43   MPI_Win win;
44   int winbuf[100] = {0};
45
46   MPI_Init(&argc, &argv);
47   MPI_Comm_size(MPI_COMM_WORLD, &nprocs);
48   MPI_Comm_rank(MPI_COMM_WORLD, &rank);
49   printf("Hello from rank %d \\n", rank);
50
51   if (nprocs < 2)
52     printf("MBI ERROR: This test needs at least 2 processes to produce a bug!\\n");
53
54   MPI_Datatype type = MPI_INT;
55   int target = 1;
56
57   MPI_Win_create(&winbuf, 100 * sizeof(int), sizeof(int), MPI_INFO_NULL, MPI_COMM_WORLD, &win);
58
59   winbuf[0] = 12345;
60   @{init1}@
61
62   @{epoch}@
63
64   if (rank == 0) {
65     @{operation1}@ /* MBIERROR1 */
66     @{operation2}@ /* MBIERROR2 */
67   }
68
69   @{finEpoch}@
70
71   MPI_Win_free(&win);
72
73   MPI_Finalize();
74   return 0;
75 }
76 """
77
78
79 for e in gen.epoch:
80     for p1 in gen.get:
81         for p2 in gen.put + gen.store + gen.load + gen.get + gen.loadstore:
82             patterns = {}
83             patterns = {'e': e, 'p1': p1, 'p2': p2}
84             patterns['generatedby'] = f'DO NOT EDIT: this file was generated by {os.path.basename(sys.argv[0])}. DO NOT EDIT.'
85             patterns['rmafeature'] = 'Yes'
86             patterns['p1'] = p1
87             patterns['p2'] = p2
88             patterns['e'] = e
89             patterns['epoch'] = gen.epoch[e]("1")
90             patterns['finEpoch'] = gen.finEpoch[e]("1")
91             patterns['init1'] = gen.init[p1]("1")
92             patterns['operation1'] = gen.operation[p1]("1")
93             patterns['operation2'] = gen.operation[p2]("1")
94
95             # Generate a data race (Get + Get/load/store/Put)
96             replace = patterns
97             replace['shortdesc'] = 'Local Concurrency error.'
98             replace['longdesc'] = 'Local Concurrency error. @{p2}@ conflicts with @{p1}@'
99             replace['outcome'] = 'ERROR: LocalConcurrency'
100             replace['errormsg'] = 'Local Concurrency error. @{p2}@ at @{filename}@:@{line:MBIERROR2}@ conflicts with @{p1}@ line @{line:MBIERROR1}@'
101             gen.make_file(template, f'LocalConcurrency_lloutwindow_{e}_{p1}_{p2}_nok.c', replace)
102             # Generate a correct code by switching operation1 and  operation2
103             if p2 in gen.store + gen.load + gen.loadstore:
104                 replace = patterns
105                 replace['shortdesc'] = 'Correct code using RMA operations'
106                 replace['longdesc'] = 'Correct code using RMA operations'
107                 replace['outcome'] = 'OK'
108                 replace['errormsg'] = 'OK'
109                 replace['operation1'] = gen.operation[p2]("1")
110                 replace['operation2'] = gen.operation[p1]("1")
111                 gen.make_file(template, f'LocalConcurrency_lloutwindow_{e}_{p2}_{p1}_ok.c', replace)
112         # Generate a correct code by removing operation2
113         replace = patterns
114         replace['shortdesc'] = 'Correct code using RMA operations'
115         replace['longdesc'] = 'Correct code using RMA operations'
116         replace['outcome'] = 'OK'
117         replace['errormsg'] = 'OK'
118         replace['operation1'] = gen.operation[p1]("1")
119         replace['operation2'] = ''
120         gen.make_file(template, f'LocalConcurrency_{e}_{p1}_ok.c', replace)
121
122
123 for e in gen.epoch:
124     for p1 in gen.put:
125         for p2 in gen.store:
126             patterns = {}
127             patterns = {'e': e, 'p1': p1, 'p2': p2}
128             patterns['generatedby'] = f'DO NOT EDIT: this file was generated by {os.path.basename(sys.argv[0])}. DO NOT EDIT.'
129             patterns['rmafeature'] = 'Yes'
130             patterns['p1'] = p1
131             patterns['p2'] = p2
132             patterns['e'] = e
133             patterns['epoch'] = gen.epoch[e]("1")
134             patterns['finEpoch'] = gen.finEpoch[e]("1")
135             patterns['init1'] = gen.init[p1]("1")
136             patterns['operation1'] = gen.operation[p1]("1")
137             patterns['operation2'] = gen.operation[p2]("1")
138
139             # Generate a data race (Put + store)
140             replace = patterns
141             replace['shortdesc'] = 'Local Concurrency error.'
142             replace['longdesc'] = 'Local Concurrency error. @{p2}@ conflicts with @{p1}@'
143             replace['outcome'] = 'ERROR: LocalConcurrency'
144             replace['errormsg'] = 'Local Concurrency error. @{p2}@ at @{filename}@:@{line:MBIERROR2}@ conflicts with @{p1}@ line @{line:MBIERROR1}@'
145             gen.make_file(template, f'LocalConcurrency_lloutwindow_{e}_{p1}_{p2}_nok.c', replace)
146             # Generate a correct code by switching operation1 and operation2
147             replace = patterns
148             replace['shortdesc'] = 'Correct code using RMA operations'
149             replace['longdesc'] = 'Correct code using RMA operations'
150             replace['outcome'] = 'OK'
151             replace['errormsg'] = 'OK'
152             replace['operation1'] = gen.operation[p2]("1")
153             replace['operation2'] = gen.operation[p1]("1")
154             gen.make_file(template, f'LocalConcurrency_lloutwindow_{e}_{p2}_{p1}_ok.c', replace)
155
156             # Generate a correct code by removing operation2
157             replace = patterns
158             replace['shortdesc'] = 'Correct code using RMA operations'
159             replace['longdesc'] = 'Correct code using RMA operations'
160             replace['outcome'] = 'OK'
161             replace['errormsg'] = 'OK'
162             replace['operation1'] = gen.operation[p1]("1")
163             replace['operation2'] = ''
164             gen.make_file(template, f'LocalConcurrency_{e}_{p1}_ok.c', replace)