Skip to content

Commit 569efa1

Browse files
jtrongeggouaillardethppritcha
committed
Generate mpi_f08 bindings and add CFI support
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]>
1 parent 1ae5439 commit 569efa1

File tree

156 files changed

+9127
-1336
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

156 files changed

+9127
-1336
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -219,6 +219,7 @@ ompi/mpi/fortran/mpiext/mpi-ext-module.F90
219219
ompi/mpi/fortran/mpiext/mpi-f08-ext-module.F90
220220
ompi/mpi/fortran/mpiext-use-mpi/mpi-ext-module.F90
221221
ompi/mpi/fortran/mpiext-use-mpi-f08/mpi-f08-ext-module.F90
222+
ompi/mpi/fortran/use-mpi-f08/psizeof_f08.f90
222223

223224
ompi/mpi/fortran/mpif-h/sizeof_f.f90
224225
ompi/mpi/fortran/mpif-h/profile/p*.c

config/ompi_config_files.m4

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,6 @@ AC_DEFUN([OMPI_CONFIG_FILES],[
4040
ompi/mpi/fortran/use-mpi-ignore-tkr/mpi-ignore-tkr-file-interfaces.h
4141
ompi/mpi/fortran/use-mpi-ignore-tkr/mpi-ignore-tkr-removed-interfaces.h
4242
ompi/mpi/fortran/use-mpi-f08/Makefile
43-
ompi/mpi/fortran/use-mpi-f08/profile/Makefile
4443
ompi/mpi/fortran/use-mpi-f08/base/Makefile
4544
ompi/mpi/fortran/use-mpi-f08/bindings/Makefile
4645
ompi/mpi/fortran/use-mpi-f08/mod/Makefile

ompi/mpi/bindings/ompi_bindings/fortran.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -229,7 +229,7 @@ def print_c_source_header(out):
229229
out.dump('#include "ompi/errhandler/errhandler.h"')
230230
out.dump('#include "ompi/datatype/ompi_datatype.h"')
231231
out.dump('#include "ts.h"')
232-
out.dump('#include "array.h"')
232+
out.dump('#include "bigcount.h"')
233233

234234

235235
def print_binding(prototype, lang, out, bigcount=False, template=None):

ompi/mpi/fortran/base/fint_2_int.h

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -33,21 +33,22 @@
3333
*/
3434

3535
#if OMPI_SIZEOF_FORTRAN_INTEGER == SIZEOF_INT
36-
#define OMPI_ARRAY_NAME_DECL(a) int *c_##a = NULL
37-
#define OMPI_2_DIM_ARRAY_NAME_DECL(a, dim2) int (*c_##a)[dim2]
36+
#define OMPI_ARRAY_NAME_DECL(a)
37+
#define OMPI_2_DIM_ARRAY_NAME_DECL(a, dim2)
3838
#define OMPI_SINGLE_NAME_DECL(a)
39-
#define OMPI_ARRAY_NAME_CONVERT(a) c_##a
39+
#define OMPI_ARRAY_NAME_CONVERT(a) a
4040
#define OMPI_SINGLE_NAME_CONVERT(a) a
4141
#define OMPI_INT_2_FINT(a) a
4242
#define OMPI_FINT_2_INT(a) a
4343
#define OMPI_PFINT_2_PINT(a) a
44-
#define OMPI_ARRAY_FINT_2_INT_ALLOC(in, n) { OMPI_ARRAY_NAME_CONVERT(in) = in; }
45-
#define OMPI_ARRAY_FINT_2_INT(in, n) { OMPI_ARRAY_NAME_CONVERT(in) = in; }
46-
#define OMPI_2_DIM_ARRAY_FINT_2_INT(in, n, dim2) { OMPI_ARRAY_NAME_CONVERT(in) = in; }
44+
#define OMPI_ARRAY_FINT_2_INT_ALLOC(in, n)
45+
#define OMPI_ARRAY_FINT_2_INT(in, n)
46+
#define OMPI_2_DIM_ARRAY_FINT_2_INT(in, n, dim2)
4747
#define OMPI_ARRAY_FINT_2_INT_CLEANUP(in)
4848
#define OMPI_SINGLE_FINT_2_INT(in)
4949
#define OMPI_SINGLE_INT_2_FINT(in)
5050
#define OMPI_ARRAY_INT_2_FINT(in, n)
51+
#define OMPI_COND_STATEMENT(a)
5152

5253
#elif OMPI_SIZEOF_FORTRAN_INTEGER > SIZEOF_INT
5354
#define OMPI_ARRAY_NAME_DECL(a) int *c_##a = NULL
@@ -87,7 +88,8 @@
8788

8889
/* This is for IN parameters. Does only free */
8990
#define OMPI_ARRAY_FINT_2_INT_CLEANUP(in) \
90-
free(OMPI_ARRAY_NAME_CONVERT(in))
91+
if (NULL != OMPI_ARRAY_NAME_CONVERT(in)) \
92+
free(OMPI_ARRAY_NAME_CONVERT(in))
9193

9294
/* This is for single IN parameter */
9395
#define OMPI_SINGLE_FINT_2_INT(in) \
@@ -106,6 +108,8 @@
106108
} \
107109
free(OMPI_ARRAY_NAME_CONVERT(in)); \
108110
} while (0)
111+
112+
#define OMPI_COND_STATEMENT(a) a
109113
#else /* int > MPI_Fint */
110114
#define OMPI_ARRAY_NAME_DECL(a) int *c_##a = NULL
111115
#define OMPI_2_DIM_ARRAY_NAME_DECL(a, dim2) int (*c_##a)[dim2], dim2_index
@@ -141,7 +145,8 @@
141145
} while (0)
142146

