1- # Copyright (c) 2024 Triad National Security, LLC. All rights
1+ # Copyright (c) 2024-2025 Triad National Security, LLC. All rights
22# reserved.
33#
44# $COPYRIGHT$
2525class FortranBinding :
2626 """Class for generating the binding for a single function."""
2727
28- def __init__ (self , prototype , out , template = None , bigcount = False ):
28+ def __init__ (self , prototype , out , template = None , bigcount = False , needs_ts = 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
34+ self .needs_ts = needs_ts
3435 self .parameters = []
3536 for param in self .template .prototype .params :
3637 self .parameters .append (param .construct (fn_name = self .fn_name ,
@@ -117,7 +118,7 @@ def _print_fortran_header(self, is_interface=False):
117118
118119 def _print_fortran_subroutine (self ):
119120 """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 )
121122 params = [param .name for param in self .parameters ]
122123 params .append (consts .FORTRAN_ERROR_NAME )
123124 lines = util .break_param_lines_fortran (f'subroutine { sub_name } (' , params , ')' )
@@ -126,7 +127,7 @@ def _print_fortran_subroutine(self):
126127
127128 def _print_fortran_subroutine_end (self ):
128129 """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 )
130131 self .dump (f'end subroutine { sub_name } ' )
131132
132133 def dump_lines (self , line_text ):
@@ -197,19 +198,23 @@ def print_f_source_header(out):
197198 out .dump ('#include "ompi/mpi/fortran/configure-fortran-output.h"' )
198199
199200
200- def print_profiling_rename_macros (templates , out ):
201+ def print_profiling_rename_macros (templates , out , args ):
201202 """Print macros for renaming functions for the profiling interface.
202203
203204 Previously hardcoded in mpi-f08-rename.h.
204205 """
205206 out .dump ('#if OMPI_BUILD_MPI_PROFILING' )
206207 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 )
208211 out .dump (f'#define { name } P{ name } ' )
209212 # Check for bigcount version
210213 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 )
212215 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 } ' )
213218 out .dump ('#endif /* OMPI_BUILD_MPI_PROFILING */' )
214219
215220
@@ -233,9 +238,9 @@ def print_c_source_header(out):
233238 out .dump ('#include "bigcount.h"' )
234239
235240
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 ):
237242 """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 )
239244 if lang == 'fortran' :
240245 binding .print_f_source ()
241246 else :
@@ -257,32 +262,38 @@ def generate_code(args, out):
257262 if args .lang == 'fortran' :
258263 print_f_source_header (out )
259264 out .dump ()
260- print_profiling_rename_macros (templates , out )
265+ print_profiling_rename_macros (templates , out , args )
261266 out .dump ()
262267 else :
263268 print_c_source_header (out )
264269
265270 for template in templates :
266271 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 )
268275 if util .prototype_has_bigcount (template .prototype ):
269276 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 )
271278
272279
273280def generate_interface (args , out ):
274281 """Generate the Fortran interface files."""
275282 out .dump (f'! { consts .GENERATED_MESSAGE } ' )
276283
277284 templates = load_function_templates (args .prototype_files )
285+ print_profiling_rename_macros (templates , out , args )
286+
278287 for template in templates :
279288 ext_name = util .ext_api_func_name (template .prototype .name )
280289 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 )
282293 binding .print_interface ()
283294 if util .prototype_has_bigcount (template .prototype ):
284295 out .dump ()
285296 binding_c = FortranBinding (template .prototype , out = out , template = template ,
286- bigcount = True )
297+ needs_ts = needs_ts , bigcount = True )
287298 binding_c .print_interface ()
288299 out .dump (f'end interface { ext_name } ' )
0 commit comments