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);
30 for (i=0; i<NROWS; i++)
31 for (j=0; j<NCOLS; j++)
32 A[i][j] = B[i][j] = i*NCOLS + j;
34 /* create datatype for one column */
35 MPI_Type_vector(NROWS, 1, NCOLS, MPI_INT, &column);
36 /* create datatype for matrix in column-major order */
37 MPI_Type_hvector(NCOLS, 1, sizeof(int), column, &xpose);
38 MPI_Type_commit(&xpose);
40 MPI_Win_create(B, NROWS*NCOLS*sizeof(int), sizeof(int), MPI_INFO_NULL, MPI_COMM_SELF, &win);
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++)
53 for (i=0; i<NROWS; i++)
55 if (B[j][i] != i*NCOLS + j + j*NCOLS + i)
59 printf("Error: B[%d][%d]=%d should be %d\n", j, i,
60 B[j][i], i*NCOLS + j + j*NCOLS + i);
68 printf("Total number of errors: %d\n", errs);