Skip to content

Commit 5f0ef3e

Browse files
committed
Add bigcount APIs for recv and send
1 parent 1c7c37f commit 5f0ef3e

File tree

5 files changed

+70
-28
lines changed

5 files changed

+70
-28
lines changed

ompi/mpi/fortran/use-mpi-f08/Makefile.am

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,9 @@ CLEANFILES += sizeof_f08.h sizeof_f08.f90 psizeof_f08.f90
112112

113113
mpi_api_generated_files = \
114114
send_f08_generated.F90 \
115-
recv_f08_generated.F90
115+
send_f08_c_generated.F90 \
116+
recv_f08_generated.F90 \
117+
recv_f08_c_generated.F90
116118
mpi_api_files = \
117119
abort_f08.F90 \
118120
accumulate_f08.F90 \
@@ -591,6 +593,8 @@ MAINTAINERCLEANFILES =
591593
if OMPI_GENERATE_BINDINGS
592594
%_generated.F90: %.in generate_bindings.py
593595
$(PYTHON) $(srcdir)/generate_bindings.py fortran $< > $@
596+
%_c_generated.F90: %.in generate_bindings.py
597+
$(PYTHON) $(srcdir)/generate_bindings.py fortran $< --bigcount > $@
594598

595599
MAINTAINERCLEANFILES += $(mpi_api_generated_files)
596600
endif

ompi/mpi/fortran/use-mpi-f08/base/Makefile.am

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,11 +33,15 @@ noinst_LTLIBRARIES = libusempif08_ccode.la
3333
libusempif08_ccode_la_SOURCES = \
3434
buffer_detach.c \
3535
send_f08_generated.c \
36-
recv_f08_generated.c
36+
send_f08_c_generated.c \
37+
recv_f08_generated.c \
38+
recv_f08_c_generated.c
3739

3840
if OMPI_GENERATE_BINDINGS
3941
%_generated.c: ../%.in $(srcdir)/../generate_bindings.py
4042
$(PYTHON) $(srcdir)/../generate_bindings.py c $< > $@
43+
%_c_generated.c: ../%.in $(srcdir)/../generate_bindings.py
44+
$(PYTHON) $(srcdir)/../generate_bindings.py c $< --bigcount > $@
4145

4246
MAINTAINERCLEANFILES = send_f08_generated.c
4347
endif

ompi/mpi/fortran/use-mpi-f08/generate_bindings.py

Lines changed: 35 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,9 @@
1616

1717
class FortranType(ABC):
1818

19-
def __init__(self, name, **kwargs):
19+
def __init__(self, name, bigcount=False, **kwargs):
2020
self.name = name
21-
self.bigcount = False
21+
self.bigcount = bigcount
2222

2323
TYPES = {}
2424

@@ -93,6 +93,9 @@ def declare(self):
9393
else:
9494
return f'INTEGER, INTENT(IN) :: {self.name}'
9595

96+
def use(self):
97+
return [('mpi_f08_types', 'MPI_COUNT_KIND')]
98+
9699
def c_parameter(self):
97100
type_ = 'MPI_Count' if self.bigcount else 'MPI_Fint'
98101
return f'{type_} *{self.name}'
@@ -209,20 +212,6 @@ class PrototypeParseError(Exception):
209212
"""Thrown when a parsing error is encountered."""
210213

211214

212-
def fortran_f08_name(base_name):
213-
"""Produce the final f08 name from base_name."""
214-
return f'MPI_{base_name.capitalize()}_f08'
215-
216-
217-
def c_func_name(base_name):
218-
"""Produce the final C func name from base_name."""
219-
return f'ompi_{base_name}_wrapper_f08'
220-
221-
222-
def c_api_func_name(base_name):
223-
"""Produce the actual MPI API function name to call into."""
224-
return f'PMPI_{base_name.capitalize()}'
225-
226215

227216
def print_header():
228217
"""Print the fortran f08 file header."""
@@ -232,7 +221,8 @@ def print_header():
232221

233222
class FortranBinding:
234223

