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, int count, MPI_Datatype datatype, int typebufsz);
26 int main(int argc, char **argv)
30 MPI_Init(&argc, &argv); /* MPI-1.2 doesn't allow for MPI_Init(0,0) */
31 parse_args(argc, argv);
33 /* To improve reporting of problems about operations, we
34 * change the error handler to errors return */
35 MPI_Comm_set_errhandler(MPI_COMM_WORLD, MPI_ERRORS_RETURN);
37 /* perform some tests */
38 err = subarray_1d_c_test1();
40 fprintf(stderr, "%d errors in 1d subarray c test 1.\n", err);
43 err = subarray_1d_fortran_test1();
45 fprintf(stderr, "%d errors in 1d subarray fortran test 1.\n", err);
48 err = subarray_2d_c_test1();
50 fprintf(stderr, "%d errors in 2d subarray c test 1.\n", err);
53 err = subarray_2d_fortran_test1();
55 fprintf(stderr, "%d errors in 2d subarray fortran test 1.\n", err);
58 err = subarray_2d_c_test2();
60 fprintf(stderr, "%d errors in 2d subarray c test 2.\n", err);
63 err = subarray_4d_c_test1();
65 fprintf(stderr, "%d errors in 4d subarray c test 1.\n", err);
68 err = subarray_4d_fortran_test1();
70 fprintf(stderr, "%d errors in 4d subarray fortran test 1.\n", err);
73 /* print message and exit */
75 fprintf(stderr, "Found %d errors\n", errs);
78 printf(" No Errors\n");
84 /* subarray_1d_c_test1()
86 * Returns the number of errors encountered.
88 int subarray_1d_c_test1(void)
90 MPI_Datatype subarray;
91 int array[9] = { -1, 1, 2, 3, -2, -3, -4, -5, -6 };
92 int array_size[] = { 9 };
93 int array_subsize[] = { 3 };
94 int array_start[] = { 1 };
96 int i, err, errs = 0, sizeoftype;
99 err = MPI_Type_create_subarray(1, /* dims */
101 array_subsize, array_start, MPI_ORDER_C, MPI_INT, &subarray);
102 if (err != MPI_SUCCESS) {
106 "error in MPI_Type_create_subarray call; aborting after %d errors\n", errs);
111 MPI_Type_commit(&subarray);
112 MPI_Type_size(subarray, &sizeoftype);
113 if (sizeoftype != 3 * sizeof(int)) {
116 fprintf(stderr, "size of type = %d; should be %d\n",
117 sizeoftype, (int) (3 * sizeof(int)));
121 err = pack_and_unpack((char *) array, 1, subarray, 9 * sizeof(int));
123 for (i = 0; i < 9; i++) {
136 goodval = 0; /* pack_and_unpack() zeros before unpacking */
139 if (array[i] != goodval) {
142 fprintf(stderr, "array[%d] = %d; should be %d\n", i, array[i], goodval);
146 MPI_Type_free(&subarray);
150 /* subarray_1d_fortran_test1()
152 * Returns the number of errors encountered.
154 int subarray_1d_fortran_test1(void)
156 MPI_Datatype subarray;
157 int array[9] = { -1, 1, 2, 3, -2, -3, -4, -5, -6 };
158 int array_size[] = { 9 };
159 int array_subsize[] = { 3 };
160 int array_start[] = { 1 };
162 int i, err, errs = 0, sizeoftype;
165 err = MPI_Type_create_subarray(1, /* dims */
168 array_start, MPI_ORDER_FORTRAN, MPI_INT, &subarray);
169 if (err != MPI_SUCCESS) {
173 "error in MPI_Type_create_subarray call; aborting after %d errors\n", errs);
178 MPI_Type_commit(&subarray);
179 MPI_Type_size(subarray, &sizeoftype);
180 if (sizeoftype != 3 * sizeof(int)) {
183 fprintf(stderr, "size of type = %d; should be %d\n",
184 sizeoftype, (int) (3 * sizeof(int)));
188 err = pack_and_unpack((char *) array, 1, subarray, 9 * sizeof(int));
190 for (i = 0; i < 9; i++) {
203 goodval = 0; /* pack_and_unpack() zeros before unpacking */
206 if (array[i] != goodval) {
209 fprintf(stderr, "array[%d] = %d; should be %d\n", i, array[i], goodval);
213 MPI_Type_free(&subarray);
218 /* subarray_2d_test()
220 * Returns the number of errors encountered.
222 int subarray_2d_c_test1(void)
224 MPI_Datatype subarray;
225 int array[9] = { -1, -2, -3,
229 int array_size[2] = { 3, 3 };
230 int array_subsize[2] = { 2, 2 };
231 int array_start[2] = { 1, 1 };
233 int i, err, errs = 0, sizeoftype;
236 err = MPI_Type_create_subarray(2, /* dims */
238 array_subsize, array_start, MPI_ORDER_C, MPI_INT, &subarray);
239 if (err != MPI_SUCCESS) {
243 "error in MPI_Type_create_subarray call; aborting after %d errors\n", errs);
248 MPI_Type_commit(&subarray);
249 MPI_Type_size(subarray, &sizeoftype);
250 if (sizeoftype != 4 * sizeof(int)) {
253 fprintf(stderr, "size of type = %d; should be %d\n",
254 sizeoftype, (int) (4 * sizeof(int)));
258 err = pack_and_unpack((char *) array, 1, subarray, 9 * sizeof(int));
260 for (i = 0; i < 9; i++) {
279 if (array[i] != goodval) {
282 fprintf(stderr, "array[%d] = %d; should be %d\n", i, array[i], goodval);
286 MPI_Type_free(&subarray);
290 /* subarray_2d_c_test2()
292 * Returns the number of errors encountered.
294 int subarray_2d_c_test2(void)
296 MPI_Datatype subarray;
297 int array[12] = { -1, -2, -3, -4, 1, 2,
298 -5, -6, -7, -8, -9, -10
300 int array_size[2] = { 2, 6 };
301 int array_subsize[2] = { 1, 2 };
302 int array_start[2] = { 0, 4 };
304 int i, err, errs = 0, sizeoftype;
307 err = MPI_Type_create_subarray(2, /* dims */
309 array_subsize, array_start, MPI_ORDER_C, MPI_INT, &subarray);
310 if (err != MPI_SUCCESS) {
314 "error in MPI_Type_create_subarray call; aborting after %d errors\n", errs);
319 MPI_Type_commit(&subarray);
320 MPI_Type_size(subarray, &sizeoftype);
321 if (sizeoftype != 2 * sizeof(int)) {
324 fprintf(stderr, "size of type = %d; should be %d\n",
325 sizeoftype, (int) (2 * sizeof(int)));
329 err = pack_and_unpack((char *) array, 1, subarray, 12 * sizeof(int));
331 for (i = 0; i < 12; i++) {
344 if (array[i] != goodval) {
347 fprintf(stderr, "array[%d] = %d; should be %d\n", i, array[i], goodval);
351 MPI_Type_free(&subarray);
355 /* subarray_4d_c_test1()
357 * Returns the number of errors encountered.
359 int subarray_4d_c_test1(void)
361 MPI_Datatype subarray;
363 -1111, -1112, -1113, -1114, -1115, -1116,
364 -1121, -1122, -1123, -1124, -1125, -1126,
365 -1131, -1132, -1133, -1134, -1135, -1136,
366 -1211, -1212, -1213, -1214, -1215, -1216,
367 -1221, -1222, -1223, -1224, -1225, -1226,
368 -1231, -1232, -1233, -1234, -1235, -1236,
369 -2111, -2112, -2113, -2114, 1, -2116,
370 -2121, -2122, -2123, -2124, 2, -2126,
371 -2131, -2132, -2133, -2134, 3, -2136,
372 -2211, -2212, -2213, -2214, 4, -2216,
373 -2221, -2222, -2223, -2224, 5, -2226,
374 -2231, -2232, -2233, -2234, 6, -2236
377 int array_size[4] = { 2, 2, 3, 6 };
378 int array_subsize[4] = { 1, 2, 3, 1 };
379 int array_start[4] = { 1, 0, 0, 4 };
381 int i, err, errs = 0, sizeoftype;
384 err = MPI_Type_create_subarray(4, /* dims */
386 array_subsize, array_start, MPI_ORDER_C, MPI_INT, &subarray);
387 if (err != MPI_SUCCESS) {
391 "error in MPI_Type_create_subarray call; aborting after %d errors\n", errs);
396 MPI_Type_commit(&subarray);
397 MPI_Type_size(subarray, &sizeoftype);
398 if (sizeoftype != 6 * sizeof(int)) {
401 fprintf(stderr, "size of type = %d; should be %d\n",
402 sizeoftype, (int) (6 * sizeof(int)));
406 err = pack_and_unpack((char *) array, 1, subarray, 72 * sizeof(int));
408 for (i = 0; i < 72; i++) {
433 if (array[i] != goodval) {
436 fprintf(stderr, "array[%d] = %d; should be %d\n", i, array[i], goodval);
440 MPI_Type_free(&subarray);
444 /* subarray_4d_fortran_test1()
446 * Returns the number of errors encountered.
448 int subarray_4d_fortran_test1(void)
450 MPI_Datatype subarray;
452 -1111, -1112, -1113, -1114, -1115, -1116,
453 -1121, -1122, -1123, -1124, -1125, -1126,
454 -1131, -1132, -1133, -1134, -1135, -1136,
455 -1211, -1212, -1213, -1214, -1215, -1216,
456 -1221, -1222, -1223, -1224, -1225, -1226,
457 -1231, -1232, -1233, -1234, -1235, -1236,
458 -2111, -2112, -2113, -2114, 1, -2116,
459 -2121, -2122, -2123, -2124, 2, -2126,
460 -2131, -2132, -2133, -2134, 3, -2136,
461 -2211, -2212, -2213, -2214, 4, -2216,
462 -2221, -2222, -2223, -2224, 5, -2226,
463 -2231, -2232, -2233, -2234, 6, -2236
466 int array_size[4] = { 6, 3, 2, 2 };
467 int array_subsize[4] = { 1, 3, 2, 1 };
468 int array_start[4] = { 4, 0, 0, 1 };
470 int i, err, errs = 0, sizeoftype;
473 err = MPI_Type_create_subarray(4, /* dims */
476 array_start, MPI_ORDER_FORTRAN, MPI_INT, &subarray);
477 if (err != MPI_SUCCESS) {
481 "error in MPI_Type_create_subarray call; aborting after %d errors\n", errs);
486 MPI_Type_commit(&subarray);
487 MPI_Type_size(subarray, &sizeoftype);
488 if (sizeoftype != 6 * sizeof(int)) {
491 fprintf(stderr, "size of type = %d; should be %d\n",
492 sizeoftype, (int) (6 * sizeof(int)));
496 err = pack_and_unpack((char *) array, 1, subarray, 72 * sizeof(int));
498 for (i = 0; i < 72; i++) {
523 if (array[i] != goodval) {
526 fprintf(stderr, "array[%d] = %d; should be %d\n", i, array[i], goodval);
530 MPI_Type_free(&subarray);
535 /* subarray_2d_fortran_test1()
537 * Returns the number of errors encountered.
539 int subarray_2d_fortran_test1(void)
541 MPI_Datatype subarray;
542 int array[12] = { -1, -2, -3, -4, 1, 2,
543 -5, -6, -7, -8, -9, -10
545 int array_size[2] = { 6, 2 };
546 int array_subsize[2] = { 2, 1 };
547 int array_start[2] = { 4, 0 };
549 int i, err, errs = 0, sizeoftype;
552 err = MPI_Type_create_subarray(2, /* dims */
555 array_start, MPI_ORDER_FORTRAN, MPI_INT, &subarray);
556 if (err != MPI_SUCCESS) {
560 "error in MPI_Type_create_subarray call; aborting after %d errors\n", errs);
565 MPI_Type_commit(&subarray);
566 MPI_Type_size(subarray, &sizeoftype);
567 if (sizeoftype != 2 * sizeof(int)) {
570 fprintf(stderr, "size of type = %d; should be %d\n",
571 sizeoftype, (int) (2 * sizeof(int)));
575 err = pack_and_unpack((char *) array, 1, subarray, 12 * sizeof(int));
577 for (i = 0; i < 12; i++) {
590 if (array[i] != goodval) {
593 fprintf(stderr, "array[%d] = %d; should be %d\n", i, array[i], goodval);
597 MPI_Type_free(&subarray);
601 /******************************************************************/
605 * Perform packing and unpacking of a buffer for the purposes of checking
606 * to see if we are processing a type correctly. Zeros the buffer between
607 * these two operations, so the data described by the type should be in
608 * place upon return but all other regions of the buffer should be zero.
611 * typebuf - pointer to buffer described by datatype and count that
612 * will be packed and then unpacked into
613 * count, datatype - description of typebuf
614 * typebufsz - size of typebuf; used specifically to zero the buffer
615 * between the pack and unpack steps
618 static int pack_and_unpack(char *typebuf, int count, MPI_Datatype datatype, int typebufsz)
621 int err, errs = 0, pack_size, type_size, position;
623 err = MPI_Type_size(datatype, &type_size);
624 if (err != MPI_SUCCESS) {
627 fprintf(stderr, "error in MPI_Type_size call; aborting after %d errors\n", errs);
634 err = MPI_Pack_size(count, datatype, MPI_COMM_SELF, &pack_size);
635 if (err != MPI_SUCCESS) {
638 fprintf(stderr, "error in MPI_Pack_size call; aborting after %d errors\n", errs);
642 packbuf = (char *) malloc(pack_size);
643 if (packbuf == NULL) {
646 fprintf(stderr, "error in malloc call; aborting after %d errors\n", errs);
652 err = MPI_Pack(typebuf, count, datatype, packbuf, type_size, &position, MPI_COMM_SELF);
654 if (position != type_size) {
657 fprintf(stderr, "position = %d; should be %d (pack)\n", position, type_size);
660 memset(typebuf, 0, typebufsz);
662 err = MPI_Unpack(packbuf, type_size, &position, typebuf, count, datatype, MPI_COMM_SELF);
663 if (err != MPI_SUCCESS) {
666 fprintf(stderr, "error in MPI_Unpack call; aborting after %d errors\n", errs);
672 if (position != type_size) {
675 fprintf(stderr, "position = %d; should be %d (unpack)\n", position, type_size);
681 static int parse_args(int argc, char **argv)
686 * while ((ret = getopt(argc, argv, "v")) >= 0)
695 if (argc > 1 && strcmp(argv[1], "-v") == 0)