Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
first commit to add the mpich-test suite to smpi tesh suite. Obviously all tests...
[simgrid.git] / teshsuite / smpi / mpich-test / pt2pt / hvectest.c
1 /*
2     hvectest - test program that sends an array of floats from the first 
3              process of a group to the last, using send and recv and the
4              vector datatype.
5 */
6
7 #include <stdio.h>
8 #include "mpi.h"
9 #include "test.h"
10 /* #define SHOWMSG */
11
12 #ifdef VERBOSE
13 static int verbose = 1;
14 #else
15 static int verbose = 0;
16 #endif
17 int main( int argc, char **argv )
18 {
19     int rank, size, to, from, tag, count, i;
20     int src, dest;
21     int st_source, st_tag, st_count;
22     int errcnt = 0;
23     MPI_Request handle;
24     MPI_Status status;
25     double data[100];
26     MPI_Datatype rowtype;
27
28     MPI_Init( &argc, &argv );
29     MPI_Comm_rank( MPI_COMM_WORLD, &rank );
30     MPI_Comm_size( MPI_COMM_WORLD, &size );
31
32     src  = size - 1;
33     dest = 0;
34 /*
35     dest  = size - 1;
36     src = 0;
37  */
38     MPI_Type_vector( 10, 1, 10, MPI_DOUBLE, &rowtype );
39     MPI_Type_commit( &rowtype );
40     /* First test: send a row */
41     if (rank == src) {
42         to     = dest;
43         count  = 1;
44         tag    = 2001;
45         for (i = 0; i < 100; i++)
46             data[i] = i;
47         /* Send a row */
48         MPI_Send( data, count, rowtype, to, tag, MPI_COMM_WORLD );
49 #ifdef SHOWMSG
50         printf("%d sent", rank );
51         for (i = 0; i < 10; i++) printf(" %f",data[i*10]);printf("\n");
52 #endif
53     }
54
55     if (rank == dest) {
56         tag   = MPI_ANY_TAG;
57         count = 10;             
58         from  = MPI_ANY_SOURCE;
59         MPI_Recv(data, count, MPI_DOUBLE, from, tag, MPI_COMM_WORLD,
60                  &status ); 
61
62         st_source = status.MPI_SOURCE;
63         st_tag    = status.MPI_TAG;
64         MPI_Get_count( &status, MPI_DOUBLE, &st_count );
65
66         if (st_source != src || st_tag != 2001 || st_count != 10 || verbose) {
67             printf( "Status info: source = %d, tag = %d, count = %d\n",
68                     st_source, st_tag, st_count );
69         }
70 #ifdef SHOWMSG
71         printf( "%d received", rank);
72         for (i = 0; i < 10; i++) printf(" %f",data[i]); printf("\n");
73 #endif
74         for (i = 0; i < 10; i++) if (data[i] != 10*i) { 
75             errcnt++;
76             fprintf( stderr, 
77                     "[%d](rcv double) %d'th element = %f, should be %f\n",
78                      rank, i, data[i], 10.0*i );
79             }
80     }
81
82     /* Second test: receive a column into row */
83     if (rank == src)
84     {
85         to     = dest;
86         count  = 10;
87         tag    = 2001;
88         for (i = 0; i < 100; i++)
89             data[i] = i;
90         /* Send a row */
91         MPI_Send( data, count, MPI_DOUBLE, to, tag, MPI_COMM_WORLD );
92 #ifdef SHOWMSG
93         printf("%d sent", rank );
94         for (i = 0; i < 10; i++) printf(" %f",data[i]);printf("\n");
95 #endif
96     }
97     if (rank == dest)
98     {
99         tag   = MPI_ANY_TAG;
100         count = 1;              
101         from  = MPI_ANY_SOURCE;
102         MPI_Recv(data, count, rowtype, from, tag, MPI_COMM_WORLD,
103                  &status ); 
104
105         st_source = status.MPI_SOURCE;
106         st_tag    = status.MPI_TAG;
107         MPI_Get_count( &status, MPI_DOUBLE, &st_count );
108
109         if (st_source != src || st_tag != 2001 || st_count != 10 || verbose) {
110             printf( "Status info: source = %d, tag = %d, count = %d\n",
111                 st_source, st_tag, st_count );
112         }
113 #ifdef SHOWMSG
114         printf( "%d received", rank);
115         for (i = 0; i < 10; i++) printf(" %f",data[i*10]);printf("\n");
116 #endif
117         for (i = 0; i < 10; i++) if (data[i*10] != i) {
118             errcnt++;
119             fprintf( stderr, 
120                     "[%d](rcv row) %d'th element = %f, should be %f\n",
121                      rank, i, data[i*10], 1.0*i );
122             }
123     }
124
125     /* Third test: send AND receive a row */
126     if (rank == src)
127     {
128         to     = dest;
129         count  = 1;
130         tag    = 2001;
131         for (i = 0; i < 100; i++)
132             data[i] = i;
133         /* Send a row */
134         MPI_Send( data, count, rowtype, to, tag, MPI_COMM_WORLD );
135 #ifdef SHOWMSG
136         printf("%d sent", rank );
137         for (i = 0; i < 10; i++) printf(" %f",data[i*10]);printf("\n");
138 #endif
139     }
140     if (rank == dest)
141     {
142         tag   = MPI_ANY_TAG;
143         count = 1;              
144         from  = MPI_ANY_SOURCE;
145         MPI_Recv(data, count, rowtype, from, tag, MPI_COMM_WORLD,
146                  &status ); 
147
148         st_source = status.MPI_SOURCE;
149         st_tag    = status.MPI_TAG;
150         MPI_Get_count( &status, MPI_DOUBLE, &st_count );
151
152         if (st_source != src || st_tag != 2001 || st_count != 10 || verbose) {
153             printf( "Status info: source = %d, tag = %d, count = %d\n",
154                     st_source, st_tag, st_count );
155         }
156 #ifdef SHOWMSG
157         printf( "%d received", rank);
158         for (i = 0; i < 10; i++) printf(" %f",data[i*10]);printf("\n");
159 #endif
160         for (i = 0; i < 10; i++) if (data[i*10] != i*10) {
161             errcnt++;
162             fprintf( stderr, 
163                     "[%d](rcv row-row) %d'th element = %f, should be %f\n",
164                      rank, i, data[i*10], 10.0*i );
165             }
166     }
167
168     /* Second Set of Tests: Use Isend and Irecv instead of Send and Recv */
169     /* First test: send a row */
170     if (rank == src)
171     {
172         to     = dest;
173         count  = 1;
174         tag    = 2001;
175         for (i = 0; i < 100; i++)
176             data[i] = i;
177         /* Send a row */
178         MPI_Isend( data, count, rowtype, to, tag, MPI_COMM_WORLD, &handle );
179         MPI_Wait( &handle, &status );
180 #ifdef SHOWMSG
181         printf("%d sent", rank );
182         for (i = 0; i < 10; i++) printf(" %f",data[i*10]);printf("\n");
183 #endif
184     }
185
186     if (rank == dest)
187     {
188         tag   = MPI_ANY_TAG;
189         count = 10;             
190         from  = MPI_ANY_SOURCE;
191         MPI_Irecv(data, count, MPI_DOUBLE, from, tag, MPI_COMM_WORLD,
192                  &handle ); 
193         MPI_Wait( &handle, &status );
194
195         st_source = status.MPI_SOURCE;
196         st_tag    = status.MPI_TAG;
197         MPI_Get_count( &status, MPI_DOUBLE, &st_count );
198
199         if (st_source != src || st_tag != 2001 || st_count != 10 || verbose) {
200             printf( "Status info: source = %d, tag = %d, count = %d\n",
201                     st_source, st_tag, st_count );
202         }
203 #ifdef SHOWMSG
204         printf( "%d received", rank);
205         for (i = 0; i < 10; i++) printf(" %f",data[i]); printf("\n");
206 #endif
207         for (i = 0; i < 10; i++) if (data[i] != 10*i) {
208             errcnt++;
209             fprintf( stderr, 
210                     "[%d](ircv double) %d'th element = %f, should be %f\n",
211                      rank, i, data[i], 10.0*i );
212             }
213     }
214
215     /* Second test: receive a column into row */
216     if (rank == src)
217     {
218         to     = dest;
219         count  = 10;
220         tag    = 2001;
221         for (i = 0; i < 100; i++)
222             data[i] = i;
223         /* Send a row */
224         MPI_Isend( data, count, MPI_DOUBLE, to, tag, MPI_COMM_WORLD, 
225                    &handle );
226         MPI_Wait( &handle, &status );
227 #ifdef SHOWMSG
228         printf("%d sent", rank );
229         for (i = 0; i < 10; i++) printf(" %f",data[i]);printf("\n");
230 #endif
231     }
232     if (rank == dest)
233     {
234         tag   = MPI_ANY_TAG;
235         count = 1;              
236         from  = MPI_ANY_SOURCE;
237         MPI_Irecv(data, count, rowtype, from, tag, MPI_COMM_WORLD,
238                  &handle ); 
239         MPI_Wait( &handle, &status );
240
241         st_source = status.MPI_SOURCE;
242         st_tag    = status.MPI_TAG;
243         MPI_Get_count( &status, MPI_DOUBLE, &st_count );
244
245         if (st_source != src || st_tag != 2001 || st_count != 10 || verbose) {
246             printf( "Status info: source = %d, tag = %d, count = %d\n",
247                     st_source, st_tag, st_count );
248         }
249 #ifdef SHOWMSG
250         printf( "%d received", rank);
251         for (i = 0; i < 10; i++) printf(" %f",data[i*10]);printf("\n");
252 #endif
253         for (i = 0; i < 10; i++) if (data[i*10] != i) {
254             errcnt++;
255             fprintf( stderr, 
256                     "[%d](ircv row) %d'th element = %f, should be %f\n",
257                      rank, i, data[i*10], 1.0*i );
258             }
259     }
260
261     /* Third test: send AND receive a row */
262     if (rank == src)
263     {
264         to     = dest;
265         count  = 1;
266         tag    = 2001;
267         for (i = 0; i < 100; i++)
268             data[i] = i;
269         /* Send a row */
270         MPI_Isend( data, count, rowtype, to, tag, MPI_COMM_WORLD, &handle );
271         MPI_Wait( &handle, &status );
272 #ifdef SHOWMSG
273         printf("%d sent", rank );
274         for (i = 0; i < 10; i++) printf(" %f",data[i*10]);printf("\n");
275 #endif
276     }
277     if (rank == dest)
278     {
279         tag   = MPI_ANY_TAG;
280         count = 1;              
281         from  = MPI_ANY_SOURCE;
282         MPI_Irecv(data, count, rowtype, from, tag, MPI_COMM_WORLD,
283                  &handle ); 
284         MPI_Wait( &handle, &status );
285
286         st_source = status.MPI_SOURCE;
287         st_tag    = status.MPI_TAG;
288         MPI_Get_count( &status, MPI_DOUBLE, &st_count );
289
290         if (st_source != src || st_tag != 2001 || st_count != 10 || verbose) {
291             printf( "Status info: source = %d, tag = %d, count = %d\n",
292                     st_source, st_tag, st_count );
293         }
294 #ifdef SHOWMSG
295         printf( "%d received", rank);
296         for (i = 0; i < 10; i++) printf(" %f",data[i*10]);printf("\n");
297 #endif
298         for (i = 0; i < 10; i++) if (data[i*10] != i*10) {
299             errcnt++;
300             fprintf( stderr, 
301                     "[%d](ircv row-row) %d'th element = %f, should be %f\n",
302                      rank, i, data[i*10], 10.0*i );
303             }
304     }
305
306     i = errcnt;
307     MPI_Allreduce( &i, &errcnt, 1, MPI_INT, MPI_SUM, MPI_COMM_WORLD );
308     if (errcnt > 0) {
309         printf( "Found %d errors in the run \n", errcnt );
310         }
311     MPI_Type_free( &rowtype );
312     Test_Waitforall( );
313     MPI_Finalize();
314     return 0;
315 }