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.
11 /* tests put and get with post/start/complete/wait on 2 processes */
13 /* same as test1.c but uses alloc_mem */
18 int main(int argc, char *argv[])
20 int rank, destrank, nprocs, *A, *B, i;
22 MPI_Group comm_group, group;
26 MTest_Init(&argc,&argv);
27 MPI_Comm_size(MPI_COMM_WORLD,&nprocs);
28 MPI_Comm_rank(MPI_COMM_WORLD,&rank);
31 printf("Run this program with 2 or more processes\n");
32 MPI_Abort(MPI_COMM_WORLD, 1);
35 MPI_Comm_split(MPI_COMM_WORLD, (rank < 2), rank, &CommDeuce);
40 i = MPI_Alloc_mem(SIZE2 * sizeof(int), MPI_INFO_NULL, &A);
42 printf("Can't allocate memory in test program\n");
43 MPI_Abort(MPI_COMM_WORLD, 1);
45 i = MPI_Alloc_mem(SIZE2 * sizeof(int), MPI_INFO_NULL, &B);
47 printf("Can't allocate memory in test program\n");
48 MPI_Abort(MPI_COMM_WORLD, 1);
51 MPI_Comm_group(CommDeuce, &comm_group);
54 for (i=0; i<SIZE2; i++) A[i] = B[i] = i;
55 MPI_Win_create(NULL, 0, 1, MPI_INFO_NULL, CommDeuce, &win);
57 MPI_Group_incl(comm_group, 1, &destrank, &group);
58 MPI_Win_start(group, 0, win);
59 for (i=0; i<SIZE1; i++)
60 MPI_Put(A+i, 1, MPI_INT, 1, i, 1, MPI_INT, win);
61 for (i=0; i<SIZE1; i++)
62 MPI_Get(B+i, 1, MPI_INT, 1, SIZE1+i, 1, MPI_INT, win);
64 MPI_Win_complete(win);
66 for (i=0; i<SIZE1; i++)
67 if (B[i] != (-4)*(i+SIZE1)) {
68 SQUELCH( printf("Get Error: B[i] is %d, should be %d\n", B[i], (-4)*(i+SIZE1)); );
73 for (i=0; i<SIZE2; i++) B[i] = (-4)*i;
74 MPI_Win_create(B, SIZE2*sizeof(int), sizeof(int), MPI_INFO_NULL, CommDeuce, &win);
76 MPI_Group_incl(comm_group, 1, &destrank, &group);
77 MPI_Win_post(group, 0, win);
80 for (i=0; i<SIZE1; i++) {
82 SQUELCH( printf("Put Error: B[i] is %d, should be %d\n", B[i], i); );
88 MPI_Group_free(&group);
89 MPI_Group_free(&comm_group);
95 MPI_Comm_free(&CommDeuce);