1
1
#!/usr/bin/env python3
2
2
#
3
- # Copyright (c) 2015 Research Organization for Information Science
3
+ # Copyright (c) 2015-2025 Research Organization for Information Science
4
4
# and Technology (RIST). All rights reserved.
5
5
# Copyright (c) 2015-2020 Cisco Systems, Inc. All rights reserved.
6
6
# Copyright (c) 2025 Jeffrey M. Squyres. All rights reserved.
22
22
23
23
# Header comment block
24
24
header_comment = """/*
25
- * Copyright (c) 2015 Research Organization for Information Science
25
+ * Copyright (c) 2015-2025 Research Organization for Information Science
26
26
* and Technology (RIST). All rights reserved.
27
27
* Copyright (c) 2015-2020 Cisco Systems, Inc. All rights reserved.
28
28
* $COPYRIGHT$
32
32
"""
33
33
34
34
fortran_header_comment = """!
35
- ! Copyright (c) 2015 Research Organization for Information Science
35
+ ! Copyright (c) 2015-2025 Research Organization for Information Science
36
36
! and Technology (RIST). All rights reserved.
37
37
! Copyright (c) 2015-2020 Cisco Systems, Inc. All rights reserved.
38
38
! $COPYRIGHT$
43
43
def get_fortran_constants (args ):
44
44
return {
45
45
'bottom' : {
46
- 'c_type' : "int " ,
46
+ 'c_type' : "MPI_Fint " ,
47
47
'c_name' : "mpi_fortran_bottom" ,
48
48
'f_type' : "integer" ,
49
49
'f_name' : "MPI_BOTTOM" ,
50
50
},
51
51
'in_place' : {
52
- 'c_type' : "int " ,
52
+ 'c_type' : "MPI_Fint " ,
53
53
'c_name' : "mpi_fortran_in_place" ,
54
54
'f_type' : "integer" ,
55
55
'f_name' : "MPI_IN_PLACE" ,
56
56
},
57
57
'unweighted' : {
58
- 'c_type' : "int " ,
58
+ 'c_type' : "MPI_Fint " ,
59
59
'c_name' : "mpi_fortran_unweighted" ,
60
60
'f_type' : "integer, dimension(1)" ,
61
61
'f_name' : "MPI_UNWEIGHTED" ,
62
62
},
63
63
'weights_empty' : {
64
- 'c_type' : "int " ,
64
+ 'c_type' : "MPI_Fint " ,
65
65
'c_name' : "mpi_fortran_weights_empty" ,
66
66
'f_type' : "integer, dimension(1)" ,
67
67
'f_name' : "MPI_WEIGHTS_EMPTY" ,
@@ -79,19 +79,21 @@ def get_fortran_constants(args):
79
79
'f_name' : "MPI_ARGVS_NULL" ,
80
80
},
81
81
'errcodes_ignore' : {
82
- 'c_type' : "int " ,
82
+ 'c_type' : "MPI_Fint " ,
83
83
'c_name' : "mpi_fortran_errcodes_ignore" ,
84
84
'f_type' : "integer, dimension(1)" ,
85
85
'f_name' : "MPI_ERRCODES_IGNORE" ,
86
86
},
87
87
'status_ignore' : {
88
- 'c_type' : "int" ,
88
+ 'c_type' : "MPI_Fint" ,
89
+ 'c_dim' : f"[{ args .status_size } ]" ,
89
90
'c_name' : "mpi_fortran_status_ignore" ,
90
91
'f_type' : "type(MPI_STATUS)" ,
91
92
'f_name' : "MPI_STATUS_IGNORE" ,
92
93
},
93
94
'statuses_ignore' : {
94
- 'c_type' : "int" ,
95
+ 'c_type' : "MPI_Fint" ,
96
+ 'c_dim' : f"[{ args .status_size } ]" ,
95
97
'c_name' : "mpi_fortran_statuses_ignore" ,
96
98
'f_type' : "type(MPI_STATUS)" ,
97
99
'f_name' : "MPI_STATUSES_IGNORE(1)" ,
@@ -111,7 +113,7 @@ def mangle(name, mangling_type):
111
113
else :
112
114
raise ValueError ("Unknown name mangling type" )
113
115
114
- def gen_c_constants_decl (mangling_type , fortran_constants ):
116
+ def gen_c_constants_decl (mangling_type , fortran_constants , args ):
115
117
# Generates the mpif-c-constants-decl.h file
116
118
with open (file_c_constants_decl , "w" ) as f :
117
119
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):
124
126
for key in sorted (fortran_constants .keys ()):
125
127
const = fortran_constants [key ]
126
128
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 " )
128
131
f .write (f"#define OMPI_IS_FORTRAN_{ key .upper ()} (addr) \\ \n " )
129
132
f .write (f" (addr == (void*) &{ mangled_name } )\n \n " )
130
133
131
- def gen_c_constants (mangling_type , fortran_constants ):
134
+ def gen_c_constants (mangling_type , fortran_constants , args ):
132
135
# Generates the mpif-c-constants.h file
133
136
with open (file_c_constants , "w" ) as f :
134
137
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):
137
140
138
141
for key in sorted (fortran_constants .keys ()):
139
142
const = fortran_constants [key ]
143
+ align = f" __opal_attribute_aligned__({ args .align } ) " if args .align else ' '
144
+ dim = const .get ('c_dim' , '' )
140
145
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 " )
142
147
143
148
def gen_f08_types (mangling_type , fortran_constants ):
144
149
# Generates the mpif-f08-types.h file
@@ -163,6 +168,10 @@ def main():
163
168
help = 'Use single underscore suffix mangling' )
164
169
parser .add_argument ('--double' , type = int , default = 0 ,
165
170
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' )
166
175
167
176
args = parser .parse_args ()
168
177
@@ -190,9 +199,9 @@ def main():
190
199
191
200
# Generate the files based on the selected mangling type
192
201
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 )
196
205
gen_f08_types (mangling_type , fortran_constants )
197
206
print (f"Generated files with '{ mangling_type } ' mangling." )
198
207
sys .exit (0 )
0 commit comments