]>
git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/mpi/example/string_cat.cpp
1 // Copyright (C) 2006 Douglas Gregor <doug.gregor@gmail.com>
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 // An example using Boost.MPI's reduce() to concatenate strings.
8 #include <boost/mpi.hpp>
11 #include <boost/serialization/string.hpp> // Important for sending strings!
12 namespace mpi
= boost::mpi
;
14 /* Defining STRING_CONCAT_COMMUTATIVE lies to Boost.MPI by forcing it
15 * to assume that string concatenation is commutative, which it is
16 * not. However, doing so illustrates how the results of a reduction
17 * can change when a non-commutative operator is assumed to be
20 #ifdef STRING_CONCAT_COMMUTATIVE
21 namespace boost
{ namespace mpi
{
24 struct is_commutative
<std::plus
<std::string
>, std::string
> : mpl::true_
{ };
26 } } // end namespace boost::mpi
29 int main(int argc
, char* argv
[])
31 mpi::environment
env(argc
, argv
);
32 mpi::communicator world
;
34 std::string names
[10] = { "zero ", "one ", "two ", "three ", "four ",
35 "five ", "six ", "seven ", "eight ", "nine " };
39 world
.rank() < 10? names
[world
.rank()] : std::string("many "),
40 result
, std::plus
<std::string
>(), 0);
42 if (world
.rank() == 0)
43 std::cout
<< "The result is " << result
<< std::endl
;