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();
37 if (err && verbose) fprintf(stderr, "%d errors in builtin float test.\n",
41 err = vector_of_vectors_test();
42 if (err && verbose) fprintf(stderr,
43 "%d errors in vector of vectors test.\n", err);
46 err = optimizable_vector_of_basics_test();
47 if (err && verbose) fprintf(stderr,
48 "%d errors in vector of basics test.\n", err);
51 err = struct_of_basics_test();
52 if (err && verbose) fprintf(stderr,
53 "%d errors in struct of basics test.\n", err);
56 MTest_Finalize( errs );
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;
71 int /* err, */ errs = 0;
73 /* err = */ MPI_Type_get_envelope(MPI_FLOAT,
79 if (combiner != MPI_COMBINER_NAMED) errs++;
81 /* Note: it is erroneous to call MPI_Type_get_contents() on a basic. */
85 /* vector_of_vectors_test()
87 * Builds a vector of a vector of ints. Assuming an int array of size 9
88 * integers, and treating the array as a 3x3 2D array, this will grab the
91 * Returns the number of errors encountered.
93 int vector_of_vectors_test(void)
95 MPI_Datatype inner_vector;
96 MPI_Datatype outer_vector;
97 int array[9] = { 1, -1, 2,
102 int i, err, errs = 0;
103 MPI_Aint sizeoftype, position;
106 err = MPI_Type_vector(2,
111 if (err != MPI_SUCCESS) {
113 if (verbose) fprintf(stderr,
114 "error in MPI call; aborting after %d errors\n",
119 err = MPI_Type_vector(2,
124 if (err != MPI_SUCCESS) {
126 if (verbose) fprintf(stderr,
127 "error in MPI call; aborting after %d errors\n",
132 MPI_Type_commit(&outer_vector);
134 MPI_Pack_external_size((char*)"external32", 1, outer_vector, &sizeoftype);
135 if (sizeoftype != 4*4) {
137 if (verbose) fprintf(stderr, "size of type = %d; should be %d\n",
138 (int) sizeoftype, 4*4);
142 buf = (char *) malloc(sizeoftype);
145 err = MPI_Pack_external((char*)"external32",
153 if (position != sizeoftype) {
155 if (verbose) fprintf(stderr, "position = %d; should be %d (pack)\n",
156 (int) position, (int) sizeoftype);
159 memset(array, 0, 9*sizeof(int));
161 err = MPI_Unpack_external((char*)"external32",
169 if (position != sizeoftype) {
171 if (verbose) fprintf(stderr, "position = %d; should be %d (unpack)\n",
172 (int) position, (int) sizeoftype);
175 for (i=0; i < 9; i++) {
194 if (array[i] != goodval) {
196 if (verbose) fprintf(stderr, "array[%d] = %d; should be %d\n",
197 i, array[i], goodval);
201 MPI_Type_free(&inner_vector);
202 MPI_Type_free(&outer_vector);
206 /* optimizable_vector_of_basics_test()
208 * Builds a vector of ints. Count is 10, blocksize is 2, stride is 2, so this
209 * is equivalent to a contig of 20.
211 * Returns the number of errors encountered.
213 int optimizable_vector_of_basics_test(void)
215 MPI_Datatype parent_type;
216 int array[20] = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15,
220 MPI_Aint sizeofint, sizeoftype, position;
222 int /* err, */ errs = 0;
224 MPI_Pack_external_size((char*)"external32", 1, MPI_INT, &sizeofint);
226 if (sizeofint != 4) {
228 if (verbose) fprintf(stderr,
229 "size of external32 MPI_INT = %d; should be %d\n",
234 /* err = */ MPI_Type_vector(10,
240 MPI_Type_commit(&parent_type);
242 MPI_Pack_external_size((char*)"external32", 1, parent_type, &sizeoftype);
245 if (sizeoftype != 20 * sizeofint) {
247 if (verbose) fprintf(stderr, "size of vector = %d; should be %d\n",
248 (int) sizeoftype, (int) (20 * sizeofint));
251 buf = (char *) malloc(sizeoftype);
254 /* err = */ MPI_Pack_external((char*)"external32",
262 if (position != sizeoftype) {
264 if (verbose) fprintf(stderr, "position = %d; should be %d (pack)\n",
265 (int) position, (int) sizeoftype);
268 memset(array, 0, 20 * sizeof(int));
270 /* err = */ MPI_Unpack_external((char*)"external32",
278 if (position != sizeoftype) {
280 if (verbose) fprintf(stderr,
281 "position = %ld; should be %ld (unpack)\n",
282 (long) position, (long) sizeoftype);
285 for (i=0; i < 20; i++) {
288 if (verbose) fprintf(stderr, "array[%d] = %d; should be %d\n",
293 MPI_Type_free(&parent_type);
297 /* struct_of_basics_test()
299 * Builds a struct of ints. Count is 10, all blocksizes are 2, all
300 * strides are 2*sizeofint, so this is equivalent to a contig of 20.
302 * Returns the number of errors encountered.
304 int struct_of_basics_test(void)
306 MPI_Datatype parent_type;
307 int array[20] = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15,
311 MPI_Aint sizeofint, sizeoftype, position;
313 MPI_Aint indices[10];
314 MPI_Datatype types[10];
316 int /* err, */ errs = 0;
318 MPI_Pack_external_size((char*)"external32", 1, MPI_INT, &sizeofint);
320 if (sizeofint != 4) {
322 if (verbose) fprintf(stderr,
323 "size of external32 MPI_INT = %d; should be %d\n",
327 for (i = 0; i < 10; i++) {
329 indices[i] = 2 * i * sizeofint;
330 /* This will cause MPICH to consider this as a blockindex. We
331 * need different types here. */
336 /* err = */ MPI_Type_struct(10,
342 MPI_Type_commit(&parent_type);
344 MPI_Pack_external_size((char*)"external32", 1, parent_type, &sizeoftype);
346 if (sizeoftype != 20 * sizeofint) {
348 if (verbose) fprintf(stderr, "size of vector = %d; should be %d\n",
349 (int) sizeoftype, (int) (20 * sizeofint));
352 buf = (char *) malloc(sizeoftype);
355 /* err = */ MPI_Pack_external((char*)"external32",
363 if (position != sizeoftype) {
365 if (verbose) fprintf(stderr, "position = %d; should be %d (pack)\n",
366 (int) position, (int) sizeoftype);
369 memset(array, 0, 20 * sizeof(int));
371 /* err = */ MPI_Unpack_external((char*)"external32",
379 if (position != sizeoftype) {
381 if (verbose) fprintf(stderr,
382 "position = %ld; should be %ld (unpack)\n",
383 (long) position, (long) sizeoftype);
386 for (i=0; i < 20; i++) {
389 if (verbose) fprintf(stderr, "array[%d] = %d; should be %d\n",
394 MPI_Type_free(&parent_type);
398 int parse_args(int argc, char **argv)
402 while ((ret = getopt(argc, argv, "v")) >= 0)