Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
change some tests to avoid useless global variables
[simgrid.git] / teshsuite / smpi / mpich3-test / rma / test1_dt.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 /* Same as test1.c but uses derived datatypes to receive data */
13
14 #define SIZE 100
15
16 int main(int argc, char *argv[])
17 {
18     int rank, nprocs, A[SIZE], B[SIZE], i;
19     MPI_Comm CommDeuce;
20     MPI_Win win;
21     MPI_Datatype contig_2ints;
22     int errs = 0;
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
37         if (rank == 0) {
38             for (i = 0; i < SIZE; i++)
39                 A[i] = B[i] = i;
40         }
41         else {
42             for (i = 0; i < SIZE; i++) {
43                 A[i] = (-3) * i;
44                 B[i] = (-4) * i;
45             }
46         }
47
48         MPI_Type_contiguous(2, MPI_INT, &contig_2ints);
49         MPI_Type_commit(&contig_2ints);
50
51         MPI_Win_create(B, SIZE * sizeof(int), sizeof(int), MPI_INFO_NULL, CommDeuce, &win);
52
53         MPI_Win_fence(0, win);
54
55         if (rank == 0) {
56             for (i = 0; i < SIZE - 2; i += 2)
57                 MPI_Put(A + i, 2, MPI_INT, 1, i, 1, contig_2ints, win);
58         }
59         else {
60             for (i = 0; i < SIZE - 2; i += 2)
61                 MPI_Get(A + i, 2, MPI_INT, 0, i, 1, contig_2ints, win);
62
63             MPI_Accumulate(A + SIZE - 2, 2, MPI_INT, 0, SIZE - 2, 1, contig_2ints, MPI_SUM, win);
64         }
65         MPI_Win_fence(0, win);
66
67         if (rank == 1) {
68             for (i = 0; i < SIZE - 2; i++) {
69                 if (A[i] != B[i]) {
70                     SQUELCH(printf("Put/Get Error: A[i]=%d, B[i]=%d\n", A[i], B[i]););
71                     errs++;
72                 }
73             }
74         }
75         else {
76             if (B[SIZE - 1] != SIZE - 1 - 3 * (SIZE - 1)) {
77                 SQUELCH(printf
78                         ("Accumulate Error: B[SIZE-1] is %d, should be %d\n", B[SIZE - 1],
79                          SIZE - 1 - 3 * (SIZE - 1)););
80                 errs++;
81             }
82         }
83
84         MPI_Win_free(&win);
85         MPI_Type_free(&contig_2ints);
86     }
87     MPI_Comm_free(&CommDeuce);
88     MTest_Finalize(errs);
89     MPI_Finalize();
90     return 0;
91 }