Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
remove few tests which may never finish, and change one that used too much stack...
[simgrid.git] / teshsuite / smpi / mpich-test / pt2pt / sendrecv2.c
1 #include "mpi.h"
2 #include <stdio.h>
3 #include "dtypes.h"
4 #include "gcomm.h"
5 #include "test.h"
6
7 int verbose = 0;
8 /*
9    This program is from mpich/tsuite/pt2pt and should be changed there only.
10    It needs gcomm and dtype from mpich/tsuite, and can be run with 
11    any number of processes > 1.
12  */
13 int main( int argc, char **argv)
14 {
15     MPI_Datatype *types;
16     void         **inbufs, **outbufs;
17     char         **names;
18     int          *counts, *bytesize, ntype;
19     MPI_Comm     comms[20];
20     int          ncomm = 20, rank, np, partner, tag, count;
21     int          i, j, k, err, toterr, world_rank, errloc;
22     MPI_Status   status;
23     char         *obuf;
24
25     MPI_Init( &argc, &argv );
26     
27     /* 
28      * Check for -basiconly to select only the simple datatypes
29      */
30     for (i=1; i<argc; i++) {
31         if (!argv[i]) break;
32         if (strcmp( argv[i], "-basiconly" ) == 0) {
33             BasicDatatypesOnly();
34         }
35         else if (strcmp( argv[i], "-verbose" ) == 0) {
36             verbose = 1;
37         }
38     }
39     
40     AllocateForData( &types, &inbufs, &outbufs, &counts, &bytesize, 
41                      &names, &ntype );
42     GenerateData( types, inbufs, outbufs, counts, bytesize, names, &ntype );
43     
44     MPI_Comm_rank( MPI_COMM_WORLD, &world_rank );
45     MakeComms( comms, 20, &ncomm, 0 );
46     
47  /* Test over a wide range of datatypes and communicators */
48     err = 0;
49     for (i=0; i<ncomm; i++) {
50         if (comms[i] == MPI_COMM_NULL) continue;
51         MPI_Comm_rank( comms[i], &rank );
52         MPI_Comm_size( comms[i], &np );
53         if (np < 2) continue;
54         if (world_rank == 0 && verbose) 
55             fprintf( stdout, "Testing communicator number %d\n", i );
56         
57         tag = i;
58         for (j=0; j<ntype; j++) {
59             if (world_rank == 0 && verbose) 
60                 fprintf( stdout, "Testing type %s\n", names[j] );
61             if (rank == 0) {
62                 partner = np - 1;
63 #if 0
64                 MPIR_PrintDatatypePack( stdout, counts[j], types[j], 0, 0 );
65 #endif
66                 MPI_Send( inbufs[j], counts[j], types[j], partner, tag, comms[i] );
67             }
68             else if (rank == np-1) {
69                 partner = 0;
70                 obuf = outbufs[j];
71                 for (k=0; k<bytesize[j]; k++) 
72                     obuf[k] = 0;
73                 MPI_Recv( outbufs[j], counts[j], types[j], partner, tag, 
74                           comms[i], &status );
75                 /* Test correct */
76                 MPI_Get_count( &status, types[j], &count );
77                 if (count != counts[j]) {
78                     fprintf( stderr, 
79                      "Error in counts (got %d expected %d) with type %s\n",
80                          count, counts[j], names[j] );
81                     err++;
82                 }
83                 if (status.MPI_SOURCE != partner) {
84                     fprintf( stderr, 
85                         "Error in source (got %d expected %d) with type %s\n",
86                          status.MPI_SOURCE, partner, names[j] );
87                     err++;
88                 }
89                 if ((errloc = CheckData( inbufs[j], outbufs[j], bytesize[j] ))) {
90                     char *p1, *p2;
91                     fprintf( stderr, 
92                     "Error in data with type %s (type %d on %d) at byte %d\n", 
93                              names[j], j, world_rank, errloc - 1 );
94                     p1 = (char *)inbufs[j];
95                     p2 = (char *)outbufs[j];
96                     fprintf( stderr, 
97                         "Got %x expected %x\n", p1[errloc-1], p2[errloc-1] );
98                     err++;
99 #if 0
100                     MPIR_PrintDatatypeUnpack( stderr, counts[j], types[j], 
101                                               0, 0 );
102 #endif
103                 }
104             }
105         }
106     }
107     if (err > 0) {
108         fprintf( stderr, "%d errors on %d\n", err, rank );
109     }
110     MPI_Allreduce( &err, &toterr, 1, MPI_INT, MPI_SUM, MPI_COMM_WORLD );
111     if (world_rank == 0) {
112         if (toterr == 0) {
113             printf( " No Errors\n" );
114         }
115         else {
116             printf (" Found %d errors\n", toterr );
117         }
118     }
119     FreeDatatypes( types, inbufs, outbufs, counts, bytesize, names, ntype );
120     FreeComms( comms, ncomm );
121     MPI_Finalize();
122     return err;
123 }