Skip to content

Commit

Permalink
Generate mpi_f08 bindings and add CFI support
Browse files Browse the repository at this point in the history
This updates fortran/use-mpi-f08 to generate most of the Fortran
bindings from a script and template files. It also adds support for
Fortran TS 29113 when possible, allowing for better Fortran array
handling that matches the standard.

The C files were imported from PR #10302 and converted to templates to
be fed into the binding script.

Co-authored-by: Gilles Gouaillardet <[email protected]>
Co-authored-by: Howard Pritchard <[email protected]>
Signed-off-by: Jake Tronge <[email protected]>
  • Loading branch information
3 people committed Aug 12, 2024
1 parent 1ae5439 commit 569efa1
Show file tree
Hide file tree
Showing 156 changed files with 9,127 additions and 1,336 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,7 @@ ompi/mpi/fortran/mpiext/mpi-ext-module.F90
ompi/mpi/fortran/mpiext/mpi-f08-ext-module.F90
ompi/mpi/fortran/mpiext-use-mpi/mpi-ext-module.F90
ompi/mpi/fortran/mpiext-use-mpi-f08/mpi-f08-ext-module.F90
ompi/mpi/fortran/use-mpi-f08/psizeof_f08.f90

ompi/mpi/fortran/mpif-h/sizeof_f.f90
ompi/mpi/fortran/mpif-h/profile/p*.c
Expand Down
1 change: 0 additions & 1 deletion config/ompi_config_files.m4
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ AC_DEFUN([OMPI_CONFIG_FILES],[
ompi/mpi/fortran/use-mpi-ignore-tkr/mpi-ignore-tkr-file-interfaces.h
ompi/mpi/fortran/use-mpi-ignore-tkr/mpi-ignore-tkr-removed-interfaces.h
ompi/mpi/fortran/use-mpi-f08/Makefile
ompi/mpi/fortran/use-mpi-f08/profile/Makefile
ompi/mpi/fortran/use-mpi-f08/base/Makefile
ompi/mpi/fortran/use-mpi-f08/bindings/Makefile
ompi/mpi/fortran/use-mpi-f08/mod/Makefile
Expand Down
2 changes: 1 addition & 1 deletion ompi/mpi/bindings/ompi_bindings/fortran.py
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@ def print_c_source_header(out):
out.dump('#include "ompi/errhandler/errhandler.h"')
out.dump('#include "ompi/datatype/ompi_datatype.h"')
out.dump('#include "ts.h"')
out.dump('#include "array.h"')
out.dump('#include "bigcount.h"')


def print_binding(prototype, lang, out, bigcount=False, template=None):
Expand Down
22 changes: 14 additions & 8 deletions ompi/mpi/fortran/base/fint_2_int.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,21 +33,22 @@
*/

#if OMPI_SIZEOF_FORTRAN_INTEGER == SIZEOF_INT
#define OMPI_ARRAY_NAME_DECL(a) int *c_##a = NULL
#define OMPI_2_DIM_ARRAY_NAME_DECL(a, dim2) int (*c_##a)[dim2]
#define OMPI_ARRAY_NAME_DECL(a)
#define OMPI_2_DIM_ARRAY_NAME_DECL(a, dim2)
#define OMPI_SINGLE_NAME_DECL(a)
#define OMPI_ARRAY_NAME_CONVERT(a) c_##a
#define OMPI_ARRAY_NAME_CONVERT(a) a
#define OMPI_SINGLE_NAME_CONVERT(a) a
#define OMPI_INT_2_FINT(a) a
#define OMPI_FINT_2_INT(a) a
#define OMPI_PFINT_2_PINT(a) a
#define OMPI_ARRAY_FINT_2_INT_ALLOC(in, n) { OMPI_ARRAY_NAME_CONVERT(in) = in; }
#define OMPI_ARRAY_FINT_2_INT(in, n) { OMPI_ARRAY_NAME_CONVERT(in) = in; }
#define OMPI_2_DIM_ARRAY_FINT_2_INT(in, n, dim2) { OMPI_ARRAY_NAME_CONVERT(in) = in; }
#define OMPI_ARRAY_FINT_2_INT_ALLOC(in, n)
#define OMPI_ARRAY_FINT_2_INT(in, n)
#define OMPI_2_DIM_ARRAY_FINT_2_INT(in, n, dim2)
#define OMPI_ARRAY_FINT_2_INT_CLEANUP(in)
#define OMPI_SINGLE_FINT_2_INT(in)
#define OMPI_SINGLE_INT_2_FINT(in)
#define OMPI_ARRAY_INT_2_FINT(in, n)
#define OMPI_COND_STATEMENT(a)

#elif OMPI_SIZEOF_FORTRAN_INTEGER > SIZEOF_INT
#define OMPI_ARRAY_NAME_DECL(a) int *c_##a = NULL
Expand Down Expand Up @@ -87,7 +88,8 @@

/* This is for IN parameters. Does only free */
#define OMPI_ARRAY_FINT_2_INT_CLEANUP(in) \
free(OMPI_ARRAY_NAME_CONVERT(in))
if (NULL != OMPI_ARRAY_NAME_CONVERT(in)) \
free(OMPI_ARRAY_NAME_CONVERT(in))

/* This is for single IN parameter */
#define OMPI_SINGLE_FINT_2_INT(in) \
Expand All @@ -106,6 +108,8 @@
} \
free(OMPI_ARRAY_NAME_CONVERT(in)); \
} while (0)

