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 #include "mpitestconf.h"
16 static int verbose = 0;
18 int main(int argc, char *argv[]);
19 int parse_args(int argc, char **argv);
21 int main(int argc, char *argv[])
23 /* Variable declarations */
24 int a[100][100], b[100][100];
25 MPI_Datatype row, xpose;
29 int bufsize, position = 0;
34 /* Initialize a to some known values. */
35 for (i = 0; i < 100; i++) {
36 for (j = 0; j < 100; j++) {
37 a[i][j] = i * 1000 + j;
43 MPI_Init(&argc, &argv);
44 parse_args(argc, argv);
46 MPI_Type_extent(MPI_INT, &sizeofint);
48 /* Create datatypes. */
49 MPI_Type_vector(100, 1, 100, MPI_INT, &row);
50 MPI_Type_hvector(100, 1, sizeofint, row, &xpose);
51 MPI_Type_commit(&xpose);
54 MPI_Pack_size(1, xpose, MPI_COMM_WORLD, &bufsize);
55 buffer = (char *) malloc((unsigned) bufsize);
57 /* To improve reporting of problems about operations, we
58 * change the error handler to errors return */
59 MPI_Comm_set_errhandler(MPI_COMM_WORLD, MPI_ERRORS_RETURN);
61 MPI_Pack(a, 1, xpose, buffer, bufsize, &position, MPI_COMM_WORLD);
63 /* Unpack the buffer into b. */
65 MPI_Unpack(buffer, bufsize, &position, b, 100 * 100, MPI_INT, MPI_COMM_WORLD);
67 for (i = 0; i < 100; i++) {
68 for (j = 0; j < 100; j++) {
69 if (b[i][j] != a[j][i]) {
72 fprintf(stderr, "b[%d][%d] = %d, should be %d\n", i, j, b[i][j], a[j][i]);
77 MPI_Type_free(&xpose);
80 /* print message and exit */
82 fprintf(stderr, "Found %d errors\n", errs);
85 printf(" No Errors\n");
93 int parse_args(int argc, char **argv)
98 * while ((ret = getopt(argc, argv, "v")) >= 0)
107 if (argc > 1 && strcmp(argv[1], "-v") == 0)