31#define YAC_RAD (0.01745329251994329576923690768489)
33int main(
int argc,
char *argv[]) {
36 PUT_ERR(
"wrong number of arguments\n");
44 PUT_ERR(
"invalid argument (has to be either \"src\" or \"tgt\")\n");
50 xt_initialize(MPI_COMM_WORLD);
52 int comm_rank, comm_size;
53 MPI_Comm_rank(MPI_COMM_WORLD, &comm_rank);
54 MPI_Comm_size(MPI_COMM_WORLD, &comm_size);
55 MPI_Barrier(MPI_COMM_WORLD);
58 PUT_ERR(
"ERROR: wrong number of processes");
64 unsigned is_source = comm_rank > 0;
65 unsigned is_target = comm_rank < 2;
110 char const source_grid_name[] =
"source_grid";
111 char const target_grid_name[] =
"target_grid";
113 double src_coordinates_x[] = {0,1,2,3,4,5};
114 double src_coordinates_y[] = {0,1,2,3,4};
115 size_t src_global_num_cells[] = {5,4};
116 int src_with_halo = 1;
117 size_t src_local_start[2][2] = {{0,0}, {0,2}};
118 size_t src_local_count[2] = {5,2};
120 for (
size_t i = 0; i <= src_global_num_cells[0]; ++i)
121 src_coordinates_x[i] *=
YAC_RAD;
122 for (
size_t i = 0; i <= src_global_num_cells[1]; ++i)
123 src_coordinates_y[i] *=
YAC_RAD;
129 utest_generate_basic_grid_data_reg2d(
130 src_coordinates_x, src_coordinates_y, src_global_num_cells,
131 src_local_start[comm_rank-1], src_local_count, src_with_halo)):
134 double tgt_coordinates_x[] = {0.7,1.7,2.7,3.7,4.7,5.7,6.7};
135 double tgt_coordinates_y[] = {0.7,1.7,2.7,3.7};
136 size_t tgt_global_num_cells[] = {6,3};
137 int tgt_with_halo = 1;
138 size_t tgt_local_start[2][2] = {{3,0}, {0,0}};
139 size_t tgt_local_count[2] = {3,3};
141 for (
size_t i = 0; i <= tgt_global_num_cells[0]; ++i)
142 tgt_coordinates_x[i] *=
YAC_RAD;
143 for (
size_t i = 0; i <= tgt_global_num_cells[1]; ++i)
144 tgt_coordinates_y[i] *=
YAC_RAD;
150 utest_generate_basic_grid_data_reg2d(
151 tgt_coordinates_x, tgt_coordinates_y, tgt_global_num_cells,
152 tgt_local_start[comm_rank], tgt_local_count, tgt_with_halo)):
162 size_t num_src_fields =
sizeof(src_fields) /
sizeof(src_fields[0]);
164 {.location =
YAC_LOC_CORNER, .coordinates_idx = SIZE_MAX, .masks_idx = SIZE_MAX};
171 char const * sum_weight_file_name =
172 "test_interpolation_parallel5_weight_file.nc";
173 if (comm_rank == 0) {
174 int src_indices[4*5*4] =
175 {0,1,6,7, 1,2,7,8, 2,3,8,9, 3,4,9,10, 4,5,10,11,
176 6,7,12,13, 7,8,13,14, 8,9,14,15, 9,10,15,16, 10,11,16,17,
177 12,13,18,19, 13,14,19,20, 14,15,20,21, 15,16,21,22, 16,17,22,23,
178 18,19,24,25, 19,20,25,26, 20,21,26,27, 21,22,27,28, 22,23,28,29};
179 int tgt_indices[4*5*4] =
180 {0,0,0,0, 1,1,1,1, 2,2,2,2, 3,3,3,3, 4,4,4,4,
181 7,7,7,7, 8,8,8,8, 9,9,9,9, 10,10,10,10, 11,11,11,11,
182 14,14,14,14, 15,15,15,15, 16,16,16,16, 17,17,17,17, 18,18,18,18,
183 21,21,21,21, 22,22,22,22, 23,23,23,23, 24,24,24,24, 25,25,25,25};
184 double weights[4*5*4];
185 for (
size_t i = 0; i < 4*5*4; ++i) weights[i] = 1.0;
186 size_t num_links = 4*5*4;
190 int num_links_per_field[1] = {num_links};
191 int * tgt_id_fixed = NULL;
192 size_t num_fixed_tgt = 0;
193 double * fixed_values = NULL;
194 int * num_tgt_per_fixed_value = NULL;
195 size_t num_fixed_values = 0;
197 utest_write_weight_file(
198 sum_weight_file_name, src_indices, tgt_indices, weights, num_links,
200 num_fixed_tgt, fixed_values, num_tgt_per_fixed_value,
201 num_fixed_values, tgt_location,
202 source_grid_name, target_grid_name);
204 MPI_Barrier(MPI_COMM_WORLD);
206 size_t const num_method_stacks = 3;
215 .max_search_distance =
225 for (
size_t method_stack_index = 0;
226 method_stack_index < num_method_stacks; ++method_stack_index) {
230 method_stacks[method_stack_index], interp_grid);
236 weights, reorder_type, 1,
240 "test_interpolation_parallel5_weight_file_out.nc";
251 double * source_data_field =
254 double * source_data_pointset[1] = {source_data_field};
255 double ** source_data[1] = {source_data_pointset};
259 double * target_data_field =
262 double * target_data[1] = {target_data_field};
269 for (
size_t i = 0; i < src_grid_data->
num_vertices; ++i)
270 source_data_field[i] =
272 ((double)(src_grid_data->
vertex_ids[i])):(-1.0);
275 for (
int use_put_get = 0; use_put_get < 2; ++use_put_get) {
281 for (
size_t i = 0; i < tgt_grid_data->
num_vertices; ++i)
282 target_data_field[i] = -1.0;
300 double ref_target_data[3][4*7] =
301 {{3.5,4.5,5.5,6.5,7.5,1337,1337,
302 9.5,10.5,11.5,12.5,13.5,1337,1337,
303 15.5,16.5,17.5,18.5,19.5,1337,1337,
304 21.5,22.5,23.5,24.5,25.5,1337,1337},
306 13,14,15,16,17,17,17,
307 19,20,21,22,23,23,23,
308 25,26,27,28,29,29,29},
309 {14,18,22,26,30,1337,1337,
310 38,42,46,50,54,1337,1337,
311 62,66,70,74,78,1337,1337,
312 86,90,94,98,102,1337,1337}};
314 for (
size_t i = 0; i < tgt_grid_data->
num_vertices; ++i) {
316 if (utest_double_are_unequal(
319 [method_stack_index][tgt_grid_data->
vertex_ids[i]]))
320 PUT_ERR(
"error in interpolated data on target side\n");
322 if (target_data[0][i] != -1.0)
323 PUT_ERR(
"error in interpolated data on target side\n");
329 if (is_target) free(target_data_field);
330 if (is_source) free(source_data_field);
342 if (comm_rank == 0) unlink(sum_weight_file_name);
struct yac_basic_grid * yac_basic_grid_new(char const *name, struct yac_basic_grid_data grid_data)
struct yac_basic_grid_data * yac_basic_grid_get_data(struct yac_basic_grid *grid)
struct yac_basic_grid * yac_basic_grid_empty_new(char const *name)
void yac_basic_grid_delete(struct yac_basic_grid *grid)
void yac_dist_grid_pair_delete(struct yac_dist_grid_pair *grid_pair)
struct yac_dist_grid_pair * yac_dist_grid_pair_new(struct yac_basic_grid *grid_a, struct yac_basic_grid *grid_b, MPI_Comm comm)
void yac_interp_grid_delete(struct yac_interp_grid *interp_grid)
struct yac_interp_grid * yac_interp_grid_new(struct yac_dist_grid_pair *grid_pair, char const *src_grid_name, char const *tgt_grid_name, size_t num_src_fields, struct yac_interp_field const *src_fields, struct yac_interp_field const tgt_field)
void yac_interp_method_delete(struct interp_method **method)
Delete an interpolation stack and free its resources (but not the pointer array).
struct yac_interp_weights * yac_interp_method_do_search(struct interp_method **method, struct yac_interp_grid *interp_grid)
Perform weight computation using given interpolation stack and grid.
struct interp_method * yac_interp_method_avg_new(enum yac_interp_avg_weight_type weight_type, int partial_coverage)
@ YAC_INTERP_AVG_ARITHMETIC
struct interp_method * yac_interp_method_file_new(char const *weight_file_name, enum yac_interp_file_on_missing_file on_missing_file, enum yac_interp_file_on_success on_success)
#define YAC_INTERP_FILE_ON_SUCCESS_DEFAULT
#define YAC_INTERP_FILE_ON_MISSING_FILE_DEFAULT
struct interp_method * yac_interp_method_fixed_new(double value)
struct interp_method * yac_interp_method_nnn_new(struct yac_interp_method_nnn_config config)
@ YAC_INTERP_NNN_AVG
average of n source points
#define YAC_INTERP_NNN_MAX_SEARCH_DISTANCE_DEFAULT
#define YAC_INTERP_NNN_N_MIN_DEFAULT
a value of 0 is interpreted as "use the value of n"
struct yac_interpolation * yac_interp_weights_get_interpolation(struct yac_interp_weights *weights, enum yac_interp_weights_reorder_type reorder, size_t collection_size, double frac_mask_fallback_value, double scaling_factor, double scaling_summand, char const *yaxt_exchanger_name, int is_source, int is_target)
void yac_interp_weights_delete(struct yac_interp_weights *weights)
void yac_interp_weights_write_to_file(struct yac_interp_weights *weights, char const *filename, char const *src_grid_name, char const *tgt_grid_name, size_t src_grid_size, size_t tgt_grid_size, enum yac_weight_file_on_existing on_existing)
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
@ YAC_WEIGHT_FILE_ERROR
error when weight file existis already
void yac_interpolation_execute(struct yac_interpolation *interp, double ***src_fields, double **tgt_field)
Execute interpolation synchronously and write results to the target field.
void yac_interpolation_delete(struct yac_interpolation *interp)
Free an interpolation object and release all resources.
void yac_interpolation_execute_get(struct yac_interpolation *interp, double **tgt_field)
Complete interpolation and write results to the target field (get phase).
void yac_interpolation_execute_put(struct yac_interpolation *interp, double ***src_fields)
Provide source field data and start asynchronous execution of interpolation (put phase).
double const YAC_FRAC_MASK_NO_VALUE
enum yac_location location
struct yac_interp_field tgt_field
struct yac_dist_grid_pair * grid_pair
struct yac_interp_field src_fields[]
char const weight_file_out[]