Skip to content

Commit 1c7c37f

Browse files
committed
Add generated version of MPI_Recv_f08
1 parent 903186d commit 1c7c37f

File tree

5 files changed

+62
-48
lines changed

5 files changed

+62
-48
lines changed

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,8 @@ psizeof_f08.f90:
111111
CLEANFILES += sizeof_f08.h sizeof_f08.f90 psizeof_f08.f90
112112

113113
mpi_api_generated_files = \
114-
send_f08_generated.F90
114+
send_f08_generated.F90 \
115+
recv_f08_generated.F90
115116
mpi_api_files = \
116117
abort_f08.F90 \
117118
accumulate_f08.F90 \
@@ -380,7 +381,6 @@ mpi_api_files = \
380381
put_f08.F90 \
381382
query_thread_f08.F90 \
382383
raccumulate_f08.F90 \
383-
recv_f08.F90 \
384384
recv_init_f08.F90 \
385385
reduce_f08.F90 \
386386
reduce_init_f08.F90 \

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,8 @@ noinst_LTLIBRARIES = libusempif08_ccode.la
3232

3333
libusempif08_ccode_la_SOURCES = \
3434
buffer_detach.c \
35-
send_f08_generated.c
35+
send_f08_generated.c \
36+
recv_f08_generated.c
3637

3738
if OMPI_GENERATE_BINDINGS
3839
%_generated.c: ../%.in $(srcdir)/../generate_bindings.py

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

Lines changed: 57 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,19 @@
1+
"""Fortran binding generation code.
2+
3+
This takes as input a *.in file containing the prototype of a Fortran function
4+
with generic types. Both the Fortran subroutine and a wrapping C function can
5+
generated from this file.
6+
"""
17
from abc import ABC, abstractmethod
28
import argparse
39
import re
410

511

12+
C_ERROR_TEMP_NAME = 'c_ierr'
13+
GENERATED_MESSAGE = 'THIS FILE WAS AUTOMATICALLY GENERATED. DO NOT EDIT BY HAND.'
14+
PROTOTYPE_RE = re.compile(r'^\w+\((\s*\w+\s+\w+\s*,?)+\)$')
15+
16+
617
class FortranType(ABC):
718

819
def __init__(self, name, **kwargs):
@@ -56,6 +67,12 @@ def c_post(self):
5667
return []
5768

5869

70+
#
71+
# Definitions of generic types in Fortran and how these can be converted
72+
# to and from C.
73+
#
74+
75+
5976
@FortranType.add('BUFFER')
6077
class BufferType(FortranType):
6178
def declare(self):
@@ -84,11 +101,16 @@ def c_argument(self):
84101
return f'*{self.name}' if self.bigcount else f'OMPI_FINT_2_INT(*{self.name})'
85102

86103

87-
def tmp_c_type(name):
104+
def tmp_c_name(name):
88105
"""Return a temporary name for use in C."""
89106
return f'c_{name}'
90107

91108

109+
def tmp_c_name2(name):
110+
"""Return a secondary temporary name for use in C."""
111+
return f'c_{name}2'
112+
113+
92114
@FortranType.add('DATATYPE')
93115
class DatatypeType(FortranType):
94116
def declare(self):
@@ -107,10 +129,10 @@ def c_parameter(self):
107129
return f'MPI_Fint *{self.name}'
108130

109131
def c_prepare(self):
110-
return [f'MPI_Datatype {tmp_c_type(self.name)} = PMPI_Type_f2c(*{self.name});']
132+
return [f'MPI_Datatype {tmp_c_name(self.name)} = PMPI_Type_f2c(*{self.name});']
111133

112134
def c_argument(self):
113-
return tmp_c_type(self.name)
135+
return tmp_c_name(self.name)
114136

115137

116138
class IntType(FortranType):
@@ -152,13 +174,35 @@ def c_parameter(self):
152174
return f'MPI_Fint *{self.name}'
153175

154176
def c_prepare(self):
155-
return [f'MPI_Comm {tmp_c_type(self.name)} = PMPI_Comm_f2c(*{self.name});']
177+
return [f'MPI_Comm {tmp_c_name(self.name)} = PMPI_Comm_f2c(*{self.name});']
156178

157179
def c_argument(self):
158-
return tmp_c_type(self.name)
180+
return tmp_c_name(self.name)
159181

160182

