YAC 3.13.0
Yet Another Coupler
Loading...
Searching...
No Matches
dynamic_config.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#define VERBOSE
6
7#include <mpi.h>
8#include <stdlib.h>
9#include <stdio.h>
10#include "yac.h"
11
12#define YAC_RAD (0.01745329251994329576923690768489) // M_PI / 180
13
14int main () {
15 // Initialisation of MPI
16
17 MPI_Init (0, NULL);
18
19 /* The initialisation phase */
20#ifdef VERBOSE
21 printf (". main: calling yac_cinit\n");
22#endif
23
24 // start with an empty config
25 yac_cinit ();
27 yac_cdef_datetime("2022-11-11T13:18:00", "2022-11-12T13:18:00");
28
29 int global_rank, global_size;
30 MPI_Comm_rank(MPI_COMM_WORLD,&global_rank);
31 MPI_Comm_size(MPI_COMM_WORLD,&global_size);
32
33 /* Dynamic component definition. */
34
35#ifdef VERBOSE
36 printf (". main: calling yac_cdef_comp\n");
37#endif
38
39 int comp_id;
40 char * comp_name;
41 if(global_rank == 0)
42 comp_name = "ICON-atmosphere";
43 else if(global_rank == 1)
44 comp_name = "ICON-ocean";
45 else if(global_rank == 2)
46 comp_name = "VIZ";
47 else
48 comp_name = "OUTPUT";
49
50 yac_cdef_comp ( comp_name, &comp_id );
51#ifdef VERBOSE
52 printf ( ". main: defined %s with local comp ID %i \n", comp_name, comp_id );
53#endif
54
55 MPI_Comm localcomm;
56 yac_cget_comp_comm(comp_id, &localcomm);
57 int comp_size;
58 MPI_Comm_size(localcomm, &comp_size);
59#ifdef VERBOSE
60 printf ( ". main: component %s has %i processes\n", comp_name, comp_size );
61#endif
62
63 MPI_Comm_free(&localcomm);
64
65 // register grids (for simplicity one grid per comp)
66 int num_vert[2] = {3,3};
67 int cyclic[2] = {0,0};
68 double vertices[3] = {0*YAC_RAD, 1.*YAC_RAD, 2.*YAC_RAD};
69 int grid_id;
70 yac_cdef_grid_reg2d(comp_name, num_vert, cyclic,
71 vertices, vertices, &grid_id);
72
73 int point_id;
75 num_vert,YAC_LOCATION_CORNER, vertices, vertices, &point_id);
76
77 int t_id, t2_id, s_id;
79 "t", comp_id, &point_id, 1, 1, "1", YAC_TIME_UNIT_SECOND, &t_id);
81 "t2", comp_id, &point_id, 1, 1, "1", YAC_TIME_UNIT_SECOND, &t2_id);
82 if(global_rank < 2)
84 "s", comp_id, &point_id, 1, 1, "1", YAC_TIME_UNIT_SECOND, &s_id);
85
86 if(global_rank != 1)
88 printf("synced!\n");
89
90 if(global_rank == 0){
91 int interp_stack_config_id;
92 yac_cget_interp_stack_config(&interp_stack_config_id);
94 interp_stack_config_id, YAC_NNN_AVG, 1, 0.0, 1.);
95 if(global_size > 1){
96 yac_cdef_couple("ICON-atmosphere", "ICON-atmosphere", "t", // source (comp, grid, field)
97 "ICON-ocean", "ICON-ocean", "t", // target (comp, grid, field)
99 interp_stack_config_id, 0, 0);
100 yac_cdef_couple("ICON-atmosphere", "ICON-atmosphere", "t2", // source (comp, grid, field)
101 "ICON-ocean", "ICON-ocean", "t2", // target (comp, grid, field)
103 interp_stack_config_id, 0, 0);
104 yac_cdef_couple("ICON-ocean", "ICON-ocean", "s", // source (comp, grid, field)
105 "ICON-atmosphere", "ICON-atmosphere", "s", // target (comp, grid, field)
107 interp_stack_config_id, 0, 0);
108 yac_cfree_interp_stack_config(interp_stack_config_id);
109 }
110 }else if (global_rank == 2){
111 int interp_stack_config_id;
112 yac_cget_interp_stack_config(&interp_stack_config_id);
114 interp_stack_config_id, YAC_NNN_AVG, 1, 0.0, 1.);
115 yac_cdef_couple("ICON-atmosphere", "ICON-atmosphere", "t", // source (comp, grid, field)
116 "VIZ", "VIZ", "t", // target (comp, grid, field)
118 interp_stack_config_id, 0, 0);
119 if(global_size > 3) // add couple for two other components
120 yac_cdef_couple("ICON-atmosphere", "ICON-atmosphere", "t", // source (comp, grid, field)
121 "OUTPUT", "OUTPUT", "t", // target (comp, grid, field)
123 interp_stack_config_id, 0, 0);
124 yac_cfree_interp_stack_config(interp_stack_config_id);
125 }
126
127 int ierr;
128 yac_cenddef( );
129
130 double * data = malloc(sizeof(double) * num_vert[0]*num_vert[1]);
131 int info;
132 if(global_rank == 0){
133 for(int i = 0; i < num_vert[0]*num_vert[1]; ++i)
134 data[i] = 42.+i;
135 double ** data_ptr = &data;
136 yac_cput(t_id, 1, &data_ptr, &info, &ierr);
137 for(int i = 0; i < num_vert[0]*num_vert[1]; ++i)
138 data[i] = -42.+i;
139 yac_cput(t2_id, 1, &data_ptr, &info, &ierr);
140 }else{
141 yac_cget(t2_id, 1, &data, &info, &ierr);
142 printf("info: %d\nerr: %d\n%f\n", info, ierr, data[2]);
143 yac_cget(t_id, 1, &data, &info, &ierr);
144 printf("info: %d\nerr: %d\n%f\n", info, ierr, data[2]);
145 }
146
148
149 MPI_Finalize();
150
151 return EXIT_SUCCESS;
152}
#define YAC_RAD
double * data
int point_id
unsigned cyclic[2]
int info
int grid_id
int comp_id
int const YAC_REDUCTION_TIME_AVERAGE
Definition yac.c:54
void yac_cenddef(void)
Definition yac.c:4400
void yac_cdef_datetime(const char *start_datetime, const char *end_datetime)
Definition yac.c:761
void yac_csync_def(void)
Definition yac.c:4385
void yac_cinit(void)
Definition yac.c:510
void yac_cfinalize()
Finalises YAC.
Definition yac.c:740
int const YAC_LOCATION_CORNER
Definition yac.c:35
void yac_cget_comp_comm(int comp_id, MPI_Comm *comp_comm)
Definition yac.c:856
void yac_cget(int const field_id, int collection_size, double **recv_field, int *info, int *ierr)
Definition yac.c:2759
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)
Definition yac.c:4831
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)
Definition yac.c:1103
int const YAC_TIME_UNIT_SECOND
Definition yac.c:59
void yac_cput(int const field_id, int const collection_size, double ***const send_field, int *info, int *ierr)
Definition yac.c:3721
void yac_cdef_calendar(int calendar)
Definition yac.c:769
int const YAC_PROLEPTIC_GREGORIAN
Definition yac.c:68
void yac_cfree_interp_stack_config(int interp_stack_config_id)
Definition yac.c:5151
int const YAC_NNN_AVG
Definition yac.c:79
void yac_cadd_interp_stack_config_nnn(int interp_stack_config_id, int type, size_t n, double max_search_distance, double scale)
Definition yac.c:5208
void yac_cget_interp_stack_config(int *interp_stack_config_id)
Definition yac.c:5137
void yac_cdef_comp(char const *comp_name, int *comp_id)
Definition yac.c:1013
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)
Definition yac.c:1396
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)
Definition yac.c:1951