36static void utest_compute_weights_callback(
37 double const tgt_coords[3],
int src_cell_id,
size_t src_cell_idx,
38 int const ** global_results_points,
double ** result_weights,
47} utest_instr_counters;
50static void utest_instrumentation_enable(utest_instr_counters * instr_ctx);
53static void utest_instrumentation_disable_and_check(
54 utest_instr_counters * instr_ctx,
int const * ref_start_calls);
57static void utest_init_ref_start_calls(
58 int * ref_start_calls,
int default_start_calls);
60int main(
int argc,
char** argv) {
64 xt_initialize(MPI_COMM_WORLD);
66 int comm_rank, comm_size;
67 MPI_Comm_rank(MPI_COMM_WORLD, &comm_rank);
68 MPI_Comm_size(MPI_COMM_WORLD, &comm_size);
70 utest_set_even_io_rank_list(MPI_COMM_WORLD);
73 PUT_ERR(
"ERROR: missing grid file directory");
80 char * grid_filenames[] ={
"icon_grid_R02B01.nc",
"icon_grid_R03B01.nc"};
81 for (
int i = 0;
i < 2; ++
i)
85 malloc(strlen(argv[1]) + strlen(grid_filenames[i]) + 2), argv[1]),
90 for (
int i = 0;
i < 2; ++
i)
93 filenames[i], MPI_COMM_WORLD);
104 size_t num_src_fields =
sizeof(src_fields) /
sizeof(src_fields[0]);
106 {.location =
YAC_LOC_CELL, .coordinates_idx = SIZE_MAX, .masks_idx = SIZE_MAX};
119 utest_instr_counters instr_ctx;
120 utest_instrumentation_enable(&instr_ctx);
127 utest_init_ref_start_calls(ref_start_calls, 0);
128 ref_start_calls[YAC_INSTR_INTERP_SEARCH_FIXED] = 1;
130 utest_instrumentation_disable_and_check(&instr_ctx, ref_start_calls);
152 for (
int i = 0;
i < 2; ++
i) {
159 char const * weight_file_empty =
160 "test_interp_method_parallel_weights_empty.nc";
161 char const * weight_file_fixed =
162 "test_interp_method_parallel_weights_fixed.nc";
168 if (comm_rank == 0) {
171 int * tgt_indices = NULL;
172 int * src_indices = NULL;
174 size_t num_links = 0;
178 NUM_SRC_FIELDS =
sizeof(src_locations) /
sizeof(src_locations[0])};
180 int * tgt_id_fixed = NULL;
181 size_t num_fixed_tgt = 0;
182 double * fixed_values = NULL;
183 int * num_tgt_per_fixed_value = NULL;
184 size_t num_fixed_values = 0;
186 utest_write_weight_file(
187 weight_file_empty, src_indices, tgt_indices, weights, num_links,
189 num_fixed_tgt, fixed_values, num_tgt_per_fixed_value,
194 int * tgt_indices = NULL;
195 int * src_indices = NULL;
197 size_t num_links = 0;
201 NUM_SRC_FIELDS =
sizeof(src_locations) /
sizeof(src_locations[0])};
203 int tgt_id_fixed[] = {0, 1, 2, 3};
204 size_t num_fixed_tgt = 4;
205 double fixed_values[] = {999.0};
206 int num_tgt_per_fixed_value[] = {4};
207 size_t num_fixed_values = 1;
209 utest_write_weight_file(
210 weight_file_fixed, src_indices, tgt_indices, weights, num_links,
212 num_fixed_tgt, fixed_values, num_tgt_per_fixed_value,
218 size_t num_vertices[2] = {3,3};
229 double cell_coords_x[] = {0.5, 1.5};
230 double cell_coords_y[] = {0.5, 1.5};
231 for (
int i = 0, k = 0;
i < 2; ++
i)
232 for (
int j = 0; j < 2; ++j, ++k)
242 size_t num_src_fields =
sizeof(src_fields) /
sizeof(src_fields[0]);
244 {.location =
YAC_LOC_CELL, .coordinates_idx = 0, .masks_idx = SIZE_MAX};
295 utest_instr_counters instr_ctx;
296 utest_instrumentation_enable(&instr_ctx);
303 "error in handling of interpolation_complete argument by do_search");
310 utest_init_ref_start_calls(ref_start_calls, 0);
311 ref_start_calls[YAC_INSTR_INTERP_SEARCH_FILE] = 1;
312 ref_start_calls[YAC_INSTR_INTERP_SEARCH_CHECK] = 1;
314 utest_instrumentation_disable_and_check(&instr_ctx, ref_start_calls);
332 utest_instr_counters nnn_instr_ctx;
333 utest_instrumentation_enable(&nnn_instr_ctx);
339 utest_init_ref_start_calls(ref_start_calls, 0);
340 ref_start_calls[YAC_INSTR_INTERP_SEARCH_NNN] = 1;
342 utest_instrumentation_disable_and_check(&nnn_instr_ctx, ref_start_calls);
344 int nnn_search_calls =
345 nnn_instr_ctx.start_calls[YAC_INSTR_DIST_GRID_PAIR_NNN_SEARCH];
346 int nnn_search_depth =
347 nnn_instr_ctx.last_start_depth[YAC_INSTR_DIST_GRID_PAIR_NNN_SEARCH];
349 if (nnn_search_calls != 1) {
351 "error in instrumentation of yac_dist_grid_pair_do_nnn_search: "
352 "region was entered %d times (expected 1)\n", nnn_search_calls);
353 }
else if (nnn_search_depth != 2) {
355 "error in instrumentation of yac_dist_grid_pair_do_nnn_search: "
356 "region was entered at depth %d (expected 2)\n", nnn_search_depth);
374 if (comm_rank == 0) {
375 unlink(weight_file_empty);
376 unlink(weight_file_fixed);
387static void utest_compute_weights_callback(
388 double const tgt_coords[3],
int src_cell_id,
size_t src_cell_idx,
389 int const ** global_results_points,
double ** result_weights,
390 size_t * result_count,
void *
user_data) {
395 UNUSED(global_results_points);
400 PUT_ERR(
"ERROR: in handling interpolation_complete in do_search_callback");
407static void * utest_instrument_create_cb(
int id,
void *
user_data) {
411 return (
void *)&utest_instr_handles[
id];
414static void utest_instrument_start_cb(
415 int id,
void * handle,
int depth,
void *
user_data) {
417 utest_instr_counters * instr_ctx = (utest_instr_counters *)
user_data;
419 if (handle != (
void *)&utest_instr_handles[
id])
420 instr_ctx->bad_handle_calls++;
421 instr_ctx->start_calls[
id]++;
422 instr_ctx->last_start_depth[
id] = depth;
425static void utest_instrument_stop_cb(
426 int id,
void * handle,
int depth,
void *
user_data) {
430 utest_instr_counters * instr_ctx = (utest_instr_counters *)
user_data;
432 if (handle != (
void *)&utest_instr_handles[
id])
433 instr_ctx->bad_handle_calls++;
434 instr_ctx->stop_calls[
id]++;
437static void utest_instrumentation_enable(utest_instr_counters * instr_ctx) {
439 memset(instr_ctx, 0,
sizeof(*instr_ctx));
441 instr_ctx->last_start_depth[i] = -1;
444 utest_instrument_create_cb, utest_instrument_start_cb,
445 utest_instrument_stop_cb, NULL, instr_ctx);
448static void utest_init_ref_start_calls(
449 int * ref_start_calls,
int default_start_calls) {
456 ref_start_calls[i] = -1;
457 for (
int i = YAC_INSTR_INTERP_SEARCH;
458 i <= YAC_INSTR_INTERP_SEARCH_SPMAP; ++
i)
459 ref_start_calls[i] = default_start_calls;
462 ref_start_calls[YAC_INSTR_INTERP_SEARCH] = 1;
465static void utest_instrumentation_disable_and_check(
466 utest_instr_counters * instr_ctx,
int const * ref_start_calls) {
470 if (instr_ctx->bad_handle_calls != 0)
472 "error in instrumentation of do_search "
473 "(handle does not match the one created for the region)");
477 char const * region_name =
480 if (instr_ctx->start_calls[i] != instr_ctx->stop_calls[i])
482 "error in instrumentation of do_search: region \"%s\" was started "
483 "%d times, but stopped %d times\n",
484 region_name, instr_ctx->start_calls[i], instr_ctx->stop_calls[i]);
486 if (ref_start_calls[i] == -1)
continue;
488 if (instr_ctx->start_calls[i] != ref_start_calls[i])
490 "error in instrumentation of do_search: region \"%s\" was started "
491 "%d times (expected %d)\n",
492 region_name, instr_ctx->start_calls[i], ref_start_calls[i]);
496 if (instr_ctx->start_calls[i] > 0) {
497 int ref_depth = (
i == (size_t)YAC_INSTR_INTERP_SEARCH)?0:1;
498 if (instr_ctx->last_start_depth[i] != ref_depth)
500 "error in instrumentation of do_search: region \"%s\" was started "
501 "at depth %d (expected %d)\n",
502 region_name, instr_ctx->last_start_depth[i], ref_depth);
struct yac_basic_grid * yac_basic_grid_new(char const *name, struct yac_basic_grid_data grid_data)
struct yac_basic_grid * yac_basic_grid_reg_2d_deg_new(char const *name, size_t nbr_vertices[2], int cyclic[2], double *lon_vertices, double *lat_vertices)
size_t yac_basic_grid_add_coordinates(struct yac_basic_grid *grid, enum yac_location location, yac_coordinate_pointer coordinates, size_t count)
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)
static void LLtoXYZ_deg(double lon, double lat, double p_out[])
void yac_instrument_set_callbacks(yac_instrument_create_cb create_cb, yac_instrument_start_cb start_cb, yac_instrument_stop_cb stop_cb, yac_instrument_destroy_cb destroy_cb, void *user_data)
void yac_instrument_clear_callbacks(void)
const char * yac_instrument_region_name(yac_instrument_region_id id)
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.
Defines the interface of the interpolation method "base class" in YAC.
struct interp_method * yac_interp_method_avg_new(enum yac_interp_avg_weight_type weight_type, int partial_coverage)
#define YAC_INTERP_AVG_PARTIAL_COVERAGE_DEFAULT
yac_interp_avg_weight_type
#define YAC_INTERP_AVG_WEIGHT_TYPE_DEFAULT
struct interp_method * yac_interp_method_callback_new(yac_func_compute_weights compute_weights_callback, void *user_data)
struct interp_method * yac_interp_method_check_new(func_constructor constructor_callback, void *constructor_user_data, func_do_search do_search_callback, void *do_search_user_data)
struct interp_method * yac_interp_method_conserv_new(int order, int enforced_conserv, int partial_coverage, enum yac_interp_method_conserv_normalisation normalisation)
#define YAC_INTERP_CONSERV_NORMALISATION_DEFAULT
#define YAC_INTERP_CONSERV_ENFORCED_CONSERV_DEFAULT
#define YAC_INTERP_CONSERV_PARTIAL_COVERAGE_DEFAULT
#define YAC_INTERP_CONSERV_ORDER_DEFAULT
yac_interp_method_conserv_normalisation
struct interp_method * yac_interp_method_creep_new(int creep_distance)
#define YAC_INTERP_CREEP_DISTANCE_DEFAULT
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)
@ YAC_INTERP_FILE_MISSING_ERROR
abort on missing file
@ YAC_INTERP_FILE_SUCCESS_CONT
@ YAC_INTERP_FILE_SUCCESS_STOP
struct interp_method * yac_interp_method_fixed_new(double value)
#define YAC_INTERP_FIXED_VALUE_DEFAULT
struct interp_method * yac_interp_method_hcsbb_new()
struct interp_method * yac_interp_method_ncc_new(enum yac_interp_ncc_weight_type weight_type, int partial_coverage)
#define YAC_INTERP_NCC_PARTIAL_COVERAGE_DEFAULT
#define YAC_INTERP_NCC_WEIGHT_TYPE_DEFAULT
yac_interp_ncc_weight_type
struct interp_method * yac_interp_method_nnn_new(struct yac_interp_method_nnn_config config)
#define YAC_INTERP_NNN_WEIGHTED_DEFAULT
yac_interp_nnn_weight_type
@ YAC_INTERP_NNN_AVG
average of n source points
#define YAC_INTERP_NNN_MAX_SEARCH_DISTANCE_DEFAULT
#define YAC_INTERP_NNN_GAUSS_SCALE_DEFAULT
#define YAC_INTERP_NNN_N_DEFAULT
struct interp_method * yac_interp_method_spmap_new(struct yac_interp_spmap_config const *default_config, struct yac_spmap_overwrite_config const *const *overwrite_configs)
#define YAC_INTERP_SPMAP_OVERWRITE_DEFAULT
#define YAC_INTERP_SPMAP_DEFAULT_CONFIG
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)
size_t yac_interp_weights_get_interp_count(struct yac_interp_weights *weights)
@ YAC_MAPPING_ON_TGT
weights will be applied at target processes
@ YAC_MAPPING_ON_SRC
weights will be applied at source processes
void yac_interpolation_delete(struct yac_interpolation *interp)
Free an interpolation object and release all resources.
double const YAC_FRAC_MASK_NO_VALUE
struct yac_basic_grid_data yac_read_icon_basic_grid_data_parallel(const char *filename, MPI_Comm comm)
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 src_grid_name[]
char const tgt_grid_name[]
double cell_coords[36][3]
#define PUT_ERR_F(fmt,...)