1
- # Copyright (c) 2024 Triad National Security, LLC. All rights
1
+ # Copyright (c) 2024-2025 Triad National Security, LLC. All rights
2
2
# reserved.
3
3
#
4
4
# $COPYRIGHT$
25
25
class FortranBinding :
26
26
"""Class for generating the binding for a single function."""
27
27
28
- def __init__ (self , prototype , out , template = None , bigcount = False ):
28
+ def __init__ (self , prototype , out , template = None , bigcount = False , needs_ts = False ):
29
29
# Generate bigcount interface version
30
30
self .bigcount = bigcount
31
31
self .fn_name = template .prototype .name
32
32
self .out = out
33
33
self .template = template
34
+ self .needs_ts = needs_ts
34
35
self .parameters = []
35
36
for param in self .template .prototype .params :
36
37
self .parameters .append (param .construct (fn_name = self .fn_name ,
@@ -117,7 +118,7 @@ def _print_fortran_header(self, is_interface=False):
117
118
118
119
def _print_fortran_subroutine (self ):
119
120
"""Output the Fortran subroutine line."""
120
- sub_name = util .fortran_f08_name (self .fn_name , bigcount = self .bigcount )
121
+ sub_name = util .fortran_f08_name (self .fn_name , bigcount = self .bigcount , needs_ts = self . needs_ts )
121
122
params = [param .name for param in self .parameters ]
122
123
params .append (consts .FORTRAN_ERROR_NAME )
123
124
lines = util .break_param_lines_fortran (f'subroutine { sub_name } (' , params , ')' )
@@ -126,7 +127,7 @@ def _print_fortran_subroutine(self):
126
127
127
128
def _print_fortran_subroutine_end (self ):
128
129
"""Output the Fortran end subroutine line."""
129
- sub_name = util .fortran_f08_name (self .fn_name , bigcount = self .bigcount )
130
+ sub_name = util .fortran_f08_name (self .fn_name , bigcount = self .bigcount , needs_ts = self . needs_ts )
130
131
self .dump (f'end subroutine { sub_name } ' )
131
132
132
133
def dump_lines (self , line_text ):
@@ -197,19 +198,23 @@ def print_f_source_header(out):
197
198
out .dump ('#include "ompi/mpi/fortran/configure-fortran-output.h"' )
198
199
199
200
200
- def print_profiling_rename_macros (templates , out ):
201
+ def print_profiling_rename_macros (templates , out , args ):
201
202
"""Print macros for renaming functions for the profiling interface.
202
203
203
204
Previously hardcoded in mpi-f08-rename.h.
204
205
"""
205
206
out .dump ('#if OMPI_BUILD_MPI_PROFILING' )
206
207
for template in templates :
207
- name = util .fortran_f08_name (template .prototype .name )
208
+ has_buffers = util .prototype_has_buffers (template .prototype )
209
+ needs_ts = has_buffers and args .generate_ts_suffix
210
+ name = util .fortran_f08_name (template .prototype .name , needs_ts = needs_ts )
208
211
out .dump (f'#define { name } P{ name } ' )
209
212
# Check for bigcount version
210
213
if util .prototype_has_bigcount (template .prototype ):
211
- bigcount_name = util .fortran_f08_name (template .prototype .name , bigcount = True )
214
+ bigcount_name = util .fortran_f08_name (template .prototype .name , bigcount = True , needs_ts = needs_ts )
212
215
out .dump (f'#define { bigcount_name } P{ bigcount_name } ' )
216
+ name = util .fortran_f08_generic_interface_name (template .prototype .name )
217
+ out .dump (f'#define { name } P{ name } ' )
213
218
out .dump ('#endif /* OMPI_BUILD_MPI_PROFILING */' )
214
219
215
220
@@ -233,9 +238,9 @@ def print_c_source_header(out):
233
238
out .dump ('#include "bigcount.h"' )
234
239
235
240
236
- def print_binding (prototype , lang , out , bigcount = False , template = None ):
241
+ def print_binding (prototype , lang , out , bigcount = False , template = None , needs_ts = False ):
237
242
"""Print the binding with or without bigcount."""
238
- binding = FortranBinding (prototype , out = out , bigcount = bigcount , template = template )
243
+ binding = FortranBinding (prototype , out = out , bigcount = bigcount , template = template , needs_ts = needs_ts )
239
244
if lang == 'fortran' :
240
245
binding .print_f_source ()
241
246
else :
@@ -257,32 +262,38 @@ def generate_code(args, out):
257
262
if args .lang == 'fortran' :
258
263
print_f_source_header (out )
259
264
out .dump ()
260
- print_profiling_rename_macros (templates , out )
265
+ print_profiling_rename_macros (templates , out , args )
261
266
out .dump ()
262
267
else :
263
268
print_c_source_header (out )
264
269
265
270
for template in templates :
266
271
out .dump ()
267
- print_binding (template .prototype , args .lang , out , template = template )
272
+ has_buffers = util .prototype_has_buffers (template .prototype )
273
+ needs_ts = has_buffers and args .generate_ts_suffix
274
+ print_binding (template .prototype , args .lang , out , template = template , needs_ts = needs_ts )
268
275
if util .prototype_has_bigcount (template .prototype ):
269
276
out .dump ()
270
- print_binding (template .prototype , args .lang , bigcount = True , out = out , template = template )
277
+ print_binding (template .prototype , args .lang , bigcount = True , out = out , template = template , needs_ts = needs_ts )
271
278
272
279
273
280
def generate_interface (args , out ):
274
281
"""Generate the Fortran interface files."""
275
282
out .dump (f'! { consts .GENERATED_MESSAGE } ' )
276
283
277
284
templates = load_function_templates (args .prototype_files )
285
+ print_profiling_rename_macros (templates , out , args )
286
+
278
287
for template in templates :
279
288
ext_name = util .ext_api_func_name (template .prototype .name )
280
289
out .dump (f'interface { ext_name } ' )
281
- binding = FortranBinding (template .prototype , template = template , out = out )
290
+ has_buffers = util .prototype_has_buffers (template .prototype )
291
+ needs_ts = has_buffers and args .generate_ts_suffix
292
+ binding = FortranBinding (template .prototype , template = template , needs_ts = needs_ts , out = out )
282
293
binding .print_interface ()
283
294
if util .prototype_has_bigcount (template .prototype ):
284
295
out .dump ()
285
296
binding_c = FortranBinding (template .prototype , out = out , template = template ,
286
- bigcount = True )
297
+ needs_ts = needs_ts , bigcount = True )
287
298
binding_c .print_interface ()
288
299
out .dump (f'end interface { ext_name } ' )
0 commit comments