Skip to content

Commit 0750fb3

Browse files
committed
use-mpi-ignore: start using binding infrastructure
for new fortran methods starting with MPI_Request_get_status_(any/all/some) plus switch MPI_Request_get_status to use the binding infrastructure as well. Signed-off-by: Howard Pritchard <howardp@lanl.gov>
1 parent 31a0d60 commit 0750fb3

File tree

11 files changed

+537
-224
lines changed

11 files changed

+537
-224
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -539,3 +539,5 @@ ompi/mpi/c/*_generated*.c
539539
ompi/mpi/fortran/use-mpi-f08/*_generated.F90
540540
ompi/mpi/fortran/use-mpi-f08/base/*_generated.c
541541
ompi/mpi/fortran/use-mpi-f08/mod/mpi-f08-interfaces-generated.h
542+
ompi/mpi/fortran/use-mpi-ignore-tkr/mpi-ignore-tkr-interfaces-generated.h
543+
ompi/mpi/fortran/use-mpi-ignore-tkr/*_generated.F90

ompi/mpi/bindings/bindings.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,12 +37,16 @@ def main():
3737
subparsers_fortran = parser_fortran.add_subparsers()
3838
parser_code = subparsers_fortran.add_parser('code', help='generate binding code')
3939
parser_code.set_defaults(handler=lambda args, out: fortran.generate_code(args, out))
40-
parser_code.add_argument('--lang', choices=('fortran', 'c'),
40+
parser_code.add_argument('--lang', choices=('fortran', 'c', 'f90'),
4141
help='language to generate (only for code subparser)')
42+
parser_code.add_argument('--fort-std', choices=('f90', 'f08'),
43+
help='fortran standard to use for fortran module generation')
4244
# Handler for generating the Fortran interface files
4345
parser_interface = subparsers_fortran.add_parser('interface',
4446
help='generate Fortran interface specifications')
4547
parser_interface.set_defaults(handler=lambda args, out: fortran.generate_interface(args, out))
48+
parser_interface.add_argument('--fort-std', choices=('f90', 'f08'),
49+
help='fortran standard to use for fortran module generation')
4650
# The prototype files argument must come last and be specified for both subparsers
4751
for f_subparser in [parser_code, parser_interface]:
4852
f_subparser.add_argument('--prototype-files', nargs='+', help='prototype files to generate code for')

ompi/mpi/bindings/ompi_bindings/fortran.py

Lines changed: 52 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -25,17 +25,19 @@
2525
class FortranBinding:
2626
"""Class for generating the binding for a single function."""
2727

28-
def __init__(self, prototype, out, template=None, bigcount=False, needs_ts=False):
28+
def __init__(self, prototype, out, template=None, bigcount=False, needs_ts=False, gen_f90=False):
2929
# Generate bigcount interface version
3030
self.bigcount = bigcount
3131
self.fn_name = template.prototype.name
3232
self.out = out
3333
self.template = template
3434
self.needs_ts = needs_ts
35+
self.gen_f90 = gen_f90
3536
self.parameters = []
3637
for param in self.template.prototype.params:
3738
self.parameters.append(param.construct(fn_name=self.fn_name,
38-
bigcount=bigcount))
39+
bigcount=bigcount,
40+
gen_f90=gen_f90))
3941

4042
def dump(self, *pargs, **kwargs):
4143
"""Write to the output file."""
@@ -74,6 +76,19 @@ def _use_stmts(self):
7476
stmts.append(f'use :: {mod}, only: {names}')
7577
return stmts
7678

79+
def _include_stmts(self):
80+
"""Return a list of required includes needed."""
81+
includes = []
82+
names = []
83+
for param in self.parameters:
84+
name = param.include()
85+
if name != '':
86+
if name in names:
87+
continue
88+
includes.append(f'include \'{name}\'')
89+
names.append(f'{name}')
90+
return includes
91+
7792
def _print_fortran_interface(self):
7893
"""Output the C subroutine binding for the Fortran code."""
7994
name = self.c_func_name
@@ -92,6 +107,9 @@ def _print_fortran_interface(self):
92107
for stmt in use_stmts:
93108
self.dump(f' {stmt}')
94109
self.dump(' implicit none')
110+
include_stmts = self._include_stmts()
111+
for stmt in include_stmts:
112+
self.dump(f' {stmt}')
95113
for param in self.parameters:
96114
self.dump(f' {param.declare_cbinding_fortran()}')
97115
self.dump(f' INTEGER, INTENT(OUT) :: {consts.FORTRAN_ERROR_NAME}')
@@ -108,17 +126,24 @@ def _print_fortran_header(self, is_interface=False):
108126
for stmt in use_stmts:
109127
self.dump(f' {stmt}')
110128
self.dump(' implicit none')
129+
# Include statements
130+
include_stmts = self._include_stmts()
131+
for stmt in include_stmts:
132+
self.dump(f' {stmt}')
111133
# Parameters/dummy variable declarations
112134
for param in self.parameters:
113135
if is_interface:
114136
self.dump_lines(param.interface_predeclare())
115137
self.dump_lines(param.declare())
116138
# Add the integer error manually
117-
self.dump(f' INTEGER, OPTIONAL, INTENT(OUT) :: {consts.FORTRAN_ERROR_NAME}')
139+
if self.gen_f90 == True:
140+
self.dump(f' INTEGER, INTENT(OUT) :: {consts.FORTRAN_ERROR_NAME}')
141+
else:
142+
self.dump(f' INTEGER, OPTIONAL, INTENT(OUT) :: {consts.FORTRAN_ERROR_NAME}')
118143

119144
def _print_fortran_subroutine(self):
120145
"""Output the Fortran subroutine line."""
121-
sub_name = util.fortran_f08_name(self.fn_name, bigcount=self.bigcount, needs_ts=self.needs_ts)
146+
sub_name = util.fortran_name(self.fn_name, bigcount=self.bigcount, gen_f90=self.gen_f90, needs_ts=self.needs_ts)
122147
params = [param.name for param in self.parameters]
123148
params.append(consts.FORTRAN_ERROR_NAME)
124149
lines = util.break_param_lines_fortran(f'subroutine {sub_name}(', params, ')')
@@ -127,7 +152,7 @@ def _print_fortran_subroutine(self):
127152

128153
def _print_fortran_subroutine_end(self):
129154
"""Output the Fortran end subroutine line."""
130-
sub_name = util.fortran_f08_name(self.fn_name, bigcount=self.bigcount, needs_ts=self.needs_ts)
155+
sub_name = util.fortran_name(self.fn_name, bigcount=self.bigcount, gen_f90=self.gen_f90, needs_ts=self.needs_ts)
131156
self.dump(f'end subroutine {sub_name}')
132157

133158
def dump_lines(self, line_text):
@@ -210,18 +235,20 @@ def print_profiling_rename_macros(templates, out, args):
210235
211236
Previously hardcoded in mpi-f08-rename.h.
212237
"""
238+
gen_f90 = True if args.fort_std == 'f90' else False
213239
out.dump('#if OMPI_BUILD_MPI_PROFILING')
214240
for template in templates:
215241
has_buffers = util.prototype_has_buffers(template.prototype)
216242
needs_ts = has_buffers and args.generate_ts_suffix
217-
name = util.fortran_f08_name(template.prototype.name, needs_ts=needs_ts)
243+
name = util.fortran_name(template.prototype.name, gen_f90=gen_f90, needs_ts=needs_ts)
218244
out.dump(f'#define {name} P{name}')
219245
# Check for bigcount version
220246
if util.prototype_has_bigcount(template.prototype):
221-
bigcount_name = util.fortran_f08_name(template.prototype.name, bigcount=True, needs_ts=needs_ts)
247+
bigcount_name = util.fortran_name(template.prototype.name, bigcount=True, needs_ts=needs_ts)
222248
out.dump(f'#define {bigcount_name} P{bigcount_name}')
223-
name = util.fortran_f08_generic_interface_name(template.prototype.name)
224-
out.dump(f'#define {name} P{name}')
249+
if gen_f90 == False:
250+
name = util.fortran_f08_generic_interface_name(template.prototype.name)
251+
out.dump(f'#define {name} P{name}')
225252
out.dump('#endif /* OMPI_BUILD_MPI_PROFILING */')
226253

