YAC 3.12.0
Yet Another Coupler
Loading...
Searching...
No Matches
test_duplicate_stencils_parallel_c.c
Go to the documentation of this file.
1// Copyright (c) 2024 The YAC Authors
2//
3// SPDX-License-Identifier: BSD-3-Clause
4
5#include <limits.h>
6#include <mpi.h>
7#include <yaxt.h>
8
9#include "tests.h"
10#include "dist_grid_utils.h"
11#include "grids/basic_grid.h"
13#include "duplicate_stencils.h"
14
20static struct yac_basic_grid_data
22 size_t local_num_cells, size_t global_num_cells, size_t num_cells_offset);
23
24int main(void) {
25
26 MPI_Init(NULL, NULL);
27
28 xt_initialize(MPI_COMM_WORLD);
29
30 int comm_rank, comm_size;
31 MPI_Comm_rank(MPI_COMM_WORLD, &comm_rank);
32 MPI_Comm_size(MPI_COMM_WORLD, &comm_size);
33
34 if (comm_size != 3) {
35 PUT_ERR("This test requires 3 processes\n");
36 xt_finalize();
37 MPI_Finalize();
38 return TEST_EXIT_CODE;
39 }
40
42 enum {NUM_LOCATIONS = sizeof(locations) / sizeof(locations[0])};
43
44 for (size_t loc_idx = 0; loc_idx < NUM_LOCATIONS; ++loc_idx) {
45
46 // generate dummy grid
48 generate_dummy_grid_data(5, 15, comm_rank * 5);
50
51 // generate weights
54 MPI_COMM_WORLD, locations[loc_idx],
55 (enum yac_location[]){locations[loc_idx]}, 1);
56
57 struct remote_point tgts_data[5];
58 struct remote_points tgts = {.data = tgts_data};
59 struct remote_point srcs[5];
60
61 yac_int tgts_global_ids[3][5] = {{0,1,2,5,6},{7,8,9},{-1}};
62 int tgts_ranks[3][5] = {{0,0,0,1,1},{1,1,1},{-1}};
63 uint64_t tgts_orig_poses[3][5] = {{0,1,2,0,1},{2,3,4},{UINT64_MAX}};
64 int srcs_ranks[3][5] = {{1,1,1,1,2},{2,2,2},{-1}};
65 uint64_t srcs_orig_poses[3][5] = {{0,1,2,3,0},{1,2,3},{UINT64_MAX}};
66 size_t num_tgts[3] = {5, 3, 0};
67
68 // generate initial weights
69 tgts.count = num_tgts[comm_rank];
70 for (size_t i = 0; i < tgts.count; ++i) {
71 tgts.data[i].global_id = tgts_global_ids[comm_rank][i];
72 tgts.data[i].data.count = 1;
73 tgts.data[i].data.data.single.rank = tgts_ranks[comm_rank][i];
74 tgts.data[i].data.data.single.orig_pos = tgts_orig_poses[comm_rank][i];
75 srcs[i].data.count = 1;
76 srcs[i].data.data.single.rank = srcs_ranks[comm_rank][i];
77 srcs[i].data.data.single.orig_pos = srcs_orig_poses[comm_rank][i];
78 }
79 yac_interp_weights_add_direct(weights, &tgts, srcs);
80
81 // duplicate some stencils
82 yac_int tgt_orig_global_id[3][4] = {{8,9},{-1},{0,1,8,9}};
83 size_t tgt_duplicated_idx[3][4] = {{3,4},{SIZE_MAX},{0,1,3,4}};
84 size_t nbr_duplicated[3] = {2,0,4};
86 weights, grid, tgt_orig_global_id[comm_rank],
87 tgt_duplicated_idx[comm_rank], nbr_duplicated[comm_rank],
88 locations[loc_idx]);
89
90 // get interpolation from the weights
91 struct yac_interpolation * interpolation =
93 weights, YAC_MAPPING_ON_SRC, 1,
94 YAC_FRAC_MASK_NO_VALUE, 1.0, 0.0, NULL, 1, 1);
95
96 // execute interpolation
97 double src_field_data[3][4] =
98 {{-1, -1, -1, -1}, {0, 1, 2, 3}, {4, 5, 6, 7}};
99 double ** src_fields[1] = {(double*[1]){src_field_data[comm_rank]}};
100 double * tgt_field[1] = {(double[5]){-1,-1,-1,-1,-1}};
101 yac_interpolation_execute(interpolation, src_fields, tgt_field);
102
103 // check results
104 double ref_tgt_field[3][5] =
105 {{0,1,2,6,7}, {3,4,5,6,7}, {0,1,-1,6,7}};
106 for (size_t i = 0; i < 5; ++i)
107 if (ref_tgt_field[comm_rank][i] != tgt_field[0][i])
108 PUT_ERR("ERROR in yac_duplicate_stencils");
109
110 // cleanup
111 yac_interpolation_delete(interpolation);
114 }
115
116 xt_finalize();
117 MPI_Finalize();
118
119 return TEST_EXIT_CODE;
120}
121
122static struct yac_basic_grid_data
124 size_t local_num_cells, size_t global_num_cells, size_t num_cells_offset) {
125
126 double coordinates_x[global_num_cells + 1];
127 double coordinates_y[2] = {0.0, 1.0};
128 size_t num_cells[2] = {global_num_cells, 1};
129 size_t local_start[2] = {num_cells_offset, 0};
130 size_t local_count[2] = {local_num_cells, 1};
131
132 for (size_t i = 0; i <= global_num_cells; ++i) coordinates_x[i] = (double)i;
133
134 return
136 coordinates_x, coordinates_y, num_cells, local_start, local_count, 0);
137}
struct yac_basic_grid * yac_basic_grid_new(char const *name, struct yac_basic_grid_data grid_data)
Definition basic_grid.c:50
void yac_basic_grid_delete(struct yac_basic_grid *grid)
Definition basic_grid.c:70
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_duplicate_stencils(struct yac_interp_weights *weights, struct yac_basic_grid *tgt_grid, yac_int *tgt_orig_global_id, size_t *tgt_duplicated_idx, size_t nbr_duplicated, enum yac_location location)
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_add_direct(struct yac_interp_weights *weights, struct remote_points *tgts, struct remote_point *srcs)
struct yac_interp_weights * yac_interp_weights_new(MPI_Comm comm, enum yac_location tgt_location, enum yac_location *src_locations, size_t num_src_fields)
@ YAC_MAPPING_ON_SRC
weights will be applied at source processes
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.
double const YAC_FRAC_MASK_NO_VALUE
yac_location
Definition location.h:12
@ YAC_LOC_CORNER
Definition location.h:15
@ YAC_LOC_EDGE
Definition location.h:16
@ YAC_LOC_CELL
Definition location.h:14
struct remote_point_info single
union remote_point_infos::@59 data
information (global id and location) about a point that
yac_int global_id
struct remote_point_infos data
structure containing the information (global id and location)
struct remote_point * data
static enum yac_location locations[]
static struct yac_basic_grid_data generate_dummy_grid_data(size_t local_num_cells, size_t global_num_cells, size_t num_cells_offset)
double coordinates_x[]
double coordinates_y[]
#define TEST_EXIT_CODE
Definition tests.h:14
#define PUT_ERR(string)
Definition tests.h:10
YAC_INT yac_int
Definition yac_types.h:15