Logo AND Algorithmique Numérique Distribuée

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