Skip to content
Snippets Groups Projects
Commit e85035fe authored by Moritz Hanke's avatar Moritz Hanke
Browse files

removes limitation of routine yac_duplicate_stencils to YAC_LOC_CELL

parent e025e16d
No related branches found
No related tags found
No related merge requests found
......@@ -94,19 +94,34 @@ void yac_duplicate_stencils(
char const * routine = "yac_duplicate_stencils";
YAC_ASSERT_F(
location == YAC_LOC_CELL, "ERROR(%s): only supported for cells", routine);
yac_int * duplicated_global_ids =
xmalloc(nbr_duplicated * sizeof(*duplicated_global_ids));
struct yac_basic_grid_data * grid_data =
yac_basic_grid_get_data(tgt_grid);
yac_int const * cell_ids = grid_data->cell_ids;
struct yac_basic_grid_data * grid_data = yac_basic_grid_get_data(tgt_grid);
YAC_ASSERT_F(
(location == YAC_LOC_CELL) ||
(location == YAC_LOC_CORNER) ||
(location == YAC_LOC_EDGE),
"ERROR(%s): invalid location", routine)
yac_int * point_ids;
switch (location) {
default:
case(YAC_LOC_CELL):
point_ids = grid_data->cell_ids;
break;
case(YAC_LOC_CORNER):
point_ids = grid_data->vertex_ids;
break;
case(YAC_LOC_EDGE):
point_ids = grid_data->edge_ids;
break;
};
// get global ids of all duplicated target cells
for (size_t i = 0; i < nbr_duplicated; ++i)
duplicated_global_ids[i] = cell_ids[tgt_duplicated_idx[i]];
duplicated_global_ids[i] = point_ids[tgt_duplicated_idx[i]];
// get target global ids of all local stencils
size_t stencil_count = yac_interp_weights_get_interp_count(weights);
......
......@@ -33,72 +33,80 @@ int main(void) {
return TEST_EXIT_CODE;
}
// generate dummy grid
struct yac_basic_grid_data grid_data =
generate_dummy_grid_data(5, 15, comm_rank * 5);
struct yac_basic_grid * grid = yac_basic_grid_new("grid", grid_data);
// generate weights
struct yac_interp_weights * weights =
yac_interp_weights_new(
MPI_COMM_WORLD, YAC_LOC_CELL, (enum yac_location[]){YAC_LOC_CELL}, 1);
struct remote_point tgts_data[5];
struct remote_points tgts = {.data = tgts_data};
struct remote_point srcs[5];
yac_int tgts_global_ids[3][5] = {{0,1,2,5,6},{7,8,9},{-1}};
int tgts_ranks[3][5] = {{0,0,0,1,1},{1,1,1},{-1}};
uint64_t tgts_orig_poses[3][5] = {{0,1,2,0,1},{2,3,4},{UINT64_MAX}};
int srcs_ranks[3][5] = {{1,1,1,1,2},{2,2,2},{-1}};
uint64_t srcs_orig_poses[3][5] = {{0,1,2,3,0},{1,2,3},{UINT64_MAX}};
size_t num_tgts[3] = {5, 3, 0};
// generate initial weights
tgts.count = num_tgts[comm_rank];
for (size_t i = 0; i < tgts.count; ++i) {
tgts.data[i].global_id = tgts_global_ids[comm_rank][i];
tgts.data[i].data.count = 1;
tgts.data[i].data.data.single.rank = tgts_ranks[comm_rank][i];
tgts.data[i].data.data.single.orig_pos = tgts_orig_poses[comm_rank][i];
srcs[i].data.count = 1;
srcs[i].data.data.single.rank = srcs_ranks[comm_rank][i];
srcs[i].data.data.single.orig_pos = srcs_orig_poses[comm_rank][i];
enum yac_location locations[] = {YAC_LOC_CELL, YAC_LOC_CORNER, YAC_LOC_EDGE};
enum {NUM_LOCATIONS = sizeof(locations) / sizeof(locations[0])};
for (size_t loc_idx = 0; loc_idx < NUM_LOCATIONS; ++loc_idx) {
// generate dummy grid
struct yac_basic_grid_data grid_data =
generate_dummy_grid_data(5, 15, comm_rank * 5);
struct yac_basic_grid * grid = yac_basic_grid_new("grid", grid_data);
// generate weights
struct yac_interp_weights * weights =
yac_interp_weights_new(
MPI_COMM_WORLD, locations[loc_idx],
(enum yac_location[]){locations[loc_idx]}, 1);
struct remote_point tgts_data[5];
struct remote_points tgts = {.data = tgts_data};
struct remote_point srcs[5];
yac_int tgts_global_ids[3][5] = {{0,1,2,5,6},{7,8,9},{-1}};
int tgts_ranks[3][5] = {{0,0,0,1,1},{1,1,1},{-1}};
uint64_t tgts_orig_poses[3][5] = {{0,1,2,0,1},{2,3,4},{UINT64_MAX}};
int srcs_ranks[3][5] = {{1,1,1,1,2},{2,2,2},{-1}};
uint64_t srcs_orig_poses[3][5] = {{0,1,2,3,0},{1,2,3},{UINT64_MAX}};
size_t num_tgts[3] = {5, 3, 0};
// generate initial weights
tgts.count = num_tgts[comm_rank];
for (size_t i = 0; i < tgts.count; ++i) {
tgts.data[i].global_id = tgts_global_ids[comm_rank][i];
tgts.data[i].data.count = 1;
tgts.data[i].data.data.single.rank = tgts_ranks[comm_rank][i];
tgts.data[i].data.data.single.orig_pos = tgts_orig_poses[comm_rank][i];
srcs[i].data.count = 1;
srcs[i].data.data.single.rank = srcs_ranks[comm_rank][i];
srcs[i].data.data.single.orig_pos = srcs_orig_poses[comm_rank][i];
}
yac_interp_weights_add_direct(weights, &tgts, srcs);
// duplicate some stencils
yac_int tgt_orig_global_id[3][4] = {{8,9},{-1},{0,1,8,9}};
size_t tgt_duplicated_idx[3][4] = {{3,4},{SIZE_MAX},{0,1,3,4}};
size_t nbr_duplicated[3] = {2,0,4};
yac_duplicate_stencils(
weights, grid, tgt_orig_global_id[comm_rank],
tgt_duplicated_idx[comm_rank], nbr_duplicated[comm_rank],
locations[loc_idx]);
// get interpolation from the weights
struct yac_interpolation * interpolation =
yac_interp_weights_get_interpolation(
weights, YAC_MAPPING_ON_SRC, 1,
YAC_FRAC_MASK_NO_VALUE, 1.0, 0.0, NULL);
// execute interpolation
double src_field_data[3][4] =
{{-1, -1, -1, -1}, {0, 1, 2, 3}, {4, 5, 6, 7}};
double ** src_fields[1] = {(double*[1]){src_field_data[comm_rank]}};
double * tgt_field[1] = {(double[5]){-1,-1,-1,-1,-1}};
yac_interpolation_execute(interpolation, src_fields, tgt_field);
// check results
double ref_tgt_field[3][5] =
{{0,1,2,6,7}, {3,4,5,6,7}, {0,1,-1,6,7}};
for (size_t i = 0; i < 5; ++i)
if (ref_tgt_field[comm_rank][i] != tgt_field[0][i])
PUT_ERR("ERROR in yac_duplicate_stencils");
// cleanup
yac_interpolation_delete(interpolation);
yac_interp_weights_delete(weights);
yac_basic_grid_delete(grid);
}
yac_interp_weights_add_direct(weights, &tgts, srcs);
// duplicate some stencils
yac_int tgt_orig_global_id[3][4] = {{8,9},{-1},{0,1,8,9}};
size_t tgt_duplicated_idx[3][4] = {{3,4},{SIZE_MAX},{0,1,3,4}};
size_t nbr_duplicated[3] = {2,0,4};
yac_duplicate_stencils(
weights, grid, tgt_orig_global_id[comm_rank],
tgt_duplicated_idx[comm_rank], nbr_duplicated[comm_rank], YAC_LOC_CELL);
// get interpolation from the weights
struct yac_interpolation * interpolation =
yac_interp_weights_get_interpolation(
weights, YAC_MAPPING_ON_SRC, 1,
YAC_FRAC_MASK_NO_VALUE, 1.0, 0.0, NULL);
// execute interpolation
double src_field_data[3][4] =
{{-1, -1, -1, -1}, {0, 1, 2, 3}, {4, 5, 6, 7}};
double ** src_fields[1] = {(double*[1]){src_field_data[comm_rank]}};
double * tgt_field[1] = {(double[5]){-1,-1,-1,-1,-1}};
yac_interpolation_execute(interpolation, src_fields, tgt_field);
// check results
double ref_tgt_field[3][5] =
{{0,1,2,6,7}, {3,4,5,6,7}, {0,1,-1,6,7}};
for (size_t i = 0; i < 5; ++i)
if (ref_tgt_field[comm_rank][i] != tgt_field[0][i])
PUT_ERR("ERROR in yac_duplicate_stencils");
// cleanup
yac_interpolation_delete(interpolation);
yac_interp_weights_delete(weights);
yac_basic_grid_delete(grid);
xt_finalize();
MPI_Finalize();
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment