30double const tol = 1e-7;
35char const file_name[] =
"test_interp_method_file_parallel_weights.nc";
36char const file_name_2[] =
"test_interp_method_file_parallel_weights_2.nc";
38static void utest_target_main(MPI_Comm target_comm);
39static void utest_source_main(MPI_Comm source_comm);
40static void utest_target_main_abort(MPI_Comm target_comm);
41static void utest_source_main_abort(MPI_Comm source_comm);
54 MPI_Comm comm,
char const * msg,
char const * source,
int line);
62 xt_initialize(MPI_COMM_WORLD);
64 int comm_rank, comm_size;
65 MPI_Comm_rank(MPI_COMM_WORLD, &comm_rank);
66 MPI_Comm_size(MPI_COMM_WORLD, &comm_size);
67 MPI_Barrier(MPI_COMM_WORLD);
70 PUT_ERR(
"ERROR: wrong number of processes");
76 int tgt_flag = comm_rank < 1;
77 MPI_Comm_split(MPI_COMM_WORLD, tgt_flag, 0, &
split_comm);
79 char const * io_ranks[3] = {
"0",
"1,2",
"0,1,2"};
81 for (
int i = 0; i < 3; ++i) {
83 setenv(
"YAC_IO_RANK_LIST", io_ranks[i], 1);
84 setenv(
"YAC_IO_MAX_NUM_RANKS_PER_NODE",
"3", 1);
90 if (tgt_flag) utest_target_main_abort(
split_comm);
100static void utest_source_main(MPI_Comm source_comm) {
103 MPI_Comm_rank(source_comm, &my_source_rank);
126 if (my_source_rank == 0) {
128 int src_indices[] = {0,1,2,3,4,5,6,7,8,9,10,11};
129 int tgt_indices[] = {0,1,2,3,4,5,6,7,8,9,10,11};
130 double weights[] = {0,1,2,3,4,5,6,7,8,9,10,11};
131 size_t num_links = 12;
134 unsigned num_src_fields = 2;
135 int num_links_per_field[2] = {num_links, 0};
136 int * tgt_id_fixed = NULL;
137 size_t num_fixed_tgt = 0;
138 double * fixed_values = NULL;
139 int * num_tgt_per_fixed_value = NULL;
140 size_t num_fixed_values = 0;
143 file_name, src_indices, tgt_indices, weights, num_links,
144 src_locations, num_src_fields, num_links_per_field, tgt_id_fixed,
145 num_fixed_tgt, fixed_values, num_tgt_per_fixed_value,
151 size_t const num_global_cells[2] = {3,2};
152 size_t local_start[2][2] = {{0,0},{2,0}};
153 size_t local_count[2][2] = {{2,2},{1,2}};
155 int global_corner_mask[3][4] = {
156 {1,1,1,1}, {1,1,0,0}, {0,0,0,0}};
157 for (
size_t i = 0;
i <= num_global_cells[0]; ++
i)
159 for (
size_t i = 0;
i <= num_global_cells[1]; ++
i)
165 local_start[my_source_rank], local_count[my_source_rank],
with_halo);
167 int * src_corner_mask =
169 for (
size_t i = 0;
i <
grid_data.num_vertices; ++
i)
171 ((
int*)(&(global_corner_mask[0][0])))[
grid_data.vertex_ids[
i]];
185 {.location =
YAC_LOC_CELL, .coordinates_idx = SIZE_MAX, .masks_idx = SIZE_MAX}};
186 size_t num_src_fields =
sizeof(src_fields) /
sizeof(src_fields[0]);
188 {.location =
YAC_LOC_CORNER, .coordinates_idx = SIZE_MAX, .masks_idx = SIZE_MAX};
215 for (
size_t i = 0;
i <
sizeof(reorder_type) /
sizeof(reorder_type[0]);
233 src_data[collection_idx] =
xmalloc(1 *
sizeof(**src_data));
234 src_data[collection_idx][0] =
236 for (
size_t i = 0;
i <
grid_data.num_vertices; ++
i)
237 src_data[collection_idx][0][i] =
239 (
double)(collection_idx * 12);
246 free(src_data[collection_idx][0]);
247 free(src_data[collection_idx]);
270 if (my_source_rank == 0) unlink(
file_name);
293 if (my_source_rank == 0) {
295 int tgt_indices[] = { 0, 0, 0, 0,
301 int src_indices[] = { 0, 1, 4, 5,
307 double weights[] = {0.1,0.2,0.3,0.4,
313 size_t num_links = 24;
316 unsigned num_src_fields = 2;
317 int num_links_per_field[2] = {num_links, 0};
318 int * tgt_id_fixed = NULL;
319 size_t num_fixed_tgt = 0;
320 double * fixed_values = NULL;
321 int * num_tgt_per_fixed_value = NULL;
322 size_t num_fixed_values = 0;
325 file_name, src_indices, tgt_indices, weights, num_links,
326 src_locations, num_src_fields, num_links_per_field, tgt_id_fixed,
327 num_fixed_tgt, fixed_values, num_tgt_per_fixed_value,
333 size_t const num_global_cells[2] = {3,2};
334 size_t local_start[2][2] = {{0,0},{2,0}};
335 size_t local_count[2][2] = {{2,2},{1,2}};
337 for (
size_t i = 0;
i <= num_global_cells[0]; ++
i)
339 for (
size_t i = 0;
i <= num_global_cells[1]; ++
i)
345 local_start[my_source_rank], local_count[my_source_rank],
with_halo);
357 {.location =
YAC_LOC_CELL, .coordinates_idx = SIZE_MAX, .masks_idx = SIZE_MAX}};
358 size_t num_src_fields =
sizeof(src_fields) /
sizeof(src_fields[0]);
360 {.location =
YAC_LOC_CORNER, .coordinates_idx = SIZE_MAX, .masks_idx = SIZE_MAX};
387 for (
size_t i = 0;
i <
sizeof(reorder_type) /
sizeof(reorder_type[0]);
392 weights, reorder_type[i], 1,
399 double ** src_fields =
xmalloc(1 *
sizeof(*src_fields));
400 double *** src_data = &src_fields;
404 for (
size_t i = 0;
i <
grid_data.num_vertices; ++
i)
405 src_field[i] = (
double)(
grid_data.vertex_ids[
i]);
431 if (my_source_rank == 0) unlink(
file_name);
466 if (my_source_rank == 0) {
468 int tgt_indices[] = { 0, 0, 0, 0,
474 int src_indices[] = { 0, 1, 4, 5,
480 double weights[] = {0.1,0.2,0.3,0.4,
486 size_t num_links = 24;
489 unsigned num_src_fields = 2;
490 int num_links_per_field[2] = {num_links, 0};
491 int * tgt_id_fixed = NULL;
492 size_t num_fixed_tgt = 0;
493 double * fixed_values = NULL;
494 int * num_tgt_per_fixed_value = NULL;
495 size_t num_fixed_values = 0;
498 file_name, src_indices, tgt_indices, weights, num_links,
499 src_locations, num_src_fields, num_links_per_field, tgt_id_fixed,
500 num_fixed_tgt, fixed_values, num_tgt_per_fixed_value,
506 size_t const num_global_cells[2] = {3,2};
507 size_t local_start[2][2] = {{0,0},{2,0}};
508 size_t local_count[2][2] = {{2,2},{1,2}};
509 int global_src_vertex_mask[] = {1, 1, 1, 0,
512 int global_src_cell_mask[] = {1, 1, 0,
515 for (
size_t i = 0;
i <= num_global_cells[0]; ++
i)
517 for (
size_t i = 0;
i <= num_global_cells[1]; ++
i)
523 local_start[my_source_rank], local_count[my_source_rank],
with_halo);
525 int * src_vertex_mask =
xmalloc(12 *
sizeof(*src_vertex_mask));
526 int * src_cell_mask =
xmalloc(6 *
sizeof(*src_cell_mask));;
527 for (
size_t i = 0;
i <
grid_data.num_vertices; ++
i)
529 global_src_vertex_mask[
grid_data.vertex_ids[i]];
532 global_src_cell_mask[
grid_data.cell_ids[i]];
545 {{.location =
YAC_LOC_CORNER, .coordinates_idx = SIZE_MAX, .masks_idx = 0},
546 {.location =
YAC_LOC_CELL, .coordinates_idx = SIZE_MAX, .masks_idx = 0}};
547 size_t num_src_fields =
sizeof(src_fields) /
sizeof(src_fields[0]);
549 {.location =
YAC_LOC_CORNER, .coordinates_idx = SIZE_MAX, .masks_idx = SIZE_MAX};
576 for (
size_t i = 0;
i <
sizeof(reorder_type) /
sizeof(reorder_type[0]);
581 weights, reorder_type[i], 1,
588 double ** src_fields =
xmalloc(1 *
sizeof(*src_fields));
589 double *** src_data = &src_fields;
593 for (
size_t i = 0;
i <
grid_data.num_vertices; ++
i)
594 src_field[i] = (
double)(
grid_data.vertex_ids[
i]);
620 if (my_source_rank == 0) unlink(
file_name);
644 if (my_source_rank == 0) {
646 int * tgt_indices = NULL;
647 int * src_indices = NULL;
649 size_t num_links = 0;
652 unsigned num_src_fields = 2;
653 int num_links_per_field[2] = {num_links, 0};
654 int * tgt_id_fixed = NULL;
655 size_t num_fixed_tgt = 0;
656 double * fixed_values = NULL;
657 int * num_tgt_per_fixed_value = NULL;
658 size_t num_fixed_values = 0;
661 file_name, src_indices, tgt_indices, weights, num_links,
662 src_locations, num_src_fields, num_links_per_field, tgt_id_fixed,
663 num_fixed_tgt, fixed_values, num_tgt_per_fixed_value,
669 size_t const num_global_cells[2] = {3,2};
670 size_t local_start[2][2] = {{0,0},{2,0}};
671 size_t local_count[2][2] = {{2,2},{1,2}};
673 for (
size_t i = 0;
i <= num_global_cells[0]; ++
i)
675 for (
size_t i = 0;
i <= num_global_cells[1]; ++
i)
681 local_start[my_source_rank], local_count[my_source_rank],
with_halo);
692 {{.location =
YAC_LOC_CORNER, .coordinates_idx = SIZE_MAX, .masks_idx = SIZE_MAX},
693 {.location =
YAC_LOC_CELL, .coordinates_idx = SIZE_MAX, .masks_idx = SIZE_MAX}};
694 size_t num_src_fields =
sizeof(src_fields) /
sizeof(src_fields[0]);
696 {.location =
YAC_LOC_CORNER, .coordinates_idx = SIZE_MAX, .masks_idx = SIZE_MAX};
723 for (
size_t i = 0;
i <
sizeof(reorder_type) /
sizeof(reorder_type[0]);
728 weights, reorder_type[i], 1,
735 double ** src_fields =
xmalloc(1 *
sizeof(*src_fields));
736 double *** src_data = &src_fields;
740 for (
size_t i = 0;
i <
grid_data.num_vertices; ++
i)
741 src_field[i] = (
double)(
grid_data.vertex_ids[
i]);
767 if (my_source_rank == 0) unlink(
file_name);
789 if (my_source_rank == 0) {
791 int * tgt_indices = NULL;
792 int * src_indices = NULL;
794 size_t num_links = 0;
797 unsigned num_src_fields = 2;
798 int num_links_per_field[2] = {num_links, 0};
799 int tgt_id_fixed[] = {0, 2, 4, 6};
800 size_t num_fixed_tgt = 4;
801 double fixed_values[] = {-1.0, -2.0};
802 int num_tgt_per_fixed_value[] = {1, 3};
803 size_t num_fixed_values = 2;
806 file_name, src_indices, tgt_indices, weights, num_links,
807 src_locations, num_src_fields, num_links_per_field, tgt_id_fixed,
808 num_fixed_tgt, fixed_values, num_tgt_per_fixed_value,
814 size_t const num_global_cells[2] = {3,2};
815 size_t local_start[2][2] = {{0,0},{2,0}};
816 size_t local_count[2][2] = {{2,2},{1,2}};
818 for (
size_t i = 0;
i <= num_global_cells[0]; ++
i)
820 for (
size_t i = 0;
i <= num_global_cells[1]; ++
i)
826 local_start[my_source_rank], local_count[my_source_rank],
with_halo);
837 {{.location =
YAC_LOC_CORNER, .coordinates_idx = SIZE_MAX, .masks_idx = SIZE_MAX},
838 {.location =
YAC_LOC_CELL, .coordinates_idx = SIZE_MAX, .masks_idx = SIZE_MAX}};
839 size_t num_src_fields =
sizeof(src_fields) /
sizeof(src_fields[0]);
841 {.location =
YAC_LOC_CORNER, .coordinates_idx = SIZE_MAX, .masks_idx = SIZE_MAX};
868 for (
size_t i = 0;
i <
sizeof(reorder_type) /
sizeof(reorder_type[0]);
873 weights, reorder_type[i], 1,
880 double ** src_fields =
xmalloc(1 *
sizeof(*src_fields));
881 double *** src_data = &src_fields;
885 for (
size_t i = 0;
i <
grid_data.num_vertices; ++
i)
886 src_field[i] = (
double)(
grid_data.vertex_ids[
i]);
912 if (my_source_rank == 0) unlink(
file_name);
934 if (my_source_rank == 0) {
936 int * tgt_indices = NULL;
937 int * src_indices = NULL;
939 size_t num_links = 0;
942 unsigned num_src_fields = 1;
943 int num_links_per_field[1] = {num_links};
944 int tgt_id_fixed[] = {1,3,5,7,9,11,0,2,4,6,8,10};
945 size_t num_fixed_tgt = 12;
946 double fixed_values[] = {-1.0, -2.0};
947 int num_tgt_per_fixed_value[] = {6, 6};
948 size_t num_fixed_values = 2;
951 file_name, src_indices, tgt_indices, weights, num_links,
952 src_locations, num_src_fields, num_links_per_field, tgt_id_fixed,
953 num_fixed_tgt, fixed_values, num_tgt_per_fixed_value,
959 size_t const num_global_cells[2] = {3,2};
960 size_t local_start[2][2] = {{0,0},{2,0}};
961 size_t local_count[2][2] = {{2,2},{1,2}};
963 for (
size_t i = 0;
i <= num_global_cells[0]; ++
i)
965 for (
size_t i = 0;
i <= num_global_cells[1]; ++
i)
971 local_start[my_source_rank], local_count[my_source_rank],
with_halo);
982 {{.location =
YAC_LOC_CORNER, .coordinates_idx = SIZE_MAX, .masks_idx = SIZE_MAX}};
983 size_t num_src_fields =
sizeof(src_fields) /
sizeof(src_fields[0]);
985 {.location =
YAC_LOC_EDGE, .coordinates_idx = SIZE_MAX, .masks_idx = SIZE_MAX};
1012 for (
size_t i = 0;
i <
sizeof(reorder_type) /
sizeof(reorder_type[0]);
1017 weights, reorder_type[i], 1,
1024 double ** src_fields =
xmalloc(1 *
sizeof(*src_fields));
1025 double *** src_data = &src_fields;
1029 for (
size_t i = 0;
i <
grid_data.num_vertices; ++
i)
1030 src_field[i] = (
double)(
grid_data.vertex_ids[
i]);
1035 free(src_fields[0]);
1056 if (my_source_rank == 0) unlink(
file_name);
1077 if (my_source_rank == 0) {
1079 int * tgt_indices = NULL;
1080 int * src_indices = NULL;
1082 size_t num_links = 0;
1085 unsigned num_src_fields = 1;
1086 int num_links_per_field[1] = {num_links};
1087 int tgt_id_fixed[] = {1,3,5,7,9,11,0,2,4,6,8,10};
1088 size_t num_fixed_tgt = 12;
1089 double fixed_values[] = {-1.0, NAN};
1090 int num_tgt_per_fixed_value[] = {6, 6};
1091 size_t num_fixed_values = 2;
1094 file_name, src_indices, tgt_indices, weights, num_links,
1095 src_locations, num_src_fields, num_links_per_field, tgt_id_fixed,
1096 num_fixed_tgt, fixed_values, num_tgt_per_fixed_value,
1102 size_t const num_global_cells[2] = {3,2};
1103 size_t local_start[2][2] = {{0,0},{2,0}};
1104 size_t local_count[2][2] = {{2,2},{1,2}};
1106 for (
size_t i = 0;
i <= num_global_cells[0]; ++
i)
1108 for (
size_t i = 0;
i <= num_global_cells[1]; ++
i)
1114 local_start[my_source_rank], local_count[my_source_rank],
with_halo);
1125 {{.location =
YAC_LOC_CORNER, .coordinates_idx = SIZE_MAX, .masks_idx = SIZE_MAX}};
1126 size_t num_src_fields =
sizeof(src_fields) /
sizeof(src_fields[0]);
1128 {.location =
YAC_LOC_EDGE, .coordinates_idx = SIZE_MAX, .masks_idx = SIZE_MAX};
1171 for (
int from_file = 0; from_file <= 1; ++from_file) {
1172 for (
size_t i = 0;
i <
sizeof(reorder_type) /
sizeof(reorder_type[0]);
1177 (from_file)?weights_from_file:
weights,
1185 double ** src_fields =
xmalloc(1 *
sizeof(*src_fields));
1186 double *** src_data = &src_fields;
1190 for (
size_t i = 0;
i <
grid_data.num_vertices; ++
i)
1191 src_field[i] = (
double)(
grid_data.vertex_ids[
i]);
1196 free(src_fields[0]);
1218 if (my_source_rank == 0) unlink(
file_name);
1248 if (my_source_rank == 0) {
1250 int src_indices[3][36] = {{0,1,2,3,
1251 0,1,3,4, 1,2,4,5, 3,4,6,7, 4,5,7,8,
1252 0,1,3,5, 2,3,4,7, 5,6,8,10, 7,8,9,11},
1254 0,1,3,4, 1,2,4,5, 3,4,6,7, 4,5,7,8,
1255 0,1,3,5, 2,3,4,7, 5,6,8,10, 7,8,9,11},
1259 int tgt_indices[3][36] = {{0,1,2,3,
1260 0,0,0,0, 1,1,1,1, 2,2,2,2, 3,3,3,3,
1261 0,0,0,0, 1,1,1,1, 2,2,2,2, 3,3,3,3},
1263 0,0,0,0, 1,1,1,1, 2,2,2,2, 3,3,3,3,
1264 0,0,0,0, 1,1,1,1, 2,2,2,2, 3,3,3,3},
1268 double weights[3][36] = {{1,1,1,1,
1269 0.25,0.25,0.25,0.25, 0.25,0.25,0.25,0.25,
1270 0.25,0.25,0.25,0.25, 0.25,0.25,0.25,0.25,
1271 0.25,0.25,0.25,0.25, 0.25,0.25,0.25,0.25,
1272 0.25,0.25,0.25,0.25, 0.25,0.25,0.25,0.25},
1279 size_t num_links[3] = {1*4 + 4*4 + 4*4,
1285 unsigned num_src_fields = 3;
1286 int num_links_per_field[3][3] = {{1*4, 4*4, 4*4},
1289 int * tgt_id_fixed = NULL;
1290 size_t num_fixed_tgt = 0;
1291 double * fixed_values = NULL;
1292 int * num_tgt_per_fixed_value = NULL;
1293 size_t num_fixed_values = 0;
1298 num_src_fields, num_links_per_field[
weight_type], tgt_id_fixed,
1299 num_fixed_tgt, fixed_values, num_tgt_per_fixed_value,
1305 size_t const num_global_cells[2] = {2,2};
1306 size_t local_start[2][2] = {{0,0},{1,0}};
1307 size_t local_count[2][2] = {{1,2},{1,2}};
1309 for (
size_t i = 0;
i <= num_global_cells[0]; ++
i)
1311 for (
size_t i = 0;
i <= num_global_cells[1]; ++
i)
1317 local_start[my_source_rank], local_count[my_source_rank],
with_halo);
1328 {{.location =
YAC_LOC_CELL, .coordinates_idx = SIZE_MAX, .masks_idx = SIZE_MAX},
1329 {.location =
YAC_LOC_CORNER, .coordinates_idx = SIZE_MAX, .masks_idx = SIZE_MAX},
1330 {.location =
YAC_LOC_EDGE, .coordinates_idx = SIZE_MAX, .masks_idx = SIZE_MAX}};
1331 size_t num_src_fields =
sizeof(src_fields) /
sizeof(src_fields[0]);
1333 {.location =
YAC_LOC_CORNER, .coordinates_idx = SIZE_MAX, .masks_idx = SIZE_MAX};
1373 for (
int from_file = 0; from_file <= 1; ++from_file) {
1375 for (
size_t i = 0;
i <
sizeof(reorder_type) /
sizeof(reorder_type[0]);
1383 (from_file)?weights_from_file:
weights,
1396 double ** src_fields =
xmalloc(3 *
sizeof(*src_fields));
1397 src_data[collection_idx] = src_fields;
1404 (
double)(
grid_data.cell_ids[
i] + 10 * collection_idx) + 0.0;
1410 for (
size_t i = 0;
i <
grid_data.num_vertices; ++
i)
1412 (
double)(
grid_data.vertex_ids[
i] + 10 * collection_idx) + 0.3;
1420 (
double)(
grid_data.edge_ids[
i] + 10 * collection_idx) + 0.7;
1429 for (
size_t i = 0;
i < 3; ++
i) free(src_data[collection_idx][i]);
1430 free(src_data[collection_idx]);
1455 if (my_source_rank == 0) {
1490 if (my_source_rank == 0) {
1492 int src_indices[16] = {0,1,4,8,13,14,
1495 int tgt_indices[16] = {0,1,4,8,13,14,
1498 double weights[16] = {1,1,1,1,1,1,
1501 size_t num_links = 16;
1505 unsigned num_src_fields = 3;
1506 int num_links_per_field[3] = {6, 5, 5};
1507 int * tgt_id_fixed = NULL;
1508 size_t num_fixed_tgt = 0;
1509 double * fixed_values = NULL;
1510 int * num_tgt_per_fixed_value = NULL;
1511 size_t num_fixed_values = 0;
1514 file_name, src_indices, tgt_indices, weights, num_links,
1515 src_locations, num_src_fields, num_links_per_field, tgt_id_fixed,
1516 num_fixed_tgt, fixed_values, num_tgt_per_fixed_value,
1522 size_t const num_global_cells[2] = {4,4};
1523 size_t local_start[2][2] = {{0,0},{2,0}};
1524 size_t local_count[2][2] = {{2,4},{2,4}};
1526 for (
size_t i = 0;
i <= num_global_cells[0]; ++
i)
1528 for (
size_t i = 0;
i <= num_global_cells[1]; ++
i)
1534 local_start[my_source_rank], local_count[my_source_rank],
with_halo);
1545 {{.location =
YAC_LOC_CELL, .coordinates_idx = SIZE_MAX, .masks_idx = SIZE_MAX},
1546 {.location =
YAC_LOC_CORNER, .coordinates_idx = SIZE_MAX, .masks_idx = SIZE_MAX},
1547 {.location =
YAC_LOC_EDGE, .coordinates_idx = SIZE_MAX, .masks_idx = SIZE_MAX}};
1548 size_t num_src_fields =
sizeof(src_fields) /
sizeof(src_fields[0]);
1550 {.location =
YAC_LOC_CELL, .coordinates_idx = SIZE_MAX, .masks_idx = SIZE_MAX};
1590 for (
int from_file = 0; from_file <= 1; ++from_file) {
1592 for (
size_t i = 0;
i <
sizeof(reorder_type) /
sizeof(reorder_type[0]);
1600 (from_file)?weights_from_file:
weights,
1613 double ** src_fields =
xmalloc(3 *
sizeof(*src_fields));
1614 src_data[collection_idx] = src_fields;
1621 (
double)(
grid_data.cell_ids[
i] + 10 * collection_idx) + 0.0;
1627 for (
size_t i = 0;
i <
grid_data.num_vertices; ++
i)
1629 (
double)(
grid_data.vertex_ids[
i] + 10 * collection_idx) + 0.3;
1637 (
double)(
grid_data.edge_ids[
i] + 10 * collection_idx) + 0.7;
1646 for (
size_t i = 0;
i < 3; ++
i) free(src_data[collection_idx][i]);
1647 free(src_data[collection_idx]);
1672 if (my_source_rank == 0) {
1685 if (my_source_rank == 0) {
1688 int * tgt_indices = NULL;
1689 int * src_indices = NULL;
1691 size_t num_links = 0;
1695 NUM_SRC_FIELDS =
sizeof(src_locations) /
sizeof(src_locations[0])};
1697 int * tgt_id_fixed = NULL;
1698 size_t num_fixed_tgt = 0;
1699 double * fixed_values = NULL;
1700 int * num_tgt_per_fixed_value = NULL;
1701 size_t num_fixed_values = 0;
1704 file_name, src_indices, tgt_indices, weights, num_links,
1705 src_locations,
NUM_SRC_FIELDS, num_links_per_field, tgt_id_fixed,
1706 num_fixed_tgt, fixed_values, num_tgt_per_fixed_value,
1711 int * tgt_indices = NULL;
1712 int * src_indices = NULL;
1714 size_t num_links = 0;
1718 NUM_SRC_FIELDS =
sizeof(src_locations) /
sizeof(src_locations[0])};
1720 int tgt_id_fixed[] = {0, 1, 2, 3};
1721 size_t num_fixed_tgt = 4;
1722 double fixed_values[] = {999.0};
1723 int num_tgt_per_fixed_value[] = {4};
1724 size_t num_fixed_values = 1;
1727 file_name_2, src_indices, tgt_indices, weights, num_links,
1728 src_locations,
NUM_SRC_FIELDS, num_links_per_field, tgt_id_fixed,
1729 num_fixed_tgt, fixed_values, num_tgt_per_fixed_value,
1736 size_t num_vertices[2] = {3,3};
1748 {{.location =
YAC_LOC_CELL, .coordinates_idx = SIZE_MAX, .masks_idx = SIZE_MAX}};
1749 enum {
NUM_SRC_FIELDS =
sizeof(src_fields) /
sizeof(src_fields[0])};
1751 {.location =
YAC_LOC_CELL, .coordinates_idx = SIZE_MAX, .masks_idx = SIZE_MAX};
1795 double src_data_raw[NUM_CELLS] = {0.0, 0.0, 0.0, 0.0};
1819 if (my_source_rank == 0) {
1826static void utest_source_main_abort(MPI_Comm source_comm) {
1829 MPI_Comm_rank(source_comm, &my_source_rank);
1839 size_t num_vertices[2] = {3,3};
1852 enum {
NUM_SRC_FIELDS =
sizeof(src_fields) /
sizeof(src_fields[0])};
1854 {.location =
YAC_LOC_CELL, .coordinates_idx = SIZE_MAX, .masks_idx = SIZE_MAX};
1863 for (
int on_missing_file_idx = 0;
1875 "missing_file.nc", curr_on_missing_file,
1886 int abort_handler_was_called = 0;
1888 MPI_IN_PLACE, &abort_handler_was_called, 1,
1889 MPI_INT, MPI_MAX, MPI_COMM_WORLD);
1894 "ERROR unsupported value for on_missing_file");
1896 switch(curr_on_missing_file) {
1899 if (abort_handler_was_called)
1900 PUT_ERR(
"error in handling of YAC_INTERP_FILE_MISSING_CONT");
1903 if (!abort_handler_was_called)
1904 PUT_ERR(
"error in handling of YAC_INTERP_FILE_MISSING_ERROR");
1908 if (abort_handler_was_called) {
1937 PUT_ERR(
"test internal error");
1940static void utest_target_main(MPI_Comm target_comm) {
1943 MPI_Comm_rank(target_comm, &my_target_rank);
1967 size_t const num_global_cells[2] = {2,2};
1968 size_t local_start[2] = {0,0};
1969 size_t local_count[2] = {2,2};
1971 for (
size_t i = 0;
i <= num_global_cells[0]; ++
i)
1973 for (
size_t i = 0;
i <= num_global_cells[1]; ++
i)
1991 {.location =
YAC_LOC_CELL, .coordinates_idx = SIZE_MAX, .masks_idx = SIZE_MAX}};
1992 size_t num_src_fields =
sizeof(src_fields) /
sizeof(src_fields[0]);
1994 {.location =
YAC_LOC_CORNER, .coordinates_idx = SIZE_MAX, .masks_idx = SIZE_MAX};
2021 for (
size_t i = 0;
i <
sizeof(reorder_type) /
sizeof(reorder_type[0]);
2038 tgt_data[collection_idx] =
2040 for (
size_t i = 0;
i <
grid_data.num_vertices; ++
i)
2041 tgt_data[collection_idx][i] = -1;
2048 for (
size_t i = 0;
i <
grid_data.num_vertices; ++
i)
2050 if (tgt_data[collection_idx][i] != -1.0)
2051 PUT_ERR(
"wrong interpolation result");
2052 }
else if (fabs((
double)(i * (i + 12 * collection_idx)) -
2053 tgt_data[collection_idx][i]) > 1e-9) {
2054 PUT_ERR(
"wrong interpolation result");
2059 free(tgt_data[collection_idx]);
2102 size_t const num_global_cells[2] = {2,2};
2103 size_t local_start[2] = {0,0};
2104 size_t local_count[2] = {2,2};
2106 for (
size_t i = 0;
i <= num_global_cells[0]; ++
i)
2108 for (
size_t i = 0;
i <= num_global_cells[1]; ++
i)
2126 {.location =
YAC_LOC_CELL, .coordinates_idx = SIZE_MAX, .masks_idx = SIZE_MAX}};
2127 size_t num_src_fields =
sizeof(src_fields) /
sizeof(src_fields[0]);
2129 {.location =
YAC_LOC_CORNER, .coordinates_idx = SIZE_MAX, .masks_idx = SIZE_MAX};
2156 for (
size_t i = 0;
i <
sizeof(reorder_type) /
sizeof(reorder_type[0]);
2161 weights, reorder_type[i], 1,
2168 double ** tgt_data =
xmalloc(1 *
sizeof(*tgt_data));
2171 for (
size_t i = 0;
i <
grid_data.num_vertices; ++
i)
2172 tgt_data[0][i] = -1;
2174 double ref_tgt_field[9] =
2175 {0.1*0+0.2*1+0.3*4+0.4*5,
2176 0.5*1+0.6*2+0.7*5+0.8*6,
2177 0.9*2+1.0*3+1.1*6+1.2*7,
2178 1.3*4+1.4*5+1.5*8+1.6*9,
2179 1.7*5+1.8*6+1.9*9+2.0*10,
2180 2.1*6+2.2*7+2.3*10+2.4*11,
2185 for (
size_t i = 0;
i <
grid_data.num_vertices; ++
i)
2187 if (tgt_data[0][i] != -1.0)
2188 PUT_ERR(
"wrong interpolation result");
2189 }
else if (fabs(ref_tgt_field[i] - tgt_data[0][i]) > 1e-9) {
2190 PUT_ERR(
"wrong interpolation result");
2235 size_t const num_global_cells[2] = {2,2};
2236 size_t local_start[2] = {0,0};
2237 size_t local_count[2] = {2,2};
2239 for (
size_t i = 0;
i <= num_global_cells[0]; ++
i)
2241 for (
size_t i = 0;
i <= num_global_cells[1]; ++
i)
2259 {.location =
YAC_LOC_CELL, .coordinates_idx = SIZE_MAX, .masks_idx = 0}};
2260 size_t num_src_fields =
sizeof(src_fields) /
sizeof(src_fields[0]);
2262 {.location =
YAC_LOC_CORNER, .coordinates_idx = SIZE_MAX, .masks_idx = SIZE_MAX};
2289 for (
size_t i = 0;
i <
sizeof(reorder_type) /
sizeof(reorder_type[0]);
2294 weights, reorder_type[i], 1,
2301 double ** tgt_data =
xmalloc(1 *
sizeof(*tgt_data));
2304 for (
size_t i = 0;
i <
grid_data.num_vertices; ++
i)
2305 tgt_data[0][i] = -1;
2307 double ref_tgt_field[9] =
2308 {0.1*0+0.2*1+0.3*4+0.4*5,
2309 0.5*1+0.6*2+0.7*5+0.8*6,
2312 1.7*5+1.8*6+1.9*9+2.0*10,
2313 2.1*6+2.2*7+2.3*10+2.4*11,
2318 for (
size_t i = 0;
i <
grid_data.num_vertices; ++
i)
2320 if (tgt_data[0][i] != -1.0)
2321 PUT_ERR(
"wrong interpolation result");
2322 }
else if (fabs(ref_tgt_field[i] - tgt_data[0][i]) > 1e-9) {
2323 PUT_ERR(
"wrong interpolation result");
2367 size_t const num_global_cells[2] = {2,2};
2368 size_t local_start[2] = {0,0};
2369 size_t local_count[2] = {2,2};
2371 for (
size_t i = 0;
i <= num_global_cells[0]; ++
i)
2373 for (
size_t i = 0;
i <= num_global_cells[1]; ++
i)
2391 {.location =
YAC_LOC_CELL, .coordinates_idx = SIZE_MAX, .masks_idx = SIZE_MAX}};
2392 size_t num_src_fields =
sizeof(src_fields) /
sizeof(src_fields[0]);
2394 {.location =
YAC_LOC_CORNER, .coordinates_idx = SIZE_MAX, .masks_idx = SIZE_MAX};
2421 for (
size_t i = 0;
i <
sizeof(reorder_type) /
sizeof(reorder_type[0]);
2426 weights, reorder_type[i], 1,
2433 double ** tgt_data =
xmalloc(1 *
sizeof(*tgt_data));
2436 for (
size_t i = 0;
i <
grid_data.num_vertices; ++
i)
2437 tgt_data[0][i] = -1;
2441 for (
size_t i = 0;
i <
grid_data.num_vertices; ++
i)
2442 if (tgt_data[0][i] != -1.0)
2443 PUT_ERR(
"wrong interpolation result");
2486 size_t const num_global_cells[2] = {2,2};
2487 size_t local_start[2] = {0,0};
2488 size_t local_count[2] = {2,2};
2490 for (
size_t i = 0;
i <= num_global_cells[0]; ++
i)
2492 for (
size_t i = 0;
i <= num_global_cells[1]; ++
i)
2510 {.location =
YAC_LOC_CELL, .coordinates_idx = SIZE_MAX, .masks_idx = SIZE_MAX}};
2511 size_t num_src_fields =
sizeof(src_fields) /
sizeof(src_fields[0]);
2513 {.location =
YAC_LOC_CORNER, .coordinates_idx = SIZE_MAX, .masks_idx = SIZE_MAX};
2540 for (
size_t i = 0;
i <
sizeof(reorder_type) /
sizeof(reorder_type[0]);
2545 weights, reorder_type[i], 1,
2552 double ** tgt_data =
xmalloc(1 *
sizeof(*tgt_data));
2555 for (
size_t i = 0;
i <
grid_data.num_vertices; ++
i) tgt_data[0][i] = -3;
2557 double ref_tgt_field[9] =
2558 {-1,-3,-2, -3,-2,-3, -2,-3,-3};
2562 for (
size_t i = 0;
i <
grid_data.num_vertices; ++
i)
2563 if (ref_tgt_field[i] != tgt_data[0][i])
2564 PUT_ERR(
"wrong interpolation result");
2607 size_t const num_global_cells[2] = {2,2};
2608 size_t local_start[2] = {0,0};
2609 size_t local_count[2] = {2,2};
2611 for (
size_t i = 0;
i <= num_global_cells[0]; ++
i)
2613 for (
size_t i = 0;
i <= num_global_cells[1]; ++
i)
2631 size_t num_src_fields =
sizeof(src_fields) /
sizeof(src_fields[0]);
2633 {.location =
YAC_LOC_EDGE, .coordinates_idx = SIZE_MAX, .masks_idx = SIZE_MAX};
2660 for (
size_t i = 0;
i <
sizeof(reorder_type) /
sizeof(reorder_type[0]);
2665 weights, reorder_type[i], 1,
2672 double ** tgt_data =
xmalloc(1 *
sizeof(*tgt_data));
2674 for (
size_t i = 0;
i <
grid_data.num_edges; ++
i) tgt_data[0][i] = -3;
2676 double ref_tgt_field[12] = {-2,-1,-2,-1,-2,-1,-2,-1,-2,-1,-2,-1};
2681 if (ref_tgt_field[i] != tgt_data[0][i])
2682 PUT_ERR(
"wrong interpolation result");
2724 size_t const num_global_cells[2] = {2,2};
2725 size_t local_start[2] = {0,0};
2726 size_t local_count[2] = {2,2};
2728 for (
size_t i = 0;
i <= num_global_cells[0]; ++
i)
2730 for (
size_t i = 0;
i <= num_global_cells[1]; ++
i)
2748 size_t num_src_fields =
sizeof(src_fields) /
sizeof(src_fields[0]);
2750 {.location =
YAC_LOC_EDGE, .coordinates_idx = SIZE_MAX, .masks_idx = SIZE_MAX};
2791 for (
int from_file = 0; from_file <= 1; ++from_file) {
2792 for (
size_t i = 0;
i <
sizeof(reorder_type) /
sizeof(reorder_type[0]);
2797 (from_file)?weights_from_file:
weights,
2805 double ** tgt_data =
xmalloc(1 *
sizeof(*tgt_data));
2807 for (
size_t i = 0;
i <
grid_data.num_edges; ++
i) tgt_data[0][i] = -3;
2809 double ref_tgt_field[12] = {NAN,-1,NAN,-1,NAN,-1,NAN,-1,NAN,-1,NAN,-1};
2815 if (memcmp(&ref_tgt_field[i], &tgt_data[0][i],
sizeof(tgt_data[0][i])))
2816 PUT_ERR(
"wrong interpolation result");
2864 size_t const num_global_cells[2] = {1,1};
2865 size_t local_start[2] = {0,0};
2866 size_t local_count[2] = {1,1};
2868 for (
size_t i = 0;
i <= num_global_cells[0]; ++
i)
2870 for (
size_t i = 0;
i <= num_global_cells[1]; ++
i)
2888 {.location =
YAC_LOC_CORNER, .coordinates_idx = SIZE_MAX, .masks_idx = SIZE_MAX},
2889 {.location =
YAC_LOC_EDGE, .coordinates_idx = SIZE_MAX, .masks_idx = SIZE_MAX}};
2890 size_t num_src_fields =
sizeof(src_fields) /
sizeof(src_fields[0]);
2892 {.location =
YAC_LOC_CORNER, .coordinates_idx = SIZE_MAX, .masks_idx = SIZE_MAX};
2931 for (
int from_file = 0; from_file <= 1; ++from_file) {
2933 for (
size_t i = 0;
i <
sizeof(reorder_type) /
sizeof(reorder_type[0]);
2941 (from_file)?weights_from_file:
weights,
2952 tgt_data[collection_idx] =
2954 for (
size_t i = 0;
i <
grid_data.num_vertices; ++
i)
2955 tgt_data[collection_idx][i] = -3;
2958 double ref_tgt_field[3][4] =
2959 {{0.0 + 0.25 * (0.3+1.3+3.3+4.3) + 0.25 * (0.7+1.7+3.7+ 5.7),
2960 1.0 + 0.25 * (1.3+2.3+4.3+5.3) + 0.25 * (2.7+3.7+4.7+ 7.7),
2961 2.0 + 0.25 * (3.3+4.3+6.3+7.3) + 0.25 * (5.7+6.7+8.7+10.7),
2962 3.0 + 0.25 * (4.3+5.3+7.3+8.3) + 0.25 * (7.7+8.7+9.7+11.7)},
2963 {0.0 + (0.3+1.3+3.3+4.3) + (0.7+1.7+3.7+ 5.7),
2964 1.0 + (1.3+2.3+4.3+5.3) + (2.7+3.7+4.7+ 7.7),
2965 2.0 + (3.3+4.3+6.3+7.3) + (5.7+6.7+8.7+10.7),
2966 3.0 + (4.3+5.3+7.3+8.3) + (7.7+8.7+9.7+11.7)},
2967 {4.3, 1.0, 2.0, 11.7}};
2968 double collection_factor[3] = {30.0, 90.0, 10.0};
2974 for (
size_t i = 0;
i <
grid_data.num_vertices; ++
i)
2977 (
double)collection_idx) -
2978 tgt_data[collection_idx][i]) > 1e-9)
2979 PUT_ERR(
"wrong interpolation result");
2982 ++collection_idx) free(tgt_data[collection_idx]);
3042 size_t const num_global_cells[2] = {4,4};
3043 size_t local_start[2] = {0,0};
3044 size_t local_count[2] = {4,4};
3046 for (
size_t i = 0;
i <= num_global_cells[0]; ++
i)
3048 for (
size_t i = 0;
i <= num_global_cells[1]; ++
i)
3066 {.location =
YAC_LOC_CORNER, .coordinates_idx = SIZE_MAX, .masks_idx = SIZE_MAX},
3067 {.location =
YAC_LOC_EDGE, .coordinates_idx = SIZE_MAX, .masks_idx = SIZE_MAX}};
3068 size_t num_src_fields =
sizeof(src_fields) /
sizeof(src_fields[0]);
3070 {.location =
YAC_LOC_CELL, .coordinates_idx = SIZE_MAX, .masks_idx = SIZE_MAX};
3109 for (
int from_file = 0; from_file <= 1; ++from_file) {
3111 for (
size_t i = 0;
i <
sizeof(reorder_type) /
sizeof(reorder_type[0]);
3119 (from_file)?weights_from_file:
weights,
3130 tgt_data[collection_idx] =
3133 tgt_data[collection_idx][i] = -3;
3136 double ref_tgt_field[16] =
3137 { 0.0, 1.0, 8.3, 8.7,
3138 4.0, 12.3, 13.3, 17.7,
3139 8.0, 17.3, 25.7, 26.7,
3140 30.7, 13.0, 14.0, 24.3};
3147 if (fabs((ref_tgt_field[i] + 10.0 * (
double)collection_idx) -
3148 tgt_data[collection_idx][i]) > 1e-9)
3149 PUT_ERR(
"wrong interpolation result");
3152 ++collection_idx) free(tgt_data[collection_idx]);
3184 size_t num_vertices[2] = {3,3};
3197 size_t num_src_fields =
sizeof(src_fields) /
sizeof(src_fields[0]);
3199 {.location =
YAC_LOC_CELL, .coordinates_idx = SIZE_MAX, .masks_idx = SIZE_MAX};
3243 double tgt_data_raw[NUM_CELLS];
3244 double * tgt_data[] = {&(tgt_data_raw[0])};
3245 for (
size_t i = 0;
i < NUM_CELLS; ++
i) tgt_data_raw[i] = -1.0;
3251 for (
size_t i = 0;
i < NUM_CELLS; ++
i)
3252 if (tgt_data_raw[i] != ref_tgt_field_value[on_success_idx])
3253 PUT_ERR(
"wrong interpolation result");
3271static void utest_target_main_abort(MPI_Comm target_comm) {
3274 MPI_Comm_rank(target_comm, &my_target_rank);
3284 size_t num_vertices[2] = {3,3};
3297 size_t num_src_fields =
sizeof(src_fields) /
sizeof(src_fields[0]);
3299 {.location =
YAC_LOC_CELL, .coordinates_idx = SIZE_MAX, .masks_idx = SIZE_MAX};
3308 for (
int on_missing_file_idx = 0;
3320 "missing_file.nc", curr_on_missing_file,
3331 int abort_handler_was_called = 0;
3333 MPI_IN_PLACE, &abort_handler_was_called, 1,
3334 MPI_INT, MPI_MAX, MPI_COMM_WORLD);
3339 "ERROR unsupported value for on_missing_file");
3341 switch(curr_on_missing_file) {
3344 if (abort_handler_was_called)
3345 PUT_ERR(
"error in handling of YAC_INTERP_FILE_MISSING_CONT");
3348 if (!abort_handler_was_called)
3349 PUT_ERR(
"error in handling of YAC_INTERP_FILE_MISSING_ERROR");
3353 if (abort_handler_was_called) {
3377 PUT_ERR(
"test internal error");
3382 MPI_Comm
comm,
char const * msg,
char const * source,
int line) {
3389 int interpolation_complete = 0;
3392 MPI_IN_PLACE, &interpolation_complete, 1, MPI_INT, MPI_MAX,
comm),
comm);
3394 int abort_handler_was_called = 1;
3396 MPI_IN_PLACE, &abort_handler_was_called, 1,
3397 MPI_INT, MPI_MAX, MPI_COMM_WORLD);
#define YAC_ASSERT(exp, msg)
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)
struct yac_basic_grid * yac_basic_grid_empty_new(char const *name)
void yac_basic_grid_delete(struct yac_basic_grid *grid)
size_t yac_basic_grid_add_mask_nocpy(struct yac_basic_grid *grid, enum yac_location location, int const *mask, char const *mask_name)
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)
MPI_Comm yac_interp_grid_get_MPI_Comm(struct yac_interp_grid *interp_grid)
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_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_on_missing_file
@ YAC_INTERP_FILE_MISSING_CONT
continue on missing file
@ YAC_INTERP_FILE_MISSING_ERROR
abort on missing file
yac_interp_file_on_success
@ YAC_INTERP_FILE_SUCCESS_CONT
@ YAC_INTERP_FILE_SUCCESS_STOP
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[]
enum yac_interp_file_on_success on_success_types[]
char const src_grid_name[]
char const tgt_grid_name[]
static MPI_Comm split_comm
enum yac_interp_file_on_missing_file on_missing_file_types[]
static void on_missing_abort_handler(MPI_Comm comm, char const *msg, char const *source, int line)
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)
void yac_set_default_comm(MPI_Comm comm)
void(* yac_abort_func)(MPI_Comm comm, const char *msg, const char *source, int line) __attribute__((noreturn))
void yac_set_abort_handler(yac_abort_func custom_abort)
#define yac_mpi_call(call, comm)