Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
This particular RMA test is filled with stupid calls... We send errors for most of...
[simgrid.git] / teshsuite / smpi / mpich3-test / rma / test1_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 a series of puts, gets, and accumulate on 2 processes using fence */
12
13 /* same as test1.c but uses alloc_mem */
14
15 #define SIZE 100
16
17 int main(int argc, char *argv[])
18 {
19     int rank, nprocs, i;
20     MPI_Comm CommDeuce;
21     int *A, *B;
22
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         i = MPI_Alloc_mem(SIZE * sizeof(int), MPI_INFO_NULL, &A);
39         if (i) {
40             printf("Can't allocate memory in test program\n");
41             MPI_Abort(MPI_COMM_WORLD, 1);
42         }
43         i = MPI_Alloc_mem(SIZE * sizeof(int), MPI_INFO_NULL, &B);
44         if (i) {
45             printf("Can't allocate memory in test program\n");
46             MPI_Abort(MPI_COMM_WORLD, 1);
47         }
48
49         if (rank == 0) {
50             for (i = 0; i < SIZE; i++)
51                 A[i] = B[i] = i;
52         }
53         else {
54             for (i = 0; i < SIZE; i++) {
55                 A[i] = (-3) * i;
56                 B[i] = (-4) * i;
57             }
58         }
59
60         MPI_Win_create(B, SIZE * sizeof(int), sizeof(int), MPI_INFO_NULL, CommDeuce, &win);
61
62         MPI_Win_fence(0, win);
63
64         if (rank == 0) {
65             for (i = 0; i < SIZE - 1; i++)
66                 MPI_Put(A + i, 1, MPI_INT, 1, i, 1, MPI_INT, win);
67         }
68         else {
69             for (i = 0; i < SIZE - 1; i++)
70                 MPI_Get(A + i, 1, MPI_INT, 0, i, 1, MPI_INT, win);
71
72             MPI_Accumulate(A + i, 1, MPI_INT, 0, i, 1, MPI_INT, MPI_SUM, win);
73         }
74         MPI_Win_fence(0, win);
75
76         if (rank == 1) {
77             for (i = 0; i < SIZE - 1; i++) {
78                 if (A[i] != B[i]) {
79                     SQUELCH(printf("Put/Get Error: A[i]=%d, B[i]=%d\n", A[i], B[i]););
80                     errs++;
81                 }
82             }
83         }
84         else {
85             if (B[SIZE - 1] != SIZE - 1 - 3 * (SIZE - 1)) {
86                 SQUELCH(printf
87                         ("Accumulate Error: B[SIZE-1] is %d, should be %d\n", B[SIZE - 1],
88                          SIZE - 1 - 3 * (SIZE - 1)););
89                 errs++;
90             }
91         }
92         MPI_Win_free(&win);
93
94         MPI_Free_mem(A);
95         MPI_Free_mem(B);
96     }
97     MPI_Comm_free(&CommDeuce);
98
99     MTest_Finalize(errs);
100     MPI_Finalize();
101     return 0;
102 }