From 9d8f15146bbdecd755d9aa23e2dd22dce1b92d0c Mon Sep 17 00:00:00 2001 From: Alain Miniussi Date: Wed, 1 Aug 2018 15:08:35 +0200 Subject: [PATCH] Try to make sure user's operators are stateless, and do not use their state if any. refs #68 --- include/boost/mpi/collectives/all_reduce.hpp | 2 +- include/boost/mpi/collectives/reduce.hpp | 4 ++-- include/boost/mpi/collectives/scan.hpp | 2 +- include/boost/mpi/operations.hpp | 10 +++------- 4 files changed, 7 insertions(+), 11 deletions(-) diff --git a/include/boost/mpi/collectives/all_reduce.hpp b/include/boost/mpi/collectives/all_reduce.hpp index 06e116a..0793112 100644 --- a/include/boost/mpi/collectives/all_reduce.hpp +++ b/include/boost/mpi/collectives/all_reduce.hpp @@ -51,7 +51,7 @@ namespace detail { T* out_values, Op op, mpl::false_ /*is_mpi_op*/, mpl::true_ /*is_mpi_datatype*/) { - user_op mpi_op(op); + user_op mpi_op; BOOST_MPI_CHECK_RESULT(MPI_Allreduce, (const_cast(in_values), out_values, n, boost::mpi::get_mpi_datatype(*in_values), diff --git a/include/boost/mpi/collectives/reduce.hpp b/include/boost/mpi/collectives/reduce.hpp index 1e2722e..3248e32 100644 --- a/include/boost/mpi/collectives/reduce.hpp +++ b/include/boost/mpi/collectives/reduce.hpp @@ -81,7 +81,7 @@ namespace detail { T* out_values, Op op, int root, mpl::false_ /*is_mpi_op*/, mpl::true_/*is_mpi_datatype*/) { - user_op mpi_op(op); + user_op mpi_op; BOOST_MPI_CHECK_RESULT(MPI_Reduce, (const_cast(in_values), out_values, n, boost::mpi::get_mpi_datatype(*in_values), @@ -96,7 +96,7 @@ namespace detail { reduce_impl(const communicator& comm, const T* in_values, int n, Op op, int root, mpl::false_/*is_mpi_op*/, mpl::true_/*is_mpi_datatype*/) { - user_op mpi_op(op); + user_op mpi_op; BOOST_MPI_CHECK_RESULT(MPI_Reduce, (const_cast(in_values), 0, n, boost::mpi::get_mpi_datatype(*in_values), diff --git a/include/boost/mpi/collectives/scan.hpp b/include/boost/mpi/collectives/scan.hpp index 9264838..a840436 100644 --- a/include/boost/mpi/collectives/scan.hpp +++ b/include/boost/mpi/collectives/scan.hpp @@ -67,7 +67,7 @@ namespace detail { scan_impl(const communicator& comm, const T* in_values, int n, T* out_values, Op op, mpl::false_ /*is_mpi_op*/, mpl::true_ /*is_mpi_datatype*/) { - user_op mpi_op(op); + user_op mpi_op; BOOST_MPI_CHECK_RESULT(MPI_Scan, (const_cast(in_values), out_values, n, boost::mpi::get_mpi_datatype(*in_values), diff --git a/include/boost/mpi/operations.hpp b/include/boost/mpi/operations.hpp index b72b13d..5af8c8f 100644 --- a/include/boost/mpi/operations.hpp +++ b/include/boost/mpi/operations.hpp @@ -292,14 +292,12 @@ namespace detail { class user_op { public: - explicit user_op(Op& op) + user_op() { BOOST_MPI_CHECK_RESULT(MPI_Op_create, (&user_op::perform, is_commutative::value, &mpi_op)); - - op_ptr = &op; } ~user_op() @@ -321,18 +319,16 @@ namespace detail { private: MPI_Op mpi_op; - static Op* op_ptr; static void BOOST_MPI_CALLING_CONVENTION perform(void* vinvec, void* voutvec, int* plen, MPI_Datatype*) { T* invec = static_cast(vinvec); T* outvec = static_cast(voutvec); - std::transform(invec, invec + *plen, outvec, outvec, *op_ptr); + Op op; + std::transform(invec, invec + *plen, outvec, outvec, op); } }; - template Op* user_op::op_ptr = 0; - } // end namespace detail } } // end namespace boost::mpi