Skip to content

Commit

Permalink
Generate interfaces for Fortran and C with bigcount
Browse files Browse the repository at this point in the history
This adds scripts for generating the Fortran and C API bindings from
template files, while also generating bigcount interfaces for those that
require them. The Fortran binding code (for mpi_f08) is designed to
generate both the Fortran subroutines and wrapping C code which calls
into the MPI C api.

Python >=3.6 is required for running these scripts, which is only
necessary when the binding files have not already been generated. Users
of the distribution tarball should not need to generate these files and
thus should not require Python.

Signed-off-by: Jake Tronge <jtronge@lanl.gov>
  • Loading branch information
jtronge committed Jan 11, 2024
1 parent 5fa32f7 commit 37ada30
Show file tree
Hide file tree
Showing 45 changed files with 2,313 additions and 1,028 deletions.
8 changes: 8 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -543,3 +543,11 @@ docs/schizo-ompi-rst-content
# tarballs)
docs/html
docs/man

# Generated C Bindings
ompi/mpi/c/ompi_*.c

# Generated Fortran Bindings
ompi/mpi/fortran/use-mpi-f08/*_generated.F90
ompi/mpi/fortran/use-mpi-f08/base/*_generated.c
ompi/mpi/fortran/use-mpi-f08/generate_bindings.py
2 changes: 1 addition & 1 deletion config/ompi_config_files.m4
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,10 @@ AC_DEFUN([OMPI_CONFIG_FILES],[
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/base/Makefile
ompi/mpi/fortran/use-mpi-f08/profile/Makefile
ompi/mpi/fortran/use-mpi-f08/bindings/Makefile
ompi/mpi/fortran/use-mpi-f08/mod/Makefile
ompi/mpi/fortran/use-mpi-f08/mod/mpi-f08-interfaces.h
ompi/mpi/fortran/use-mpi-f08/generate_bindings.py
ompi/mpi/fortran/mpiext-use-mpi/Makefile
ompi/mpi/fortran/mpiext-use-mpi-f08/Makefile
ompi/mpi/tool/Makefile
Expand Down
7 changes: 7 additions & 0 deletions config/ompi_configure_options.m4
Original file line number Diff line number Diff line change
Expand Up @@ -244,5 +244,12 @@ else
fi
AM_CONDITIONAL(OMPI_OMPIO_SUPPORT, test "$ompi_want_ompio" = "1")

# If the binding source files don't exist, then we need Python to generate them
AM_PATH_PYTHON([3.6],,[:])
binding_file="${srcdir}/ompi/mpi/c/ompi_send.c"
AS_IF([! test -e "$binding_file" && test "$PYTHON" = ":"],
[AC_MSG_ERROR([Open MPI requires Python >=3.6 for generating the bindings. Aborting])])
AM_CONDITIONAL(OMPI_GENERATE_BINDINGS,[test "$PYTHON" != ":"])

])dnl

27 changes: 26 additions & 1 deletion ompi/include/mpi.h.in
Original file line number Diff line number Diff line change
Expand Up @@ -1389,7 +1389,7 @@ OMPI_DECLSPEC extern struct ompi_predefined_datatype_t ompi_mpi_ub;
/*
* MPI API
*/

