25static void utest_delete_file(
char const * filename);
31 xt_initialize(MPI_COMM_WORLD);
33 int comm_rank, comm_size;
34 MPI_Comm_rank(MPI_COMM_WORLD, &comm_rank);
35 MPI_Comm_size(MPI_COMM_WORLD, &comm_size);
36 MPI_Barrier(MPI_COMM_WORLD);
40 PUT_ERR(
"ERROR: wrong number of processes");
60 {{.nbr_vertices = {{2,5},{5,5},{6,2}},
61 .lon_vertices = {{0,1},{1,2,3,4,5},{0,1,2,3,4,5}},
62 .lat_vertices = {{0,1,2,3,4},{0,1,2,3,4},{4,5}},
63 .cell_global_ids = {{0,5,10,15},
64 {1,2,3,4, 6,7,8,9, 11,12,13,14, 16,17,18,19},
66 .core_cell_mask = {{1,0,1,0},
67 {0,1,0,1, 1,0,1,0, 0,1,0,1, 1,0,1,0},
69 .vertex_global_ids = {{0,1,6,7,12,13,18,19,24,25},
70 {1,2,3,4,5, 7,8,9,10,11, 13,14,15,16,17,
71 19,20,21,22,23, 25,26,27,28,29},
72 {24,25,26,27,28,29, 30,31,32,33,34,35}},
73 .core_vertex_mask = {{1,0,
85 .edge_global_ids = {{0,1,3,
91 13,14,15,16,17,18,19,20,21,
92 24,25,26,27,28,29,30,31,32,
93 35,36,37,38,39,40,41,42,43,
95 {44,45,46,47,48,49,50,51,52,53,54,
97 .core_edge_mask = {{1,0,0,
107 {1,0,1,0,1,0,1,0,1,0,0,
109 .has_vertex_data = 1,
111 {.nbr_vertices = {{6,6},{0,0},{0,0}},
112 .lon_vertices = {{0,1,2,3,4,5},{-1},{-1}},
113 .lat_vertices = {{0,1,2,3,4,5},{-1},{-1}},
114 .cell_global_ids = {{0,1,2,3,4,
118 20,21,22,23,24}, {-1}, {-1}},
119 .core_cell_mask = {{1,0,1,0,1,
123 1,0,1,0,1}, {-1}, {-1}},
124 .core_vertex_mask = {{1,0,1,0,1,0,
131 .vertex_global_ids = {{0,1,2,3,4,5,
138 .has_vertex_data = 1,
140 {.nbr_vertices = {{3,3},{6,6},{0,0}},
141 .lon_vertices = {{0,1,2},{0,1,2,3,4,5},{-1}},
142 .lat_vertices = {{0,1,2},{0,1,2,3,4,5},{-1}},
143 .cell_global_ids = {{0,1,
149 20,21,22,23,24}, {-1}},
150 .core_cell_mask = {{1,0,
157 .has_vertex_data = 0,
158 .has_edge_data = 0}};
159 enum {NUM_DECOMP =
sizeof(decomp) /
sizeof(decomp[0])};
160 char const * grid_filename =
"test_basic_grid_parallel.nc";
165 for (
size_t decomp_idx = 0; decomp_idx < NUM_DECOMP; ++decomp_idx) {
166 for (
int with_cell_centers = 0; with_cell_centers <= 1; ++with_cell_centers) {
167 for (
int with_core_cell_mask = 0; with_core_cell_mask <= 1; ++with_core_cell_mask) {
168 for (
int with_cell_global_ids = 0; with_cell_global_ids <= 1; ++with_cell_global_ids) {
169 for (
int with_core_vertex_mask = 0; with_core_vertex_mask <= 1; ++with_core_vertex_mask) {
170 for (
int with_vertex_global_ids = 0; with_vertex_global_ids <= 1; ++with_vertex_global_ids) {
171 for (
int with_core_edge_mask = 0; with_core_edge_mask <= 1; ++with_core_edge_mask) {
172 for (
int with_edge_global_ids = 0; with_edge_global_ids <= 1; ++with_edge_global_ids) {
174 if ((!decomp[decomp_idx].has_vertex_data &&
175 with_core_vertex_mask) ||
176 (!decomp[decomp_idx].has_vertex_data &&
177 with_vertex_global_ids) ||
178 (!decomp[decomp_idx].has_edge_data &&
179 with_core_edge_mask) ||
180 (!decomp[decomp_idx].has_edge_data &&
181 with_edge_global_ids))
continue;
187 char const * grid_name =
"test_grid";
188 if (decomp[decomp_idx].nbr_vertices[comm_rank][0] *
189 decomp[decomp_idx].nbr_vertices[comm_rank][1] > 0) {
192 decomp[decomp_idx].nbr_vertices[comm_rank],
cyclic,
193 decomp[decomp_idx].lon_vertices[comm_rank],
194 decomp[decomp_idx].lat_vertices[comm_rank]);
204 malloc(basic_grid_data->
num_cells *
sizeof(*cell_center_coords));
205 for (
size_t i = 0;
i < basic_grid_data->
num_cells; ++
i) {
206 cell_center_coords[
i][0] = 0.0;
207 cell_center_coords[
i][1] = 0.0;
208 cell_center_coords[
i][2] = 0.0;
210 for (
size_t k = 0; k < 3; ++k)
211 cell_center_coords[i][k] +=
217 if (with_cell_centers && (basic_grid_data->
num_cells > 0))
220 free(cell_center_coords);
221 if (with_cell_global_ids && (basic_grid_data->
num_cells > 0))
224 decomp[decomp_idx].cell_global_ids[comm_rank],
225 basic_grid_data->
num_cells *
sizeof(decomp[0].cell_global_ids[0]));
226 if (with_core_cell_mask && (basic_grid_data->
num_cells > 0))
230 basic_grid_data->
num_cells *
sizeof(decomp[0].core_cell_mask[0]));
231 if (with_vertex_global_ids && (basic_grid_data->
num_vertices > 0))
234 decomp[decomp_idx].vertex_global_ids[comm_rank],
235 basic_grid_data->
num_vertices *
sizeof(decomp[0].vertex_global_ids[0]));
236 if (with_core_vertex_mask && (basic_grid_data->
num_vertices > 0))
240 basic_grid_data->
num_vertices *
sizeof(decomp[0].core_vertex_mask[0]));
241 if (with_edge_global_ids && (basic_grid_data->
num_edges > 0))
244 decomp[decomp_idx].edge_global_ids[comm_rank],
245 basic_grid_data->
num_edges *
sizeof(decomp[0].edge_global_ids[0]));
246 if (with_core_edge_mask && (basic_grid_data->
num_edges > 0))
250 basic_grid_data->
num_edges *
sizeof(decomp[0].core_edge_mask[0][0]));
254 setenv(
"YAC_IO_RANK_LIST",
"0,2", 1);
255 setenv(
"YAC_IO_MAX_NUM_RANKS_PER_NODE",
"3", 1);
264 if (comm_rank == 0) {
265 enum {NUM_CELLS = 25, NUM_CRN = 4};
266 double ref_cla[NUM_CELLS][NUM_CRN] =
267 {{0,0,1,1},{0,0,1,1},{0,0,1,1},{0,0,1,1},{0,0,1,1},
268 {1,1,2,2},{1,1,2,2},{1,1,2,2},{1,1,2,2},{1,1,2,2},
269 {2,2,3,3},{2,2,3,3},{2,2,3,3},{2,2,3,3},{2,2,3,3},
270 {3,3,4,4},{3,3,4,4},{3,3,4,4},{3,3,4,4},{3,3,4,4},
271 {4,4,5,5},{4,4,5,5},{4,4,5,5},{4,4,5,5},{4,4,5,5}};
272 double ref_clo[NUM_CELLS][NUM_CRN] =
273 {{0,1,1,0},{1,2,2,1},{2,3,3,2},{3,4,4,3},{4,5,5,4},
274 {0,1,1,0},{1,2,2,1},{2,3,3,2},{3,4,4,3},{4,5,5,4},
275 {0,1,1,0},{1,2,2,1},{2,3,3,2},{3,4,4,3},{4,5,5,4},
276 {0,1,1,0},{1,2,2,1},{2,3,3,2},{3,4,4,3},{4,5,5,4},
277 {0,1,1,0},{1,2,2,1},{2,3,3,2},{3,4,4,3},{4,5,5,4}};
278 double ref_lat[NUM_CELLS] =
279 {0.5,0.5,0.5,0.5,0.5,
283 4.5,4.5,4.5,4.5,4.5};
284 double ref_lon[NUM_CELLS] =
285 {0.5,1.5,2.5,3.5,4.5,
289 0.5,1.5,2.5,3.5,4.5};
290 int ref_cell_global_ids[NUM_CELLS] =
296 int ref_core_cell_mask[NUM_CELLS] =
302 int ref_vertex_global_ids[NUM_CELLS][NUM_CRN] =
303 {{0,1,7,6},{1,2,8,7},{2,3,9,8},{3,4,10,9},{4,5,11,10},
304 {6,7,13,12},{7,8,14,13},{8,9,15,14},{9,10,16,15},{10,11,17,16},
305 {12,13,19,18},{13,14,20,19},{14,15,21,20},{15,16,22,21},{16,17,23,22},
306 {18,19,25,24},{19,20,26,25},{20,21,27,26},{21,22,28,27},{22,23,29,28},
307 {24,25,31,30},{25,26,32,31},{26,27,33,32},{27,28,34,33},{28,29,35,34}};
308 int ref_core_vertex_mask[NUM_CELLS][NUM_CRN] =
309 {{1,0,1,0},{0,1,0,1},{1,0,1,0},{0,1,0,1},{1,0,1,0},
310 {0,1,0,1},{1,0,1,0},{0,1,0,1},{1,0,1,0},{0,1,0,1},
311 {1,0,1,0},{0,1,0,1},{1,0,1,0},{0,1,0,1},{1,0,1,0},
312 {0,1,0,1},{1,0,1,0},{0,1,0,1},{1,0,1,0},{0,1,0,1},
313 {1,0,1,0},{0,1,0,1},{1,0,1,0},{0,1,0,1},{1,0,1,0}};
314 int ref_edge_global_ids[NUM_CELLS][NUM_CRN] =
315 {{0,3,11,1},{2,5,13,3},{4,7,15,5},{6,9,17,7},{8,10,19,9},
316 {11,14,22,12},{13,16,24,14},{15,18,26,16},{17,20,28,18},{19,21,30,20},
317 {22,25,33,23},{24,27,35,25},{26,29,37,27},{28,31,39,29},{30,32,41,31},
318 {33,36,44,34},{35,38,46,36},{37,40,48,38},{39,42,50,40},{41,43,52,42},
319 {44,47,55,45},{46,49,56,47},{48,51,57,49},{50,53,58,51},{52,54,59,53}};
320 int ref_core_edge_mask[NUM_CELLS][NUM_CRN] =
321 {{1,0,1,0},{1,0,1,0},{1,0,1,0},{1,0,1,0},{1,0,1,0},
322 {1,0,1,0},{1,0,1,0},{1,0,1,0},{1,0,1,0},{1,0,1,0},
323 {1,0,1,0},{1,0,1,0},{1,0,1,0},{1,0,1,0},{1,0,1,0},
324 {1,0,1,0},{1,0,1,0},{1,0,1,0},{1,0,1,0},{1,0,1,0},
325 {1,0,1,0},{1,0,1,0},{1,0,1,0},{1,0,1,0},{1,0,1,0}};
328 grid_filename, grid_name, NUM_CELLS, NUM_CRN,
329 &ref_cla[0][0], &ref_clo[0][0],
330 with_cell_centers?ref_lat:NULL,
331 with_cell_centers?ref_lon:NULL,
332 with_cell_global_ids?ref_cell_global_ids:NULL,
333 with_core_cell_mask?ref_core_cell_mask:NULL,
334 with_vertex_global_ids?&ref_vertex_global_ids[0][0]:NULL,
335 with_core_vertex_mask?&ref_core_vertex_mask[0][0]:NULL,
336 with_edge_global_ids?&ref_edge_global_ids[0][0]:NULL,
337 with_core_edge_mask?&ref_core_edge_mask[0][0]:NULL);
339 MPI_Barrier(MPI_COMM_WORLD);
344 utest_delete_file(grid_filename);
353 size_t nbr_vertices[
NUM_PROCS] = {4,5,3};
356 double lon_vertices[
NUM_PROCS][5] = {{0,1,1,0}, {1,2,2,1.5,1}, {0,1,1.5}};
357 double lat_vertices[
NUM_PROCS][5] = {{0,0,1,1}, {0,0,1,1.5,1}, {1,1,1.5}};
358 int cell_to_vertex[
NUM_PROCS][5] = {{0,1,2,3}, {0,1,2,3,4}, {0,1,2}};
360 char const * grid_name =
"test_grid";
363 grid_name, nbr_vertices[comm_rank], nbr_cells[comm_rank],
364 num_vertices_per_cell[comm_rank], lon_vertices[comm_rank],
368 int core_cell_mask[
NUM_PROCS][1] = {{1}, {1}, {1}};
369 yac_int vertex_global_ids[
NUM_PROCS][5] = {{0,1,4,3}, {1,2,5,6,4}, {3,4,6}};
370 int core_vertex_mask[
NUM_PROCS][5] = {{1,1,1,1}, {1,1,1,1,1}, {1,1,1}};
371 yac_int edge_global_ids[
NUM_PROCS][5] = {{0,1,3,5}, {2,3,4,8,7}, {5,6,7}};
372 int core_edge_mask[
NUM_PROCS][5] = {{1,1,1,1}, {1,1,1,1,1}, {1,1,1}};
378 cell_global_ids[comm_rank],
379 grid_data->num_cells *
sizeof(cell_global_ids[0]));
386 vertex_global_ids[comm_rank],
387 grid_data->num_vertices *
sizeof(vertex_global_ids[0]));
394 edge_global_ids[comm_rank],
395 grid_data->num_edges *
sizeof(edge_global_ids[0]));
403 setenv(
"YAC_IO_RANK_LIST",
"0,2", 1);
404 setenv(
"YAC_IO_MAX_NUM_RANKS_PER_NODE",
"3", 1);
407 char const * grid_filename =
"test_basic_grid_parallel.nc";
412 MPI_Barrier(MPI_COMM_WORLD);
414 if (comm_rank == 0) {
415 enum {NUM_CELLS = 3, NUM_CRN = 5};
416 double ref_clo[NUM_CELLS][NUM_CRN] =
417 {{0,1,1,0,DBL_MAX},{1,2,2,1.5,1},{0,1,1.5,DBL_MAX,DBL_MAX}};
418 double ref_cla[NUM_CELLS][NUM_CRN] =
419 {{0,0,1,1,DBL_MAX},{0,0,1,1.5,1},{1,1,1.5,DBL_MAX,DBL_MAX}};
420 int ref_cell_global_ids[NUM_CELLS] = {0,1,2};
421 int ref_core_cell_mask[NUM_CELLS] = {1,1,1};
422 int ref_vertex_global_ids[NUM_CELLS][NUM_CRN] =
423 {{0,1,4,3,INT_MAX},{1,2,5,6,4},{3,4,6,INT_MAX,INT_MAX}};
424 int ref_core_vertex_mask[NUM_CELLS][NUM_CRN] =
425 {{1,1,1,1,INT_MAX},{1,1,1,1,1},{1,1,1,INT_MAX,INT_MAX}};
426 int ref_edge_global_ids[NUM_CELLS][NUM_CRN] =
427 {{0,3,5,1,INT_MAX}, {2,4,8,7,3}, {5,7,6,INT_MAX,INT_MAX}};
428 int ref_core_edge_mask[NUM_CELLS][NUM_CRN] =
429 {{1,1,1,1,INT_MAX},{1,1,1,1,1},{1,1,1,INT_MAX,INT_MAX}};
432 grid_filename, grid_name, NUM_CELLS, NUM_CRN,
433 &ref_cla[0][0], &ref_clo[0][0], NULL, NULL,
434 ref_cell_global_ids, ref_core_cell_mask,
435 &ref_vertex_global_ids[0][0], &ref_core_vertex_mask[0][0],
436 &ref_edge_global_ids[0][0], &ref_core_edge_mask[0][0]);
439 MPI_Barrier(MPI_COMM_WORLD);
440 utest_delete_file(grid_filename);
449static void utest_delete_file(
char const * filename) {
452 MPI_Comm_rank(MPI_COMM_WORLD, &rank);
453 MPI_Barrier(MPI_COMM_WORLD);
454 if (rank == 0) unlink(filename);
455 MPI_Barrier(MPI_COMM_WORLD);
struct yac_basic_grid * yac_basic_grid_new(char const *name, struct yac_basic_grid_data grid_data)
void yac_basic_grid_to_file_parallel(struct yac_basic_grid *grid, char const *filename, MPI_Comm comm)
struct yac_basic_grid * yac_basic_grid_unstruct_deg_new(char const *name, size_t nbr_vertices, size_t nbr_cells, int *num_vertices_per_cell, double *x_vertices, double *y_vertices, int *cell_to_vertex)
struct yac_basic_grid_data * yac_basic_grid_get_data(struct yac_basic_grid *grid)
size_t yac_basic_grid_add_coordinates(struct yac_basic_grid *grid, enum yac_location location, yac_coordinate_pointer coordinates, size_t count)
struct yac_basic_grid * yac_basic_grid_empty_new(char const *name)
void yac_basic_grid_delete(struct yac_basic_grid *grid)
struct yac_basic_grid_data yac_generate_basic_grid_data_reg_2d_deg(size_t nbr_vertices[2], int cyclic[2], double *lon_vertices, double *lat_vertices)
static void normalise_vector(double v[])
void check_grid_file(char const *filename, char const *grid_name, size_t ref_num_cells, size_t ref_num_corners_per_cell, double *ref_cla, double *ref_clo, double *ref_lat, double *ref_lon, int *ref_cell_global_ids, int *ref_core_cell_mask, int *ref_vertex_global_ids, int *ref_core_vertex_mask, int *ref_edge_global_ids, int *ref_core_edge_mask)
int yac_file_exists(const char *filename)
yac_coordinate_pointer vertex_coordinates
size_t * cell_to_vertex_offsets
int * num_vertices_per_cell
void * to_pointer(void *data, size_t size_data)
double(* yac_coordinate_pointer)[3]