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.
11 static int verbose = 0;
14 int subarray_1d_c_test1(void);
15 int subarray_1d_fortran_test1(void);
16 int subarray_2d_c_test1(void);
17 int subarray_4d_c_test1(void);
18 int subarray_2d_c_test2(void);
19 int subarray_2d_fortran_test1(void);
20 int subarray_4d_fortran_test1(void);
22 /* helper functions */
23 static int parse_args(int argc, char **argv);
24 static int pack_and_unpack(char *typebuf,
26 MPI_Datatype datatype,
29 int main(int argc, char **argv)
33 MPI_Init(&argc, &argv); /* MPI-1.2 doesn't allow for MPI_Init(0,0) */
34 parse_args(argc, argv);
36 /* To improve reporting of problems about operations, we
37 change the error handler to errors return */
38 MPI_Comm_set_errhandler( MPI_COMM_WORLD, MPI_ERRORS_RETURN );
40 /* perform some tests */
41 err = subarray_1d_c_test1();
42 if (err && verbose) fprintf(stderr,
43 "%d errors in 1d subarray c test 1.\n", err);
46 err = subarray_1d_fortran_test1();
47 if (err && verbose) fprintf(stderr,
48 "%d errors in 1d subarray fortran test 1.\n",
52 err = subarray_2d_c_test1();
53 if (err && verbose) fprintf(stderr,
54 "%d errors in 2d subarray c test 1.\n", err);
57 err = subarray_2d_fortran_test1();
58 if (err && verbose) fprintf(stderr,
59 "%d errors in 2d subarray fortran test 1.\n",
63 err = subarray_2d_c_test2();
64 if (err && verbose) fprintf(stderr,
65 "%d errors in 2d subarray c test 2.\n", err);
68 err = subarray_4d_c_test1();
69 if (err && verbose) fprintf(stderr,
70 "%d errors in 4d subarray c test 1.\n", err);
73 err = subarray_4d_fortran_test1();
74 if (err && verbose) fprintf(stderr,
75 "%d errors in 4d subarray fortran test 1.\n", err);
78 /* print message and exit */
80 fprintf(stderr, "Found %d errors\n", errs);
83 printf(" No Errors\n");
89 /* subarray_1d_c_test1()
91 * Returns the number of errors encountered.
93 int subarray_1d_c_test1(void)
95 MPI_Datatype subarray;
96 int array[9] = { -1, 1, 2, 3, -2, -3, -4, -5, -6 };
97 int array_size[] = {9};
98 int array_subsize[] = {3};
99 int array_start[] = {1};
101 int i, err, errs = 0, sizeoftype;
104 err = MPI_Type_create_subarray(1, /* dims */
111 if (err != MPI_SUCCESS) {
115 "error in MPI_Type_create_subarray call; aborting after %d errors\n",
121 MPI_Type_commit(&subarray);
122 MPI_Type_size(subarray, &sizeoftype);
123 if (sizeoftype != 3 * sizeof(int)) {
125 if (verbose) fprintf(stderr, "size of type = %d; should be %d\n",
126 sizeoftype, (int) (3 * sizeof(int)));
130 err = pack_and_unpack((char *) array, 1, subarray, 9 * sizeof(int));
132 for (i=0; i < 9; i++) {
145 goodval = 0; /* pack_and_unpack() zeros before unpacking */
148 if (array[i] != goodval) {
150 if (verbose) fprintf(stderr, "array[%d] = %d; should be %d\n",
151 i, array[i], goodval);
155 MPI_Type_free(&subarray);
159 /* subarray_1d_fortran_test1()
161 * Returns the number of errors encountered.
163 int subarray_1d_fortran_test1(void)
165 MPI_Datatype subarray;
166 int array[9] = { -1, 1, 2, 3, -2, -3, -4, -5, -6 };
167 int array_size[] = {9};
168 int array_subsize[] = {3};
169 int array_start[] = {1};
171 int i, err, errs = 0, sizeoftype;
174 err = MPI_Type_create_subarray(1, /* dims */
181 if (err != MPI_SUCCESS) {
185 "error in MPI_Type_create_subarray call; aborting after %d errors\n",
191 MPI_Type_commit(&subarray);
192 MPI_Type_size(subarray, &sizeoftype);
193 if (sizeoftype != 3 * sizeof(int)) {
195 if (verbose) fprintf(stderr, "size of type = %d; should be %d\n",
196 sizeoftype, (int) (3 * sizeof(int)));
200 err = pack_and_unpack((char *) array, 1, subarray, 9 * sizeof(int));
202 for (i=0; i < 9; i++) {
215 goodval = 0; /* pack_and_unpack() zeros before unpacking */
218 if (array[i] != goodval) {
220 if (verbose) fprintf(stderr, "array[%d] = %d; should be %d\n",
221 i, array[i], goodval);
225 MPI_Type_free(&subarray);
230 /* subarray_2d_test()
232 * Returns the number of errors encountered.
234 int subarray_2d_c_test1(void)
236 MPI_Datatype subarray;
237 int array[9] = { -1, -2, -3,
240 int array_size[2] = {3, 3};
241 int array_subsize[2] = {2, 2};
242 int array_start[2] = {1, 1};
244 int i, err, errs = 0, sizeoftype;
247 err = MPI_Type_create_subarray(2, /* dims */
254 if (err != MPI_SUCCESS) {
258 "error in MPI_Type_create_subarray call; aborting after %d errors\n",
264 MPI_Type_commit(&subarray);
265 MPI_Type_size(subarray, &sizeoftype);
266 if (sizeoftype != 4*sizeof(int)) {
268 if (verbose) fprintf(stderr, "size of type = %d; should be %d\n",
269 sizeoftype, (int) (4*sizeof(int)));
273 err = pack_and_unpack((char *) array, 1, subarray, 9*sizeof(int));
275 for (i=0; i < 9; i++) {
294 if (array[i] != goodval) {
296 if (verbose) fprintf(stderr, "array[%d] = %d; should be %d\n",
297 i, array[i], goodval);
301 MPI_Type_free(&subarray);
305 /* subarray_2d_c_test2()
307 * Returns the number of errors encountered.
309 int subarray_2d_c_test2(void)
311 MPI_Datatype subarray;
312 int array[12] = { -1, -2, -3, -4, 1, 2,
313 -5, -6, -7, -8, -9, -10 };
314 int array_size[2] = {2, 6};
315 int array_subsize[2] = {1, 2};
316 int array_start[2] = {0, 4};
318 int i, err, errs = 0, sizeoftype;
321 err = MPI_Type_create_subarray(2, /* dims */
328 if (err != MPI_SUCCESS) {
332 "error in MPI_Type_create_subarray call; aborting after %d errors\n",
338 MPI_Type_commit(&subarray);
339 MPI_Type_size(subarray, &sizeoftype);
340 if (sizeoftype != 2*sizeof(int)) {
342 if (verbose) fprintf(stderr, "size of type = %d; should be %d\n",
343 sizeoftype, (int) (2*sizeof(int)));
347 err = pack_and_unpack((char *) array, 1, subarray, 12*sizeof(int));
349 for (i=0; i < 12; i++) {
362 if (array[i] != goodval) {
364 if (verbose) fprintf(stderr, "array[%d] = %d; should be %d\n",
365 i, array[i], goodval);
369 MPI_Type_free(&subarray);
373 /* subarray_4d_c_test1()
375 * Returns the number of errors encountered.
377 int subarray_4d_c_test1(void)
379 MPI_Datatype subarray;
381 -1111, -1112, -1113, -1114, -1115, -1116,
382 -1121, -1122, -1123, -1124, -1125, -1126,
383 -1131, -1132, -1133, -1134, -1135, -1136,
384 -1211, -1212, -1213, -1214, -1215, -1216,
385 -1221, -1222, -1223, -1224, -1225, -1226,
386 -1231, -1232, -1233, -1234, -1235, -1236,
387 -2111, -2112, -2113, -2114, 1, -2116,
388 -2121, -2122, -2123, -2124, 2, -2126,
389 -2131, -2132, -2133, -2134, 3, -2136,
390 -2211, -2212, -2213, -2214, 4, -2216,
391 -2221, -2222, -2223, -2224, 5, -2226,
392 -2231, -2232, -2233, -2234, 6, -2236
395 int array_size[4] = {2, 2, 3, 6};
396 int array_subsize[4] = {1, 2, 3, 1};
397 int array_start[4] = {1, 0, 0, 4};
399 int i, err, errs = 0, sizeoftype;
402 err = MPI_Type_create_subarray(4, /* dims */
409 if (err != MPI_SUCCESS) {
413 "error in MPI_Type_create_subarray call; aborting after %d errors\n",
419 MPI_Type_commit(&subarray);
420 MPI_Type_size(subarray, &sizeoftype);
421 if (sizeoftype != 6*sizeof(int)) {
423 if (verbose) fprintf(stderr, "size of type = %d; should be %d\n",
424 sizeoftype, (int) (6*sizeof(int)));
428 err = pack_and_unpack((char *) array, 1, subarray, 72*sizeof(int));
430 for (i=0; i < 72; i++) {
455 if (array[i] != goodval) {
457 if (verbose) fprintf(stderr, "array[%d] = %d; should be %d\n",
458 i, array[i], goodval);
462 MPI_Type_free(&subarray);
465 /* subarray_4d_fortran_test1()
467 * Returns the number of errors encountered.
469 int subarray_4d_fortran_test1(void)
471 MPI_Datatype subarray;
473 -1111, -1112, -1113, -1114, -1115, -1116,
474 -1121, -1122, -1123, -1124, -1125, -1126,
475 -1131, -1132, -1133, -1134, -1135, -1136,
476 -1211, -1212, -1213, -1214, -1215, -1216,
477 -1221, -1222, -1223, -1224, -1225, -1226,
478 -1231, -1232, -1233, -1234, -1235, -1236,
479 -2111, -2112, -2113, -2114, 1, -2116,
480 -2121, -2122, -2123, -2124, 2, -2126,
481 -2131, -2132, -2133, -2134, 3, -2136,
482 -2211, -2212, -2213, -2214, 4, -2216,
483 -2221, -2222, -2223, -2224, 5, -2226,
484 -2231, -2232, -2233, -2234, 6, -2236
487 int array_size[4] = {6, 3, 2, 2};
488 int array_subsize[4] = {1, 3, 2, 1};
489 int array_start[4] = {4, 0, 0, 1};
491 int i, err, errs = 0, sizeoftype;
494 err = MPI_Type_create_subarray(4, /* dims */
501 if (err != MPI_SUCCESS) {
505 "error in MPI_Type_create_subarray call; aborting after %d errors\n",
511 MPI_Type_commit(&subarray);
512 MPI_Type_size(subarray, &sizeoftype);
513 if (sizeoftype != 6*sizeof(int)) {
515 if (verbose) fprintf(stderr, "size of type = %d; should be %d\n",
516 sizeoftype, (int) (6*sizeof(int)));
520 err = pack_and_unpack((char *) array, 1, subarray, 72*sizeof(int));
522 for (i=0; i < 72; i++) {
547 if (array[i] != goodval) {
549 if (verbose) fprintf(stderr, "array[%d] = %d; should be %d\n",
550 i, array[i], goodval);
554 MPI_Type_free(&subarray);
559 /* subarray_2d_fortran_test1()
561 * Returns the number of errors encountered.
563 int subarray_2d_fortran_test1(void)
565 MPI_Datatype subarray;
566 int array[12] = { -1, -2, -3, -4, 1, 2,
567 -5, -6, -7, -8, -9, -10 };
568 int array_size[2] = {6, 2};
569 int array_subsize[2] = {2, 1};
570 int array_start[2] = {4, 0};
572 int i, err, errs = 0, sizeoftype;
575 err = MPI_Type_create_subarray(2, /* dims */
582 if (err != MPI_SUCCESS) {
586 "error in MPI_Type_create_subarray call; aborting after %d errors\n",
592 MPI_Type_commit(&subarray);
593 MPI_Type_size(subarray, &sizeoftype);
594 if (sizeoftype != 2*sizeof(int)) {
596 if (verbose) fprintf(stderr, "size of type = %d; should be %d\n",
597 sizeoftype, (int) (2*sizeof(int)));
601 err = pack_and_unpack((char *) array, 1, subarray, 12*sizeof(int));
603 for (i=0; i < 12; i++) {
616 if (array[i] != goodval) {
618 if (verbose) fprintf(stderr, "array[%d] = %d; should be %d\n",
619 i, array[i], goodval);
623 MPI_Type_free(&subarray);
627 /******************************************************************/
631 * Perform packing and unpacking of a buffer for the purposes of checking
632 * to see if we are processing a type correctly. Zeros the buffer between
633 * these two operations, so the data described by the type should be in
634 * place upon return but all other regions of the buffer should be zero.
637 * typebuf - pointer to buffer described by datatype and count that
638 * will be packed and then unpacked into
639 * count, datatype - description of typebuf
640 * typebufsz - size of typebuf; used specifically to zero the buffer
641 * between the pack and unpack steps
644 static int pack_and_unpack(char *typebuf,
646 MPI_Datatype datatype,
650 int err, errs = 0, pack_size, type_size, position;
652 err = MPI_Type_size(datatype, &type_size);
653 if (err != MPI_SUCCESS) {
657 "error in MPI_Type_size call; aborting after %d errors\n",
665 err = MPI_Pack_size(count, datatype, MPI_COMM_SELF, &pack_size);
666 if (err != MPI_SUCCESS) {
670 "error in MPI_Pack_size call; aborting after %d errors\n",
675 packbuf = (char *) malloc(pack_size);
676 if (packbuf == NULL) {
680 "error in malloc call; aborting after %d errors\n",
687 err = MPI_Pack(typebuf,
695 if (position != type_size) {
697 if (verbose) fprintf(stderr, "position = %d; should be %d (pack)\n",
698 position, type_size);
701 memset(typebuf, 0, typebufsz);
703 err = MPI_Unpack(packbuf,
710 if (err != MPI_SUCCESS) {
714 "error in MPI_Unpack call; aborting after %d errors\n",
721 if (position != type_size) {
723 if (verbose) fprintf(stderr, "position = %d; should be %d (unpack)\n",
724 position, type_size);
730 static int parse_args(int argc, char **argv)
735 while ((ret = getopt(argc, argv, "v")) >= 0)
744 if (argc > 1 && strcmp(argv[1], "-v") == 0)