Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Revert "[TESTS] SMPI/MPICH3: Fix failing rma test"
[simgrid.git] / teshsuite / smpi / mpich3-test / rma / test2_am.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 #include "squelch.h"
10
11 /* tests put and get with post/start/complete/wait on 2 processes */
12
13 /* same as test1.c but uses alloc_mem */
14
15 #define SIZE1 100
16 #define SIZE2 200
17
18 int main(int argc, char *argv[])
19 {
20     int rank, destrank, nprocs, *A, *B, i;
21     MPI_Comm CommDeuce;
22     MPI_Group comm_group, group;
23     MPI_Win win;
24     int errs = 0;
25
26     MTest_Init(&argc, &argv);
27     MPI_Comm_size(MPI_COMM_WORLD, &nprocs);
28     MPI_Comm_rank(MPI_COMM_WORLD, &rank);
29
30     if (nprocs < 2) {
31         printf("Run this program with 2 or more processes\n");
32         MPI_Abort(MPI_COMM_WORLD, 1);
33     }
34
35     MPI_Comm_split(MPI_COMM_WORLD, (rank < 2), rank, &CommDeuce);
36
37     if (rank < 2) {
38
39         i = MPI_Alloc_mem(SIZE2 * sizeof(int), MPI_INFO_NULL, &A);
40         if (i) {
41             printf("Can't allocate memory in test program\n");
42             MPI_Abort(MPI_COMM_WORLD, 1);
43         }
44
45         MPI_Comm_group(CommDeuce, &comm_group);
46
47         if (rank == 0) {
48             i = MPI_Alloc_mem(SIZE2 * sizeof(int), MPI_INFO_NULL, &B);
49             if (i) {
50                 printf("Can't allocate memory in test program\n");
51                 MPI_Abort(MPI_COMM_WORLD, 1);
52             }
53
54             for (i = 0; i < SIZE2; i++)
55                 A[i] = B[i] = i;
56 #ifdef USE_WIN_ALLOCATE
57             char *base_ptr;
58             MPI_Win_allocate(0, 1, MPI_INFO_NULL, CommDeuce, &base_ptr, &win);
59 #else
60             MPI_Win_create(NULL, 0, 1, MPI_INFO_NULL, CommDeuce, &win);
61 #endif
62             destrank = 1;
63             MPI_Group_incl(comm_group, 1, &destrank, &group);
64             MPI_Win_start(group, 0, win);
65             for (i = 0; i < SIZE1; i++)
66                 MPI_Put(A + i, 1, MPI_INT, 1, i, 1, MPI_INT, win);
67             for (i = 0; i < SIZE1; i++)
68                 MPI_Get(B + i, 1, MPI_INT, 1, SIZE1 + i, 1, MPI_INT, win);
69
70             MPI_Win_complete(win);
71
72             for (i = 0; i < SIZE1; i++)
73                 if (B[i] != (-4) * (i + SIZE1)) {
74                     SQUELCH(printf
75                             ("Get Error: B[i] is %d, should be %d\n", B[i], (-4) * (i + SIZE1)););
76                     errs++;
77                 }
78
79             MPI_Free_mem(B);
80         }
81         else if (rank == 1) {
82 #ifdef USE_WIN_ALLOCATE
83             MPI_Win_allocate(SIZE2 * sizeof(int), sizeof(int), MPI_INFO_NULL, CommDeuce, &B, &win);
84 #else
85             i = MPI_Alloc_mem(SIZE2 * sizeof(int), MPI_INFO_NULL, &B);
86             if (i) {
87                 printf("Can't allocate memory in test program\n");
88                 MPI_Abort(MPI_COMM_WORLD, 1);
89             }
90             MPI_Win_create(B, SIZE2 * sizeof(int), sizeof(int), MPI_INFO_NULL, CommDeuce, &win);
91 #endif
92             MPI_Win_lock(MPI_LOCK_SHARED, rank, 0, win);
93             for (i = 0; i < SIZE2; i++)
94                 B[i] = (-4) * i;
95             MPI_Win_unlock(rank, win);
96
97             destrank = 0;
98             MPI_Group_incl(comm_group, 1, &destrank, &group);
99             MPI_Win_post(group, 0, win);
100             MPI_Win_wait(win);
101
102             for (i = 0; i < SIZE1; i++) {
103                 if (B[i] != i) {
104                     SQUELCH(printf("Put Error: B[i] is %d, should be %d\n", B[i], i););
105                     errs++;
106                 }
107             }
108 #ifndef USE_WIN_ALLOCATE
109             MPI_Free_mem(B);
110 #endif
111         }
112
113         MPI_Group_free(&group);
114         MPI_Group_free(&comm_group);
115         MPI_Win_free(&win);
116         MPI_Free_mem(A);
117     }
118
119     MPI_Comm_free(&CommDeuce);
120     MTest_Finalize(errs);
121     MPI_Finalize();
122     return 0;
123 }