25 int comm_rank, comm_size;
26 MPI_Comm_rank(MPI_COMM_WORLD, &comm_rank);
27 MPI_Comm_size(MPI_COMM_WORLD, &comm_size);
31 if (comm_rank == 0)
PUT_ERR(
"This test must be run with 4 processes");
37 char const * comp_name =
"main_component";
43 GLOBAL_NUM_CELLS_X = 16,
44 GLOBAL_NUM_CELLS_Y = 16,
48 double vertices_x[GLOBAL_NUM_CELLS_X+1];
49 double vertices_y[GLOBAL_NUM_CELLS_Y+1];
50 double cells_x[GLOBAL_NUM_CELLS_X];
51 double cells_y[GLOBAL_NUM_CELLS_Y];
52 for (
size_t i = 0;
i <= GLOBAL_NUM_CELLS_X; ++
i)
54 (-5.0 + (10.0 * (
double)i) / (
double)GLOBAL_NUM_CELLS_X) *
YAC_RAD;
55 for (
size_t j = 0; j <= GLOBAL_NUM_CELLS_Y; ++j)
57 (-5.0 + (10.0 * (
double)j) / (
double)GLOBAL_NUM_CELLS_Y) *
YAC_RAD;
58 for (
size_t i = 0;
i < GLOBAL_NUM_CELLS_X; ++
i)
59 cells_x[i] = 0.5 * (vertices_x[i] + vertices_x[i+1]);
60 for (
size_t j = 0; j < GLOBAL_NUM_CELLS_Y; ++j)
61 cells_y[j] = 0.5 * (vertices_y[j] + vertices_y[j+1]);
64 int local_start_x = 0;
65 int local_start_y = (comm_rank * GLOBAL_NUM_CELLS_Y) / comm_size;
66 int local_count_x = GLOBAL_NUM_CELLS_X;
68 ((comm_rank + 1) * GLOBAL_NUM_CELLS_Y) / comm_size - local_start_y;
69 char const * grid_name =
"main_grid";
70 int nbr_cells[2] = {local_count_x, local_count_y};
71 int nbr_vertices[2] = {local_count_x + 1, local_count_y + 1};
75 grid_name, nbr_vertices,
cyclic,
76 vertices_x + local_start_x, vertices_y + local_start_y, &
grid_id);
82 cells_x + local_start_x, cells_y + local_start_y, &
cell_point_id);
85 enum {COAST_COLUMN = 8};
86 int coast_mask[GLOBAL_NUM_CELLS_Y][GLOBAL_NUM_CELLS_X];
87 int ocean_mask[GLOBAL_NUM_CELLS_Y][GLOBAL_NUM_CELLS_X];
88 for (
size_t j = 0; j < GLOBAL_NUM_CELLS_Y; ++j) {
89 for (
size_t i = 0;
i < GLOBAL_NUM_CELLS_X; ++
i) {
92 coast_mask[j][
i] = (
i == COAST_COLUMN);
95 ocean_mask[j][
i] = (
i > COAST_COLUMN);
98 int coast_mask_id, ocean_mask_id;
101 &coast_mask[local_start_y][0], &coast_mask_id);
104 &ocean_mask[local_start_y][0], &ocean_mask_id);
108 char const * timestep =
"1";
109 int temp_field_id, sst_field_id, runoff_coast_field_id, runoff_ocean_field_id;
130 enum {SRC_LAG = 0, TGT_LAG = 0};
131 int interp_stack_1nn;
133 "[{\"nnn\": {\"n\": 1}}]", &interp_stack_1nn);
135 comp_name, grid_name,
"temp",
136 comp_name, grid_name,
"sst",
138 interp_stack_1nn, SRC_LAG, TGT_LAG);
141 int interp_stack_spmap;
143 "[\"source_to_target_map\", {\"fixed\": {\"user_value\": 999}}]",
144 &interp_stack_spmap);
146 comp_name, grid_name,
"runoff",
147 comp_name, grid_name,
"river_runoff",
149 interp_stack_spmap, SRC_LAG, TGT_LAG);
157 double global_temp_data[GLOBAL_NUM_CELLS_Y][GLOBAL_NUM_CELLS_X];
158 double global_runoff_data[GLOBAL_NUM_CELLS_Y][GLOBAL_NUM_CELLS_X];
161 for (
size_t j = 0; j < GLOBAL_NUM_CELLS_Y; ++j) {
162 for (
size_t i = 0;
i < GLOBAL_NUM_CELLS_X; ++
i) {
163 global_temp_data[j][
i] = 100.0 + 10.0 * (double)j + (
double)
i;
168 for (
size_t j = 0; j < GLOBAL_NUM_CELLS_Y; ++j) {
169 for (
size_t i = 0;
i < GLOBAL_NUM_CELLS_X; ++
i) {
170 if (i == COAST_COLUMN) {
171 global_runoff_data[j][
i] = (double)j;
173 global_runoff_data[j][
i] = -1.0;
179 double sst_data[local_count_y][local_count_x];
180 double river_runoff_data[local_count_y][local_count_x];
181 for (
int j = 0; j < local_count_y; ++j) {
182 for (
int i = 0;
i < local_count_x; ++
i) {
183 sst_data[j][
i] = -2.0;
184 river_runoff_data[j][
i] = -2.0;
192 &global_temp_data[local_start_y][0], &sst_data[0][0],
196 &global_runoff_data[local_start_y][0], &river_runoff_data[0][0],
201 double ref_global_sst_data[GLOBAL_NUM_CELLS_Y][GLOBAL_NUM_CELLS_X];
202 for (
size_t j = 0; j < GLOBAL_NUM_CELLS_Y; ++j) {
203 for (
size_t i = 0;
i < GLOBAL_NUM_CELLS_X; ++
i) {
204 if (i > COAST_COLUMN) {
206 ref_global_sst_data[j][
i] = global_temp_data[j][
i];
208 ref_global_sst_data[j][
i] = -2.0;
216 double ref_global_river_runoff_data[GLOBAL_NUM_CELLS_Y][GLOBAL_NUM_CELLS_X];
217 for (
size_t j = 0; j < GLOBAL_NUM_CELLS_Y; ++j) {
218 for (
size_t i = 0;
i < GLOBAL_NUM_CELLS_X; ++
i) {
219 if (i == COAST_COLUMN + 1) {
221 ref_global_river_runoff_data[j][
i] = global_runoff_data[j][COAST_COLUMN];
222 }
else if (i > COAST_COLUMN + 1) {
223 ref_global_river_runoff_data[j][
i] = 999.0;
225 ref_global_river_runoff_data[j][
i] = -2.0;
231 for (
int j = local_start_y; j < local_count_y; ++j) {
232 for (
int i = local_start_x;
i < local_count_x; ++
i) {
233 if (sst_data[j][i] !=
234 ref_global_sst_data[local_start_y + j][local_start_x + i]) {
237 if (river_runoff_data[j][i] !=
238 ref_global_river_runoff_data[local_start_y + j][local_start_x + i]) {
void yac_cdef_field_mask(char const *name, int const comp_id, int const *point_ids, int const *mask_ids, int const num_pointsets, int collection_size, const char *timestep, int time_unit, int *field_id)
void yac_cdef_datetime(const char *start_datetime, const char *end_datetime)
int const YAC_LOCATION_CELL
void yac_cget_interp_stack_config_from_string_json(char const *interp_stack_config, int *interp_stack_config_id)
int const YAC_TIME_UNIT_HOUR
void yac_cfinalize()
Finalises YAC.
void yac_cexchange_(int const send_field_id, int const recv_field_id, int const collection_size, double *send_field, double *recv_field, int *send_info, int *recv_info, int *ierr)
void yac_cdef_grid_reg2d(const char *grid_name, int nbr_vertices[2], int cyclic[2], double *x_vertices, double *y_vertices, int *grid_id)
void yac_cdef_points_reg2d(int const grid_id, int const *nbr_points, int const located, double const *x_points, double const *y_points, int *point_id)
void yac_cdef_calendar(int calendar)
int const YAC_PROLEPTIC_GREGORIAN
void yac_cdef_mask(int const grid_id, int const nbr_points, int const located, int const *is_valid, int *mask_id)
void yac_cfree_interp_stack_config(int interp_stack_config_id)
void yac_cdef_comp(char const *comp_name, int *comp_id)
void yac_cdef_field(char const *name, int const comp_id, int const *point_ids, int const num_pointsets, int collection_size, const char *timestep, int time_unit, int *field_id)
void yac_cdef_couple(char const *src_comp_name, char const *src_grid_name, char const *src_field_name, char const *tgt_comp_name, char const *tgt_grid_name, char const *tgt_field_name, char const *coupling_timestep, int time_unit, int time_reduction, int interp_stack_config_id, int src_lag, int tgt_lag)
int const YAC_REDUCTION_TIME_NONE