Skip to content

Feature/non blocking common #106

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 6 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions include/boost/mpi/communicator.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -775,6 +775,15 @@ class BOOST_MPI_DECL communicator
void barrier() const;
#endif

#if BOOST_MPI_VERSION >= 3
/**
* @brief Non blocking version of barrier.
*
* This version will return immediatly. The request completes
* once all participants have reached the barrier.
*/
request ibarrier() const;
#endif
/** @brief Determine if this communicator is valid for
* communication.
*
Expand Down
2 changes: 1 addition & 1 deletion include/boost/mpi/config.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
#endif

#if defined MPI_SUBVERSION
/** @brief Major version of the underlying MPI implementation supproted standard.
/** @brief Major version of the underlying MPI implementation supported standard.
*
* If, for some reason, MPI_SUBVERSION is not supported, you should probably set that
* according to your MPI documentation
Expand Down
3 changes: 3 additions & 0 deletions include/boost/mpi/detail/request_handlers.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -509,6 +509,9 @@ class BOOST_MPI_DECL request::trivial_handler : public request::handler {

private:
friend class request;
#if BOOST_MPI_VERSION >= 3
friend class communicator;
#endif
MPI_Request m_request;
};

Expand Down
7 changes: 7 additions & 0 deletions include/boost/mpi/request.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,11 @@ class BOOST_MPI_DECL request
*/
request();

/**
* Just make a request from a C API request and provide its address
* for future assignement.
*/
static request make_trivial(MPI_Request*& r);
/**
* Send a known number of primitive objects in one MPI request.
*/
Expand Down Expand Up @@ -150,7 +155,9 @@ class BOOST_MPI_DECL request
template<typename T, class A> class legacy_dynamic_primitive_array_handler;
#if BOOST_MPI_VERSION >= 3
template<class Data> class probe_handler;
friend class communicator;
#endif

private:
shared_ptr<handler> m_handler;
shared_ptr<void> m_preserved;
Expand Down
11 changes: 10 additions & 1 deletion src/communicator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,6 @@ void (communicator::barrier)() const
BOOST_MPI_CHECK_RESULT(MPI_Barrier, (MPI_Comm(*this)));
}


communicator::operator MPI_Comm() const
{
if (comm_ptr) return *comm_ptr;
Expand Down Expand Up @@ -325,4 +324,14 @@ bool operator==(const communicator& comm1, const communicator& comm2)
return result == MPI_IDENT;
}

// Non blocking common
#if BOOST_MPI_VERSION >= 3
request communicator::ibarrier() const
{
request::trivial_handler* handler = new request::trivial_handler;
BOOST_MPI_CHECK_RESULT(MPI_Ibarrier, (*this, &handler->m_request));
return request(handler);
}
#endif

} } // end namespace boost::mpi
7 changes: 7 additions & 0 deletions src/request.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,13 @@ request::preserve(boost::shared_ptr<void> d) {
}
request request::make_dynamic() { return request(new dynamic_handler()); }

request request::make_trivial(MPI_Request*& r) {
trivial_handler *handler = new trivial_handler;
r = &(handler->m_request);
return request(handler);
}


request
request::make_bottom_send(communicator const& comm, int dest, int tag, MPI_Datatype tp) {
trivial_handler* handler = new trivial_handler;
Expand Down
4 changes: 3 additions & 1 deletion test/Jamfile.v2
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,9 @@ test-suite mpi
[ mpi-test groups_test ]
# tests that require -std=c++11
[ mpi-test sendrecv_vector : : : 2 ]
# Intel MPI 2018 and older are axtected to fail:
# Intel MPI 2018 and older are expected to fail:
[ mpi-test non_blocking_any_source : : : 2 17 ]
# Non Blockin common (MPI 3 only)
[ mpi-test ibarrier_test : : : 1 3 ]
;
}
42 changes: 42 additions & 0 deletions test/ibarrier_test.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
// Copyright Alain Miniussi 2014.
// Distributed under 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)

// A test of the non blocking barrier operation.

#include <boost/mpi/communicator.hpp>
#include <boost/mpi/environment.hpp>


#define BOOST_TEST_MODULE mpi_ibarrier
#include <boost/test/included/unit_test.hpp>

namespace mpi = boost::mpi;

BOOST_AUTO_TEST_CASE(ibarrier_check)
{
mpi::environment env;
mpi::communicator world;

std::ostringstream buf;
int rk = world.rank();
buf << "rk" << rk << ": calling ibarrier.\n";
std::cout << buf.str();
mpi::request r = world.ibarrier();
if (rk == 0) {
while (!r.test()) {
buf << "rk" << rk << ": not completed yet.\n";
std::cout << buf.str();
}
buf << "rk" << rk << ": completed.\n";
std::cout << buf.str();
} else {
buf << "rk" << rk << ": waiting...";
std::cout << buf.str() << std::flush;
r.wait();
buf << "rk" << rk << ": done.\n";
std::cout << buf.str();
}
BOOST_TEST(true);
}
2 changes: 1 addition & 1 deletion test/sendrecv_test.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright Alain Miniussi 20014.
// Copyright Alain Miniussi 2014.
// Distributed under 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)
Expand Down