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 /** Contended RMA put test -- James Dinan <dinan@mcs.anl.gov>
9 * Each process issues COUNT put operations to non-overlapping locations on
10 * every other processs.
23 static const int verbose = 0;
31 double src_buf[MAXELEMS];
35 MPI_Alloc_mem(sizeof(double) * nproc * MAXELEMS, MPI_INFO_NULL, &dst_buf);
36 MPI_Win_create(dst_buf, sizeof(double) * nproc * MAXELEMS, 1, MPI_INFO_NULL,
37 MPI_COMM_WORLD, &dst_win);
39 for (i = 0; i < MAXELEMS; i++)
40 src_buf[i] = me + 1.0;
42 MPI_Win_lock(MPI_LOCK_EXCLUSIVE, me, 0, dst_win);
44 for (i = 0; i < nproc * MAXELEMS; i++)
47 MPI_Win_unlock(me, dst_win);
49 MPI_Barrier(MPI_COMM_WORLD);
51 for (i = 0; i < nproc; i++) {
52 /* int target = (me + i) % nproc; */
54 for (j = 0; j < COUNT; j++) {
56 printf("%2d -> %2d [%2d]\n", me, target, j);
57 MPI_Win_lock(MPI_LOCK_EXCLUSIVE, target, 0, dst_win);
58 MPI_Put(&src_buf[j], sizeof(double), MPI_BYTE, target,
59 (me * MAXELEMS + j) * sizeof(double), sizeof(double), MPI_BYTE, dst_win);
60 MPI_Win_unlock(target, dst_win);
64 MPI_Barrier(MPI_COMM_WORLD);
66 /* Check that the correct data was returned. This assumes that the
67 * systems have the same data representations */
68 for (i = 0; i < nproc; i++) {
69 for (j = 0; j < COUNT; j++) {
70 if (dst_buf[i * MAXELEMS + j] != 1.0 + i) {
72 printf("dst_buf[%d] = %e, expected %e\n",
73 i * MAXELEMS + j, dst_buf[i * MAXELEMS + j], 1.0 + i);
78 MPI_Win_free(&dst_win);
79 MPI_Free_mem(dst_buf);
85 int main(int argc, char *argv[])
89 MTest_Init(&argc, &argv);
90 MPI_Comm_size(MPI_COMM_WORLD, &nproc);
91 MPI_Comm_rank(MPI_COMM_WORLD, &me);
93 assert(COUNT <= MAXELEMS);
95 if (me == 0 && verbose) {
96 printf("Test starting on %d processes\n", nproc);
102 MPI_Barrier(MPI_COMM_WORLD);
104 MTest_Finalize(errs);
106 return MTestReturnValue(errs);