#define OMPI_COND_STATEMENT(a) a
#else /* int > MPI_Fint */
#define OMPI_ARRAY_NAME_DECL(a) int *c_##a = NULL
#define OMPI_2_DIM_ARRAY_NAME_DECL(a, dim2) int (*c_##a)[dim2], dim2_index
Expand Down Expand Up @@ -141,7 +145,8 @@
} while (0)

#define OMPI_ARRAY_FINT_2_INT_CLEANUP(in) \
free(OMPI_ARRAY_NAME_CONVERT(in))
if (NULL != OMPI_ARRAY_NAME_CONVERT(in)) \
free(OMPI_ARRAY_NAME_CONVERT(in))

#define OMPI_SINGLE_FINT_2_INT(in) \
OMPI_ARRAY_NAME_CONVERT(in) = *(in)
Expand All @@ -158,6 +163,7 @@
free(OMPI_ARRAY_NAME_CONVERT(in)); \
} while (0)

#define OMPI_COND_STATEMENT(a) a
#endif

/*
Expand Down
3 changes: 3 additions & 0 deletions ompi/mpi/fortran/configure-fortran-output.h.in
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,9 @@
! Line 2 of the ignore TKR syntax
#define OMPI_FORTRAN_IGNORE_TKR_TYPE @OMPI_FORTRAN_IGNORE_TKR_TYPE@
! f08 TKR syntax (w/o TS 29113)
#define OMPI_F08_IGNORE_TKR_PREDECL @OMPI_F08_IGNORE_TKR_PREDECL@
#define OMPI_F08_IGNORE_TKR_TYPE @OMPI_F08_IGNORE_TKR_TYPE@
#define OMPI_FORTRAN_BUILD_SIZEOF @OMPI_FORTRAN_BUILD_SIZEOF@
! Integers
Expand Down
100 changes: 61 additions & 39 deletions ompi/mpi/fortran/use-mpi-f08/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,6 @@
# $HEADER$
#

SUBDIRS = profile

include $(top_srcdir)/Makefile.ompi-rules

# Note that Automake's Fortran-buidling rules uses CPPFLAGS and
Expand All @@ -45,14 +43,14 @@ AM_FCFLAGS = -I$(top_srcdir)/ompi/mpi/fortran/use-mpi-f08/mod \
$(OMPI_FC_MODULE_FLAG)$(top_builddir)/ompi/$(OMPI_FORTRAN_USEMPI_DIR) \
$(OMPI_FC_MODULE_FLAG)mod \
$(OMPI_FC_MODULE_FLAG)bindings \
-I$(top_srcdir) -I$(top_builddir) $(FCFLAGS_f90) \
-DOMPI_BUILD_MPI_PROFILING=0
-I$(top_srcdir) -I$(top_builddir) $(FCFLAGS_f90)

MOSTLYCLEANFILES = *.mod

CLEANFILES += *.i90

lib_LTLIBRARIES = lib@OMPI_LIBMPI_NAME@_usempif08.la
noinst_LTLIBRARIES = lib@OMPI_LIBMPI_NAME@_usempif08_profile.la

module_sentinel_files = \
mod/libforce_usempif08_internal_modules_to_be_built.la \
Expand Down Expand Up @@ -97,9 +95,9 @@ sizeof_f08.f90:
--complex4=$(OMPI_HAVE_FORTRAN_COMPLEX4) \
--complex32=$(OMPI_HAVE_FORTRAN_COMPLEX32)

profile/psizeof_f08.f90: $(top_builddir)/config.status
profile/psizeof_f08.f90: $(sizeof_pl)
profile/psizeof_f08.f90:
psizeof_f08.f90: $(top_builddir)/config.status
psizeof_f08.f90: $(sizeof_pl)
psizeof_f08.f90:
$(OMPI_V_GEN) $(sizeof_pl) \
--impl=$@ --ierror=optional --pmpi \
--maxrank=$(OMPI_FORTRAN_MAX_ARRAY_RANK) \
Expand All @@ -110,34 +108,25 @@ profile/psizeof_f08.f90:
--complex4=$(OMPI_HAVE_FORTRAN_COMPLEX4) \
--complex32=$(OMPI_HAVE_FORTRAN_COMPLEX32)

CLEANFILES += sizeof_f08.h sizeof_f08.f90 profile/psizeof_f08.f90
CLEANFILES += sizeof_f08.h sizeof_f08.f90 psizeof_f08.f90

mpi_api_files = \
abort_f08.F90 \
accumulate_f08.F90 \
add_error_class_f08.F90 \
add_error_code_f08.F90 \
add_error_string_f08.F90 \
aint_add_f08.F90 \
aint_diff_f08.F90 \
allgather_f08.F90 \
allgather_init_f08.F90 \
allgatherv_f08.F90 \
allgatherv_init_f08.F90 \
alloc_mem_f08.F90 \
allreduce_f08.F90 \
allreduce_init_f08.F90 \
alltoall_f08.F90 \
alltoall_init_f08.F90 \
alltoallv_f08.F90 \
alltoallv_init_f08.F90 \
alltoallw_f08.F90 \
alltoallw_init_f08.F90 \
barrier_f08.F90 \
barrier_init_f08.F90 \
bcast_f08.F90 \
bcast_init_f08.F90 \
bsend_f08.F90 \
bsend_init_f08.F90 \
buffer_attach_f08.F90 \
buffer_detach_f08.F90 \
Expand Down Expand Up @@ -255,7 +244,6 @@ mpi_api_files = \
file_write_at_all_end_f08.F90 \
file_write_at_all_f08.F90 \
file_write_at_f08.F90 \
file_write_f08.F90 \
file_write_ordered_begin_f08.F90 \
file_write_ordered_end_f08.F90 \
file_write_ordered_f08.F90 \
Expand Down Expand Up @@ -334,15 +322,13 @@ mpi_api_files = \
intercomm_create_from_groups_f08.F90 \
intercomm_merge_f08.F90 \
iprobe_f08.F90 \
irecv_f08.F90 \
ireduce_f08.F90 \
ireduce_scatter_f08.F90 \
ireduce_scatter_block_f08.F90 \
irsend_f08.F90 \
iscan_f08.F90 \
iscatter_f08.F90 \
iscatterv_f08.F90 \
isend_f08.F90 \
isendrecv_f08.F90 \
isendrecv_replace_f08.F90 \
issend_f08.F90 \
Expand Down Expand Up @@ -380,9 +366,7 @@ mpi_api_files = \
put_f08.F90 \
query_thread_f08.F90 \
raccumulate_f08.F90 \
recv_f08.F90 \
recv_init_f08.F90 \
reduce_f08.F90 \
reduce_init_f08.F90 \
reduce_local_f08.F90 \
reduce_scatter_f08.F90 \
Expand All @@ -403,7 +387,6 @@ mpi_api_files = \
scatter_init_f08.F90 \
scatterv_f08.F90 \
scatterv_init_f08.F90 \
send_f08.F90 \
send_init_f08.F90 \
sendrecv_f08.F90 \
sendrecv_replace_f08.F90 \
Expand All @@ -427,7 +410,6 @@ mpi_api_files = \
status_set_elements_f08.F90 \
status_set_elements_x_f08.F90 \
testall_f08.F90 \
testany_f08.F90 \
test_cancelled_f08.F90 \
test_f08.F90 \
testsome_f08.F90 \
Expand Down Expand Up @@ -468,13 +450,11 @@ mpi_api_files = \
unpack_external_f08.F90 \
unpack_f08.F90 \
unpublish_name_f08.F90 \
waitall_f08.F90 \
waitany_f08.F90 \
wait_f08.F90 \
waitsome_f08.F90 \
win_allocate_f08.F90 \
win_allocate_shared_f08.F90 \
win_attach_f08.F90 \
win_call_errhandler_f08.F90 \
win_complete_f08.F90 \
win_create_dynamic_f08.F90 \
Expand Down Expand Up @@ -508,28 +488,25 @@ mpi_api_files = \
win_test_f08.F90 \
win_unlock_f08.F90 \
win_unlock_all_f08.F90 \
win_wait_f08.F90

# JMS Somehow this variable substitution isn't quite working, and I
# don't have time to figure it out. So just wholesale copy the file
# list. :-(
#pmpi_api_files = $(mpi_api_files:%=profile/p%)
win_wait_f08.F90 \
api_f08_generated.F90

lib@OMPI_LIBMPI_NAME@_usempif08_la_SOURCES = \
$(mpi_api_files) \
mpi-f08.F90

# These are generated; do not ship them
nodist_lib@OMPI_LIBMPI_NAME@_usempif08_la_SOURCES =

if BUILD_FORTRAN_SIZEOF
SIZEOF_H = sizeof_f08.h
nodist_lib@OMPI_LIBMPI_NAME@_usempif08_la_SOURCES += \
nodist_lib@OMPI_LIBMPI_NAME@_usempif08_la_SOURCES = \
sizeof_f08.h \
sizeof_f08.f90 \
profile/psizeof_f08.f90
psizeof_f08.f90
endif

lib@OMPI_LIBMPI_NAME@_usempif08_la_FCFLAGS = \
$(AM_FCFLAGS) \
-DOMPI_BUILD_MPI_PROFILING=0

#
# Include the mpi_f08-based MPI extensions in libmpi_usempif08, too.
#
Expand All @@ -539,13 +516,20 @@ endif
#

lib@OMPI_LIBMPI_NAME@_usempif08_la_LIBADD = \
profile/libmpi_usempif08_pmpi.la \
lib@OMPI_LIBMPI_NAME@_usempif08_profile.la \
$(OMPI_MPIEXT_USEMPIF08_LIBS) \
$(top_builddir)/ompi/mpi/fortran/mpif-h/lib@OMPI_LIBMPI_NAME@_mpifh.la \
$(top_builddir)/ompi/lib@[email protected] \
mod/libusempif08_internal_modules.la \
base/libusempif08_ccode.la
lib@OMPI_LIBMPI_NAME@_usempif08_la_DEPENDENCIES = $(module_sentinel_files)

#
# Make sure to build the profile library before this library, since adding it
# to LIBADD doesn't enforce any ordering
#
lib@OMPI_LIBMPI_NAME@_usempif08_la_DEPENDENCIES = \
$(module_sentinel_files) \
lib@OMPI_LIBMPI_NAME@_usempif08_profile.la
lib@OMPI_LIBMPI_NAME@_usempif08_la_LDFLAGS = -version-info $(libmpi_usempif08_so_version)

#
Expand All @@ -558,6 +542,44 @@ mpi_api_lo_files = $(mpi_api_files:.F90=.lo)
$(mpi_api_lo_files): bindings/libforce_usempif08_internal_bindings_to_be_built.la

mpi-f08.lo: $(module_sentinel_files) $(SIZEOF_H)
mpi-f08.F90: $(SIZEOF_H)

#
# Profiling interface
#

lib@OMPI_LIBMPI_NAME@_usempif08_profile_la_SOURCES = \
$(mpi_api_files)

lib@OMPI_LIBMPI_NAME@_usempif08_profile_la_FCFLAGS = \
$(AM_FCFLAGS) \
-DOMPI_BUILD_MPI_PROFILING=1


#
# Generate the Fortran bindings and C wrapper functions for bindings with a
# *.in template.
#

if OMPI_GENERATE_BINDINGS

include Makefile.prototype_files

api_f08_generated.F90: $(prototype_files)
$(OMPI_V_GEN) $(PYTHON) $(top_srcdir)/ompi/mpi/bindings/bindings.py \
--builddir $(abs_top_builddir) \
--srcdir $(abs_top_srcdir) \
--output $(abs_builddir)/$@ \
fortran \
code \
--lang fortran \
--prototype-files $(ready_prototype_files)

EXTRA_DIST = $(extra_dist_prototype_files)

# Delete generated file on maintainer-clean
MAINTAINERCLEANFILES = api_f08_generated.F90
endif

###########################################################################

Expand Down
Loading

0 comments on commit 569efa1

Please sign in to comment.