22#define YAC_RAD (0.01745329251994329576923690768489)
24int main(
int argc,
char** argv) {
29 PUT_ERR(
"ERROR: missing config file directory");
34 feenableexcept(FE_INVALID);
36 for (
int with_core_mask = 0; with_core_mask < 2; ++with_core_mask) {
37 for (
int with_field_mask = 0; with_field_mask < 2; ++with_field_mask) {
46 malloc(strlen(argv[1]) + 32), argv[1]),
"coupling_test5.yaml");
51 MPI_Comm_rank ( MPI_COMM_WORLD, &rank );
52 MPI_Comm_size ( MPI_COMM_WORLD, &size );
55 fputs(
"wrong number of processes (has to be 3)\n", stderr);
59 int is_target = rank < 2;
60 int is_source = rank > 0;
61 YAC_ASSERT((is_target || is_source),
"internal error")
65 char const * comp_name =
"main_comp";
75 "target_grid", (
int[2]){3,3}, (
int[2]){0,0},
76 x_vertices[rank], y_vertices, &grid_ids[0]);
79 "source_grid", (
int[2]){3,3}, (
int[2]){0,0},
80 x_vertices[rank-1], y_vertices, &grid_ids[1]);
82 yac_int cell_global_index[2][4] = {{0,1,3,4}, {1,2,4,5}};
83 yac_int corner_global_index[2][9] =
84 {{0,1,2, 4,5,6, 8,9,10}, {1,2,3, 5,6,7, 9,10,11}};
85 yac_int edge_global_index[2][12] =
86 {{0,1,2,3,5, 7,8,9,10,12, 14,15}, {2,3,4,5,6, 9,10,11,12,13, 15,16}};
88 int corner_core_mask[2][9] = {{1,1,1, 1,1,1, 1,1,0}, {0,1,1, 1,1,1, 1,1,1}};
89 int edge_core_mask[2][12] = {{1,1,1,1,1, 1,1,1,1,0, 1,0},
90 {0,0,1,1,1, 1,1,1,1,1, 1,1}};
91 int corner_field_mask[2][9] = {{1,1,1, 0,1,1, 1,1,1}, {1,1,1, 1,1,1, 1,1,1}};
115 if (with_core_mask) {
130 x_vertices[rank], y_vertices, &point_ids[0]);
137 x_vertices[rank-1], y_vertices, &point_ids[1]);
144 int dummy_field_ids[2];
154 &dummy_field_ids[0]);
165 &dummy_field_ids[1]);
170 double source_data[10][2][9] =
171 {{{ 0, 1, 2, 4, 5, 6, 8, 9,10}, { 1, 2, 3, 5, 6, 7, 9,10,11}},
172 {{ 1, 2, 3, 5, 6, 7, 9,10,11}, { 2, 3, 4, 6, 7, 8,10,11,12}},
173 {{ 2, 3, 4, 6, 7, 8,10,11,12}, { 3, 4, 5, 7, 8, 9,11,12,13}},
174 {{ 3, 4, 5, 7, 8, 9,11,12,13}, { 4, 5, 6, 8, 9,10,12,13,14}},
175 {{ 4, 5, 6, 8, 9,10,12,13,14}, { 5, 6, 7, 9,10,11,13,14,15}},
176 {{ 5, 6, 7, 9,10,11,13,14,15}, { 6, 7, 8,10,11,12,14,15,16}},
177 {{ 6, 7, 8,10,11,12,14,15,16}, { 7, 8, 9,11,12,13,15,16,17}},
178 {{-1,-1,-1,-1,-1,-1,-1,-1,-1}, {-1,-1,-1,-1,-1,-1,-1,-1,-1}},
179 {{-1,-1,-1,-1,-1,-1,-1,-1,-1}, {-1,-1,-1,-1,-1,-1,-1,-1,-1}},
180 {{-1,-1,-1,-1,-1,-1,-1,-1,-1}, {-1,-1,-1,-1,-1,-1,-1,-1,-1}}};
181 double ref_recv_field[2][7][2][9] =
182 {{{{ 0, 1, 2, 4, 5, 6, 8, 9,10}, { 1, 2, 3, 5, 6, 7, 9,10,11}},
183 {{-1,-1,-1,-1,-1,-1,-1,-1,-1}, {-1,-1,-1,-1,-1,-1,-1,-1,-1}},
184 {{ 6, 9,12,18,21,24,30,33,36}, { 9,12,15,21,24,27,33,36,39}},
185 {{-1,-1,-1,-1,-1,-1,-1,-1,-1}, {-1,-1,-1,-1,-1,-1,-1,-1,-1}},
186 {{15,18,21,27,30,33,39,42,45}, {18,21,24,30,33,36,42,45,48}},
187 {{-1,-1,-1,-1,-1,-1,-1,-1,-1}, {-1,-1,-1,-1,-1,-1,-1,-1,-1}},
188 {{-1,-1,-1,-1,-1,-1,-1,-1,-1}, {-1,-1,-1,-1,-1,-1,-1,-1,-1}}},
189 {{{ 0, 1, 2, 4, 5, 6, 8, 9,10}, { 1, 2, 3, 5, 6, 7, 9,10,11}},
190 {{-1,-1,-1,-1,-1,-1,-1,-1,-1}, {-1,-1,-1,-1,-1,-1,-1,-1,-1}},
191 {{ 3, 4, 5, 7, 8, 9,11,12,13}, { 4, 5, 6, 8, 9,10,12,13,14}},
192 {{-1,-1,-1,-1,-1,-1,-1,-1,-1}, {-1,-1,-1,-1,-1,-1,-1,-1,-1}},
193 {{ 6, 7, 8,10,11,12,14,15,16}, { 7, 8, 9,11,12,13,15,16,17}},
194 {{-1,-1,-1,-1,-1,-1,-1,-1,-1}, {-1,-1,-1,-1,-1,-1,-1,-1,-1}},
195 {{-1,-1,-1,-1,-1,-1,-1,-1,-1}, {-1,-1,-1,-1,-1,-1,-1,-1,-1}}}};
199 for (
size_t i = 0; i < 10; ++i)
200 for (
size_t j = 0; j < 2; ++j)
201 for (
size_t k = 0; k < 9; ++k)
202 if ((with_core_mask && !corner_core_mask[rank-1][k]) ||
203 (with_field_mask && !corner_field_mask[rank-1][k]))
204 source_data[i][j][k] = SNAN;
207 for (
size_t i = 0; i < 2; ++i)
208 for (
size_t j = 0; j < 7; ++j)
209 for (
size_t k = 0; k < 2; ++k)
210 for (
size_t l = 0; l < 9; ++l)
211 if ((with_core_mask && !corner_core_mask[rank][l]) ||
212 (with_field_mask && !corner_field_mask[rank][l]))
213 ref_recv_field[i][j][k][l] = -1;
215 int ref_send_info[2][10] =
236 int ref_recv_info[7] =
245 int const source_period = 2;
246 int const target_period = 3;
247 int const test_time = 18;
250 for (
int t = 0, put_idx = 0, get_idx = 0; t <= test_time; ++t) {
252 int is_even_timestep = !(t%2);
253 int is_source_timestep = is_source && (!(t%source_period));
254 int is_target_timestep = is_target && (!(t%target_period));
257 double * send_field_vertex =
258 (is_source_timestep)?(source_data[put_idx][rank-1]):NULL;
259 double * send_fields[1] = {send_field_vertex};
260 double ** send_field_collection_data[1] = {send_fields};
261 double recv_field_data[9] = {-1.0,-1.0,-1.0,-1.0,-1.0,-1.0,-1.0,-1.0,-1.0};
262 double * recv_field_vertex =
263 (is_target_timestep)?recv_field_data:NULL;
264 double * recv_field_collection_data[1] = {recv_field_vertex};
266 int send_info, recv_info, send_action, recv_action;
267 int dummy_send_ierr, dummy_recv_ierr;
272 if (is_even_timestep) {
275 &send_info, &dummy_send_ierr);
276 if (dummy_send_ierr != 0)
PUT_ERR(
"ERROR in dummy_send_ierr");
285 if (is_even_timestep) {
288 &recv_info, &dummy_recv_ierr);
289 if (dummy_recv_ierr != 0)
PUT_ERR(
"ERROR in dummy_recv_ierr");
296 for (
int i = 0; i < 2; ++i) {
298 if (is_source_timestep && !is_target_timestep) {
308 }
else if (!is_source_timestep && is_target_timestep) {
318 }
else if (is_source_timestep && is_target_timestep) {
323 send_field_collection_data, recv_field_collection_data,
324 &send_info, &recv_info, &ierr);
327 if (ierr != 0)
PUT_ERR(
"ERROR in ierr");
328 if (is_source_timestep) {
329 if (send_info != ref_send_info[i][put_idx])
331 if (send_action != ref_send_info[i][put_idx])
332 PUT_ERR(
"ERROR in send_action");
334 if (is_target_timestep) {
335 if (recv_info != ref_recv_info[get_idx])
337 if (recv_action != ref_recv_info[get_idx])
338 PUT_ERR(
"ERROR in recv_action");
339 for (
int j = 0; j < 9; ++j)
340 if (fabs(recv_field_data[j] -
341 ref_recv_field[i][get_idx][rank][j]) > 1e-9)
342 PUT_ERR(
"ERROR in recv_field_data");
346 if (is_source_timestep) ++put_idx;
347 if (is_target_timestep) ++get_idx;
#define YAC_ASSERT(exp, msg)
void yac_cset_global_index_yac_int(yac_int const *global_index, int location, int grid_id)
int const YAC_ACTION_OUT_OF_BOUND
put/get is outside of the valid range
int const YAC_LOCATION_CELL
void yac_cfinalize_instance(int yac_instance_id)
Finalises YAC.
void yac_cenddef_instance(int yac_instance_id)
void yac_cread_config_yaml_instance(int yac_instance_id, const char *yaml_filename)
int const YAC_LOCATION_CORNER
void yac_cget(int const field_id, int collection_size, double **recv_field, int *info, int *ierr)
void yac_cupdate(int field_id)
void yac_cget_action(int field_id, int *action)
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)
int const YAC_TIME_UNIT_SECOND
void yac_cexchange(int const send_field_id, int const recv_field_id, int const collection_size, double ***const send_field, double **recv_field, int *send_info, int *recv_info, int *ierr)
int const YAC_LOCATION_EDGE
void yac_cput(int const field_id, int const collection_size, double ***const send_field, int *info, int *ierr)
int const YAC_ACTION_NONE
no data exchanges
void yac_cdef_calendar(int calendar)
void yac_cset_core_mask(int const *is_core, int location, int grid_id)
int const YAC_ACTION_REDUCTION
data reduction, but data exchange
int const YAC_ACTION_GET_FOR_RESTART
last valid get
int const YAC_PROLEPTIC_GREGORIAN
void yac_cset_mask(int const *is_valid, int points_id)
int const YAC_ACTION_COUPLING
data exchange
void yac_cinit_instance(int *yac_instance_id)
int const YAC_ACTION_PUT_FOR_RESTART
last valid put
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_comps_instance(int yac_instance_id, char const **comp_names, int num_comps, int *comp_ids)