1 /* -*- Mode: C; c-basic-offset:4 ; indent-tabs-mode:nil ; -*- */
3 * (C) 2001 by Argonne National Laboratory.
4 * See COPYRIGHT in top-level directory.
9 #include "mpitestconf.h"
14 static int verbose = 1;
17 MPI_Datatype atype, ptype;
20 MPI_FLOAT, MPI_FLOAT_INT, "MPI_FLOAT_INT"}, {
21 MPI_DOUBLE, MPI_DOUBLE_INT, "MPI_DOUBLE_INT"}, {
22 MPI_LONG, MPI_LONG_INT, "MPI_LONG_INT"}, {
23 MPI_SHORT, MPI_SHORT_INT, "MPI_SHORT_INT"}, {
24 MPI_LONG_DOUBLE, MPI_LONG_DOUBLE_INT, "MPI_LONG_DOUBLE_INT"}, {
25 (MPI_Datatype) - 1, (MPI_Datatype) - 1, "end"}
28 int parse_args(int argc, char **argv);
30 MPI_Aint pairtype_displacement(MPI_Datatype type, int *out_size_p);
32 MPI_Aint pairtype_displacement(MPI_Datatype type, int *out_size_p)
36 /* Note that a portable test may not use a switch statement for
37 * datatypes, as they are not required to be compile-time constants */
38 if (type == MPI_FLOAT_INT) {
43 disp = (MPI_Aint) ((char *) &foo.b - (char *) &foo.a);
44 *out_size_p = sizeof(foo);
46 else if (type == MPI_DOUBLE_INT) {
51 disp = (MPI_Aint) ((char *) &foo.b - (char *) &foo.a);
52 *out_size_p = sizeof(foo);
54 else if (type == MPI_LONG_INT) {
59 disp = (MPI_Aint) ((char *) &foo.b - (char *) &foo.a);
60 *out_size_p = sizeof(foo);
62 else if (type == MPI_SHORT_INT) {
67 disp = (MPI_Aint) ((char *) &foo.b - (char *) &foo.a);
68 *out_size_p = sizeof(foo);
70 else if (type == MPI_LONG_DOUBLE_INT && type != MPI_DATATYPE_NULL) {
75 disp = (MPI_Aint) ((char *) &foo.b - (char *) &foo.a);
76 *out_size_p = sizeof(foo);
84 int main(int argc, char *argv[])
89 int blks[2] = { 1, 1 };
90 MPI_Aint disps[2] = { 0, 0 };
91 MPI_Datatype types[2] = { MPI_INT, MPI_INT };
94 MPI_Init(&argc, &argv);
95 parse_args(argc, argv);
97 for (i = 0; pairtypes[i].atype != (MPI_Datatype) - 1; i++) {
98 int atype_size, ptype_size, stype_size, handbuilt_extent;
99 MPI_Aint ptype_extent, stype_extent, dummy_lb;
101 types[0] = pairtypes[i].atype;
103 /* Check for undefined optional types, such as
104 * LONG_DOUBLE_INT (if, for example, long double or
105 * long long are not supported) */
106 if (types[0] == MPI_DATATYPE_NULL)
109 MPI_Type_size(types[0], &atype_size);
110 disps[1] = pairtype_displacement(pairtypes[i].ptype, &handbuilt_extent);
112 MPI_Type_create_struct(2, blks, disps, types, &stype);
114 MPI_Type_size(stype, &stype_size);
115 MPI_Type_size(pairtypes[i].ptype, &ptype_size);
116 if (stype_size != ptype_size) {
121 "size of %s (%d) does not match size of hand-built MPI struct (%d)\n",
122 pairtypes[i].name, ptype_size, stype_size);
125 MPI_Type_get_extent(stype, &dummy_lb, &stype_extent);
126 MPI_Type_get_extent(pairtypes[i].ptype, &dummy_lb, &ptype_extent);
127 if (stype_extent != ptype_extent || stype_extent != handbuilt_extent) {
132 "extent of %s (%d) does not match extent of either hand-built MPI struct (%d) or equivalent C struct (%d)\n",
133 pairtypes[i].name, (int) ptype_extent,
134 (int) stype_extent, handbuilt_extent);
136 MPI_Type_free(&stype);
140 /* print message and exit */
142 fprintf(stderr, "Found %d errors\n", errs);
145 printf(" No Errors\n");
151 int parse_args(int argc, char **argv)
153 /* We use a simple test because getopt isn't universally available */
154 if (argc > 1 && strcmp(argv[1], "-v") == 0)
156 if (argc > 1 && strcmp(argv[1], "-nov") == 0)