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];
16 /* helper functions */
17 static int parse_args(int argc, char **argv);
19 int main(int argc, char *argv[])
21 /* Variable declarations */
22 MPI_Datatype oneslice, twoslice, threeslice;
24 MPI_Aint sizeofint, bufsize, position;
29 /* Initialize a to some known values. */
30 for (i = 0; i < 100; i++) {
31 for (j = 0; j < 100; j++) {
32 for (k = 0; k < 100; k++) {
33 a[i][j][k] = i*1000000+j*1000+k;
39 MPI_Init(&argc, &argv);
40 MPI_Type_extent(MPI_INT, &sizeofint);
42 parse_args(argc, argv);
44 /* Create data types. */
45 /* NOTE: This differs from the way that it's done on the sheet. */
46 /* On the sheet, the slice is a[0, 2, 4, ..., 16][2-10][1-9]. */
47 /* Below, the slice is a[0-8][2-10][1, 3, 5, ..., 17]. */
48 MPI_Type_vector(9, 1, 2, MPI_INT, &oneslice);
49 MPI_Type_hvector(9, 1, 100*sizeofint, oneslice, &twoslice);
50 MPI_Type_hvector(9, 1, 100*100*sizeofint, twoslice, &threeslice);
52 MPI_Type_commit(&threeslice);
54 /* Pack it into a buffer. */
56 /* MPI_Pack_size(1, threeslice, MPI_COMM_WORLD, &bufsize); */
57 MPI_Pack_external_size((char*)"external32", 1, threeslice, &bufsize);
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",
72 /* Unpack the buffer into e. */
74 MPI_Unpack_external((char*)"external32",
81 /* Display errors, if any. */
82 for (i = 0; i < 9; i++) {
83 for (j = 0; j < 9; j++) {
84 for (k = 0; k < 9; k++) {
85 /* The truncation in integer division makes this safe. */
86 if (e[i][j][k] != a[i][j+2][k*2+1]) {
89 printf("Error in location %d x %d x %d: %d, should be %d.\n",
90 i, j, k, e[i][j][k], a[i][j+2][k*2+1]);
101 fprintf(stderr, "Found %d errors\n", errs);
104 printf(" No Errors\n");
107 MPI_Type_free(&oneslice);
108 MPI_Type_free(&twoslice);
109 MPI_Type_free(&threeslice);
117 static int parse_args(int argc, char **argv)
121 while ((ret = getopt(argc, argv, "v")) >= 0)