Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Add new entry in Release_Notes.
[simgrid.git] / teshsuite / smpi / MBI / P2PMatchingANYSRCGenerator.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 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: Lacking
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 src=MPI_ANY_SOURCE, dest=0;
43   int stag = 42, rtag = MPI_ANY_TAG;
44   int buff_size = 1;
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   int send_buffer=rank;
55
56   MPI_Datatype type = MPI_INT;
57   MPI_Comm newcom = MPI_COMM_WORLD;
58
59   @{init1}@
60   @{init2}@
61
62   if (rank == 0) {
63     for (int i = 0; i < nprocs - 1; i++) {
64       @{operation1}@ /* MBIERROR */
65       @{fini1}@
66     }
67   if (@{cond}@ != 3) {
68       printf("MBI_MSG_RACE: The last received message is not 3 but %d!\\n", buf1);
69       fflush(stdout);
70       abort();
71     }
72   }else{
73     @{operation2}@
74     @{fini2}@
75   }
76
77
78   MPI_Finalize();
79   printf("Rank %d finished normally\\n", rank);
80   return 0;
81 }
82 """
83
84
85 for s in gen.send + gen.isend:
86     for r in gen.recv + gen.irecv:
87         patterns = {}
88         patterns = {'s': s, 'r': r}
89         patterns['generatedby'] = f'DO NOT EDIT: this file was generated by {os.path.basename(sys.argv[0])}. DO NOT EDIT.'
90         patterns['p2pfeature'] = 'Yes' if s in gen.send or r in gen.recv else 'Lacking'
91         patterns['ip2pfeature'] = 'Yes' if s in gen.isend or r in gen.irecv else 'Lacking'
92         patterns['s'] = s
93         patterns['r'] = r
94         patterns['cond'] = 'buf1'
95         patterns['init2'] = gen.init[s]("2")
96         patterns['init1'] = gen.init[r]("1")
97         patterns['fini2'] = gen.fini[s]("2")
98         patterns['fini1'] = gen.fini[r]("1")
99         patterns['operation2'] = gen.operation[s]("2")
100         patterns['operation1'] = gen.operation[r]("1")
101
102         # Generate the incorrect matching
103         replace = patterns.copy()
104         replace['shortdesc'] = 'The message ordering is non-deterministic.'
105         replace['longdesc'] = 'The code assumes a fixed order in the reception of messages while the message ordering is non-deterministic.'
106         replace['outcome'] = 'ERROR: MessageRace'
107         replace['errormsg'] = 'P2P message race which can cause a deadlock. @{r}@ at @{filename}@:@{line:MBIERROR}@ is called with ANY_SRC.'
108         gen.make_file(template, f'MessageRace_{r}_{s}_nok.c', replace)