1 | \newpage |
---|
2 | % |
---|
3 | |
---|
4 | \chapter{Compiling, running and debugging} |
---|
5 | \label{sec_compilationrunning} |
---|
6 | |
---|
7 | \section{Compiling OASIS3-MCT} |
---|
8 | \label{subsec_compile} |
---|
9 | |
---|
10 | OASIS3-MCT is a mixed MPI-OpenMP parallel code. Compiling OASIS3-MCT libraries can be done |
---|
11 | from the {\tt oasis3-MCT/util/make\_dir} directory |
---|
12 | with the makefile {\tt TopMakefileOasis3}. |
---|
13 | {\tt TopMakefileOasis3} includes the header file {\tt make.inc} |
---|
14 | which should then point to (include) your own {\tt make.your\_platform} |
---|
15 | file. That file is specific to the hardware and compiling platform used. |
---|
16 | |
---|
17 | Several header files are distributed with the release and can by used as |
---|
18 | a template to create a custom file for your machine. |
---|
19 | The root of the OASIS3-MCT tree can be anywhere, but it must be defined |
---|
20 | by the variable {\tt COUPLE}. Similarly, the variable {\tt ARCHDIR} defines |
---|
21 | the location of the compilation directory. |
---|
22 | Finally, the OASIS3-MCT library |
---|
23 | should be compiled with the same compilers and system software as any |
---|
24 | coupled models using it. After successful compilation, resulting |
---|
25 | libraries are found in the directory in {\tt \$ARCHDIR/lib} while |
---|
26 | object and module files are found in {\tt \$ARCHDIR/build} and {\tt \$ARCHDIR/build\_shared}. |
---|
27 | |
---|
28 | OASIS3-MCT has historically created static libraries for use in |
---|
29 | Fortran source codes. However, C language bindings are now |
---|
30 | available, and python codes are now fully supported. Therefore, the OASIS3-MCT makefile {\tt TopMakefileOasis3} |
---|
31 | supports compilation of both static and shared libraries. |
---|
32 | |
---|
33 | {\tt TopMakefileOasis3} has several targets including: |
---|
34 | |
---|
35 | \begin{itemize} |
---|
36 | \item {\tt oasis3-psmile =} static-libs-fortran (for backwards compatibility) |
---|
37 | \item {\tt static-libs-fortran =} static oasis libraries for fortran only (default) |
---|
38 | \item {\tt shared-libs-fortran =} shared (dynamic) oasis libraries for fortran only |
---|
39 | \item {\tt static-libs =} static oasis libraries including fortran and c-bindings |
---|
40 | \item {\tt shared-libs =} shared (dynamic) oasis libraries including fortran and c-bindings |
---|
41 | \item {\tt pyoasis =} builds and installs shared-libs plus higher and intermediate python classes |
---|
42 | \item {\tt realclean =} cleans and resets the build |
---|
43 | \end{itemize} |
---|
44 | |
---|
45 | The names of the libraries produced |
---|
46 | are {\it mct}, {\it mpeu}, {\it scrip}, {\it psmile.MPI1}, and {\it oasis.cbind} |
---|
47 | with standard prefixes ({\it lib}) and suffixes ({\it .a} or {\it .so}). |
---|
48 | |
---|
49 | The following targets have been used historically to compile oasis for Fortran |
---|
50 | codes and they are all still supported: |
---|
51 | |
---|
52 | \begin{itemize} |
---|
53 | \item {\tt make -f TopMakefileOasis3 help} |
---|
54 | |
---|
55 | provides a current list of available targets. |
---|
56 | |
---|
57 | \item {\tt make -f TopMakefileOasis3 realclean} |
---|
58 | |
---|
59 | removes all OASIS3-MCT compiled sources and librairies. |
---|
60 | |
---|
61 | \item {\tt make -f TopMakefileOasis3} or |
---|
62 | |
---|
63 | {\tt make -f TopMakefileOasis3 oasis3\_psmile} |
---|
64 | |
---|
65 | compiles static versions of OASIS3-MCT Fortran libraries {\it mct}, {\it mpeu}, |
---|
66 | {\it scrip} and {\it psmile}; |
---|
67 | |
---|
68 | \end{itemize} |
---|
69 | |
---|
70 | Log and error messages from compilation are normally saved in the directory |
---|
71 | {\tt /util/make\_dir} in the files |
---|
72 | {\tt COMP.log} and {\tt COMP.err} or similar. The {\tt TopMakefileOasis3} |
---|
73 | output will direct users to the compile output files. |
---|
74 | |
---|
75 | To interface a component code with OASIS3-MCT and use {\tt mod\_oasis} (see section \ref{subsubsec_Use}), it is required to include OASIS3-MCT modules from {\tt \$ARCHDIR/include} and link with appropriate libraries in {\tt \$ARCHDIR/lib} during the compilation and linking. |
---|
76 | |
---|
77 | Exchange of coupling fields in single and double precision is now supported directly through the interface |
---|
78 | (see section \ref{subsubsec_Declaration}). Single precision fields are converted to double precision fields internally and temporarily. |
---|
79 | For double precision coupling fields, there is no need to promote REAL variables to DOUBLE PRECISION at compilation; this is done automatically within the OASIS3-MCT library. |
---|
80 | |
---|
81 | \section{CPP keys} |
---|
82 | \label{subsec_cpp} |
---|
83 | |
---|
84 | The following OASIS3-MCT CPP keys can be specified in {\tt CPPDEF} in {\tt make.{\it your\_platform}} file: |
---|
85 | \begin{itemize} |
---|
86 | \item {\tt TREAT\_OVERLAY}: ensures, in {\tt SCRIPR/CONSERV} |
---|
87 | remapping (see section \ref{subsec_interp}), that if two cells of |
---|
88 | the source grid overlay and none is masked a priori, the one with the greater numerical |
---|
89 | index will not be considered (they also can be both masked); this is mandatory |
---|
90 | for this remapping. For example, if the grid line with {\it i=1} overlaps |
---|
91 | the grid line with {\it i=imax}, it is the latter that must be masked; |
---|
92 | when this is not the case with the mask defined in {\it masks.nc}, |
---|
93 | this CPP key forces these rules to be respected. |
---|
94 | |
---|
95 | \item {\tt \_\_NO\_16BYTE\_REALS}: {\bf must} be specified if you compile |
---|
96 | with {\bf PGF90}. |
---|
97 | \end{itemize} |
---|
98 | |
---|
99 | %\item {\tt balance}: Add a MPI\_Wtime() function before and after |
---|
100 | % mct\_isend (MPI put) and mct\_recv (MPI get) to calculate the time |
---|
101 | % of the send and receive of a coupling field. This option can be used |
---|
102 | % to produce timestamps in OASIS3-MCT debug files. During a post-processing |
---|
103 | % phase, this information can be used to perform an analysis of the |
---|
104 | % coupled components load (un)balance; specific tools have been |
---|
105 | % developed to do this and will be released with a further version of |
---|
106 | % OASIS3-MCT. {\bf This option is temporarily not recommended as it was observed that |
---|
107 | % it was increasing the simulation time of coupled models on |
---|
108 | % the PRACE computer MareNostrum.} |
---|
109 | |
---|
110 | \section{Running OASIS3-MCT} |
---|
111 | \label{subsec_running} |
---|
112 | |
---|
113 | Examples of running environments are provided with the sources. See also the instructions on OASIS web site at |
---|
114 | {\tt |
---|
115 | https://verc.enes.org/oasis/oasis-dedicated-user-support-1/user-toys} |
---|
116 | for more details. |
---|
117 | |
---|
118 | \subsection{The tutorial toy model} |
---|
119 | \label{subsec_tutorial} |
---|
120 | |
---|
121 | A practical example is provided in {\tt |
---|
122 | oasis3-mct/examples/tutorial} reproducing the coupling between two |
---|
123 | simple codes, model1 and model2, with OASIS3-MCT. |
---|
124 | |
---|
125 | See |
---|
126 | the document {\tt tutorial.pdf} there in and the on-line |
---|
127 | tutorial at \\ |
---|
128 | {\tt |
---|
129 | https://verc.enes.org/oasis/oasis-dedicated-user-support-1/user-toys} |
---|
130 | |
---|
131 | {\tt |
---|
132 | /tutorial-and-test\_interpolation-of-oasis3-mct-1} |
---|
133 | for more details. |
---|
134 | |
---|
135 | \subsection{The test\_1bin\_ocnice toy model} |
---|
136 | \label{subsec_1bin_ocnice} |
---|
137 | |
---|
138 | Another practical example on how to use OASIS3-MCT is provided in \\ {\tt oasis3-mct/examples/test\_1bin\_ocnice}. |
---|
139 | This toy model reproduces the coupling between 5 sub-components within |
---|
140 | the âocniceâ executable. See |
---|
141 | the document {\tt test\_1bin\_ocnice.pdf} there in for more details. |
---|
142 | |
---|
143 | \subsection{The test\_interpolation environment} |
---|
144 | \label{subsec_testinterpolation} |
---|
145 | |
---|
146 | This environment available with the sources in {\tt |
---|
147 | oasis3-mct/examples/test\_interpolation} allows the user to test the |
---|
148 | quality of the interpolations and transformations between his source |
---|
149 | and target grids by calculating the error of interpolation on the |
---|
150 | target grid. For more details, see also the document {\tt test\_interpolation.pdf} there in. |
---|
151 | |
---|
152 | \subsection{The Fortran, C and python equivalent examples} |
---|
153 | \label{subsec_equivalent} |
---|
154 | |
---|
155 | Different examples implementing the different parts of the API with the Fortran, C and python interfaces are provided as practical illustrations in directory {\tt pyoasis/examples} : |
---|
156 | |
---|
157 | \begin{itemize} |
---|
158 | |
---|
159 | \item{{\tt 1-serial}}: one coupling exchange between a serial sender and a serial receiver. |
---|
160 | \item{{\tt 2-apple}}: one coupling exchange between an Apple-parallel sender and a serial receiver; an additonal component, not part of the coupling, is also started and the example shows how to use the {\tt commworld} argument, in Fortran and C, and the communicator optional argument when setting the component in python. |
---|
161 | \item{{\tt 3-box}}: one coupling exchange between an Box-parallel sender and a serial receiver; it shows also how to check if a coupling field declared in the code is activated in the configuration file {\it namcouple}. |
---|
162 | \item{{\tt 4-orange}}: one coupling exchange between an Orange-parallel sender and a serial receiver; not all processes of the sender participate in the coupling and this example shows how to use {\tt create\_couplcomm}. |
---|
163 | \item{{\tt 5-points}}: one coupling exchange between a Point-parallel sender and a serial receiver. |
---|
164 | \item{{\tt 6-apple\_and\_orange}}: one coupling exchange between an Apple-parallel sender and an Orange-parallel receiver; not all processes of the sender participate in the coupling and this example shows how to use {\tt set\_couplcomm}. |
---|
165 | \item{{\tt 7-multiple-puts}}: two coupling fields are both sent from a serial sender to two different serial receivers; this example also sets up an intra communicator between the sender and one receiver and an inter communicator between the sender and the other receiver. |
---|
166 | \item{{\tt 8-interoperability/fortran\_and\_C}}: implements a coupling of a bundle field, with two bundle elements, between a Fortran Apple-parallel sender and a C component. This C component is Orange-parallel for the reception of the bundle field; it also defines another partition of type Box onto which a second coupling field is defined and sent to a third Fortran serial receiver. The sum of the Box partitions in the C component does not cover the global grid, hence the fourth argument {\tt ig\_size} is used to specify the grid global size. The C component also illustrates how the order of the partition definition does not need to be the same for the different processes but that, in that case, a meaningful {\tt name} fifth argument must be used. |
---|
167 | \item{{\tt 8-interoperability/fortran\_and\_python}}: implements the same coupling exchanges than {{\tt 8-interoperability/fortran\_and\_C}} but with the C component replaced by a python component. |
---|
168 | \item{{\tt 9-python\_fortran\_C-multi\_intracomm}}: illustrates the set-up of an intracommunicator between a Fortran, a C and a python components using OASIS3-MCT; a bcast is then realised to share some data. In this example, an additional component is also launched at start but does not participate in the coupling and hence uses the {\tt coupled} third argument of {\tt oasis\_initi\_comp}. |
---|
169 | \item{{\tt 10-grid}}: a single Box-parallel component defines and writes two grids {\tt pyoa} and {\tt mono}, the first one with distributed calls from all the processes, the second one from the master process only. |
---|
170 | \item{{\tt 11-test-interpolation}}: one exchange of a coupling bundle field defined on real grids involving a first-order concervative regridding between an Apple-parallel sender and a serial receiver. In the Fortran and C examples, the grids are fixed, while in the python example, the user chooses the source and target grids interactively, among the ones available in the files available in the {\tt common\_data} directory. This example produces graphical output of the received fields if the following packages are installed |
---|
171 | \begin{itemize} |
---|
172 | \item pip3 install matplotlib |
---|
173 | \item pip3 install scipy |
---|
174 | \item pip3 install cartopy |
---|
175 | \item pip3 uninstall shapely |
---|
176 | \item pip3 install shapely --no-binary shapely |
---|
177 | \end{itemize} |
---|
178 | \item{\tt 12-grid-functions}: Graphical version of {{\tt 10-grid}}, i.e. the {\tt pyoa} grid layout is displayed if the same graphical packages than for {{\tt 11-test-interpolation}} are installed. |
---|
179 | \end{itemize} |
---|
180 | |
---|
181 | \section{Debugging} |
---|
182 | \label{subsec_debug} |
---|
183 | |
---|
184 | \subsection{Debug files} |
---|
185 | If you experience problems while running your coupled model with |
---|
186 | OASIS3-MCT, you can obtain more information on what is happening by |
---|
187 | increasing the {\tt \$NLOGPRT} value in your {\it namcouple}, see section |
---|
188 | \ref{subsec_namcouplefirst} for details. |
---|
189 | |
---|
190 | \subsection{Time statistics files} |
---|
191 | \label{timestat} |
---|
192 | |
---|
193 | The variable TIMER\_Debug, defined in the {\it namcouple} (second |
---|
194 | number on the line below \$NLOGPRT keyword), is used to obtain time |
---|
195 | statistics over all the processors for each routine. |
---|
196 | |
---|
197 | Different output are written (in files named {\tt *.timers\_xxxx}) |
---|
198 | depending on TIMER\_Debug value : |
---|
199 | |
---|
200 | \begin{itemize} |
---|
201 | \item {TIMER\_Debug=0} : nothing is calculated, nothing is written. |
---|
202 | \item {TIMER\_Debug=1} : the times are calculated and written in a |
---|
203 | single file by the process 0 as well as the min and the max times |
---|
204 | over all the processes. |
---|
205 | \item {TIMER\_Debug=2} : the times are calculated and each process |
---|
206 | writes its own file ; process 0 also writes the min and the max |
---|
207 | times over all the processes in its file. |
---|
208 | \item {TIMER\_Debug=3} : the times are calculated and each process |
---|
209 | writes its own file ; process 0 also writes in its file the min |
---|
210 | and the max times over all processes and also writes in its file |
---|
211 | all the results for each process. |
---|
212 | \end{itemize} |
---|
213 | |
---|
214 | Note that TIMER\_Debug can also be set to -1 to activate the {\it lucia} |
---|
215 | tool that can be used to perform an analysis of the coupled components |
---|
216 | load balance. More information can be found in the README file in {\tt |
---|
217 | oasis3-mct/util/lucia} directory and report mentioned therein. |
---|
218 | |
---|
219 | The time given for each timer is calculated by the difference between |
---|
220 | calls to {\tt oasis\_timer\_start()} and {\tt oasis\_timer\_stop()} |
---|
221 | and is the accumulated time over the entire run. Here is an overview |
---|
222 | of the meaning of the different timers as implemented by default. |
---|
223 | \footnote{Many other measures can be obtained by defining the logical |
---|
224 | {\tt local\_timers\_on} as {\tt .true.} in different routines or by |
---|
225 | implementing other timers. Of course, OASIS3\_MCT and the model code then have to be recompiled.} |
---|
226 | |
---|
227 | \begin{itemize} |
---|
228 | |
---|
229 | \item {'total'} : total time of the simulation, implemented |
---|
230 | in {\tt mod\_oasis\_method}, i.e. between the end of {\tt |
---|
231 | oasis\_init\_comp} and the {\tt |
---|
232 | mpi\_finalize} in routine {\tt oasis\_terminate}. |
---|
233 | |
---|
234 | \item {'init\_thru\_enddef'} : time between the end of {\tt |
---|
235 | oasis\_init\_comp} and the end of {\tt oasis\_enddef}, implemented |
---|
236 | in {\tt mod\_oasis\_method}. |
---|
237 | |
---|
238 | \item {'part\_definition'} : time spent in routine {\tt oasis\_def\_partition}. |
---|
239 | |
---|
240 | \item {'oasis\_enddef'} : time spent in |
---|
241 | routine {\tt oasis\_enddef}; this routine performs basically all the |
---|
242 | important steps to initialize the coupling exchanges, e.g. the |
---|
243 | internal management of the partition and variable definition, the |
---|
244 | definition of the patterns of communication between the source and |
---|
245 | target processes, the reading of the remapping weight-and-address |
---|
246 | file and the initialisation of the sparse matrix vector multiplication. |
---|
247 | \item {'grcv\_00x'} : time spent in the reception of field x in {\tt |
---|
248 | mct\_recv} (including communication and possible waiting time |
---|
249 | linked to unbalance of components). |
---|
250 | \item {'wout\_00x'} : time spent in the I/O for field x in routine |
---|
251 | {\tt oasis\_advance\_run}. |
---|
252 | \item {'gcpy\_00x'} : time spent in routine {\tt oasis\_advance\_run} |
---|
253 | in copying the field x just received in a local array. |
---|
254 | \item {'pcpy\_00x'} : time spent in routine {\tt oasis\_advance\_run} |
---|
255 | in copying the local field x in the array to send (i.e. with local |
---|
256 | transformation besides division for averaging). |
---|
257 | \item {'pavg\_00x'} : time spent in routine {\tt oasis\_advance\_run} |
---|
258 | to calculate the average of field x (if done). |
---|
259 | \item {'pmap\_00x'/'gmap\_00x'} : time spent in routine {\tt |
---|
260 | oasis\_advance\_run} for the matrix vector multiplication for |
---|
261 | field x on the source/target processes. |
---|
262 | \item {'psnd\_00x'} : time spent in routine {\tt oasis\_advance\_run} |
---|
263 | for sending field x (i.e. including call to {\tt mct\_waitsend} and |
---|
264 | {\tt mct\_isend}). |
---|
265 | \item {'wtrn\_00x'} : time spent in routine {\tt oasis\_advance\_run} |
---|
266 | to write fields associated with non-instant loctrans operations to |
---|
267 | restart files (see section \ref{subsec_restartdata} for details). |
---|
268 | \item {'wrst\_00x'} : time spent in routine {\tt oasis\_advance\_run} |
---|
269 | to write fields to |
---|
270 | restart files (see section \ref{subsec_restartdata} for details). |
---|
271 | \end{itemize} |
---|
272 | |
---|