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.
22 static const int verbose = 0;
29 MPI_Comm_size(MPI_COMM_WORLD, &nproc);
30 MPI_Comm_rank(MPI_COMM_WORLD, &me);
32 assert(COUNT <= MAXELEMS);
34 if (me == 0 && verbose) {
35 printf("Test starting on %d processes\n", nproc);
41 double src_buf[MAXELEMS];
45 MPI_Alloc_mem(sizeof(double) * nproc * MAXELEMS, MPI_INFO_NULL, &dst_buf);
46 MPI_Win_create(dst_buf, sizeof(double) * nproc * MAXELEMS, 1, MPI_INFO_NULL,
47 MPI_COMM_WORLD, &dst_win);
49 for (i = 0; i < MAXELEMS; i++)
50 src_buf[i] = me + 1.0;
52 MPI_Win_lock(MPI_LOCK_EXCLUSIVE, me, 0, dst_win);
54 for (i = 0; i < nproc * MAXELEMS; i++)
57 MPI_Win_unlock(me, dst_win);
59 MPI_Barrier(MPI_COMM_WORLD);
61 for (i = 0; i < nproc; i++) {
62 /* int target = (me + i) % nproc; */
64 for (j = 0; j < COUNT; j++) {
66 printf("%2d -> %2d [%2d]\n", me, target, j);
67 MPI_Win_lock(MPI_LOCK_EXCLUSIVE, target, 0, dst_win);
68 MPI_Put(&src_buf[j], sizeof(double), MPI_BYTE, target,
69 (me * MAXELEMS + j) * sizeof(double), sizeof(double), MPI_BYTE, dst_win);
70 MPI_Win_unlock(target, dst_win);
74 MPI_Barrier(MPI_COMM_WORLD);
76 /* Check that the correct data was returned. This assumes that the
77 * systems have the same data representations */
78 for (i = 0; i < nproc; i++) {
79 for (j = 0; j < COUNT; j++) {
80 if (dst_buf[i * MAXELEMS + j] != 1.0 + i) {
82 printf("dst_buf[%d] = %e, expected %e\n",
83 i * MAXELEMS + j, dst_buf[i * MAXELEMS + j], 1.0 + i);
88 MPI_Win_free(&dst_win);
89 MPI_Free_mem(dst_buf);
95 int main(int argc, char *argv[])
99 MTest_Init(&argc, &argv);
103 MPI_Barrier(MPI_COMM_WORLD);
105 MTest_Finalize(errs);
107 return MTestReturnValue(errs);