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.
10 /* This does a local transpose-cum-accumulate operation. Uses
11 vector and hvector datatypes (Example 3.32 from MPI 1.1
12 Standard). Run on 1 process. */
17 int main(int argc, char *argv[])
19 int rank, nprocs, A[NROWS][NCOLS], B[NROWS][NCOLS], i, j;
21 MPI_Datatype column, xpose;
24 MTest_Init(&argc, &argv);
25 MPI_Comm_rank(MPI_COMM_WORLD, &rank);
26 MPI_Comm_size(MPI_COMM_WORLD, &nprocs);
29 for (i = 0; i < NROWS; i++)
30 for (j = 0; j < NCOLS; j++)
31 A[i][j] = B[i][j] = i * NCOLS + j;
33 /* create datatype for one column */
34 MPI_Type_vector(NROWS, 1, NCOLS, MPI_INT, &column);
35 /* create datatype for matrix in column-major order */
36 MPI_Type_hvector(NCOLS, 1, sizeof(int), column, &xpose);
37 MPI_Type_commit(&xpose);
39 MPI_Win_create(B, NROWS * NCOLS * sizeof(int), sizeof(int), MPI_INFO_NULL, MPI_COMM_SELF,
42 MPI_Win_fence(0, win);
44 MPI_Accumulate(A, NROWS * NCOLS, MPI_INT, 0, 0, 1, xpose, MPI_SUM, win);
46 MPI_Type_free(&column);
47 MPI_Type_free(&xpose);
49 MPI_Win_fence(0, win);
51 for (j = 0; j < NCOLS; j++) {
52 for (i = 0; i < NROWS; i++) {
53 if (B[j][i] != i * NCOLS + j + j * NCOLS + i) {
55 printf("Error: B[%d][%d]=%d should be %d\n", j, i,
56 B[j][i], i * NCOLS + j + j * NCOLS + i);
63 printf("Total number of errors: %d\n", errs);