From e1aea365fb2bfa6a53feec2ceaed4b628462e612 Mon Sep 17 00:00:00 2001 From: Alain O Miniussi Date: Tue, 23 Jun 2020 10:48:47 +0200 Subject: [PATCH] put status code in status files --- build/Jamfile.v2 | 3 ++- include/boost/mpi/communicator.hpp | 32 ------------------------------ include/boost/mpi/status.hpp | 27 ++++++++++++++++++++++++- src/communicator.cpp | 14 ------------- src/status.cpp | 18 +++++++++++++++++ 5 files changed, 46 insertions(+), 48 deletions(-) create mode 100644 src/status.cpp diff --git a/build/Jamfile.v2 b/build/Jamfile.v2 index 0848384..8a2f1ac 100644 --- a/build/Jamfile.v2 +++ b/build/Jamfile.v2 @@ -46,15 +46,16 @@ lib boost_mpi intercommunicator.cpp mpi_datatype_cache.cpp mpi_datatype_oarchive.cpp + offsets.cpp packed_iarchive.cpp packed_oarchive.cpp packed_skeleton_iarchive.cpp packed_skeleton_oarchive.cpp point_to_point.cpp request.cpp + status.cpp text_skeleton_oarchive.cpp timer.cpp - offsets.cpp : # Requirements ../../serialization/build//boost_serialization /mpi//mpi [ mpi.extra-requirements ] diff --git a/include/boost/mpi/communicator.hpp b/include/boost/mpi/communicator.hpp index 8663ba3..cfa603f 100644 --- a/include/boost/mpi/communicator.hpp +++ b/include/boost/mpi/communicator.hpp @@ -1256,38 +1256,6 @@ communicator::irecv(int source, int tag, return irecv(source, tag, c); } -// Count elements in a message -template -inline optional status::count() const -{ - return count_impl(is_mpi_datatype()); -} - -template -optional status::count_impl(mpl::true_) const -{ - if (m_count != -1) - return m_count; - - int return_value; - BOOST_MPI_CHECK_RESULT(MPI_Get_count, - (&m_status, get_mpi_datatype(T()), &return_value)); - if (return_value == MPI_UNDEFINED) - return optional(); - else - /* Cache the result. */ - return m_count = return_value; -} - -template -inline optional status::count_impl(mpl::false_) const -{ - if (m_count == -1) - return optional(); - else - return m_count; -} - // We're sending a type that has an associated MPI datatype, so we // map directly to that datatype. template diff --git a/include/boost/mpi/status.hpp b/include/boost/mpi/status.hpp index 326c0a8..e82a7a9 100644 --- a/include/boost/mpi/status.hpp +++ b/include/boost/mpi/status.hpp @@ -13,6 +13,7 @@ #define BOOST_MPI_STATUS_HPP #include +#include #include #include @@ -69,7 +70,7 @@ class BOOST_MPI_DECL status * @returns the number of @c T elements in the message, if it can be * determined. */ - template optional count() const; + template optional count() const { return count_impl(is_mpi_datatype()); } /** * References the underlying @c MPI_Status @@ -102,6 +103,30 @@ class BOOST_MPI_DECL status friend class request; }; +template +optional status::count_impl(mpl::true_) const +{ + if (m_count != -1) + return m_count; + + int return_value; + BOOST_MPI_CHECK_RESULT(MPI_Get_count, + (&m_status, get_mpi_datatype(T()), &return_value)); + if (return_value == MPI_UNDEFINED) + return optional(); + else + /* Cache the result. */ + return m_count = return_value; +} + +template +inline optional status::count_impl(mpl::false_) const +{ + if (m_count == -1) + return optional(); + else + return m_count; +} } } // end namespace boost::mpi diff --git a/src/communicator.cpp b/src/communicator.cpp index 016c6af..8f801e3 100644 --- a/src/communicator.cpp +++ b/src/communicator.cpp @@ -13,20 +13,6 @@ namespace boost { namespace mpi { -/*************************************************************************** - * status * - ***************************************************************************/ -bool status::cancelled() const -{ - int flag = 0; - BOOST_MPI_CHECK_RESULT(MPI_Test_cancelled, (&m_status, &flag)); - return flag != 0; -} - -/*************************************************************************** - * communicator * - ***************************************************************************/ - communicator::communicator() { comm_ptr.reset(new MPI_Comm(MPI_COMM_WORLD)); diff --git a/src/status.cpp b/src/status.cpp new file mode 100644 index 0000000..5719ab6 --- /dev/null +++ b/src/status.cpp @@ -0,0 +1,18 @@ +// Copyright (C) 2005, 2006 Douglas Gregor. + +// Use, modification and distribution is subject to the Boost Software +// License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at +// http://www.boost.org/LICENSE_1_0.txt) + +#include + +namespace boost { namespace mpi { + +bool status::cancelled() const +{ + int flag = 0; + BOOST_MPI_CHECK_RESULT(MPI_Test_cancelled, (&m_status, &flag)); + return flag != 0; +} + +}}