This example simulates a restart of a coupled configuration with a grid redefinition.
#define EXACT
#include <mpi.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <unistd.h>
#include "tests.h"
#define DUMMY_VALUE (-1337.0)
static int point_id = INT_MAX;
double * field_out_data = NULL;
double * field_in_data = NULL;
size_t field_data_size = 0;
char const * config_filename = "test_restart_c.yaml";
static void generate_icon_grid(
int comm_rank, int comm_size, char const * grid_dir);
static void generate_cube_grid(int comm_rank, int comm_size);
static void run_model_config(
int icon_to_cube, int cube_to_icon, int config_from_file,
char const * grid_dir) {
int global_rank, global_size;
MPI_Comm_rank(MPI_COMM_WORLD, &global_rank);
MPI_Comm_size(MPI_COMM_WORLD, &global_size);
if (global_size < 3) {
fprintf(stderr, "Wrong number of processes (should be at least 3)\n");
exit(EXIT_FAILURE);
}
int is_icon = global_rank < (global_size / 2);
int comp_id;
MPI_Comm local_comm;
int local_rank, local_size;
MPI_Comm_rank(local_comm, &local_rank);
MPI_Comm_size(local_comm, &local_size);
MPI_Comm_free(&local_comm);
if (point_id == INT_MAX) {
if (is_icon) generate_icon_grid(local_rank, local_size, grid_dir);
else generate_cube_grid(local_rank, local_size);
}
int field_out_id, field_in_id;
int receives_data;
if (is_icon) {
receives_data = cube_to_icon;
"icon_to_cube", comp_id, &point_id, 1, 1, "1",
"cube_to_icon", comp_id, &point_id, 1, 1, "1",
} else {
receives_data = icon_to_cube;
"cube_to_icon", comp_id, &point_id, 1, 1, "1",
"icon_to_cube", comp_id, &point_id, 1, 1, "1",
}
if (config_from_file) {
} else {
int interp_stack_id;
if (icon_to_cube && !is_icon)
"icon", "icon", "icon_to_cube",
"cube", "cube", "icon_to_cube",
interp_stack_id, 0, 0);
if (cube_to_icon && is_icon)
"cube", "cube", "cube_to_icon",
"icon", "icon", "cube_to_icon",
interp_stack_id, 0, 0);
char * config;
if (global_rank == 0) {
FILE * config_file = fopen(config_filename, "w");
fputs(config, config_file);
fclose(config_file);
}
free(config);
}
for (int t = 0; t < 10; ++t) {
{
int info, err;
double *point_set_data[1];
double **collection_data[1] = {point_set_data};
point_set_data[0] = field_out_data;
yac_cput(field_out_id, 1, collection_data, &info, &err);
}
{
for (size_t i = 0; i < field_data_size; ++i)
field_in_data[i] = DUMMY_VALUE;
int info, err;
double *collection_data[1] = {field_in_data};
yac_cget(field_in_id, 1, collection_data, &info, &err);
for (size_t i = 0; i < field_data_size; ++i) {
if (receives_data) {
if (fabs(field_in_data[i] - field_out_data[i]) > 1e-3)
PUT_ERR("data missmatch");
} else {
if (field_in_data[i] != DUMMY_VALUE)
PUT_ERR("data missmatch");
}
}
}
}
}
int main(
int argc,
char** argv) {
if (argc != 2) {
PUT_ERR("ERROR: missing grid file directory");
return TEST_EXIT_CODE;
}
for (int icon_to_cube = 0; icon_to_cube < 2; ++icon_to_cube)
for (int cube_to_icon = 0; cube_to_icon < 2; ++cube_to_icon)
for (int config_from_file = 0; config_from_file < 2; ++config_from_file)
run_model_config(
icon_to_cube, cube_to_icon, config_from_file, argv[1]);
free(field_out_data);
free(field_in_data);
int global_rank;
MPI_Comm_rank(MPI_COMM_WORLD, &global_rank);
if (global_rank == 0) unlink(config_filename);
return TEST_EXIT_CODE;
}
static void generate_icon_grid(
int comm_rank, int comm_size, char const * grid_dir) {
int nbr_vertices;
int nbr_cells;
int * num_vertices_per_cell;
int * cell_to_vertex;
double * x_vertices;
double * y_vertices;
double * x_cells;
double * y_cells;
int * cell_mask;
int * global_cell_id;
int * cell_core_mask;
int * global_corner_id;
int * corner_core_mask;
char const * grid_filename =
strcat(
strcpy(malloc(strlen(grid_dir) + 32), grid_dir),
"icon_grid_0030_R02B03_G.nc");
grid_filename, &nbr_vertices, &nbr_cells, &num_vertices_per_cell,
&cell_to_vertex, &x_vertices, &y_vertices, &x_cells, &y_cells,
&global_cell_id, &cell_mask,
&cell_core_mask, &global_corner_id, &corner_core_mask,
comm_rank, comm_size);
int grid_id;
"icon", nbr_vertices, nbr_cells, num_vertices_per_cell,
x_vertices, y_vertices, cell_to_vertex, &grid_id);
for (int i = 0; i < nbr_cells; ++i) cell_mask[i] = cell_mask[i] == 0;
field_out_data =
xmalloc(nbr_cells *
sizeof(*field_out_data));
field_data_size = nbr_cells;
for (int i = 0; i < nbr_cells; ++i)
field_out_data[i] =
(cell_core_mask[i])?
DUMMY_VALUE;
field_in_data =
xmalloc(nbr_cells *
sizeof(*field_in_data));
&global_cell_id,
&cell_core_mask,
&num_vertices_per_cell,
&global_corner_id,
&corner_core_mask,
&cell_to_vertex,
&x_cells,
&y_cells,
&x_vertices,
&y_vertices);
}
static void generate_cube_grid(int comm_rank, int comm_size) {
unsigned n = 50;
unsigned nbr_vertices;
unsigned nbr_cells;
unsigned * num_vertices_per_cell;
unsigned * cell_to_vertex;
double * x_vertices;
double * y_vertices;
double * x_cells;
double * y_cells;
int * cell_core_mask;
int * corner_core_mask;
int * global_cell_id;
int * global_corner_id;
&num_vertices_per_cell, &cell_to_vertex,
&x_vertices, &y_vertices, &x_cells,
&y_cells, &global_cell_id,
&cell_core_mask, &global_corner_id,
&corner_core_mask, comm_rank, comm_size);
int grid_id;
"cube", nbr_vertices, nbr_cells, (int*)num_vertices_per_cell,
x_vertices, y_vertices, (int*)cell_to_vertex, &grid_id);
field_out_data =
xmalloc(nbr_cells *
sizeof(*field_out_data));
for (unsigned i = 0; i < nbr_cells; ++i)
field_out_data[i] =
(cell_core_mask[i])?
DUMMY_VALUE;
field_in_data =
xmalloc(nbr_cells *
sizeof(*field_in_data));
field_data_size = nbr_cells;
free(cell_core_mask);
free(corner_core_mask);
free(global_cell_id);
free(global_corner_id);
free(x_vertices);
free(y_vertices);
free(x_cells);
free(y_cells);
free(num_vertices_per_cell);
free(cell_to_vertex);
}
int const YAC_YAML_EMITTER_DEFAULT
emit to YAML format
int main(int argc, char **argv)
void yac_generate_part_cube_grid_information(unsigned n, unsigned *nbr_vertices, unsigned *nbr_cells, unsigned **num_vertices_per_cell, unsigned **cell_to_vertex, double **x_vertices, double **y_vertices, double **x_cells, double **y_cells, int **global_cell_id, int **cell_core_mask, int **global_corner_id, int **corner_core_mask, int rank, int size)
void yac_delete_icon_grid_data(int **cell_mask, int **global_cell_id, int **global_cell_id_rank, int **num_vertices_per_cell, int **global_corner_id, int **global_corner_id_rank, int **cell_to_vertex, double **x_cells, double **y_cells, double **x_vertices, double **y_vertices)
void yac_read_part_icon_grid_information(const char *filename, int *nbr_vertices, int *nbr_cells, int **num_vertices_per_cell, int **cell_to_vertex, double **x_vertices, double **y_vertices, double **x_cells, double **y_cells, int **global_cell_id, int **cell_mask, int **cell_core_mask, int **global_corner_id, int **corner_core_mask, int rank, int size)
double yac_test_harmonic(double lon, double lat)
void yac_cenddef_and_emit_config(int emit_flags, char **config)
void yac_cset_global_index(int const *global_index, int location, int grid_id)
void yac_cdef_datetime(const char *start_datetime, const char *end_datetime)
int const YAC_LOCATION_CELL
int const YAC_LOCATION_CORNER
void yac_cget_comp_comm(int comp_id, MPI_Comm *comp_comm)
void yac_cget(int const field_id, int collection_size, double **recv_field, int *info, int *ierr)
int const YAC_TIME_UNIT_SECOND
void yac_cadd_interp_stack_config_conservative(int interp_stack_config_id, int order, int enforced_conserv, int partial_coverage, int normalisation)
void yac_cdef_grid_unstruct(const char *grid_name, int nbr_vertices, int nbr_cells, int *num_vertices_per_cell, double *x_vertices, double *y_vertices, int *cell_to_vertex, int *grid_id)
void yac_cdef_points_unstruct(int const grid_id, int const nbr_points, int const located, double const *x_points, double const *y_points, int *point_id)
void yac_cput(int const field_id, int const collection_size, double ***const send_field, int *info, int *ierr)
void yac_cread_config_yaml(const char *yaml_filename)
void yac_cdef_calendar(int calendar)
void yac_cset_core_mask(int const *is_core, int location, int grid_id)
int const YAC_PROLEPTIC_GREGORIAN
void yac_cset_mask(int const *is_valid, int points_id)
void yac_cfree_interp_stack_config(int interp_stack_config_id)
void yac_cget_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