diff --git a/NEWS b/NEWS index 5c49d84ee4..6b581c4425 100644 --- a/NEWS +++ b/NEWS @@ -29,6 +29,8 @@ version 1.0. 1.0.2 ----- +- Fixed some more C++ const_cast<> issues. Thanks for Martin Audet + (again) for bringing this to our attention. - Updated ROMIO with the version from MPICH 1.2.7p1, marked as version 2005-06-09. - Fixes for some cases where the use of MPI_BOTTOM could cause diff --git a/ompi/mpi/cxx/errhandler.h b/ompi/mpi/cxx/errhandler.h index 15b02d11cc..bac5f0d4d2 100644 --- a/ompi/mpi/cxx/errhandler.h +++ b/ompi/mpi/cxx/errhandler.h @@ -124,7 +124,7 @@ public: #if ! 0 /* OMPI_ENABLE_MPI_PROFILING */ // $%%@#%# AIX/POE 2.3.0.0 makes us put in this cast here (void)MPI_Errhandler_create((MPI_Handler_function*) &ompi_mpi_cxx_throw_excptn_fctn, - (MPI_Errhandler *) &mpi_errhandler); + const_cast &mpi_errhandler); #else pmpi_errhandler.init(); #endif @@ -134,7 +134,7 @@ public: //this is called from MPI::Finalize inline void free() const { #if ! 0 /* OMPI_ENABLE_MPI_PROFILING */ - (void)MPI_Errhandler_free((MPI_Errhandler *) &mpi_errhandler); + (void)MPI_Errhandler_free(const_cast &mpi_errhandler); #else pmpi_errhandler.free(); #endif diff --git a/ompi/mpi/cxx/intracomm.h b/ompi/mpi/cxx/intracomm.h index 575cf16d0a..20f2a0b2e6 100644 --- a/ompi/mpi/cxx/intracomm.h +++ b/ompi/mpi/cxx/intracomm.h @@ -228,6 +228,12 @@ protected: PMPI::Intracomm pmpi_comm; #endif + // Convert an array of p_nbr Info object into an array of MPI_Info. + // A pointer to the allocated array is returned and must be + // eventually deleted. + static inline MPI_Info *convert_info_to_mpi_info(int p_nbr, + const Info p_info_tbl[]); + public: // JGS see above about friend decls #if ! 0 /* OMPI_ENABLE_MPI_PROFILING */ static Op* current_op; diff --git a/ompi/mpi/cxx/intracomm_inln.h b/ompi/mpi/cxx/intracomm_inln.h index bc29773b34..cf59859615 100644 --- a/ompi/mpi/cxx/intracomm_inln.h +++ b/ompi/mpi/cxx/intracomm_inln.h @@ -144,13 +144,25 @@ MPI::Intracomm::Alltoallw(const void *sendbuf, const int sendcounts[], void *recvbuf, const int recvcounts[], const int rdispls[], const Datatype recvtypes[]) const { - (void)MPI_Alltoallw(const_cast(sendbuf), - const_cast(sendcounts), - const_cast(sdispls), - (MPI_Datatype *)(sendtypes), recvbuf, - const_cast(recvcounts), - const_cast(rdispls), - (MPI_Datatype *)(recvtypes), mpi_comm); + const int comm_size = Get_size(); + MPI_Datatype *const data_type_tbl = new MPI_Datatype [2*comm_size]; + + // This must be done because MPI::Datatype arrays cannot be + // converted directly into MPI_Datatype arrays. + for (int i_rank=0; i_rank < comm_size; i_rank++) { + data_type_tbl[i_rank] = sendtypes[i_rank]; + data_type_tbl[i_rank + comm_size] = recvtypes[i_rank]; + } + + (void)MPI_Alltoallw(const_cast(sendbuf), + const_cast(sendcounts), + const_cast(sdispls), + data_type_tbl, recvbuf, + const_cast(recvcounts), + const_cast(rdispls), + data_type_tbl[comm_size], mpi_comm); + + delete[] data_type_tbl; } inline void @@ -158,7 +170,7 @@ MPI::Intracomm::Reduce(const void *sendbuf, void *recvbuf, int count, const MPI::Datatype & datatype, const MPI::Op& op, int root) const { - current_op = (MPI::Op*)&op; + current_op = const_cast(&op); (void)MPI_Reduce(const_cast(sendbuf), recvbuf, count, datatype, op, root, mpi_comm); current_op = (Op*)0; } @@ -167,7 +179,7 @@ inline void MPI::Intracomm::Allreduce(const void *sendbuf, void *recvbuf, int count, const MPI::Datatype & datatype, const MPI::Op& op) const { - current_op = (MPI::Op*)&op; + current_op = const_cast(&op); (void)MPI_Allreduce (const_cast(sendbuf), recvbuf, count, datatype, op, mpi_comm); current_op = (Op*)0; } @@ -178,7 +190,7 @@ MPI::Intracomm::Reduce_scatter(const void *sendbuf, void *recvbuf, const MPI::Datatype & datatype, const MPI::Op& op) const { - current_op = (MPI::Op*)&op; + current_op = const_cast(&op); (void)MPI_Reduce_scatter(const_cast(sendbuf), recvbuf, recvcounts, datatype, op, mpi_comm); current_op = (Op*)0; @@ -188,7 +200,7 @@ inline void MPI::Intracomm::Scan(const void *sendbuf, void *recvbuf, int count, const MPI::Datatype & datatype, const MPI::Op& op) const { - current_op = (MPI::Op*)&op; + current_op = const_cast(&op); (void)MPI_Scan(const_cast(sendbuf), recvbuf, count, datatype, op, mpi_comm); current_op = (Op*)0; } @@ -198,7 +210,7 @@ MPI::Intracomm::Exscan(const void *sendbuf, void *recvbuf, int count, const MPI::Datatype & datatype, const MPI::Op& op) const { - current_op = (MPI::Op*)&op; + current_op = const_cast(&op); (void)MPI_Exscan(const_cast(sendbuf), recvbuf, count, datatype, op, mpi_comm); current_op = (Op*)0; } @@ -337,13 +349,29 @@ MPI::Intracomm::Spawn_multiple(int count, const Info array_of_info[], int root) { MPI_Comm newcomm; + MPI_Info *const array_of_mpi_info = + convert_info_to_mpi_info(count, array_of_info); + MPI_Comm_spawn_multiple(count, const_cast(array_of_commands), - const_cast(array_of_argv), const_cast(array_of_maxprocs), - (MPI_Info *) array_of_info, root, + const_cast(array_of_argv), + const_cast(array_of_maxprocs), + array_of_mpi_info, root, mpi_comm, &newcomm, (int *)MPI_ERRCODES_IGNORE); + delete[] array_of_mpi_info; return newcomm; } +inline MPI_Info * +MPI::Intracomm::convert_info_to_mpi_info(int p_nbr, const Info p_info_tbl[]) +{ + MPI_Info *const mpi_info_tbl = new MPI_Info [p_nbr]; + + for (int i_tbl=0; i_tbl < p_nbr; i_tbl++) { + mpi_info_tbl[i_tbl] = p_info_tbl[i_tbl]; + } + + return mpi_info_tbl; +} inline MPI::Intercomm MPI::Intracomm::Spawn_multiple(int count, @@ -354,10 +382,15 @@ MPI::Intracomm::Spawn_multiple(int count, int array_of_errcodes[]) { MPI_Comm newcomm; + MPI_Info *const array_of_mpi_info = + convert_info_to_mpi_info(count, array_of_info); + MPI_Comm_spawn_multiple(count, const_cast(array_of_commands), - const_cast(array_of_argv), const_cast(array_of_maxprocs), - (MPI_Info *) array_of_info, root, + const_cast(array_of_argv), + const_cast(array_of_maxprocs), + array_of_mpi_info, root, mpi_comm, &newcomm, array_of_errcodes); + delete[] array_of_mpi_info; return newcomm; }