@@ -2,10 +2,10 @@ C and Fortran Bindings
22======================
33
44The C and Fortran (mpi_f08) bindings are generated from Python code in
5- ``ompi/mpi/bindings ``. The C code is generated based on a template file for
6- each function, with a header and a body containing error-checking and
7- conversion code; the mpi_f08 Fortran bindings are generated from a single
8- file `` ompi/mpi/fortran/use-mpi-f08/interface.in `` .
5+ ``ompi/mpi/bindings ``. Both the language bindings are generated from
6+ template files for each function. In the C case, each template file corresponds
7+ to a single generated C file, while in the Fortran case there are three major
8+ files generated for all functions .
99
1010The Python code depends on special prototype lines used with both the C and
1111Fortran bindings. These "prototypes" are designed to be easy to parse and use
@@ -69,66 +69,32 @@ generated file name must be of the form ``generated_${basename}.c``, where
6969Fortran Bindings
7070----------------
7171
72- To add a new Fortran binding, or update an existing one, one will need to
73- modify the ``ompi/mpi/fortran/use-mpi-f08/interface.json `` file; this JSON file
74- contains a list of prototype objects, including information about their name
75- and each parameter passed. Below is an example for ``MPI_Waitall ``:
72+ Adding new Fortran bindings follows a similar process to the C version above.
73+ All new interfaces are actually based on a single C-template file following the
74+ same format as the C interface templates. However, the C file generated will
75+ use Fortran-specific arguments, including ``CFI_* `` arguments, when TS 29113 is
76+ enabled, ``MPI_Fint * `` arguments in other cases, and others specific to how
77+ the Fortran MPI types are defined. Most of these files perform Fortran-specific
78+ error handling, Fortran-to-C type conversion, and other necessary steps before
79+ calling the actually C bindings with the proper arguments.
7680
77- .. code-block ::
78-
79- {
80- "name": "waitall",
81- "parameters": [
82- {
83- "type": "SHORTCUT_COUNT",
84- "name": "count"
85- },
86- {
87- "type": "REQUEST_ARRAY",
88- "name": "array_of_requests",
89- "dep_params": {
90- "count": "count"
91- }
92- },
93- {
94- "type": "STATUS_ARRAY",
95- "name": "array_of_statuses",
96- "dep_params": {
97- "count": "count"
98- }
99- }
100- ]
101- }
102-
103- This object includes two properties: the ``name `` property holding the
104- subroutine name, converted to lowercase and the ``mpi_ `` prefix removed; and
105- the ``parameters `` property describing all parameters, their types and
106- dependencies. Some parameters may depend on other types and this is listed in
107- the ``dep_params `` field. An example of this can be seen with
108- ``array_of_requests `` above, in which ``dep_params `` holds a key-value pair
109- ``"count": "count" ``, where the key ``count `` corresponds to a key required by
110- the ``REQUEST_ARRAY `` type and the value ``count `` to the name of another
111- parameter. These parameter dependencies are specific to the types used and are
112- validated by the binding scripts.
113-
114- The Fortran binding code not only generates Fortran, but also additional
115- wrapping C code that calls into the C bindings, making conversions and checking
116- for Fortran-specific error conditions as necessary. The following files will be
117- generated by the script:
81+ These templates are used not only to generate a C backing file for the Fortran
82+ code, but also the Fortran interface definitions and the Fortran subroutines
83+ corresponding to the generated C file. These are output in three separate files:
11884
11985* ``ompi/mpi/fortran/use-mpi-f08/api_f08_generated.F90 ``
12086* ``ompi/mpi/fortran/use-mpi-f08/base/api_f08_generated.c ``
121- * ``ompi/mpi/fortran/use-mpi-f08/base/api_f08_ts_generated.c ``
12287* ``ompi/mpi/fortran/use-mpi-f08/mod/mpi-f08-interfaces-generated.h ``
12388
12489The Fortran file ``api_f08_generated.F90 `` contains all the internal subroutine
125- definitions, each of which makes a call into corresponding C functions. Two
126- different C files are generated: ``api_f08_ts_generated.c `` contains support
127- for compilers with TS 29113 support, allowing the use of ``CFI_cdesc_t `` types
128- (see `Fortran 2018 `_ for more details); and ``api_f08_generated.c `` for
129- compilers without TS 29113 support. The internal subroutine names are mapped to
130- the external interface, including multiple interfaces for the bigcount version
131- of functions, in ``mpi-f08-interfaces-generated.h ``.
90+ definitions, each of which makes a call into corresponding C functions. The
91+ internal subroutine names are mapped to the external interface, including
92+ multiple interfaces for the bigcount version of functions, in
93+ ``mpi-f08-interfaces-generated.h ``. The C file ``api_f08_generated.c ``
94+ basically contains a concatenation of all fully expanded C templates.
95+ These files contain preprocessing directives to ensure they can support
96+ compilers with and without TS 29113 support, allowing use of
97+ ``CFI_cdesc_t `` types when available (see `Fortran 2018 `_ for more details).
13298
13399.. _Fortran 2018 : https://fortranwiki.org/fortran/show/Fortran+2018
134100
0 commit comments