Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Reduce the size of partial shared malloc tests.
[simgrid.git] / teshsuite / smpi / mpich3-test / rma / test1.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 #define SIZE 100
14
15 int main(int argc, char *argv[])
16 {
17     int rank, nprocs, A[SIZE], B[SIZE], i;
18     MPI_Comm CommDeuce;
19     MPI_Win win;
20     int errs = 0;
21
22     MTest_Init(&argc, &argv);
23     MPI_Comm_size(MPI_COMM_WORLD, &nprocs);
24     MPI_Comm_rank(MPI_COMM_WORLD, &rank);
25
26     if (nprocs < 2) {
27         printf("Run this program with 2 or more processes\n");
28         MPI_Abort(MPI_COMM_WORLD, 1);
29     }
30
31     MPI_Comm_split(MPI_COMM_WORLD, (rank < 2), rank, &CommDeuce);
32
33     if (rank < 2) {
34         if (rank == 0) {
35             for (i = 0; i < SIZE; i++)
36                 A[i] = B[i] = i;
37         }
38         else {
39             for (i = 0; i < SIZE; i++) {
40                 A[i] = (-3) * i;
41                 B[i] = (-4) * i;
42             }
43         }
44
45         MPI_Win_create(B, SIZE * sizeof(int), sizeof(int), MPI_INFO_NULL, CommDeuce, &win);
46
47         MPI_Win_fence(0, win);
48
49         if (rank == 0) {
50             for (i = 0; i < SIZE - 1; i++)
51                 MPI_Put(A + i, 1, MPI_INT, 1, i, 1, MPI_INT, win);
52         }
53         else {
54             for (i = 0; i < SIZE - 1; i++)
55                 MPI_Get(A + i, 1, MPI_INT, 0, i, 1, MPI_INT, win);
56
57             MPI_Accumulate(A + i, 1, MPI_INT, 0, i, 1, MPI_INT, MPI_SUM, win);
58         }
59         MPI_Win_fence(0, win);
60
61         if (rank == 1) {
62             for (i = 0; i < SIZE - 1; i++) {
63                 if (A[i] != B[i]) {
64                     SQUELCH(printf("Put/Get Error: A[i]=%d, B[i]=%d\n", A[i], B[i]););
65                     errs++;
66                 }
67             }
68         }
69         else {
70             if (B[SIZE - 1] != SIZE - 1 - 3 * (SIZE - 1)) {
71                 SQUELCH(printf
72                         ("Accumulate Error: B[SIZE-1] is %d, should be %d\n", B[SIZE - 1],
73                          SIZE - 1 - 3 * (SIZE - 1)););
74                 errs++;
75             }
76         }
77         MPI_Win_free(&win);
78     }
79     MPI_Comm_free(&CommDeuce);
80     MTest_Finalize(errs);
81     MPI_Finalize();
82     return 0;
83 }