227254

@@ -246,9 +273,9 @@ def print_c_source_header(out):
246273
out.dump('#include "bigcount.h"')
247274

248275

249-
def print_binding(prototype, lang, out, bigcount=False, template=None, needs_ts=False):
276+
def print_binding(prototype, lang, out, bigcount=False, template=None, needs_ts=False, gen_f90=False):
250277
"""Print the binding with or without bigcount."""
251-
binding = FortranBinding(prototype, out=out, bigcount=bigcount, template=template, needs_ts=needs_ts)
278+
binding = FortranBinding(prototype, out=out, bigcount=bigcount, template=template, needs_ts=needs_ts, gen_f90=gen_f90)
252279
if lang == 'fortran':
253280
binding.print_f_source()
254281
else:
@@ -267,6 +294,11 @@ def generate_code(args, out):
267294
"""Generate binding code based on arguments."""
268295
templates = load_function_templates(args.prototype_files)
269296

297+
if args.fort_std == 'f08' or args.fort_std == None:
298+
gen_f90 = False
299+
else:
300+
gen_f90 = True
301+
270302
if args.lang == 'fortran':
271303
print_f_source_header(out)
272304
out.dump()
@@ -279,8 +311,8 @@ def generate_code(args, out):
279311
out.dump()
280312
has_buffers = util.prototype_has_buffers(template.prototype)
281313
needs_ts = has_buffers and args.generate_ts_suffix
282-
print_binding(template.prototype, args.lang, out, template=template, needs_ts=needs_ts)
283-
if util.prototype_has_bigcount(template.prototype):
314+
print_binding(template.prototype, args.lang, out, template=template, needs_ts=needs_ts, gen_f90=gen_f90)
315+
if util.prototype_has_bigcount(template.prototype) and gen_f90 == False:
284316
out.dump()
285317
print_binding(template.prototype, args.lang, bigcount=True, out=out, template=template, needs_ts=needs_ts)
286318

@@ -292,14 +324,19 @@ def generate_interface(args, out):
292324
templates = load_function_templates(args.prototype_files)
293325
print_profiling_rename_macros(templates, out, args)
294326

327+
if args.fort_std == 'f08' or args.fort_std == None:
328+
gen_f90 = False
329+
else:
330+
gen_f90 = True
331+
295332
for template in templates:
296333
ext_name = util.ext_api_func_name(template.prototype.name)
297334
out.dump(f'interface {ext_name}')
298335
has_buffers = util.prototype_has_buffers(template.prototype)
299336
needs_ts = has_buffers and args.generate_ts_suffix
300-
binding = FortranBinding(template.prototype, template=template, needs_ts=needs_ts, out=out)
337+
binding = FortranBinding(template.prototype, template=template, needs_ts=needs_ts, gen_f90=gen_f90, out=out)
301338
binding.print_interface()
302-
if util.prototype_has_bigcount(template.prototype):
339+
if util.prototype_has_bigcount(template.prototype) and gen_f90 == False:
303340
out.dump()
304341
binding_c = FortranBinding(template.prototype, out=out, template=template,
305342
needs_ts=needs_ts, bigcount=True)

0 commit comments

Comments
 (0)