Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
4bafe00e1ad9e2d84d8bb56c7362a34b2da94a73
[simgrid.git] / teshsuite / smpi / MBI / CollTopoGenerator.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: Lacking
21   COLL!nonblocking: Lacking
22   COLL!persistent: Lacking
23   COLL!tools: @{toolfeature}@
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
44   MPI_Init(&argc, &argv);
45   MPI_Comm_size(MPI_COMM_WORLD, &nprocs);
46   MPI_Comm_rank(MPI_COMM_WORLD, &rank);
47   printf("Hello from rank %d \\n", rank);
48
49   if (nprocs < 2)
50     printf("MBI ERROR: This test needs at least 2 processes to produce a bug!\\n");
51
52    MPI_Comm newcom;
53    int dims[2], periods[2], coords[2];
54    int source, dest;
55    dims[0] = 2;
56    dims[1] = 1;
57    periods[0] = 1;
58    periods[1] = 1;
59
60    @{change_dims}@
61
62    MPI_Cart_create(MPI_COMM_WORLD, 2, dims, periods, 0, &newcom); /* create a cartesian communicator */
63
64    @{change_com}@
65
66    @{init}@
67    @{operation}@ /* MBIERROR2 */
68    @{fini}@
69
70    if (newcom != MPI_COMM_NULL)
71      MPI_Comm_free(&newcom);
72
73   MPI_Finalize();
74   printf("Rank %d finished normally\\n", rank);
75   return 0;
76 }
77 """
78
79 for c in tcoll4topo:
80     patterns = {}
81     patterns = {'c': c}
82     patterns['generatedby'] = f'DO NOT EDIT: this file was generated by {os.path.basename(sys.argv[0])}. DO NOT EDIT.'
83     patterns['toolfeature'] = 'Yes' if c in tcoll4topo else 'Lacking'
84     patterns['c'] = c
85     patterns['init'] = init[c]("1")
86     patterns['fini'] = fini[c]("1")
87     patterns['operation'] = operation[c]("1")
88
89     # Generate the correct code
90     replace = patterns
91     replace['shortdesc'] = 'Function @{c}@ with correct arguments'
92     replace['longdesc'] = f'All ranks in comm call {c} with correct arguments'
93     replace['outcome'] = 'OK'
94     replace['errormsg'] = ''
95     replace['change_com'] = '/* No error injected here */'
96     replace['change_dims'] = '/* No error injected here */'
97     make_file(template, f'InvalidParam_{c}_ok.c', replace)
98
99     # Generate the incorrect code
100     replace = patterns
101     replace['shortdesc'] = 'The code tries to get cartesian information of MPI_COMM_WORLD.'
102     replace['longdesc'] = 'The code creates a cartesian communicator, and tries to get cartesian information of MPI_COMM_WORLD.'
103     replace['outcome'] = 'ERROR: InvalidCommunicator'
104     replace['errormsg'] = 'Invalid Communicator in a collective. @{c}@ at @{filename}@:@{line:MBIERROR2}@ tries to get cartesian information of MPI_COMM_WORLD.'
105     replace['change_com'] = 'newcom = MPI_COMM_WORLD; /* MBIERROR1 */'
106     make_file(template, f'InvalidParam_Com_{c}_nok.c', replace)
107
108     # Generate the code with newcom=MPI_COMM_NULL
109     replace = patterns
110     replace['shortdesc'] = 'Function @{c}@ called with comm=MPI_COMM_NULL'
111     replace['longdesc'] = 'Function @{c}@ called with comm=MPI_COMM_NULL'
112     replace['outcome'] = 'ERROR: InvalidCommunicator'
113     replace['errormsg'] = 'Invalid communicator. @{c}@ at @{filename}@:@{line:MBIERROR2}@ has MPI_COMM_NULL as a communicator.'
114     replace['change_com'] = 'newcom = MPI_COMM_NULL; /* MBIERROR1 */'
115     make_file(template, f'InvalidParam_ComNull_{c}_nok.c', replace)
116
117     # Generate the code with invalid dimension
118     replace = patterns
119     replace['shortdesc'] = 'Creates a cartesian communicator with a negative entry in the dims attribute'
120     replace['longdesc'] = 'Creates a cartesian communicator with a negative entry in the dims attribute, which is a usage error'
121     replace['outcome'] = 'ERROR: InvalidOtherArg'
122     replace['errormsg'] = 'Invalid Argument. MPI_Cart_create has invalid dimensions.'
123     replace['change_com'] = ""
124     replace['change_dims'] = 'dims[0] = -2; dims[1] = -1; /* MBIERROR1 */'
125     make_file(template, f'InvalidParam_Dim_MPI_Cart_create_nok.c', replace)