Skip to content

Commit 5bd90ee

Browse files
Merge pull request #6824 from ggouaillardet/topic/alltoallw_cid
fortran/mpif-h: fix MPI_Alltoallw and friends bindings
2 parents 41c2007 + b71af0e commit 5bd90ee

File tree

3 files changed

+22
-20
lines changed

3 files changed

+22
-20
lines changed

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ void ompi_alltoallw_f(char *sendbuf, MPI_Fint *sendcounts,
7575
MPI_Fint *comm, MPI_Fint *ierr)
7676
{
7777
MPI_Comm c_comm;
78-
MPI_Datatype *c_sendtypes, *c_recvtypes;
78+
MPI_Datatype *c_sendtypes = NULL, *c_recvtypes;
7979
int size, c_ierr;
8080
OMPI_ARRAY_NAME_DECL(sendcounts);
8181
OMPI_ARRAY_NAME_DECL(sdispls);
@@ -119,7 +119,7 @@ void ompi_alltoallw_f(char *sendbuf, MPI_Fint *sendcounts,
119119
OMPI_ARRAY_FINT_2_INT_CLEANUP(sdispls);
120120
OMPI_ARRAY_FINT_2_INT_CLEANUP(recvcounts);
121121
OMPI_ARRAY_FINT_2_INT_CLEANUP(rdispls);
122-
if (MPI_IN_PLACE != sendbuf) {
122+
if (NULL != c_sendtypes) {
123123
free(c_sendtypes);
124124
}
125125
free(c_recvtypes);

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

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ void ompi_ialltoallw_f(char *sendbuf, MPI_Fint *sendcounts,
7575
MPI_Fint *comm, MPI_Fint *request, MPI_Fint *ierr)
7676
{
7777
MPI_Comm c_comm;
78-
MPI_Datatype *c_sendtypes, *c_recvtypes;
78+
MPI_Datatype *c_sendtypes = NULL, *c_recvtypes;
7979
MPI_Request c_request;
8080
int size, c_ierr;
8181
OMPI_ARRAY_NAME_DECL(sendcounts);
@@ -101,7 +101,6 @@ void ompi_ialltoallw_f(char *sendbuf, MPI_Fint *sendcounts,
101101
for (int i=0; i<size; i++) {
102102
c_recvtypes[i] = PMPI_Type_f2c(recvtypes[i]);
103103
}
104-
c_recvtypes = (MPI_Datatype *) malloc(size * sizeof(MPI_Datatype));
105104

106105
sendbuf = (char *) OMPI_F2C_IN_PLACE(sendbuf);
107106
sendbuf = (char *) OMPI_F2C_BOTTOM(sendbuf);
@@ -122,7 +121,7 @@ void ompi_ialltoallw_f(char *sendbuf, MPI_Fint *sendcounts,
122121
OMPI_ARRAY_FINT_2_INT_CLEANUP(sdispls);
123122
OMPI_ARRAY_FINT_2_INT_CLEANUP(recvcounts);
124123
OMPI_ARRAY_FINT_2_INT_CLEANUP(rdispls);
125-
if (MPI_IN_PLACE != sendbuf) {
124+
if (NULL != c_sendtypes) {
126125
free(c_sendtypes);
127126
}
128127
free(c_recvtypes);

ompi/mpiext/pcollreq/mpif-h/alltoallw_init_f.c

Lines changed: 18 additions & 15 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-2018 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
#include "ompi/mpiext/pcollreq/mpif-h/mpiext_pcollreq_prototypes.h"
2728

2829
#if OMPI_BUILD_MPI_PROFILING
@@ -85,22 +86,22 @@ void ompix_alltoallw_init_f(char *sendbuf, MPI_Fint *sendcounts,
8586
OMPI_ARRAY_NAME_DECL(rdispls);
8687

8788
c_comm = PMPI_Comm_f2c(*comm);
88-
PMPI_Comm_size(c_comm, &size);
89+
size = OMPI_COMM_IS_INTER(c_comm)?ompi_comm_remote_size(c_comm):ompi_comm_size(c_comm);
90+
91+
if (!OMPI_IS_FORTRAN_IN_PLACE(sendbuf)) {
92+
c_sendtypes = (MPI_Datatype *) malloc(size * sizeof(MPI_Datatype));
93+
OMPI_ARRAY_FINT_2_INT(sendcounts, size);
94+
OMPI_ARRAY_FINT_2_INT(sdispls, size);
95+
for (int i=0; i<size; i++) {
96+
c_sendtypes[i] = PMPI_Type_f2c(sendtypes[i]);
97+
}
98+
}
8999

90-
c_sendtypes = (MPI_Datatype *) malloc(size * sizeof(MPI_Datatype));
91100
c_recvtypes = (MPI_Datatype *) malloc(size * sizeof(MPI_Datatype));
92-
93-
c_info = PMPI_Info_f2c(*info);
94-
95-
OMPI_ARRAY_FINT_2_INT(sendcounts, size);
96-
OMPI_ARRAY_FINT_2_INT(sdispls, size);
97101
OMPI_ARRAY_FINT_2_INT(recvcounts, size);
98102
OMPI_ARRAY_FINT_2_INT(rdispls, size);
99-
100-
while (size > 0) {
101-
c_sendtypes[size - 1] = PMPI_Type_f2c(sendtypes[size - 1]);
102-
c_recvtypes[size - 1] = PMPI_Type_f2c(recvtypes[size - 1]);
103-
--size;
103+
for (int i=0; i<size; i++) {
104+
c_recvtypes[i] = PMPI_Type_f2c(recvtypes[i]);
104105
}
105106

106107
sendbuf = (char *) OMPI_F2C_IN_PLACE(sendbuf);
@@ -122,6 +123,8 @@ void ompix_alltoallw_init_f(char *sendbuf, MPI_Fint *sendcounts,
122123
OMPI_ARRAY_FINT_2_INT_CLEANUP(sdispls);
123124
OMPI_ARRAY_FINT_2_INT_CLEANUP(recvcounts);
124125
OMPI_ARRAY_FINT_2_INT_CLEANUP(rdispls);
125-
free(c_sendtypes);
126+
if (NULL != c_sendtypes) {
127+
free(c_sendtypes);
128+
}
126129
free(c_recvtypes);
127130
}

0 commit comments

Comments
 (0)