Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Merge branch 'master' into fix/execute_benched
[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])
36             break;
37         if (strcmp(argv[i], "-basiconly") == 0) {
38             MTestDatatype2BasicOnly();
39         }
40     }
41
42     MTestDatatype2Allocate(&types, &inbufs, &outbufs, &counts, &bytesize, &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)
52             continue;
53         MPI_Comm_rank(comm, &rank);
54         MPI_Comm_size(comm, &np);
55         if (np < 2)
56             continue;
57         if (world_rank == 0)
58             MTestPrintfMsg(10, "Testing communicator number %s\n", MTestGetIntracommName());
59
60         tag++;
61         for (j = 0; j < ntype; j++) {
62             MPI_Type_get_name(types[j], myname, &mynamelen);
63             if (world_rank == 0)
64                 MTestPrintfMsg(10, "Testing type %s\n", myname);
65             if (rank == 0) {
66                 partner = np - 1;
67                 MPI_Send(inbufs[j], counts[j], types[j], partner, tag, comm);
68             }
69             else if (rank == np - 1) {
70                 partner = 0;
71                 obuf = outbufs[j];
72                 for (k = 0; k < bytesize[j]; k++)
73                     obuf[k] = 0;
74                 MPI_Recv(outbufs[j], counts[j], types[j], partner, tag, 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], 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                             myname, j, world_rank, errloc - 1);
94                     p1 = (char *) inbufs[j];
95                     p2 = (char *) outbufs[j];
96                     fprintf(stderr, "Got %hhx expected %hhx\n", p1[errloc - 1], p2[errloc - 1]);
97                     err++;
98                 }
99             }
100         }
101         MTestFreeComm(&comm);
102     }
103
104     MTestDatatype2Free(types, inbufs, outbufs, counts, bytesize, ntype);
105     MTest_Finalize(err);
106     MPI_Finalize();
107     return MTestReturnValue(err);
108 }