1 | /* pyOASIS - A Python wrapper for OASIS |
---|
2 | Authors: Philippe Gambron, Rupert Ford |
---|
3 | Copyright (C) 2019 UKRI - STFC |
---|
4 | |
---|
5 | This program is free software: you can redistribute it and/or modify |
---|
6 | it under the terms of the GNU Lesser General Public License as |
---|
7 | published by the Free Software Foundation, either version 3 of the |
---|
8 | License, or any later version. |
---|
9 | |
---|
10 | This program is distributed in the hope that it will be useful, |
---|
11 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
---|
13 | GNU Lesser General Public License for more details. |
---|
14 | |
---|
15 | A copy of the GNU Lesser General Public License, version 3, is supplied |
---|
16 | with this program, in the file lgpl-3.0.txt. It is also available at |
---|
17 | <https://www.gnu.org/licenses/lgpl-3.0.html>. */ |
---|
18 | |
---|
19 | |
---|
20 | #ifndef __OASIS_C_ROUTINES_C_H__ |
---|
21 | #define __OASIS_C_ROUTINES_C_H__ |
---|
22 | |
---|
23 | |
---|
24 | #include <stdbool.h> |
---|
25 | #include <mpi.h> |
---|
26 | |
---|
27 | |
---|
28 | #if defined(c_plusplus) || defined(__cplusplus) |
---|
29 | extern "C" { |
---|
30 | #endif |
---|
31 | |
---|
32 | #define OASIS_CHECK_ERR(x) { \ |
---|
33 | int retval = (x); \ |
---|
34 | if (retval != OASIS_Ok) { \ |
---|
35 | fprintf(stderr, "Runtime error: %s returned %d at %s:%d\n", #x, retval, __FILE__, __LINE__); \ |
---|
36 | fflush(stderr); \ |
---|
37 | oasis_c_abort(0, #x, "Runtime error", __FILE__, __LINE__); \ |
---|
38 | } \ |
---|
39 | } |
---|
40 | |
---|
41 | #define OASIS_CHECK_MPI_ERR(x) { \ |
---|
42 | int retval = (x); \ |
---|
43 | if (retval != MPI_SUCCESS) { \ |
---|
44 | fprintf(stderr, "Runtime MPI error: %s returned %d at %s:%d\n", #x, retval, __FILE__, __LINE__); \ |
---|
45 | fflush(stderr); \ |
---|
46 | oasis_c_abort(0, #x, "Runtime MPI error", __FILE__, __LINE__); \ |
---|
47 | } \ |
---|
48 | } |
---|
49 | |
---|
50 | enum mnemonic_params |
---|
51 | { |
---|
52 | OASIS_Real = 4, |
---|
53 | OASIS_REAL = 4, |
---|
54 | OASIS_Double = 8, |
---|
55 | OASIS_DOUBLE = 8, |
---|
56 | OASIS_ROW_MAJOR = 0, |
---|
57 | OASIS_COL_MAJOR = 1, |
---|
58 | OASIS_Out = 20, |
---|
59 | OASIS_OUT = 20, |
---|
60 | OASIS_In = 21, |
---|
61 | OASIS_IN = 21, |
---|
62 | OASIS_Coupled = 1, |
---|
63 | OASIS_COUPLED = 1, |
---|
64 | OASIS_Not_Coupled = 0, |
---|
65 | OASIS_NOT_COUPLED = 0, |
---|
66 | OASIS_Write_Restart = 1, |
---|
67 | OASIS_WRITE_RESTART = 1, |
---|
68 | OASIS_No_Restart = 0, |
---|
69 | OASIS_NO_RESTART = 0, |
---|
70 | OASIS_No_Part = -1, |
---|
71 | OASIS_NO_PART = -1 |
---|
72 | }; |
---|
73 | |
---|
74 | #define OASIS_No_Companion "NULL-STRING" |
---|
75 | |
---|
76 | enum partition_params { |
---|
77 | OASIS_Serial = 0, |
---|
78 | OASIS_Apple = 1, |
---|
79 | OASIS_Box = 2, |
---|
80 | OASIS_Orange = 3, |
---|
81 | OASIS_Points = 4, |
---|
82 | OASIS_Strategy = 0, |
---|
83 | OASIS_Segments = 1, |
---|
84 | OASIS_Npoints = 1, |
---|
85 | OASIS_Offset = 1, |
---|
86 | OASIS_Length = 2, |
---|
87 | OASIS_SizeX = 2, |
---|
88 | OASIS_SizeY = 3, |
---|
89 | OASIS_LdX = 4, |
---|
90 | OASIS_Serial_Params = 3, |
---|
91 | OASIS_Apple_Params = 3, |
---|
92 | OASIS_Box_Params = 5, |
---|
93 | OASIS_No_Gsize = 0 |
---|
94 | }; |
---|
95 | |
---|
96 | #define OASIS_No_Name "" |
---|
97 | #define OASIS_Orange_Params(n_segments) (2 + 2*n_segments) |
---|
98 | #define OASIS_Points_Params(n_points) (2 + n_points) |
---|
99 | |
---|
100 | enum return_codes |
---|
101 | { |
---|
102 | OASIS_Ok = 0, |
---|
103 | OASIS_Success = 0, |
---|
104 | OASIS_Error = -10, |
---|
105 | OASIS_NotDef = -2, |
---|
106 | OASIS_Var_Uncpl = -1, |
---|
107 | OASIS_InOut = 2, |
---|
108 | OASIS_Recvd = 3, |
---|
109 | OASIS_Sent = 4, |
---|
110 | OASIS_LocTrans = 5, |
---|
111 | OASIS_ToRest = 6, |
---|
112 | OASIS_Output = 7, |
---|
113 | OASIS_SentOut = 8, |
---|
114 | OASIS_ToRestOut = 9, |
---|
115 | OASIS_FromRest = 10, |
---|
116 | OASIS_Input = 11, |
---|
117 | OASIS_RecvOut = 12, |
---|
118 | OASIS_FromRestOut = 13, |
---|
119 | OASIS_Waitgroup = 14 |
---|
120 | }; |
---|
121 | |
---|
122 | /* C interfaces with MPI Communicator defined as C MPI_Comm (for C) */ |
---|
123 | |
---|
124 | int oasis_c_get_localcomm(MPI_Comm* localcomm); |
---|
125 | |
---|
126 | int oasis_c_create_couplcomm(const int icpl, const MPI_Comm allcomm, MPI_Comm* cplcomm); |
---|
127 | |
---|
128 | int oasis_c_set_couplcomm(const MPI_Comm localcomm); |
---|
129 | |
---|
130 | int oasis_c_get_intercomm(MPI_Comm* new_comm, char* cdnam); |
---|
131 | |
---|
132 | int oasis_c_get_intracomm(MPI_Comm* new_comm, char* cdnam); |
---|
133 | |
---|
134 | int oasis_c_get_multi_intracomm(MPI_Comm* new_comm, const int cdnam_size, char** cdnam, int* root_ranks); |
---|
135 | |
---|
136 | int oasis_c_set_debug(const int debug); |
---|
137 | |
---|
138 | int oasis_c_get_debug(int* debug); |
---|
139 | |
---|
140 | int oasis_c_put_inquire(int varid, int msec, int *kinfo); |
---|
141 | |
---|
142 | int oasis_c_get_ncpl(const int varid, int* ncpl); |
---|
143 | |
---|
144 | int oasis_c_get_freqs(const int varid, const int mop, const int ncpl, int* cpl_freqs); |
---|
145 | |
---|
146 | int oasis_c_put(const int var_id, const int kstep, const int x_size, const int y_size, const int bundle_size, const int fkind, const int storage, const void* fld1, const bool write_restart, int* kinfo); |
---|
147 | |
---|
148 | int oasis_c_get(const int var_id, const int kstep, const int x_size, const int y_size, const int bundle_size, const int fkind, const int storage, void* fld1, int* kinfo); |
---|
149 | |
---|
150 | int oasis_c_start_grids_writing(); |
---|
151 | |
---|
152 | int oasis_c_write_grid(const char* cgrid, const int nx, const int ny, const int nx_loc, const int ny_loc, const double* lon, const double* lat, const int partid); |
---|
153 | |
---|
154 | int oasis_c_write_corner(const char* cgrid, const int nx, const int ny, const int nc, const int nx_loc, const int ny_loc, const double* clo, const double* cla, const int partid); |
---|
155 | |
---|
156 | int oasis_c_write_mask(const char* cgrid, const int nx, const int ny, const int nx_loc, const int ny_loc, const int* mask, const int partid, const char* companion); |
---|
157 | |
---|
158 | int oasis_c_write_frac(const char* cgrid, const int nx, const int ny, const int nx_loc, const int ny_loc, const double* frac, const int partid, const char* companion); |
---|
159 | |
---|
160 | int oasis_c_write_area(const char* cgrid, const int nx, const int ny, const int nx_loc, const int ny_loc, const double* area, const int partid); |
---|
161 | |
---|
162 | int oasis_c_write_angle(const char* cgrid, const int nx, const int ny, const int nx_loc, const int ny_loc, const double* angle, const int partid); |
---|
163 | |
---|
164 | int oasis_c_terminate_grids_writing(); |
---|
165 | |
---|
166 | int oasis_c_init_comp_with_comm(int* mynummod, const char* cdnam, const bool coupled, const MPI_Comm commworld); |
---|
167 | |
---|
168 | int oasis_c_init_comp(int* mynummod, const char* cdnam, const bool coupled); |
---|
169 | |
---|
170 | int oasis_c_enddef(); |
---|
171 | |
---|
172 | int oasis_c_terminate(); |
---|
173 | |
---|
174 | int oasis_c_def_partition(int* id_part, const int kparal_size, const int* kparal, const int ig_size, const char* name); |
---|
175 | |
---|
176 | int oasis_c_abort(const int id_compid, const char* cd_routine, const char* cd_message, const char* file, const int line); |
---|
177 | |
---|
178 | int oasis_c_def_var(int* id_nports, const char* cdport, const int id_part, const int bundle_size, const int kinout, const int ktype); |
---|
179 | |
---|
180 | #define IS_VALID_PUT(k) ( k == OASIS_Ok) || ( k == OASIS_Output ) || ( k == OASIS_ToRestOut ) || \ |
---|
181 | ( k == OASIS_ToRest ) || ( k == OASIS_SentOut ) || ( k == OASIS_Sent ) || \ |
---|
182 | ( k == OASIS_LocTrans ) || ( k == OASIS_Waitgroup ) |
---|
183 | |
---|
184 | #define IS_VALID_GET(k) ( k == OASIS_Ok) || ( k == OASIS_Input ) || ( k == OASIS_FromRestOut ) || \ |
---|
185 | ( k == OASIS_Recvd ) || ( k == OASIS_RecvOut ) || ( k == OASIS_Output ) |
---|
186 | |
---|
187 | #if defined(c_plusplus) || defined(__cplusplus) |
---|
188 | } |
---|
189 | #endif |
---|
190 | |
---|
191 | |
---|
192 | #endif |
---|