Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
08dc4a3682f97f83b3ba35cf6107f9df6e4ababf
[simgrid.git] / teshsuite / smpi / mpich3-test / rma / badrma.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
7 #include "mpi.h"
8 #include "stdio.h"
9
10 #define SIZE 100
11
12 MPI_Win win;
13 int win_buf[SIZE], origin_buf[SIZE], result_buf[SIZE];
14 int do_test(int origin_count, MPI_Datatype origin_type, int result_count,
15             MPI_Datatype result_type, int target_count, MPI_Datatype target_type);
16 int do_test(int origin_count, MPI_Datatype origin_type, int result_count,
17             MPI_Datatype result_type, int target_count, MPI_Datatype target_type)
18 {
19     int errs = 0, ret, origin_type_size, result_type_size;
20
21     ret = MPI_Put(origin_buf, origin_count, origin_type, 1, 0, target_count, target_type, win);
22     if (ret)
23         errs++;
24
25     ret = MPI_Get(origin_buf, origin_count, origin_type, 1, 0, target_count, target_type, win);
26     if (ret)
27         errs++;
28
29     ret = MPI_Accumulate(origin_buf, origin_count, origin_type, 1, 0, target_count,
30                          target_type, MPI_SUM, win);
31     if (ret)
32         errs++;
33
34     ret = MPI_Get_accumulate(origin_buf, origin_count, origin_type, result_buf, result_count,
35                              result_type, 1, 0, target_count, target_type, MPI_SUM, win);
36     if (ret)
37         errs++;
38
39     MPI_Type_size(origin_type, &origin_type_size);
40     MPI_Type_size(result_type, &result_type_size);
41
42     if (origin_count == 0 || origin_type_size == 0) {
43         ret = MPI_Put(NULL, origin_count, origin_type, 1, 0, target_count, target_type, win);
44         if (ret)
45             errs++;
46
47         ret = MPI_Get(NULL, origin_count, origin_type, 1, 0, target_count, target_type, win);
48         if (ret)
49             errs++;
50
51         ret = MPI_Accumulate(NULL, origin_count, origin_type, 1, 0, target_count, target_type,
52                              MPI_SUM, win);
53         if (ret)
54             errs++;
55
56         ret = MPI_Get_accumulate(NULL, origin_count, origin_type, result_buf, result_count,
57                                  result_type, 1, 0, target_count, target_type, MPI_SUM, win);
58         if (ret)
59             errs++;
60
61         if (result_count == 0 || result_type_size == 0) {
62             ret = MPI_Get_accumulate(NULL, origin_count, origin_type, NULL, result_count,
63                                      result_type, 1, 0, target_count, target_type, MPI_SUM, win);
64             if (ret)
65                 errs++;
66         }
67     }
68
69     return errs;
70 }
71
72 int main(int argc, char *argv[])
73 {
74     int rank, nprocs, i, j, k;
75     int errs = 0;
76     MPI_Datatype types[4];
77
78     MPI_Init(&argc, &argv);
79     MPI_Comm_size(MPI_COMM_WORLD, &nprocs);
80     MPI_Comm_rank(MPI_COMM_WORLD, &rank);
81
82     if (nprocs < 2) {
83         printf("Run this program with 2 or more processes\n");
84         MPI_Abort(MPI_COMM_WORLD, 1);
85     }
86
87     /* types[0] is of zero size.  Everything else is non-zero size */
88     MPI_Type_contiguous(0, MPI_INT, &types[0]);
89     MPI_Type_commit(&types[0]);
90
91     MPI_Type_contiguous(1, MPI_INT, &types[1]);
92     MPI_Type_commit(&types[1]);
93
94     types[2] = MPI_INT;
95     types[3] = MPI_DOUBLE;
96
97     MPI_Win_create(win_buf, SIZE * sizeof(int), sizeof(int), MPI_INFO_NULL, MPI_COMM_WORLD, &win);
98
99     MPI_Win_fence(0, win);
100
101     if (rank == 0) {
102         /* zero-count */
103         for (i = 0; i < 4; i++)
104             for (j = 0; j < 4; j++)
105                 for (k = 0; k < 4; k++)
106                     do_test(0, types[i], 0, types[j], 0, types[k]);
107
108         /* single zero-size datatype, but non-zero count */
109         for (i = 1; i < 4; i++) {
110             for (j = 1; j < 4; j++) {
111                 do_test(1, types[0], 0, types[i], 0, types[j]);
112                 do_test(0, types[i], 1, types[0], 0, types[j]);
113                 do_test(0, types[i], 0, types[j], 1, types[0]);
114             }
115         }
116
117         /* two zero-size datatypes, but non-zero count */
118         for (i = 1; i < 4; i++) {
119             do_test(1, types[0], 1, types[0], 0, types[i]);
120             do_test(1, types[0], 0, types[i], 1, types[0]);
121             do_test(0, types[i], 1, types[0], 1, types[0]);
122
123             do_test(1, types[0], 2, types[0], 0, types[i]);
124             do_test(2, types[0], 1, types[0], 0, types[i]);
125
126             do_test(1, types[0], 0, types[i], 2, types[0]);
127             do_test(2, types[0], 0, types[i], 1, types[0]);
128
129             do_test(0, types[i], 1, types[0], 2, types[0]);
130             do_test(0, types[i], 2, types[0], 1, types[0]);
131         }
132
133         /* three zero-size datatypes, but non-zero count */
134         do_test(1, types[0], 1, types[0], 1, types[0]);
135         do_test(1, types[0], 1, types[0], 2, types[0]);
136         do_test(1, types[0], 2, types[0], 1, types[0]);
137         do_test(1, types[0], 2, types[0], 2, types[0]);
138         do_test(2, types[0], 1, types[0], 1, types[0]);
139         do_test(2, types[0], 1, types[0], 2, types[0]);
140         do_test(2, types[0], 2, types[0], 1, types[0]);
141     }
142     MPI_Win_fence(0, win);
143
144     MPI_Win_free(&win);
145     MPI_Type_free(&types[0]);
146     MPI_Type_free(&types[1]);
147
148     if (!errs && !rank)
149         printf(" No Errors\n");
150
151     MPI_Finalize();
152
153     return 0;
154 }