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];
20 /* helper functions */
21 static int parse_args(int argc, char **argv);
23 int main(int argc, char *argv[])
25 /* Variable declarations */
26 MPI_Datatype oneslice, twoslice, threeslice;
30 int bufsize, position;
35 /* Initialize a to some known values. */
36 for (i = 0; i < 100; i++) {
37 for (j = 0; j < 100; j++) {
38 for (k = 0; k < 100; k++) {
39 a[i][j][k] = i*1000000+j*1000+k;
45 MPI_Init(&argc, &argv);
46 MPI_Type_extent(MPI_INT, &sizeofint);
48 parse_args(argc, argv);
50 /* Create data types. */
51 /* NOTE: This differs from the way that it's done on the sheet. */
52 /* On the sheet, the slice is a[0, 2, 4, ..., 16][2-10][1-9]. */
53 /* Below, the slice is a[0-8][2-10][1, 3, 5, ..., 17]. */
54 MPI_Type_vector(9, 1, 2, MPI_INT, &oneslice);
55 MPI_Type_hvector(9, 1, 100*sizeofint, oneslice, &twoslice);
56 MPI_Type_hvector(9, 1, 100*100*sizeofint, twoslice, &threeslice);
58 MPI_Type_commit(&threeslice);
60 /* Pack it into a buffer. */
62 MPI_Pack_size(1, threeslice, MPI_COMM_WORLD, &bufsize);
63 buffer = (void *) malloc((unsigned) bufsize);
65 /* -1 to indices on sheet to compensate for Fortran --> C */
66 MPI_Pack(&(a[0][2][1]),
73 /* Unpack the buffer into e. */
82 /* Display errors, if any. */
83 for (i = 0; i < 9; i++) {
84 for (j = 0; j < 9; j++) {
85 for (k = 0; k < 9; k++) {
86 /* The truncation in integer division makes this safe. */
87 if (e[i][j][k] != a[i][j+2][k*2+1]) {
90 printf("Error in location %d x %d x %d: %d, should be %d.\n",
91 i, j, k, e[i][j][k], a[i][j+2][k*2+1]);
102 fprintf(stderr, "Found %d errors\n", errs);
105 printf(" No Errors\n");
108 MPI_Type_free(&oneslice);
109 MPI_Type_free(&twoslice);
110 MPI_Type_free(&threeslice);
118 static int parse_args(int argc, char **argv)
123 while ((ret = getopt(argc, argv, "v")) >= 0)
132 if (argc > 1 && strcmp(argv[1], "-v") == 0)