143147
#define OMPI_ARRAY_FINT_2_INT_CLEANUP(in) \
144-
free(OMPI_ARRAY_NAME_CONVERT(in))
148+
if (NULL != OMPI_ARRAY_NAME_CONVERT(in)) \
149+
free(OMPI_ARRAY_NAME_CONVERT(in))
145150

146151
#define OMPI_SINGLE_FINT_2_INT(in) \
147152
OMPI_ARRAY_NAME_CONVERT(in) = *(in)
@@ -158,6 +163,7 @@
158163
free(OMPI_ARRAY_NAME_CONVERT(in)); \
159164
} while (0)
160165

166+
#define OMPI_COND_STATEMENT(a) a
161167
#endif
162168

163169
/*

ompi/mpi/fortran/configure-fortran-output.h.in

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,9 @@
4343
! Line 2 of the ignore TKR syntax
4444
#define OMPI_FORTRAN_IGNORE_TKR_TYPE @OMPI_FORTRAN_IGNORE_TKR_TYPE@
4545
46+
! f08 TKR syntax (w/o TS 29113)
47+
#define OMPI_F08_IGNORE_TKR_PREDECL @OMPI_F08_IGNORE_TKR_PREDECL@
48+
#define OMPI_F08_IGNORE_TKR_TYPE @OMPI_F08_IGNORE_TKR_TYPE@
4649
4750
#define OMPI_FORTRAN_BUILD_SIZEOF @OMPI_FORTRAN_BUILD_SIZEOF@
4851
! Integers

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

Lines changed: 61 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,6 @@
2323
# $HEADER$
2424
#
2525

26-
SUBDIRS = profile
27-
2826
include $(top_srcdir)/Makefile.ompi-rules
2927

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

5148
MOSTLYCLEANFILES = *.mod
5249

5350
CLEANFILES += *.i90
5451

5552
lib_LTLIBRARIES = lib@OMPI_LIBMPI_NAME@_usempif08.la
53+
noinst_LTLIBRARIES = lib@OMPI_LIBMPI_NAME@_usempif08_profile.la
5654

5755
module_sentinel_files = \
5856
mod/libforce_usempif08_internal_modules_to_be_built.la \
@@ -97,9 +95,9 @@ sizeof_f08.f90:
9795
--complex4=$(OMPI_HAVE_FORTRAN_COMPLEX4) \
9896
--complex32=$(OMPI_HAVE_FORTRAN_COMPLEX32)
9997

100-
profile/psizeof_f08.f90: $(top_builddir)/config.status
101-
profile/psizeof_f08.f90: $(sizeof_pl)
102-
profile/psizeof_f08.f90:
98+
psizeof_f08.f90: $(top_builddir)/config.status
99+
psizeof_f08.f90: $(sizeof_pl)
100+
psizeof_f08.f90:
103101
$(OMPI_V_GEN) $(sizeof_pl) \
104102
--impl=$@ --ierror=optional --pmpi \
105103
--maxrank=$(OMPI_FORTRAN_MAX_ARRAY_RANK) \
@@ -110,34 +108,25 @@ profile/psizeof_f08.f90:
110108
--complex4=$(OMPI_HAVE_FORTRAN_COMPLEX4) \
111109
--complex32=$(OMPI_HAVE_FORTRAN_COMPLEX32)
112110

113-
CLEANFILES += sizeof_f08.h sizeof_f08.f90 profile/psizeof_f08.f90
111+
CLEANFILES += sizeof_f08.h sizeof_f08.f90 psizeof_f08.f90
114112

115113
mpi_api_files = \
116114
abort_f08.F90 \
117-
accumulate_f08.F90 \
118115
add_error_class_f08.F90 \
119116
add_error_code_f08.F90 \
120117
add_error_string_f08.F90 \
121118
aint_add_f08.F90 \
122119
aint_diff_f08.F90 \
123-
allgather_f08.F90 \
124120
allgather_init_f08.F90 \
125-
allgatherv_f08.F90 \
126121
allgatherv_init_f08.F90 \
127122
alloc_mem_f08.F90 \
128-
allreduce_f08.F90 \
129123
allreduce_init_f08.F90 \
130-
alltoall_f08.F90 \
131124
alltoall_init_f08.F90 \
132-
alltoallv_f08.F90 \
133125
alltoallv_init_f08.F90 \
134-
alltoallw_f08.F90 \
135126
alltoallw_init_f08.F90 \
136127
barrier_f08.F90 \
137128
barrier_init_f08.F90 \
138-
bcast_f08.F90 \
139129
bcast_init_f08.F90 \
140-
bsend_f08.F90 \
141130
bsend_init_f08.F90 \
142131
buffer_attach_f08.F90 \
143132
buffer_detach_f08.F90 \
@@ -255,7 +244,6 @@ mpi_api_files = \
255244
file_write_at_all_end_f08.F90 \
256245
file_write_at_all_f08.F90 \
257246
file_write_at_f08.F90 \
258-
file_write_f08.F90 \
259247
file_write_ordered_begin_f08.F90 \
260248
file_write_ordered_end_f08.F90 \
261249
file_write_ordered_f08.F90 \
@@ -334,15 +322,13 @@ mpi_api_files = \
334322
intercomm_create_from_groups_f08.F90 \
335323
intercomm_merge_f08.F90 \
336324
iprobe_f08.F90 \
337-
irecv_f08.F90 \
338325
ireduce_f08.F90 \
339326
ireduce_scatter_f08.F90 \
340327
ireduce_scatter_block_f08.F90 \
341328
irsend_f08.F90 \
342329
iscan_f08.F90 \
343330
iscatter_f08.F90 \
344331
iscatterv_f08.F90 \
345-
isend_f08.F90 \
346332
isendrecv_f08.F90 \
347333
isendrecv_replace_f08.F90 \
348334
issend_f08.F90 \
@@ -380,9 +366,7 @@ mpi_api_files = \
380366
put_f08.F90 \
381367
query_thread_f08.F90 \
382368
raccumulate_f08.F90 \
383-
recv_f08.F90 \
384369
recv_init_f08.F90 \
385-
reduce_f08.F90 \
386370
reduce_init_f08.F90 \
387371
reduce_local_f08.F90 \
388372
reduce_scatter_f08.F90 \
@@ -403,7 +387,6 @@ mpi_api_files = \
403387
scatter_init_f08.F90 \
404388
scatterv_f08.F90 \
405389
scatterv_init_f08.F90 \
406-
send_f08.F90 \
407390
send_init_f08.F90 \
408391
sendrecv_f08.F90 \
409392
sendrecv_replace_f08.F90 \
@@ -427,7 +410,6 @@ mpi_api_files = \
427410
status_set_elements_f08.F90 \
428411
status_set_elements_x_f08.F90 \
429412
testall_f08.F90 \
430-
testany_f08.F90 \
431413
test_cancelled_f08.F90 \
432414
test_f08.F90 \
433415
testsome_f08.F90 \
@@ -468,13 +450,11 @@ mpi_api_files = \
468450
unpack_external_f08.F90 \
469451
unpack_f08.F90 \
470452
unpublish_name_f08.F90 \
471-
waitall_f08.F90 \
472453
waitany_f08.F90 \
473454
wait_f08.F90 \
474455
waitsome_f08.F90 \
475456
win_allocate_f08.F90 \
476457
win_allocate_shared_f08.F90 \
477-
win_attach_f08.F90 \
478458
win_call_errhandler_f08.F90 \
479459
win_complete_f08.F90 \
480460
win_create_dynamic_f08.F90 \
@@ -508,28 +488,25 @@ mpi_api_files = \
508488
win_test_f08.F90 \
509489
win_unlock_f08.F90 \
510490
win_unlock_all_f08.F90 \
511-
win_wait_f08.F90
512-
513-
# JMS Somehow this variable substitution isn't quite working, and I
514-
# don't have time to figure it out. So just wholesale copy the file
515-
# list. :-(
516-
#pmpi_api_files = $(mpi_api_files:%=profile/p%)
491+
win_wait_f08.F90 \
492+
api_f08_generated.F90
517493

518494
lib@OMPI_LIBMPI_NAME@_usempif08_la_SOURCES = \
519495
$(mpi_api_files) \
520496
mpi-f08.F90
521497

522-
# These are generated; do not ship them
523-
nodist_lib@OMPI_LIBMPI_NAME@_usempif08_la_SOURCES =
524-
525498
if BUILD_FORTRAN_SIZEOF
526499
SIZEOF_H = sizeof_f08.h
527-
nodist_lib@OMPI_LIBMPI_NAME@_usempif08_la_SOURCES += \
500+
nodist_lib@OMPI_LIBMPI_NAME@_usempif08_la_SOURCES = \
528501
sizeof_f08.h \
529502
sizeof_f08.f90 \
530-
profile/psizeof_f08.f90
503+
psizeof_f08.f90
531504
endif
532505

506+
lib@OMPI_LIBMPI_NAME@_usempif08_la_FCFLAGS = \
507+
$(AM_FCFLAGS) \
508+
-DOMPI_BUILD_MPI_PROFILING=0
509+
533510
#
534511
# Include the mpi_f08-based MPI extensions in libmpi_usempif08, too.
535512
#
@@ -539,13 +516,20 @@ endif
539516
#
540517

541518
lib@OMPI_LIBMPI_NAME@_usempif08_la_LIBADD = \
542-
profile/libmpi_usempif08_pmpi.la \
519+
lib@OMPI_LIBMPI_NAME@_usempif08_profile.la \
543520
$(OMPI_MPIEXT_USEMPIF08_LIBS) \
544521
$(top_builddir)/ompi/mpi/fortran/mpif-h/lib@OMPI_LIBMPI_NAME@_mpifh.la \
545522
$(top_builddir)/ompi/lib@[email protected] \
546523
mod/libusempif08_internal_modules.la \
547524
base/libusempif08_ccode.la
548-
lib@OMPI_LIBMPI_NAME@_usempif08_la_DEPENDENCIES = $(module_sentinel_files)
525+
526+
#
527+
# Make sure to build the profile library before this library, since adding it
528+
# to LIBADD doesn't enforce any ordering
529+
#
530+
lib@OMPI_LIBMPI_NAME@_usempif08_la_DEPENDENCIES = \
531+
$(module_sentinel_files) \
532+
lib@OMPI_LIBMPI_NAME@_usempif08_profile.la
549533
lib@OMPI_LIBMPI_NAME@_usempif08_la_LDFLAGS = -version-info $(libmpi_usempif08_so_version)
550534

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

560544
mpi-f08.lo: $(module_sentinel_files) $(SIZEOF_H)
545+
mpi-f08.F90: $(SIZEOF_H)
546+
547+
#
548+
# Profiling interface
549+
#
550+
551+
lib@OMPI_LIBMPI_NAME@_usempif08_profile_la_SOURCES = \
552+
$(mpi_api_files)
553+
554+
lib@OMPI_LIBMPI_NAME@_usempif08_profile_la_FCFLAGS = \
555+
$(AM_FCFLAGS) \
556+
-DOMPI_BUILD_MPI_PROFILING=1
557+
558+
559+
#
560+
# Generate the Fortran bindings and C wrapper functions for bindings with a
561+
# *.in template.
562+
#
563+
564+
if OMPI_GENERATE_BINDINGS
565+
566+
include Makefile.prototype_files
567+
568+
api_f08_generated.F90: $(prototype_files)
569+
$(OMPI_V_GEN) $(PYTHON) $(top_srcdir)/ompi/mpi/bindings/bindings.py \
570+
--builddir $(abs_top_builddir) \
571+
--srcdir $(abs_top_srcdir) \
572+
--output $(abs_builddir)/$@ \
573+
fortran \
574+
code \
575+
--lang fortran \
576+
--prototype-files $(ready_prototype_files)
577+
578+
EXTRA_DIST = $(extra_dist_prototype_files)
579+
580+
# Delete generated file on maintainer-clean
581+
MAINTAINERCLEANFILES = api_f08_generated.F90
582+
endif
561583

562584
###########################################################################
563585

0 commit comments

Comments
 (0)