161-
PROTOTYPE_RE = re.compile(r'^\w+\((\s*\w+\s+\w+\s*,?)+\)$')
183+
@FortranType.add('STATUS')
184+
class StatusType(FortranType):
185+
def declare(self):
186+
return f'TYPE(MPI_Status), INTENT(OUT) :: {self.name}'
187+
188+
def use(self):
189+
return [('mpi_f08_types', 'MPI_Status')]
190+
191+
def c_parameter(self):
192+
# TODO: Is this correct? (I've listed it as TYPE(MPI_Status) in the binding)
193+
return f'MPI_Fint *{self.name}'
194+
195+
def c_prepare(self):
196+
return [
197+
f'OMPI_FORTRAN_STATUS_DECLARATION({tmp_c_name(self.name)}, {tmp_c_name2(self.name)});',
198+
f'OMPI_FORTRAN_STATUS_SET_POINTER({tmp_c_name(self.name)}, {tmp_c_name2(self.name)}, {self.name});'
199+
]
200+
201+
def c_argument(self):
202+
return tmp_c_name(self.name)
203+
204+
def c_post(self):
205+
return [f'OMPI_FORTRAN_STATUS_RETURN({tmp_c_name(self.name)}, {tmp_c_name2(self.name)}, {self.name}, {C_ERROR_TEMP_NAME});']
162206

163207

164208
class PrototypeParseError(Exception):
@@ -186,10 +230,6 @@ def print_header():
186230
print('#include "mpi-f08-rename.h"')
187231

188232

189-
190-
GENERATED_MESSAGE = 'THIS FILE WAS AUTOMATICALLY GENERATED. DO NOT EDIT BY HAND.'
191-
192-
193233
class FortranBinding:
194234

195235
def __init__(self, fname):
@@ -272,7 +312,7 @@ def print_f_source(self):
272312
# Add the integer error manually
273313
print(' INTEGER, OPTIONAL, INTENT(OUT) :: ierror')
274314
# Temporaries
275-
print(' INTEGER :: c_ierror')
315+
print(f' INTEGER :: {C_ERROR_TEMP_NAME}')
276316

277317
# Interface for call to C function
278318
print()
@@ -281,9 +321,9 @@ def print_f_source(self):
281321

282322
# Call into the C function
283323
args = ','.join(param.argument() for param in self.parameters)
284-
print(f' call {c_func}({args},c_ierror)')
324+
print(f' call {c_func}({args},{C_ERROR_TEMP_NAME})')
285325
# Convert error type
286-
print(' if (present(ierror)) ierror = c_ierror')
326+
print(f' if (present(ierror)) ierror = {C_ERROR_TEMP_NAME}')
287327

288328
print(f'end subroutine {sub_name}')
289329

@@ -292,6 +332,7 @@ def print_c_source(self):
292332
print(f'/* {GENERATED_MESSAGE} */')
293333
print('#include "ompi_config.h"')
294334
print('#include "mpi.h"')
335+
print('#include "ompi/mpi/fortran/mpif-h/status-conversion.h"')
295336
print('#include "ompi/mpi/fortran/base/constants.h"')
296337
print('#include "ompi/mpi/fortran/base/fint_2_int.h"')
297338
c_func = c_func_name(self.fn_name)
@@ -303,19 +344,19 @@ def print_c_source(self):
303344
print(f'void {c_func}({parameters});')
304345
print(f'void {c_func}({parameters})')
305346
print('{')
306-
print(' int c_ierr; ')
347+
print(f' int {C_ERROR_TEMP_NAME}; ')
307348
for param in self.parameters:
308349
for line in param.c_prepare():
309350
print(f' {line}')
310351
c_api_func = c_api_func_name(self.fn_name)
311352
arguments = [param.c_argument() for param in self.parameters]
312353
arguments = ', '.join(arguments)
313-
print(f' c_ierr = {c_api_func}({arguments});')
354+
print(f' {C_ERROR_TEMP_NAME} = {c_api_func}({arguments});')
314355
for param in self.parameters:
315356
for line in param.c_post():
316357
print(f' {line}')
317358
# TODO: Is this NULL check necessary for mpi_f08?
318-
print(' if (NULL != ierr) *ierr = OMPI_INT_2_FINT(c_ierr);')
359+
print(f' if (NULL != ierr) *ierr = OMPI_INT_2_FINT({C_ERROR_TEMP_NAME});')
319360
print('}')
320361

321362

ompi/mpi/fortran/use-mpi-f08/recv_f08.F90

Lines changed: 0 additions & 29 deletions
This file was deleted.
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
recv(BUFFER buf, COUNT count, DATATYPE datatype, RANK source, TAG tag, COMM comm, STATUS status)

0 commit comments

Comments
 (0)