Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Add new entry in Release_Notes.
[simgrid.git] / teshsuite / smpi / MBI / RMAP2PLocalConcurrencyGenerator.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: @{origin}@
10
11   Description: @{shortdesc}@
12     @{longdesc}@
13
14   Version of MPI: Conforms to MPI 2, does not require MPI 3 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: @{rmafeature}@
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 1
39
40 int main(int argc, char **argv) {
41   int nprocs = -1;
42   int rank = -1;
43   MPI_Win win;
44   int * winbuf = (int *)malloc(N * sizeof(int)); // Window buffer
45   int buff_size = N;
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 < 3)
53     printf("MBI ERROR: This test needs at least 3 processes to produce a bug!\\n");
54
55   MPI_Comm newcom = MPI_COMM_WORLD;
56   MPI_Datatype type = MPI_INT;
57   int stag=0, rtag=0;
58   winbuf[0] = nprocs;
59
60   MPI_Win_create(winbuf, N*sizeof(int), sizeof(int), MPI_INFO_NULL, MPI_COMM_WORLD, &win);
61
62
63   @{init1}@
64   @{init2}@
65   @{init3}@
66
67   @{comment_fence}@MPI_Win_fence(0, win);
68
69   if (rank == 0) {
70     int target=1, dest=2;
71
72     @{comment_lock}@MPI_Win_lock(MPI_LOCK_EXCLUSIVE, 1, 0, win);
73     @{operation1}@
74     @{operation2}@ /* MBIERROR */
75     @{comment_lock}@MPI_Win_unlock(1, win);
76
77     @{fini2}@
78   }else if (rank == 2){
79     int src=0;
80     @{operation3}@
81     @{fini3}@
82   }
83
84   @{comment_fence}@MPI_Win_fence(0, win);
85
86   MPI_Win_free(&win);
87   free(winbuf);
88
89   MPI_Finalize();
90   printf("Rank %d finished normally\\n", rank);
91   return 0;
92 }
93 """
94
95
96 for p in gen.get:
97     for s in gen.send + gen.isend:
98          for r in gen.recv + gen.irecv:
99              patterns = {}
100              patterns = {'p': p, 's': s, 'r': r}
101              patterns['generatedby'] = f'DO NOT EDIT: this file was generated by {os.path.basename(sys.argv[0])}. DO NOT EDIT.'
102              patterns['origin'] = 'RTED'
103              patterns['shortdesc'] = 'Local Concurrency error.'
104              patterns['longdesc'] = 'Local Concurrency error. Concurrent access of variable localbuf1 by @{p}@ (write) and @{s}@ (read)'
105              patterns['rmafeature'] = 'Yes'
106              patterns['p2pfeature'] = 'Yes' if s in gen.send or r in gen.recv  else 'Lacking'
107              patterns['ip2pfeature'] = 'Yes' if s in gen.isend or r in gen.irecv  else 'Lacking'
108              patterns['p'] = p
109              patterns['s'] = s
110              patterns['r'] = r
111              patterns['init1'] = gen.init[p]("1")
112              patterns['init2'] = gen.init[s]("2")
113              patterns['init3'] = gen.init[r]("3")
114              patterns['fini2'] = gen.fini[s]("2")
115              patterns['fini3'] = gen.fini[r]("3")
116              patterns['operation1'] = gen.operation[p]("1")
117              patterns['operation2'] = gen.operation[s]("2").replace("buf2", "localbuf1")
118              patterns['operation3'] = gen.operation[r]("3")
119              patterns['comment_lock'] = ''
120              patterns['comment_fence'] = ''
121
122              # Use fence epoch
123              replace = patterns.copy()
124              replace['outcome'] = 'ERROR: LocalConcurrency'
125              replace['errormsg'] = 'Local Concurrency error. @{p}@ at @{filename}@:@{line:MBIERROR}@ .'
126              replace['comment_lock'] = '// '
127              gen.make_file(template, f'LocalConcurrency_fence_{p}_{s}_{r}_nok.c', replace)
128
129              # Use lock epoch
130              replace = patterns.copy()
131              replace['outcome'] = 'ERROR: LocalConcurrency'
132              replace['errormsg'] = 'Local Concurrency error. @{p}@ at @{filename}@:@{line:MBIERROR}@ .'
133              replace['comment_fence'] = '// '
134              gen.make_file(template, f'LocalConcurrency_lock_{p}_{s}_{r}_nok.c', replace)