YAC 3.13.0
Yet Another Coupler
Loading...
Searching...
No Matches
test_interpolation_gen_config.c
Go to the documentation of this file.
1// Copyright (c) 2025 The YAC Authors
2//
3// SPDX-License-Identifier: BSD-3-Clause
4
5#include <mpi.h>
6#include <string.h>
7
8#include "tests.h"
9#include "test_common.h"
10
13
19static void utest_default_values(void);
20static void utest_setters_and_getters(void);
21static void utest_copy(void);
22static void utest_delete_null(void);
23static void utest_compare(void);
24static void utest_pack_unpack(void);
25
26int main(void) {
27
28 MPI_Init(NULL, NULL);
29
30 utest_default_values();
31 utest_setters_and_getters();
32 utest_copy();
33 utest_delete_null();
34 utest_compare();
35 utest_pack_unpack();
36
37 MPI_Finalize();
38
39 return TEST_EXIT_CODE;
40}
41
42static void utest_default_values(void) {
43
44 struct yac_interpolation_gen_config *gen_config =
46
47 if (gen_config == NULL) PUT_ERR("config is NULL after construction");
48
50 PUT_ERR("default reorder should be YAC_MAPPING_ON_SRC");
51
52 /* collection_selection has to be explicitly set -> no default value*/
53
56 PUT_ERR("wrong default frac_mask_fallback_value");
57
59 PUT_ERR("wrong default scaling_factor");
60
62 PUT_ERR("wrong default scaling_summand");
63
65 PUT_ERR("default exchanger name should be NULL");
66
68}
69
70static void utest_setters_and_getters(void) {
71
72 struct yac_interpolation_gen_config *gen_config =
74
75 /* reorder */
78 PUT_ERR("set/get reorder failed");
79
80 /* contiguous collection selection*/
81 struct yac_collection_selection * cont_coll_sel =
86 cont_coll_sel))
87 PUT_ERR("set collection_size failed");
89
90 /* non-contiguous collection selection*/
91 struct yac_collection_selection * non_cont_coll_sel =
92 yac_collection_selection_new(3, (size_t[]){2, 3, 1});
94 gen_config, non_cont_coll_sel);
97 non_cont_coll_sel))
98 PUT_ERR("set/get collection_selection failed");
99 yac_collection_selection_delete(non_cont_coll_sel);
100
101
102 /* frac_mask_fallback_value */
105 PUT_ERR("set/get frac_mask_fallback_value failed");
106
107 /* scaling_factor */
110 PUT_ERR("set/get scaling_factor failed");
111
112 /* scaling_summand */
115 PUT_ERR("set/get scaling_summand failed");
116
117 /* exchanger name */
118 const char *name = "custom_exchanger";
120 if (strcmp(
122 PUT_ERR("set/get yaxt_exchanger_name failed");
123
125}
126
127static void utest_copy(void) {
128
129 struct yac_interpolation_gen_config *orig =
131
137 const char *name = "copy_exchanger";
139
140 struct yac_interpolation_gen_config *copy =
142
143 if (copy == NULL)
144 PUT_ERR("copy is NULL");
145
148 PUT_ERR("reorder mismatch in copy");
149
153 PUT_ERR("collection_selection mismatch in copy");
154
157 PUT_ERR("frac_mask_fallback_value mismatch in copy");
158
161 PUT_ERR("scaling_factor mismatch in copy");
162
165 PUT_ERR("scaling_summand mismatch in copy");
166
167 if (strcmp(
170 PUT_ERR("yaxt_exchanger_name pointer mismatch in copy");
171
174
175 /* NULL is a valid input */
176 struct yac_interpolation_gen_config *null_copy =
178
179 if (null_copy != NULL)
180 PUT_ERR("copy of NULL config should be NULL");
181}
182
183static void utest_delete_null(void) {
184 /* should not crash */
186}
187
188static void utest_compare(void) {
189
190 { // both are NULL
191 if (yac_interpolation_gen_config_compare(NULL, NULL) != 0)
192 PUT_ERR("yac_interpolation_gen_config_compare(NULL, NULL) failed");
193 }
194
195 { // One is NULL, the other is not
198 if (yac_interpolation_gen_config_compare(a, NULL) == 0)
199 PUT_ERR("yac_interpolation_gen_config_compare(a, NULL) failed");
202 PUT_ERR("yac_interpolation_gen_config_compare(a, NULL) failed");
204 }
205
206 { // Both are different
207
212
215 enum {NUM_REORDER_TYPES = sizeof(reorder_types) / sizeof(reorder_types[0])};
216
217 size_t collection_sizes[] = {1,3};
218 enum {
219 NUM_COLLECTION_SIZES =
220 sizeof(collection_sizes) / sizeof(collection_sizes[0])};
221
222 double frac_mask_values[] = {0.0, NAN};
223 enum {NUM_FRAC_MASK_VALUES =
224 sizeof(frac_mask_values) / sizeof(frac_mask_values[0])};
225
226 double scaling_factors[] = {-1.0, 1.0};
227 enum {NUM_SCALING_FACTORS =
228 sizeof(scaling_factors) / sizeof(scaling_factors[0])};
229
230 double scaling_summands[] = {0.0, 1.0};
231 enum {NUM_SCALING_SUMMANDS =
232 sizeof(scaling_summands) / sizeof(scaling_summands[0])};
233
234 const char *exchanger_names[] = {NULL, "irecv_isend"};
235 enum {NUM_EXCHANGER_NAMES =
236 sizeof(exchanger_names) / sizeof(exchanger_names[0])};
237
238 for (size_t reorder_a = 0; reorder_a < NUM_REORDER_TYPES; ++reorder_a) {
240
241 for (size_t reorder_b = 0; reorder_b < NUM_REORDER_TYPES; ++reorder_b) {
243
244 for (size_t col_a = 0; col_a < NUM_COLLECTION_SIZES; ++col_a) {
246 a, collection_sizes[col_a]);
247
248 for (size_t col_b = 0; col_b < NUM_COLLECTION_SIZES; ++col_b) {
250 b, collection_sizes[col_b]);
251
252 for (size_t frac_a = 0; frac_a < NUM_FRAC_MASK_VALUES; ++frac_a) {
254 a, frac_mask_values[frac_a]);
255
256 for (size_t frac_b = 0; frac_b < NUM_FRAC_MASK_VALUES; ++frac_b) {
258 b, frac_mask_values[frac_b]);
259
260 for (size_t scale_a = 0; scale_a < NUM_SCALING_FACTORS; ++scale_a) {
262 a, scaling_factors[scale_a]);
263
264 for (size_t scale_b = 0; scale_b < NUM_SCALING_FACTORS; ++scale_b) {
266 b, scaling_factors[scale_b]);
267
268 for (size_t sum_a = 0; sum_a < NUM_SCALING_SUMMANDS; ++sum_a) {
270 a, scaling_summands[sum_a]);
271
272 for (size_t sum_b = 0; sum_b < NUM_SCALING_SUMMANDS; ++sum_b) {
274 b, scaling_summands[sum_b]);
275
276 for (size_t exch_a = 0; exch_a < NUM_EXCHANGER_NAMES; ++exch_a) {
278 a, exchanger_names[exch_a]);
279
280 for (size_t exch_b = 0; exch_b < NUM_EXCHANGER_NAMES; ++exch_b) {
282 b, exchanger_names[exch_b]);
283
285 int cmp_rev = yac_interpolation_gen_config_compare(b, a);
286
287 int identical =
288 (reorder_a == reorder_b) &&
289 (col_a == col_b) &&
290 (frac_a == frac_b) &&
291 (scale_a == scale_b) &&
292 (sum_a == sum_b) &&
293 (exch_a == exch_b);
294
295 if (identical) {
296 if (cmp != 0)
297 PUT_ERR("identical configurations compare nonzero");
298 } else {
299 if (cmp == 0)
300 PUT_ERR("different configurations compare equal");
301 if (cmp != -cmp_rev)
302 PUT_ERR("antisymmetry property failed");
303 }
304
305 } // exch_b
306 } // exch_a
307 } // sum_b
308 } // sum_a
309 } // scale_b
310 } // scale_a
311 } // frac_b
312 } // frac_a
313 } // col_b
314 } // col_a
315 } // reorder_b
316 } // reorder_a
317
318 // cleanup
321 }
322}
323
324static void utest_pack_unpack(void) {
325
326 MPI_Comm comm = MPI_COMM_SELF;
327
328 struct {
331 double scaling_factor;
332 double scaling_summand;
333 size_t collection_size;
334 const char * yaxt_exchanger_name;
335 } test_cases[] =
336 {{.reorder = YAC_MAPPING_ON_SRC,
337 .frac_mask_fallback_value = 1.0,
338 .scaling_factor = 1.0,
339 .scaling_summand = 0.0,
340 .collection_size = 3,
341 .yaxt_exchanger_name = NULL},
342 {.reorder = YAC_MAPPING_ON_SRC,
343 .frac_mask_fallback_value = 1.0,
344 .scaling_factor = 1.0,
345 .scaling_summand = 0.0,
346 .collection_size = 5,
347 .yaxt_exchanger_name = "irecv_isend"}};
348 enum { NUM_TESTS = sizeof(test_cases) / sizeof(test_cases[0]) };
349
350 struct yac_interpolation_gen_config * orig =
352
353 for (size_t t = 0; t < NUM_TESTS; ++t) {
354
356 orig, test_cases[t].reorder);
358 orig, test_cases[t].collection_size);
360 orig, test_cases[t].frac_mask_fallback_value);
362 orig, test_cases[t].scaling_factor);
364 orig, test_cases[t].scaling_summand);
366 orig, test_cases[t].yaxt_exchanger_name);
367
368 size_t pack_size = yac_interpolation_gen_config_get_pack_size(orig, comm);
370 pack_size > 0, "utest_pack_unpack_config: pack_size must be positive");
371
372 void *buffer = xmalloc(pack_size);
373 int position = 0;
374
376 orig, buffer, (int)pack_size, &position, comm);
377
378 int unpack_position = 0;
379 struct yac_interpolation_gen_config * copy =
381 buffer, (int)pack_size, &unpack_position, comm);
382
384 PUT_ERR("error pack/unpack");
385
386 // cleanup
388 free(buffer);
389 }
390
392}
#define YAC_ASSERT(exp, msg)
void yac_collection_selection_delete(struct yac_collection_selection *collection_selection)
Delete a collection selection object.
int yac_collection_selection_compare(struct yac_collection_selection const *a, struct yac_collection_selection const *b)
Compare two collection selections.
struct yac_collection_selection * yac_collection_selection_new(size_t collection_size, size_t const *selection_indices)
Create a new collection selection.
yac_interp_weights_reorder_type
@ YAC_MAPPING_ON_TGT
weights will be applied at target processes
@ YAC_MAPPING_ON_SRC
weights will be applied at source processes
double const YAC_FRAC_MASK_NO_VALUE
void yac_interpolation_gen_config_set_reorder(struct yac_interpolation_gen_config *config, enum yac_interp_weights_reorder_type reorder)
Set the reordering strategy for interpolation weights.
void yac_interpolation_gen_config_set_collection_size(struct yac_interpolation_gen_config *config, size_t collection_size)
Set the number of contiguous fields (starting at "0") in the field collection.
enum yac_interp_weights_reorder_type yac_interpolation_gen_config_get_reorder(struct yac_interpolation_gen_config const *config)
Get the configured reordering strategy.
int yac_interpolation_gen_config_compare(struct yac_interpolation_gen_config const *a, struct yac_interpolation_gen_config const *b)
Compare two interpolation configuration structures.
double yac_interpolation_gen_config_get_frac_mask_fallback_value(struct yac_interpolation_gen_config const *config)
Get the configured fractional mask fallback value.
void yac_interpolation_gen_config_set_collection_selection(struct yac_interpolation_gen_config *config, struct yac_collection_selection const *collection_selection)
Set the collection selection of source field in the source field collection.
void yac_interpolation_gen_config_set_scaling_factor(struct yac_interpolation_gen_config *config, double scaling_factor)
Set the multiplicative scaling factor.
double yac_interpolation_gen_config_get_scaling_factor(struct yac_interpolation_gen_config const *config)
Get the configured scaling factor.
struct yac_collection_selection const * yac_interpolation_gen_config_get_collection_selection(struct yac_interpolation_gen_config const *config)
Get the configured collection selection.
size_t yac_interpolation_gen_config_get_pack_size(struct yac_interpolation_gen_config const *cfg, MPI_Comm comm)
Get the MPI packing size of an interpolation generation configuration.
void yac_interpolation_gen_config_set_yaxt_exchanger_name(struct yac_interpolation_gen_config *config, char const *name)
Set the name of the Yaxt exchanger.
const char * yac_interpolation_gen_config_get_yaxt_exchanger_name(struct yac_interpolation_gen_config const *config)
Get the configured Yaxt exchanger name.
void yac_interpolation_gen_config_delete(struct yac_interpolation_gen_config *config)
Release a interpolation generation configuration structure allocated by yac_interpolation_gen_config_...
void yac_interpolation_gen_config_set_frac_mask_fallback_value(struct yac_interpolation_gen_config *config, double frac_mask_fallback_value)
Set the fractional mask fallback value.
struct yac_interpolation_gen_config * yac_interpolation_gen_config_copy(struct yac_interpolation_gen_config const *src)
Create a copy of an interpolation generation configuration.
struct yac_interpolation_gen_config * yac_interpolation_gen_config_new(void)
Allocate and initialise an interpolation generation configuration structure.
void yac_interpolation_gen_config_pack(struct yac_interpolation_gen_config const *cfg, void *buffer, int buffer_size, int *position, MPI_Comm comm)
Pack an interpolation generation configuration into an MPI buffer.
void yac_interpolation_gen_config_set_scaling_summand(struct yac_interpolation_gen_config *config, double scaling_summand)
Set the additive scaling summand.
double yac_interpolation_gen_config_get_scaling_summand(struct yac_interpolation_gen_config const *config)
Get the configured scaling summand.
struct yac_interpolation_gen_config * yac_interpolation_gen_config_unpack(void const *buffer, int buffer_size, int *position, MPI_Comm comm)
Unpack an interpolation generation configuration from an MPI buffer.
#define xmalloc(size)
Definition ppm_xfuncs.h:66
Configuration structure for interpolation generation.
enum yac_interp_weights_reorder_type reorder
int collection_size
enum yac_interp_weights_reorder_type reorder_types[]
#define NUM_TESTS
#define TEST_EXIT_CODE
Definition tests.h:14
#define PUT_ERR(string)
Definition tests.h:10
double * buffer
char const * name
Definition toy_scrip.c:114