Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
[MBI] Import generator_utils as gen.
[simgrid.git] / teshsuite / smpi / MBI / RMAP2PGlobalConcurrencyGenerator.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, 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 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 #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 = malloc(N * sizeof(int)); // Window buffer
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 at least 4 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   if (rank == 0) {
68     int target=1;
69     MPI_Win_lock(MPI_LOCK_EXCLUSIVE, 1, 0, win);
70     @{operation1}@
71     localbuf1[0] = 12345; /* MBIERROR1 */
72     MPI_Win_unlock(1, win);
73   }else if (rank == 2){
74     int dest=1;
75     @{operation2}@
76     @{fini2}@
77   }else if (rank == 1){
78     int src=2;
79     buf3 = winbuf[0];
80     @{operation3}@
81     winbuf[0] = buf3; /* MBIERROR2 */
82     @{fini3}@
83   }
84
85   MPI_Win_free(&win);
86   free(winbuf);
87
88   MPI_Finalize();
89   printf("Rank %d finished normally\\n", rank);
90   return 0;
91 }
92 """
93
94
95 for p in gen.put + gen.get:
96     for s in gen.send + gen.isend:
97         for r in gen.recv + gen.irecv:
98             patterns = {}
99             patterns = {'p': p, 's': s, 'r': r}
100             patterns['generatedby'] = f'DO NOT EDIT: this file was generated by {os.path.basename(sys.argv[0])}. DO NOT EDIT.'
101             patterns['rmafeature'] = 'Yes'
102             patterns['p2pfeature'] = 'Yes' if s in gen.send or r in gen.recv  else 'Lacking'
103             patterns['ip2pfeature'] = 'Yes' if s in gen.isend or r in gen.irecv  else 'Lacking'
104             patterns['p'] = p
105             patterns['s'] = s
106             patterns['r'] = r
107             patterns['init1'] = gen.init[p]("1")
108             patterns['init2'] = gen.init[s]("2")
109             patterns['init3'] = gen.init[r]("3")
110             patterns['fini2'] = gen.fini[s]("2")
111             patterns['fini3'] = gen.fini[r]("3")
112             patterns['operation1'] = gen.operation[p]("1") #put or get
113             patterns['operation2'] = gen.operation[s]("2") #send
114             patterns['operation3'] = gen.operation[r]("3") #recv
115
116             replace = patterns
117             replace['shortdesc'] = 'Global Concurrency error.'
118             replace['longdesc'] = 'Global Concurrency error. Concurrent access of variable winbuf by @{p}@ and @{r}@'
119             replace['outcome'] = 'ERROR: GlobalConcurrency'
120             replace['errormsg'] = 'Global Concurrency error. @{p}@ at @{filename}@:@{line:MBIERROR1}@ accesses the window of process 1. Process 1 receives data from process 2 and uses variable winbuf. winbuf in process 1 is then nondeterministic.'
121             gen.make_file(template, f'GlobalConcurrency_{p}_{s}_{r}_nok.c', replace)