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 a series of puts, gets, and accumulate on 2 processes using fence */
13 /* same as test1.c but uses alloc_mem */
17 int main(int argc, char *argv[])
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);
38 i = MPI_Alloc_mem(SIZE * sizeof(int), MPI_INFO_NULL, &A);
40 printf("Can't allocate memory in test program\n");
41 MPI_Abort(MPI_COMM_WORLD, 1);
43 i = MPI_Alloc_mem(SIZE * sizeof(int), MPI_INFO_NULL, &B);
45 printf("Can't allocate memory in test program\n");
46 MPI_Abort(MPI_COMM_WORLD, 1);
50 for (i=0; i<SIZE; i++)
54 for (i=0; i<SIZE; i++) {
60 MPI_Win_create(B, SIZE*sizeof(int), sizeof(int), MPI_INFO_NULL, CommDeuce, &win);
62 MPI_Win_fence(0, win);
65 for (i=0; i<SIZE-1; i++)
66 MPI_Put(A+i, 1, MPI_INT, 1, i, 1, MPI_INT, win);
69 for (i=0; i<SIZE-1; i++)
70 MPI_Get(A+i, 1, MPI_INT, 0, i, 1, MPI_INT, win);
72 MPI_Accumulate(A+i, 1, MPI_INT, 0, i, 1, MPI_INT, MPI_SUM, win);
74 MPI_Win_fence(0, win);
77 for (i=0; i<SIZE-1; i++) {
79 SQUELCH( printf("Put/Get Error: A[i]=%d, B[i]=%d\n", A[i], B[i]); );
85 if (B[SIZE-1] != SIZE - 1 - 3*(SIZE-1)) {
86 SQUELCH( printf("Accumulate Error: B[SIZE-1] is %d, should be %d\n", B[SIZE-1], SIZE - 1 - 3*(SIZE-1)); );
95 MPI_Comm_free(&CommDeuce);