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.
13 static int verbose = 0;
16 int builtin_float_test(void);
17 int vector_of_vectors_test(void);
18 int optimizable_vector_of_basics_test(void);
19 int struct_of_basics_test(void);
21 /* helper functions */
22 int parse_args(int argc, char **argv);
24 int main(int argc, char **argv)
28 MTest_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);
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 err = struct_of_basics_test();
53 fprintf(stderr, "%d errors in struct of basics test.\n", err);
61 /* builtin_float_test()
63 * Tests functionality of get_envelope() and get_contents() on a MPI_FLOAT.
65 * Returns the number of errors encountered.
67 int builtin_float_test(void)
69 int nints, nadds, ntypes, combiner;
73 err = MPI_Type_get_envelope(MPI_FLOAT, &nints, &nadds, &ntypes, &combiner);
75 if (combiner != MPI_COMBINER_NAMED)
78 /* Note: it is erroneous to call MPI_Type_get_contents() on a basic. */
82 /* vector_of_vectors_test()
84 * Builds a vector of a vector of ints. Assuming an int array of size 9
85 * integers, and treating the array as a 3x3 2D array, this will grab the
88 * Returns the number of errors encountered.
90 int vector_of_vectors_test(void)
92 MPI_Datatype inner_vector;
93 MPI_Datatype outer_vector;
94 int array[9] = { 1, -1, 2,
100 int i, err, errs = 0;
101 MPI_Aint 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);
122 MPI_Pack_external_size((char *) "external32", 1, outer_vector, &sizeoftype);
123 if (sizeoftype != 4 * 4) {
126 fprintf(stderr, "size of type = %d; should be %d\n", (int) sizeoftype, 4 * 4);
130 buf = (char *) malloc(sizeoftype);
133 err = MPI_Pack_external((char *) "external32",
134 array, 1, outer_vector, buf, sizeoftype, &position);
136 if (position != sizeoftype) {
139 fprintf(stderr, "position = %d; should be %d (pack)\n",
140 (int) position, (int) sizeoftype);
143 memset(array, 0, 9 * sizeof(int));
145 err = MPI_Unpack_external((char *) "external32",
146 buf, sizeoftype, &position, array, 1, outer_vector);
148 if (position != sizeoftype) {
151 fprintf(stderr, "position = %d; should be %d (unpack)\n",
152 (int) position, (int) sizeoftype);
155 for (i = 0; i < 9; i++) {
174 if (array[i] != goodval) {
177 fprintf(stderr, "array[%d] = %d; should be %d\n", i, array[i], goodval);
182 MPI_Type_free(&inner_vector);
183 MPI_Type_free(&outer_vector);
187 /* optimizable_vector_of_basics_test()
189 * Builds a vector of ints. Count is 10, blocksize is 2, stride is 2, so this
190 * is equivalent to a contig of 20.
192 * Returns the number of errors encountered.
194 int optimizable_vector_of_basics_test(void)
196 MPI_Datatype parent_type;
197 int array[20] = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15,
202 MPI_Aint sizeofint, sizeoftype, position;
206 MPI_Pack_external_size((char *) "external32", 1, MPI_INT, &sizeofint);
208 if (sizeofint != 4) {
211 fprintf(stderr, "size of external32 MPI_INT = %d; should be %d\n", (int) sizeofint, 4);
215 err = MPI_Type_vector(10, 2, 2, MPI_INT, &parent_type);
217 MPI_Type_commit(&parent_type);
219 MPI_Pack_external_size((char *) "external32", 1, parent_type, &sizeoftype);
222 if (sizeoftype != 20 * sizeofint) {
225 fprintf(stderr, "size of vector = %d; should be %d\n",
226 (int) sizeoftype, (int) (20 * sizeofint));
229 buf = (char *) malloc(sizeoftype);
232 err = MPI_Pack_external((char *) "external32",
233 array, 1, parent_type, buf, sizeoftype, &position);
235 if (position != sizeoftype) {
238 fprintf(stderr, "position = %d; should be %d (pack)\n",
239 (int) position, (int) sizeoftype);
242 memset(array, 0, 20 * sizeof(int));
244 err = MPI_Unpack_external((char *) "external32",
245 buf, sizeoftype, &position, array, 1, parent_type);
247 if (position != sizeoftype) {
251 "position = %ld; should be %ld (unpack)\n", (long) position, (long) sizeoftype);
254 for (i = 0; i < 20; i++) {
258 fprintf(stderr, "array[%d] = %d; should be %d\n", i, array[i], i);
263 MPI_Type_free(&parent_type);
267 /* struct_of_basics_test()
269 * Builds a struct of ints. Count is 10, all blocksizes are 2, all
270 * strides are 2*sizeofint, so this is equivalent to a contig of 20.
272 * Returns the number of errors encountered.
274 int struct_of_basics_test(void)
276 MPI_Datatype parent_type;
277 int array[20] = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15,
282 MPI_Aint sizeofint, sizeoftype, position;
284 MPI_Aint indices[10];
285 MPI_Datatype types[10];
289 MPI_Pack_external_size((char *) "external32", 1, MPI_INT, &sizeofint);
291 if (sizeofint != 4) {
294 fprintf(stderr, "size of external32 MPI_INT = %d; should be %d\n", (int) sizeofint, 4);
297 for (i = 0; i < 10; i++) {
299 indices[i] = 2 * i * sizeofint;
300 /* This will cause MPICH to consider this as a blockindex. We
301 * need different types here. */
306 err = MPI_Type_struct(10, blocks, indices, types, &parent_type);
308 MPI_Type_commit(&parent_type);
310 MPI_Pack_external_size((char *) "external32", 1, parent_type, &sizeoftype);
312 if (sizeoftype != 20 * sizeofint) {
315 fprintf(stderr, "size of vector = %d; should be %d\n",
316 (int) sizeoftype, (int) (20 * sizeofint));
319 buf = (char *) malloc(sizeoftype);
322 err = MPI_Pack_external((char *) "external32",
323 array, 1, parent_type, buf, sizeoftype, &position);
325 if (position != sizeoftype) {
328 fprintf(stderr, "position = %d; should be %d (pack)\n",
329 (int) position, (int) sizeoftype);
332 memset(array, 0, 20 * sizeof(int));
334 err = MPI_Unpack_external((char *) "external32",
335 buf, sizeoftype, &position, array, 1, parent_type);
337 if (position != sizeoftype) {
341 "position = %ld; should be %ld (unpack)\n", (long) position, (long) sizeoftype);
344 for (i = 0; i < 20; i++) {
348 fprintf(stderr, "array[%d] = %d; should be %d\n", i, array[i], i);
353 MPI_Type_free(&parent_type);
357 int parse_args(int argc, char **argv)
361 while ((ret = getopt(argc, argv, "v")) >= 0) {