123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341 |
- #ifndef BOOST_MPI_GROUP_HPP
- #define BOOST_MPI_GROUP_HPP
- #include <boost/mpi/exception.hpp>
- #include <boost/mpi/detail/antiques.hpp>
- #include <boost/shared_ptr.hpp>
- #include <boost/optional.hpp>
- #include <vector>
- namespace boost { namespace mpi {
- class BOOST_MPI_DECL group
- {
- public:
-
- group() : group_ptr() { }
-
- group(const MPI_Group& in_group, bool adopt);
-
- optional<int> rank() const;
-
- int size() const;
-
- template<typename InputIterator, typename OutputIterator>
- OutputIterator translate_ranks(InputIterator first, InputIterator last,
- const group& to_group, OutputIterator out);
-
- operator bool() const { return (bool)group_ptr; }
-
- operator MPI_Group() const
- {
- if (group_ptr)
- return *group_ptr;
- else
- return MPI_GROUP_EMPTY;
- }
-
- template<typename InputIterator>
- group include(InputIterator first, InputIterator last);
-
- template<typename InputIterator>
- group exclude(InputIterator first, InputIterator last);
-
- protected:
-
- struct group_free
- {
- void operator()(MPI_Group* comm) const
- {
- int finalized;
- BOOST_MPI_CHECK_RESULT(MPI_Finalized, (&finalized));
- if (!finalized)
- BOOST_MPI_CHECK_RESULT(MPI_Group_free, (comm));
- delete comm;
- }
- };
-
- shared_ptr<MPI_Group> group_ptr;
- };
- BOOST_MPI_DECL bool operator==(const group& g1, const group& g2);
- inline bool operator!=(const group& g1, const group& g2)
- {
- return !(g1 == g2);
- }
- BOOST_MPI_DECL group operator|(const group& g1, const group& g2);
- BOOST_MPI_DECL group operator&(const group& g1, const group& g2);
- BOOST_MPI_DECL group operator-(const group& g1, const group& g2);
- template<typename InputIterator, typename OutputIterator>
- OutputIterator
- group::translate_ranks(InputIterator first, InputIterator last,
- const group& to_group, OutputIterator out)
- {
- std::vector<int> in_array(first, last);
- if (in_array.empty())
- return out;
- std::vector<int> out_array(in_array.size());
- BOOST_MPI_CHECK_RESULT(MPI_Group_translate_ranks,
- ((MPI_Group)*this,
- in_array.size(),
- detail::c_data(in_array),
- (MPI_Group)to_group,
- detail::c_data(out_array)));
- for (std::vector<int>::size_type i = 0, n = out_array.size(); i < n; ++i)
- *out++ = out_array[i];
- return out;
- }
- template<>
- BOOST_MPI_DECL int*
- group::translate_ranks(int* first, int* last, const group& to_group, int* out);
- template<typename InputIterator>
- group group::include(InputIterator first, InputIterator last)
- {
- if (first == last)
- return group();
- std::vector<int> ranks(first, last);
- MPI_Group result;
- BOOST_MPI_CHECK_RESULT(MPI_Group_incl,
- ((MPI_Group)*this, ranks.size(), detail::c_data(ranks), &result));
- return group(result, true);
- }
- template<> BOOST_MPI_DECL group group::include(int* first, int* last);
- template<typename InputIterator>
- group group::exclude(InputIterator first, InputIterator last)
- {
- if (first == last)
- return group();
- std::vector<int> ranks(first, last);
- MPI_Group result;
- BOOST_MPI_CHECK_RESULT(MPI_Group_excl,
- ((MPI_Group)*this, ranks.size(), detail::c_data(ranks), &result));
- return group(result, true);
- }
- template<> BOOST_MPI_DECL group group::exclude(int* first, int* last);
- } }
- #endif
|