]> git.proxmox.com Git - ceph.git/blame - ceph/src/boost/libs/mpi/test/all_to_all_test.cpp
import new upstream nautilus stable release 14.2.8
[ceph.git] / ceph / src / boost / libs / mpi / test / all_to_all_test.cpp
CommitLineData
7c673cae
FG
1// Copyright (C) 2005, 2006 Douglas Gregor.
2
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)
6
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>
7c673cae
FG
11#include <algorithm>
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>
17
92f5a8d4
TL
18#define BOOST_TEST_MODULE mpi_all_to_all
19#include <boost/test/included/unit_test.hpp>
20
7c673cae
FG
21using boost::mpi::communicator;
22
23using boost::mpi::packed_skeleton_iarchive;
24using boost::mpi::packed_skeleton_oarchive;
25
26template<typename Generator>
27void
28all_to_all_test(const communicator& comm, Generator generator,
29 const char* kind)
30{
31 typedef typename Generator::result_type value_type;
32
33 using boost::mpi::all_to_all;
34
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)));
38
39 if (comm.rank() == 0) {
40 std::cout << "Performing all-to-all operation on " << kind << "...";
41 std::cout.flush();
42 }
43 std::vector<value_type> out_values;
44 all_to_all(comm, in_values, out_values);
45
46 for (int p = 0; p < comm.size(); ++p) {
47 BOOST_CHECK(out_values[p] == generator((p + 1) * (comm.rank() + 1)));
48 }
49
50 if (comm.rank() == 0) {
51 std::cout << " done." << std::endl;
52 }
53
54 (comm.barrier)();
55}
56
57// Generates integers to test with all_to_all()
58struct int_generator
59{
60 typedef int result_type;
61
62 int operator()(int p) const { return 17 + p; }
63};
64
65// Generates GPS positions to test with all_to_all()
66struct gps_generator
67{
68 typedef gps_position result_type;
69
70 gps_position operator()(int p) const
71 {
72 return gps_position(39 + p, 16, 20.2799);
73 }
74};
75
76struct string_generator
77{
78 typedef std::string result_type;
79
80 std::string operator()(int p) const
81 {
82 std::string result = boost::lexical_cast<std::string>(p);
83 result += " rosebud";
84 if (p != 1) result += 's';
85 return result;
86 }
87};
88
89struct string_list_generator
90{
91 typedef std::list<std::string> result_type;
92
93 std::list<std::string> operator()(int p) const
94 {
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);
99 }
100 return result;
101 }
102};
103
92f5a8d4 104BOOST_AUTO_TEST_CASE(all_to_all_check)
7c673cae 105{
92f5a8d4 106 boost::mpi::environment env;
7c673cae 107 communicator comm;
92f5a8d4 108
7c673cae
FG
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");
7c673cae 113}