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.
7 /* One-Sided MPI 2-D Strided Get Test
9 * Author: James Dinan <dinan@mcs.anl.gov>
10 * Date : December, 2010
12 * This code performs N strided get operations from a 2d patch of a shared
13 * array. The array has dimensions [X, Y] and the subarray has dimensions
14 * [SUB_X, SUB_Y] and begins at index [0, 0]. The input and output buffers are
15 * specified using an MPI indexed type.
30 int main(int argc, char **argv)
32 int i, j, rank, nranks, peer, bufsize, errors;
33 double *win_buf, *loc_buf;
36 int idx_rem[SUB_YDIM];
37 int blk_len[SUB_YDIM];
38 MPI_Datatype loc_type, rem_type;
40 MTest_Init(&argc, &argv);
42 MPI_Comm_rank(MPI_COMM_WORLD, &rank);
43 MPI_Comm_size(MPI_COMM_WORLD, &nranks);
45 bufsize = XDIM * YDIM * sizeof(double);
46 MPI_Alloc_mem(bufsize, MPI_INFO_NULL, &win_buf);
47 MPI_Alloc_mem(bufsize, MPI_INFO_NULL, &loc_buf);
49 for (i = 0; i < XDIM * YDIM; i++) {
50 *(win_buf + i) = 1.0 + rank;
51 *(loc_buf + i) = -1.0;
54 MPI_Win_create(win_buf, bufsize, 1, MPI_INFO_NULL, MPI_COMM_WORLD, &buf_win);
56 peer = (rank + 1) % nranks;
58 /* Build the datatype */
60 for (i = 0; i < SUB_YDIM; i++) {
61 idx_rem[i] = i * XDIM;
62 blk_len[i] = SUB_XDIM;
65 MPI_Type_indexed(SUB_YDIM, blk_len, idx_rem, MPI_DOUBLE, &loc_type);
66 MPI_Type_indexed(SUB_YDIM, blk_len, idx_rem, MPI_DOUBLE, &rem_type);
68 MPI_Type_commit(&loc_type);
69 MPI_Type_commit(&rem_type);
71 /* Perform get operation */
73 MPI_Win_lock(MPI_LOCK_EXCLUSIVE, peer, 0, buf_win);
75 MPI_Get(loc_buf, 1, loc_type, peer, 0, 1, rem_type, buf_win);
77 /* Use the datatype only on the remote side (must have SUB_XDIM == XDIM) */
78 /* MPI_Get(loc_buf, SUB_XDIM*SUB_YDIM, MPI_DOUBLE, peer, 0, 1, rem_type, buf_win); */
80 MPI_Win_unlock(peer, buf_win);
82 MPI_Type_free(&loc_type);
83 MPI_Type_free(&rem_type);
85 MPI_Barrier(MPI_COMM_WORLD);
87 /* Verify that the results are correct */
90 for (i = 0; i < SUB_XDIM; i++) {
91 for (j = 0; j < SUB_YDIM; j++) {
92 const double actual = *(loc_buf + i + j * XDIM);
93 const double expected = (1.0 + peer);
94 if (fabs(actual - expected) > 1.0e-10) {
95 SQUELCH(printf("%d: Data validation failed at [%d, %d] expected=%f actual=%f\n",
96 rank, j, i, expected, actual););
102 for (i = SUB_XDIM; i < XDIM; i++) {
103 for (j = 0; j < SUB_YDIM; j++) {
104 const double actual = *(loc_buf + i + j * XDIM);
105 const double expected = -1.0;
106 if (fabs(actual - expected) > 1.0e-10) {
107 SQUELCH(printf("%d: Data validation failed at [%d, %d] expected=%f actual=%f\n",
108 rank, j, i, expected, actual););
114 for (i = 0; i < XDIM; i++) {
115 for (j = SUB_YDIM; j < YDIM; j++) {
116 const double actual = *(loc_buf + i + j * XDIM);
117 const double expected = -1.0;
118 if (fabs(actual - expected) > 1.0e-10) {
119 SQUELCH(printf("%d: Data validation failed at [%d, %d] expected=%f actual=%f\n",
120 rank, j, i, expected, actual););
127 MPI_Win_free(&buf_win);
128 MPI_Free_mem(win_buf);
129 MPI_Free_mem(loc_buf);
131 MTest_Finalize(errors);
133 return MTestReturnValue(errors);