]>
git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/mpi/test/all_to_all_test.cpp
1 // Copyright (C) 2005, 2006 Douglas Gregor.
3 // Use, modification and distribution is subject to the Boost Software
4 // License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
5 // http://www.boost.org/LICENSE_1_0.txt)
7 // A test of the all_to_all() collective.
8 #include <boost/mpi/collectives/all_to_all.hpp>
9 #include <boost/mpi/communicator.hpp>
10 #include <boost/mpi/environment.hpp>
12 #include "gps_position.hpp"
13 #include <boost/serialization/string.hpp>
14 #include <boost/serialization/list.hpp>
15 #include <boost/iterator/counting_iterator.hpp>
16 #include <boost/lexical_cast.hpp>
18 #define BOOST_TEST_MODULE mpi_all_to_all
19 #include <boost/test/included/unit_test.hpp>
21 using boost::mpi::communicator
;
23 using boost::mpi::packed_skeleton_iarchive
;
24 using boost::mpi::packed_skeleton_oarchive
;
26 template<typename Generator
>
28 all_to_all_test(const communicator
& comm
, Generator generator
,
31 typedef typename
Generator::result_type value_type
;
33 using boost::mpi::all_to_all
;
35 std::vector
<value_type
> in_values
;
36 for (int p
= 0; p
< comm
.size(); ++p
)
37 in_values
.push_back(generator((p
+ 1) * (comm
.rank() + 1)));
39 if (comm
.rank() == 0) {
40 std::cout
<< "Performing all-to-all operation on " << kind
<< "...";
43 std::vector
<value_type
> out_values
;
44 all_to_all(comm
, in_values
, out_values
);
46 for (int p
= 0; p
< comm
.size(); ++p
) {
47 BOOST_CHECK(out_values
[p
] == generator((p
+ 1) * (comm
.rank() + 1)));
50 if (comm
.rank() == 0) {
51 std::cout
<< " done." << std::endl
;
57 // Generates integers to test with all_to_all()
60 typedef int result_type
;
62 int operator()(int p
) const { return 17 + p
; }
65 // Generates GPS positions to test with all_to_all()
68 typedef gps_position result_type
;
70 gps_position
operator()(int p
) const
72 return gps_position(39 + p
, 16, 20.2799);
76 struct string_generator
78 typedef std::string result_type
;
80 std::string
operator()(int p
) const
82 std::string result
= boost::lexical_cast
<std::string
>(p
);
84 if (p
!= 1) result
+= 's';
89 struct string_list_generator
91 typedef std::list
<std::string
> result_type
;
93 std::list
<std::string
> operator()(int p
) const
95 std::list
<std::string
> result
;
96 for (int i
= 0; i
<= p
; ++i
) {
97 std::string value
= boost::lexical_cast
<std::string
>(i
);
98 result
.push_back(value
);
104 BOOST_AUTO_TEST_CASE(all_to_all_check
)
106 boost::mpi::environment env
;
109 all_to_all_test(comm
, int_generator(), "integers");
110 all_to_all_test(comm
, gps_generator(), "GPS positions");
111 all_to_all_test(comm
, string_generator(), "string");
112 all_to_all_test(comm
, string_list_generator(), "list of strings");