From f159b108b09c28156ff066ffc00b93c1db3dc3fd Mon Sep 17 00:00:00 2001 From: Vishal Sahay Date: Fri, 27 Aug 2004 21:53:11 +0000 Subject: [PATCH] Modified bindings to take care of difference in size of int and MPI_Fint This commit was SVN r2337. --- src/mpi/f77/allgather_f.c | 9 +++-- src/mpi/f77/allgatherv_f.c | 21 +++++++++-- src/mpi/f77/allreduce_f.c | 4 ++- src/mpi/f77/alltoall_f.c | 8 +++-- src/mpi/f77/alltoallv_f.c | 27 +++++++++++++-- src/mpi/f77/alltoallw_f.c | 37 ++++++++++++++++++-- src/mpi/f77/attr_delete_f.c | 3 +- src/mpi/f77/attr_get_f.c | 11 +++++- src/mpi/f77/attr_put_f.c | 4 ++- src/mpi/f77/bindings.h | 69 +++++++++++++++++++++++++++++++++++++ 10 files changed, 178 insertions(+), 15 deletions(-) diff --git a/src/mpi/f77/allgather_f.c b/src/mpi/f77/allgather_f.c index 81751748ec..3a433d457a 100644 --- a/src/mpi/f77/allgather_f.c +++ b/src/mpi/f77/allgather_f.c @@ -57,6 +57,11 @@ void mpi_allgather_f(char *sendbuf, MPI_Fint *sendcount, MPI_Fint *sendtype, c_sendtype = MPI_Type_f2c(*sendtype); c_recvtype = MPI_Type_f2c(*recvtype); - *ierr = MPI_Allgather(sendbuf, *sendcount, c_sendtype, - recvbuf, *recvcount, c_recvtype, c_comm); + *ierr = OMPI_INT_2_FINT(MPI_Allgather(sendbuf, + OMPI_FINT_2_INT(*sendcount), + c_sendtype, + recvbuf, + OMPI_FINT_2_INT(*recvcount), + c_recvtype, c_comm)); + } diff --git a/src/mpi/f77/allgatherv_f.c b/src/mpi/f77/allgatherv_f.c index ad9109a262..eaa1019f3f 100644 --- a/src/mpi/f77/allgatherv_f.c +++ b/src/mpi/f77/allgatherv_f.c @@ -47,16 +47,31 @@ OMPI_GENERATE_F77_BINDINGS (MPI_ALLGATHERV, #endif void mpi_allgatherv_f(char *sendbuf, MPI_Fint *sendcount, MPI_Fint *sendtype, - char *recvbuf, MPI_Fint *recvcount, MPI_Fint *displs, + char *recvbuf, MPI_Fint *recvcounts, MPI_Fint *displs, MPI_Fint *recvtype, MPI_Fint *comm, MPI_Fint *ierr) { MPI_Comm c_comm; MPI_Datatype c_sendtype, c_recvtype; + int size; + OMPI_ARRAY_NAME_DECL(recvcounts); + OMPI_ARRAY_NAME_DECL(displs); c_comm = MPI_Comm_f2c(*comm); c_sendtype = MPI_Type_f2c(*sendtype); c_recvtype = MPI_Type_f2c(*recvtype); - *ierr = MPI_Allgatherv(sendbuf, *sendcount, c_sendtype, - recvbuf, *recvcount, displs, c_recvtype, c_comm); + MPI_Comm_size(c_comm, &size); + OMPI_ARRAY_FINT_2_INT(recvcounts, size); + OMPI_ARRAY_FINT_2_INT(displs, size); + + *ierr = OMPI_INT_2_FINT(MPI_Allgatherv(sendbuf, + OMPI_FINT_2_INT(*sendcount), + c_sendtype, + recvbuf, + OMPI_ARRAY_NAME_CONVERT(recvcounts), + OMPI_ARRAY_NAME_CONVERT(displs), + c_recvtype, c_comm)); + + OMPI_ARRAY_FINT_2_INT_CLEANUP(recvcounts); + OMPI_ARRAY_FINT_2_INT_CLEANUP(displs); } diff --git a/src/mpi/f77/allreduce_f.c b/src/mpi/f77/allreduce_f.c index 17ad5408a9..090af74ad3 100644 --- a/src/mpi/f77/allreduce_f.c +++ b/src/mpi/f77/allreduce_f.c @@ -58,5 +58,7 @@ void mpi_allreduce_f(char *sendbuf, char *recvbuf, MPI_Fint *count, c_type = MPI_Type_f2c(*datatype); c_op = MPI_Op_f2c(*op); - *ierr = MPI_Allreduce(sendbuf, recvbuf, *count, c_type, c_op, c_comm); + *ierr = OMPI_INT_2_FINT(MPI_Allreduce(sendbuf, recvbuf, + OMPI_FINT_2_INT(*count), + c_type, c_op, c_comm)); } diff --git a/src/mpi/f77/alltoall_f.c b/src/mpi/f77/alltoall_f.c index c74e452260..c9596e95c8 100644 --- a/src/mpi/f77/alltoall_f.c +++ b/src/mpi/f77/alltoall_f.c @@ -57,6 +57,10 @@ void mpi_alltoall_f(char *sendbuf, MPI_Fint *sendcount, MPI_Fint *sendtype, c_sendtype = MPI_Type_f2c(*sendtype); c_recvtype = MPI_Type_f2c(*recvtype); - *ierr = MPI_Allgather(sendbuf, *sendcount, c_sendtype, - recvbuf, *recvcount, c_recvtype, c_comm); + *ierr = OMPI_INT_2_FINT(MPI_Allgather(sendbuf, + OMPI_FINT_2_INT(*sendcount), + c_sendtype, + recvbuf, + OMPI_FINT_2_INT(*recvcount), + c_recvtype, c_comm)); } diff --git a/src/mpi/f77/alltoallv_f.c b/src/mpi/f77/alltoallv_f.c index cbb9ca3053..1815a95b4b 100644 --- a/src/mpi/f77/alltoallv_f.c +++ b/src/mpi/f77/alltoallv_f.c @@ -53,12 +53,35 @@ void mpi_alltoallv_f(char *sendbuf, MPI_Fint *sendcounts, MPI_Fint *sdispls, { MPI_Comm c_comm; MPI_Datatype c_sendtype, c_recvtype; + int size; + OMPI_ARRAY_NAME_DECL(sendcounts); + OMPI_ARRAY_NAME_DECL(sdispls); + OMPI_ARRAY_NAME_DECL(recvcounts); + OMPI_ARRAY_NAME_DECL(rdispls); c_comm = MPI_Comm_f2c(*comm); c_sendtype = MPI_Type_f2c(*sendtype); c_recvtype = MPI_Type_f2c(*recvtype); - *ierr = MPI_Alltoallv(sendbuf, sendcounts, sdispls, c_sendtype, - recvbuf, recvcounts, rdispls, c_recvtype, c_comm); + MPI_Comm_size(c_comm, &size); + OMPI_ARRAY_FINT_2_INT(sendcounts, size); + OMPI_ARRAY_FINT_2_INT(sdispls, size); + OMPI_ARRAY_FINT_2_INT(recvcounts, size); + OMPI_ARRAY_FINT_2_INT(rdispls, size); + + + *ierr = OMPI_INT_2_FINT(MPI_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_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); } diff --git a/src/mpi/f77/alltoallw_f.c b/src/mpi/f77/alltoallw_f.c index 994b2cfc0d..61a866ea84 100644 --- a/src/mpi/f77/alltoallw_f.c +++ b/src/mpi/f77/alltoallw_f.c @@ -53,8 +53,41 @@ void mpi_alltoallw_f(char *sendbuf, MPI_Fint *sendcounts, MPI_Fint *comm, MPI_Fint *ierr) { MPI_Comm c_comm; + MPI_Datatype *c_sendtypes, *c_recvtypes; + int size; + OMPI_ARRAY_NAME_DECL(sendcounts); + OMPI_ARRAY_NAME_DECL(sdispls); + OMPI_ARRAY_NAME_DECL(recvcounts); + OMPI_ARRAY_NAME_DECL(rdispls); c_comm = MPI_Comm_f2c(*comm); - *ierr = MPI_Alltoallw(sendbuf, sendcounts, sdispls, sendtypes, - recvbuf, recvcounts, rdispls, recvtypes, c_comm); + MPI_Comm_size(c_comm, &size); + + c_sendtypes = malloc(size * sizeof(MPI_Datatype)); + c_recvtypes = malloc(size * sizeof(MPI_Datatype)); + + OMPI_ARRAY_FINT_2_INT(sendcounts, size); + OMPI_ARRAY_FINT_2_INT(sdispls, size); + OMPI_ARRAY_FINT_2_INT(recvcounts, size); + OMPI_ARRAY_FINT_2_INT(rdispls, size); + + while (size > 0) { + c_sendtypes[size - 1] = MPI_Type_f2c(sendtypes[size - 1]); + c_recvtypes[size - 1] = MPI_Type_f2c(recvtypes[size - 1]); + --size; + } + + *ierr = OMPI_INT_2_FINT(MPI_Alltoallw(sendbuf, + OMPI_ARRAY_NAME_CONVERT(sendcounts), + OMPI_ARRAY_NAME_CONVERT(sdispls), + c_sendtypes, + recvbuf, + OMPI_ARRAY_NAME_CONVERT(recvcounts), + OMPI_ARRAY_NAME_CONVERT(rdispls), + c_recvtypes, c_comm)); + + 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); } diff --git a/src/mpi/f77/attr_delete_f.c b/src/mpi/f77/attr_delete_f.c index 6b39b50978..14e6180062 100644 --- a/src/mpi/f77/attr_delete_f.c +++ b/src/mpi/f77/attr_delete_f.c @@ -51,5 +51,6 @@ void mpi_attr_delete_f(MPI_Fint *comm, MPI_Fint *keyval, MPI_Fint *ierr) MPI_Comm c_comm; c_comm = MPI_Comm_f2c(*comm); - *ierr = MPI_Attr_delete(c_comm, *keyval); + *ierr = OMPI_INT_2_FINT(MPI_Attr_delete(c_comm, + OMPI_FINT_2_INT(*keyval))); } diff --git a/src/mpi/f77/attr_get_f.c b/src/mpi/f77/attr_get_f.c index 7503c0e280..1c9ddbbfc6 100644 --- a/src/mpi/f77/attr_get_f.c +++ b/src/mpi/f77/attr_get_f.c @@ -50,8 +50,17 @@ void mpi_attr_get_f(MPI_Fint *comm, MPI_Fint *keyval, char *attribute_val, MPI_Fint *flag, MPI_Fint *ierr) { MPI_Comm c_comm; + int size; + OMPI_ARRAY_NAME_DECL(flag); + size = 1; c_comm = MPI_Comm_f2c(*comm); + + OMPI_ARRAY_FINT_2_INT_ALLOC(flag, size); - *ierr = MPI_Attr_get(c_comm, *keyval, attribute_val, flag); + *ierr = OMPI_INT_2_FINT(MPI_Attr_get(c_comm, + OMPI_FINT_2_INT(*keyval), + attribute_val, + OMPI_ARRAY_NAME_CONVERT(flag))); + OMPI_ARRAY_INT_2_FINT(flag, size); } diff --git a/src/mpi/f77/attr_put_f.c b/src/mpi/f77/attr_put_f.c index fd5f332c78..c4010c032f 100644 --- a/src/mpi/f77/attr_put_f.c +++ b/src/mpi/f77/attr_put_f.c @@ -53,5 +53,7 @@ void mpi_attr_put_f(MPI_Fint *comm, MPI_Fint *keyval, char *attribute_val, c_comm = MPI_Comm_f2c(*comm); - *ierr = MPI_Attr_put(c_comm, *keyval, attribute_val); + *ierr = OMPI_INT_2_FINT(MPI_Attr_put(c_comm, + OMPI_FINT_2_INT(*keyval), + attribute_val)); } diff --git a/src/mpi/f77/bindings.h b/src/mpi/f77/bindings.h index 0b4f184b24..955b44e616 100644 --- a/src/mpi/f77/bindings.h +++ b/src/mpi/f77/bindings.h @@ -33,6 +33,75 @@ * .h files and lower-level includes "src/mpi/interface/f77/profile" .h files */ +/* + * Define MACROS to take account of different size of MPI_Fint from int + */ + +#if OMPI_SIZEOF_FORTRAN_INT == SIZEOF_INT + #define OMPI_ARRAY_NAME_DECL(a) + #define OMPI_ARRAY_NAME_CONVERT(a) a + #define OMPI_INT_2_FINT(a) a + #define OMPI_FINT_2_INT(a) a + #define OMPI_ARRAY_FINT_2_INT_ALLOC(in, n) + #define OMPI_ARRAY_FINT_2_INT(in, n) + #define OMPI_ARRAY_INT_2_FINT(in, n) + #define OMPI_ARRAY_FINT_2_INT_CLEANUP(in) + +#elif OMPI_SIZEOF_FORTRAN_INT > SIZEOF_INT + #define OMPI_ARRAY_NAME_DECL(a) int *c_##a + #define OMPI_ARRAY_NAME_CONVERT(a) c_##a + #define OMPI_INT_2_FINT(a) (a) + #define OMPI_FINT_2_INT(a) (int) (a) + + /* This is for OUT parameters. Does only alloc */ + #define OMPI_ARRAY_FINT_2_INT_ALLOC(in, n) \ + OMPI_ARRAY_NAME_CONVERT(in) = malloc(n * sizeof(int)) + + /* This is for IN/IN-OUT parameters. Does alloc and assignment */ + #define OMPI_ARRAY_FINT_2_INT(in, n) \ + OMPI_ARRAY_NAME_CONVERT(in) = malloc(n * sizeof(int)); \ + while(n > 0) { \ + OMPI_ARRAY_NAME_CONVERT(in)[n - 1] = (int) in[n - 1]; \ + --n; \ + } + + /* This is for OUT/IN-OUT parametes. Does back assignment and free */ + #define OMPI_ARRAY_INT_2_FINT(in, n) \ + while(n > 0) {\ + in[n - 1] = OMPI_ARRAY_NAME_CONVERT(in)[n - 1]; \ + --n; \ + } \ + free(OMPI_ARRAY_NAME_CONVERT(in)) + + /* This is for IN parameters. Does only free */ + #define OMPI_ARRAY_FINT_2_INT_CLEANUP(in) \ + free(OMPI_ARRAY_NAME_CONVERT(in)) + +#else /* int > MPI_Fint */ + #define OMPI_ARRAY_NAME_DECL(a) int *c_##a + #define OMPI_ARRAY_NAME_CONVERT(a) c_##a + #define OMPI_INT_2_FINT(a) (MPI_Fint)(a) + #define OMPI_FINT_2_INT(a) (a) + + #define OMPI_ARRAY_INT_2_FINT(in, n) \ + while(n > 0) {\ + in[n - 1] = (MPI_Fint) OMPI_ARRAY_NAME_CONVERT(in)[n - 1]; \ + --n; \ + } \ + free(OMPI_ARRAY_NAME_CONVERT(in)) + + #define OMPI_ARRAY_FINT_2_INT_CLEANUP(in) \ + free(OMPI_ARRAY_NAME_CONVERT(in)) + + #define OMPI_ARRAY_FINT_2_INT(in, n) \ + OMPI_ARRAY_NAME_CONVERT(in) = malloc(n * sizeof(int)); \ + while(n > 0) { \ + OMPI_ARRAY_NAME_CONVERT(in)[n - 1] = in[n - 1]; \ + --n; \ + } + +#endif + #include "mpi/f77/prototypes_mpi.h" #include "mpi/f77/profile/prototypes_pmpi.h"