mirror of
https://github.com/boostorg/mpi.git
synced 2026-01-19 04:22:10 +00:00
Add the boost/mpi/optional.hpp file to host the using directive to access boost::optional as boost::mpi::optional
Propagate the change
This commit is contained in:
@@ -6,12 +6,13 @@
|
||||
|
||||
// An example using Boost.MPI's split() operation on communicators to
|
||||
// create separate data-generating processes and data-collecting
|
||||
// processes using boost::optional for broadcasting.
|
||||
// processes using boost::mpi::optional for broadcasting.
|
||||
#include <boost/mpi.hpp>
|
||||
#include <iostream>
|
||||
#include <cstdlib>
|
||||
#include <boost/serialization/vector.hpp>
|
||||
#include <boost/serialization/optional.hpp>
|
||||
#include <boost/mpi/optional.hpp>
|
||||
namespace mpi = boost::mpi;
|
||||
|
||||
enum message_tags { msg_data_packet, msg_finished };
|
||||
@@ -61,8 +62,8 @@ void collect_data(mpi::communicator local, mpi::communicator world)
|
||||
// Wait for a message
|
||||
mpi::status msg = world.probe();
|
||||
if (msg.tag() == msg_data_packet) {
|
||||
// Receive the packet of data into a boost::optional
|
||||
boost::optional<std::vector<int> > data;
|
||||
// Receive the packet of data into a boost::mpi::optional
|
||||
boost::mpi::optional<std::vector<int> > data;
|
||||
data = std::vector<int>();
|
||||
world.recv(msg.source(), msg.source(), *data);
|
||||
|
||||
@@ -73,13 +74,13 @@ void collect_data(mpi::communicator local, mpi::communicator world)
|
||||
world.recv(msg.source(), msg.tag());
|
||||
|
||||
// Broadcast to each collector to tell them we've finished.
|
||||
boost::optional<std::vector<int> > data;
|
||||
boost::mpi::optional<std::vector<int> > data;
|
||||
broadcast(local, data, 0);
|
||||
break;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
boost::optional<std::vector<int> > data;
|
||||
boost::mpi::optional<std::vector<int> > data;
|
||||
do {
|
||||
// Wait for a broadcast from the master collector
|
||||
broadcast(local, data, 0);
|
||||
|
||||
@@ -23,6 +23,7 @@
|
||||
#include <boost/mpi/collectives.hpp>
|
||||
#include <boost/mpi/communicator.hpp>
|
||||
#include <boost/mpi/datatype.hpp>
|
||||
#include <boost/mpi/optional.hpp>
|
||||
#include <boost/mpi/environment.hpp>
|
||||
#include <boost/mpi/graph_communicator.hpp>
|
||||
#include <boost/mpi/group.hpp>
|
||||
|
||||
@@ -17,7 +17,7 @@
|
||||
#include <boost/assert.hpp>
|
||||
#include <boost/mpi/config.hpp>
|
||||
#include <boost/mpi/exception.hpp>
|
||||
#include <boost/optional.hpp>
|
||||
#include <boost/mpi/optional.hpp>
|
||||
#include <boost/shared_ptr.hpp>
|
||||
#include <boost/mpi/datatype.hpp>
|
||||
#include <boost/mpi/nonblocking.hpp>
|
||||
@@ -752,7 +752,7 @@ class BOOST_MPI_DECL communicator
|
||||
*
|
||||
* @returns If a matching message is available, returns
|
||||
* information about that message. Otherwise, returns an empty
|
||||
* @c boost::optional.
|
||||
* @c boost::mpi::optional.
|
||||
*/
|
||||
optional<status>
|
||||
iprobe(int source = any_source, int tag = any_tag) const;
|
||||
|
||||
@@ -14,8 +14,8 @@
|
||||
#define BOOST_MPI_ENVIRONMENT_HPP
|
||||
|
||||
#include <boost/mpi/config.hpp>
|
||||
#include <boost/mpi/optional.hpp>
|
||||
#include <boost/noncopyable.hpp>
|
||||
#include <boost/optional.hpp>
|
||||
#include <string>
|
||||
#include <iosfwd>
|
||||
|
||||
|
||||
@@ -18,7 +18,7 @@
|
||||
#include <boost/mpi/exception.hpp>
|
||||
#include <boost/mpi/detail/antiques.hpp>
|
||||
#include <boost/shared_ptr.hpp>
|
||||
#include <boost/optional.hpp>
|
||||
#include <boost/mpi/optional.hpp>
|
||||
#include <vector>
|
||||
|
||||
namespace boost { namespace mpi {
|
||||
|
||||
@@ -15,7 +15,7 @@
|
||||
#include <boost/mpi/config.hpp>
|
||||
#include <vector>
|
||||
#include <iterator> // for std::iterator_traits
|
||||
#include <boost/optional.hpp>
|
||||
#include <boost/mpi/optional.hpp>
|
||||
#include <utility> // for std::pair
|
||||
#include <algorithm> // for iter_swap, reverse
|
||||
#include <boost/static_assert.hpp>
|
||||
|
||||
18
include/boost/mpi/optional.hpp
Normal file
18
include/boost/mpi/optional.hpp
Normal file
@@ -0,0 +1,18 @@
|
||||
// Copyright (C) 2025 Alain Miniussi <alain.miniussi -at- oca.eu>.
|
||||
|
||||
// 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)
|
||||
|
||||
#ifndef BOOST_MPI_OPTIONAL_HPP
|
||||
#define BOOST_MPI_OPTIONAL_HPP
|
||||
|
||||
#include <boost/mpi/config.hpp>
|
||||
|
||||
#include <boost/optional.hpp>
|
||||
|
||||
namespace boost { namespace mpi {
|
||||
template <typename T> using optional = boost::optional<T>;
|
||||
}}
|
||||
|
||||
#endif // BOOST_MPI_OPTIONAL_HPP
|
||||
@@ -14,7 +14,7 @@
|
||||
|
||||
#include <boost/mpi/config.hpp>
|
||||
#include <boost/mpi/status.hpp>
|
||||
#include <boost/optional.hpp>
|
||||
#include <boost/mpi/optional.hpp>
|
||||
#include <boost/shared_ptr.hpp>
|
||||
#include <boost/mpi/packed_iarchive.hpp>
|
||||
|
||||
|
||||
@@ -14,7 +14,7 @@
|
||||
|
||||
#include <boost/mpi/config.hpp>
|
||||
#include <boost/mpi/datatype.hpp>
|
||||
#include <boost/optional.hpp>
|
||||
#include <boost/mpi/optional.hpp>
|
||||
#include <boost/mpl/bool.hpp>
|
||||
|
||||
namespace boost { namespace mpi {
|
||||
|
||||
@@ -62,7 +62,7 @@ communicator_irecv(const communicator& comm, int source, int tag)
|
||||
object
|
||||
communicator_iprobe(const communicator& comm, int source, int tag)
|
||||
{
|
||||
if (boost::optional<status> result = comm.iprobe(source, tag))
|
||||
if (boost::mpi::optional<status> result = comm.iprobe(source, tag))
|
||||
return object(*result);
|
||||
else
|
||||
return object();
|
||||
|
||||
@@ -125,7 +125,7 @@ namespace
|
||||
object wrap_test_any(request_list &requests)
|
||||
{
|
||||
check_request_list_not_empty(requests);
|
||||
::boost::optional<pair<status, request_list::iterator> > result =
|
||||
::boost::mpi::optional<pair<status, request_list::iterator> > result =
|
||||
test_any(requests.begin(), requests.end());
|
||||
|
||||
if (result)
|
||||
|
||||
@@ -52,7 +52,7 @@ const object python::request_with_value::wrap_wait()
|
||||
|
||||
const object python::request_with_value::wrap_test()
|
||||
{
|
||||
::boost::optional<status> stat = request::test();
|
||||
::boost::mpi::optional<status> stat = request::test();
|
||||
if (stat)
|
||||
{
|
||||
if (m_internal_value.get() || m_external_value)
|
||||
@@ -69,7 +69,7 @@ namespace boost { namespace mpi { namespace python {
|
||||
|
||||
const object request_test(request &req)
|
||||
{
|
||||
::boost::optional<status> stat = req.test();
|
||||
::boost::mpi::optional<status> stat = req.test();
|
||||
if (stat)
|
||||
return object(*stat);
|
||||
else
|
||||
|
||||
@@ -8,6 +8,7 @@
|
||||
#include <boost/mpi/nonblocking.hpp>
|
||||
#include <boost/mpi/communicator.hpp>
|
||||
#include <boost/mpi/environment.hpp>
|
||||
#include <boost/mpi/optional.hpp>
|
||||
#include "gps_position.hpp"
|
||||
#include <boost/lexical_cast.hpp>
|
||||
#include <boost/serialization/string.hpp>
|
||||
@@ -122,7 +123,7 @@ nonblocking_test(const communicator& comm, const T* values, int num_values,
|
||||
|
||||
case mk_test_any:
|
||||
{
|
||||
boost::optional<status_iterator_pair> result;
|
||||
boost::mpi::optional<status_iterator_pair> result;
|
||||
do {
|
||||
result = test_any(reqs.begin(), reqs.end());
|
||||
} while (!result);
|
||||
|
||||
@@ -10,6 +10,7 @@
|
||||
// types, serializable objects, etc.)
|
||||
#include <boost/mpi/communicator.hpp>
|
||||
#include <boost/mpi/environment.hpp>
|
||||
#include <boost/mpi/optional.hpp>
|
||||
#include <algorithm>
|
||||
#include "gps_position.hpp"
|
||||
#include <boost/serialization/string.hpp>
|
||||
@@ -70,7 +71,7 @@ ring_array_test(const communicator& comm, const T* pass_values,
|
||||
if (okay) std::cout << " OK." << std::endl;
|
||||
} else {
|
||||
status stat = comm.probe(boost::mpi::any_source, 0);
|
||||
boost::optional<int> num_values = stat.template count<T>();
|
||||
boost::mpi::optional<int> num_values = stat.template count<T>();
|
||||
if (boost::mpi::is_mpi_datatype<T>())
|
||||
BOOST_CHECK(num_values && *num_values == n);
|
||||
else
|
||||
|
||||
@@ -8,6 +8,7 @@
|
||||
#include <boost/mpi/nonblocking.hpp>
|
||||
#include <boost/mpi/communicator.hpp>
|
||||
#include <boost/mpi/environment.hpp>
|
||||
#include <boost/mpi/optional.hpp>
|
||||
#include "gps_position.hpp"
|
||||
#include <boost/lexical_cast.hpp>
|
||||
#include <boost/serialization/string.hpp>
|
||||
@@ -126,7 +127,7 @@ nonblocking_test(const communicator& comm, const T* values, int num_values,
|
||||
|
||||
case mk_test_any:
|
||||
{
|
||||
boost::optional<status_iterator_pair> result;
|
||||
boost::mpi::optional<status_iterator_pair> result;
|
||||
do {
|
||||
result = test_any(reqs.begin(), reqs.end());
|
||||
} while (!result);
|
||||
|
||||
@@ -10,6 +10,7 @@
|
||||
// types, serializable objects, etc.)
|
||||
#include <boost/mpi/communicator.hpp>
|
||||
#include <boost/mpi/environment.hpp>
|
||||
#include <boost/mpi/optional.hpp>
|
||||
#include <algorithm>
|
||||
#include "gps_position.hpp"
|
||||
#include <boost/serialization/string.hpp>
|
||||
@@ -72,7 +73,7 @@ ring_array_test(const communicator& comm, const T* pass_values,
|
||||
if (okay) std::cout << " OK." << std::endl;
|
||||
} else {
|
||||
status stat = comm.probe(boost::mpi::any_source, 0);
|
||||
boost::optional<int> num_values = stat.template count<T>();
|
||||
boost::mpi::optional<int> num_values = stat.template count<T>();
|
||||
if (boost::mpi::is_mpi_datatype<T>()) {
|
||||
BOOST_MPI_CHECK(num_values && *num_values == n, failed);
|
||||
} else {
|
||||
|
||||
Reference in New Issue
Block a user