1 // Copyright (C) 2007 Trustees of Indiana University
3 // Authors: Douglas Gregor
6 // Use, modification and distribution is subject to the Boost Software
7 // License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
8 // http://www.boost.org/LICENSE_1_0.txt)
9 #include <boost/mpi/group.hpp>
10 #include <boost/mpi/communicator.hpp>
12 namespace boost
{ namespace mpi
{
14 group::group(const MPI_Group
& in_group
, bool adopt
)
16 if (in_group
!= MPI_GROUP_EMPTY
) {
17 if (adopt
) group_ptr
.reset(new MPI_Group(in_group
), group_free());
18 else group_ptr
.reset(new MPI_Group(in_group
));
22 optional
<int> group::rank() const
25 return optional
<int>();
28 BOOST_MPI_CHECK_RESULT(MPI_Group_rank
, (*group_ptr
, &rank
));
29 if (rank
== MPI_UNDEFINED
)
30 return optional
<int>();
35 int group::size() const
41 BOOST_MPI_CHECK_RESULT(MPI_Group_size
, (*group_ptr
, &size
));
45 bool operator==(const group
& g1
, const group
& g2
)
48 BOOST_MPI_CHECK_RESULT(MPI_Group_compare
,
49 ((MPI_Group
)g1
, (MPI_Group
)g2
, &result
));
50 return result
== MPI_IDENT
;
53 group
operator|(const group
& g1
, const group
& g2
)
56 BOOST_MPI_CHECK_RESULT(MPI_Group_union
,
57 ((MPI_Group
)g1
, (MPI_Group
)g2
, &result
));
58 return group(result
, /*adopt=*/true);
61 group
operator&(const group
& g1
, const group
& g2
)
64 BOOST_MPI_CHECK_RESULT(MPI_Group_intersection
,
65 ((MPI_Group
)g1
, (MPI_Group
)g2
, &result
));
66 return group(result
, /*adopt=*/true);
69 group
operator-(const group
& g1
, const group
& g2
)
72 BOOST_MPI_CHECK_RESULT(MPI_Group_difference
,
73 ((MPI_Group
)g1
, (MPI_Group
)g2
, &result
));
74 return group(result
, /*adopt=*/true);
79 group::translate_ranks(int* first
, int* last
, const group
& to_group
, int* out
)
81 BOOST_MPI_CHECK_RESULT(MPI_Group_translate_ranks
,
87 return out
+ (last
- first
);
90 template<> group
group::include(int* first
, int* last
)
93 BOOST_MPI_CHECK_RESULT(MPI_Group_incl
,
94 ((MPI_Group
)*this, last
- first
, first
, &result
));
95 return group(result
, /*adopt=*/true);
98 template<> group
group::exclude(int* first
, int* last
)
101 BOOST_MPI_CHECK_RESULT(MPI_Group_excl
,
102 ((MPI_Group
)*this, last
- first
, first
, &result
));
103 return group(result
, /*adopt=*/true);
106 } } // end namespace boost::mpi