YAC 3.13.0
Yet Another Coupler
Loading...
Searching...
No Matches
test_interp_operator_fixed.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 <stdio.h>
7#include <string.h>
8#include <unistd.h>
9
10#include <mpi.h>
11#include <yaxt.h>
12
13#include "tests.h"
15#include "yac_mpi.h"
16#include "test_common.h"
18
24static void utest_init_data();
25static void utest_check_fixed();
26
27enum {
33
34int main(void) {
35
36 MPI_Init(NULL, NULL);
37 xt_initialize(MPI_COMM_WORLD);
38
39 int comm_rank, comm_size;
40 MPI_Comm_rank(MPI_COMM_WORLD, &comm_rank);
41 MPI_Comm_size(MPI_COMM_WORLD, &comm_size);
42
43 if (comm_size != 2) {
44 PUT_ERR("ERROR: test requires 2 processes");
45 xt_finalize();
46 MPI_Finalize();
47 return TEST_EXIT_CODE;
48 }
49
50 // set up source field data structure
51 double * src_fields[MAX_COLLECTION_SIZE][NUM_SRC_FIELDS];
52 double ** src_fields_collection[MAX_COLLECTION_SIZE];
53 for (size_t i = 0; i < MAX_COLLECTION_SIZE; ++i) {
54 for (size_t j = 0; j < NUM_SRC_FIELDS; ++j) {
55 src_fields[i][j] = src_fields_data[i][j];
56 }
57 src_fields_collection[i] = src_fields[i];
58 }
59
60 // set up target field data structure
61 double * tgt_field_collection[MAX_COLLECTION_SIZE];
62 for (size_t i = 0; i < MAX_COLLECTION_SIZE; ++i)
63 tgt_field_collection[i] = tgt_field_data[i];
64
65 struct {
66 size_t N;
67 size_t * indices;
68 } collection_selection_configs[] =
69 {{.N = 3, .indices = (size_t[]){0, 2, 3}},
70 {.N = 4, .indices = (size_t[]){0, 1, 2, 3}},
71 {.N = 2, .indices = NULL}};
72 enum {
73 NUM_COLL_SEL_CONFIGS =
74 sizeof(collection_selection_configs) /
75 sizeof(collection_selection_configs[0])};
76
77 // for all collection selection configurations
78 for (size_t i = 0; i < NUM_COLL_SEL_CONFIGS; ++i) {
79
80 // create collection selection
81 struct yac_collection_selection * sel =
83 collection_selection_configs[i].N,
84 collection_selection_configs[i].indices);
85
86 struct {
87 double fixed_value;
88 size_t num_tgts;
89 size_t * tgts;
90 } fixed_value_configs[] =
91 {{.fixed_value = 1.0, .num_tgts = 0, .tgts = NULL},
92 {.fixed_value = 2.0, .num_tgts = 4, .tgts = (size_t[]){0,2,4,6}},
93 {.fixed_value = 3.0, .num_tgts = 8,
94 .tgts = (size_t[]){0,1,2,3,4,5,6,7}}};
95 enum {
96 NUM_FIXED_VALUE_CONFIGS =
97 sizeof(fixed_value_configs) /
98 sizeof(fixed_value_configs[0])};
99
100 // for all fixed value configurations
101 for (size_t j = 0; j < NUM_FIXED_VALUE_CONFIGS; ++j) {
102
103 // create fixed interpolation operators (on rank 1)
104 // (dummy operator on rank 0)
105 struct yac_interp_operator * interp_fixed =
106 (comm_rank == 0)?
107 yac_interp_operator_fixed_new(NULL, -1.0, 0, NULL):
109 sel, fixed_value_configs[j].fixed_value,
110 fixed_value_configs[j].num_tgts, fixed_value_configs[j].tgts);
111
112 for (int use_interp_fixed_copy = 0; use_interp_fixed_copy <= 1;
113 ++use_interp_fixed_copy) {
114
115 if (use_interp_fixed_copy) {
116 struct yac_interp_operator * interp_fixed_copy =
117 yac_interp_operator_copy(interp_fixed);
118 yac_interp_operator_delete(interp_fixed);
119 interp_fixed = interp_fixed_copy;
120 }
121
122 // generate reference data
123 for (size_t k = 0; k < MAX_COLLECTION_SIZE; ++k) {
124 for (size_t l = 0; l < NUM_TGT_POINTS; ++l) {
125 ref_tgt_field_data[k][l] = (double)-1;
126 }
127 }
128 if (comm_rank == 1) {
129 for (size_t k = 0; k < collection_selection_configs[i].N; ++k) {
130 double fixed_value = fixed_value_configs[j].fixed_value;
131 for (size_t l = 0; l < fixed_value_configs[j].num_tgts; ++l) {
132 ref_tgt_field_data[k][fixed_value_configs[j].tgts[l]] =
133 fixed_value;
134 }
135 }
136 }
137
138 struct {
139 double frac_mask_fallback_value;
140 } frac_mask_configs[] =
141 {{.frac_mask_fallback_value = YAC_FRAC_MASK_NO_VALUE},
142 {.frac_mask_fallback_value = 10.0}};
143 enum {
144 NUM_FRAC_MASK_CONFIGS =
145 sizeof(frac_mask_configs) / sizeof(frac_mask_configs[0])};
146
147 for (size_t frac_mask_config_idx = 0;
148 frac_mask_config_idx < NUM_FRAC_MASK_CONFIGS;
149 ++frac_mask_config_idx) {
150
151 double frac_mask_fallback_value =
152 frac_mask_configs[frac_mask_config_idx].frac_mask_fallback_value;
153
154 { // test synchronous exchange
155
156 // initialise source and target fields data
157 utest_init_data();
158
160 interp_fixed, src_fields_collection, NULL, tgt_field_collection,
161 frac_mask_fallback_value, 1.0, 0.0);
162
163 // check data
164 utest_check_fixed();
165 }
166
167 { // test independent execution of put and get
168
169 // initialise source and target fields data
170 utest_init_data();
171
173 interp_fixed, src_fields_collection, NULL,
174 1, frac_mask_fallback_value, 1.0, 0.0);
176 interp_fixed, tgt_field_collection,
177 frac_mask_fallback_value, 1.0, 0.0);
178
179 // Before get: execute_put_test result is
180 // undefined (can be either true or false)
181 if (!yac_interp_operator_execute_put_test(interp_fixed))
182 PUT_ERR("error in execute_put_test");
183 if (!yac_interp_operator_execute_get_test(interp_fixed))
184 PUT_ERR("error in execute_get_test");
185
186 // check data
187 utest_check_fixed();
188 }
189
190 { // test independent execution of put and async get
191
192 // initialise source and target fields data
193 utest_init_data();
194
196 interp_fixed, src_fields_collection, NULL,
197 1, frac_mask_fallback_value, 1.0, 0.0);
199 interp_fixed, tgt_field_collection,
200 frac_mask_fallback_value, 1.0, 0.0);
202
203 // Before wait: execute_put_test and execute_get_test result is
204 // undefined (can be either true or false)
205 if (!yac_interp_operator_execute_put_test(interp_fixed))
206 PUT_ERR("error in execute_put_test");
207 if (!yac_interp_operator_execute_get_test(interp_fixed))
208 PUT_ERR("error in execute_get_test");
209
210 // check data
211 utest_check_fixed();
212 }
213
214 } // frac_mask_config_idx
215
216 } // use_interp_fixed_copy
217
218 yac_interp_operator_delete(interp_fixed);
219
220 } // NUM_FIXED_VALUE_CONFIGS
221
222 // free collection selection
224
225 } // NUM_COLL_SEL_CONFIGS
226
227 xt_finalize();
228 MPI_Finalize();
229
230 return TEST_EXIT_CODE;
231}
232
233static void utest_init_data() {
234
235 // initialise source and target fields data
236 for (size_t k = 0; k < MAX_COLLECTION_SIZE; ++k) {
237 for (size_t l = 0; l < NUM_SRC_FIELDS; ++l) {
238 for (size_t m = 0; m < NUM_SRC_POINTS; ++m) {
239 src_fields_data[k][l][m] = (double)m;
240 }
241 }
242 for (size_t l = 0; l < NUM_TGT_POINTS; ++l) {
243 tgt_field_data[k][l] = (double)-1;
244 }
245 }
246}
247
248static void utest_check_fixed() {
249
250 for (size_t i = 0; i < MAX_COLLECTION_SIZE; ++i) {
251 for (size_t j = 0; j < NUM_TGT_POINTS; ++j) {
252 if (tgt_field_data[i][j] != ref_tgt_field_data[i][j])
253 PUT_ERR("wrong data");
254 }
255 }
256}
void yac_collection_selection_delete(struct yac_collection_selection *collection_selection)
Delete a collection selection object.
struct yac_collection_selection * yac_collection_selection_new(size_t collection_size, size_t const *selection_indices)
Create a new collection selection.
struct yac_interp_operator * yac_interp_operator_fixed_new(struct yac_collection_selection const *collection_selection, double value, size_t count, size_t const *pos)
Create a fixed-value interpolation operator.
void yac_interp_operator_execute_wait(struct yac_interp_operator *interp)
Wait for all pending put/get operations to finish.
struct yac_interp_operator * yac_interp_operator_copy(struct yac_interp_operator *interp)
Create a deep copy of the interpolation operator.
enum YAC_INTERP_TEST_STATUS yac_interp_operator_execute_put_test(struct yac_interp_operator *interp)
Test whether the put phase has completed.
enum YAC_INTERP_TEST_STATUS yac_interp_operator_execute_get_test(struct yac_interp_operator *interp)
Test whether the get phase has completed.
void yac_interp_operator_execute_get(struct yac_interp_operator *interp, double **tgt_field, double frac_mask_fallback_value, double scale_factor, double scale_summand)
void yac_interp_operator_execute_put(struct yac_interp_operator *interp, double ***src_fields, double ***src_frac_masks, int is_target, double frac_mask_fallback_value, double scale_factor, double scale_summand)
void yac_interp_operator_execute_get_async(struct yac_interp_operator *interp, double **tgt_field, double frac_mask_fallback_value, double scale_factor, double scale_summand)
void yac_interp_operator_execute(struct yac_interp_operator *interp, double ***src_fields, double ***src_frac_masks, double **tgt_field, double frac_mask_fallback_value, double scale_factor, double scale_summand)
void yac_interp_operator_delete(struct yac_interp_operator *interp)
Delete the interpolation operator and free resources.
Fixed-value interpolation operator in YAC.
double const YAC_FRAC_MASK_NO_VALUE
Public interface for interpolation execution in YAC.
Abstract interpolation operator type.
static double tgt_field_data[MAX_COLLECTION_SIZE][NUM_TGT_POINTS]
static double src_fields_data[MAX_COLLECTION_SIZE][NUM_SRC_FIELDS][NUM_SRC_POINTS]
static double ref_tgt_field_data[MAX_COLLECTION_SIZE][NUM_TGT_POINTS]
#define N
#define TEST_EXIT_CODE
Definition tests.h:14
#define PUT_ERR(string)
Definition tests.h:10