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 /* helper functions */
14 int parse_args(int argc, char **argv);
16 static int verbose = 0;
18 int main(int argc, char *argv[])
20 /* Variable declarations */
21 int a[100][100], b[100][100];
22 int disp[100], block[100];
25 int bufsize, position = 0;
30 /* Initialize a to some known values and zero out b. */
31 for(i = 0; i < 100; i++) {
32 for(j = 0; j < 100; j++) {
39 MTest_Init( &argc, &argv );
41 parse_args(argc, argv);
43 for(i = 0; i < 100; i++) {
44 /* Fortran version has disp(i) = 100*(i-1) + i and block(i) = 100-i. */
45 /* This code here is wrong. It compacts everything together,
46 * which isn't what we want.
47 * What we want is to put the lower triangular values into b and leave
48 * the rest of it unchanged, right?
54 /* Create datatype for lower triangular part. */
55 MPI_Type_indexed(100, block, disp, MPI_INT, <ype);
56 MPI_Type_commit(<ype);
59 MPI_Pack_size(1, ltype, MPI_COMM_WORLD, &bufsize);
60 buffer = (void *) malloc((unsigned) bufsize);
61 MPI_Pack( a, 1, ltype, buffer, bufsize, &position, MPI_COMM_WORLD );
63 /* Unpack the buffer into b. */
65 MPI_Unpack(buffer, bufsize, &position, b, 1, ltype, MPI_COMM_WORLD);
67 for(i = 0; i < 100; i++) {
68 for(j = 0; j < 100; j++) {
69 if (j > i && b[i][j] != 0) {
71 if (verbose) fprintf(stderr, "b[%d][%d] = %d; should be %d\n",
74 else if (j <= i && b[i][j] != 1000*i + j) {
76 if (verbose) fprintf(stderr, "b[%d][%d] = %d; should be %d\n",
77 i, j, b[i][j], 1000*i + j);
82 MTest_Finalize( errs );
87 int parse_args(int argc, char **argv)
91 while ((ret = getopt(argc, argv, "v")) >= 0)