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 = 0;
17 int builtin_float_test(void);
18 int vector_of_vectors_test(void);
19 int optimizable_vector_of_basics_test(void);
21 /* helper functions */
22 int parse_args(int argc, char **argv);
24 int main(int argc, char **argv)
28 MPI_Init(&argc, &argv); /* MPI-1.2 doesn't allow for MPI_Init(0,0) */
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);
35 /* perform some tests */
36 err = builtin_float_test();
38 fprintf(stderr, "%d errors in builtin float test.\n", err);
41 err = vector_of_vectors_test();
43 fprintf(stderr, "%d errors in vector of vectors test.\n", err);
46 err = optimizable_vector_of_basics_test();
48 fprintf(stderr, "%d errors in vector of basics test.\n", err);
51 /* print message and exit */
53 fprintf(stderr, "Found %d errors\n", errs);
56 printf(" No Errors\n");
62 /* builtin_float_test()
64 * Tests functionality of get_envelope() and get_contents() on a MPI_FLOAT.
66 * Returns the number of errors encountered.
68 int builtin_float_test(void)
70 int nints, nadds, ntypes, combiner;
74 MPI_Type_get_envelope(MPI_FLOAT, &nints, &nadds, &ntypes, &combiner);
76 if (combiner != MPI_COMBINER_NAMED)
79 /* Note: it is erroneous to call MPI_Type_get_contents() on a basic. */
83 /* vector_of_vectors_test()
85 * Builds a vector of a vector of ints. Assuming an int array of size 9
86 * integers, and treating the array as a 3x3 2D array, this will grab the
89 * Returns the number of errors encountered.
91 int vector_of_vectors_test(void)
93 MPI_Datatype inner_vector;
94 MPI_Datatype outer_vector;
95 int array[9] = { 1, -1, 2,
101 int i, err, errs = 0, sizeoftype, position;
104 err = MPI_Type_vector(2, 1, 2, MPI_INT, &inner_vector);
105 if (err != MPI_SUCCESS) {
108 fprintf(stderr, "error in MPI call; aborting after %d errors\n", errs + 1);
112 err = MPI_Type_vector(2, 1, 2, inner_vector, &outer_vector);
113 if (err != MPI_SUCCESS) {
116 fprintf(stderr, "error in MPI call; aborting after %d errors\n", errs + 1);
120 MPI_Type_commit(&outer_vector);
121 MPI_Type_size(outer_vector, &sizeoftype);
122 if (sizeoftype != 4 * sizeof(int)) {
125 fprintf(stderr, "size of type = %d; should be %d\n",
126 (int) sizeoftype, (int) (4 * sizeof(int)));
130 buf = (char *) malloc(sizeoftype);
133 err = MPI_Pack(array, 1, outer_vector, buf, sizeoftype, &position, MPI_COMM_WORLD);
135 if (position != sizeoftype) {
138 fprintf(stderr, "position = %d; should be %d (pack)\n", position, sizeoftype);
141 memset(array, 0, 9 * sizeof(int));
143 err = MPI_Unpack(buf, sizeoftype, &position, array, 1, outer_vector, MPI_COMM_WORLD);
145 if (position != sizeoftype) {
148 fprintf(stderr, "position = %d; should be %d (unpack)\n", position, sizeoftype);
151 for (i = 0; i < 9; i++) {
170 if (array[i] != goodval) {
173 fprintf(stderr, "array[%d] = %d; should be %d\n", i, array[i], goodval);
178 MPI_Type_free(&inner_vector);
179 MPI_Type_free(&outer_vector);
183 /* optimizable_vector_of_basics_test()
185 * Builds a vector of ints. Count is 10, blocksize is 2, stride is 2, so this
186 * is equivalent to a contig of 20.
188 * Returns the number of errors encountered.
190 int optimizable_vector_of_basics_test(void)
192 MPI_Datatype parent_type;
193 int array[20] = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15,
197 int i, sizeofint, sizeoftype, position;
201 MPI_Type_size(MPI_INT, &sizeofint);
203 if (sizeofint != sizeof(int)) {
206 fprintf(stderr, "size of MPI_Int = %d; should be %d\n", sizeofint, (int) sizeof(int));
210 MPI_Type_vector(10, 2, 2, MPI_INT, &parent_type);
212 MPI_Type_commit(&parent_type);
214 MPI_Type_size(parent_type, &sizeoftype);
216 if (sizeoftype != 20 * sizeof(int)) {
219 fprintf(stderr, "size of vector = %d; should be %d\n",
220 (int) sizeoftype, (int) (20 * sizeof(int)));
223 buf = (char *) malloc(sizeoftype);
226 MPI_Pack(array, 1, parent_type, buf, sizeoftype, &position, MPI_COMM_WORLD);
228 if (position != sizeoftype) {
231 fprintf(stderr, "position = %d; should be %d (pack)\n", position, sizeoftype);
234 memset(array, 0, 20 * sizeof(int));
236 MPI_Unpack(buf, sizeoftype, &position, array, 1, parent_type, MPI_COMM_WORLD);
238 if (position != sizeoftype) {
241 fprintf(stderr, "position = %d; should be %d (unpack)\n", position, sizeoftype);
244 for (i = 0; i < 20; i++) {
248 fprintf(stderr, "array[%d] = %d; should be %d\n", i, array[i], i);
253 MPI_Type_free(&parent_type);
258 int parse_args(int argc, char **argv)
263 * while ((ret = getopt(argc, argv, "v")) >= 0)
272 if (argc > 1 && strcmp(argv[1], "-v") == 0)