Skip to content

Commit

Permalink
fortran/mpif-h: fix MPI_[I]Alltoallw() binding
Browse files Browse the repository at this point in the history
 - ignore sendcounts, sendispls and sendtypes arguments when MPI_IN_PLACE is used
 - use the right size when an inter-communicator is used.

Thanks Markus Geimer for reporting this.

Refs. #5459

Signed-off-by: Gilles Gouaillardet <gilles@rist.or.jp>
  • Loading branch information
ggouaillardet committed Jul 13, 2019
1 parent 020a591 commit cdaed89
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 25 deletions.
29 changes: 17 additions & 12 deletions ompi/mpi/fortran/mpif-h/alltoallw_f.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
* 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
* Copyright (c) 2015-2019 Research Organization for Information Science
* and Technology (RIST). All rights reserved.
* $COPYRIGHT$
*
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 @@ -82,20 +83,22 @@ void ompi_alltoallw_f(char *sendbuf, MPI_Fint *sendcounts,
OMPI_ARRAY_NAME_DECL(rdispls);

c_comm = PMPI_Comm_f2c(*comm);
PMPI_Comm_size(c_comm, &size);
size = OMPI_COMM_IS_INTER(c_comm)?ompi_comm_remote_size(c_comm):ompi_comm_size(c_comm);

c_sendtypes = (MPI_Datatype *) malloc(size * sizeof(MPI_Datatype));
c_recvtypes = (MPI_Datatype *) malloc(size * sizeof(MPI_Datatype));
if (!OMPI_IS_FORTRAN_IN_PLACE(sendbuf)) {
c_sendtypes = (MPI_Datatype *) malloc(size * sizeof(MPI_Datatype));
OMPI_ARRAY_FINT_2_INT(sendcounts, size);
OMPI_ARRAY_FINT_2_INT(sdispls, size);
for (int i=0; i<size; i++) {
c_sendtypes[i] = PMPI_Type_f2c(sendtypes[i]);
}
}

OMPI_ARRAY_FINT_2_INT(sendcounts, size);
OMPI_ARRAY_FINT_2_INT(sdispls, size);
c_recvtypes = (MPI_Datatype *) malloc(size * sizeof(MPI_Datatype));
OMPI_ARRAY_FINT_2_INT(recvcounts, size);
OMPI_ARRAY_FINT_2_INT(rdispls, size);

while (size > 0) {
c_sendtypes[size - 1] = PMPI_Type_f2c(sendtypes[size - 1]);
c_recvtypes[size - 1] = PMPI_Type_f2c(recvtypes[size - 1]);
--size;
for (int i=0; i<size; i++) {
c_recvtypes[i] = PMPI_Type_f2c(recvtypes[i]);
}

sendbuf = (char *) OMPI_F2C_IN_PLACE(sendbuf);
Expand All @@ -116,6 +119,8 @@ void ompi_alltoallw_f(char *sendbuf, MPI_Fint *sendcounts,
OMPI_ARRAY_FINT_2_INT_CLEANUP(sdispls);
OMPI_ARRAY_FINT_2_INT_CLEANUP(recvcounts);
OMPI_ARRAY_FINT_2_INT_CLEANUP(rdispls);
free(c_sendtypes);
if (MPI_IN_PLACE != sendbuf) {
free(c_sendtypes);
}
free(c_recvtypes);
}
32 changes: 19 additions & 13 deletions ompi/mpi/fortran/mpif-h/ialltoallw_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 @@ -83,21 +84,24 @@ void ompi_ialltoallw_f(char *sendbuf, MPI_Fint *sendcounts,
OMPI_ARRAY_NAME_DECL(rdispls);

c_comm = PMPI_Comm_f2c(*comm);
PMPI_Comm_size(c_comm, &size);
size = OMPI_COMM_IS_INTER(c_comm)?ompi_comm_remote_size(c_comm):ompi_comm_size(c_comm);

c_sendtypes = (MPI_Datatype *) malloc(size * sizeof(MPI_Datatype));
c_recvtypes = (MPI_Datatype *) malloc(size * sizeof(MPI_Datatype));
if (!OMPI_IS_FORTRAN_IN_PLACE(sendbuf)) {
c_sendtypes = (MPI_Datatype *) malloc(size * sizeof(MPI_Datatype));
OMPI_ARRAY_FINT_2_INT(sendcounts, size);
OMPI_ARRAY_FINT_2_INT(sdispls, size);
for (int i=0; i<size; i++) {
c_sendtypes[i] = PMPI_Type_f2c(sendtypes[i]);
}
}

OMPI_ARRAY_FINT_2_INT(sendcounts, size);
OMPI_ARRAY_FINT_2_INT(sdispls, size);
c_recvtypes = (MPI_Datatype *) malloc(size * sizeof(MPI_Datatype));
OMPI_ARRAY_FINT_2_INT(recvcounts, size);
OMPI_ARRAY_FINT_2_INT(rdispls, size);

while (size > 0) {
c_sendtypes[size - 1] = PMPI_Type_f2c(sendtypes[size - 1]);
c_recvtypes[size - 1] = PMPI_Type_f2c(recvtypes[size - 1]);
--size;
for (int i=0; i<size; i++) {
c_recvtypes[i] = PMPI_Type_f2c(recvtypes[i]);
}
c_recvtypes = (MPI_Datatype *) malloc(size * sizeof(MPI_Datatype));

sendbuf = (char *) OMPI_F2C_IN_PLACE(sendbuf);
sendbuf = (char *) OMPI_F2C_BOTTOM(sendbuf);
Expand All @@ -118,6 +122,8 @@ void ompi_ialltoallw_f(char *sendbuf, MPI_Fint *sendcounts,
OMPI_ARRAY_FINT_2_INT_CLEANUP(sdispls);
OMPI_ARRAY_FINT_2_INT_CLEANUP(recvcounts);
OMPI_ARRAY_FINT_2_INT_CLEANUP(rdispls);
free(c_sendtypes);
if (MPI_IN_PLACE != sendbuf) {
free(c_sendtypes);
}
free(c_recvtypes);
}

0 comments on commit cdaed89

Please sign in to comment.