Skip to content

fortran/mpif-h: fix bindings for collective operations #6839

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
5 changes: 3 additions & 2 deletions config/ompi_config_files.m4
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
# -*- shell-script -*-
#
# Copyright (c) 2009-2017 Cisco Systems, Inc. All rights reserved
# Copyright (c) 2017-2018 Research Organization for Information Science
# and Technology (RIST). All rights reserved.
# Copyright (c) 2017-2019 Research Organization for Information Science
# and Technology (RIST). All rights reserved.
# Copyright (c) 2018 Los Alamos National Security, LLC. All rights
# reserved.
# Copyright (c) 2018 FUJITSU LIMITED. All rights reserved.
Expand Down Expand Up @@ -38,6 +38,7 @@ 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/bindings/Makefile
ompi/mpi/fortran/use-mpi-f08/mod/Makefile
ompi/mpi/fortran/mpiext-use-mpi/Makefile
Expand Down
4 changes: 4 additions & 0 deletions ompi/mpi/fortran/base/fint_2_int.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
#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
Expand Down Expand Up @@ -105,6 +106,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
#define OMPI_2_DIM_ARRAY_NAME_DECL(a, dim2) int (*c_##a)[dim2], dim2_index
Expand Down Expand Up @@ -157,6 +160,7 @@
free(OMPI_ARRAY_NAME_CONVERT(in)); \
} while (0)

#define OMPI_COND_STATEMENT(a) a
#endif

