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;
17 int a[100][100][100], e[9][9][9];
19 int main(int argc, char *argv[]);
21 /* helper functions */
22 static int parse_args(int argc, char **argv);
24 int main(int argc, char *argv[])
26 /* Variable declarations */
27 MPI_Datatype oneslice, twoslice, threeslice;
31 int bufsize, position;
36 /* Initialize a to some known values. */
37 for (i = 0; i < 100; i++) {
38 for (j = 0; j < 100; j++) {
39 for (k = 0; k < 100; k++) {
40 a[i][j][k] = i * 1000000 + j * 1000 + k;
46 MPI_Init(&argc, &argv);
47 MPI_Type_extent(MPI_INT, &sizeofint);
49 parse_args(argc, argv);
51 /* Create data types. */
52 /* NOTE: This differs from the way that it's done on the sheet. */
53 /* On the sheet, the slice is a[0, 2, 4, ..., 16][2-10][1-9]. */
54 /* Below, the slice is a[0-8][2-10][1, 3, 5, ..., 17]. */
55 MPI_Type_vector(9, 1, 2, MPI_INT, &oneslice);
56 MPI_Type_hvector(9, 1, 100 * sizeofint, oneslice, &twoslice);
57 MPI_Type_hvector(9, 1, 100 * 100 * sizeofint, twoslice, &threeslice);
59 MPI_Type_commit(&threeslice);
61 /* Pack it into a buffer. */
63 MPI_Pack_size(1, threeslice, MPI_COMM_WORLD, &bufsize);
64 buffer = (void *) malloc((unsigned) bufsize);
66 /* -1 to indices on sheet to compensate for Fortran --> C */
67 MPI_Pack(&(a[0][2][1]), 1, threeslice, buffer, bufsize, &position, MPI_COMM_WORLD);
69 /* Unpack the buffer into e. */
71 MPI_Unpack(buffer, bufsize, &position, e, 9 * 9 * 9, MPI_INT, MPI_COMM_WORLD);
73 /* Display errors, if any. */
74 for (i = 0; i < 9; i++) {
75 for (j = 0; j < 9; j++) {
76 for (k = 0; k < 9; k++) {
77 /* The truncation in integer division makes this safe. */
78 if (e[i][j][k] != a[i][j + 2][k * 2 + 1]) {
81 printf("Error in location %d x %d x %d: %d, should be %d.\n",
82 i, j, k, e[i][j][k], a[i][j + 2][k * 2 + 1]);
93 fprintf(stderr, "Found %d errors\n", errs);
96 printf(" No Errors\n");
99 MPI_Type_free(&oneslice);
100 MPI_Type_free(&twoslice);
101 MPI_Type_free(&threeslice);
109 static int parse_args(int argc, char **argv)
114 * while ((ret = getopt(argc, argv, "v")) >= 0)
123 if (argc > 1 && strcmp(argv[1], "-v") == 0)