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();
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 /* 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;
72 int /* err, */ errs = 0;
74 /* err = */ MPI_Type_get_envelope(MPI_FLOAT,
80 if (combiner != MPI_COMBINER_NAMED) errs++;
82 /* Note: it is erroneous to call MPI_Type_get_contents() on a basic. */
86 /* vector_of_vectors_test()
88 * Builds a vector of a vector of ints. Assuming an int array of size 9
89 * integers, and treating the array as a 3x3 2D array, this will grab the
92 * Returns the number of errors encountered.
94 int vector_of_vectors_test(void)
96 MPI_Datatype inner_vector;
97 MPI_Datatype outer_vector;
98 int array[9] = { 1, -1, 2,
103 int i, err, errs = 0, 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);
133 MPI_Type_size(outer_vector, &sizeoftype);
134 if (sizeoftype != 4*sizeof(int)) {
136 if (verbose) fprintf(stderr, "size of type = %d; should be %d\n",
137 (int) sizeoftype, (int) (4*sizeof(int)));
141 buf = (char *) malloc(sizeoftype);
144 err = MPI_Pack(array,
152 if (position != sizeoftype) {
154 if (verbose) fprintf(stderr, "position = %d; should be %d (pack)\n",
155 position, sizeoftype);
158 memset(array, 0, 9*sizeof(int));
160 err = MPI_Unpack(buf,
168 if (position != sizeoftype) {
170 if (verbose) fprintf(stderr, "position = %d; should be %d (unpack)\n",
171 position, sizeoftype);
174 for (i=0; i < 9; i++) {
193 if (array[i] != goodval) {
195 if (verbose) fprintf(stderr, "array[%d] = %d; should be %d\n",
196 i, array[i], goodval);
200 MPI_Type_free(&inner_vector);
201 MPI_Type_free(&outer_vector);
205 /* optimizable_vector_of_basics_test()
207 * Builds a vector of ints. Count is 10, blocksize is 2, stride is 2, so this
208 * is equivalent to a contig of 20.
210 * Returns the number of errors encountered.
212 int optimizable_vector_of_basics_test(void)
214 MPI_Datatype parent_type;
215 int array[20] = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15,
218 int i, sizeofint, sizeoftype, position;
220 int /* err, */ errs = 0;
222 MPI_Type_size(MPI_INT, &sizeofint);
224 if (sizeofint != sizeof(int)) {
226 if (verbose) fprintf(stderr, "size of MPI_Int = %d; should be %d\n",
227 sizeofint, (int) sizeof(int));
231 /* err = */ MPI_Type_vector(10,
237 MPI_Type_commit(&parent_type);
239 MPI_Type_size(parent_type, &sizeoftype);
241 if (sizeoftype != 20 * sizeof(int)) {
243 if (verbose) fprintf(stderr, "size of vector = %d; should be %d\n",
244 (int) sizeoftype, (int) (20 * sizeof(int)));
247 buf = (char *) malloc(sizeoftype);
250 /* err = */ MPI_Pack(array,
258 if (position != sizeoftype) {
260 if (verbose) fprintf(stderr, "position = %d; should be %d (pack)\n",
261 position, sizeoftype);
264 memset(array, 0, 20 * sizeof(int));
266 /* err = */ MPI_Unpack(buf,
274 if (position != sizeoftype) {
276 if (verbose) fprintf(stderr, "position = %d; should be %d (unpack)\n",
277 position, sizeoftype);
280 for (i=0; i < 20; i++) {
283 if (verbose) fprintf(stderr, "array[%d] = %d; should be %d\n",
288 MPI_Type_free(&parent_type);
293 int parse_args(int argc, char **argv)
298 while ((ret = getopt(argc, argv, "v")) >= 0)
307 if (argc > 1 && strcmp(argv[1], "-v") == 0)