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.
12 /* tests passive target RMA on 2 processes. tests the lock-single_op-unlock
15 /* same as test4.c but uses alloc_mem */
20 int main(int argc, char *argv[])
22 int rank, nprocs, *A, *B, i;
27 MTest_Init(&argc, &argv);
28 MPI_Comm_size(MPI_COMM_WORLD, &nprocs);
29 MPI_Comm_rank(MPI_COMM_WORLD, &rank);
32 printf("Run this program with 2 or more processes\n");
33 MPI_Abort(MPI_COMM_WORLD, 1);
36 MPI_Comm_split(MPI_COMM_WORLD, (rank < 2), rank, &CommDeuce);
39 i = MPI_Alloc_mem(SIZE2 * sizeof(int), MPI_INFO_NULL, &A);
41 printf("Can't allocate memory in test program\n");
42 MPI_Abort(MPI_COMM_WORLD, 1);
44 i = MPI_Alloc_mem(SIZE2 * sizeof(int), MPI_INFO_NULL, &B);
46 printf("Can't allocate memory in test program\n");
47 MPI_Abort(MPI_COMM_WORLD, 1);
51 for (i = 0; i < SIZE2; i++)
53 MPI_Win_create(NULL, 0, 1, MPI_INFO_NULL, CommDeuce, &win);
55 for (i = 0; i < SIZE1; i++) {
56 MPI_Win_lock(MPI_LOCK_SHARED, 1, 0, win);
57 MPI_Put(A + i, 1, MPI_INT, 1, i, 1, MPI_INT, win);
58 MPI_Win_unlock(1, win);
61 for (i = 0; i < SIZE1; i++) {
62 MPI_Win_lock(MPI_LOCK_SHARED, 1, 0, win);
63 MPI_Get(B + i, 1, MPI_INT, 1, SIZE1 + i, 1, MPI_INT, win);
64 MPI_Win_unlock(1, win);
69 for (i = 0; i < SIZE1; i++)
70 if (B[i] != (-4) * (i + SIZE1)) {
72 ("Get Error: B[%d] is %d, should be %d\n", i, B[i],
73 (-4) * (i + SIZE1)););
78 for (i = 0; i < SIZE2; i++)
80 MPI_Win_create(B, SIZE2 * sizeof(int), sizeof(int), MPI_INFO_NULL, CommDeuce, &win);
84 for (i = 0; i < SIZE1; i++) {
86 SQUELCH(printf("Put Error: B[%d] is %d, should be %d\n", i, B[i], i););
95 MPI_Comm_free(&CommDeuce);