#ifndef OMPI_NO_MPI_PROTOTYPES
OMPI_DECLSPEC int MPI_Abort(MPI_Comm comm, int errorcode);
OMPI_DECLSPEC int MPI_Accumulate(const void *origin_addr, int origin_count, MPI_Datatype origin_datatype,
int target_rank, MPI_Aint target_disp, int target_count,
Expand Down Expand Up @@ -1419,6 +1419,8 @@ OMPI_DECLSPEC int MPI_Alloc_mem(MPI_Aint size, MPI_Info info,
void *baseptr);
OMPI_DECLSPEC int MPI_Allreduce(const void *sendbuf, void *recvbuf, int count, MPI_Datatype datatype,
MPI_Op op, MPI_Comm comm);
OMPI_DECLSPEC int MPI_Allreduce_c(const void *sendbuf, void *recvbuf, MPI_Count count, MPI_Datatype datatype,
MPI_Op op, MPI_Comm comm);
OMPI_DECLSPEC int MPI_Iallreduce(const void *sendbuf, void *recvbuf, int count, MPI_Datatype datatype,
MPI_Op op, MPI_Comm comm, MPI_Request *request);
OMPI_DECLSPEC int MPI_Allreduce_init(const void *sendbuf, void *recvbuf, int count, MPI_Datatype datatype,
Expand Down Expand Up @@ -1774,10 +1776,14 @@ OMPI_DECLSPEC int MPI_Iprobe(int source, int tag, MPI_Comm comm, int *flag,
MPI_Status *status);
OMPI_DECLSPEC int MPI_Irecv(void *buf, int count, MPI_Datatype datatype, int source,
int tag, MPI_Comm comm, MPI_Request *request);
OMPI_DECLSPEC int MPI_Irecv_c(void *buf, MPI_Count count, MPI_Datatype datatype, int source,
int tag, MPI_Comm comm, MPI_Request *request);
OMPI_DECLSPEC int MPI_Irsend(const void *buf, int count, MPI_Datatype datatype, int dest,
int tag, MPI_Comm comm, MPI_Request *request);
OMPI_DECLSPEC int MPI_Isend(const void *buf, int count, MPI_Datatype datatype, int dest,
int tag, MPI_Comm comm, MPI_Request *request);
OMPI_DECLSPEC int MPI_Isend_c(const void *buf, MPI_Count count, MPI_Datatype datatype, int dest,
int tag, MPI_Comm comm, MPI_Request *request);
OMPI_DECLSPEC int MPI_Isendrecv(const void *sendbuf, int sendcount, MPI_Datatype sendtype,
int dest, int sendtag, void *recvbuf, int recvcount,
MPI_Datatype recvtype, int source, int recvtag,
Expand Down Expand Up @@ -1882,6 +1888,8 @@ OMPI_DECLSPEC int MPI_Recv_init(void *buf, int count, MPI_Datatype datatype, in
int tag, MPI_Comm comm, MPI_Request *request);
OMPI_DECLSPEC int MPI_Recv(void *buf, int count, MPI_Datatype datatype, int source,
int tag, MPI_Comm comm, MPI_Status *status);
OMPI_DECLSPEC int MPI_Recv_c(void *buf, MPI_Count count, MPI_Datatype datatype, int source,
int tag, MPI_Comm comm, MPI_Status *status);
OMPI_DECLSPEC int MPI_Reduce(const void *sendbuf, void *recvbuf, int count, MPI_Datatype datatype,
MPI_Op op, int root, MPI_Comm comm);
OMPI_DECLSPEC int MPI_Ireduce(const void *sendbuf, void *recvbuf, int count, MPI_Datatype datatype,
Expand Down Expand Up @@ -1957,6 +1965,8 @@ OMPI_DECLSPEC int MPI_Send_init(const void *buf, int count, MPI_Datatype dataty
MPI_Request *request);
OMPI_DECLSPEC int MPI_Send(const void *buf, int count, MPI_Datatype datatype, int dest,
int tag, MPI_Comm comm);
OMPI_DECLSPEC int MPI_Send_c(const void *buf, MPI_Count count, MPI_Datatype datatype, int dest,
int tag, MPI_Comm comm);
OMPI_DECLSPEC int MPI_Sendrecv(const void *sendbuf, int sendcount, MPI_Datatype sendtype,
int dest, int sendtag, void *recvbuf, int recvcount,
MPI_Datatype recvtype, int source, int recvtag,
Expand Down Expand Up @@ -2153,6 +2163,9 @@ OMPI_DECLSPEC int PMPI_Abort(MPI_Comm comm, int errorcode);
OMPI_DECLSPEC int PMPI_Accumulate(const void *origin_addr, int origin_count, MPI_Datatype origin_datatype,
int target_rank, MPI_Aint target_disp, int target_count,
MPI_Datatype target_datatype, MPI_Op op, MPI_Win win);
OMPI_DECLSPEC int PMPI_Accumulate_c(const void *origin_addr, MPI_Count origin_count, MPI_Datatype origin_datatype,
int target_rank, MPI_Aint target_disp, MPI_Count target_count,
MPI_Datatype target_datatype, MPI_Op op, MPI_Win win);
OMPI_DECLSPEC int PMPI_Add_error_class(int *errorclass);
OMPI_DECLSPEC int PMPI_Add_error_code(int errorclass, int *errorcode);
OMPI_DECLSPEC int PMPI_Add_error_string(int errorcode, const char *string);
Expand All @@ -2178,6 +2191,8 @@ OMPI_DECLSPEC int PMPI_Alloc_mem(MPI_Aint size, MPI_Info info,
void *baseptr);
OMPI_DECLSPEC int PMPI_Allreduce(const void *sendbuf, void *recvbuf, int count,
MPI_Datatype datatype, MPI_Op op, MPI_Comm comm);
OMPI_DECLSPEC int PMPI_Allreduce_c(const void *sendbuf, void *recvbuf, MPI_Count count,
MPI_Datatype datatype, MPI_Op op, MPI_Comm comm);
OMPI_DECLSPEC int PMPI_Iallreduce(const void *sendbuf, void *recvbuf, int count, MPI_Datatype datatype,
MPI_Op op, MPI_Comm comm, MPI_Request *request);
OMPI_DECLSPEC int PMPI_Allreduce_init(const void *sendbuf, void *recvbuf, int count, MPI_Datatype datatype,
Expand Down Expand Up @@ -2535,10 +2550,14 @@ OMPI_DECLSPEC int PMPI_Iprobe(int source, int tag, MPI_Comm comm, int *flag,
MPI_Status *status);
OMPI_DECLSPEC int PMPI_Irecv(void *buf, int count, MPI_Datatype datatype, int source,
int tag, MPI_Comm comm, MPI_Request *request);
OMPI_DECLSPEC int PMPI_Irecv_c(void *buf, MPI_Count count, MPI_Datatype datatype, int source,
int tag, MPI_Comm comm, MPI_Request *request);
OMPI_DECLSPEC int PMPI_Irsend(const void *buf, int count, MPI_Datatype datatype, int dest,
int tag, MPI_Comm comm, MPI_Request *request);
OMPI_DECLSPEC int PMPI_Isend(const void *buf, int count, MPI_Datatype datatype, int dest,
int tag, MPI_Comm comm, MPI_Request *request);
OMPI_DECLSPEC int PMPI_Isend_c(const void *buf, MPI_Count count, MPI_Datatype datatype, int dest,
int tag, MPI_Comm comm, MPI_Request *request);
OMPI_DECLSPEC int PMPI_Isendrecv(const void *sendbuf, int sendcount, MPI_Datatype sendtype,
int dest, int sendtag, void *recvbuf, int recvcount,
MPI_Datatype recvtype, int source, int recvtag,
Expand Down Expand Up @@ -2643,6 +2662,8 @@ OMPI_DECLSPEC int PMPI_Recv_init(void *buf, int count, MPI_Datatype datatype, i
int tag, MPI_Comm comm, MPI_Request *request);
OMPI_DECLSPEC int PMPI_Recv(void *buf, int count, MPI_Datatype datatype, int source,
int tag, MPI_Comm comm, MPI_Status *status);
OMPI_DECLSPEC int PMPI_Recv_c(void *buf, MPI_Count count, MPI_Datatype datatype, int source,
int tag, MPI_Comm comm, MPI_Status *status);
OMPI_DECLSPEC int PMPI_Reduce(const void *sendbuf, void *recvbuf, int count, MPI_Datatype datatype,
MPI_Op op, int root, MPI_Comm comm);
OMPI_DECLSPEC int PMPI_Ireduce(const void *sendbuf, void *recvbuf, int count, MPI_Datatype datatype,
Expand Down Expand Up @@ -2718,6 +2739,8 @@ OMPI_DECLSPEC int PMPI_Send_init(const void *buf, int count, MPI_Datatype datat
MPI_Request *request);
OMPI_DECLSPEC int PMPI_Send(const void *buf, int count, MPI_Datatype datatype, int dest,
int tag, MPI_Comm comm);
OMPI_DECLSPEC int PMPI_Send_c(const void *buf, MPI_Count count, MPI_Datatype datatype, int dest,
int tag, MPI_Comm comm);
OMPI_DECLSPEC int PMPI_Sendrecv(const void *sendbuf, int sendcount, MPI_Datatype sendtype,
int dest, int sendtag, void *recvbuf, int recvcount,
MPI_Datatype recvtype, int source, int recvtag,
Expand Down Expand Up @@ -3176,6 +3199,8 @@ OMPI_DECLSPEC int PMPI_Type_ub(MPI_Datatype mtype, MPI_Aint *ub)
#define MPI_Type_ub(...) THIS_FUNCTION_WAS_REMOVED_IN_MPI30(MPI_Type_ub, MPI_Type_get_extent)
#endif

#endif /* OMPI_NO_MPI_PROTOTYPES */

#if defined(c_plusplus) || defined(__cplusplus)
}
#endif
Expand Down
87 changes: 63 additions & 24 deletions ompi/mpi/c/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,36 @@ endif

headers = bindings.h

prototype_sources = \
abort.c.in \
send.c.in \
isend.c.in \
recv.c.in \
irecv.c.in \
waitsome.c.in \
accumulate.c.in \
comm_f2c.c.in \
wtime.c.in \
file_open.c.in \
init.c.in \
finalize.c.in \
comm_rank.c.in \
comm_size.c.in \
waitall.c.in \
comm_split.c.in \
comm_split_type.c.in \
comm_free.c.in \
finalized.c.in \
initialized.c.in \
allreduce.c.in \
get_library_version.c.in \
get_processor_name.c.in \
barrier.c.in

# Include script and template files in case someone wants to update the
# template files
EXTRA_DIST = generate_bindings.py $(prototype_sources)

# attr_fn.c contains attribute manipulation functions which do not
# profiling implications, and so are always built.
libmpi_c_la_SOURCES = \
Expand All @@ -60,7 +90,7 @@ endif
# List of all C files that have profile versions
#
interface_profile_sources = \
abort.c \
ompi_abort.c \
add_error_class.c \
add_error_code.c \
add_error_string.c \
Expand All @@ -71,7 +101,7 @@ interface_profile_sources = \
iallgatherv.c \
allgatherv_init.c \
alloc_mem.c \
allreduce.c \
ompi_allreduce.c \
iallreduce.c \
allreduce_init.c \
alltoall.c \
Expand All @@ -86,7 +116,7 @@ interface_profile_sources = \
attr_delete.c \
attr_get.c \
attr_put.c \
barrier.c \
ompi_barrier.c \
ibarrier.c \
barrier_init.c \
bcast.c \
Expand Down Expand Up @@ -122,8 +152,8 @@ interface_profile_sources = \
comm_dup_with_info.c \
comm_idup.c \
comm_idup_with_info.c \
comm_f2c.c \
comm_free.c \
ompi_comm_f2c.c \
ompi_comm_free.c \
comm_free_keyval.c \
comm_get_attr.c \
comm_get_errhandler.c \
Expand All @@ -132,7 +162,7 @@ interface_profile_sources = \
comm_get_parent.c \
comm_group.c \
comm_join.c \
comm_rank.c \
ompi_comm_rank.c \
comm_remote_group.c \
comm_remote_size.c \
comm_set_attr.c \
Expand All @@ -143,11 +173,11 @@ interface_profile_sources = \
dist_graph_neighbors_count.c \
comm_set_errhandler.c \
comm_set_name.c \
comm_size.c \
ompi_comm_size.c \
comm_spawn.c \
comm_spawn_multiple.c \
comm_split.c \
comm_split_type.c \
ompi_comm_split.c \
ompi_comm_split_type.c \
comm_test_inter.c \
compare_and_swap.c \
dims_create.c \
Expand Down Expand Up @@ -187,7 +217,7 @@ interface_profile_sources = \
file_iwrite.c \
file_iwrite_all.c \
file_iwrite_shared.c \
file_open.c \
ompi_file_open.c \
file_preallocate.c \
file_read_all_begin.c \
file_read_all.c \
Expand Down Expand Up @@ -221,8 +251,8 @@ interface_profile_sources = \
file_write_ordered.c \
file_write_ordered_end.c \
file_write_shared.c \
finalize.c \
finalized.c \
ompi_finalize.c \
ompi_finalized.c \
free_mem.c \
gather.c \
igather.c \
Expand All @@ -235,8 +265,8 @@ interface_profile_sources = \
get_elements.c \
get_elements_x.c \
get_accumulate.c \
get_library_version.c \
get_processor_name.c \
ompi_get_library_version.c \
ompi_get_processor_name.c \
get_version.c \
graph_create.c \
graph_get.c \
Expand Down Expand Up @@ -277,17 +307,17 @@ interface_profile_sources = \
info_get_string.c \
info_get_valuelen.c \
info_set.c \
init.c \
ompi_init.c \
init_thread.c \
initialized.c \
ompi_initialized.c \
intercomm_create.c \
intercomm_create_from_groups.c \
intercomm_merge.c \
iprobe.c \
irecv.c \
ompi_irecv.c \
irsend.c \
is_thread_main.c \
isend.c \
ompi_isend.c \
isendrecv.c \
isendrecv_replace.c \
issend.c \
Expand Down Expand Up @@ -335,7 +365,7 @@ interface_profile_sources = \
query_thread.c \
raccumulate.c \
recv_init.c \
recv.c \
ompi_recv.c \
reduce.c \
ireduce.c \
reduce_init.c \
Expand Down Expand Up @@ -365,7 +395,6 @@ interface_profile_sources = \
scatterv.c \
iscatterv.c \
scatterv_init.c \
send.c \
send_init.c \
sendrecv.c \
sendrecv_replace.c \
Expand Down Expand Up @@ -440,12 +469,12 @@ interface_profile_sources = \
unpack.c \
unpublish_name.c \
wait.c \
waitall.c \
ompi_waitall.c \
waitany.c \
waitsome.c \
wtime.c \
ompi_waitsome.c \
ompi_wtime.c \
wtick.c \
accumulate.c \
ompi_accumulate.c \
get.c \
put.c \
win_allocate.c \
Expand Down Expand Up @@ -486,6 +515,7 @@ interface_profile_sources = \
win_test.c \
win_unlock.c \
win_unlock_all.c \
ompi_send.c \
win_wait.c

# The following functions were removed from the MPI standard, but are
Expand All @@ -509,3 +539,12 @@ libmpi_c_profile_la_CPPFLAGS = -DOMPI_BUILD_MPI_PROFILING=1

libmpi_c_noprofile_la_SOURCES = $(interface_profile_sources)
libmpi_c_noprofile_la_CPPFLAGS = -DOMPI_BUILD_MPI_PROFILING=0

# ABI generation rules
if OMPI_GENERATE_BINDINGS
ompi_%.c: %.c.in generate_bindings.py
$(PYTHON) $(srcdir)/generate_bindings.py source ompi $< > $@

distclean-local:
-rm -rf ompi_*.c
endif
12 changes: 1 addition & 11 deletions ompi/mpi/c/abort.c → ompi/mpi/c/abort.c.in
Original file line number Diff line number Diff line change
Expand Up @@ -28,17 +28,7 @@
#include "ompi/memchecker.h"
#include "ompi/communicator/communicator.h"

#if OMPI_BUILD_MPI_PROFILING
#if OPAL_HAVE_WEAK_SYMBOLS
#pragma weak MPI_Abort = PMPI_Abort
#endif
#define MPI_Abort PMPI_Abort
#endif

static const char FUNC_NAME[] = "MPI_Abort";


int MPI_Abort(MPI_Comm comm, int errorcode)
PROTOTYPE ERROR_CLASS abort(COMM comm, INT errorcode)
{
MEMCHECKER(
memchecker_comm(comm);
Expand Down
15 changes: 3 additions & 12 deletions ompi/mpi/c/accumulate.c → ompi/mpi/c/accumulate.c.in
Original file line number Diff line number Diff line change
Expand Up @@ -34,18 +34,9 @@
#include "ompi/datatype/ompi_datatype_internal.h"
#include "ompi/memchecker.h"

#if OMPI_BUILD_MPI_PROFILING
#if OPAL_HAVE_WEAK_SYMBOLS
#pragma weak MPI_Accumulate = PMPI_Accumulate
#endif
#define MPI_Accumulate PMPI_Accumulate
#endif

static const char FUNC_NAME[] = "MPI_Accumulate";

int MPI_Accumulate(const void *origin_addr, int origin_count, MPI_Datatype origin_datatype,
int target_rank, MPI_Aint target_disp, int target_count,
MPI_Datatype target_datatype, MPI_Op op, MPI_Win win)
PROTOTYPE ERROR_CLASS accumulate(BUFFER origin_addr, COUNT origin_count, DATATYPE origin_datatype,
INT target_rank, AINT target_disp, COUNT target_count,
DATATYPE target_datatype, OP op, WIN win)
{
int rc;
ompi_win_t *ompi_win = (ompi_win_t*) win;
Expand Down
Loading

0 comments on commit 37ada30

Please sign in to comment.