Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Merge branch 'issue105' into 'master'
[simgrid.git] / teshsuite / smpi / MBI / CollComGenerator.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: Lacking
18   P2P!nonblocking: Lacking
19   P2P!persistent: Lacking
20   COLL!basic: @{collfeature}@
21   COLL!nonblocking: @{icollfeature}@
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 #define buff_size 128
39
40 int main(int argc, char **argv) {
41   int nprocs = -1;
42   int rank = -1;
43   int root = 0;
44
45   MPI_Init(&argc, &argv);
46   MPI_Comm_size(MPI_COMM_WORLD, &nprocs);
47   MPI_Comm_rank(MPI_COMM_WORLD, &rank);
48   printf("Hello from rank %d \\n", rank);
49
50   if (nprocs < 2)
51     printf("MBI ERROR: This test needs at least 2 processes to produce a bug!\\n");
52
53   MPI_Op op = MPI_SUM;
54   MPI_Datatype type = MPI_INT;
55   MPI_Comm newcom;
56   MPI_Comm_split(MPI_COMM_WORLD, 0, nprocs - rank, &newcom);
57
58   @{change_com}@
59
60   int dbs = sizeof(int)*nprocs; /* Size of the dynamic buffers for alltoall and friends */
61   @{init}@
62   @{start}@
63   @{operation}@ /* MBIERROR */
64   @{fini}@
65   @{free}@
66
67   if(newcom != MPI_COMM_NULL && newcom != MPI_COMM_WORLD)
68     MPI_Comm_free(&newcom);
69
70   MPI_Finalize();
71   printf("Rank %d finished normally\\n", rank);
72   return 0;
73 }
74 """
75
76
77 # Generate code with one collective
78 for c in coll + icoll + ibarrier:
79     patterns = {}
80     patterns = {'c': c}
81     patterns['generatedby'] = f'DO NOT EDIT: this file was generated by {os.path.basename(sys.argv[0])}. DO NOT EDIT.'
82     patterns['collfeature'] = 'Yes' if c in coll else 'Lacking'
83     patterns['icollfeature'] = 'Yes' if c in icoll + ibarrier else 'Lacking'
84     patterns['c'] = c
85     patterns['init'] = init[c]("1")
86     patterns['start'] = start[c]("1")
87     patterns['fini'] = fini[c]("1")
88     patterns['free'] = free[c]("1")
89     patterns['operation'] = operation[c]("1")
90
91     # Generate the correct code => to remove?
92     replace = patterns
93     replace['shortdesc'] = 'Collective @{c}@ with correct arguments'
94     replace['longdesc'] = f'All ranks in newcom call {c} with correct arguments'
95     replace['outcome'] = 'OK'
96     replace['errormsg'] = ''
97     replace['change_com'] = '/* No error injected here */'
98     make_file(template, f'ParamMatching_Com_{c}_ok.c', replace)
99
100     # Generate the incorrect communicator matching
101     replace = patterns
102     replace['shortdesc'] = 'Collective @{c}@ with a communicator mismatch'
103     replace['longdesc'] = f'Odd ranks call the collective on newcom while even ranks call the collective on MPI_COMM_WORLD'
104     replace['outcome'] = 'ERROR: CommunicatorMatching'
105     replace['errormsg'] = 'Communicator mistmatch in collectives. @{c}@ at @{filename}@:@{line:MBIERROR}@ has newcom or MPI_COMM_WORLD as a communicator.'
106     replace['change_com'] = 'if (rank % 2)\n    newcom = MPI_COMM_WORLD; /* MBIERROR */'
107     make_file(template, f'ParamMatching_Com_{c}_nok.c', replace)
108
109     # Generate the coll with newcom=MPI_COMM_NULL
110     replace = patterns
111     replace['shortdesc'] = f'Collective @{c}@ with newcom=MPI_COMM_NULL'
112     replace['longdesc'] = f'Collective @{c}@ with newcom=MPI_COMM_NULL'
113     replace['outcome'] = 'ERROR: InvalidCommunicator'
114     replace['errormsg'] = 'Invalid communicator. @{c}@ at @{filename}@:@{line:MBIERROR}@ has MPI_COMM_NULL as a communicator.'
115     replace['change_com'] = 'newcom = MPI_COMM_NULL; /* MBIERROR */'
116     make_file(template, f'InvalidParam_ComNull_{c}_nok.c', replace)