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++) A[i] = B[i] = i;
52 MPI_Win_create(NULL, 0, 1, MPI_INFO_NULL, CommDeuce, &win);
54 for (i=0; i<SIZE1; i++) {
55 MPI_Win_lock(MPI_LOCK_SHARED, 1, 0, win);
56 MPI_Put(A+i, 1, MPI_INT, 1, i, 1, MPI_INT, win);
57 MPI_Win_unlock(1, win);
60 for (i=0; i<SIZE1; i++) {
61 MPI_Win_lock(MPI_LOCK_SHARED, 1, 0, win);
62 MPI_Get(B+i, 1, MPI_INT, 1, SIZE1+i, 1, MPI_INT, win);
63 MPI_Win_unlock(1, win);
68 for (i=0; i<SIZE1; i++)
69 if (B[i] != (-4)*(i+SIZE1)) {
70 SQUELCH( printf("Get Error: B[%d] is %d, should be %d\n", i, B[i], (-4)*(i+SIZE1)); );
75 for (i=0; i<SIZE2; i++) B[i] = (-4)*i;
76 MPI_Win_create(B, SIZE2*sizeof(int), sizeof(int), MPI_INFO_NULL, CommDeuce, &win);
80 for (i=0; i<SIZE1; i++) {
82 SQUELCH( printf("Put Error: B[%d] is %d, should be %d\n", i, B[i], i); );
91 MPI_Comm_free(&CommDeuce);