235-
def __init__(self, fname):
224+
def __init__(self, fname, bigcount=False):
225+
self.bigcount = bigcount
236226
with open(fname) as fp:
237227
data = []
238228
for line in fp:
@@ -251,7 +241,26 @@ def __init__(self, fname):
251241
type_, name = param.split()
252242
type_ = FortranType.get(type_)
253243
indent = ' '
254-
self.parameters.append(type_(name))
244+
self.parameters.append(type_(name, bigcount=bigcount))
245+
246+
def _fn_name_suffix(self):
247+
"""Return a suffix for function names."""
248+
return '_c' if self.bigcount else ''
249+
250+
@property
251+
def fortran_f08_name(self):
252+
"""Produce the final f08 name from base_name."""
253+
return f'MPI_{self.fn_name.capitalize()}_f08{self._fn_name_suffix()}'
254+
255+
@property
256+
def c_func_name(self):
257+
"""Produce the final C func name from base_name."""
258+
return f'ompi_{self.fn_name}_wrapper_f08{self._fn_name_suffix()}'
259+
260+
@property
261+
def c_api_func_name(self):
262+
"""Produce the actual MPI API function name to call into."""
263+
return f'PMPI_{self.fn_name.capitalize()}{self._fn_name_suffix()}'
255264

256265
def _param_list(self):
257266
return ','.join(type_.name for type_ in self.parameters)
@@ -277,7 +286,7 @@ def _use_stmts(self):
277286

278287
def _print_fortran_interface(self):
279288
"""Output the C subroutine binding for the Fortran code."""
280-
name = c_func_name(self.fn_name)
289+
name = self.c_func_name
281290
print(' interface')
282291
print(f' subroutine {name}({self._param_list()},ierror) &')
283292
print(f' BIND(C, name="{name}")')
@@ -297,8 +306,8 @@ def print_f_source(self):
297306

298307
print_header()
299308

300-
sub_name = fortran_f08_name(self.fn_name)
301-
c_func = c_func_name(self.fn_name)
309+
sub_name = self.fortran_f08_name
310+
c_func = self.c_func_name
302311
print('subroutine', f'{sub_name}({self._param_list()},ierror)')
303312
# Use statements
304313
use_stmts = self._use_stmts()
@@ -335,7 +344,7 @@ def print_c_source(self):
335344
print('#include "ompi/mpi/fortran/mpif-h/status-conversion.h"')
336345
print('#include "ompi/mpi/fortran/base/constants.h"')
337346
print('#include "ompi/mpi/fortran/base/fint_2_int.h"')
338-
c_func = c_func_name(self.fn_name)
347+
c_func = self.c_func_name
339348
parameters = [param.c_parameter() for param in self.parameters]
340349
# Always append the integer error
341350
parameters.append('MPI_Fint *ierr')
@@ -348,25 +357,25 @@ def print_c_source(self):
348357
for param in self.parameters:
349358
for line in param.c_prepare():
350359
print(f' {line}')
351-
c_api_func = c_api_func_name(self.fn_name)
360+
c_api_func = self.c_api_func_name
352361
arguments = [param.c_argument() for param in self.parameters]
353362
arguments = ', '.join(arguments)
354363
print(f' {C_ERROR_TEMP_NAME} = {c_api_func}({arguments});')
364+
print(f' *ierr = OMPI_INT_2_FINT({C_ERROR_TEMP_NAME});')
355365
for param in self.parameters:
356366
for line in param.c_post():
357367
print(f' {line}')
358-
# TODO: Is this NULL check necessary for mpi_f08?
359-
print(f' if (NULL != ierr) *ierr = OMPI_INT_2_FINT({C_ERROR_TEMP_NAME});')
360368
print('}')
361369

362370

363371
def main():
364372
parser = argparse.ArgumentParser(description='generate fortran binding files')
365373
parser.add_argument('lang', choices=('fortran', 'c'), help='generate dependent files in C or Fortran')
366374
parser.add_argument('template', help='template file to use')
375+
parser.add_argument('--bigcount', action='store_true', help='generate bigcount interface for function')
367376
args = parser.parse_args()
368377

