Skip to content

Commit 0df0e5c

Browse files
authored
Merge pull request #6813 from ggouaillardet/topic/alltoallw_inplace_mpifh
fortran/mpif-h: fix MPI_Alltoallw() binding
2 parents 020a591 + cdaed89 commit 0df0e5c

File tree

2 files changed

+36
-25
lines changed

2 files changed

+36
-25
lines changed

ompi/mpi/fortran/mpif-h/alltoallw_f.c

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
* Copyright (c) 2004-2005 The Regents of the University of California.
1111
* All rights reserved.
1212
* Copyright (c) 2011-2012 Cisco Systems, Inc. All rights reserved.
13-
* Copyright (c) 2015 Research Organization for Information Science
13+
* Copyright (c) 2015-2019 Research Organization for Information Science
1414
* and Technology (RIST). All rights reserved.
1515
* $COPYRIGHT$
1616
*
@@ -23,6 +23,7 @@
2323

2424
#include "ompi/mpi/fortran/mpif-h/bindings.h"
2525
#include "ompi/mpi/fortran/base/constants.h"
26+
#include "ompi/communicator/communicator.h"
2627

2728
#if OMPI_BUILD_MPI_PROFILING
2829
#if OPAL_HAVE_WEAK_SYMBOLS
@@ -82,20 +83,22 @@ void ompi_alltoallw_f(char *sendbuf, MPI_Fint *sendcounts,
8283
OMPI_ARRAY_NAME_DECL(rdispls);
8384

8485
c_comm = PMPI_Comm_f2c(*comm);
85-
PMPI_Comm_size(c_comm, &size);
86+
size = OMPI_COMM_IS_INTER(c_comm)?ompi_comm_remote_size(c_comm):ompi_comm_size(c_comm);
8687

87-
c_sendtypes = (MPI_Datatype *) malloc(size * sizeof(MPI_Datatype));
88-
c_recvtypes = (MPI_Datatype *) malloc(size * sizeof(MPI_Datatype));
88+
if (!OMPI_IS_FORTRAN_IN_PLACE(sendbuf)) {
89+
c_sendtypes = (MPI_Datatype *) malloc(size * sizeof(MPI_Datatype));
90+
OMPI_ARRAY_FINT_2_INT(sendcounts, size);
91+
OMPI_ARRAY_FINT_2_INT(sdispls, size);
92+
for (int i=0; i<size; i++) {
93+
c_sendtypes[i] = PMPI_Type_f2c(sendtypes[i]);
94+
}
95+
}
8996

90-
OMPI_ARRAY_FINT_2_INT(sendcounts, size);
91-
OMPI_ARRAY_FINT_2_INT(sdispls, size);
97+
c_recvtypes = (MPI_Datatype *) malloc(size * sizeof(MPI_Datatype));
9298
OMPI_ARRAY_FINT_2_INT(recvcounts, size);
9399
OMPI_ARRAY_FINT_2_INT(rdispls, size);
94-
95-
while (size > 0) {
96-
c_sendtypes[size - 1] = PMPI_Type_f2c(sendtypes[size - 1]);
97-
c_recvtypes[size - 1] = PMPI_Type_f2c(recvtypes[size - 1]);
98-
--size;
100+
for (int i=0; i<size; i++) {
101+
c_recvtypes[i] = PMPI_Type_f2c(recvtypes[i]);
99102
}
100103

101104
sendbuf = (char *) OMPI_F2C_IN_PLACE(sendbuf);
@@ -116,6 +119,8 @@ void ompi_alltoallw_f(char *sendbuf, MPI_Fint *sendcounts,
116119
OMPI_ARRAY_FINT_2_INT_CLEANUP(sdispls);
117120
OMPI_ARRAY_FINT_2_INT_CLEANUP(recvcounts);
118121
OMPI_ARRAY_FINT_2_INT_CLEANUP(rdispls);
119-
free(c_sendtypes);
122+
if (MPI_IN_PLACE != sendbuf) {
123+
free(c_sendtypes);
124+
}
120125
free(c_recvtypes);
121126
}

ompi/mpi/fortran/mpif-h/ialltoallw_f.c

Lines changed: 19 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@
1010
* Copyright (c) 2004-2005 The Regents of the University of California.
1111
* All rights reserved.
1212
* Copyright (c) 2011-2012 Cisco Systems, Inc. All rights reserved.
13-
* Copyright (c) 2015 Research Organization for Information Science
14-
* and Technology (RIST). All rights reserved.
13+
* Copyright (c) 2015-2019 Research Organization for Information Science
14+
* and Technology (RIST). All rights reserved.
1515
* $COPYRIGHT$
1616
*
1717
* Additional copyrights may follow
@@ -23,6 +23,7 @@
2323

2424
#include "ompi/mpi/fortran/mpif-h/bindings.h"
2525
#include "ompi/mpi/fortran/base/constants.h"
26+
#include "ompi/communicator/communicator.h"
2627

2728
#if OMPI_BUILD_MPI_PROFILING
2829
#if OPAL_HAVE_WEAK_SYMBOLS
@@ -83,21 +84,24 @@ void ompi_ialltoallw_f(char *sendbuf, MPI_Fint *sendcounts,
8384
OMPI_ARRAY_NAME_DECL(rdispls);
8485

8586
c_comm = PMPI_Comm_f2c(*comm);
86-
PMPI_Comm_size(c_comm, &size);
87+
size = OMPI_COMM_IS_INTER(c_comm)?ompi_comm_remote_size(c_comm):ompi_comm_size(c_comm);
8788

88-
c_sendtypes = (MPI_Datatype *) malloc(size * sizeof(MPI_Datatype));
89-
c_recvtypes = (MPI_Datatype *) malloc(size * sizeof(MPI_Datatype));
89+
if (!OMPI_IS_FORTRAN_IN_PLACE(sendbuf)) {
90+
c_sendtypes = (MPI_Datatype *) malloc(size * sizeof(MPI_Datatype));
91+
OMPI_ARRAY_FINT_2_INT(sendcounts, size);
92+
OMPI_ARRAY_FINT_2_INT(sdispls, size);
93+
for (int i=0; i<size; i++) {
94+
c_sendtypes[i] = PMPI_Type_f2c(sendtypes[i]);
95+
}
96+
}
9097

91-
OMPI_ARRAY_FINT_2_INT(sendcounts, size);
92-
OMPI_ARRAY_FINT_2_INT(sdispls, size);
98+
c_recvtypes = (MPI_Datatype *) malloc(size * sizeof(MPI_Datatype));
9399
OMPI_ARRAY_FINT_2_INT(recvcounts, size);
94100
OMPI_ARRAY_FINT_2_INT(rdispls, size);
95-
96-
while (size > 0) {
97-
c_sendtypes[size - 1] = PMPI_Type_f2c(sendtypes[size - 1]);
98-
c_recvtypes[size - 1] = PMPI_Type_f2c(recvtypes[size - 1]);
99-
--size;
101+
for (int i=0; i<size; i++) {
102+
c_recvtypes[i] = PMPI_Type_f2c(recvtypes[i]);
100103
}
104+
c_recvtypes = (MPI_Datatype *) malloc(size * sizeof(MPI_Datatype));
101105

102106
sendbuf = (char *) OMPI_F2C_IN_PLACE(sendbuf);
103107
sendbuf = (char *) OMPI_F2C_BOTTOM(sendbuf);
@@ -118,6 +122,8 @@ void ompi_ialltoallw_f(char *sendbuf, MPI_Fint *sendcounts,
118122
OMPI_ARRAY_FINT_2_INT_CLEANUP(sdispls);
119123
OMPI_ARRAY_FINT_2_INT_CLEANUP(recvcounts);
120124
OMPI_ARRAY_FINT_2_INT_CLEANUP(rdispls);
121-
free(c_sendtypes);
125+
if (MPI_IN_PLACE != sendbuf) {
126+
free(c_sendtypes);
127+
}
122128
free(c_recvtypes);
123129
}

0 commit comments

Comments
 (0)