YAC 3.21.0
Yet Another Coupler
Loading...
Searching...
No Matches
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 <stdlib.h>
6#include <string.h>
7
8#include <mpi.h>
9
10#include "ppm/ppm_xfuncs.h"
11
13#include "utils_core.h"
17#include "yac_mpi_internal.h"
18
57
60
61 struct yac_interpolation_gen_config * config = xmalloc(1 * sizeof(*config));
62
63 config->reorder = YAC_MAPPING_ON_SRC;
64 config->collection_selection = NULL; // unset
65
66 // fractional masking is deactivated by default
67 config->frac_mask_fallback_value = YAC_FRAC_MASK_NO_VALUE;
68 config->scaling_factor = 1.0;
69 config->scaling_summand = 0.0;
70 config->yaxt_exchanger_name = NULL;
71
72 return config;
73}
74
77
78 if (config == NULL) return;
79 yac_collection_selection_delete(config->collection_selection);
80 free(config->yaxt_exchanger_name);
81 free(config);
82}
83
85 struct yac_interpolation_gen_config const * src) {
86
87 if (src == NULL) return NULL;
88
89 struct yac_interpolation_gen_config * copy = xmalloc(1 * sizeof(*copy));
90
91 memcpy(copy, src, sizeof(*copy));
93 yac_collection_selection_copy(src->collection_selection);
94 if (src->yaxt_exchanger_name != NULL) {
95 copy->yaxt_exchanger_name = xstrdup(src->yaxt_exchanger_name);
96 }
97
98 return copy;
99}
100
101/* ---------------- Setters ---------------- */
102
106
107 YAC_ASSERT(config != NULL, "config is NULL");
110 "invalid reorder value");
111
112 config->reorder = reorder;
113}
114
115
127
130
131 YAC_ASSERT(config != NULL, "config is NULL");
133 collection_size != SIZE_MAX, "collection_size must be != SIZE_MAX");
134 YAC_ASSERT(collection_size > 0, "collection_size must be > 0");
135
136 yac_collection_selection_delete(config->collection_selection);
137 config->collection_selection =
139}
140
144
145 YAC_ASSERT(config != NULL, "config is NULL");
147 collection_selection != NULL, "collection_selection must be != NULL");
150 "collection_size of collection_selection must be > 0");
151
152 yac_collection_selection_delete(config->collection_selection);
153 config->collection_selection =
155}
156
160
161 YAC_ASSERT(config != NULL, "config is NULL");
164 "%lf is not a valid fractional masking fallback value",
166
167 config->frac_mask_fallback_value = frac_mask_fallback_value;
168}
169
172
173 YAC_ASSERT(config != NULL, "config is NULL");
175 isnormal(scaling_factor) || (fabs(scaling_factor) == 0.0),
176 "%lf is not a valid scaling factor", scaling_factor);
177
178 config->scaling_factor = scaling_factor;
179}
180
183
184 YAC_ASSERT(config != NULL, "config is NULL");
186 isnormal(scaling_summand) || (fabs(scaling_summand) == 0.0),
187 "%lf is not a valid scaling summand", scaling_summand);
188
189 config->scaling_summand = scaling_summand;
190}
191
193 struct yac_interpolation_gen_config * config, char const * name) {
194
195 YAC_ASSERT(config != NULL, "config is NULL");
196
197 free(config->yaxt_exchanger_name);
198 config->yaxt_exchanger_name = (name == NULL)?NULL:xstrdup(name);
199}
200
202 struct yac_interpolation_gen_config * config, char const * name) {
203
204 YAC_ASSERT(config != NULL, "config is NULL");
205
206 if ((name != NULL) && strlen(name) == 0) name = NULL;
208}
209
210/* ---------------- Getters ---------------- */
211
213 struct yac_interpolation_gen_config const * config) {
214
215 YAC_ASSERT(config != NULL, "config is NULL");
216
217 return config->reorder;
218}
219
220struct yac_collection_selection const *
222 struct yac_interpolation_gen_config const * config) {
223
224 YAC_ASSERT(config != NULL, "config is NULL");
226 config->collection_selection != NULL, "collection_selection is unset");
227
228 return config->collection_selection;
229}
230
232 struct yac_interpolation_gen_config const * config) {
233
234 YAC_ASSERT(config != NULL, "config is NULL");
235
236 return config->frac_mask_fallback_value;
237}
238
240 struct yac_interpolation_gen_config const * config) {
241
242 YAC_ASSERT(config != NULL, "config is NULL");
243
244 return config->scaling_factor;
245}
246
248 struct yac_interpolation_gen_config const * config) {
249
250 YAC_ASSERT(config != NULL, "config is NULL");
251
252 return config->scaling_summand;
253}
254
256 struct yac_interpolation_gen_config const * config) {
257
258 YAC_ASSERT(config != NULL, "config is NULL");
259
260 return config->yaxt_exchanger_name;
261}
262
264 struct yac_interpolation_gen_config const * a,
265 struct yac_interpolation_gen_config const * b) {
266
267 // Same pointer or both NULL
268 int ret = (a == b);
269 if (ret) return 0;
270
271 // One is NULL, the other is not
272 ret = (a == NULL) - (b == NULL);
273 if (ret) return ret;
274
275 // Different reorder types
276 ret = (a->reorder > b->reorder) - (a->reorder < b->reorder);
277 if (ret) return ret;
278
279 // Different collection selections
280 ret =
283 if (ret) return ret;
284
285 // Different scaling factor
286 ret = (a->scaling_factor > b->scaling_factor) -
288 if (ret) return ret;
289
290 // Different scaling summand
291 ret = (a->scaling_summand > b->scaling_summand) -
293 if (ret) return ret;
294
295 // Different yaxt exchanger
297
298 // One is unset (default), the other is set
299 ret = (a->yaxt_exchanger_name == NULL) -
300 (b->yaxt_exchanger_name == NULL);
301 if (ret) return ret;
302
303 // Both exchangers are different
304 ret = strcmp(a->yaxt_exchanger_name, b->yaxt_exchanger_name);
305 if (ret) return ret;
306 }
307
308 // Different fractional mask values
309 // (use memcmp to compare frac_mask_fallback_value, because they can be nan)
310 ret =
311 memcmp(
313 sizeof(double));
314 // if (ret) return ret;
315
316 return ret;
317}
318
320 struct yac_interpolation_gen_config const *cfg, MPI_Comm comm) {
321
322 YAC_ASSERT(cfg != NULL, "config is NULL");
323
324 int pack_size_int, pack_size_dble;
325 yac_mpi_call(MPI_Pack_size(1, MPI_INT, comm, &pack_size_int), comm);
326 yac_mpi_call(MPI_Pack_size(1, MPI_DOUBLE, comm, &pack_size_dble), comm);
327
328 return pack_size_int + // reorder
329 pack_size_dble + // frac_mask_fallback_value
330 pack_size_dble + // scaling_factor
331 pack_size_dble + // scaling_summand
333 (cfg != NULL)?cfg->collection_selection:NULL, comm) +
335 "yac_interpolation_gen_config_get_pack_size",
336 (cfg != NULL)?cfg->yaxt_exchanger_name:NULL, comm, 1);
337}
338
340 struct yac_interpolation_gen_config const * cfg,
341 void * buffer, int buffer_size, int * position, MPI_Comm comm) {
342
343 YAC_ASSERT(cfg != NULL, "config is NULL");
344
345 int reorder = (int)cfg->reorder;
347 MPI_Pack(&reorder, 1, MPI_INT, buffer, buffer_size, position, comm), comm);
348
350 MPI_Pack(
351 &cfg->frac_mask_fallback_value, 1, MPI_DOUBLE, buffer, buffer_size,
352 position, comm), comm);
354 MPI_Pack(
355 &cfg->scaling_factor, 1, MPI_DOUBLE, buffer, buffer_size,
356 position, comm), comm);
358 MPI_Pack(
359 &cfg->scaling_summand, 1, MPI_DOUBLE, buffer, buffer_size,
360 position, comm), comm);
361
363 cfg->collection_selection, buffer, buffer_size, position, comm);
364
366 "yac_interpolation_gen_config_pack",
367 cfg->yaxt_exchanger_name, buffer, buffer_size, position, comm, 1);
368}
369
371 void const * buffer, int buffer_size, int *position, MPI_Comm comm) {
372
373 struct yac_interpolation_gen_config * cfg = xmalloc(1 * sizeof(*cfg));
374
375 int reorder_int;
377 MPI_Unpack(buffer, buffer_size, position, &reorder_int, 1, MPI_INT, comm),
378 comm);
379 cfg->reorder = (enum yac_interp_weights_reorder_type)reorder_int;
380
382 MPI_Unpack(
383 buffer, buffer_size, position,
384 &cfg->frac_mask_fallback_value, 1, MPI_DOUBLE, comm), comm);
386 MPI_Unpack(
387 buffer, buffer_size, position,
388 &cfg->scaling_factor, 1, MPI_DOUBLE, comm), comm);
390 MPI_Unpack(
391 buffer, buffer_size, position,
392 &cfg->scaling_summand, 1, MPI_DOUBLE, comm), comm);
393
394 cfg->collection_selection =
395 yac_collection_selection_unpack(buffer, buffer_size, position, comm);
396
397 cfg->yaxt_exchanger_name =
398 yac_string_unpack(buffer, buffer_size, position, comm);
399
400 return cfg;
401}
#define YAC_ASSERT(exp, msg)
size_t yac_collection_selection_get_collection_size(struct yac_collection_selection const *collection_selection)
Get the size of the collection selection.
struct yac_collection_selection * yac_collection_selection_unpack(void const *buffer, int buffer_size, int *position, MPI_Comm comm)
Unpack a collection selection from a contiguous MPI buffer.
size_t yac_collection_selection_get_pack_size(struct yac_collection_selection const *sel, MPI_Comm comm)
Compute the MPI pack size of a collection selection.
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_copy(const struct yac_collection_selection *collection_selection)
Selection of indices from a collection.
void yac_collection_selection_pack(struct yac_collection_selection const *sel, void *buffer, int buffer_size, int *position, MPI_Comm comm)
Pack a collection selection into a contiguous MPI buffer.
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.
void yac_interpolation_gen_config_set_yaxt_exchanger_name_f2c(struct yac_interpolation_gen_config *config, char const *name)
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.
void yac_interpolation_gen_config_set_reorder_f2c(struct yac_interpolation_gen_config *config, int reorder)
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.
Defines internal basic interpolation definitions.
#define YAC_FRAC_MASK_VALUE_IS_VALID(value)
Test whether a fractional mask value is valid.
Definition __init__.py:1
add versions of standard API functions not returning on error
#define xstrdup(s)
Definition ppm_xfuncs.h:84
#define xmalloc(size)
Definition ppm_xfuncs.h:66
Configuration structure for interpolation generation.
struct yac_collection_selection * collection_selection
enum yac_interp_weights_reorder_type reorder
int collection_size
static struct yac_interp_method_config * config
double * buffer
char const * name
Definition toy_scrip.c:114
#define YAC_ASSERT_F(exp, format,...)
Definition yac_assert.h:39
size_t yac_string_get_pack_size(char const *caller, char const *string, MPI_Comm comm, int allow_null)
Compute number of bytes required to pack a string for MPI transport.
Definition yac_mpi.c:651
char * yac_string_unpack(void const *buffer, int buffer_size, int *position, MPI_Comm comm)
Unpack a C string from a buffer packed with yac_string_pack.
Definition yac_mpi.c:701
void yac_string_pack(char const *caller, char const *string, void *buffer, int buffer_size, int *position, MPI_Comm comm, int allow_null)
Pack a C string into a provided buffer using MPI_Pack semantics.
Definition yac_mpi.c:671
#define yac_mpi_call(call, comm)