1 /* -*- Mode: C; c-basic-offset:4 ; indent-tabs-mode:nil ; -*- */
4 * (C) 2010 by Argonne National Laboratory.
5 * See COPYRIGHT in top-level directory.
14 /* Test the given operation within a Fence epoch */
15 #define TEST_FENCE_OP(op_name_, fcn_call_) \
21 MTestPrintErrorMsg("Zero-byte op " op_name_, err); \
24 err = MPI_Win_fence(0, win); \
28 MTestPrintErrorMsg("Fence after " op_name_, err); \
34 /* Test the given operation within a passive target epoch */
35 #define TEST_PT_OP(op_name_, fcn_call_) \
37 err = MPI_Win_lock(MPI_LOCK_EXCLUSIVE, TARGET, 0, win); \
41 MTestPrintErrorMsg("Lock before" op_name_, err); \
48 MTestPrintErrorMsg("Zero-byte op " op_name_, err); \
51 err = MPI_Win_unlock(TARGET, win); \
55 MTestPrintErrorMsg("Unlock after " op_name_, err); \
61 /* Test the given request-based operation within a passive target epoch */
62 #define TEST_REQ_OP(op_name_, req_, fcn_call_) \
64 err = MPI_Win_lock(MPI_LOCK_EXCLUSIVE, TARGET, 0, win); \
68 MTestPrintErrorMsg("Lock before" op_name_, err); \
75 MTestPrintErrorMsg("Zero-byte op " op_name_, err); \
78 err = MPI_Win_unlock(TARGET, win); \
82 MTestPrintErrorMsg("Unlock after " op_name_, err); \
85 err = MPI_Wait(&req_, MPI_STATUS_IGNORE); \
89 MTestPrintErrorMsg("Wait after " op_name_, err); \
95 static char MTEST_Descrip[] = "Test handling of zero-byte transfers";
98 int main(int argc, char *argv[])
104 int *rmabuf, rsize, rcount;
108 MPI_Datatype derived_dtp;
110 MTest_Init(&argc, &argv);
112 bufsize = 256 * sizeof(int);
113 buf = (int *) malloc(bufsize);
115 fprintf(stderr, "Unable to allocated %d bytes\n", bufsize);
116 MPI_Abort(MPI_COMM_WORLD, 1);
118 result = (int *) malloc(bufsize);
120 fprintf(stderr, "Unable to allocated %d bytes\n", bufsize);
121 MPI_Abort(MPI_COMM_WORLD, 1);
124 rsize = rcount * sizeof(int);
125 rmabuf = (int *) malloc(rsize);
127 fprintf(stderr, "Unable to allocated %d bytes\n", rsize);
128 MPI_Abort(MPI_COMM_WORLD, 1);
131 MPI_Type_contiguous(2, MPI_INT, &derived_dtp);
132 MPI_Type_commit(&derived_dtp);
134 /* The following loop is used to run through a series of communicators
135 * that are subsets of MPI_COMM_WORLD, of size 1 or greater. */
136 while (MTestGetIntracommGeneral(&comm, 1, 1)) {
139 if (comm == MPI_COMM_NULL)
141 /* Determine the sender and receiver */
142 MPI_Comm_rank(comm, &rank);
143 MPI_Comm_size(comm, &size);
145 MPI_Win_create(buf, bufsize, 2 * sizeof(int), MPI_INFO_NULL, comm, &win);
146 /* To improve reporting of problems about operations, we
147 * change the error handler to errors return */
148 MPI_Win_set_errhandler(win, MPI_ERRORS_RETURN);
150 /** TEST OPERATIONS USING ACTIVE TARGET (FENCE) SYNCHRONIZATION **/
151 MPI_Win_fence(0, win);
153 TEST_FENCE_OP("Put", MPI_Put(rmabuf, count, MPI_INT, TARGET, 0, count, MPI_INT, win);
156 TEST_FENCE_OP("Get", MPI_Get(rmabuf, count, MPI_INT, TARGET, 0, count, MPI_INT, win);
158 TEST_FENCE_OP("Accumulate",
159 MPI_Accumulate(rmabuf, count, MPI_INT, TARGET,
160 0, count, MPI_INT, MPI_SUM, win);
162 TEST_FENCE_OP("Accumulate_derived",
163 MPI_Accumulate(rmabuf, count, derived_dtp, TARGET,
164 0, count, derived_dtp, MPI_SUM, win);
166 TEST_FENCE_OP("Get accumulate",
167 MPI_Get_accumulate(rmabuf, count, MPI_INT, result,
168 count, MPI_INT, TARGET, 0, count, MPI_INT, MPI_SUM, win);
170 /* Note: It's not possible to generate a zero-byte FOP or CAS */
172 /** TEST OPERATIONS USING PASSIVE TARGET SYNCHRONIZATION **/
174 TEST_PT_OP("Put", MPI_Put(rmabuf, count, MPI_INT, TARGET, 0, count, MPI_INT, win);
176 TEST_PT_OP("Get", MPI_Get(rmabuf, count, MPI_INT, TARGET, 0, count, MPI_INT, win);
178 TEST_PT_OP("Accumulate",
179 MPI_Accumulate(rmabuf, count, MPI_INT, TARGET, 0, count, MPI_INT, MPI_SUM, win);
181 TEST_PT_OP("Accumulate_derived",
182 MPI_Accumulate(rmabuf, count, derived_dtp, TARGET, 0,
183 count, derived_dtp, MPI_SUM, win);
185 TEST_PT_OP("Get accumulate",
186 MPI_Get_accumulate(rmabuf, count, MPI_INT, result, count,
187 MPI_INT, TARGET, 0, count, MPI_INT, MPI_SUM, win);
190 /* Note: It's not possible to generate a zero-byte FOP or CAS */
192 /** TEST REQUEST-BASED OPERATIONS (PASSIVE TARGET ONLY) **/
194 TEST_REQ_OP("Rput", req,
195 MPI_Rput(rmabuf, count, MPI_INT, TARGET, 0, count, MPI_INT, win, &req);
197 TEST_REQ_OP("Rget", req,
198 MPI_Rget(rmabuf, count, MPI_INT, TARGET, 0, count, MPI_INT, win, &req);
200 TEST_REQ_OP("Raccumulate", req,
201 MPI_Raccumulate(rmabuf, count, MPI_INT, TARGET, 0,
202 count, MPI_INT, MPI_SUM, win, &req);
204 TEST_REQ_OP("Raccumulate_derived", req,
205 MPI_Raccumulate(rmabuf, count, derived_dtp, TARGET, 0,
206 count, derived_dtp, MPI_SUM, win, &req);
208 TEST_REQ_OP("Rget_accumulate", req,
209 MPI_Rget_accumulate(rmabuf, count, MPI_INT, result,
210 count, MPI_INT, TARGET, 0,
211 count, MPI_INT, MPI_SUM, win, &req);
215 MTestFreeComm(&comm);
218 MPI_Type_free(&derived_dtp);
223 MTest_Finalize(errs);