29#define YAC_RAD (0.01745329251994329576923690768489)
32#define NUM_CELLS_X 128
33#define NUM_CELLS_Y 128
34#define NUM_CELLS_X_2 64
35#define NUM_CELLS_Y_2 64
37static void utest_generate_input_weights();
39static void utest_generate_ref_weights();
41static void utest_submain_src(
44static void utest_submain_tgt(
54 "test_interpolation_parallel4_weight_file_in.nc";
56 "test_interpolation_parallel4_weight_file_out.nc";
78int main(
int argc,
char *argv[]) {
81 PUT_ERR(
"wrong number of arguments\n");
89 PUT_ERR(
"invalid argument (has to be either \"src\" or \"tgt\")\n");
95 xt_initialize(MPI_COMM_WORLD);
97 utest_generate_input_weights();
98 utest_generate_ref_weights();
106 int comm_rank, comm_size;
107 MPI_Comm_rank(MPI_COMM_WORLD, &comm_rank);
108 MPI_Comm_size(MPI_COMM_WORLD, &comm_size);
109 MPI_Barrier(MPI_COMM_WORLD);
111 if (comm_size != 5) {
112 PUT_ERR(
"ERROR: wrong number of processes");
120 int comp_flag = comm_rank < 4;
126 if (comp_flag) utest_submain_src(
split_comm, reorder_type);
127 else utest_submain_tgt(
split_comm, reorder_type);
136static void utest_submain_tgt(
141 size_t local_start[2] = {0,0};
177 size_t num_src_fields =
sizeof(src_fields) /
sizeof(src_fields[0]);
179 {.location =
YAC_LOC_CELL, .coordinates_idx = 0, .masks_idx = SIZE_MAX};
199 weights, reorder_type, 1,
210 double * target_field_ = &target_field[0][0];
211 double ** target_data = &target_field_;
215 target_field[i][j] = -1;
230 ref_target_field[i] = 0;
234 for (
unsigned k = 0; k < 4; ++k)
240 if (fabs(target_field[i][j] - ref_target_field[i *
NUM_CELLS_X + j]) >
242 PUT_ERR(
"wrong interpolation result\n")
262static
void utest_submain_src(
266 MPI_Comm_rank(comp_comm, &my_rank);
272 int * tgt_id_fixed = NULL;
273 unsigned num_fixed_tgt = 0;
274 double * fixed_values = NULL;
275 int * num_tgt_per_fixed_value = NULL;
276 unsigned num_fixed_values = 0;
280 tgt_id_fixed, num_fixed_tgt, fixed_values,
281 num_tgt_per_fixed_value, num_fixed_values,
285 size_t local_start[4][2] =
293 local_start[my_rank], local_count,
with_halo);
309 size_t num_src_fields =
sizeof(src_fields) /
sizeof(src_fields[0]);
311 {.location =
YAC_LOC_CELL, .coordinates_idx = 0, .masks_idx = SIZE_MAX};
331 weights, reorder_type, 1,
341 double * source_data_field =
342 xmalloc(num_vertices *
sizeof(*source_data_field));
344 double * source_data_pointset[1] = {source_data_field};
345 double ** source_data[1] = {source_data_pointset};
346 for (
size_t i = 0;
i < num_vertices; ++
i)
347 source_data_field[i] =
349 ((double)(
grid_data.vertex_ids[i])):(-1.0);
376 free(source_data_field);
398utest_generate_input_weights() {
410 for (
unsigned k = 0; k < 4; ++k)
413 for (
unsigned k = 0; k < 4; ++k)
420utest_generate_ref_weights() {
423 for (
unsigned j = 0; j <
NUM_CELLS_X; ++j, ++idx) {
428 for (
unsigned k = 0; k < 4; ++k) {
436 for (
unsigned k = 0; k < 4; ++k)
struct yac_basic_grid * yac_basic_grid_new(char const *name, struct yac_basic_grid_data grid_data)
size_t yac_basic_grid_add_coordinates_nocpy(struct yac_basic_grid *grid, enum yac_location location, yac_coordinate_pointer coordinates)
size_t yac_basic_grid_add_coordinates(struct yac_basic_grid *grid, enum yac_location location, yac_coordinate_pointer coordinates, size_t count)
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)
struct yac_basic_grid_data yac_generate_basic_grid_data_reg2d(double const *global_coords_x, double const *global_coords_y, size_t const num_global_cells_[2], size_t const local_start[2], size_t const local_count[2], int with_halo)
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)
struct yac_interp_weights * yac_interp_method_do_search(struct interp_method **method, struct yac_interp_grid *interp_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 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_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[]
static MPI_Comm split_comm
double cell_coordinates_y[]
double cell_coordinates_x[]
int tgt_address_file[NUM_CELLS_Y_2][NUM_CELLS_X_2][4]
int const * ref_tgt_address_fixed
int ref_tgt_address[NUM_CELLS_Y][NUM_CELLS_X][4]
unsigned ref_num_fixed_values
char const src_grid_name[]
int ref_src_address[NUM_CELLS_Y][NUM_CELLS_X][4]
char const tgt_grid_name[]
double weights_file[NUM_CELLS_Y_2][NUM_CELLS_X_2][4]
char const weight_file_out[]
double global_coordinates_y[NUM_CELLS_X+1]
int const * ref_num_tgt_per_fixed_value
double global_coordinates_x[NUM_CELLS_X+1]
double const * ref_fixed_values
int src_address_file[NUM_CELLS_Y_2][NUM_CELLS_X_2][4]
double ref_weights[NUM_CELLS_Y][NUM_CELLS_X][4]
char const weight_file_in[]
static void LLtoXYZ(double lon, double lat, double p_out[])
void check_weight_file(char const *file_name, int const *ref_src_address, int const *ref_tgt_address, double const *ref_weights, unsigned ref_num_links, enum yac_location const *ref_src_locations, unsigned ref_num_src_fields, int const *ref_num_links_per_src_field, int const *ref_tgt_address_fixed, double const *ref_fixed_values, int const *ref_num_tgt_per_fixed_value, unsigned ref_num_fixed_values, enum yac_location ref_tgt_location, char const *ref_src_grid_name, char const *ref_tgt_grid_name)
void write_weight_file(char const *file_name, int const *src_id, int const *tgt_id, double const *weights, unsigned num_links, enum yac_location const *src_locations, unsigned num_src_fields, int const *num_links_per_src_field, int *tgt_id_fixed, unsigned num_fixed_tgt, double *fixed_values, int *num_tgt_per_fixed_value, unsigned num_fixed_values, enum yac_location tgt_location, char const *src_grid_name, char const *tgt_grid_name)