Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Add the remaining MBI generators
[simgrid.git] / teshsuite / smpi / MBI / P2PComGenerator.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: @{origin}@
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: @{persfeature}@
20         COLL!basic: Lacking
21         COLL!nonblocking: Lacking
22         COLL!persistent: Lacking
23         COLL!tools: Yes
24         RMA: Lacking
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
39 int main(int argc, char **argv) {
40   int nprocs = -1;
41   int rank = -1;
42         int src=0, dest=1;
43   int stag = 0, rtag = 0;
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         MPI_Datatype type = MPI_INT; 
55   MPI_Comm newcom; 
56   MPI_Comm_split(MPI_COMM_WORLD, 0, nprocs - rank, &newcom);
57   @{change_com}@
58   @{change_srcdest}@
59
60   @{init1}@
61   @{init2}@
62         if (rank == 0) {
63         @{operation1}@ /* MBIERROR1 */
64           @{start1}@
65           @{fini1}@
66         }else if (rank == 1) {
67         @{operation2}@ /* MBIERROR2 */
68           @{start2}@
69           @{fini2}@
70         }
71   @{free1}@
72   @{free2}@
73
74         if(newcom != MPI_COMM_NULL && newcom != MPI_COMM_WORLD)
75                 MPI_Comm_free(&newcom);
76
77   MPI_Finalize();
78   printf("Rank %d finished normally\\n", rank);
79   return 0;
80 }
81 """
82
83
84 for p1 in send + isend + psend:
85     for p2 in recv + irecv + precv:
86         patterns = {}
87         patterns = {'p1': p1, 'p2': p2}
88         patterns['origin'] = "MBI" 
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 p1 in send or p2 in recv  else 'Lacking'
91         patterns['ip2pfeature'] = 'Yes' if p1 in isend or p2 in irecv  else 'Lacking' 
92         patterns['persfeature'] = 'Yes' if p1 in psend or p2 in precv  else 'Lacking' 
93         patterns['p1'] = p1 
94         patterns['p2'] = p2 
95         patterns['init1'] = init[p1]("1") 
96         patterns['init2'] = init[p2]("2")
97         patterns['start1'] = start[p1]("1") 
98         patterns['start2'] = start[p2]("2")
99         patterns['fini1'] = fini[p1]("1") 
100         patterns['fini2'] = fini[p2]("2") 
101         patterns['operation1'] = operation[p1]("1") #send
102         patterns['operation2'] = operation[p2]("2") #recv
103         patterns['free1'] = free[p1]("1") 
104         patterns['free2'] = free[p2]("2") 
105         patterns['change_srcdest'] = "" 
106
107                 # Generate the incorrect matching 
108         replace = patterns 
109         replace['shortdesc'] = 'Point to point @{p1}@ and @{p2}@ have a communicator mismatch' 
110         replace['longdesc'] = 'Process 1 uses newcom as the communicator while process 0 uses MPI_COMM_WORLD.' 
111         replace['outcome'] = 'ERROR: CommunicatorMatching' 
112         replace['errormsg'] = 'P2P Communicator mismatch. @{p1}@ at @{filename}@:@{line:MBIERROR1}@ and @{p2}@ at @{filename}@:@{line:MBIERROR2}@ have newcom or MPI_COMM_WORLD as a communicator.' 
113         replace['change_com'] = 'if (rank==0)\n    newcom = MPI_COMM_WORLD; /* MBIERROR */'
114         make_file(template, f'ParamMatching_Com_{p1}_{p2}_nok.c', replace)
115
116                 # Generate the code with an invalid communicator 
117         replace = patterns 
118         replace['shortdesc'] = 'Point to point @{p1}@ and @{p2}@ have an invalid communicator' 
119         replace['longdesc'] = 'Point to point @{p1}@ and @{p2}@ have an invalid communicator.' 
120         replace['outcome'] = 'ERROR: InvalidCommunicator' 
121         replace['errormsg'] = 'Invalid Communicator. @{p1}@ at @{filename}@:@{line:MBIERROR1}@ and @{p2}@ at @{filename}@:@{line:MBIERROR2}@ use a communicator that is freed line @{line:MBIERROR}@.' 
122         replace['change_com'] = 'MPI_Comm_free(&newcom);  /* MBIERROR */'
123         make_file(template, f'InvalidParam_Com_{p1}_{p2}_nok.c', replace)
124
125                                 #  Generate the code with an invalid communicator ==> TO CHECK
126         #replace = patterns 
127         #replace['shortdesc'] = 'Point to point @{p1}@ and @{p2}@ have an invalid communicator' 
128        # replace['longdesc'] = 'Point to point @{p1}@ and @{p2}@ have an invalid communicator.' 
129        # replace['outcome'] = 'ERROR: InvalidCommunicator' 
130        # replace['errormsg'] = 'Invalid Communicator. @{p1}@ at @{filename}@:@{line:MBIERROR1}@ and @{p2}@ at @{filename}@:@{line:MBIERROR2}@ use different communicators' 
131        # replace['origin'] = "MPI-Corrbench"
132        # replace['change_com'] = ""
133        # make_file(template, f'InvalidParam_Com_{p1}_{p2}_nok.c', replace)
134
135                 # Generate the code with an invalid dest 
136         replace = patterns 
137         replace['origin'] = "MBI"
138         replace['shortdesc'] = 'Point to point @{p1}@ has an invalid argument' 
139         replace['longdesc'] = 'Point to point @{p1}@ and @{p2}@ have an invalid communicator.' 
140         replace['outcome'] = 'ERROR: InvalidSrcDest' 
141         replace['errormsg'] = 'InvalidSrcDest. @{p1}@ at @{filename}@:@{line:MBIERROR1}@ performs a send with a dest not in communicator (dest is changed line @{line:MBIERROR}@).' 
142         replace['change_com'] = ""
143         replace['change_srcdest'] = 'dest=4; /* MBIERROR */'
144         make_file(template, f'InvalidParam_Dest_{p1}_{p2}_nok.c', replace)
145
146                 # Generate the code with an invalid src 
147         replace = patterns 
148         replace['shortdesc'] = 'Point to point @{p2}@ has an invalid argument'
149         replace['longdesc'] = 'Point to point @{p1}@ and @{p2}@ have an invalid communicator.' 
150         replace['outcome'] = 'ERROR: InvalidSrcDest' 
151         replace['errormsg'] = 'InvalidSrcDest. @{p2}@ at @{filename}@:@{line:MBIERROR2}@ performs a recv with a negative integer as source (src is changed line @{line:MBIERROR}@).' 
152         replace['change_srcdest'] = 'src=-1; /* MBIERROR */'
153         make_file(template, f'InvalidParam_Src_{p1}_{p2}_nok.c', replace)