Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
fix+activate rma test
[simgrid.git] / teshsuite / smpi / mpich3-test / rma / wintest.c
1 /* -*- Mode: C; c-basic-offset:4 ; indent-tabs-mode:nil ; -*- */
2 /*
3  *  (C) 2001 by Argonne National Laboratory.
4  *      See COPYRIGHT in top-level directory.
5  */
6 #include "mpi.h"
7 #include "stdio.h"
8 #include "mpitest.h"
9
10 /* tests put and get with post/start/complete/test on 2 processes */
11 /* Same as test2.c, but uses win_test instead of win_wait */
12
13 #define SIZE1 10
14 #define SIZE2 20
15
16 int main(int argc, char *argv[])
17 {
18     int rank, destrank, nprocs, A[SIZE2], i;
19     MPI_Comm CommDeuce;
20     MPI_Group comm_group, group;
21     MPI_Win win;
22     int errs = 0, flag;
23
24     MTest_Init(&argc, &argv);
25     MPI_Comm_size(MPI_COMM_WORLD, &nprocs);
26     MPI_Comm_rank(MPI_COMM_WORLD, &rank);
27
28     if (nprocs < 2) {
29         printf("Run this program with 2 or more processes\n");
30         MPI_Abort(MPI_COMM_WORLD, 1);
31     }
32
33     MPI_Comm_split(MPI_COMM_WORLD, (rank < 2), rank, &CommDeuce);
34
35     if (rank < 2) {
36         MPI_Comm_group(CommDeuce, &comm_group);
37
38         if (rank == 0) {
39             int B[SIZE2];
40             for (i = 0; i < SIZE2; i++)
41                 A[i] = B[i] = i;
42 #ifdef USE_WIN_ALLOCATE
43             int *base_ptr = NULL;
44             MPI_Win_allocate(0, 1, MPI_INFO_NULL, CommDeuce, &base_ptr, &win);
45 #else
46             MPI_Win_create(NULL, 0, 1, MPI_INFO_NULL, CommDeuce, &win);
47 #endif
48             destrank = 1;
49             MPI_Group_incl(comm_group, 1, &destrank, &group);
50             MPI_Win_start(group, 0, win);
51             for (i = 0; i < SIZE1; i++)
52                 MPI_Put(A + i, 1, MPI_INT, 1, i, 1, MPI_INT, win);
53             for (i = 0; i < SIZE1; i++)
54                 MPI_Get(B + i, 1, MPI_INT, 1, SIZE1 + i, 1, MPI_INT, win);
55
56             MPI_Win_complete(win);
57
58             for (i = 0; i < SIZE1; i++)
59                 if (B[i] != (-4) * (i + SIZE1)) {
60                     printf("Get Error: B[i] is %d, should be %d\n", B[i], (-4) * (i + SIZE1));
61                     errs++;
62                 }
63         }
64         else {  /* rank=1 */
65 #ifdef USE_WIN_ALLOCATE
66             int *B;
67             MPI_Win_allocate(SIZE2 * sizeof(int), sizeof(int), MPI_INFO_NULL, CommDeuce, &B, &win);
68 #else
69             int B[SIZE2];
70             MPI_Win_create(B, SIZE2 * sizeof(int), sizeof(int), MPI_INFO_NULL, CommDeuce, &win);
71 #endif
72             MPI_Win_lock(MPI_LOCK_SHARED, rank, 0, win);
73             for (i = 0; i < SIZE2; i++)
74                 B[i] = (-4) * i;
75             MPI_Win_unlock(rank, win);
76
77             destrank = 0;
78             MPI_Group_incl(comm_group, 1, &destrank, &group);
79             MPI_Win_post(group, 0, win);
80             flag = 0;
81             while (!flag)
82                 MPI_Win_test(win, &flag);
83
84             for (i = 0; i < SIZE1; i++) {
85                 if (B[i] != i) {
86                     printf("Put Error: B[i] is %d, should be %d\n", B[i], i);
87                     errs++;
88                 }
89             }
90         }
91
92         MPI_Group_free(&group);
93         MPI_Group_free(&comm_group);
94         MPI_Win_free(&win);
95     }
96     MPI_Comm_free(&CommDeuce);
97     MTest_Finalize(errs);
98     MPI_Finalize();
99     return 0;
100 }