Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Fix HAVE_FOOBAR flags handling
[simgrid.git] / teshsuite / smpi / mpich3-test / datatype / sendrecvt2.c
1 /* -*- Mode: C; c-basic-offset:4 ; indent-tabs-mode:nil ; -*- */
2 /*
3  *  (C) 2014 by Argonne National Laboratory.
4  *      See COPYRIGHT in top-level directory.
5  */
6 #include "mpi.h"
7 #include "mpitest.h"
8 #include <stdio.h>
9 #include <string.h>
10 #include "dtypes.h"
11
12 /*
13    This program is derived from one in the MPICH-1 test suite.  It
14    tests a wide variety of basic and derived datatypes.
15  */
16 int main( int argc, char **argv)
17 {
18     MPI_Datatype *types;
19     void         **inbufs, **outbufs;
20     int          *counts, *bytesize, ntype;
21     MPI_Comm     comm;
22     int          rank, np, partner, tag, count;
23     int          i, j, k, err, world_rank, errloc;
24     MPI_Status   status;
25     char         *obuf;
26     char         myname[MPI_MAX_OBJECT_NAME];
27     int          mynamelen;
28
29     MTest_Init( &argc, &argv );
30
31     /*
32      * Check for -basiconly to select only the simple datatypes
33      */
34     for (i=1; i<argc; i++) {
35         if (!argv[i]) break;
36         if (strcmp( argv[i], "-basiconly" ) == 0) {
37             MTestDatatype2BasicOnly();
38         }
39     }
40
41     MTestDatatype2Allocate( &types, &inbufs, &outbufs, &counts, &bytesize,
42                             &ntype );
43     MTestDatatype2Generate( types, inbufs, outbufs, counts, bytesize, &ntype );
44
45     MPI_Comm_rank( MPI_COMM_WORLD, &world_rank );
46
47  /* Test over a wide range of datatypes and communicators */
48     err = 0;
49     tag = 0;
50     while (MTestGetIntracomm( &comm, 2 )) {
51         if (comm == MPI_COMM_NULL) continue;
52         MPI_Comm_rank( comm, &rank );
53         MPI_Comm_size( comm, &np );
54         if (np < 2) continue;
55         if (world_rank == 0)
56             MTestPrintfMsg( 10, "Testing communicator number %s\n",
57                             MTestGetIntracommName() );
58
59         tag++;
60         for (j=0; j<ntype; j++) {
61             MPI_Type_get_name( types[j], myname, &mynamelen );
62             if (world_rank == 0)
63                 MTestPrintfMsg( 10, "Testing type %s\n", myname );
64             if (rank == 0) {
65                 partner = np - 1;
66                 MPI_Send( inbufs[j], counts[j], types[j], partner, tag, comm );
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                           comm, &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], myname );
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, myname );
87                     err++;
88                 }
89                 if ((errloc = MTestDatatype2Check( inbufs[j], outbufs[j],
90                                                    bytesize[j] ))) {
91                     char *p1, *p2;
92                     fprintf( stderr,
93                     "Error in data with type %s (type %d on %d) at byte %d\n",
94                              myname, j, world_rank, errloc - 1 );
95                     p1 = (char *)inbufs[j];
96                     p2 = (char *)outbufs[j];
97                     fprintf( stderr,
98                         "Got %x expected %x\n", p1[errloc-1], p2[errloc-1] );
99                     err++;
100                 }
101             }
102         }
103         MTestFreeComm( &comm );
104     }
105
106     MTestDatatype2Free( types, inbufs, outbufs, counts, bytesize, ntype );
107     MTest_Finalize( err );
108     MPI_Finalize();
109     return MTestReturnValue( err );
110 }