1 /* -*- Mode: C; c-basic-offset:4 ; indent-tabs-mode:nil ; -*- */
3 * (C) 2014 by Argonne National Laboratory.
4 * See COPYRIGHT in top-level directory.
13 This program is derived from one in the MPICH-1 test suite. It
14 tests a wide variety of basic and derived datatypes.
16 int main(int argc, char **argv)
19 void **inbufs, **outbufs;
20 int *counts, *bytesize, ntype;
22 int rank, np, partner, tag, count;
23 int i, j, k, err, world_rank, errloc;
26 char myname[MPI_MAX_OBJECT_NAME];
29 MTest_Init(&argc, &argv);
32 * Check for -basiconly to select only the simple datatypes
34 for (i = 1; i < argc; i++) {
37 if (strcmp(argv[i], "-basiconly") == 0) {
38 MTestDatatype2BasicOnly();
42 MTestDatatype2Allocate(&types, &inbufs, &outbufs, &counts, &bytesize, &ntype);
43 MTestDatatype2Generate(types, inbufs, outbufs, counts, bytesize, &ntype);
45 MPI_Comm_rank(MPI_COMM_WORLD, &world_rank);
47 /* Test over a wide range of datatypes and communicators */
50 while (MTestGetIntracomm(&comm, 2)) {
51 if (comm == MPI_COMM_NULL)
53 MPI_Comm_rank(comm, &rank);
54 MPI_Comm_size(comm, &np);
58 MTestPrintfMsg(10, "Testing communicator number %s\n", MTestGetIntracommName());
61 for (j = 0; j < ntype; j++) {
62 MPI_Type_get_name(types[j], myname, &mynamelen);
64 MTestPrintfMsg(10, "Testing type %s\n", myname);
67 MPI_Send(inbufs[j], counts[j], types[j], partner, tag, comm);
69 else if (rank == np - 1) {
72 for (k = 0; k < bytesize[j]; k++)
74 MPI_Recv(outbufs[j], counts[j], types[j], partner, tag, comm, &status);
76 MPI_Get_count(&status, types[j], &count);
77 if (count != counts[j]) {
79 "Error in counts (got %d expected %d) with type %s\n",
80 count, counts[j], myname);
83 if (status.MPI_SOURCE != partner) {
85 "Error in source (got %d expected %d) with type %s\n",
86 status.MPI_SOURCE, partner, myname);
89 if ((errloc = MTestDatatype2Check(inbufs[j], outbufs[j], bytesize[j]))) {
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]);
101 MTestFreeComm(&comm);
104 MTestDatatype2Free(types, inbufs, outbufs, counts, bytesize, ntype);
107 return MTestReturnValue(err);