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 / test5.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 Gets. Run on 2 processes. */
12
13 #define SIZE 2000
14
15 int main(int argc, char *argv[])
16 {
17     int rank, nprocs, i, A[SIZE], B[SIZE];
18     MPI_Comm CommDeuce;
19     MPI_Win win;
20     int errs = 0;
21
22     MTest_Init(&argc, &argv);
23
24     MPI_Comm_size(MPI_COMM_WORLD, &nprocs);
25     MPI_Comm_rank(MPI_COMM_WORLD, &rank);
26
27     if (nprocs < 2) {
28         printf("Run this program with 2 or more processes\n");
29         MPI_Abort(MPI_COMM_WORLD, 1);
30     }
31
32     MPI_Comm_split(MPI_COMM_WORLD, (rank < 2), rank, &CommDeuce);
33
34     if (rank < 2) {
35         if (rank == 0) {
36             for (i = 0; i < SIZE; i++)
37                 B[i] = 500 + i;
38             MPI_Win_create(B, SIZE * sizeof(int), sizeof(int), MPI_INFO_NULL, CommDeuce, &win);
39             MPI_Win_fence(0, win);
40             for (i = 0; i < SIZE; i++) {
41                 A[i] = i + 100;
42                 MPI_Get(&A[i], 1, MPI_INT, 1, i, 1, MPI_INT, win);
43             }
44             MPI_Win_fence(0, win);
45             for (i = 0; i < SIZE; i++)
46                 if (A[i] != 1000 + i) {
47                     SQUELCH(printf("Rank 0: A[%d] is %d, should be %d\n", i, A[i], 1000 + i););
48                     errs++;
49                 }
50         }
51         if (rank == 1) {
52             for (i = 0; i < SIZE; i++)
53                 A[i] = 1000 + i;
54             MPI_Win_create(A, SIZE * sizeof(int), sizeof(int), MPI_INFO_NULL, CommDeuce, &win);
55             MPI_Win_fence(0, win);
56             for (i = 0; i < SIZE; i++) {
57                 B[i] = i + 200;
58                 MPI_Get(&B[i], 1, MPI_INT, 0, i, 1, MPI_INT, win);
59             }
60             MPI_Win_fence(0, win);
61             for (i = 0; i < SIZE; i++)
62                 if (B[i] != 500 + i) {
63                     SQUELCH(printf("Rank 1: B[%d] is %d, should be %d\n", i, B[i], 500 + i););
64                     errs++;
65                 }
66         }
67
68         MPI_Win_free(&win);
69     }
70     MPI_Comm_free(&CommDeuce);
71     MTest_Finalize(errs);
72     MPI_Finalize();
73     return 0;
74 }