Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Merge branch 'add_barrier_python_bindings' into 'master'
[simgrid.git] / teshsuite / smpi / MBI / CollMatchingGenerator.py
1 #! /usr/bin/python3
2
3 # Copyright 2021-2022. The MBI project. All rights reserved.
4 # This program is free software; you can redistribute it and/or modify it under the terms of the license (GNU GPL).
5
6 import sys
7 from generator_utils import *
8
9 template = """// @{generatedby}@
10 /* ///////////////////////// The MPI Bugs Initiative ////////////////////////
11
12   Origin: MBI
13
14   Description: @{shortdesc}@
15     @{longdesc}@
16
17          Version of MPI: Conforms to MPI 1.1, does not require MPI 2 implementation
18
19 BEGIN_MPI_FEATURES
20         P2P!basic: Lacking
21         P2P!nonblocking: Lacking
22         P2P!persistent: Lacking
23         COLL!basic: @{collfeature}@
24         COLL!nonblocking: @{icollfeature}@
25         COLL!persistent: Lacking
26         COLL!tools: Lacking
27         RMA: Lacking
28 END_MPI_FEATURES
29
30 BEGIN_MBI_TESTS
31   $ mpirun -np 2 ${EXE}
32   | @{outcome}@
33   | @{errormsg}@
34 END_MBI_TESTS
35 //////////////////////       End of MBI headers        /////////////////// */
36
37 #include <mpi.h>
38 #include <stdio.h>
39 #include <stdlib.h>
40
41 #define buff_size 128
42
43 int main(int argc, char **argv) {
44   int nprocs = -1;
45   int rank = -1;
46         int root = 0;
47
48   MPI_Init(&argc, &argv);
49   MPI_Comm_size(MPI_COMM_WORLD, &nprocs);
50   MPI_Comm_rank(MPI_COMM_WORLD, &rank);
51   printf("Hello from rank %d \\n", rank);
52
53   if (nprocs < 2)
54     printf("MBI ERROR: This test needs at least 2 processes to produce a bug.\\n");
55
56         MPI_Comm newcom = MPI_COMM_WORLD;
57         MPI_Datatype type = MPI_INT;
58   MPI_Op op = MPI_SUM;
59
60   int dbs = sizeof(int)*nprocs; /* Size of the dynamic buffers for alltoall and friends */
61   @{init1}@
62   @{init2}@
63
64   if (@{change_cond}@) {
65     @{operation1a}@ /* MBIERROR1 */
66         @{fini1a}@
67     @{operation2a}@
68         @{fini2a}@
69   } else {
70     @{operation1b}@ /* MBIERROR2 */
71         @{fini1b}@
72     @{operation2b}@
73         @{fini2b}@
74   }
75
76   @{free1}@
77   @{free2}@
78   
79   MPI_Finalize();
80   printf("Rank %d finished normally\\n", rank);
81   return 0;
82 }
83 """
84
85 for c1 in coll + icoll + ibarrier:
86     for c2 in coll + icoll + ibarrier:
87         patterns = {}
88         patterns = {'c1': c1, 'c2': c2}
89         patterns['generatedby'] = f'DO NOT EDIT: this file was generated by {sys.argv[0]}. DO NOT EDIT.'
90         patterns['collfeature'] = 'Yes' if c1 in coll or c2 in coll else 'Lacking'
91         patterns['icollfeature'] = 'Yes' if c1 in icoll + ibarrier or c2 in icoll + ibarrier else 'Lacking'
92         patterns['c1'] = c1
93         patterns['c2'] = c2
94         patterns['init1'] = init[c1]("1")
95         patterns['init2'] = init[c2]("2")
96         patterns['fini1a'] = fini[c1]("1")
97         patterns['fini2a'] = fini[c2]("2")
98         patterns['fini1b'] = fini[c1]("1")
99         patterns['fini2b'] = fini[c2]("2")
100         patterns['free1'] = free[c1]("1")
101         patterns['free2'] = free[c2]("2")
102         patterns['operation1a'] = operation[c1]("1")
103         patterns['operation1b'] = operation[c1]("1")
104         patterns['operation2a'] = operation[c2]("2")
105         patterns['operation2b'] = operation[c2]("2")
106         patterns['change_cond'] = 'rank % 2'
107
108         if c1 == c2:
109             # Generate the correct code using the same collective twice
110             replace = patterns
111             replace['shortdesc'] = 'Correct collective ordering'
112             replace['longdesc'] = f'All ranks call {c1} twice'
113             replace['outcome'] = 'OK'
114             replace['errormsg'] = ''
115             make_file(template, f'CallOrdering_{c1}_{c2}_ok.c', replace)
116             # Generate the correct code using the collective once
117             replace = patterns
118             replace['shortdesc'] = 'Correct collective ordering'
119             replace['longdesc'] = f'All ranks call {c1} once'
120             replace['outcome'] = 'OK'
121             replace['errormsg'] = ''
122             replace['init2'] = ''
123             replace['operation2a'] = ''
124             replace['operation2b'] = ''
125             replace['fini2a'] = ''
126             replace['fini2b'] = ''
127             replace['free2'] = ''
128             make_file(template, f'CallOrdering_{c1}_ok.c', replace)
129         else:
130             # Generate the correct ordering with two different collectives
131             replace = patterns
132             replace['shortdesc'] = 'Correct collective ordering'
133             replace['longdesc'] = f'All ranks call {c1} and then {c2}'
134             replace['outcome'] = 'OK'
135             replace['errormsg'] = ''
136             make_file(template, f'CallOrdering_{c1}_{c2}_ok.c', replace)
137             # Generate the incorrect ordering with two different collectives
138             replace = patterns
139             replace['shortdesc'] = 'Incorrect collective ordering'
140             replace['longdesc'] = f'Odd ranks call {c1} and then {c2} while even ranks call these collectives in the other order'
141             replace['outcome'] = 'ERROR: CallMatching'
142             replace['errormsg'] = 'Collective mistmatch. @{c1}@ at @{filename}@:@{line:MBIERROR1}@ is matched with @{c2}@ line @{filename}@:@{line:MBIERROR2}@.'
143             replace['operation1b'] = operation[c2]("2")  # Inversion
144             replace['operation2b'] = operation[c1]("1")
145             replace['fini1a'] = fini[c1]("1") # Inversion
146             replace['fini2a'] = fini[c2]("2")
147             replace['fini1b'] = fini[c2]("2") # Inversion
148             replace['fini2b'] = fini[c1]("1")
149             replace['free1'] = free[c2]("2") 
150             replace['free2'] = free[c1]("1")
151
152             make_file(template, f'CallOrdering_{c1}_{c2}_nok.c', replace)
153
154     # Generate the incorrect ordering with one collective
155     replace = patterns
156     replace['shortdesc'] = 'Incorrect collective ordering'
157     replace['longdesc'] = f'Odd ranks call {c1} while even ranks do not call any collective'
158     replace['outcome'] = 'ERROR: CallMatching'
159     replace['errormsg'] = 'Collective mistmatch. @{c1}@ at @{filename}@:@{line:MBIERROR1}@ is not matched.'
160     replace['operation1b'] = ''  # Remove functions
161     replace['operation2b'] = ''
162     replace['operation2a'] = ''
163     replace['fini1b'] = ''
164     replace['fini2a'] = ''
165     replace['fini2b'] = ''
166     make_file(template, f'CallOrdering_{c1}_none_nok.c', replace)
167     # Generate a correct ordering with a conditional not depending on ranks
168     replace = patterns
169     replace['shortdesc'] = 'Correct collective ordering'
170     replace['longdesc'] = f'All ranks call {c1} and then {c2} or inversely'
171     replace['outcome'] = 'OK'
172     replace['errormsg'] = ''
173     replace['change_cond'] = 'nprocs<256'
174     replace['operation2b'] = '' # Remove functions
175     replace['operation2a'] = ''
176     replace['fini2b'] = ''
177     replace['free2a'] = ''
178     make_file(template, f'CallOrdering_{c1}_none_ok.c', replace)