1 /*
2  * Copyright (C) by Argonne National Laboratory
3  *     See COPYRIGHT in top-level directory
4  */
5 
6 #include "mpi.h"
7 #include "stdio.h"
8 #include "mpitest.h"
9 #include "squelch.h"
10 
11 /* tests a series of Gets. Run on 2 processes. */
12 
13 /* same as test5.c but uses alloc_mem */
14 
15 #define SIZE 2000
16 
main(int argc,char * argv[])17 int main(int argc, char *argv[])
18 {
19     int rank, nprocs, i, *A, *B;
20     MPI_Comm CommDeuce;
21     MPI_Win win;
22     int errs = 0;
23 
24     MTest_Init(&argc, &argv);
25 
26     MPI_Comm_size(MPI_COMM_WORLD, &nprocs);
27     MPI_Comm_rank(MPI_COMM_WORLD, &rank);
28 
29     if (nprocs < 2) {
30         printf("Run this program with 2 or more processes\n");
31         MPI_Abort(MPI_COMM_WORLD, 1);
32     }
33 
34     MPI_Comm_split(MPI_COMM_WORLD, (rank < 2), rank, &CommDeuce);
35 
36     if (rank < 2) {
37         i = MPI_Alloc_mem(SIZE * sizeof(int), MPI_INFO_NULL, &A);
38         if (i) {
39             printf("Can't allocate memory in test program\n");
40             MPI_Abort(MPI_COMM_WORLD, 1);
41         }
42         i = MPI_Alloc_mem(SIZE * sizeof(int), MPI_INFO_NULL, &B);
43         if (i) {
44             printf("Can't allocate memory in test program\n");
45             MPI_Abort(MPI_COMM_WORLD, 1);
46         }
47 
48         if (rank == 0) {
49             for (i = 0; i < SIZE; i++)
50                 B[i] = 500 + i;
51             MPI_Win_create(B, SIZE * sizeof(int), sizeof(int), MPI_INFO_NULL, CommDeuce, &win);
52             MPI_Win_fence(0, win);
53             for (i = 0; i < SIZE; i++) {
54                 A[i] = i + 100;
55                 MPI_Get(&A[i], 1, MPI_INT, 1, i, 1, MPI_INT, win);
56             }
57             MPI_Win_fence(0, win);
58             for (i = 0; i < SIZE; i++)
59                 if (A[i] != 1000 + i) {
60                     SQUELCH(printf("Rank 0: A[%d] is %d, should be %d\n", i, A[i], 1000 + i););
61                     errs++;
62                 }
63         }
64         if (rank == 1) {
65             for (i = 0; i < SIZE; i++)
66                 A[i] = 1000 + i;
67             MPI_Win_create(A, SIZE * sizeof(int), sizeof(int), MPI_INFO_NULL, CommDeuce, &win);
68             MPI_Win_fence(0, win);
69             for (i = 0; i < SIZE; i++) {
70                 B[i] = i + 200;
71                 MPI_Get(&B[i], 1, MPI_INT, 0, i, 1, MPI_INT, win);
72             }
73             MPI_Win_fence(0, win);
74             for (i = 0; i < SIZE; i++)
75                 if (B[i] != 500 + i) {
76                     SQUELCH(printf("Rank 1: B[%d] is %d, should be %d\n", i, B[i], 500 + i););
77                     errs++;
78                 }
79         }
80 
81         MPI_Win_free(&win);
82 
83         MPI_Free_mem(A);
84         MPI_Free_mem(B);
85     }
86 
87     MPI_Comm_free(&CommDeuce);
88     MTest_Finalize(errs);
89     return MTestReturnValue(errs);
90 }
91