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 /* This does a transpose with a get operation, fence, and derived
12 datatypes. Uses vector and hvector (Example 3.32 from MPI 1.1
13 Standard). Run on 2 processes */
18 int main(int argc, char *argv[])
20 int rank, nprocs, **A, *A_data, i, j;
23 MPI_Datatype column, xpose;
26 MTest_Init(&argc, &argv);
27 MPI_Comm_size(MPI_COMM_WORLD, &nprocs);
28 MPI_Comm_rank(MPI_COMM_WORLD, &rank);
31 printf("Run this program with 2 or more processes\n");
32 MPI_Abort(MPI_COMM_WORLD, 1);
35 MPI_Comm_split(MPI_COMM_WORLD, (rank < 2), rank, &CommDeuce);
38 A_data = (int *) malloc(NROWS * NCOLS * sizeof(int));
39 A = (int **) malloc(NROWS * sizeof(int *));
42 for (i = 1; i < NROWS; i++)
43 A[i] = A[i - 1] + NCOLS;
46 for (i = 0; i < NROWS; i++)
47 for (j = 0; j < NCOLS; j++)
50 /* create datatype for one column */
51 MPI_Type_vector(NROWS, 1, NCOLS, MPI_INT, &column);
52 /* create datatype for matrix in column-major order */
53 MPI_Type_hvector(NCOLS, 1, sizeof(int), column, &xpose);
54 MPI_Type_commit(&xpose);
56 MPI_Win_create(NULL, 0, 1, MPI_INFO_NULL, CommDeuce, &win);
58 MPI_Win_fence(0, win);
60 MPI_Get(&A[0][0], NROWS * NCOLS, MPI_INT, 1, 0, 1, xpose, win);
62 MPI_Type_free(&column);
63 MPI_Type_free(&xpose);
65 MPI_Win_fence(0, win);
67 for (j = 0; j < NCOLS; j++) {
68 for (i = 0; i < NROWS; i++) {
69 if (A[j][i] != i * NCOLS + j) {
71 printf("Error: A[%d][%d]=%d should be %d\n", j, i,
72 A[j][i], i * NCOLS + j);
79 printf("Total number of errors: %d\n", errs);
83 for (i = 0; i < NROWS; i++)
84 for (j = 0; j < NCOLS; j++)
85 A[i][j] = i * NCOLS + j;
87 MPI_Win_create(&A[0][0], NROWS * NCOLS * sizeof(int), sizeof(int), MPI_INFO_NULL,
89 MPI_Win_fence(0, win);
90 MPI_Win_fence(0, win);
96 MPI_Comm_free(&CommDeuce);