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.
12 static int verbose = 0;
13 int a[100][100][100], e[9][9][9];
15 int main(int argc, char *argv[]);
17 /* helper functions */
18 static int parse_args(int argc, char **argv);
20 int main(int argc, char *argv[])
22 /* Variable declarations */
23 MPI_Datatype oneslice, twoslice, threeslice;
25 MPI_Aint sizeofint, bufsize, position;
30 /* Initialize a to some known values. */
31 for (i = 0; i < 100; i++) {
32 for (j = 0; j < 100; j++) {
33 for (k = 0; k < 100; k++) {
34 a[i][j][k] = i * 1000000 + j * 1000 + k;
40 MPI_Init(&argc, &argv);
41 MPI_Type_extent(MPI_INT, &sizeofint);
43 parse_args(argc, argv);
45 /* Create data types. */
46 /* NOTE: This differs from the way that it's done on the sheet. */
47 /* On the sheet, the slice is a[0, 2, 4, ..., 16][2-10][1-9]. */
48 /* Below, the slice is a[0-8][2-10][1, 3, 5, ..., 17]. */
49 MPI_Type_vector(9, 1, 2, MPI_INT, &oneslice);
50 MPI_Type_hvector(9, 1, 100 * sizeofint, oneslice, &twoslice);
51 MPI_Type_hvector(9, 1, 100 * 100 * sizeofint, twoslice, &threeslice);
53 MPI_Type_commit(&threeslice);
55 /* Pack it into a buffer. */
57 /* MPI_Pack_size(1, threeslice, MPI_COMM_WORLD, &bufsize); */
58 MPI_Pack_external_size((char *) "external32", 1, threeslice, &bufsize);
59 if (bufsize != 2916) {
60 fprintf(stderr, " Error on pack size! Got %d; expecting %d\n", (int) bufsize, 2916);
62 buffer = (void *) malloc((unsigned) bufsize);
64 /* -1 to indices on sheet to compensate for Fortran --> C */
65 MPI_Pack_external((char *) "external32",
66 &(a[0][2][1]), 1, threeslice, buffer, bufsize, &position);
68 /* Unpack the buffer into e. */
70 MPI_Unpack_external((char *) "external32", buffer, bufsize, &position, e, 9 * 9 * 9, MPI_INT);
72 /* Display errors, if any. */
73 for (i = 0; i < 9; i++) {
74 for (j = 0; j < 9; j++) {
75 for (k = 0; k < 9; k++) {
76 /* The truncation in integer division makes this safe. */
77 if (e[i][j][k] != a[i][j + 2][k * 2 + 1]) {
80 printf("Error in location %d x %d x %d: %d, should be %d.\n",
81 i, j, k, e[i][j][k], a[i][j + 2][k * 2 + 1]);
92 fprintf(stderr, "Found %d errors\n", errs);
95 printf(" No Errors\n");
98 MPI_Type_free(&oneslice);
99 MPI_Type_free(&twoslice);
100 MPI_Type_free(&threeslice);
108 static int parse_args(int argc, char **argv)
112 while ((ret = getopt(argc, argv, "v")) >= 0) {