/*
Expand Down
14 changes: 9 additions & 5 deletions ompi/mpi/fortran/mpif-h/allgather_f.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@
* Copyright (c) 2004-2005 The Regents of the University of California.
* All rights reserved.
* Copyright (c) 2011-2012 Cisco Systems, Inc. All rights reserved.
* Copyright (c) 2015 Research Organization for Information Science
* and Technology (RIST). All rights reserved.
* Copyright (c) 2015-2019 Research Organization for Information Science
* and Technology (RIST). All rights reserved.
* $COPYRIGHT$
*
* Additional copyrights may follow
Expand All @@ -23,6 +23,7 @@

#include "ompi/mpi/fortran/mpif-h/bindings.h"
#include "ompi/mpi/fortran/base/constants.h"
#include "ompi/communicator/communicator.h"

#if OMPI_BUILD_MPI_PROFILING
#if OPAL_HAVE_WEAK_SYMBOLS
Expand Down Expand Up @@ -73,13 +74,16 @@ void ompi_allgather_f(char *sendbuf, MPI_Fint *sendcount, MPI_Fint *sendtype,
{
int ierr_c;
MPI_Comm c_comm;
MPI_Datatype c_sendtype, c_recvtype;
MPI_Datatype c_sendtype = NULL, c_recvtype;

c_comm = PMPI_Comm_f2c(*comm);
c_sendtype = PMPI_Type_f2c(*sendtype);
if (OMPI_COMM_IS_INTER(c_comm) || !OMPI_IS_FORTRAN_IN_PLACE(sendbuf)) {
c_sendtype = PMPI_Type_f2c(*sendtype);
} else {
sendbuf = MPI_IN_PLACE;
}
c_recvtype = PMPI_Type_f2c(*recvtype);

sendbuf = (char *) OMPI_F2C_IN_PLACE(sendbuf);
sendbuf = (char *) OMPI_F2C_BOTTOM(sendbuf);
recvbuf = (char *) OMPI_F2C_BOTTOM(recvbuf);

Expand Down
23 changes: 16 additions & 7 deletions ompi/mpi/fortran/mpif-h/allgatherv_f.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@
* Copyright (c) 2004-2005 The Regents of the University of California.
* All rights reserved.
* Copyright (c) 2011-2012 Cisco Systems, Inc. All rights reserved.
* Copyright (c) 2015 Research Organization for Information Science
* and Technology (RIST). All rights reserved.
* Copyright (c) 2015-2019 Research Organization for Information Science
* and Technology (RIST). All rights reserved.
* $COPYRIGHT$
*
* Additional copyrights may follow
Expand All @@ -23,6 +23,7 @@

#include "ompi/mpi/fortran/mpif-h/bindings.h"
#include "ompi/mpi/fortran/base/constants.h"
#include "ompi/communicator/communicator.h"

#if OMPI_BUILD_MPI_PROFILING
#if OPAL_HAVE_WEAK_SYMBOLS
Expand Down Expand Up @@ -72,20 +73,28 @@ void ompi_allgatherv_f(char *sendbuf, MPI_Fint *sendcount, MPI_Fint *sendtype,
MPI_Fint *recvtype, MPI_Fint *comm, MPI_Fint *ierr)
{
MPI_Comm c_comm;
MPI_Datatype c_sendtype, c_recvtype;
int size, ierr_c;
MPI_Datatype c_sendtype = NULL, c_recvtype;
int ierr_c;
OMPI_COND_STATEMENT(int size);
OMPI_ARRAY_NAME_DECL(recvcounts);
OMPI_ARRAY_NAME_DECL(displs);

c_comm = PMPI_Comm_f2c(*comm);
c_sendtype = PMPI_Type_f2c(*sendtype);
if (OMPI_COMM_IS_INTER(c_comm)) {
OMPI_COND_STATEMENT(size = ompi_comm_remote_size(c_comm));
} else {
OMPI_COND_STATEMENT(size = ompi_comm_size(c_comm));
if (OMPI_IS_FORTRAN_IN_PLACE(sendbuf)) {
sendbuf = MPI_IN_PLACE;
} else {
c_sendtype = PMPI_Type_f2c(*sendtype);
}
}
c_recvtype = PMPI_Type_f2c(*recvtype);

PMPI_Comm_size(c_comm, &size);
OMPI_ARRAY_FINT_2_INT(recvcounts, size);
OMPI_ARRAY_FINT_2_INT(displs, size);

sendbuf = (char *) OMPI_F2C_IN_PLACE(sendbuf);
sendbuf = (char *) OMPI_F2C_BOTTOM(sendbuf);
recvbuf = (char *) OMPI_F2C_BOTTOM(recvbuf);

Expand Down
16 changes: 11 additions & 5 deletions ompi/mpi/fortran/mpif-h/alltoall_f.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@
* Copyright (c) 2004-2005 The Regents of the University of California.
* All rights reserved.
* Copyright (c) 2011-2012 Cisco Systems, Inc. All rights reserved.
* Copyright (c) 2015 Research Organization for Information Science
* and Technology (RIST). All rights reserved.
* Copyright (c) 2015-2019 Research Organization for Information Science
* and Technology (RIST). All rights reserved.
* $COPYRIGHT$
*
* Additional copyrights may follow
Expand All @@ -23,6 +23,7 @@

#include "ompi/mpi/fortran/mpif-h/bindings.h"
#include "ompi/mpi/fortran/base/constants.h"
#include "ompi/communicator/communicator.h"

#if OMPI_BUILD_MPI_PROFILING
#if OPAL_HAVE_WEAK_SYMBOLS
Expand Down Expand Up @@ -73,13 +74,18 @@ void ompi_alltoall_f(char *sendbuf, MPI_Fint *sendcount, MPI_Fint *sendtype,
{
int c_ierr;
MPI_Comm c_comm;
MPI_Datatype c_sendtype, c_recvtype;
MPI_Datatype c_sendtype = NULL, c_recvtype;

c_comm = PMPI_Comm_f2c(*comm);
c_sendtype = PMPI_Type_f2c(*sendtype);

if (OMPI_IS_FORTRAN_IN_PLACE(sendbuf)) {
sendbuf = MPI_IN_PLACE;
} else {
c_sendtype = PMPI_Type_f2c(*sendtype);
}

c_recvtype = PMPI_Type_f2c(*recvtype);

sendbuf = (char *) OMPI_F2C_IN_PLACE(sendbuf);
sendbuf = (char *) OMPI_F2C_BOTTOM(sendbuf);
recvbuf = (char *) OMPI_F2C_BOTTOM(recvbuf);

Expand Down
45 changes: 26 additions & 19 deletions ompi/mpi/fortran/mpif-h/alltoallv_f.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@
* Copyright (c) 2004-2005 The Regents of the University of California.
* All rights reserved.
* Copyright (c) 2011-2012 Cisco Systems, Inc. All rights reserved.
* Copyright (c) 2015 Research Organization for Information Science
* and Technology (RIST). All rights reserved.
* Copyright (c) 2015-2019 Research Organization for Information Science
* and Technology (RIST). All rights reserved.
* $COPYRIGHT$
*
* Additional copyrights may follow
Expand All @@ -23,6 +23,7 @@

#include "ompi/mpi/fortran/mpif-h/bindings.h"
#include "ompi/mpi/fortran/base/constants.h"
#include "ompi/communicator/communicator.h"

#if OMPI_BUILD_MPI_PROFILING
#if OPAL_HAVE_WEAK_SYMBOLS
Expand Down Expand Up @@ -73,39 +74,45 @@ void ompi_alltoallv_f(char *sendbuf, MPI_Fint *sendcounts, MPI_Fint *sdispls,
MPI_Fint *comm, MPI_Fint *ierr)
{
MPI_Comm c_comm;
MPI_Datatype c_sendtype, c_recvtype;
int size, c_ierr;
MPI_Datatype c_sendtype = NULL, c_recvtype;
int c_ierr;
OMPI_ARRAY_NAME_DECL(sendcounts);
OMPI_ARRAY_NAME_DECL(sdispls);
OMPI_ARRAY_NAME_DECL(recvcounts);
OMPI_ARRAY_NAME_DECL(rdispls);

c_comm = PMPI_Comm_f2c(*comm);
c_sendtype = PMPI_Type_f2c(*sendtype);
c_recvtype = PMPI_Type_f2c(*recvtype);
OMPI_COND_STATEMENT(int size = OMPI_COMM_IS_INTER(c_comm)?ompi_comm_remote_size(c_comm):ompi_comm_size(c_comm));

if (OMPI_IS_FORTRAN_IN_PLACE(sendbuf)) {
sendbuf = MPI_IN_PLACE;
} else {
c_sendtype = PMPI_Type_f2c(*sendtype);
OMPI_ARRAY_FINT_2_INT(sendcounts, size);
OMPI_ARRAY_FINT_2_INT(sdispls, size);
}

PMPI_Comm_size(c_comm, &size);
OMPI_ARRAY_FINT_2_INT(sendcounts, size);
OMPI_ARRAY_FINT_2_INT(sdispls, size);
c_recvtype = PMPI_Type_f2c(*recvtype);
OMPI_ARRAY_FINT_2_INT(recvcounts, size);
OMPI_ARRAY_FINT_2_INT(rdispls, size);

sendbuf = (char *) OMPI_F2C_IN_PLACE(sendbuf);
sendbuf = (char *) OMPI_F2C_BOTTOM(sendbuf);
recvbuf = (char *) OMPI_F2C_BOTTOM(recvbuf);

c_ierr = PMPI_Alltoallv(sendbuf,
OMPI_ARRAY_NAME_CONVERT(sendcounts),
OMPI_ARRAY_NAME_CONVERT(sdispls),
c_sendtype,
recvbuf,
OMPI_ARRAY_NAME_CONVERT(recvcounts),
OMPI_ARRAY_NAME_CONVERT(rdispls),
c_recvtype, c_comm);
OMPI_ARRAY_NAME_CONVERT(sendcounts),
OMPI_ARRAY_NAME_CONVERT(sdispls),
c_sendtype,
recvbuf,
OMPI_ARRAY_NAME_CONVERT(recvcounts),
OMPI_ARRAY_NAME_CONVERT(rdispls),
c_recvtype, c_comm);
if (NULL != ierr) *ierr = OMPI_INT_2_FINT(c_ierr);

OMPI_ARRAY_FINT_2_INT_CLEANUP(sendcounts);
OMPI_ARRAY_FINT_2_INT_CLEANUP(sdispls);
if (MPI_IN_PLACE != sendbuf) {
OMPI_ARRAY_FINT_2_INT_CLEANUP(sendcounts);
OMPI_ARRAY_FINT_2_INT_CLEANUP(sdispls);
}
OMPI_ARRAY_FINT_2_INT_CLEANUP(recvcounts);
OMPI_ARRAY_FINT_2_INT_CLEANUP(rdispls);
}
6 changes: 4 additions & 2 deletions ompi/mpi/fortran/mpif-h/alltoallw_f.c
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
* All rights reserved.
* Copyright (c) 2011-2012 Cisco Systems, Inc. All rights reserved.
* Copyright (c) 2015-2019 Research Organization for Information Science
* and Technology (RIST). All rights reserved.
* and Technology (RIST). All rights reserved.
* $COPYRIGHT$
*
* Additional copyrights may follow
Expand Down Expand Up @@ -85,7 +85,9 @@ void ompi_alltoallw_f(char *sendbuf, MPI_Fint *sendcounts,
c_comm = PMPI_Comm_f2c(*comm);
size = OMPI_COMM_IS_INTER(c_comm)?ompi_comm_remote_size(c_comm):ompi_comm_size(c_comm);

if (!OMPI_IS_FORTRAN_IN_PLACE(sendbuf)) {
if (OMPI_IS_FORTRAN_IN_PLACE(sendbuf)) {
sendbuf = MPI_IN_PLACE;
} else {
c_sendtypes = (MPI_Datatype *) malloc(size * sizeof(MPI_Datatype));
OMPI_ARRAY_FINT_2_INT(sendcounts, size);
OMPI_ARRAY_FINT_2_INT(sdispls, size);
Expand Down
31 changes: 23 additions & 8 deletions ompi/mpi/fortran/mpif-h/gather_f.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@
* Copyright (c) 2004-2005 The Regents of the University of California.
* All rights reserved.
* Copyright (c) 2011-2012 Cisco Systems, Inc. All rights reserved.
* Copyright (c) 2015 Research Organization for Information Science
* and Technology (RIST). All rights reserved.
* Copyright (c) 2015-2019 Research Organization for Information Science
* and Technology (RIST). All rights reserved.
* $COPYRIGHT$
*
* Additional copyrights may follow
Expand All @@ -23,6 +23,7 @@

#include "ompi/mpi/fortran/mpif-h/bindings.h"
#include "ompi/mpi/fortran/base/constants.h"
#include "ompi/communicator/communicator.h"

#if OMPI_BUILD_MPI_PROFILING
#if OPAL_HAVE_WEAK_SYMBOLS
Expand Down Expand Up @@ -71,23 +72,37 @@ void ompi_gather_f(char *sendbuf, MPI_Fint *sendcount, MPI_Fint *sendtype,
char *recvbuf, MPI_Fint *recvcount, MPI_Fint *recvtype,
MPI_Fint *root, MPI_Fint *comm, MPI_Fint *ierr)
{
int c_ierr;
int c_root, c_ierr;
MPI_Comm c_comm;
MPI_Datatype c_sendtype, c_recvtype;
MPI_Datatype c_sendtype = NULL, c_recvtype = NULL;

c_comm = PMPI_Comm_f2c(*comm);
c_sendtype = PMPI_Type_f2c(*sendtype);
c_recvtype = PMPI_Type_f2c(*recvtype);
c_root = OMPI_FINT_2_INT(*root);
if (OMPI_COMM_IS_INTER(c_comm)) {
if (MPI_ROOT == c_root) {
c_recvtype = PMPI_Type_f2c(*recvtype);
} else if (MPI_PROC_NULL != c_root) {
c_sendtype = PMPI_Type_f2c(*sendtype);
}
} else {
if (OMPI_IS_FORTRAN_IN_PLACE(sendbuf)) {
sendbuf = MPI_IN_PLACE;
} else {
c_sendtype = PMPI_Type_f2c(*sendtype);
}
if (ompi_comm_rank(c_comm) == c_root) {
c_recvtype = PMPI_Type_f2c(*recvtype);
}
}

sendbuf = (char *) OMPI_F2C_IN_PLACE(sendbuf);
sendbuf = (char *) OMPI_F2C_BOTTOM(sendbuf);
recvbuf = (char *) OMPI_F2C_BOTTOM(recvbuf);

c_ierr = PMPI_Gather(sendbuf, OMPI_FINT_2_INT(*sendcount),
c_sendtype, recvbuf,
OMPI_FINT_2_INT(*recvcount),
c_recvtype,
OMPI_FINT_2_INT(*root),
c_root,
c_comm);
if (NULL != ierr) *ierr = OMPI_INT_2_FINT(c_ierr);
}
Loading