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.
7 /* Tests that Type_get_extent of a couple of basic types succeeds. */
11 #include "mpitestconf.h"
16 static int verbose = 0;
18 int parse_args(int argc, char **argv);
20 int main(int argc, char **argv)
22 int mpi_err, errs = 0, size;
23 MPI_Aint lb, ub, extent;
26 struct { float a; int b; } foo;
28 MPI_Init(&argc, &argv);
29 parse_args(argc, argv);
31 /* To improve reporting of problems about operations, we
32 change the error handler to errors return */
33 MPI_Comm_set_errhandler( MPI_COMM_WORLD, MPI_ERRORS_RETURN );
36 mpi_err = MPI_Type_size(type, &size);
37 if (mpi_err != MPI_SUCCESS) {
39 fprintf(stderr, "MPI_Type_size of MPI_INT failed.\n");
43 if (size != sizeof(int)) {
45 fprintf(stderr, "MPI_Type_size of MPI_INT incorrect size (%d); should be %d.\n",
46 size, (int) sizeof(int));
51 mpi_err = MPI_Type_get_extent(type, &lb, &extent);
52 if (mpi_err != MPI_SUCCESS) {
54 fprintf(stderr, "MPI_Type_get_extent of MPI_INT failed.\n");
58 if (extent != sizeof(int)) {
60 fprintf(stderr, "MPI_Type_get_extent of MPI_INT returned incorrect extent (%d); should be %d.\n",
61 (int) extent, (int) sizeof(int));
67 fprintf(stderr, "MPI_Type_get_extent of MPI_INT returned incorrect lb (%d); should be 0.\n",
72 mpi_err = MPI_Type_ub(type, &ub);
73 if (mpi_err != MPI_SUCCESS) {
75 fprintf(stderr, "MPI_Type_ub of MPI_INT failed.\n");
79 if (ub != extent - lb) {
81 fprintf(stderr, "MPI_Type_ub of MPI_INT returned incorrect ub (%d); should be %d.\n",
82 (int) ub, (int) (extent - lb));
88 mpi_err = MPI_Type_size(type, &size);
89 if (mpi_err != MPI_SUCCESS) {
91 fprintf(stderr, "MPI_Type_size of MPI_FLOAT_INT failed.\n");
95 if (size != sizeof(float) + sizeof(int)) {
97 fprintf(stderr, "MPI_Type_size of MPI_FLOAT_INT returned incorrect size (%d); should be %d.\n",
98 size, (int) (sizeof(float) + sizeof(int)));
103 mpi_err = MPI_Type_get_extent(type, &lb, &extent);
104 if (mpi_err != MPI_SUCCESS) {
106 fprintf(stderr, "MPI_Type_get_extent of MPI_FLOAT_INT failed.\n");
110 if (extent != sizeof(foo)) {
112 fprintf(stderr, "MPI_Type_get_extent of MPI_FLOAT_INT returned incorrect extent (%d); should be %d.\n",
113 (int) extent, (int) sizeof(foo));
119 fprintf(stderr, "MPI_Type_get_extent of MPI_FLOAT_INT returned incorrect lb (%d); should be 0.\n",
124 mpi_err = MPI_Type_ub(type, &ub);
125 if (mpi_err != MPI_SUCCESS) {
127 fprintf(stderr, "MPI_Type_ub of MPI_FLOAT_INT failed.\n");
131 if (ub != extent - lb) {
133 fprintf(stderr, "MPI_Type_ub of MPI_FLOAT_INT returned incorrect ub (%d); should be %d.\n",
134 (int) ub, (int) (extent - lb));
139 /* print message and exit */
141 fprintf(stderr, "Found %d errors\n", errs);
144 printf(" No Errors\n");
150 int parse_args(int argc, char **argv)
155 while ((ret = getopt(argc, argv, "v")) >= 0)
164 if (argc > 1 && strcmp(argv[1], "-v") == 0)