369-
binding = FortranBinding(args.template)
378+
binding = FortranBinding(args.template, bigcount=args.bigcount)
370379
if args.lang == 'fortran':
371380
binding.print_f_source()
372381
else:

ompi/mpi/fortran/use-mpi-f08/mod/mpi-f08-interfaces.h.in

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -300,6 +300,18 @@ subroutine MPI_Recv_f08(buf,count,datatype,source,tag,comm,status,ierror)
300300
TYPE(MPI_Status) :: status
301301
INTEGER, OPTIONAL, INTENT(OUT) :: ierror
302302
end subroutine MPI_Recv_f08
303+
subroutine MPI_Recv_f08_c(buf,count,datatype,source,tag,comm,status,ierror)
304+
use :: mpi_f08_types, only : MPI_Datatype, MPI_Comm, MPI_Status, MPI_COUNT_KIND
305+
implicit none
306+
@OMPI_FORTRAN_IGNORE_TKR_PREDECL@ buf
307+
@OMPI_FORTRAN_IGNORE_TKR_TYPE@ :: buf
308+
INTEGER(KIND=MPI_COUNT_KIND), INTENT(IN) :: count
309+
INTEGER, INTENT(IN) :: source, tag
310+
TYPE(MPI_Datatype), INTENT(IN) :: datatype
311+
TYPE(MPI_Comm), INTENT(IN) :: comm
312+
TYPE(MPI_Status) :: status
313+
INTEGER, OPTIONAL, INTENT(OUT) :: ierror
314+
end subroutine MPI_Recv_f08_c
303315
end interface MPI_Recv
304316

305317
interface MPI_Recv_init
@@ -374,6 +386,17 @@ subroutine MPI_Send_f08(buf,count,datatype,dest,tag,comm,ierror)
374386
TYPE(MPI_Comm), INTENT(IN) :: comm
375387
INTEGER, OPTIONAL, INTENT(OUT) :: ierror
376388
end subroutine MPI_Send_f08
389+
subroutine MPI_Send_f08_c(buf,count,datatype,dest,tag,comm,ierror)
390+
use :: mpi_f08_types, only : MPI_Datatype, MPI_Comm, MPI_COUNT_KIND
391+
implicit none
392+
@OMPI_FORTRAN_IGNORE_TKR_PREDECL@ buf
393+
@OMPI_FORTRAN_IGNORE_TKR_TYPE@, INTENT(IN) :: buf
394+
INTEGER(KIND=MPI_COUNT_KIND), INTENT(IN) :: count
395+
INTEGER, INTENT(IN) :: dest, tag
396+
TYPE(MPI_Datatype), INTENT(IN) :: datatype
397+
TYPE(MPI_Comm), INTENT(IN) :: comm
398+
INTEGER, OPTIONAL, INTENT(OUT) :: ierror
399+
end subroutine MPI_Send_f08_c
377400
end interface MPI_Send
378401

379402
interface MPI_Sendrecv

ompi/mpi/fortran/use-mpi-f08/mod/mpi-f08-rename.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@
4949
#define MPI_Probe_f08 PMPI_Probe_f08
5050
#define MPI_Recv PMPI_Recv
5151
#define MPI_Recv_f08 PMPI_Recv_f08
52+
#define MPI_Recv_f08_c PMPI_Recv_f08_c
5253
#define MPI_Recv_init PMPI_Recv_init
5354
#define MPI_Recv_init_f08 PMPI_Recv_init_f08
5455
#define MPI_Request_free PMPI_Request_free
@@ -61,6 +62,7 @@
6162
#define MPI_Rsend_init_f08 PMPI_Rsend_init_f08
6263
#define MPI_Send PMPI_Send
6364
#define MPI_Send_f08 PMPI_Send_f08
65+
#define MPI_Send_f08_c PMPI_Send_f08_c
6466
#define MPI_Sendrecv PMPI_Sendrecv
6567
#define MPI_Sendrecv_f08 PMPI_Sendrecv_f08
6668
#define MPI_Sendrecv_replace PMPI_Sendrecv_replace

0 commit comments

Comments
 (0)