11#!/usr/bin/env python3
22#
3- # Copyright (c) 2015 Research Organization for Information Science
3+ # Copyright (c) 2015-2025 Research Organization for Information Science
44# and Technology (RIST). All rights reserved.
55# Copyright (c) 2015-2020 Cisco Systems, Inc. All rights reserved.
66# Copyright (c) 2025 Jeffrey M. Squyres. All rights reserved.
2222
2323# Header comment block
2424header_comment = """/*
25- * Copyright (c) 2015 Research Organization for Information Science
25+ * Copyright (c) 2015-2025 Research Organization for Information Science
2626 * and Technology (RIST). All rights reserved.
2727 * Copyright (c) 2015-2020 Cisco Systems, Inc. All rights reserved.
2828 * $COPYRIGHT$
3232"""
3333
3434fortran_header_comment = """!
35- ! Copyright (c) 2015 Research Organization for Information Science
35+ ! Copyright (c) 2015-2025 Research Organization for Information Science
3636! and Technology (RIST). All rights reserved.
3737! Copyright (c) 2015-2020 Cisco Systems, Inc. All rights reserved.
3838! $COPYRIGHT$
4343def get_fortran_constants (args ):
4444 return {
4545 'bottom' : {
46- 'c_type' : "int " ,
46+ 'c_type' : "MPI_Fint " ,
4747 'c_name' : "mpi_fortran_bottom" ,
4848 'f_type' : "integer" ,
4949 'f_name' : "MPI_BOTTOM" ,
5050 },
5151 'in_place' : {
52- 'c_type' : "int " ,
52+ 'c_type' : "MPI_Fint " ,
5353 'c_name' : "mpi_fortran_in_place" ,
5454 'f_type' : "integer" ,
5555 'f_name' : "MPI_IN_PLACE" ,
5656 },
5757 'unweighted' : {
58- 'c_type' : "int " ,
58+ 'c_type' : "MPI_Fint " ,
5959 'c_name' : "mpi_fortran_unweighted" ,
6060 'f_type' : "integer, dimension(1)" ,
6161 'f_name' : "MPI_UNWEIGHTED" ,
6262 },
6363 'weights_empty' : {
64- 'c_type' : "int " ,
64+ 'c_type' : "MPI_Fint " ,
6565 'c_name' : "mpi_fortran_weights_empty" ,
6666 'f_type' : "integer, dimension(1)" ,
6767 'f_name' : "MPI_WEIGHTS_EMPTY" ,
@@ -79,19 +79,21 @@ def get_fortran_constants(args):
7979 'f_name' : "MPI_ARGVS_NULL" ,
8080 },
8181 'errcodes_ignore' : {
82- 'c_type' : "int " ,
82+ 'c_type' : "MPI_Fint " ,
8383 'c_name' : "mpi_fortran_errcodes_ignore" ,
8484 'f_type' : "integer, dimension(1)" ,
8585 'f_name' : "MPI_ERRCODES_IGNORE" ,
8686 },
8787 'status_ignore' : {
88- 'c_type' : "int" ,
88+ 'c_type' : "MPI_Fint" ,
89+ 'c_dim' : f"[{ args .status_size } ]" ,
8990 'c_name' : "mpi_fortran_status_ignore" ,
9091 'f_type' : "type(MPI_STATUS)" ,
9192 'f_name' : "MPI_STATUS_IGNORE" ,
9293 },
9394 'statuses_ignore' : {
94- 'c_type' : "int" ,
95+ 'c_type' : "MPI_Fint" ,
96+ 'c_dim' : f"[{ args .status_size } ]" ,
9597 'c_name' : "mpi_fortran_statuses_ignore" ,
9698 'f_type' : "type(MPI_STATUS)" ,
9799 'f_name' : "MPI_STATUSES_IGNORE(1)" ,
@@ -111,7 +113,7 @@ def mangle(name, mangling_type):
111113 else :
112114 raise ValueError ("Unknown name mangling type" )
113115
114- def gen_c_constants_decl (mangling_type , fortran_constants ):
116+ def gen_c_constants_decl (mangling_type , fortran_constants , args ):
115117 # Generates the mpif-c-constants-decl.h file
116118 with open (file_c_constants_decl , "w" ) as f :
117119 f .write ("/* WARNING: This is a generated file! Edits will be lost! */\n " )
@@ -124,11 +126,12 @@ def gen_c_constants_decl(mangling_type, fortran_constants):
124126 for key in sorted (fortran_constants .keys ()):
125127 const = fortran_constants [key ]
126128 mangled_name = mangle (const ['c_name' ], mangling_type )
127- f .write (f"extern { const ['c_type' ]} { mangled_name } ;\n " )
129+ dim = const .get ('c_dim' , '' )
130+ f .write (f"extern { const ['c_type' ]} { mangled_name } { dim } ;\n " )
128131 f .write (f"#define OMPI_IS_FORTRAN_{ key .upper ()} (addr) \\ \n " )
129132 f .write (f" (addr == (void*) &{ mangled_name } )\n \n " )
130133
131- def gen_c_constants (mangling_type , fortran_constants ):
134+ def gen_c_constants (mangling_type , fortran_constants , args ):
132135 # Generates the mpif-c-constants.h file
133136 with open (file_c_constants , "w" ) as f :
134137 f .write ("/* WARNING: This is a generated file! Edits will be lost! */\n " )
@@ -137,8 +140,10 @@ def gen_c_constants(mangling_type, fortran_constants):
137140
138141 for key in sorted (fortran_constants .keys ()):
139142 const = fortran_constants [key ]
143+ align = f" __opal_attribute_aligned__({ args .align } ) " if args .align else ' '
144+ dim = const .get ('c_dim' , '' )
140145 mangled_name = mangle (const ['c_name' ], mangling_type )
141- f .write (f"{ const ['c_type' ]} { mangled_name } ;\n " )
146+ f .write (f"{ const ['c_type' ]} { align } { mangled_name } { dim } ;\n " )
142147
143148def gen_f08_types (mangling_type , fortran_constants ):
144149 # Generates the mpif-f08-types.h file
@@ -163,6 +168,10 @@ def main():
163168 help = 'Use single underscore suffix mangling' )
164169 parser .add_argument ('--double' , type = int , default = 0 ,
165170 help = 'Use double underscore suffix mangling' )
171+ parser .add_argument ('--status-size' , type = int , default = 0 ,
172+ help = 'Length of the Fortran MPI_Status array' )
173+ parser .add_argument ('--align' , type = int , default = 0 ,
174+ help = 'Alignment of Fortran intengers' )
166175
167176 args = parser .parse_args ()
168177
@@ -190,9 +199,9 @@ def main():
190199
191200 # Generate the files based on the selected mangling type
192201 try :
193- fortran_constants = get_fortran_constants ()
194- gen_c_constants_decl (mangling_type , fortran_constants )
195- gen_c_constants (mangling_type , fortran_constants )
202+ fortran_constants = get_fortran_constants (args )
203+ gen_c_constants_decl (mangling_type , fortran_constants , args )
204+ gen_c_constants (mangling_type , fortran_constants , args )
196205 gen_f08_types (mangling_type , fortran_constants )
197206 print (f"Generated files with '{ mangling_type } ' mangling." )
198207 sys .exit (0 )
0 commit comments