YAC 3.13.0
Yet Another Coupler
Loading...
Searching...
No Matches
test_yac_xmap.c
Go to the documentation of this file.
1// Copyright (c) 2024 The YAC Authors
2//
3// SPDX-License-Identifier: BSD-3-Clause
4
5#include <mpi.h>
6#include <yaxt.h>
7
8#include "tests.h"
9#include "yac_xmap.h"
10
16int main (void) {
17
18 MPI_Init(NULL, NULL);
19
20 xt_initialize(MPI_COMM_WORLD);
21
22 int comm_rank, comm_size;
23 MPI_Comm_rank(MPI_COMM_WORLD, &comm_rank);
24 MPI_Comm_size(MPI_COMM_WORLD, &comm_size);
25 MPI_Barrier(MPI_COMM_WORLD);
26
27 enum {NUM_PROCS = 3};
28
29 if (comm_size != 3) {
30 PUT_ERR("ERROR: wrong number of processes");
31 xt_finalize();
32 MPI_Finalize();
33 return TEST_EXIT_CODE;
34 }
35
36 { // test xmap without any exchanges
37 struct remote_point_infos * point_infos[NUM_PROCS] = {NULL, NULL, NULL};
38 size_t count[NUM_PROCS] = {0, 0, 0};
39
40 yac_xmap xmap =
42 point_infos[comm_rank], count[comm_rank], MPI_COMM_WORLD);
43
44 Xt_redist redist = yac_xmap_generate_redist(xmap, MPI_INT);
45
46 int src_data[1] = {0}, tgt_data[1] = {-1};
47 xt_redist_s_exchange1(redist, src_data, tgt_data);
48
49 int ref_tgt_data[NUM_PROCS][1] = {{-1},{-1},{-1}};
50
51 for (size_t i = 0; i < count[comm_rank]; ++i)
52 if (ref_tgt_data[comm_rank][i] != tgt_data[i])
53 PUT_ERR("error in empty exchange");
54
55 xt_redist_delete(redist);
56 yac_xmap_delete(xmap);
57 }
58
59 { // test xmap with bcast operation
60 struct remote_point_infos point_infos[NUM_PROCS][1] =
61 {{(struct remote_point_infos){
62 .count = 1,
63 .data.single =
64 (struct remote_point_info){
65 .rank = 0, .orig_pos = 0}}},
66 {(struct remote_point_infos){
67 .count = 1,
68 .data.single =
69 (struct remote_point_info){
70 .rank = 0, .orig_pos = 0}}},
71 {(struct remote_point_infos){
72 .count = 1,
73 .data.single =
74 (struct remote_point_info){
75 .rank = 0, .orig_pos = 0}}}};
76 size_t count[NUM_PROCS] = {1, 1, 1};
77
78 yac_xmap xmap =
80 point_infos[comm_rank], count[comm_rank], MPI_COMM_WORLD);
81
82 Xt_redist redist = yac_xmap_generate_redist(xmap, MPI_INT);
83
84 int src_data[1] = {0}, tgt_data[1] = {-1};
85 xt_redist_s_exchange1(redist, src_data, tgt_data);
86
87 int ref_tgt_data[NUM_PROCS][1] = {{0},{0},{0}};
88
89 for (size_t i = 0; i < count[comm_rank]; ++i)
90 if (ref_tgt_data[comm_rank][i] != tgt_data[i])
91 PUT_ERR("error in bcast exchange");
92
93 xt_redist_delete(redist);
94 yac_xmap_delete(xmap);
95 }
96
97 { // test xmap with gather operation
98 struct remote_point_infos point_infos[NUM_PROCS][3] =
99 {{(struct remote_point_infos){
100 .count = 1,
101 .data.single =
102 (struct remote_point_info){
103 .rank = 0, .orig_pos = 0}},
104 (struct remote_point_infos){
105 .count = 1,
106 .data.single =
107 (struct remote_point_info){
108 .rank = 1, .orig_pos = 0}},
109 (struct remote_point_infos){
110 .count = 1,
111 .data.single =
112 (struct remote_point_info){
113 .rank = 2, .orig_pos = 0}}},
114 {(struct remote_point_infos){
115 .count = 1,
116 .data.single =
117 (struct remote_point_info){
118 .rank = -1, .orig_pos = 999}}},
119 {(struct remote_point_infos){
120 .count = 1,
121 .data.single =
122 (struct remote_point_info){
123 .rank = -1, .orig_pos = 999}}}};
124 size_t count[NUM_PROCS] = {3, 0, 0};
125
126 yac_xmap xmap =
128 point_infos[comm_rank], count[comm_rank], MPI_COMM_WORLD);
129
130 Xt_redist redist = yac_xmap_generate_redist(xmap, MPI_INT);
131
132 int src_data[1] = {comm_rank}, tgt_data[3] = {-1, -1, -1};
133 xt_redist_s_exchange1(redist, src_data, tgt_data);
134
135 int ref_tgt_data[NUM_PROCS][3] = {{0, 1, 2},{-1},{-1}};
136
137 for (size_t i = 0; i < count[comm_rank]; ++i)
138 if (ref_tgt_data[comm_rank][i] != tgt_data[i])
139 PUT_ERR("error in gather exchange");
140
141 xt_redist_delete(redist);
142 yac_xmap_delete(xmap);
143 }
144
145 { // test xmap with allgather operation
146 struct remote_point_infos point_infos[NUM_PROCS][3] =
147 {{(struct remote_point_infos){
148 .count = 1,
149 .data.single =
150 (struct remote_point_info){
151 .rank = 0, .orig_pos = 0}},
152 (struct remote_point_infos){
153 .count = 1,
154 .data.single =
155 (struct remote_point_info){
156 .rank = 1, .orig_pos = 0}},
157 (struct remote_point_infos){
158 .count = 1,
159 .data.single =
160 (struct remote_point_info){
161 .rank = 2, .orig_pos = 0}}},
162 {(struct remote_point_infos){
163 .count = 1,
164 .data.single =
165 (struct remote_point_info){
166 .rank = 0, .orig_pos = 0}},
167 (struct remote_point_infos){
168 .count = 1,
169 .data.single =
170 (struct remote_point_info){
171 .rank = 1, .orig_pos = 0}},
172 (struct remote_point_infos){
173 .count = 1,
174 .data.single =
175 (struct remote_point_info){
176 .rank = 2, .orig_pos = 0}}},
177 {(struct remote_point_infos){
178 .count = 1,
179 .data.single =
180 (struct remote_point_info){
181 .rank = 0, .orig_pos = 0}},
182 (struct remote_point_infos){
183 .count = 1,
184 .data.single =
185 (struct remote_point_info){
186 .rank = 1, .orig_pos = 0}},
187 (struct remote_point_infos){
188 .count = 1,
189 .data.single =
190 (struct remote_point_info){
191 .rank = 2, .orig_pos = 0}}}};
192 size_t count[NUM_PROCS] = {3, 3, 3};
193
194 yac_xmap xmap =
196 point_infos[comm_rank], count[comm_rank], MPI_COMM_WORLD);
197
198 Xt_redist redist = yac_xmap_generate_redist(xmap, MPI_INT);
199
200 int src_data[1] = {comm_rank}, tgt_data[3] = {-1, -1, -1};
201 xt_redist_s_exchange1(redist, src_data, tgt_data);
202
203 int ref_tgt_data[NUM_PROCS][3] = {{0, 1, 2},{0, 1, 2},{0, 1, 2}};
204
205 for (size_t i = 0; i < count[comm_rank]; ++i)
206 if (ref_tgt_data[comm_rank][i] != tgt_data[i])
207 PUT_ERR("error in allgather exchange");
208
209 xt_redist_delete(redist);
210 yac_xmap_delete(xmap);
211 }
212
213 { // test xmap with all2all operation
214 struct remote_point_infos point_infos[NUM_PROCS][3] =
215 {{(struct remote_point_infos){
216 .count = 1,
217 .data.single =
218 (struct remote_point_info){
219 .rank = 0, .orig_pos = 0}},
220 (struct remote_point_infos){
221 .count = 1,
222 .data.single =
223 (struct remote_point_info){
224 .rank = 1, .orig_pos = 0}},
225 (struct remote_point_infos){
226 .count = 1,
227 .data.single =
228 (struct remote_point_info){
229 .rank = 2, .orig_pos = 0}}},
230 {(struct remote_point_infos){
231 .count = 1,
232 .data.single =
233 (struct remote_point_info){
234 .rank = 0, .orig_pos = 1}},
235 (struct remote_point_infos){
236 .count = 1,
237 .data.single =
238 (struct remote_point_info){
239 .rank = 1, .orig_pos = 1}},
240 (struct remote_point_infos){
241 .count = 1,
242 .data.single =
243 (struct remote_point_info){
244 .rank = 2, .orig_pos = 1}}},
245 {(struct remote_point_infos){
246 .count = 1,
247 .data.single =
248 (struct remote_point_info){
249 .rank = 0, .orig_pos = 2}},
250 (struct remote_point_infos){
251 .count = 1,
252 .data.single =
253 (struct remote_point_info){
254 .rank = 1, .orig_pos = 2}},
255 (struct remote_point_infos){
256 .count = 1,
257 .data.single =
258 (struct remote_point_info){
259 .rank = 2, .orig_pos = 2}}}};
260 size_t count[NUM_PROCS] = {3, 3, 3};
261
262 yac_xmap xmap =
264 point_infos[comm_rank], count[comm_rank], MPI_COMM_WORLD);
265
266 Xt_redist redist = yac_xmap_generate_redist(xmap, MPI_INT);
267
268 int src_data[3] = {comm_rank * NUM_PROCS + 0,
269 comm_rank * NUM_PROCS + 1,
270 comm_rank * NUM_PROCS + 2}, tgt_data[3] = {-1, -1, -1};
271 xt_redist_s_exchange1(redist, src_data, tgt_data);
272
273 int ref_tgt_data[NUM_PROCS][3] = {{0, 3, 6},{1, 4, 7},{2, 5, 8}};
274
275 for (size_t i = 0; i < count[comm_rank]; ++i)
276 if (ref_tgt_data[comm_rank][i] != tgt_data[i])
277 PUT_ERR("error in all2all exchange");
278
279 xt_redist_delete(redist);
280 yac_xmap_delete(xmap);
281 }
282
283 xt_finalize();
284 MPI_Finalize();
285
286 return TEST_EXIT_CODE;
287}
single location information of a point
location information about a point that is located on one or
#define TEST_EXIT_CODE
Definition tests.h:14
#define PUT_ERR(string)
Definition tests.h:10
yac_xmap yac_xmap_from_point_infos(struct remote_point_infos *point_infos, size_t count, MPI_Comm comm)
Definition yac_xmap.c:63
void yac_xmap_delete(yac_xmap xmap)
Definition yac_xmap.c:196
Xt_redist yac_xmap_generate_redist(yac_xmap xmap, MPI_Datatype base_type)
Definition yac_xmap.c:161