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.
13 int main(int argc, char *argv[]);
15 /* helper functions */
16 int parse_args(int argc, char **argv);
18 static int verbose = 0;
20 int main(int argc, char *argv[])
22 /* Variable declarations */
23 int a[100][100], b[100][100];
24 int disp[100], block[100];
27 int bufsize, position = 0;
32 /* Initialize a to some known values and zero out b. */
33 for(i = 0; i < 100; i++) {
34 for(j = 0; j < 100; j++) {
41 MTest_Init( &argc, &argv );
43 parse_args(argc, argv);
45 for(i = 0; i < 100; i++) {
46 /* Fortran version has disp(i) = 100*(i-1) + i and block(i) = 100-i. */
47 /* This code here is wrong. It compacts everything together,
48 * which isn't what we want.
49 * What we want is to put the lower triangular values into b and leave
50 * the rest of it unchanged, right?
56 /* Create datatype for lower triangular part. */
57 MPI_Type_indexed(100, block, disp, MPI_INT, <ype);
58 MPI_Type_commit(<ype);
61 MPI_Pack_size(1, ltype, MPI_COMM_WORLD, &bufsize);
62 buffer = (void *) malloc((unsigned) bufsize);
63 MPI_Pack( a, 1, ltype, buffer, bufsize, &position, MPI_COMM_WORLD );
65 /* Unpack the buffer into b. */
67 MPI_Unpack(buffer, bufsize, &position, b, 1, ltype, MPI_COMM_WORLD);
69 for(i = 0; i < 100; i++) {
70 for(j = 0; j < 100; j++) {
71 if (j > i && b[i][j] != 0) {
73 if (verbose) fprintf(stderr, "b[%d][%d] = %d; should be %d\n",
76 else if (j <= i && b[i][j] != 1000*i + j) {
78 if (verbose) fprintf(stderr, "b[%d][%d] = %d; should be %d\n",
79 i, j, b[i][j], 1000*i + j);
84 MTest_Finalize( errs );
89 int parse_args(int argc, char **argv)
93 while ((ret = getopt(argc, argv, "v")) >= 0)