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;
18 int parse_args(int argc, char **argv);
20 MPI_Aint pairtype_displacement(MPI_Datatype type, int *out_size_p);
22 MPI_Aint pairtype_displacement(MPI_Datatype type, int *out_size_p)
26 /* Note that a portable test may not use a switch statement for
27 datatypes, as they are not required to be compile-time constants */
28 if (type == MPI_FLOAT_INT) {
29 struct { float a; int b; } foo;
30 disp = (MPI_Aint) ((char *) &foo.b - (char *) &foo.a);
31 *out_size_p = sizeof(foo);
33 else if (type == MPI_DOUBLE_INT) {
34 struct { double a; int b; } foo;
35 disp = (MPI_Aint) ((char *) &foo.b - (char *) &foo.a);
36 *out_size_p = sizeof(foo);
38 else if (type == MPI_LONG_INT) {
39 struct { long a; int b; } foo;
40 disp = (MPI_Aint) ((char *) &foo.b - (char *) &foo.a);
41 *out_size_p = sizeof(foo);
43 else if (type == MPI_SHORT_INT) {
44 struct { short a; int b; } foo;
45 disp = (MPI_Aint) ((char *) &foo.b - (char *) &foo.a);
46 *out_size_p = sizeof(foo);
48 else if (type == MPI_LONG_DOUBLE_INT && type != MPI_DATATYPE_NULL) {
49 struct { long double a; int b; } foo;
50 disp = (MPI_Aint) ((char *) &foo.b - (char *) &foo.a);
51 *out_size_p = sizeof(foo);
59 int main(int argc, char *argv[])
62 struct { MPI_Datatype atype, ptype; char name[32]; }
64 { {MPI_FLOAT, MPI_FLOAT_INT, "MPI_FLOAT_INT"},
65 {MPI_DOUBLE, MPI_DOUBLE_INT, "MPI_DOUBLE_INT"},
66 {MPI_LONG, MPI_LONG_INT, "MPI_LONG_INT"},
67 {MPI_SHORT, MPI_SHORT_INT, "MPI_SHORT_INT"},
68 {MPI_LONG_DOUBLE, MPI_LONG_DOUBLE_INT, "MPI_LONG_DOUBLE_INT"},
69 {(MPI_Datatype) -1, (MPI_Datatype) -1, "end"}
75 MPI_Aint disps[2] = {0, 0};
76 MPI_Datatype types[2] = {MPI_INT, MPI_INT};
79 MPI_Init(&argc, &argv);
80 parse_args(argc, argv);
82 for (i=0; pairtypes[i].atype != (MPI_Datatype) -1; i++) {
83 int atype_size, ptype_size, stype_size, handbuilt_extent=0;
84 MPI_Aint ptype_extent, stype_extent, dummy_lb;
86 types[0] = pairtypes[i].atype;
88 /* Check for undefined optional types, such as
89 LONG_DOUBLE_INT (if, for example, long double or
90 long long are not supported) */
91 if (types[0] == MPI_DATATYPE_NULL) continue;
93 MPI_Type_size(types[0], &atype_size);
94 disps[1] = pairtype_displacement(pairtypes[i].ptype,
97 MPI_Type_create_struct(2, blks, disps, types, &stype);
99 MPI_Type_size(stype, &stype_size);
100 MPI_Type_size(pairtypes[i].ptype, &ptype_size);
101 if (stype_size != ptype_size) {
104 if (verbose) fprintf(stderr,
105 "size of %s (%d) does not match size of hand-built MPI struct (%d)\n",
106 pairtypes[i].name, ptype_size, stype_size);
109 MPI_Type_get_extent(stype, &dummy_lb, &stype_extent);
110 MPI_Type_get_extent(pairtypes[i].ptype, &dummy_lb, &ptype_extent);
111 if (stype_extent != ptype_extent || stype_extent != handbuilt_extent) {
114 if (verbose) fprintf(stderr,
115 "extent of %s (%d) does not match extent of either hand-built MPI struct (%d) or equivalent C struct (%d)\n",
116 pairtypes[i].name, (int) stype_extent,
120 MPI_Type_free( &stype );
124 /* print message and exit */
126 fprintf(stderr, "Found %d errors\n", errs);
129 printf(" No Errors\n");
135 int parse_args(int argc, char **argv)
137 /* We use a simple test because getopt isn't universally available */
138 if (argc > 1 && strcmp(argv[1], "-v") == 0)
140 if (argc > 1 && strcmp(argv[1], "-nov") == 0)