Logo AND Algorithmique Numérique Distribuée

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